From c618e058dda71b220b4460fe2a5a8a6497769a5b Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Tue, 28 Jul 2020 21:54:20 +0200 Subject: [PATCH] Return switch and decoder values over SPI --- firmware/input.c | 16 +++++++++------- firmware/input.h | 1 + firmware/main.c | 21 +++++++++++++++------ firmware/oled-display/lcd.c | 2 +- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/firmware/input.c b/firmware/input.c index 01b0cdb..cc1bdef 100644 --- a/firmware/input.c +++ b/firmware/input.c @@ -16,11 +16,9 @@ void input_init() PORT_KEYPAD(PORT) |= PIN_KEYPAD_MASK; // Key pullups } -int8_t get_rotary_delta() +inline int8_t get_rotary_delta() { - int8_t temp = rotary_delta; - //rotary_delta = 0; - return temp; + return rotary_delta; } static inline void input_proc_rotary() @@ -83,11 +81,15 @@ void input_proc_switches() } } -uint8_t get_switch_event() +inline uint8_t get_switch_event() { - uint8_t temp = sw_event; + return sw_event; +} + +inline void input_clear_events() +{ + rotary_delta = 0; sw_event = 0; - return temp; } // Need to call timer_proc() before calling this function! diff --git a/firmware/input.h b/firmware/input.h index c450e55..39d91fd 100644 --- a/firmware/input.h +++ b/firmware/input.h @@ -14,6 +14,7 @@ void input_init(); void input_proc(); int8_t get_rotary_delta(); uint8_t get_switch_event(); +void input_clear_events(); extern uint8_t ctime; #endif // INPUT_H diff --git a/firmware/main.c b/firmware/main.c index 6f38fe3..39bfe24 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -18,23 +18,28 @@ void spi_init() DDRB |= (1 << 4); } +#define Y_MAX (DISPLAY_HEIGHT / 8 - 1) uint8_t spi_proc() { static uint8_t new_data = 0; static uint8_t x = 0; - static uint8_t y = DISPLAY_HEIGHT / 8 - 1; + static uint8_t y = Y_MAX; uint8_t spi_cs; + static uint8_t spdr_next = 0; spi_cs = !(PORT_SPI(PIN) & PIN_SPI_CS); if (spi_cs) { if (SPSR & (1 << SPIF)) { - //SPDR = get_rotary_delta(); - SPDR = get_switch_event(); - //SPDR = dbg; + SPDR = spdr_next; + switch (y) { + case Y_MAX: + spdr_next = 55; // TODO: Vbat + break; + } lcd_set_buffer(x, y, SPDR); if (y == 0) { - y = DISPLAY_HEIGHT / 8 - 1; + y = Y_MAX; x++; if (x == DISPLAY_WIDTH) { x = 0; @@ -48,9 +53,13 @@ uint8_t spi_proc() if (new_data) { lcd_display(); new_data = 0; + } else if ((y == Y_MAX - 3) && (x == 0)) { // If the last one was a I/O frame + input_clear_events(); } x = 0; - y = DISPLAY_HEIGHT / 8 - 1; + y = Y_MAX; + SPDR = get_switch_event(); + spdr_next = get_rotary_delta(); } return spi_cs; diff --git a/firmware/oled-display/lcd.c b/firmware/oled-display/lcd.c index e84c290..37ebf2d 100644 --- a/firmware/oled-display/lcd.c +++ b/firmware/oled-display/lcd.c @@ -174,7 +174,7 @@ void lcd_goto_xpix_y(uint8_t x, uint8_t y){ #endif lcd_command(commandSequence, sizeof(commandSequence)); } -void lcd_set_buffer(uint8_t x, uint8_t y, uint8_t value) { +inline void lcd_set_buffer(uint8_t x, uint8_t y, uint8_t value) { displayBuffer[y][x] = value; } void lcd_clrscr(void){