// vim: ts=4 sw=4 sts=4 /* ---------------------------------------------------------------------------- * main() * ---------------------------------------------------------------------------- * Copyright (c) 2012 Ben Blazak * Released under The MIT License (MIT) (see "license.md") * Project located at * ------------------------------------------------------------------------- */ #include #include #include #include "./lib-other/pjrc/usb_keyboard/usb_keyboard.h" #include "./lib/key-functions/public.h" #include "./keyboard/controller.h" #include "./keyboard/layout.h" #include "./keyboard/matrix.h" #include "./main.h" // ---------------------------------------------------------------------------- #define MAX_ACTIVE_LAYERS 20 // ---------------------------------------------------------------------------- static bool _main_kb_is_pressed[KB_ROWS][KB_COLUMNS]; bool (*main_kb_is_pressed)[KB_ROWS][KB_COLUMNS] = &_main_kb_is_pressed; static bool _main_kb_was_pressed[KB_ROWS][KB_COLUMNS]; bool (*main_kb_was_pressed)[KB_ROWS][KB_COLUMNS] = &_main_kb_was_pressed; uint8_t main_layers_pressed[KB_ROWS][KB_COLUMNS]; uint8_t main_loop_row; uint8_t main_loop_col; uint8_t main_arg_layer; uint8_t main_arg_layer_offset; uint8_t main_arg_row; uint8_t main_arg_col; bool main_arg_is_pressed; bool main_arg_was_pressed; // ---------------------------------------------------------------------------- /* * main() */ int main(void) { kb_init(); // does controller initialization too kb_led_state_power_on(); usb_init(); while (!usb_configured()); kb_led_delay_usb_init(); // give the OS time to load drivers, etc. kb_led_state_ready(); for (;;) { // swap `main_kb_is_pressed` and `main_kb_was_pressed`, then update bool (*temp)[KB_ROWS][KB_COLUMNS] = main_kb_was_pressed; main_kb_was_pressed = main_kb_is_pressed; main_kb_is_pressed = temp; kb_update_matrix(*main_kb_is_pressed); // this loop is responsible to // - "execute" keys when they change state // - keep track of which layers the keys were on when they were pressed // (so they can be released using the function from that layer) // // note // - everything else is the key function's responsibility // - see the keyboard layout file ("keyboard/ergodox/layout/*.c") for // which key is assigned which function (per layer) // - see "lib/key-functions/public/*.c" for the function definitions #define row main_loop_row #define col main_loop_col #define layer main_arg_layer #define is_pressed main_arg_is_pressed #define was_pressed main_arg_was_pressed for (row=0; row