diff --git a/src/ersky9x/audio.cpp b/src/ersky9x/audio.cpp index cdf9aa492..ef9aa9e6c 100644 --- a/src/ersky9x/audio.cpp +++ b/src/ersky9x/audio.cpp @@ -76,7 +76,7 @@ const char * audioFilenames[] = { #endif }; -uint32_t sdAvailableAudioFiles; +uint32_t sdAvailableAudioFiles = (1 << AU_TADA); #if defined(SDCARD) // TODO enable the assert when it's C++ @@ -91,14 +91,16 @@ void retrieveAvailableAudioFiles() assert(sizeof(sdAvailableAudioFiles)*8 > AU_FRSKY_FIRST); #endif - sdAvailableAudioFiles = 0; + uint32_t availableAudioFiles = 0; for (uint32_t i=0; iPIO_PDSR & PIO_PB7) == 0 ) +// States for initialising card +#define SD_ST_ERR -1 +#define SD_ST_STARTUP 0 +#define SD_ST_EMPTY 1 +#define SD_ST_INIT1 2 +#define SD_ST_INIT2 3 +#define SD_ST_IDLE 4 +#define SD_ST_READY 5 +#define SD_ST_IDENT 6 +#define SD_ST_STBY 7 +#define SD_ST_TRAN 8 +#define SD_ST_DATA 9 +#define SD_ST_MOUNTED 10 + +extern int32_t Card_state; + /* #define BOARD_PSRAM_PINS PIN_EBI_DATA_BUS, PIN_EBI_NCS0, PIN_EBI_NRD, PIN_EBI_NWE, \ PIN_EBI_PSRAM_ADDR_BUS, PIN_EBI_PSRAM_NBS, PIN_EBI_A1 diff --git a/src/ersky9x/diskio.c b/src/ersky9x/diskio.c index 4f1854d36..d47e97b31 100644 --- a/src/ersky9x/diskio.c +++ b/src/ersky9x/diskio.c @@ -66,23 +66,10 @@ /** SDIO Combo, with SDHC embedded (0xB) */ #define CARD_SDHCCOMBO (CARD_TYPE_bmSDIO|CARD_SDHC) -// States for initialising card -#define SD_ST_ERR -1 -#define SD_ST_EMPTY 0 -#define SD_ST_INIT1 1 -#define SD_ST_INIT2 2 -#define SD_ST_IDLE 3 -#define SD_ST_READY 4 -#define SD_ST_IDENT 5 -#define SD_ST_STBY 6 -#define SD_ST_TRAN 7 -#define SD_ST_DATA 8 -#define SD_ST_MOUNTED 9 - uint32_t Card_ID[4] ; uint32_t Card_SCR[2] ; uint32_t Card_CSD[4] ; -int32_t Card_state = SD_ST_EMPTY ; +int32_t Card_state = SD_ST_STARTUP ; uint32_t Sd_128_resp[4] ; uint32_t Sd_rca ; uint32_t Cmd_8_resp ; @@ -814,6 +801,9 @@ void retrieveAvailableAudioFiles(); void sdPoll10mS() { + if (Card_state == SD_ST_STARTUP) + return; + if (!CardIsConnected()) { Card_state = SD_ST_EMPTY; Sd_rca = 0; @@ -879,52 +869,45 @@ void sdInit() Sd_rca = 0; sdErrorCount = 0; - Card_state = SD_ST_EMPTY; - if (!CardIsConnected()) + if (!CardIsConnected()) { + Card_state = SD_ST_EMPTY; return; + } - Card_state = SD_ST_INIT1; sdCmd0(); - - Card_state = SD_ST_INIT2; sdCmd8(1); - - Card_state = SD_ST_IDLE; sdMemInit(1, &Cmd_A41_resp); - Card_state = SD_ST_READY; uint8_t retry; for (retry=0; retry<10; retry++) { if (!sdCmd2()) break; CoTickDelay(1); // 2ms } - if (retry == 10) + if (retry == 10) { + Card_state = SD_ST_READY; return; - - Card_state = SD_ST_IDENT; + } for (retry=0; retry<10; retry++) { if (!sdCmd3()) break; CoTickDelay(1); // 2ms } - if (retry == 10) + if (retry == 10) { + Card_state = SD_ST_IDENT; return; + } - Card_state = SD_ST_STBY; sdCmd9(); sdCmd7(); // Select Card - - Card_state = SD_ST_TRAN; sdAcmd51(); sdAcmd6(); // Set bus width to 4 bits, and speed to 9 MHz // Should check the card can do this **** - Card_state = SD_ST_DATA; - f_mount(0, &g_FATFS_Obj); retrieveAvailableAudioFiles(); + Card_state = SD_ST_MOUNTED; } diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 15ae49f52..1976406cc 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -745,7 +745,6 @@ void menuProcTrainer(uint8_t event) } } -extern uint32_t Card_state; void menuProcDiagVers(uint8_t event) { SIMPLE_MENU(STR_MENUVERSION, menuTabDiag, e_Vers, 1); diff --git a/src/open9x.cpp b/src/open9x.cpp index 38a2dcd2c..7accdb7aa 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -2234,7 +2234,7 @@ char userDataDisplayBuf[TELEM_SCREEN_BUFFER_SIZE]; ACTIVE_MIXES_TYPE activeMixes; #endif int32_t sum_chans512[NUM_CHNOUT] = {0}; -inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms) +inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms) { #ifdef BOLD_FONT activeMixes = 0; @@ -2347,11 +2347,11 @@ inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms) val += RESX; val /= (RESX/16); // calibrate it - static uint16_t s_time_tot; + static tmr10ms_t s_time_tot; static uint8_t s_cnt_1s; static uint16_t s_sum_1s; #if defined(THRTRACE) - static uint16_t s_time_trace; + static tmr10ms_t s_time_trace; static uint16_t s_cnt_10s; static uint16_t s_sum_10s; #endif @@ -2359,7 +2359,7 @@ inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms) s_cnt_1s++; s_sum_1s += val; - if ((uint16_t)(tmr10ms - s_time_tot) >= 100) { // 1sec + if ((tmr10ms_t)(tmr10ms - s_time_tot) >= 100) { // 1sec s_time_tot += 100; s_timeCumTot += 1; @@ -2371,7 +2371,7 @@ inline void doMixerCalculations(uint16_t tmr10ms, uint8_t tick10ms) s_cnt_10s += s_cnt_1s; s_sum_10s += s_sum_1s; - if ((uint16_t)(tmr10ms - s_time_trace) >= 1000) {// 10sec + if ((tmr10ms_t)(tmr10ms - s_time_trace) >= 1000) {// 10sec s_time_trace += 1000; val = s_sum_10s / s_cnt_10s; s_sum_10s = 0; @@ -2531,7 +2531,7 @@ void perMain() { static tmr10ms_t lastTMR; tmr10ms_t tmr10ms = get_tmr10ms(); - uint8_t tick10ms = (tmr10ms > lastTMR ? tmr10ms - lastTMR : 1); + uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1); lastTMR = tmr10ms; #if defined(PCBSTD) || defined(SIMU) @@ -2747,7 +2747,7 @@ ISR(TIMER5_COMPA_vect, ISR_NOBLOCK) // mixer interrupt static tmr10ms_t lastTMR; tmr10ms_t tmr10ms = get_tmr10ms(); - uint8_t tick10ms = (tmr10ms > lastTMR ? tmr10ms - lastTMR : 1); + uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1); lastTMR = tmr10ms; if (s_current_protocol < PROTO_NONE) { @@ -3121,11 +3121,7 @@ inline void open9xInit(OPEN9X_INIT_ARGS) if (g_eeGeneral.backlightMode != e_backlight_mode_off) backlightOn(); // on Tx start turn the light on if (!UNEXPECTED_SHUTDOWN()) { -#if defined(PCBARM) - lcd_clear(); - refreshDisplay(); - sdInit(); -#elif 0 +#if 0 // defined(PCBSTD) && defined(VOICE) && !defined(SPLASH) lcd_clear(); lcd_putsAtt(20, 28, PSTR("Open9x..."), DBLSIZE); @@ -3136,6 +3132,12 @@ inline void open9xInit(OPEN9X_INIT_ARGS) doSplash(); +#if defined(PCBARM) + while (Card_state == SD_ST_STARTUP) { + CoTickDelay(1); // 2ms + } +#endif + #if !defined(PCBARM) checkLowEEPROM(); #endif @@ -3181,7 +3183,7 @@ void mixerTask(void * pdata) static tmr10ms_t lastTMR; tmr10ms_t tmr10ms = get_tmr10ms(); - uint8_t tick10ms = (tmr10ms > lastTMR ? tmr10ms - lastTMR : 1); + uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1); lastTMR = tmr10ms; if (s_current_protocol < PROTO_NONE) { diff --git a/src/simpgmspace.cpp b/src/simpgmspace.cpp index 874065fce..e187440de 100644 --- a/src/simpgmspace.cpp +++ b/src/simpgmspace.cpp @@ -394,5 +394,5 @@ FRESULT f_getcwd (TCHAR *path, UINT sz_path) return FR_OK; } -uint32_t Card_state = 8; +int32_t Card_state = SD_ST_MOUNTED; #endif