diff --git a/src/drivers.cpp b/src/drivers.cpp index d129fff92..b6c561af9 100644 --- a/src/drivers.cpp +++ b/src/drivers.cpp @@ -27,7 +27,7 @@ uint16_t eeprom_pointer; const char* eeprom_buffer_data; -volatile size_t eeprom_buffer_size = 0; +volatile int8_t eeprom_buffer_size = 0; inline void eeprom_write_byte() { @@ -72,7 +72,9 @@ void eeWriteBlockCmp(const void *i_pointer_ram, void *i_pointer_eeprom, size_t s EECR |= (1< 0); + if (s_sync_write) { + while (eeprom_buffer_size > 0) wdt_reset(); + } } #else @@ -235,7 +237,7 @@ bool keyState(EnumKeys enuk) #if defined (PCBV4) switch(enuk){ case SW_ElevDR : return PINC & (1< 0); + while (eeprom_buffer_size > 0) wdt_reset(); + s_sync_write = true; - while (theFile.m_write_len && !s_write_err) - theFile.nextWriteStep(); - while (theFile.isWriting() && !s_write_err) - theFile.nextRlcWriteStep(); + while (m_write_len && !s_write_err) + nextWriteStep(); + while (isWriting() && !s_write_err) + nextRlcWriteStep(); s_sync_write = false; } diff --git a/src/file.h b/src/file.h index f7bcf837a..0128fa695 100644 --- a/src/file.h +++ b/src/file.h @@ -48,7 +48,7 @@ void EeFsFormat(); uint16_t EeFsGetFree(); #ifdef EEPROM_ASYNC_WRITE -extern volatile size_t eeprom_buffer_size; +extern volatile int8_t eeprom_buffer_size; #endif class EFile diff --git a/src/general_menus.cpp b/src/general_menus.cpp index bd6844f7d..b4f839605 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -346,7 +346,7 @@ void menuProcTime(uint8_t event) void menuProcTrainer(uint8_t event) { - MENU("TRAINER", menuTabDiag, e_Trainer, 7, {0, 2, 2, 2, 2/*, 0, 0*/}); + MENU("TRAINER", menuTabDiag, e_Trainer, 7, {0, 2, 2, 2, 2, 0/*, 0*/}); int8_t sub = m_posVert; uint8_t subSub = m_posHorz; diff --git a/src/gruvin9x.cpp b/src/gruvin9x.cpp index 95c1defdb..c1a3b9974 100644 --- a/src/gruvin9x.cpp +++ b/src/gruvin9x.cpp @@ -632,8 +632,7 @@ void checkQuickSelect() lcd_clear(); lcd_putsAtt(64-7*FW,0*FH,PSTR("LOADING"),DBLSIZE); - for(uint8_t i=0;i4000 && val < 16000) // G: Priorotise reset pulse. (Needed when less than 8 incoming pulses) + if (val>4000 && val < 16000) // G: Prioritize reset pulse. (Needed when less than 8 incoming pulses) ppmInState = 1; // triggered else { @@ -1941,13 +1952,12 @@ ISR(TIMER3_CAPT_vect, ISR_NOBLOCK) //capture ppm in 16MHz / 8 = 2MHz lastCapt = capture; - cli(); + cli(); // disable other interrupts for stack pops before this function's RETI #if defined (PCBV3) TIMSK3 |= (1< inline int8_t sgn(t a){ return a>0 ? 1 : (a < 0 ? -1 : 0); } /// eeCheck ins EEPROM zurueckgeschrieben. void eeWriteBlockCmp(const void *i_pointer_ram, void *i_pointer_eeprom, size_t size); void eeDirty(uint8_t msk); +#ifdef EEPROM_ASYNC_WRITE +inline void eeFlush() { theFile.flush(); } +#endif void eeCheck(bool immediately=false); //void eeWriteGeneral(); void eeReadAll(); @@ -684,7 +687,7 @@ inline void _beep(uint8_t b) { } extern uint8_t toneFreq; -#if defined (PCBV3) +#if defined (PCBV3) && defined(BEEPSPKR) inline void _beepSpkr(uint8_t d, uint8_t f) { g_beepCnt=d; @@ -750,6 +753,5 @@ extern FATFS FATFS_Obj; // pers.cpp::resetTelemetry() extern FIL g_oLogFile; // pers.cpp::resetTelemetry() #endif - #endif // gruvin9x_h /*eof*/ diff --git a/src/model_menus.cpp b/src/model_menus.cpp index dc131c113..4873685da 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -96,6 +96,11 @@ void menuProcModelSelect(uint8_t event) // TODO lignes sur tout du long int8_t subOld = m_posVert; if (!check_submenu_simple(event, MAX_MODELS-1)) return; +#ifdef EEPROM_ASYNC_WRITE + // flush eeprom write so that it's possible to load model names + eeFlush(); +#endif + lcd_puts_P( 9*FW, 0, PSTR("free")); lcd_outdezAtt( 17*FW, 0, EeFsGetFree(),0); @@ -104,8 +109,6 @@ void menuProcModelSelect(uint8_t event) // TODO lignes sur tout du long int8_t sub = m_posVert; static uint8_t sel_editMode; - eeCheck(true); // force writing of current model data before this is changed - switch(event) { //case EVT_KEY_FIRST(KEY_MENU): @@ -114,6 +117,7 @@ void menuProcModelSelect(uint8_t event) // TODO lignes sur tout du long sel_editMode = false; beepKey(); killEvents(event); + eeCheck(true); // force writing of current model data before this is changed eeLoadModel(g_eeGeneral.currModel = m_posVert); STORE_GENERALVARS; break; @@ -125,6 +129,7 @@ void menuProcModelSelect(uint8_t event) // TODO lignes sur tout du long { killEvents(event); g_eeGeneral.currModel = m_posVert; + eeCheck(true); // force writing of current model data before this is changed eeLoadModel(g_eeGeneral.currModel); STORE_GENERALVARS; beepWarn1(); @@ -140,6 +145,7 @@ void menuProcModelSelect(uint8_t event) // TODO lignes sur tout du long case EVT_KEY_LONG(KEY_MENU): if(sel_editMode){ // message(PSTR("Duplicating model")); + eeCheck(true); // force writing of current model data before this is changed if (eeDuplicateModel(sub)) { beepKey(); sel_editMode = false; @@ -152,10 +158,11 @@ void menuProcModelSelect(uint8_t event) // TODO lignes sur tout du long case EVT_ENTRY: sel_editMode = false; - m_posVert = g_eeGeneral.currModel; + m_posVert = sub = g_eeGeneral.currModel; break; } if(sel_editMode && subOld!=sub){ + eeCheck(true); // force writing of current model data before this is changed #ifdef EEPROM_ASYNC_WRITE s_sync_write = true; #endif @@ -269,9 +276,14 @@ void menuProcModel(uint8_t _event) uint8_t event = (s_warning ? 0 : _event); if (s_confirmation) { - EFile::rm(FILE_MODEL(g_eeGeneral.currModel)); // delete file + uint8_t i = g_eeGeneral.currModel; + +#ifdef EEPROM_ASYNC_WRITE + // flush eeprom write + eeFlush(); +#endif + EFile::rm(FILE_MODEL(i)); // delete file - uint8_t i = g_eeGeneral.currModel; // loop to find next available model while (!EFile::exists(FILE_MODEL(i))) { i--; if (i>MAX_MODELS) i=MAX_MODELS-1; @@ -285,6 +297,7 @@ void menuProcModel(uint8_t _event) eeLoadModel(i); // load default values s_confirmation = 0; chainMenu(menuProcModelSelect); + return; } MENU("SETUP", menuTabModel, e_Model, 11, {0,sizeof(g_model.name)-1,3,3,0,0,0,1,6,3/*, 0*/}); @@ -1644,7 +1657,7 @@ void menuProcTelemetry(uint8_t event) case EVT_KEY_BREAK(KEY_UP): case EVT_KEY_BREAK(KEY_LEFT): case EVT_KEY_BREAK(KEY_RIGHT): - if(s_editMode) + if(s_editMode) // only fr-sky alarm fields have an edit mode FRSKY_setModelAlarms(); // update Fr-Sky module when edit mode exited } @@ -1732,7 +1745,7 @@ void menuProcTelemetry(uint8_t event) #ifdef TEMPLATES void menuProcTemplates(uint8_t event) { - SIMPLE_MENU("TEMPLATES", menuTabModel, e_Templates, NUM_TEMPLATES+2); + SIMPLE_MENU("TEMPLATES", menuTabModel, e_Templates, 1+NUM_TEMPLATES+1); uint8_t y = 0; uint8_t k = 0; @@ -1744,10 +1757,10 @@ void menuProcTemplates(uint8_t event) killEvents(event); //apply mixes or delete s_noHi = NO_HI_LEN; - if(sub==NUM_TEMPLATES+1) - clearMixes(); - else if((sub>=0) && (sub<(int8_t)NUM_TEMPLATES)) + if (sub>=0 && sub<(int8_t)NUM_TEMPLATES) applyTemplate(sub); + if (sub==NUM_TEMPLATES) + clearMixes(); beepWarn1(); break; } diff --git a/src/pers.cpp b/src/pers.cpp index 8f1601074..29a39a588 100644 --- a/src/pers.cpp +++ b/src/pers.cpp @@ -312,7 +312,6 @@ bool eeDuplicateModel(uint8_t id) while((len=theFile2.read(buf, 15))) { theFile.write(buf, len); - wdt_reset(); // TODO I don't know what it is if (errno() != 0) { return false; } @@ -373,7 +372,7 @@ void eeCheck(bool immediately) { #ifdef EEPROM_ASYNC_WRITE if (immediately) { - theFile.flush(); + eeFlush(); } if (s_eeDirtyMsk & EE_GENERAL) { s_eeDirtyMsk -= EE_GENERAL; diff --git a/src/simpgmspace.cpp b/src/simpgmspace.cpp index 624d414f7..b5ab2bae5 100644 --- a/src/simpgmspace.cpp +++ b/src/simpgmspace.cpp @@ -30,7 +30,7 @@ volatile unsigned char pinb=0, pinc=0xff, pind, pine=0xff, ping=0xff; unsigned char portb, dummyport; const char *eepromFile = "eeprom.bin"; -volatile size_t eeprom_buffer_size = 0; +volatile int8_t eeprom_buffer_size = 0; uint8_t eeprom[EESIZE]; diff --git a/src/stamp-gruvin9x.h b/src/stamp-gruvin9x.h deleted file mode 100644 index 054554317..000000000 --- a/src/stamp-gruvin9x.h +++ /dev/null @@ -1,6 +0,0 @@ -//Automatically generated file (Makefile) - do not edit -#define DATE_STR "2011-09-14" -#define TIME_STR "11:11:34" -#define TAG_VERS 2-bsongis -#define SVN_VERS "open9x-r3" -#define BUILD_NUM 841 diff --git a/src/templates.cpp b/src/templates.cpp index a53ae184e..68c6c166f 100644 --- a/src/templates.cpp +++ b/src/templates.cpp @@ -65,6 +65,7 @@ MixData* setDest(uint8_t dch) void clearMixes() { memset(g_model.mixData,0,sizeof(g_model.mixData)); //clear all mixes + STORE_MODELVARS; } void clearCurves()