From 2b070b173a03ced07c584a42b444017af30b2007 Mon Sep 17 00:00:00 2001 From: Markus Koch Date: Fri, 1 Nov 2019 19:52:10 +0100 Subject: [PATCH] keyboard: avr: implement ioc protocol --- keyboard/avr/main.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/keyboard/avr/main.c b/keyboard/avr/main.c index 26d2181..7a39b3d 100644 --- a/keyboard/avr/main.c +++ b/keyboard/avr/main.c @@ -196,23 +196,35 @@ uint8_t matrix_state_last_vector[9] = {0xFF, 0xFF, 0xFF, 0xFF, uint8_t fn_active = 0; +void uart_putc(char c) +{ + while (!(UCSRA & (1 << UDRE))); + UDR = c; +} + void process_key_event(uint8_t col, uint8_t row, uint8_t state) { char c; uint8_t keycode; + int event = 0; keycode = keycode_translation_matrix[fn_active][col][row]; if (keycode == SKEY_FN) { fn_active = state; #ifdef KEYCODE_FN - while (!(UCSRA & (1 << UDRE))); - UDR = KEYCODE_FN | (state << 7); + c = KEYCODE_FN | (state << 7); + event = 1; #endif } else { c = keycode | (state << 7); - while (!(UCSRA & (1 << UDRE))); - UDR = c; + event = 1; + } + + if (event) { + uart_putc(0xFF); + uart_putc(0x55); + uart_putc(c); } }