diff --git a/src/Makefile b/src/Makefile index 15b45a466..879bd0c25 100644 --- a/src/Makefile +++ b/src/Makefile @@ -442,7 +442,7 @@ ifeq ($(PCB), X9D) SRC += sky9x/usb/device/massstorage/MSDDriver.c sky9x/usb/device/massstorage/MSDDStateMachine.c sky9x/usb/device/massstorage/MSDLun.c sky9x/usb/device/massstorage/MSDDriverDescriptors.c sky9x/usb/device/massstorage/SBCMethods.c SRC += sky9x/usb/common/core/USBEndpointDescriptor.c sky9x/usb/common/core/USBGenericRequest.c sky9x/usb/common/core/USBFeatureRequest.c sky9x/usb/common/core/USBInterfaceRequest.c sky9x/usb/common/core/USBGetDescriptorRequest.c sky9x/usb/common/core/USBSetAddressRequest.c sky9x/usb/common/core/USBSetConfigurationRequest.c sky9x/usb/common/core/USBConfigurationDescriptor.c sky9x/usb/common/core/USBGenericDescriptor.c SRC += sky9x/MEDSdcard.c - EEPROMSRC = eeprom_arm.cpp + EEPROMSRC = eeprom_arm.cpp eeprom_conversions.cpp PULSESSRC = pulses_arm.cpp CPPSRC += sky9x/audio.cpp haptic.cpp CPPSRC += sky9x/sound_driver.cpp sky9x/haptic_driver.cpp sky9x/sdcard_driver.cpp @@ -476,7 +476,7 @@ ifeq ($(PCB), SKY9X) SRC += sky9x/usb/device/massstorage/MSDDriver.c sky9x/usb/device/massstorage/MSDDStateMachine.c sky9x/usb/device/massstorage/MSDLun.c sky9x/usb/device/massstorage/MSDDriverDescriptors.c sky9x/usb/device/massstorage/SBCMethods.c SRC += sky9x/usb/common/core/USBEndpointDescriptor.c sky9x/usb/common/core/USBGenericRequest.c sky9x/usb/common/core/USBFeatureRequest.c sky9x/usb/common/core/USBInterfaceRequest.c sky9x/usb/common/core/USBGetDescriptorRequest.c sky9x/usb/common/core/USBSetAddressRequest.c sky9x/usb/common/core/USBSetConfigurationRequest.c sky9x/usb/common/core/USBConfigurationDescriptor.c sky9x/usb/common/core/USBGenericDescriptor.c SRC += sky9x/MEDSdcard.c - EEPROMSRC = eeprom_arm.cpp + EEPROMSRC = eeprom_arm.cpp eeprom_conversions.cpp PULSESSRC = pulses_arm.cpp CPPSRC += rtc.cpp sky9x/rtc_driver.cpp CPPSRC += sky9x/audio.cpp haptic.cpp diff --git a/src/eeprom_arm.cpp b/src/eeprom_arm.cpp index 8620d8d6e..db613bae1 100644 --- a/src/eeprom_arm.cpp +++ b/src/eeprom_arm.cpp @@ -70,7 +70,6 @@ void eeDirty(uint8_t msk) void handle_serial( void ) ; uint32_t get_current_block_number( uint32_t block_no, uint16_t *p_size, uint32_t *p_seq ) ; -void read32_eeprom_data( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate=0 ) ; void write32_eeprom_block( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate=0 ) ; void ee32_read_model_names( void ) ; void ee32LoadModelName(uint8_t id, char *buf, uint8_t len) ; @@ -86,14 +85,6 @@ void ee32LoadModelName(uint8_t id, char *buf, uint8_t len) ; uint8_t Current_general_block ; // 0 or 1 is active block uint8_t Other_general_block_blank ; -struct t_eeprom_header -{ - uint32_t sequence_no ; // sequence # to decide which block is most recent - uint16_t data_size ; // # bytes in data area - uint8_t flags ; - uint8_t hcsum ; -}; - struct t_eeprom_buffer { struct t_eeprom_header header ; @@ -273,7 +264,7 @@ uint32_t eeprom_read_status() } // Read eeprom data starting at random address -void read32_eeprom_data( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate ) +void read32_eeprom_data(uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate) { #ifdef SIMU assert(size); @@ -428,11 +419,9 @@ uint32_t get_current_block_number( uint32_t block_no, uint16_t *p_size, uint32_t return block_no ; } -bool ee32LoadGeneral() +bool eeLoadGeneral() { - uint16_t size ; - - size = File_system[0].size ; + uint16_t size = File_system[0].size; memset(&g_eeGeneral, 0, sizeof(EEGeneral)); @@ -444,11 +433,14 @@ bool ee32LoadGeneral() read32_eeprom_data( ( File_system[0].block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&g_eeGeneral, size) ; } - if (g_eeGeneral.version == EEPROM_VER) { - uint16_t sum = evalChkSum(); - if (g_eeGeneral.chkSum == sum) { - return true; - } + if (g_eeGeneral.version != EEPROM_VER) { + if (!eeConvert()) + return false; + } + + uint16_t sum = evalChkSum(); + if (g_eeGeneral.chkSum == sum) { + return true; } #ifdef SIMU @@ -540,7 +532,7 @@ void ee32LoadModelName(uint8_t id, char *buf, uint8_t len) void eeReadAll() { - if (!ee32LoadGeneral() ) + if (!eeLoadGeneral() ) { generalDefault(); diff --git a/src/eeprom_arm.h b/src/eeprom_arm.h index c6b308e31..c560a4305 100644 --- a/src/eeprom_arm.h +++ b/src/eeprom_arm.h @@ -44,8 +44,8 @@ extern uint8_t Eeprom32_process_state ; extern void eeprom_init( void ) ; extern void end_spi(); // TODO not public extern void ee32_process( void ) ; -extern bool ee32LoadGeneral( void ) ; - +extern bool eeLoadGeneral( void ) ; +extern bool eeConvert(); extern void eeWaitFinished(); extern void eeDeleteModel( uint8_t id ) ; @@ -57,12 +57,20 @@ extern void eeSwapModels(uint8_t id1, uint8_t id2); struct t_file_entry { - uint32_t block_no ; - uint32_t sequence_no ; - uint16_t size ; - uint8_t flags ; + uint32_t block_no ; + uint32_t sequence_no ; + uint16_t size ; + uint8_t flags ; } ; +struct t_eeprom_header +{ + uint32_t sequence_no ; // sequence # to decide which block is most recent + uint16_t data_size ; // # bytes in data area + uint8_t flags ; + uint8_t hcsum ; +}; + extern struct t_file_entry File_system[] ; extern char ModelNames[][sizeof(g_model.name)] ; // Allow for general @@ -72,6 +80,8 @@ extern ModelData g_model; extern uint8_t Spi_tx_buf[] ; extern uint8_t Spi_rx_buf[] ; +void read32_eeprom_data(uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate=0); + #if defined(SDCARD) const pm_char * eeBackupModel(uint8_t i_fileSrc); const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name); diff --git a/src/eeprom_conversions.cpp b/src/eeprom_conversions.cpp new file mode 100644 index 000000000..fbbdcc244 --- /dev/null +++ b/src/eeprom_conversions.cpp @@ -0,0 +1,197 @@ +#include "open9x.h" + +PACK(typedef struct { + uint8_t destCh; + uint16_t phases; + uint8_t curveMode:1; // O=curve, 1=differential + uint8_t noExpo:1; + int8_t carryTrim:3; + uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := + uint8_t spare:1; + int8_t weight; + int8_t swtch; + int8_t curveParam; + uint8_t mixWarn; // mixer warning + uint8_t delayUp; + uint8_t delayDown; + uint8_t speedUp; + uint8_t speedDown; + uint8_t srcRaw; + int8_t sOffset; + char name[LEN_EXPOMIX_NAME]; +}) MixData_v212; + +PACK(typedef struct { + int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw + uint16_t val; +}) TimerData_v212; + +PACK(typedef struct { + uint16_t remanent:1; + uint16_t value:15; +}) TimerDataExtra_v212; + +PACK(typedef struct { + FrSkyChannelData channels[2]; + FrSkyRSSIAlarm rssiAlarms[2]; + uint8_t usrProto; // Protocol in FrSky user data, 0=None, 1=FrSky hub, 2=WS HowHigh + uint8_t voltsSource; + uint8_t blades; // How many blades for RPMs, 0=2 blades, 1=3 blades + uint8_t currentSource; + FrSkyBarData bars[4]; + uint8_t lines[4*2*2]; + uint8_t varioSource; + uint8_t varioSpeedUpMin; // if increment in 0.2m/s = 3.0m/s max + uint8_t varioSpeedDownMin; + uint8_t spare[4]; +}) FrSkyData_v212; + +PACK(typedef struct { + char name[LEN_MODEL_NAME]; // must be first for eeLoadModelName + TimerData_v212 timers[MAX_TIMERS]; + uint8_t protocol:3; + uint8_t thrTrim:1; // Enable Throttle Trim + int8_t ppmNCH:4; + uint8_t trimInc:3; // Trim Increments + uint8_t disableThrottleWarning:1; + uint8_t pulsePol:1; + uint8_t extendedLimits:1; + uint8_t extendedTrims:1; + uint8_t spare1:1; + int8_t ppmDelay; + BeepANACenter beepANACenter; // 1<<0->A1.. 1<<6->A7 + MixData_v212 mixData[MAX_MIXERS]; + LimitData limitData[NUM_CHNOUT]; + ExpoData expoData[MAX_EXPOS]; + + CURVTYPE curves[MAX_CURVES]; + int8_t points[NUM_POINTS]; + + CustomSwData customSw[NUM_CSW]; + FuncSwData funcSw[NUM_FSW]; + SwashRingData swashR; + PhaseData phaseData[MAX_PHASES]; + + int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5ms increments + uint8_t thrTraceSrc; + uint8_t modelId; + + uint8_t switchWarningStates; + + FrSkyData_v212 frsky; + + TimerDataExtra_v212 timersXtra[MAX_TIMERS]; + +}) ModelData_v212; + +bool eeConvert() +{ + if (g_eeGeneral.version == 212) { + ALERT(STR_EEPROMWARN, PSTR("EEprom Data v212"), AU_BAD_EEPROM); + } + else { + return false; + } + + MESSAGE(STR_EEPROMWARN, PSTR("EEPROM Converting"), NULL, AU_EEPROM_FORMATTING); // TODO translations + + if (g_eeGeneral.version == 212) { + memmove(((uint8_t*)&g_eeGeneral)+2, ((uint8_t*)&g_eeGeneral)+1, 81); + g_eeGeneral.variant = 0; + g_eeGeneral.version = 213; + g_eeGeneral.disableSplashSkip = 0; + + for (uint8_t id=0; id= 256) { + ModelData_v212 oldModel; + memset(&oldModel, 0, sizeof(oldModel)); + if (size > sizeof(oldModel)) { + size = sizeof(oldModel) ; + } + read32_eeprom_data((File_system[id+1].block_no << 12) + sizeof(struct t_eeprom_header), (uint8_t *)&oldModel, size); + + memcpy(g_model.name, oldModel.name, 10); + for (uint8_t i=0; i<2; i++) { + g_model.timers[i].mode = oldModel.timers[i].mode; + g_model.timers[i].start = oldModel.timers[i].val; + g_model.timers[i].remanent = oldModel.timersXtra[i].remanent; + g_model.timers[i].value = oldModel.timersXtra[i].value; + } + g_model.protocol = oldModel.protocol; + g_model.thrTrim = oldModel.thrTrim; + g_model.ppmNCH = oldModel.ppmNCH; + g_model.trimInc = oldModel.trimInc; + g_model.disableThrottleWarning = oldModel.disableThrottleWarning; + g_model.pulsePol = oldModel.pulsePol; + g_model.extendedLimits = oldModel.extendedLimits; + g_model.extendedTrims = oldModel.extendedTrims; + g_model.ppmDelay = oldModel.ppmDelay; + g_model.beepANACenter = oldModel.beepANACenter; + for (uint8_t i=0; i<64; i++) { + g_model.mixData[i].destCh = oldModel.mixData[i].destCh; + g_model.mixData[i].phases = oldModel.mixData[i].phases; + g_model.mixData[i].curveMode = oldModel.mixData[i].curveMode; + g_model.mixData[i].noExpo = oldModel.mixData[i].noExpo; + g_model.mixData[i].carryTrim = oldModel.mixData[i].carryTrim; + g_model.mixData[i].mltpx = oldModel.mixData[i].mltpx; + g_model.mixData[i].weight = oldModel.mixData[i].weight; + g_model.mixData[i].swtch = oldModel.mixData[i].swtch; + g_model.mixData[i].curveParam = oldModel.mixData[i].curveParam; + g_model.mixData[i].mixWarn = oldModel.mixData[i].mixWarn; + g_model.mixData[i].delayUp = oldModel.mixData[i].delayUp; + g_model.mixData[i].delayDown = oldModel.mixData[i].delayDown; + g_model.mixData[i].speedUp = oldModel.mixData[i].speedUp; + g_model.mixData[i].speedDown = oldModel.mixData[i].speedDown; + g_model.mixData[i].srcRaw = oldModel.mixData[i].srcRaw; + g_model.mixData[i].offset = oldModel.mixData[i].sOffset; + memcpy(g_model.mixData[i].name, oldModel.mixData[i].name, 6); + } + for (uint8_t i=0; i<32; i++) { + g_model.limitData[i] = oldModel.limitData[i]; + } + for (uint8_t i=0; i<32; i++) { + g_model.expoData[i] = oldModel.expoData[i]; + } + for (uint8_t i=0; i<16; i++) { + g_model.curves[i] = oldModel.curves[i]; + } + for (uint16_t i=0; i<512; i++) { + g_model.points[i] = oldModel.points[i]; + } + for (uint8_t i=0; i<32; i++) { + g_model.customSw[i] = oldModel.customSw[i]; + } + for (uint8_t i=0; i<32; i++) { + g_model.funcSw[i] = oldModel.funcSw[i]; + } + g_model.swashR = oldModel.swashR; + for (uint8_t i=0; i<9; i++) { + g_model.phaseData[i].swtch = oldModel.phaseData[i].swtch; + g_model.phaseData[i].fadeIn = oldModel.phaseData[i].fadeIn; + g_model.phaseData[i].fadeOut = oldModel.phaseData[i].fadeOut; + memcpy(g_model.phaseData[i].name, oldModel.phaseData[i].name, 6); + memcpy(g_model.phaseData[i].trim, oldModel.phaseData[i].trim, 4*sizeof(int16_t)); + memcpy(g_model.phaseData[i].rotaryEncoders, oldModel.phaseData[i].rotaryEncoders, 1*sizeof(int16_t)); + } + g_model.ppmFrameLength = oldModel.ppmFrameLength; + g_model.thrTraceSrc = oldModel.thrTraceSrc; + g_model.modelId = oldModel.modelId; + g_model.switchWarningStates = oldModel.switchWarningStates; + g_model.frsky.usrProto = oldModel.frsky.usrProto; + g_model.frsky.voltsSource = oldModel.frsky.voltsSource; + g_model.frsky.blades = oldModel.frsky.blades; + g_model.frsky.currentSource = oldModel.frsky.currentSource; + g_model.frsky.varioSource = oldModel.frsky.varioSource; + g_model.frsky.varioSpeedUpMin = oldModel.frsky.varioSpeedUpMin; + g_model.frsky.varioSpeedDownMin = oldModel.frsky.varioSpeedDownMin; + for (uint8_t i=0; i<2; i++) { + g_model.frsky.channels[i] = oldModel.frsky.channels[i]; + g_model.frsky.rssiAlarms[i] = oldModel.frsky.rssiAlarms[i]; + } + } + } + } + + return true; +} diff --git a/src/myeeprom.h b/src/myeeprom.h index ad095c2b0..1c149d5cd 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -101,7 +101,8 @@ enum BeeperMode { uint8_t mAhWarn; \ uint16_t mAhUsed; \ uint32_t globalTimer; \ - int8_t temperatureCalib; + int8_t temperatureCalib; \ + uint8_t btBaudrate #else #define EXTRA_SKY9X_FIELDS #define EXTRA_GENERAL_FIELDS \ @@ -137,9 +138,9 @@ PACK(typedef struct t_EEGeneral { int8_t backlightMode; TrainerData trainer; uint8_t view; //index of subview in main scrren - uint8_t btBaudrate:3; // only used on SKY9X board + int8_t spare1:3; int8_t beeperMode:2; - uint8_t spare1:1; + uint8_t spare2:1; uint8_t disableMemoryWarning:1; uint8_t disableAlarmWarning:1; uint8_t stickMode:2; @@ -151,7 +152,7 @@ PACK(typedef struct t_EEGeneral { uint8_t preBeep:1; uint8_t flashBeep:1; uint8_t disableSplashScreen:1; - uint8_t spare2:1; + uint8_t spare3:1; int8_t hapticMode:2; // -2=quiet, -1=only alarms, 0=no keys, 1=all uint8_t filterInput; uint8_t lightAutoOff; @@ -293,7 +294,7 @@ PACK(typedef struct t_MixData { int8_t carryTrim:3; uint8_t mltpx:2; // multiplex method: 0 means +=, 1 means *=, 2 means := uint8_t spare:1; - int8_t weight; + int16_t weight; int8_t swtch; int8_t curveParam; uint8_t mixWarn; // mixer warning diff --git a/src/open9x.cpp b/src/open9x.cpp index 7b053912c..f4fb1fa04 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -829,12 +829,11 @@ int8_t getMovedSwitch() } #ifdef FLIGHT_PHASES -// TODO int8_t? uint8_t getFlightPhase() { for (uint8_t i=1; iswtch && getSwitch(phase->swtch, 0)) { // TODO phase->swtch needed? + if (phase->swtch && getSwitch(phase->swtch, 0)) { return i; } } @@ -1327,12 +1326,12 @@ void checkTrims() #endif // LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP uint8_t idx = CONVERT_MODE(1+k/2) - 1; + uint8_t phase; + int16_t before; + bool thro; #if defined(GVARS) #define TRIM_REUSED() trimGvar[idx] >= 0 - uint8_t phase; - int16_t before; // TODO declarations outside #ifdef - bool thro; if (TRIM_REUSED()) { #if defined(M64) phase = 0; @@ -1349,9 +1348,9 @@ void checkTrims() } #else #define TRIM_REUSED() 0 - uint8_t phase = getTrimFlightPhase(s_perout_flight_phase, idx); - int16_t before = getRawTrimValue(phase, idx); - bool thro = (idx==THR_STICK && g_model.thrTrim); + phase = getTrimFlightPhase(s_perout_flight_phase, idx); + before = getRawTrimValue(phase, idx); + thro = (idx==THR_STICK && g_model.thrTrim); #endif int8_t v = (s==0) ? min(32, abs(before)/4+1) : 1 << (s-1); // 1=>1 2=>2 3=>4 4=>8 if (thro) v = 4; // if throttle trim and trim trottle then step=4 @@ -2656,7 +2655,7 @@ inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms) s_cnt_10s += s_cnt_1s; s_sum_10s += s_sum_1s; - if ((tmr10ms_t)(tmr10ms - s_time_trace) >= 1000) {// 10sec + if ((tmr10ms_t)(tmr10ms - s_time_trace) >= 1000) { // 10s s_time_trace += 1000; val = s_sum_10s / s_cnt_10s; s_sum_10s = 0; @@ -2664,7 +2663,7 @@ inline void doMixerCalculations(tmr10ms_t tmr10ms, uint8_t tick10ms) s_traceBuf[s_traceWr++] = val; if (s_traceWr >= MAXTRACE) s_traceWr = 0; - if (s_traceCnt >= 0) s_traceCnt++; // TODO to be checked + if (s_traceCnt >= 0) s_traceCnt++; } #endif