diff --git a/firmware/src/main.c b/firmware/src/main.c index fac89de..4b138ec 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -93,6 +93,7 @@ enum input {cw, ccw, click, hold}; static volatile enum state {home, ch1, ch2, ch3, setup} current_state = home; static volatile enum state home_state = ch1; +static volatile enum setup_state {contrast, backlight, back} setup_state = contrast; static volatile uint8_t enc = 0; @@ -329,6 +330,22 @@ static void lcd_home(void) { static void lcd_setup(void) { lcd_fill(0x00); + bool contrast_selected = false; + bool backlight_selected = false; + bool back_selected = false; + + switch (setup_state) { + case contrast: + contrast_selected = true; + break; + case backlight: + backlight_selected = true; + break; + default: // back + back_selected = true; + break; + } + for (uint8_t i = 0; i < 2; i++) { SPI_PORT &= ~(1 << LCD_CD); lcd_write(0x00); @@ -374,7 +391,8 @@ static void lcd_setup(void) { lcd_write_kerning(2, false); lcd_write_symbol_page(&sym_colon, i, false); lcd_write_kerning(11, false); - lcd_write_integer_page(123, 1, i, false); + lcd_write_integer_page(123, 1, i, contrast_selected); + lcd_write_kerning(2, contrast_selected); } for (uint8_t i = 0; i < 2; i++) { @@ -404,23 +422,26 @@ static void lcd_setup(void) { lcd_write_kerning(2, false); lcd_write_symbol_page(&sym_colon, i, false); lcd_write_kerning(7, false); - lcd_write_integer_page(123, 3, i, false); + lcd_write_integer_page(123, 3, i, backlight_selected); + lcd_write_kerning(2, backlight_selected); } for (uint8_t i = 0; i < 2; i++) { SPI_PORT &= ~(1 << LCD_CD); - lcd_write(0x03); + lcd_write(0x01); lcd_write(0x12); lcd_write(0xB6 + i); SPI_PORT |= (1 << LCD_CD); - lcd_write_symbol_page(&sym_b, i, false); - lcd_write_kerning(2, false); - lcd_write_symbol_page(&sym_a, i, false); - lcd_write_kerning(2, false); - lcd_write_symbol_page(&sym_c, i, false); - lcd_write_kerning(2, false); - lcd_write_symbol_page(&sym_k, i, false); + lcd_write_kerning(2, back_selected); + lcd_write_symbol_page(&sym_b, i, back_selected); + lcd_write_kerning(2, back_selected); + lcd_write_symbol_page(&sym_a, i, back_selected); + lcd_write_kerning(2, back_selected); + lcd_write_symbol_page(&sym_c, i, back_selected); + lcd_write_kerning(2, back_selected); + lcd_write_symbol_page(&sym_k, i, back_selected); + lcd_write_kerning(2, back_selected); } } @@ -437,6 +458,7 @@ static void change_state(enum state new_state) { case ch3: break; case setup: + setup_state = contrast; lcd_setup(); current_state = setup; break; @@ -468,10 +490,27 @@ static void update_home(enum input event) { static void update_setup(enum input event) { switch (event) { case cw: + setup_state++; + if (setup_state > back) + setup_state = contrast; + lcd_setup(); break; case ccw: + setup_state--; + if (setup_state > back) + setup_state = back; + lcd_setup(); break; case click: + switch (setup_state) { + case contrast: + break; + case backlight: + break; + case back: + change_state(home); + break; + } break; case hold: change_state(home);