Skip to content

Commit

Permalink
More fixes for boot issues
Browse files Browse the repository at this point in the history
flashProfile wasn't being controlled properly under all circumstances, I
hope now it is.
  • Loading branch information
David authored and David committed Dec 31, 2023
1 parent a3a5597 commit 18b4558
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
1 change: 0 additions & 1 deletion Core/Inc/iron.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,5 @@ bool getIronShakeFlag(void);
void clearIronShakeFlag(void);
uint32_t getIronLastShakeTime(void);
wakeSrc_t getIronWakeSource(void);
uint16_t getUserSetTemperature(void);

#endif /* IRON_H_ */
7 changes: 3 additions & 4 deletions Core/Inc/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,8 @@ bool isSystemSettingsChanged(void);
bool isCurrentProfileChanged(void);
/** Checks if the current addons settings in RAM were changed */
bool isAddonSettingsChanged(void);

/** Restores settings from the backup ram used in the last session (eg last temp/tip).
* Call this after all the modules */
void restoreLastSessionSettings(void);
/** Copies las Profile / Temperature / Tip data between flash and ram when battery option is changed*/
void copy_bkp_data(uint8_t mode);
/** Set initial values after setup screen */
void flashTempSettingsInitialSetup(void);
#endif /* SETTINGS_H_ */
35 changes: 27 additions & 8 deletions Core/Src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ static void storeSettings(uint8_t mode){
resetSystemSettings(&flashBufferSettings->settings); // Load defaults
if(mode == reset_All){
flashBufferSettings->settings.version = 0xFF; // To trigger setup screen
flashTempSettingsErase();
}
}
else if(mode & save_Settings){ // Save current settings
Expand Down Expand Up @@ -578,8 +577,9 @@ void restoreSettings(void) {
loadProfile(systemSettings.currentProfile); // loadProfile will restore lastTemp and lastTip from the correct source (Flash or backup SRAM).
}
}
if(!setup && reset) // If not in setup mode and we have bad data
if(!setup && reset){ // If not in setup mode and we have bad data
saveSettings(perform_scanFix, do_reboot); // Store settings with no arguments, this will check and reset any bad setting
}
} // Otherwise, everything be resetted when exiting the boot screen

void loadSettingsFromBackupRam(void) {
Expand Down Expand Up @@ -655,6 +655,22 @@ static uint32_t ChecksumBackupRam(){
return checksum;
}

void flashTempSettingsInitialSetup(void){ // To be called after initial setup screen
flashTempSettingsErase();
for(uint8_t i=0;i<NUM_PROFILES;i++)
flashTip[i]= 0;

flashTemp = defaultProfileSettings.defaultTemperature;
flashProfile=profile_T12;
flashTempWrite();
flashTipWrite();
flashProfileWrite();

systemSettings.currentProfile = profile_T12; // Just in case
systemSettings.currentTip = 0;
setUserTemperature( defaultProfileSettings.defaultTemperature);
}

void flashTempSettingsInit(void) //call it only once during init
{
bool setDefault=0;
Expand Down Expand Up @@ -715,10 +731,9 @@ void flashTempSettingsInit(void) //call it only once during init
}
}

if(setDefault){ // Profile not initialized yet, so we have to wait
flashTempSettingsErase(); // This will be detected later in loadProfile
systemSettings.currentProfile = profile_T12;
}
if(setDefault)
flashTempSettingsInitialSetup();

else{
systemSettings.currentProfile = flashProfile;
if(temp_settings.temperature[flashTempIndex] != UINT16_MAX)
Expand Down Expand Up @@ -800,7 +815,8 @@ void flashTempSettingsErase(void){
flashTempIndex = 0; // Reset index
flashProfileIndex = 0;
for(uint8_t i=0; i<NUM_PROFILES;i++)
flashTipIndex[i] = 0;
flashTipIndex[i] = 0;

flashTemp=0xFFFF;
flashProfile=0xFF;
}
Expand Down Expand Up @@ -867,6 +883,7 @@ static void resetSystemSettings(settings_t * data) {
uint32_t _irq = __get_PRIMASK();
__disable_irq();
*data = defaultSystemSettings;
flashTempSettingsInitialSetup();
__set_PRIMASK(_irq);
}

Expand Down Expand Up @@ -966,7 +983,9 @@ static void resetProfileSettings(profile_settings_t * data, uint8_t profile){
uint8_t loadProfile(uint8_t profile){
while(ADC_Status!=ADC_Idle);

if(profile>profile_C210) // Sanity check
if(profile==0xFF) // Erased flash, load T12
profile=profile_T12;
else if(profile>profile_C210) // Sanity check
Error_Handler();

uint32_t _irq = __get_PRIMASK();
Expand Down
1 change: 1 addition & 0 deletions Drivers/graphics/gui/screens/boot_screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ void boot_screen_onExit(screen_t *scr){
if(systemSettings.setupMode){
saveSettings(save_Settings, no_reboot); // Save now we have all heap free. All other flash settings (Profile, tips, addons) will be checked and set to default if wrong
loadProfile(profile); // Now flash is initialized and we can properly load a profile
updateTempData(force_update);
systemSettings.setupMode=0; // Disable setup mode
}
setSafeMode(disable); // Disable safe mode before exit
Expand Down

0 comments on commit 18b4558

Please sign in to comment.