diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ # SOURCES: list of sources in the user application -SOURCES = main.c usbd_conf.c usbd_cdc_if.c usb_device.c usbd_desc.c stm32f0xx_hal_msp.c stm32f0xx_it.c system_stm32f0xx.c gpio.c spi.c ssd1306.c stringhelpers.c display.c bootlib.c storage.c +SOURCES = main.c usbd_conf.c usbd_cdc_if.c usb_device.c usbd_desc.c stm32f0xx_hal_msp.c stm32f0xx_it.c system_stm32f0xx.c gpio.c spi.c ssd1306.c stringhelpers.c display.c bootlib.c storage.c flash.c # TARGET: name of the user application TARGET = main diff --git a/display.c b/display.c --- a/display.c +++ b/display.c @@ -5,6 +5,7 @@ #include "config.h" #include "states.h" #include "bootlib.h" +#include "flash.h" #include "gpio.h" uint8_t goto_mode = 2; @@ -85,13 +86,21 @@ void display_process(therm_settings_t* s case 0: { + ssd1306_DrawString("-> loader ", 1, 40); + } break; + + case 3: + { ssd1306_DrawString("-> reset ", 1, 40); - } break; + } } // Button handler if(SW_BTN_PRESSED) { switch(goto_mode) { + case 3: + status->state = STATE_IDLE; + flash_erase(set); case 2: status->state = STATE_PREHEAT_BREW; break; @@ -112,7 +121,7 @@ void display_process(therm_settings_t* s status->state = STATE_PREHEAT_BREW; } } - else if(SW_UP_PRESSED && goto_mode < 2) { + else if(SW_UP_PRESSED && goto_mode < 3) { goto_mode++; } else if(SW_DOWN_PRESSED && goto_mode > 0) { @@ -363,7 +372,7 @@ void display_process(therm_settings_t* s // Button handler if(SW_BTN_PRESSED) { - save_settings(&set); + flash_save(&set); status->state = STATE_IDLE; } else { diff --git a/flash.c b/flash.c new file mode 100644 --- /dev/null +++ b/flash.c @@ -0,0 +1,179 @@ +#include "stm32f0xx_hal.h" +#include "ssd1306.h" +#include "stm32f0xx_hal_flash.h" +#include "flash.h" + +void flash_init(therm_settings_t* tosave) +{ + uint16_t size = sizeof(therm_settings_t)-1; + uint32_t flash_adr = END_ADDR - size; + flash_adr -= 2; + uint8_t* flash_ptr = (uint8_t *)flash_adr; + + // Check if flash is blank + uint16_t i = 0; + uint16_t count = 0; + + char tempstr[10]; + itoa(flash_adr, tempstr, 10); + ssd1306_DrawString(tempstr, 1, 0); + + uint16_t test; + for(i=0;i