From 1bd590195f6065931c212310d7fc5195136aaa6e Mon Sep 17 00:00:00 2001 From: bsongis Date: Sun, 2 Sep 2012 21:00:22 +0000 Subject: [PATCH] [sky9x] Bug in SD Init fixed. Temperature alarm added. --- src/Makefile | 5 +- src/board_ersky9x.cpp | 42 ++++----- src/board_ersky9x.h | 4 +- src/ersky9x/audio.cpp | 20 ++++- src/ersky9x/audio.h | 5 ++ src/ersky9x/bluetooth.cpp | 176 ++++++++++++++++++++++++++++++-------- src/ersky9x/board.h | 2 +- src/ersky9x/diskio.c | 21 +++-- src/general_menus.cpp | 20 ++++- src/lcd.cpp | 6 +- src/myeeprom.h | 10 ++- src/open9x.cpp | 62 ++++++++------ src/open9x.h | 3 + src/simu.cpp | 4 +- src/statistics_views.cpp | 6 +- src/translations.cpp | 2 + src/translations.h | 2 + src/translations/cz.h | 2 + src/translations/de.h | 2 + src/translations/en.h | 2 + src/translations/fr.h | 2 + src/translations/it.h | 2 + src/translations/se.h | 2 + 23 files changed, 289 insertions(+), 113 deletions(-) diff --git a/src/Makefile b/src/Makefile index 480fb2acb..73ff3dad3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -423,7 +423,7 @@ RUN_FROM_FLASH = 1 ifeq ($(PCB), ARM) # V4 ARM, so ... OPT = 2 - CPPDEFS += -DPCBARM -DAUDIO -DHAPTIC -DVOICE -DPXX -DDSM2 -DDSM2_PPM -DROTARY_ENCODERS=1 + CPPDEFS += -DPCBARM -DAUDIO -DHAPTIC -DPXX -DDSM2 -DDSM2_PPM -DROTARY_ENCODERS=1 EXTRAINCDIRS += ersky9x CoOS/kernel CoOS/portable BOARDSRC = board_ersky9x.cpp SRC += ersky9x/core_cm3.c ersky9x/board_lowlevel.c ersky9x/crt.c ersky9x/vectors_sam3s.c @@ -435,13 +435,14 @@ ifeq ($(PCB), ARM) ifeq ($(SDCARD), YES) SRC += FatFs/ff.c FatFs/fattime.c FatFs/option/ccsbcs.c ersky9x/diskio.c + CPPDEFS += -DVOICE endif ifeq ($(BLUETOOTH), YES) MODS:=${MODS}S CPPDEFS += -DBLUETOOTH CPPSRC += ersky9x/bluetooth.cpp -endif + endif endif diff --git a/src/board_ersky9x.cpp b/src/board_ersky9x.cpp index 4749b0329..a0f43bc54 100644 --- a/src/board_ersky9x.cpp +++ b/src/board_ersky9x.cpp @@ -244,38 +244,20 @@ inline void UART3_Configure( uint32_t baudrate, uint32_t masterClock) /* Configure baudrate */ /* Asynchronous, no oversampling */ - baudrate = (masterClock * 8 / baudrate) / 16 ; - pUart->UART_BRGR = ( baudrate / 8 ) | ( ( baudrate & 7 ) << 16 ) ; // Fractional part to allow 152000 baud -// + pUart->UART_BRGR = ( (masterClock / baudrate) + 8 ) / 16; + /* Disable PDC channel */ pUart->UART_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS; /* Enable receiver and transmitter */ pUart->UART_CR = UART_CR_RXEN | UART_CR_TXEN; - + #if 0 - // TODO when we will want to be BT receiver pUart->UART_IER = UART_IER_RXRDY ; NVIC_EnableIRQ(UART1_IRQn) ; #endif } -struct t_serial_tx * Current_bt ; - -extern "C" void UART1_IRQHandler() -{ - Uart *pUart = BT_USART ; - if ( pUart->UART_SR & UART_SR_TXBUFE ) { - pUart->UART_IDR = UART_IDR_TXBUFE ; - pUart->UART_PTCR = US_PTCR_TXTDIS ; - Current_bt->ready = 0 ; - } - /* TODO - if ( pUart->UART_SR & UART_SR_RXRDY ) { - put_fifo32( &BtRx_fifo, pUart->UART_RHR ) ; - } */ -} - // USART0 configuration // Work in Progress, UNTESTED // Uses PA5 and PA6 (RXD and TXD) @@ -1007,8 +989,8 @@ extern uint32_t keyState(EnumKeys enuk) } uint16_t Analog_values[NUMBER_ANALOG] ; -uint16_t Temperature ; // Raw temp reading -uint16_t maxTemperature ; // Raw temp reading +uint8_t temperature ; // Raw temp reading +uint8_t maxTemperature ; // Raw temp reading // Read 8 (9 for REVB) ADC channels // Documented bug, must do them 1 by 1 @@ -1045,9 +1027,9 @@ void read_9_adc() Analog_values[8] = ADC->ADC_CDR8 ; #endif - Temperature = ( Temperature * 7 + ADC->ADC_CDR15 ) >> 3 ; // Filter it - if ( Temperature > maxTemperature ) { - maxTemperature = Temperature ; + temperature = (((int32_t)temperature * 7) + ((((int32_t)ADC->ADC_CDR15 - 838) * 621) >> 11)) >> 3; // Filter it + if (temperature > maxTemperature) { + maxTemperature = temperature; } } @@ -1180,6 +1162,13 @@ uint32_t txPdcPending() return x ; } +void end_bt_tx_interrupt() +{ + Uart *pUart = BT_USART ; + pUart->UART_IDR = UART_IDR_TXBUFE ; + NVIC_DisableIRQ(UART1_IRQn) ; +} + void usb_mode() { // This might be replaced by a software reset @@ -1187,6 +1176,7 @@ void usb_mode() // BEFORE calling sam_boot() stop_rotary_encoder(); endPdcUsartReceive() ; // Terminate any serial reception + end_bt_tx_interrupt() ; end_ppm_capture() ; end_spi() ; end_sound() ; diff --git a/src/board_ersky9x.h b/src/board_ersky9x.h index a1c78da46..1ed6f00a7 100644 --- a/src/board_ersky9x.h +++ b/src/board_ersky9x.h @@ -72,8 +72,8 @@ extern void sdPoll10mS(); void configure_pins( uint32_t pins, uint16_t config ); uint16_t getCurrent(); -extern uint16_t Temperature ; // Raw temp reading -extern uint16_t maxTemperature ; // Raw temp reading +extern uint8_t temperature ; // Raw temp reading +extern uint8_t maxTemperature ; // Raw temp reading #define strcpy_P strcpy #define strcat_P strcat diff --git a/src/ersky9x/audio.cpp b/src/ersky9x/audio.cpp index f9188ac77..b58a4fe28 100644 --- a/src/ersky9x/audio.cpp +++ b/src/ersky9x/audio.cpp @@ -33,9 +33,12 @@ #include "../open9x.h" +#if defined(SDCARD) + const char * audioFilenames[] = { "inactiv", "lowbatt", + "hightemp", "thralert", "swalert", "eebad", @@ -76,9 +79,8 @@ const char * audioFilenames[] = { #endif }; -uint32_t sdAvailableAudioFiles = (1 << AU_TADA); +uint32_t sdAvailableAudioFiles = 0; -#if defined(SDCARD) // TODO enable the assert when it's C++ extern "C" { void retrieveAvailableAudioFiles() @@ -175,6 +177,7 @@ void audioTask(void* pdata) { #if defined(SDCARD) sdInit(); + AUDIO_TADA(); #endif while (1) { @@ -477,16 +480,15 @@ void AudioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlag CoLeaveMutexSection(audioMutex); } +#if defined(SDCARD) void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id) { #ifdef SIMU printf("playFile(\"%s\")\n", filename); fflush(stdout); #endif -#if defined(SDCARD) if (Card_initialized && !sd_card_mounted()) return; -#endif CoEnterMutexSection(audioMutex); @@ -508,6 +510,7 @@ void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id) CoLeaveMutexSection(audioMutex); } +#endif void audioEvent(uint8_t e, uint8_t f) { @@ -545,9 +548,18 @@ void audioEvent(uint8_t e, uint8_t f) audioQueue.play(80, 40, 6, 2, -1); } break; + case AU_TX_TEMP_HIGH: + if (!audioQueue.busy()) { + // TODO Rob something better here? + audioQueue.play(60, 40, 6, 2, 1); + audioQueue.play(80, 40, 6, 2, -1); + } + break; // error +#if defined(VOICE) case AU_THROTTLE_ALERT: case AU_SWITCH_ALERT: +#endif case AU_ERROR: audioQueue.play(BEEP_DEFAULT_FREQ, 50, 2, PLAY_NOW); break; diff --git a/src/ersky9x/audio.h b/src/ersky9x/audio.h index 4674d4a2b..0aa5a4c62 100644 --- a/src/ersky9x/audio.h +++ b/src/ersky9x/audio.h @@ -115,8 +115,13 @@ void audioEvent(uint8_t e, uint8_t f=BEEP_DEFAULT_FREQ); #define AUDIO_WARNING1() audioEvent(AU_WARNING1) #define AUDIO_WARNING2() audioEvent(AU_WARNING2) #define AUDIO_TX_BATTERY_LOW() audioEvent(AU_TX_BATTERY_LOW) +#define AUDIO_TX_TEMP_HIGH() audioEvent(AU_TX_TEMP_HIGH) #define AUDIO_ERROR() audioEvent(AU_ERROR) +#if defined(VOICE) #define AUDIO_ERROR_MESSAGE(e) audioEvent(e) +#else +#define AUDIO_ERROR_MESSAGE(e) audioEvent(AU_ERROR) +#endif #define AUDIO_TIMER_30() audioEvent(AU_TIMER_30) #define AUDIO_TIMER_20() audioEvent(AU_TIMER_20) #define AUDIO_TIMER_10() audioEvent(AU_TIMER_10) diff --git a/src/ersky9x/bluetooth.cpp b/src/ersky9x/bluetooth.cpp index dd5a13c16..50cca17e2 100644 --- a/src/ersky9x/bluetooth.cpp +++ b/src/ersky9x/bluetooth.cpp @@ -33,10 +33,15 @@ #include "../open9x.h" +void btSetBaudrate(uint32_t index) +{ + uint32_t baudrate = (index==0 ? 115200 : (index==1 ? 9600 : 19200)); + UART3_Configure(baudrate, Master_frequency); +} + void btInit() { - uint32_t baudrate = (g_eeGeneral.btBaudrate==0 ? 115200 : (g_eeGeneral.btBaudrate==1 ? 9600 : 19200)); - UART3_Configure(baudrate, Master_frequency); + btSetBaudrate(g_eeGeneral.btBaudrate); } class Fifo32 @@ -74,12 +79,13 @@ class Fifo32 }; OS_FlagID btFlag; -Fifo32 btFifo; +Fifo32 btTxFifo; +Fifo32 btRxFifo; struct t_serial_tx btTx ; uint8_t btTxBuffer[32] ; -extern struct t_serial_tx * Current_bt ; +struct t_serial_tx * Current_bt ; uint32_t txPdcBt(struct t_serial_tx *data) { @@ -100,6 +106,27 @@ uint32_t txPdcBt(struct t_serial_tx *data) return 0 ; // Busy } +extern "C" void UART1_IRQHandler() +{ + Uart *pUart = BT_USART ; + if ( pUart->UART_SR & UART_SR_TXBUFE ) { + pUart->UART_IDR = UART_IDR_TXBUFE ; + pUart->UART_PTCR = US_PTCR_TXTDIS ; + Current_bt->ready = 0 ; + } + if ( pUart->UART_SR & UART_SR_RXRDY ) { + btRxFifo.push(pUart->UART_RHR); + } +} + +uint16_t rxBtuart() +{ + uint8_t result; + if (!btRxFifo.pop(result)) + return 0xffff; + + return result; +} void btSendBuffer() { @@ -111,46 +138,93 @@ void btSendBuffer() btTx.size = 0; } -void btPollDevice() +#define BT_POLL_TIMEOUT 500 + +uint32_t btChangeBaudrate( uint32_t baudIndex ) { -#if 0 - uint16_t x; - uint32_t y; - uint16_t rxchar; + uint16_t x ; + uint32_t y ; + uint16_t rxchar ; - x = 'O'; -#endif - - btTxBuffer[0] = 'A'; - btTxBuffer[1] = 'T'; - btTx.size = 2; - btSendBuffer(); - -#if 0 - for (y = 0; y < 300; y += 1) { - if ((rxchar = rxBtuart()) != 0xFFFF) { - if (rxchar == x) { - if (x == 'O') { - x = 'K'; + x = 4 ; // 9600 + if ( baudIndex == 0 ) + { + x = 8 ; // 115200 + } + else if ( baudIndex == 2 ) + { + x = 5 ; // 19200 + } + btTxBuffer[0] = 'A' ; + btTxBuffer[1] = 'T' ; + btTxBuffer[2] = '+' ; + btTxBuffer[3] = 'B' ; + btTxBuffer[4] = 'A' ; + btTxBuffer[5] = 'U' ; + btTxBuffer[6] = 'D' ; + btTxBuffer[7] = '0' + x ; + btTx.size = 8 ; + btSendBuffer() ; + x = 'O' ; + for( y = 0 ; y < BT_POLL_TIMEOUT ; y += 1 ) { + if ( ( rxchar = rxBtuart() ) != 0xFFFF ) { + if ( rxchar == x ) { + if ( x == 'O' ) { + x = 'K' ; } else { - break; // Found "OK" + break ; // Found "OK" } } } else { - CoTickDelay(1); // 2mS + CoTickDelay(1) ; // 2mS } } - if (y < 300) { - return 1; + + if ( y < BT_POLL_TIMEOUT ) { + return 1 ; } else { - return 0; + return 0 ; } -#endif } +uint32_t btPollDevice() +{ + uint16_t x ; + uint32_t y ; + uint16_t rxchar ; + + x = 'O' ; + btTxBuffer[0] = 'A' ; + btTxBuffer[1] = 'T' ; + btTx.size = 2 ; + btSendBuffer() ; + + for( y = 0 ; y < BT_POLL_TIMEOUT ; y++) { + if ( ( rxchar = rxBtuart() ) != 0xFFFF ) { + if ( rxchar == x ) { + if ( x == 'O' ) { + x = 'K' ; + } + else { + break ; // Found "OK" + } + } + } + else { + CoTickDelay(1) ; // 2mS + } + } + + if ( y < BT_POLL_TIMEOUT ) { + return 1 ; + } + else { + return 0 ; + } +} /* Commands to BT module @@ -178,6 +252,8 @@ Then we can change the baudrate to the required value. Or maybe just AT and get OK back */ +uint32_t btStatus; + void btTask(void* pdata) { uint8_t byte; @@ -185,9 +261,41 @@ void btTask(void* pdata) btFlag = CoCreateFlag(true, false); btTx.size = 0; -// Look for BT module baudrate, try 115200, and 9600 -// Already initialised to g_eeGeneral.bt_baudrate -// 0 : 115200, 1 : 9600, 2 : 19200 + // Look for BT module baudrate, try 115200, and 9600 + // Already initialised to g_eeGeneral.bt_baudrate + // 0 : 115200, 1 : 9600, 2 : 19200 + + uint32_t x = g_eeGeneral.btBaudrate; + + btStatus = btPollDevice() ; // Do we get a response? + + for (int y=0; y<2; y++) { + if (btStatus == 0) { + x += 1 ; + if (x > 2) { + x = 0 ; + } + btSetBaudrate(x) ; + CoTickDelay(1) ; // 2mS + btStatus = btPollDevice() ; // Do we get a response? + } + } + + if (btStatus) { + btStatus = x + 1 ; + if ( x != g_eeGeneral.btBaudrate ) { + x = g_eeGeneral.btBaudrate ; + // Need to change Bt Baudrate + btChangeBaudrate( x ) ; + btStatus += (x+1) * 10 ; + btSetBaudrate( x ) ; + } + } + else { + btInit(); + } + + CoTickDelay(1) ; btPollDevice(); // Do we get a response? @@ -195,7 +303,7 @@ void btTask(void* pdata) uint32_t x = CoWaitForSingleFlag(btFlag, 10); // Wait for data in Fifo if (x == E_OK) { // We have some data in the Fifo - while (btFifo.pop(byte)) { + while (btTxFifo.pop(byte)) { btTxBuffer[btTx.size++] = byte; if (btTx.size > 31) { btSendBuffer(); @@ -210,6 +318,6 @@ void btTask(void* pdata) void btPushByte(uint8_t data) { - btFifo.push(data); + btTxFifo.push(data); CoSetFlag(btFlag); // Tell the Bt task something to do } diff --git a/src/ersky9x/board.h b/src/ersky9x/board.h index b0f95ecfa..014ac7cc0 100644 --- a/src/ersky9x/board.h +++ b/src/ersky9x/board.h @@ -512,7 +512,7 @@ #define SD_ST_MOUNTED 10 extern int32_t Card_state; -extern uint32_t Card_initialized; +extern volatile uint32_t Card_initialized; /* #define BOARD_PSRAM_PINS PIN_EBI_DATA_BUS, PIN_EBI_NCS0, PIN_EBI_NRD, PIN_EBI_NWE, \ diff --git a/src/ersky9x/diskio.c b/src/ersky9x/diskio.c index 8ab79e6b7..a55d28aa3 100644 --- a/src/ersky9x/diskio.c +++ b/src/ersky9x/diskio.c @@ -70,7 +70,7 @@ uint32_t Card_ID[4] ; uint32_t Card_SCR[2] ; uint32_t Card_CSD[4] ; int32_t Card_state = SD_ST_STARTUP ; -uint32_t Card_initialized = 0; +volatile uint32_t Card_initialized = 0; uint32_t Sd_128_resp[4] ; uint32_t Sd_rca ; uint32_t Cmd_8_resp ; @@ -873,13 +873,21 @@ void sdInit() if (!CardIsConnected()) { Card_state = SD_ST_EMPTY; + Card_initialized = 1; return; } sdCmd0(); + CoTickDelay(5); // 10ms sdCmd8(1); sdMemInit(1, &Cmd_A41_resp); +#if 0 + // sdAvailableAudioFiles = 0; + Card_state = SD_ST_READY; + Card_initialized = 1; +#else + uint8_t retry; for (retry=0; retry<10; retry++) { if (!sdCmd2()) break; @@ -888,6 +896,7 @@ void sdInit() if (retry == 10) { Card_state = SD_ST_READY; + Card_initialized = 1; return; } @@ -898,6 +907,7 @@ void sdInit() if (retry == 10) { Card_state = SD_ST_IDENT; + Card_initialized = 1; return; } @@ -910,10 +920,11 @@ void sdInit() // Should check the card can do this **** Card_state = SD_ST_DATA; - f_mount(0, &g_FATFS_Obj); - retrieveAvailableAudioFiles(); - Card_state = SD_ST_MOUNTED; - + if (f_mount(0, &g_FATFS_Obj) == FR_OK) { + retrieveAvailableAudioFiles(); + Card_state = SD_ST_MOUNTED; + } +#endif Card_initialized = 1; } diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 923bc6ad5..647a78421 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -136,6 +136,10 @@ enum menuProcSetupItems { #endif ITEM_SETUP_CONTRAST, ITEM_SETUP_BATTERY_WARNING, +#if defined(PCBARM) + ITEM_SETUP_CAPACITY_WARNING, + ITEM_SETUP_TEMPERATURE_WARNING, +#endif ITEM_SETUP_INACTIVITY_ALARM, #if defined(BLUETOOTH) ITEM_SETUP_BT_BAUDRATE, @@ -192,7 +196,7 @@ void menuProcSetup(uint8_t event) #define FRSKY_ZEROS #endif #ifdef PCBARM -#define ARM_ZEROS 0, 0, +#define ARM_ZEROS 0, 0, 0, 0, #else #define ARM_ZEROS #endif @@ -317,6 +321,20 @@ void menuProcSetup(uint8_t event) if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatWarn, 40, 120); //4-12V break; +#if defined(PCBARM) + case ITEM_SETUP_CAPACITY_WARNING: + lcd_putsLeft(y, STR_CAPAWARNING); + putsTelemetryValue(GENERAL_PARAM_OFS, y, g_eeGeneral.mAhWarn*50, UNIT_MAH, attr|LEFT) ; + if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.mAhWarn, 0, 100); + break; + + case ITEM_SETUP_TEMPERATURE_WARNING: + lcd_putsLeft(y, STR_TEMPWARNING); + putsTelemetryValue(GENERAL_PARAM_OFS, y, 80+g_eeGeneral.temperatureWarn, UNIT_DEGREES, attr|LEFT) ; + if(attr) CHECK_INCDEC_GENVAR(event, g_eeGeneral.temperatureWarn, -80, 40); // 0-120degrees + break; +#endif + case ITEM_SETUP_INACTIVITY_ALARM: lcd_putsLeft( y,STR_INACTIVITYALARM); lcd_outdezAtt(GENERAL_PARAM_OFS, y, g_eeGeneral.inactivityTimer, attr|LEFT); diff --git a/src/lcd.cpp b/src/lcd.cpp index aacb1f1fa..5f461ca4f 100644 --- a/src/lcd.cpp +++ b/src/lcd.cpp @@ -730,7 +730,7 @@ void lcdSendCtl(uint8_t val) pioptr->PIO_SODR = LCD_E ; // Start E pulse // Need a delay here (250nS) TC0->TC_CHANNEL[0].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger) - while ( TC0->TC_CHANNEL[0].TC_CV < 3 ) // Value depends on MCK/2 (used 6MHz) + while ( TC0->TC_CHANNEL[0].TC_CV < 9 ) // Value depends on MCK/2 (used 18MHz) { // Wait } @@ -768,13 +768,13 @@ void lcd_init() pioptr->PIO_CODR = LCD_RES ; // Reset LCD TC0->TC_CHANNEL[0].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger) - while ( TC0->TC_CHANNEL[0].TC_CV < 12 ) // 2 uS, Value depends on MCK/2 (used 6MHz) + while ( TC0->TC_CHANNEL[0].TC_CV < 200 ) // > 10us, Value depends on MCK/2 (used 18MHz) { // Wait } pioptr->PIO_SODR = LCD_RES ; // Remove LCD reset TC0->TC_CHANNEL[0].TC_CCR = 5 ; // Enable clock and trigger it (may only need trigger) - while ( TC0->TC_CHANNEL[0].TC_CV < 9000 ) // 1500 uS, Value depends on MCK/2 (used 6MHz) + while ( TC0->TC_CHANNEL[0].TC_CV < 27000 ) // 1500us, Value depends on MCK/2 (used 18MHz) { // Wait } diff --git a/src/myeeprom.h b/src/myeeprom.h index 89dcda473..f70c6f251 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -96,10 +96,13 @@ enum BeeperMode { uint8_t speakerVolume; \ uint8_t backlightBright; \ int8_t currentCalib; -#define EXTRA_NON_ARM_FIELDS +#define EXTRA_GENERAL_FIELDS \ + int8_t temperatureWarn; \ + uint8_t mAhWarn; \ + uint16_t mAhUsed; #else #define EXTRA_ARM_FIELDS -#define EXTRA_NON_ARM_FIELDS \ +#define EXTRA_GENERAL_FIELDS \ int8_t speakerVolume; #endif @@ -163,7 +166,8 @@ PACK(typedef struct t_EEGeneral { uint8_t variants; - EXTRA_NON_ARM_FIELDS; + EXTRA_GENERAL_FIELDS + }) EEGeneral; // eeprom modelspec diff --git a/src/open9x.cpp b/src/open9x.cpp index 5259d4178..f87dab101 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -924,11 +924,11 @@ void putsTelemetryValue(uint8_t x, uint8_t y, int16_t val, uint8_t unit, uint8_t void clearKeyEvents() { -#if defined(PCBARM) && !defined(SIMU) +#if defined(PCBARM) CoTickDelay(100); // 200ms #endif -#ifdef SIMU +#if defined(SIMU) while (keyDown() && main_thread_running) sleep(1/*ms*/); #else while (keyDown()) WDT_RESET_STOCK(); // loop until all keys are up @@ -982,7 +982,9 @@ void doSplash() lcd_img(0, 0, splash_lbm, 0, 0); refreshDisplay(); +#if !defined(PCBARM) AUDIO_TADA(); +#endif #if defined(PCBSTD) lcdSetContrast(); @@ -992,7 +994,7 @@ void doSplash() lcdSetRefVolt(contrast); #endif -#ifndef SIMU +#if !defined(SIMU) for(uint8_t i=0; i<32; i++) getADC_filt(); // init ADC array #endif @@ -2704,6 +2706,11 @@ void perMain() if (g_vbat100mV <= g_eeGeneral.vBatWarn && g_vbat100mV>50) { AUDIO_TX_BATTERY_LOW(); } +#if defined(PCBARM) + if (temperature >= g_eeGeneral.temperatureWarn+80) { + AUDIO_TX_TEMP_HIGH(); + } +#endif } } } @@ -3131,12 +3138,10 @@ inline void open9xInit(OPEN9X_INIT_ARGS) if (!UNEXPECTED_SHUTDOWN()) { doSplash(); -#if defined(PCBARM) -#if defined(SDCARD) - while (!Card_initialized) { +#if defined(PCBARM) && defined(SDCARD) + for (int i=0; i<200 && !Card_initialized; i++) { CoTickDelay(1); // 2ms } -#endif #endif #if !defined(PCBARM) @@ -3633,19 +3638,21 @@ void menusTask(void * pdata) closeLogs(); #endif + SysTick->CTRL = 0; // turn off systick + #if defined(HAPTIC) hapticOff(); #endif - SysTick->CTRL = 0; // turn off systick + lcd_clear() ; + + if (shutdown_state != e_power_usb) { + displayPopup(STR_SHUTDOWN); + g_eeGeneral.unexpectedShutdown=0; + eeDirty(EE_GENERAL); + eeCheck(true); + } - lcd_clear() ; - displayPopup(STR_SHUTDOWN); - g_eeGeneral.unexpectedShutdown=0; - eeDirty(EE_GENERAL); - eeCheck(true); - lcd_clear() ; - refreshDisplay() ; soft_power_off(); // Only turn power off if necessary if (shutdown_state == e_power_usb) { @@ -3656,18 +3663,19 @@ void menusTask(void * pdata) #ifdef MASSSTORAGE if (mass_storage) { stop_rotary_encoder(); - endPdcUsartReceive() ; // Terminate any serial reception - end_ppm_capture() ; - end_spi() ; - end_sound() ; - TC0->TC_CHANNEL[2].TC_IDR = TC_IDR0_CPCS ; - NVIC_DisableIRQ(TC2_IRQn) ; - // PWM->PWM_IDR1 = PWM_IDR1_CHID0 ; - disable_main_ppm() ; - // PWM->PWM_IDR1 = PWM_IDR1_CHID3 ; - // NVIC_DisableIRQ(PWM_IRQn) ; - disable_ssc() ; - usbMassStorage(); + endPdcUsartReceive() ; // Terminate any serial reception + end_bt_tx_interrupt() ; + end_ppm_capture() ; + end_spi() ; + end_sound() ; + TC0->TC_CHANNEL[2].TC_IDR = TC_IDR0_CPCS ; + NVIC_DisableIRQ(TC2_IRQn) ; + // PWM->PWM_IDR1 = PWM_IDR1_CHID0 ; + disable_main_ppm() ; + // PWM->PWM_IDR1 = PWM_IDR1_CHID3 ; + // NVIC_DisableIRQ(PWM_IRQn) ; + disable_ssc() ; + usbMassStorage(); } else #endif diff --git a/src/open9x.h b/src/open9x.h index 11baa7998..69f2449d8 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -964,6 +964,9 @@ extern uint16_t jeti_keys; enum AUDIO_SOUNDS { AU_INACTIVITY, AU_TX_BATTERY_LOW, +#if defined(PCBARM) + AU_TX_TEMP_HIGH, +#endif #if defined(VOICE) AU_THROTTLE_ALERT, AU_SWITCH_ALERT, diff --git a/src/simu.cpp b/src/simu.cpp index 36890b4ac..b3f8a33fd 100644 --- a/src/simu.cpp +++ b/src/simu.cpp @@ -274,8 +274,8 @@ long Open9xSim::onTimeout(FXObject*,FXSelector,void*) ERSKY9X_EXIT_PIO->PIO_PDSR |= ERSKY9X_EXIT_MASK; PIOB->PIO_PDSR |= ERSKY9X_MENU_MASK; // PIOA->PIO_PDSR = 0xFFFFFFFF; - Temperature = 1000; - maxTemperature = 1500; + temperature = 67; + maxTemperature = 70; #elif defined(PCBV4) uint8_t pin = (pinl & ~0x3f); diff --git a/src/statistics_views.cpp b/src/statistics_views.cpp index 9b4ffe791..1f9ee2904 100644 --- a/src/statistics_views.cpp +++ b/src/statistics_views.cpp @@ -121,12 +121,12 @@ void menuProcDebug(uint8_t event) #if defined(PCBARM) #if defined(REVB) lcd_putsLeft(2*FH, STR_CURRENT); - putsTelemetryValue(MENU_DEBUG_COL_OFS, 2*FH, getCurrent(), UNIT_MILLIAMPS, 0) ; + putsTelemetryValue(MENU_DEBUG_COL_OFS, 2*FH, getCurrent(), UNIT_MILLIAMPS, 0); #endif lcd_putsLeft(3*FH, STR_CPU_TEMP); - putsTelemetryValue(MENU_DEBUG_COL_OFS, 3*FH, (((((int32_t)Temperature - 838 ) * 621 ) >> 11 ) - 20), UNIT_DEGREES, 0 ) ; - putsTelemetryValue(20*FW+2, 3*FH, (((((int32_t)maxTemperature - 838 ) * 621 ) >> 11 ) - 20), UNIT_DEGREES, 0 ) ; + putsTelemetryValue(MENU_DEBUG_COL_OFS, 3*FH, temperature, UNIT_DEGREES, 0); + putsTelemetryValue(20*FW+2, 3*FH, maxTemperature, UNIT_DEGREES, 0); // TODO mAh, Battery from ersky9x? #endif diff --git a/src/translations.cpp b/src/translations.cpp index 975c5c5e0..802e3a6cc 100644 --- a/src/translations.cpp +++ b/src/translations.cpp @@ -338,6 +338,8 @@ const pm_char STR_SPEAKER_VOLUME[] PROGMEM = TR_SPEAKER_VOLUME; const pm_char STR_OPTREX_DISPLAY[] PROGMEM = TR_OPTREX_DISPLAY; const pm_char STR_BRIGHTNESS[] PROGMEM = TR_BRIGHTNESS; const pm_char STR_CPU_TEMP[] PROGMEM = TR_CPU_TEMP; +const pm_char STR_TEMPWARNING[] PROGMEM = TR_TEMPWARNING; +const pm_char STR_CAPAWARNING[] PROGMEM = TR_CAPAWARNING; const pm_char STR_FUNC[] PROGMEM = TR_FUNC; const pm_char STR_V1[] PROGMEM = TR_V1; const pm_char STR_V2[] PROGMEM = TR_V2; diff --git a/src/translations.h b/src/translations.h index fee92b1fd..6cfb3c50a 100644 --- a/src/translations.h +++ b/src/translations.h @@ -420,6 +420,8 @@ extern const pm_char STR_SPEAKER_VOLUME[]; extern const pm_char STR_OPTREX_DISPLAY[]; extern const pm_char STR_BRIGHTNESS[]; extern const pm_char STR_CPU_TEMP[]; +extern const pm_char STR_CAPAWARNING[]; +extern const pm_char STR_TEMPWARNING[]; extern const pm_char STR_FUNC[]; extern const pm_char STR_V1[]; extern const pm_char STR_V2[]; diff --git a/src/translations/cz.h b/src/translations/cz.h index 11eb7cec3..1417da021 100644 --- a/src/translations/cz.h +++ b/src/translations/cz.h @@ -423,6 +423,8 @@ #define TR_OPTREX_DISPLAY "Optrex Display" #define TR_BRIGHTNESS "Jas" #define TR_CPU_TEMP "tepl. CPU\010>" +#define TR_CAPAWARNING "Capacity Warning" +#define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Fun." #define TR_V1 "V1" #define TR_V2 "V2" diff --git a/src/translations/de.h b/src/translations/de.h index ef1649d2d..3caf0f453 100644 --- a/src/translations/de.h +++ b/src/translations/de.h @@ -423,6 +423,8 @@ #define TR_OPTREX_DISPLAY "Optrex Display" #define TR_BRIGHTNESS "Brightness" #define TR_CPU_TEMP "CPU temp.\010>" +#define TR_CAPAWARNING "Capacity Warning" +#define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Func" #define TR_V1 "V1" #define TR_V2 "V2" diff --git a/src/translations/en.h b/src/translations/en.h index 60364ccf4..33c4df5a7 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -424,6 +424,8 @@ #define TR_OPTREX_DISPLAY "Optrex Display" #define TR_BRIGHTNESS "Brightness" #define TR_CPU_TEMP "CPU temp.\010>" +#define TR_CAPAWARNING "Capacity Warning" +#define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Func" #define TR_V1 "V1" #define TR_V2 "V2" diff --git a/src/translations/fr.h b/src/translations/fr.h index 34c610329..edf317269 100644 --- a/src/translations/fr.h +++ b/src/translations/fr.h @@ -422,6 +422,8 @@ #define TR_OPTREX_DISPLAY "Afficheur Optrex" #define TR_BRIGHTNESS "Luminosit\200" #define TR_CPU_TEMP "Temp. CPU\010>" +#define TR_CAPAWARNING "Capacity Warning" +#define TR_TEMPWARNING "Alarme temp" #define TR_FUNC "Fonc" #define TR_V1 "V1" #define TR_V2 "V2" diff --git a/src/translations/it.h b/src/translations/it.h index d8a53eef4..a945aa17a 100644 --- a/src/translations/it.h +++ b/src/translations/it.h @@ -423,6 +423,8 @@ #define TR_OPTREX_DISPLAY "Display Optrex" #define TR_BRIGHTNESS "Luminosita'" #define TR_CPU_TEMP "Temp CPU \010>" +#define TR_CAPAWARNING "Capacity Warning" +#define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Funz" #define TR_V1 "V1" #define TR_V2 "V2" diff --git a/src/translations/se.h b/src/translations/se.h index b60592e20..6e22c2915 100644 --- a/src/translations/se.h +++ b/src/translations/se.h @@ -421,6 +421,8 @@ #define TR_OPTREX_DISPLAY "Optrex Display" #define TR_BRIGHTNESS "Brightness" #define TR_CPU_TEMP "CPU temp.\010>" +#define TR_CAPAWARNING "Capacity Warning" +#define TR_TEMPWARNING "Temp Warning" #define TR_FUNC "Func" #define TR_V1 "V1" #define TR_V2 "V2"