X-Git-Url: https://git.friedersdorff.com/?a=blobdiff_plain;ds=sidebyside;f=mykey.c;h=dcb0852ec43d0a6739986268a683c6767bb3c83b;hb=1de02c1f15ca1c04aae0bde818b01ea40cf32120;hp=93f753f01f1f07e136a73520aa2daad69f53b270;hpb=3b31337cd8a5fe8b02924f2056ad2648a028c563;p=max%2Ftmk_keyboard.git diff --git a/mykey.c b/mykey.c index 93f753f0..dcb0852e 100644 --- a/mykey.c +++ b/mykey.c @@ -24,14 +24,17 @@ * THE SOFTWARE. */ +#include #include #include #include #include -#include "usb_keyboard_debug.h" + +#include "usb_device.h" #include "print.h" #include "matrix.h" #include "keymap.h" +#include "jump_bootloader.h" #define LED_CONFIG (DDRD |= (1<<6)) #define LED_ON (PORTD &= ~(1<<6)) @@ -45,7 +48,8 @@ uint16_t idle_count=0; int main(void) { - uint8_t modified = 0; + bool modified = false; + bool has_ghost = false; uint8_t key_index = 0; // set for 16 MHz clock @@ -75,57 +79,53 @@ int main(void) print("keyboard firmware 0.1 for t.m.k.\n"); while (1) { + int layer = 0; uint8_t row, col, code; - modified = 0; - matrix_scan(); + layer = get_layer(); - keyboard_modifier_keys = 0; - for (int i = 0; i < 6; i++) - keyboard_keys[i] = KB_NO; - key_index = 0; + modified = matrix_is_modified(); + has_ghost = matrix_has_ghost(); - for (row = 0; row < MATRIX_ROWS; row++) { - if (matrix[row] != prev_matrix[row]) { - modified = 1; - } + // doesnt send keys during ghost occurs + if (modified && !has_ghost) { + key_index = 0; + keyboard_modifier_keys = 0; + for (int i = 0; i < 6; i++) keyboard_keys[i] = KB_NO; - for (col = 0; col < MATRIX_COLS; col++) { - if (matrix[row] & 1< 6) { - //Rollover - } - + // run bootloader when 4 left modifier keys down + if (keyboard_modifier_keys == (MOD_LCTRL | MOD_LSHIFT | MOD_LALT | MOD_LGUI)) { + print("jump to bootloader...\n"); + _delay_ms(1000); + jump_bootloader(); + } - // if any keypresses were detected, reset the idle counter - if (modified) { - print(" 01234567\n"); - for (row = 0; row < MATRIX_ROWS; row++) { - phex(row); print(": "); pbin_reverse(matrix[row]); print("\n"); + if (key_index > 6) { + //Rollover } - print("keys: "); - for (int i = 0; i < 6; i++) { phex(keyboard_keys[i]); print(" "); } - print("\n"); - print("mod: "); phex(keyboard_modifier_keys); print("\n"); + usb_keyboard_send(); + // variables shared with interrupt routines must be // accessed carefully so the interrupt routine doesn't // try to use the variable in the middle of our access @@ -134,6 +134,23 @@ int main(void) sei(); } + // print matrix state for debug + if (modified) { + print("\nr/c 01234567\n"); + for (row = 0; row < MATRIX_ROWS; row++) { + phex(row); print(": "); + pbin_reverse(matrix[row]); + if (matrix_has_ghost_in_row(row)) { + print(" 61 * 8) { idle_count = 0; - //print("Timer Event :)\n"); - //usb_keyboard_press(KEY_SPACE, 0); + print("."); } }