Return switch and decoder values over SPI

This commit is contained in:
Markus Koch 2020-07-28 21:54:20 +02:00
parent 09bc6979e9
commit c618e058dd
4 changed files with 26 additions and 14 deletions

View File

@ -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!

View File

@ -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

View File

@ -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;

View File

@ -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){