diff --git a/src/ersky9x/diskio.cpp b/src/ersky9x/diskio.cpp index c7ab69a8c..7c45b137e 100644 --- a/src/ersky9x/diskio.cpp +++ b/src/ersky9x/diskio.cpp @@ -47,13 +47,14 @@ // States for initialising card #define SD_ST_EMPTY 0 -#define SD_ST_IDLE 1 -#define SD_ST_READY 2 -#define SD_ST_IDENT 3 -#define SD_ST_STBY 4 -#define SD_ST_TRAN 5 -#define SD_ST_DATA 6 - +#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 uint32_t Card_ID[4] ; uint32_t Card_SCR[2] ; @@ -62,6 +63,8 @@ uint32_t Card_state = SD_ST_EMPTY ; uint32_t Sd_128_resp[4] ; uint32_t Sd_rca ; //uint32_t Cmd_55_resp ; +uint32_t Cmd_8_resp ; +uint32_t Cmd_A41_resp ; /** * Initializes a MCI peripheral. @@ -224,51 +227,87 @@ void SD_Reset( uint8_t keepSettings) void sd_cmd55() { - uint32_t i ; + uint32_t i ; Hsmci *phsmci = HSMCI ; - if ( CardIsConnected() ) - { - phsmci->HSMCI_ARGR = Sd_rca ; - phsmci->HSMCI_CMDR = 0x00001077 ; + if ( CardIsConnected() ) + { + phsmci->HSMCI_ARGR = Sd_rca ; + phsmci->HSMCI_CMDR = 0x00001077 ; - for ( i = 0 ; i < 30000 ; i += 1 ) - { - if ( phsmci->HSMCI_SR & HSMCI_SR_CMDRDY ) - { - break ; - } - } + for ( i = 0 ; i < 30000 ; i += 1 ) + { + if ( phsmci->HSMCI_SR & HSMCI_SR_CMDRDY ) + { + break ; + } + } // Cmd_55_resp = phsmci->HSMCI_RSPR[0] ; - } + } } +uint32_t sd_cmd0() +{ + uint32_t i; + Hsmci *phsmci = HSMCI; + if (CardIsConnected()) { + phsmci->HSMCI_ARGR = 0; + phsmci->HSMCI_CMDR = 0x00001000; + + for (i = 0; i < 30000; i += 1) { + if (phsmci->HSMCI_SR & HSMCI_SR_CMDRDY) { + break; + } + } + return phsmci->HSMCI_RSPR[0]; + } + else { + return 0; + } +} + +uint32_t sd_cmd8() +{ + uint32_t i; + Hsmci *phsmci = HSMCI; + + if (CardIsConnected()) { + phsmci->HSMCI_ARGR = 0X000001AA; + phsmci->HSMCI_CMDR = 0x00001048; + + for (i = 0; i < 30000; i += 1) { + if (phsmci->HSMCI_SR & HSMCI_SR_CMDRDY) { + break; + } + } + return Cmd_8_resp = phsmci->HSMCI_RSPR[0]; + } + else { + return 0; + } +} uint32_t sd_acmd41() { - uint32_t i ; - Hsmci *phsmci = HSMCI ; + uint32_t i; + Hsmci *phsmci = HSMCI; - if ( CardIsConnected() ) - { - sd_cmd55() ; - phsmci->HSMCI_ARGR = 0X001F8000 ; - phsmci->HSMCI_CMDR = 0x00001069 ; + if (CardIsConnected()) { + sd_cmd55(); + phsmci->HSMCI_ARGR = 0x403F8000; + phsmci->HSMCI_CMDR = 0x00001069; - for ( i = 0 ; i < 30000 ; i += 1 ) - { - if ( phsmci->HSMCI_SR & HSMCI_SR_CMDRDY ) - { - break ; - } - } - return phsmci->HSMCI_RSPR[0] ; - } - else - { - return 0 ; - } + for (i = 0; i < 30000; i += 1) { + if (phsmci->HSMCI_SR & HSMCI_SR_CMDRDY) { + break; + } + } + return Cmd_A41_resp = phsmci->HSMCI_RSPR[0] ; + } + else { + return 0; + } } // Get Card ID @@ -498,19 +537,27 @@ void sd_poll_10mS() switch ( Card_state ) { case SD_ST_EMPTY : - if ( CardIsConnected() ) - { - Card_state = SD_ST_IDLE ; - } - break ; + if ( CardIsConnected() ) { + Card_state = SD_ST_INIT1 ; + } + break ; + + case SD_ST_INIT1 : + i = sd_cmd0() ; + Card_state = SD_ST_INIT2 ; + break ; + + case SD_ST_INIT2 : + i = sd_cmd8() ; + Card_state = SD_ST_IDLE ; + break ; case SD_ST_IDLE : - i = sd_acmd41() ; - if ( i & 0x80000000 ) - { - Card_state = SD_ST_READY ; - } - break ; + i = sd_acmd41() ; + if ( i & 0x80000000 ) { + Card_state = SD_ST_READY ; + } + break ; case SD_ST_READY : i = sd_cmd2() ; @@ -662,6 +709,12 @@ uint32_t sd_write_block( uint32_t block_no, uint32_t *data ) /* Notes on SD card: +1) CMD8 fails and CMD58 fails: must be MMC, thus initialize using CMD1 +2) CMD8 fails and CMD58 passes: must be Ver1.x Standard Capacity SD Memory Card +3) CMD8 passes and CMD58 passes (CCS = 0): must be Ver2.00 or later Standard Capacity SD Memory Card +4) CMD8 passes and CMD58 passes (CCS = 1): must be Ver2.00 or later High Capacity SD Memory Card +5) CMD8 passes and CMD58 passes but indicates non compatible voltage range: unusable card + On card present 1. Send CMD 55 (resp 48bit) followed by ACMD41 (resp48bit) diff --git a/src/main_views.cpp b/src/main_views.cpp index e3041cacf..2a5fcfd5d 100644 --- a/src/main_views.cpp +++ b/src/main_views.cpp @@ -311,7 +311,7 @@ void menuMainView(uint8_t event) #if defined(PCBV4) for (uint8_t i=0; i=-26 && v<=26) { v = -v; // toggle case - STORE_MODELVARS; // TODO optim if (c!=v) at the end if (event==EVT_KEY_LONG(KEY_LEFT)) killEvents(KEY_LEFT); } break; } - name[cur] = v; + if (c != v) { + name[cur] = v; + STORE_MODELVARS; + } lcd_putcAtt(x+cur*FW, y, idx2char(v), INVERS); cur = next; } diff --git a/src/open9x.cpp b/src/open9x.cpp index f42e29c8d..7866e44e4 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -398,6 +398,8 @@ int16_t applyLimits(uint8_t channel, int32_t value) return ofs; } +int16_t calibratedStick[NUM_STICKS+NUM_POTS]; +int16_t g_chans512[NUM_CHNOUT]; int16_t ex_chans[NUM_CHNOUT] = {0}; // Outputs (before LIMITS) of the last perMain #ifdef HELI int16_t cyc_anas[3] = {0}; @@ -1326,20 +1328,19 @@ FORCEINLINE void evalTrims() uint8_t phase = s_perout_flight_phase; for (uint8_t i=0; i throttle trim if applicable - // TODO avoid int32_t vv - int32_t vv = 2*RESX; int16_t trim = getTrimValue(phase, i); if (i==THR_STICK && g_model.thrTrim) { if (g_eeGeneral.throttleReversed) trim = -trim; int16_t v = anas[i]; - vv = ((int32_t)trim-TRIM_MIN)*(RESX-v)/(2*RESX); + int32_t vv = ((int32_t)trim-TRIM_MIN)*(RESX-v)/(2*RESX); + trim = vv; } else if (trimsCheckTimer > 0) { trim = 0; } - trims[i] = (vv==2*RESX) ? trim*2 : (int16_t)vv*2; // if throttle trim -> trim low end + trims[i] = trim*2; } } @@ -1747,12 +1748,16 @@ void perOut() if (tick10ms) { int32_t rate = (int32_t)DEL_MULT*2048*100; if(md->weight) rate /= abs(md->weight); - // TODO port optim er9x by Mike + act[i] = (diff>0) ? ((md->speedUp>0) ? act[i]+(rate)/((int16_t)100*md->speedUp) : (int32_t)v*DEL_MULT) : ((md->speedDown>0) ? act[i]-(rate)/((int16_t)100*md->speedDown) : (int32_t)v*DEL_MULT) ; } - if(((diff>0) && (v<(act[i]/DEL_MULT))) || ((diff<0) && (v>(act[i]/DEL_MULT)))) act[i]=(int32_t)v*DEL_MULT; //deal with overflow + { + int32_t tmp = act[i]/DEL_MULT ; + if(((diff>0) && (vtmp))) act[i]=(int32_t)v*DEL_MULT; //deal with overflow + } + v = act[i]/DEL_MULT; } } @@ -2563,6 +2568,20 @@ uint16_t stack_free() int main(void) { + // The WDT remains active after a WDT reset -- at maximum clock speed. So it's + // important to disable it before commencing with system initialisation (or + // we could put a bunch more wdt_reset()s in. But I don't like that approach + // during boot up.) +#if defined(PCBV4) + uint8_t mcusr_mirror = MCUSR; // save the WDT (etc) flags + MCUSR = 0; // must be zeroed before disabling the WDT +#elif defined(PCBSTD) + uint8_t mcusr_mirror = MCUCSR; + MCUCSR = 0; +#endif + + wdt_disable(); + board_init(); lcd_init(); @@ -2629,13 +2648,13 @@ int main(void) #endif #if defined(PCBV4) - if ((~MCUSR & (1 << WDRF)) && !g_eeGeneral.unexpectedShutdown) + if ((~mcusr_mirror & (1 << WDRF)) && !g_eeGeneral.unexpectedShutdown) #elif defined(PCBSTD) - if (~MCUCSR & (1 << WDRF)) + if (~mcusr_mirror & (1 << WDRF)) #else if (!g_eeGeneral.unexpectedShutdown) #endif - { + { #ifdef SPLASH #ifdef DSM2 // TODO rather use another Model Parameter diff --git a/src/open9x.h b/src/open9x.h index 92229362e..97617bae8 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -762,7 +762,7 @@ extern int16_t applyCurve(int16_t, int8_t); extern void applyExpos(int16_t *anas); extern uint16_t anaIn(uint8_t chan); -extern int16_t calibratedStick[7]; +extern int16_t calibratedStick[NUM_STICKS+NUM_POTS]; #define FLASH_DURATION 50 diff --git a/src/translations/cz.h b/src/translations/cz.h index 3ae14c523..ca9d915fa 100644 --- a/src/translations/cz.h +++ b/src/translations/cz.h @@ -76,7 +76,7 @@ #else #define TR_EXPLABEL_FP #endif -#define TR_EXPLABELS "V\200ha ""Expo ""K\206ivka" TR_EXPLABEL_FP "Sp\204na\201""Strana"" " // TODO remove all the trailing spaces +#define TR_EXPLABELS "V\200ha ""Expo ""K\206ivka" TR_EXPLABEL_FP "Sp\204na\201""Strana""\0" #define LEN_VMLTPX "\010" #define TR_VMLTPX "Se\201\204st ""N\200sobit ""Zam\203nit " @@ -166,7 +166,7 @@ #endif #define LEN_VARIOSRC "\006" -#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 " +#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0" #define LEN_GPSFORMAT "\004" #define TR_GPSFORMAT "HMS NMEA" @@ -176,7 +176,7 @@ #define TR_VTEMPLATES "Smazat Mixy\0\0""Z\200kl. 4kan\200l\0""T-Cut \0""V-Ocas \0""Elevon\\Delta\0""eCCPM \0""Heli Setup \0""Servo Test \0" #define LEN_VSWASHTYPE "\004" -#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 " +#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0" #define LEN_VKEYS "\005" #define TR_VKEYS " Menu"" Exit"" Dol\211""Nhoru""Vprvo""Vlevo" diff --git a/src/translations/de.h b/src/translations/de.h index 12e3a2004..0138a906d 100644 --- a/src/translations/de.h +++ b/src/translations/de.h @@ -71,7 +71,7 @@ #else #define TR_EXPLABEL_FP #endif -#define TR_EXPLABELS "Gew. ""Expo ""Kurve " TR_EXPLABEL_FP "Switch""Seite"" " // TODO remove all the trailing spaces +#define TR_EXPLABELS "Gew. ""Expo ""Kurve " TR_EXPLABEL_FP "Switch""Seite ""\0" #define LEN_VMLTPX "\010" #define TR_VMLTPX "Add ""Multiply""Replace " @@ -161,7 +161,7 @@ #endif #define LEN_VARIOSRC "\006" -#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 " +#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0" #define LEN_GPSFORMAT "\004" #define TR_GPSFORMAT "HMS NMEA" @@ -171,7 +171,7 @@ #define TR_VTEMPLATES "Clear Mixes\0\0""Simple 4-CH \0""T-Cut \0""V-Tail \0""Elevon\\Delta\0""eCCPM \0""Heli Setup \0""Servo Test \0" #define LEN_VSWASHTYPE "\004" -#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 " +#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0" #define LEN_VKEYS "\005" #define TR_VKEYS " Menu"" Exit""Unten"" Oben"" Re."" Li." diff --git a/src/translations/en.h b/src/translations/en.h index deaa0a18c..cb3b5717f 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -76,7 +76,7 @@ #else #define TR_EXPLABEL_FP #endif -#define TR_EXPLABELS "Weight""Expo ""Curve " TR_EXPLABEL_FP "Swtch ""Side "" " // TODO remove all the trailing spaces +#define TR_EXPLABELS "Weight""Expo ""Curve " TR_EXPLABEL_FP "Swtch ""Side\0 ""\0" #define LEN_VMLTPX "\010" #define TR_VMLTPX "Add ""Multiply""Replace " @@ -122,7 +122,7 @@ #define TR_SOMO #endif #ifdef DEBUG -#define TR_TEST "Test\0 " +#define TR_TEST "Test\0" #else #define TR_TEST #endif @@ -166,7 +166,7 @@ #endif #define LEN_VARIOSRC "\006" -#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 " +#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0" #define LEN_GPSFORMAT "\004" #define TR_GPSFORMAT "HMS NMEA" @@ -176,7 +176,7 @@ #define TR_VTEMPLATES "Clear Mixes\0\0""Simple 4-CH \0""T-Cut \0""V-Tail \0""Elevon\\Delta\0""eCCPM \0""Heli Setup \0""Servo Test \0" #define LEN_VSWASHTYPE "\004" -#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 " +#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0" #define LEN_VKEYS "\005" #define TR_VKEYS " Menu"" Exit"" Down"" Up""Right"" Left" diff --git a/src/translations/fr.h b/src/translations/fr.h index 9230739b5..a5b11a707 100644 --- a/src/translations/fr.h +++ b/src/translations/fr.h @@ -71,7 +71,7 @@ #else #define TR_EXPLABEL_FP #endif -#define TR_EXPLABELS "Ratio ""Expo ""Courbe" TR_EXPLABEL_FP "Inter ""Mode "" " +#define TR_EXPLABELS "Ratio ""Expo ""Courbe" TR_EXPLABEL_FP "Inter ""Mode ""\0" #define LEN_VMLTPX "\010" #define TR_VMLTPX "Ajoute ""Multipl.""Remplace" @@ -161,7 +161,7 @@ #endif #define LEN_VARIOSRC "\006" -#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 " +#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0" #define LEN_GPSFORMAT "\004" #define TR_GPSFORMAT "HMS NMEA" @@ -174,7 +174,7 @@ #define TR_VTEMPLATES "Suppr Mixages\0\0""4 Voies simple\0""Coupure Gaz \0""Empennage V \0""Elevon\\Delta \0""eCCPM \0""Conf. H\200lico \0""Servo Test \0" #define LEN_VSWASHTYPE "\004" -#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 " +#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0" #define LEN_VKEYS "\005" #define TR_VKEYS " Menu"" Exit"" Bas"" Haut""Droit""Gauch" diff --git a/src/translations/it.h b/src/translations/it.h index ac02cc8f6..f81ec0a80 100644 --- a/src/translations/it.h +++ b/src/translations/it.h @@ -76,7 +76,7 @@ #else #define TR_EXPLABEL_FP #endif -#define TR_EXPLABELS "Peso ""Expo ""Curva " TR_EXPLABEL_FP "Switch""Lato "" " // TODO remove all the trailing spaces +#define TR_EXPLABELS "Peso ""Expo ""Curva " TR_EXPLABEL_FP "Switch""Lato ""\0" #define LEN_VMLTPX "\010" #define TR_VMLTPX "Aggiungi""Moltipl.""Riscrivi" @@ -166,7 +166,7 @@ #endif #define LEN_VARIOSRC "\006" -#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 " +#define TR_VARIOSRC "BaroV1""BaroV2""A1\0 ""A2\0" #define LEN_GPSFORMAT "\004" #define TR_GPSFORMAT "HMS NMEA" @@ -176,7 +176,7 @@ #define TR_VTEMPLATES "Clear Mixes\0\0""Simple 4-CH \0""T-Cut \0""V-Tail \0""Elevon\\Delta\0""eCCPM \0""Heli Setup \0""Servo Test \0" #define LEN_VSWASHTYPE "\004" -#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 " +#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0" #define LEN_VKEYS "\005" #define TR_VKEYS " Men\200"" EXIT"" DN "" UP"" SX"" DX" diff --git a/src/translations/se.h b/src/translations/se.h index fefa46fd7..0280679ec 100644 --- a/src/translations/se.h +++ b/src/translations/se.h @@ -71,10 +71,10 @@ #else #define TR_EXPLABEL_FP #endif -#define TR_EXPLABELS "Vikt ""Expo ""Kurva " TR_EXPLABEL_FP "Brytar""N\201r "" " // TODO remove all the trailing spaces +#define TR_EXPLABELS "Vikt ""Expo ""Kurva " TR_EXPLABEL_FP "Brytar""N\201r ""\0" #define LEN_VMLTPX "\010" -#define TR_VMLTPX "Addera ""F\202rst\201rk""Ers\201tt " +#define TR_VMLTPX "Addera ""F\202rst\201rk""Ers\201tt\0" #define LEN_VMLTPX2 "\002" #define TR_VMLTPX2 "+=""*="":=" @@ -161,7 +161,7 @@ #endif #define LEN_VARIOSRC "\006" -#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2 " +#define TR_VARIOSRC "BaroV1""BaroV2""A1 ""A2\0" #define LEN_GPSFORMAT "\004" #define TR_GPSFORMAT "HMS NMEA" @@ -174,7 +174,7 @@ #define TR_VTEMPLATES "Nolla Mixar\0\0""Enkel 4kanal\0""Gasklippning\0""V-Stj\201rt \0""Deltavinge \0""eCCPM \0""Helikopter \0""Servotest \0" #define LEN_VSWASHTYPE "\004" -#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90 " +#define TR_VSWASHTYPE "--- ""120 ""120X""140 ""90\0" #define LEN_VKEYS "\005" #define TR_VKEYS " MENU"" EXIT"" Ned"" Upp""H\202ger""V\201nst"