diff --git a/config.h b/config.h --- a/config.h +++ b/config.h @@ -32,6 +32,9 @@ // Visual niceness #define hal_init() HAL_Init() +// Add bootloader option to top of idle screen menu +#define BOOTLOADER_SHORTCUT + #endif // vim:softtabstop=4 shiftwidth=4 expandtab diff --git a/display.c b/display.c --- a/display.c +++ b/display.c @@ -35,6 +35,7 @@ static uint8_t sw_right_last = 0; static uint8_t trigger_drawsetpoint = 1; static int16_t last_temp = 21245; static uint8_t goto_mode = MODE_HEAT; +static uint8_t reset_mode = RESET_RESET; @@ -73,10 +74,6 @@ void display_process(therm_settings_t* s ssd1306_drawlogo(); switch(goto_mode) { - case MODE_BOOTLOADER: - { - ssd1306_drawstring("-> loader ", 1, 40); - } break; case MODE_HEAT: { @@ -91,21 +88,19 @@ void display_process(therm_settings_t* s case MODE_RESET: { ssd1306_drawstring("-> reset ", 1, 40); + } break; + + #ifdef BOOTLOADER_SHORTCUT + case MODE_BOOTLOADER: + { + ssd1306_drawstring("-> dfu ", 1, 40); } + #endif } // Button handler if(SW_BTN_PRESSED) { switch(goto_mode) { - case MODE_BOOTLOADER: - { - ssd1306_clearscreen(); - ssd1306_drawstring("Bootloader Entered", 0, 0); - ssd1306_drawstring("Device won't boot", 2, 0); - ssd1306_drawstring("until reflashed!", 3, 0); - bootloader_enter(); // Resets into bootloader - status->state = STATE_IDLE; // Just in case - } break; case MODE_HEAT: status->state = STATE_PREHEAT; break; @@ -113,11 +108,19 @@ void display_process(therm_settings_t* s status->state = STATE_SETP; break; case MODE_RESET: - status->state = STATE_IDLE; - //flash_erase(); - NVIC_SystemReset(); + status->state = STATE_RESET; + reset_mode = RESET_RESET; break; - + #ifdef BOOTLOADER_SHORTCUT + case MODE_BOOTLOADER: + ssd1306_clearscreen(); + ssd1306_drawstring("Bootloader Entered", 0, 0); + ssd1306_drawstring("Device won't boot", 2, 0); + ssd1306_drawstring("until reflashed!", 3, 0); + bootloader_enter(); // Resets into bootloader + status->state = STATE_RESET; // Just in case + break; + #endif default: status->state = STATE_PREHEAT; } @@ -442,6 +445,70 @@ void display_process(therm_settings_t* s } break; + + // Reset state + case STATE_RESET: + { + // Write text to OLED + // [ therm :: reset ] + ssd1306_drawstring("therm :: reset ", 0, 40); + status->pid_enabled = 0; + + ssd1306_drawlogo(); + + switch(reset_mode) { + case RESET_RESET: + { + ssd1306_drawstring("-> reset ", 1, 40); + } break; + case RESET_BOOTLOADER: + { + ssd1306_drawstring("-> bootloader", 1, 40); + } break; + case RESET_EXIT: + { + ssd1306_drawstring("-> exit ", 1, 40); + } break; + } + + // Button handler + if(SW_BTN_PRESSED) { + switch(reset_mode) { + case RESET_BOOTLOADER: + { + ssd1306_clearscreen(); + ssd1306_drawstring("Bootloader Entered", 0, 0); + ssd1306_drawstring("Device won't boot", 2, 0); + ssd1306_drawstring("until reflashed!", 3, 0); + HAL_Delay(1000); + bootloader_enter(); // Resets into bootloader + status->state = STATE_RESET; // Just in case + } break; + case RESET_RESET: + { + status->state = STATE_RESET; + //flash_erase(); + NVIC_SystemReset(); + } break; + case RESET_EXIT: + { + status->state = STATE_IDLE; + } break; + } + } + else if(SW_DOWN_PRESSED && reset_mode < (RESET_SIZE-1)) { + reset_mode++; + } + else if(SW_UP_PRESSED && reset_mode > 0) { + reset_mode--; + } + + + // Event Handler + // N/A + + } break; + // Something is terribly wrong default: { diff --git a/states.h b/states.h --- a/states.h +++ b/states.h @@ -1,6 +1,8 @@ #ifndef STATES_H #define STATES_H +#include "config.h" + typedef struct { int32_t temp; uint8_t temp_frac; @@ -50,14 +52,24 @@ enum state { STATE_MAINTAIN, STATE_TC_ERROR, + STATE_RESET, }; enum GOTO_MODE { - MODE_HEAT = 0, + #ifdef BOOTLOADER_SHORTCUT + MODE_BOOTLOADER, + #endif + MODE_HEAT, MODE_SETUP, MODE_RESET, - MODE_BOOTLOADER, MODE_SIZE, }; +enum RESET_MODE { + RESET_RESET = 0, + RESET_BOOTLOADER, + RESET_EXIT, + RESET_SIZE, +}; + #endif diff --git a/system/syslib.c b/system/syslib.c --- a/system/syslib.c +++ b/system/syslib.c @@ -38,9 +38,9 @@ void bootloader_unset(void) void bootloader_enter(void) { FLASH_OBProgramInitTypeDef OBParam; - + HAL_FLASHEx_OBGetConfig(&OBParam); - + // FIXME TODO: CHECK THESE OPTION BYTES, he was using an F1 processor. What about the switch flag? OBParam.OptionType = OPTIONBYTE_USER;