Changeset - 618031ff9252
[Not reviewed]
cortex-f0
0 4 0
matthewreed - 9 years ago 2015-12-19 22:47:30

Added Reset menu to Idle screen
4 files changed with 103 insertions and 21 deletions:
0 comments (0 inline, 0 general)
config.h
Show inline comments
 
@@ -29,9 +29,12 @@
 

	
 
#define SSR_PIN GPIOA, GPIO_PIN_1
 

	
 
// 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 
display.c
Show inline comments
 
@@ -32,12 +32,13 @@ static uint8_t sw_right_last = 0;
 

	
 

	
 
// States
 
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;
 

	
 

	
 

	
 
// Display state machine
 
void display_process(therm_settings_t* set, therm_status_t* status)
 
{
 
@@ -70,16 +71,12 @@ void display_process(therm_settings_t* s
 
                ssd1306_drawstring(tempstr, 3, 72);
 
            }
 

	
 
            ssd1306_drawlogo();
 

	
 
            switch(goto_mode) {
 
                case MODE_BOOTLOADER:
 
                {
 
                    ssd1306_drawstring("-> loader   ", 1, 40);
 
                } break;
 

	
 
                case MODE_HEAT:
 
                {
 
                    ssd1306_drawstring("-> heat     ", 1, 40);
 
                } break;
 

	
 
@@ -88,39 +85,45 @@ void display_process(therm_settings_t* s
 
                    ssd1306_drawstring("-> setup    ", 1, 40);
 
                } break;
 

	
 
                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;
 
                    case MODE_SETUP:
 
                        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;
 
                }
 
            }
 
            else if(SW_DOWN_PRESSED && goto_mode < (MODE_SIZE - 1)) {
 
                goto_mode++;
 
@@ -439,12 +442,76 @@ void display_process(therm_settings_t* s
 
            // Event Handler
 
            // Maybe handle if TC is plugged in
 
            // N/A
 
 
 
        } 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:
 
        {
 
            status->state = STATE_IDLE;
 
            status->pid_enabled = 0;
 

	
states.h
Show inline comments
 
#ifndef STATES_H
 
#define STATES_H
 

	
 
#include "config.h"
 

	
 
typedef struct {
 
    int32_t temp;
 
    uint8_t temp_frac;
 
    uint8_t state_resume;
 
    uint8_t state;
 
    int32_t setpoint;
 
@@ -47,17 +49,27 @@ enum state {
 
    STATE_SETTEMPOFFSET,
 

	
 
    STATE_PREHEAT,
 
    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
system/syslib.c
Show inline comments
 
@@ -35,15 +35,15 @@ void bootloader_unset(void)
 

	
 
// See thread: https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy.st.com%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fJump%20to%20USB%20DFU%20Bootloader%20in%20startup%20code%20on%20STM32F042&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=185
 
// Set option bytes to enter bootloader upon reset
 
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;
 
    /*Reset NBOOT0 and BOOT_SEL,  see: RM 2.5 Boot configuration*/
 
    OBParam.USERConfig = 0x77; //Sorry for magic number :)
 
  
0 comments (0 inline, 0 general)