diff --git a/firmware/keyboard.h b/firmware/keyboard.h index e43d315..3521cd6 100644 --- a/firmware/keyboard.h +++ b/firmware/keyboard.h @@ -25,22 +25,18 @@ // ---------------------------------------------------------------------------- -#if MAKE__KEYBOARD == 'ergodox' - - #define KB__ROWS 6 - #define KB__COLUMNS 14 - -#else - - #error "Keyboard dimensions must be defined" - +#ifndef OPT__KB__ROWS + #error "OPT__KB__ROWS not defined" +#endif +#ifndef OPT__KB__COLUMNS + #error "OPT__KB__COLUMNS not defined" #endif // ---------------------------------------------------------------------------- // controller uint8_t kb__init (void); -uint8_t kb__update_matrix (bool matrix[KB__ROWS][KB__COLUMNS]); +uint8_t kb__update_matrix (bool matrix[OPT__KB__ROWS][OPT__KB__COLUMNS]); // LED void kb__led__on (uint8_t led); @@ -59,8 +55,7 @@ void kb__led__delay__usb_init (void); void kb__led__logical_on (char led); void kb__led__logical_off (char led); // ------- -void kb__layout__exec_key_pointer (bool pressed, void * pointer); -void kb__layout__exec_key_location (bool pressed, uint8_t row, uint8_t column); +void kb__layout__exec_key (bool pressed, uint8_t row, uint8_t column); // ---------------------------------------------------------------------------- @@ -78,13 +73,13 @@ void kb__layout__exec_key_location (bool pressed, uint8_t row, uint8_t column); // macros --------------------------------------------------------------------- // ---------------------------------------------------------------------------- -// === KB__ROWS === -/** macros/KB__ROWS/description +// === OPT__KB__ROWS === +/** macros/OPT__KB__ROWS/description * The number of rows in a given keyboard's matrix */ -// === KB__COLUMNS === -/** macros/KB__COLUMNS/description +// === OPT__KB__COLUMNS === +/** macros/OPT__KB__COLUMNS/description * The number of columns in a given keyboard's matrix */ @@ -239,25 +234,8 @@ void kb__layout__exec_key_location (bool pressed, uint8_t row, uint8_t column); // ---------------------------------------------------------------------------- -// === kb__layout__exec_key_pointer === -/** functions/kb__layout__exec_key_pointer/description - * Perform a "press" or "release" of the key pointed to - * - * Arguments: - * - `pressed`: - * - `true`: Indicates that the key to be "executed" has been pressed - * - `false`: Indicates that the key to be "executed" has been released - * - `pointer`: A pointer to the key to execute - * - * Notes: - * - The pointer may be of any type, and to a value in any address space. It - * is up to the keyboard implementation to define this. Since this is the - * only `exec_key_pointer` function though, all the keys should probably be - * in the same address space, wherever they are. - */ - -// === kb__layout__exec_key_location === -/** functions/kb__layout__exec_key_location/description +// === kb__layout__exec_key === +/** functions/kb__layout__exec_key/description * Perform the appropriate actions for a "press" or "release" of the key at the * given position. * diff --git a/firmware/keyboard/ergodox/controller.c b/firmware/keyboard/ergodox/controller.c index 26a8cbd..8e36770 100644 --- a/firmware/keyboard/ergodox/controller.c +++ b/firmware/keyboard/ergodox/controller.c @@ -25,7 +25,7 @@ uint8_t kb__init(void) { return 0; // success } -uint8_t kb__update_matrix(bool matrix[KB__ROWS][KB__COLUMNS]) { +uint8_t kb__update_matrix(bool matrix[OPT__KB__ROWS][OPT__KB__COLUMNS]) { if (teensy__update_matrix(matrix)) return 1; if (mcp23018__update_matrix(matrix)) diff --git a/firmware/keyboard/ergodox/controller/mcp23018.c b/firmware/keyboard/ergodox/controller/mcp23018.c index 6db3fe3..d328598 100644 --- a/firmware/keyboard/ergodox/controller/mcp23018.c +++ b/firmware/keyboard/ergodox/controller/mcp23018.c @@ -18,7 +18,7 @@ // ---------------------------------------------------------------------------- -#if KB__ROWS != 6 || KB__COLUMNS != 14 +#if OPT__KB__ROWS != 6 || OPT__KB__COLUMNS != 14 #error "Expecting different keyboard dimensions" #endif @@ -135,7 +135,7 @@ out: * - success: `0` * - failure: twi status code */ -uint8_t mcp23018__update_matrix(bool matrix[KB__ROWS][KB__COLUMNS]) { +uint8_t mcp23018__update_matrix(bool matrix[OPT__KB__ROWS][OPT__KB__COLUMNS]) { uint8_t ret, data; // initialize things, just to make sure diff --git a/firmware/keyboard/ergodox/controller/mcp23018.h b/firmware/keyboard/ergodox/controller/mcp23018.h index 1bf4765..b863af7 100644 --- a/firmware/keyboard/ergodox/controller/mcp23018.h +++ b/firmware/keyboard/ergodox/controller/mcp23018.h @@ -22,7 +22,7 @@ // ---------------------------------------------------------------------------- uint8_t mcp23018__init (void); -uint8_t mcp23018__update_matrix (bool matrix[KB__ROWS][KB__COLUMNS]); +uint8_t mcp23018__update_matrix (bool matrix[OPT__KB__ROWS][OPT__KB__COLUMNS]); // ---------------------------------------------------------------------------- diff --git a/firmware/keyboard/ergodox/controller/teensy-2-0.c b/firmware/keyboard/ergodox/controller/teensy-2-0.c index 5e0e9c1..6f9372f 100644 --- a/firmware/keyboard/ergodox/controller/teensy-2-0.c +++ b/firmware/keyboard/ergodox/controller/teensy-2-0.c @@ -23,7 +23,7 @@ #error "Expecting different CPU frequency" #endif -#if KB__ROWS != 6 || KB__COLUMNS != 14 +#if OPT__KB__ROWS != 6 || OPT__KB__COLUMNS != 14 #error "Expecting different keyboard dimensions" #endif @@ -236,7 +236,7 @@ uint8_t teensy__init(void) { * Returns: * - success: `0` */ -uint8_t teensy__update_matrix(bool matrix[KB__ROWS][KB__COLUMNS]) { +uint8_t teensy__update_matrix(bool matrix[OPT__KB__ROWS][OPT__KB__COLUMNS]) { #if OPT__TEENSY__DRIVE_ROWS update_columns_for_row(matrix, 0); update_columns_for_row(matrix, 1); diff --git a/firmware/keyboard/ergodox/controller/teensy-2-0.h b/firmware/keyboard/ergodox/controller/teensy-2-0.h index cb69953..bc805dd 100644 --- a/firmware/keyboard/ergodox/controller/teensy-2-0.h +++ b/firmware/keyboard/ergodox/controller/teensy-2-0.h @@ -22,7 +22,7 @@ // ---------------------------------------------------------------------------- uint8_t teensy__init (void); -uint8_t teensy__update_matrix (bool matrix[KB__ROWS][KB__COLUMNS]) +uint8_t teensy__update_matrix (bool matrix[OPT__KB__ROWS][OPT__KB__COLUMNS]) // ---------------------------------------------------------------------------- diff --git a/firmware/keyboard/ergodox/layout/colemak-symbol-mod.c b/firmware/keyboard/ergodox/layout/colemak-symbol-mod.c index 4cc2da2..47bc698 100644 --- a/firmware/keyboard/ergodox/layout/colemak-symbol-mod.c +++ b/firmware/keyboard/ergodox/layout/colemak-symbol-mod.c @@ -9,29 +9,21 @@ * * Implements the "layout" section of '.../firmware/keyboard.h' * - * Notes: - * - This layout *does not* contain a key mapped to the bootloader function. - * To reflash from this layout, you will need to physically press the button - * on the top right of the Teensy. - * * History: * - Originally submitted by Jason Trill [jjt] (https://github.com/jjt) (who * declined to be added to the copyright above). - * - Transcribed by Ben Blazak when the layout format changed. - * - * TODO: fix this file, after the qwerty layout is done - * TODO: rearrange things to put a btldr key somewhere + * - Various changes have been made since (see git history) */ -#include "./default/common.h" +#include "./common/definitions.h" // ---------------------------------------------------------------------------- // matrix control // ---------------------------------------------------------------------------- -#include "./default/exec_key.c.h" +#include "./common/exec_key.c.h" // ---------------------------------------------------------------------------- @@ -39,7 +31,7 @@ // ---------------------------------------------------------------------------- void kb__led__logical_on(char led) { - switch led { + switch(led) { case 'N': kb__led__on(1); break; // numlock case 'C': kb__led__on(2); break; // capslock case 'S': kb__led__on(3); break; // scroll lock @@ -49,7 +41,7 @@ void kb__led__logical_on(char led) { } void kb__led__logical_off(char led) { - switch led { + switch(led) { case 'N': kb__led__off(1); break; // numlock case 'C': kb__led__off(2); break; // capslock case 'S': kb__led__off(3); break; // scroll lock @@ -63,144 +55,142 @@ void kb__led__logical_off(char led) { // keys // ---------------------------------------------------------------------------- -#include "./default/keys.h" +#include "./common/keys.c.h" -// layer -key_t L0pu1po = { &kf__layer__push, 0x0001, &kf__layer__pop, 0x0001 }; -key_t L1pu2 = { &kf__layer__push, 0x0102, NULL, 0 }; -key_t L1po = { &kf__layer__pop, 0x0100, NULL, 0 }; -key_t L1pu2po = { &kf__layer__push, 0x0102, &kf__layer__pop, 0x0102 }; - -// --- NumPush -const uint16_t PROGMEM NumPush__press[] = { - 2, &kf__layer__push, 0x0203, - &kf__press, KEY__LockingNumLock }; -key_t NumPush = { &kf__macro__progmem, &NumPush__press, - &kf__release, KEY__LockingNumLock }; - -// --- NumPop -const uint16_t PROGMEM NumPop__press[] = { - 2, &kf__layer__pop, 0x0203, - &kf__press, KEY__LockingNumLock }; -key_t NumPop = { &kf__macro__progmem, &NumPop__press, - &kf__release, KEY__LockingNumLock }; - -// --- NumPuPo -const uint16_t PROGMEM NumPuPo__press[] = { - 3, &kf__layer__push, 0x0203, - &kf__press, KEY__LockingNumLock, - &kf__release, KEY__LockingNumLock }; -const uint16_t PROGMEM NumPuPo__release[] = { - 3, &kf__layer__pop, 0x0203, - &kf__press, KEY__LockingNumLock, - &kf__release, KEY__LockingNumLock }; -key_t NumPuPo = { &kf__macro__progmem, &NumPuPo__press, - &kf__macro__progmem, &NumPuPo__release }; +KEYS__LAYER__NUM_PU_PO(10, 4); +KEYS__LAYER__NUM_PUSH(10, 4); +KEYS__LAYER__NUM_POP(10); // ---------------------------------------------------------------------------- // layout // ---------------------------------------------------------------------------- -key_t layout[][KB__ROWS][KB__COLUMNS] = { +#include "./common/matrix.h" + + +layout_t _layout = { // ............................................................................ MATRIX_LAYER( // layer 0 : default (colemak) - -// unused -NA, +// macro, unused, + K, nop, // left hand ...... ......... ......... ......... ......... ......... ......... - Equal, K1, K2, K3, K4, K5, L1pu2, - Tab, Q, W, F, P, G, Esc, - CtrlL, A, R, S, T, D, -Sh2KCapL, Z, X, C, V, B, L1pu2po, - GUIL, Grave, Bkslash, AltL, L0pu1po, - CtrlL, AltL, - NA, NA, Home, - Space, Enter, End, + equal, 1, 2, 3, 4, 5, lpu2l2, + tab, q, w, f, p, g, esc, + ctrlL, a, r, s, t, d, +shL2kcap, z, x, c, v, b, lpupo2l2, + guiL, grave, bkslash, altL, lpupo1l1, + ctrlL, altL, + nop, nop, home, + space, enter, end, // right hand ..... ......... ......... ......... ......... ......... ......... - NumPush, K6, K7, K8, K9, K0, Dash, - Esc, J, L, U, Y, Semicol, Bkslash, - H, N, E, I, O, Quote, - NumPuPo, K, M, Comma, Period, Slash, Sh2KCapR, - L0pu1po, ArrowL, ArrowD, ArrowU, ArrowR, - AltR, CtrlR, - PageU, NA, NA, - PageD, Del, Bs ), + numPush, 6, 7, 8, 9, 0, dash, + esc, j, l, u, y, semicol, bkslash, + h, n, e, i, o, quote, + numPuPo, k, m, comma, period, slash, shR2kcap, + lpupo1l1, arrowL, arrowD, arrowU, arrowR, + altR, ctrlR, + pageU, nop, nop, + pageD, del, bs ), // ............................................................................ MATRIX_LAYER( // layer 1 : function and symbol keys -// unused -NA, +// macro, unused, + K, nop, // left hand ...... ......... ......... ......... ......... ......... ......... - Transp, F1, F2, F3, F4, F5, F11, - Transp, BraceL, BraceR, BrktL, BrktR, Colon, Transp, - Transp, Bkslash, Slash, ParenL, ParenR, Semicol, - Transp, Exclam, At, Pound, Dollar, Percent, Transp, - Transp, Transp, Transp, Transp, Transp, - Transp, Transp, - Transp, Transp, Transp, - Transp, Transp, Transp, + transp, F1, F2, F3, F4, F5, F11, + transp, braceL, braceR, brktL, brktR, colon, transp, + transp, bkslash, slash, parenL, parenR, semicol, + transp, exclam, at, pound, dollar, percent, transp, + transp, transp, transp, transp, lpupo3l3, + transp, transp, + transp, transp, transp, + transp, transp, transp, // right hand ..... ......... ......... ......... ......... ......... ......... - F12, F6, F7, F8, F9, F10, Power, - Transp, NA, Equal, Plus, Dash, Undersc, NA, - ArrowL, ArrowD, ArrowU, ArrowR, NA, NA, - Transp, Caret, Amp, Asterisk, ParenL, ParenR, Transp, - Transp, Transp, Transp, Transp, Transp, - Transp, Transp, - Transp, Transp, Transp, - Transp, Transp, Transp ), + F12, F6, F7, F8, F9, F10, power, + transp, nop, equal, plus, dash, undersc, nop, + arrowL, arrowD, arrowU, arrowR, nop, nop, + transp, caret, amp, asterisk, parenL, parenR, transp, + lpupo3l3, transp, transp, transp, transp, + transp, transp, + transp, transp, transp, + transp, transp, transp ), // ............................................................................ MATRIX_LAYER( // layer 2 : QWERTY alphanum -// unused -NA, +// macro, unused, + K, nop, // left hand ...... ......... ......... ......... ......... ......... ......... - Transp, K1, K2, K3, K4, K5, L1po, - Transp, Q, W, E, R, T, Transp, - Transp, A, S, D, F, G, - Transp, Z, X, C, V, B, Transp, - Transp, Transp, Transp, Transp, Transp, Transp, - Transp, Transp, - Transp, Transp, Transp, - Transp, Transp, Transp, + transp, 1, 2, 3, 4, 5, lpo2l2, + transp, q, w, e, r, t, transp, + transp, a, s, d, f, g, + transp, z, x, c, v, b, transp, + transp, transp, transp, transp, transp, transp, + transp, transp, + transp, transp, transp, + transp, transp, transp, // right hand ..... ......... ......... ......... ......... ......... ......... - Transp, K6, K7, K8, K9, K0, Transp, - Transp, Y, U, I, O, P, Transp, - H, J, K, L, Semicol, Transp, - Transp, N, M, Comma, Period, Slash, Transp, - Transp, Transp, Transp, Transp, Transp, - Transp, Transp, - Transp, Transp, Transp, - Transp, Transp, Transp ), + transp, 6, 7, 8, 9, 0, transp, + transp, y, u, i, o, p, transp, + h, j, k, l, semicol, transp, + transp, n, m, comma, period, slash, transp, + transp, transp, transp, transp, transp, + transp, transp, + transp, transp, transp, + transp, transp, transp ), // ............................................................................ - MATRIX_LAYER( // layer 3 : numpad -// unused -NA, + MATRIX_LAYER( // layer 3 : keyboard functions +// macro, unused, + K, nop, // left hand ...... ......... ......... ......... ......... ......... ......... - Transp, Transp, Transp, Transp, Transp, Transp, Transp, - Transp, Transp, Transp, Transp, Transp, Transp, Transp, - Transp, Transp, Transp, Transp, Transp, Transp, - Transp, Transp, Transp, Transp, Transp, Transp, Transp, - Transp, Ins, Transp, Transp, Transp, - Transp, Transp, - Transp, Transp, Transp, - Transp, Transp, Transp, + btldr, nop, nop, nop, nop, nop, nop, + nop, nop, nop, nop, nop, nop, nop, + nop, nop, nop, nop, nop, nop, + nop, nop, nop, nop, nop, nop, nop, + nop, nop, nop, nop, nop, + nop, nop, + nop, nop, nop, + nop, nop, nop, // right hand ..... ......... ......... ......... ......... ......... ......... - NumPop, Transp, NumPop, Equal, KPDiv, KPMul, Transp, - Transp, Transp, KP7, KP8, KP9, KPSub, Transp, - Transp, KP4, KP5, KP6, KPAdd, Transp, - Transp, Transp, KP1, KP2, KP3, KPEnter, Transp, - Transp, Transp, Period, KPEnter, Transp, - Transp, Transp, - Transp, Transp, Transp, - Transp, Transp, KP0 ), + nop, nop, nop, nop, nop, nop, nop, + nop, nop, nop, nop, nop, nop, nop, + nop, nop, nop, nop, nop, nop, + nop, nop, nop, nop, nop, nop, nop, + nop, nop, nop, nop, nop, + nop, nop, + nop, nop, nop, + nop, nop, nop ), + +// ............................................................................ + + MATRIX_LAYER( // layer 4 : numpad +// macro, unused, + K, nop, +// left hand ...... ......... ......... ......... ......... ......... ......... + transp, transp, transp, transp, transp, transp, transp, + transp, transp, transp, transp, transp, transp, transp, + transp, transp, transp, transp, transp, transp, + transp, transp, transp, transp, transp, transp, transp, + transp, ins, transp, transp, transp, + transp, transp, + transp, transp, transp, + transp, transp, transp, +// right hand ..... ......... ......... ......... ......... ......... ......... + numPop, transp, numPop, equal, kpDiv, kpMul, transp, + transp, transp, kp7, kp8, kp9, kpSub, transp, + transp, kp4, kp5, kp6, kpAdd, transp, + transp, transp, kp1, kp2, kp3, kpEnter, transp, + transp, transp, period, kpEnter, transp, + transp, transp, + transp, transp, transp, + transp, transp, kp0 ), // ............................................................................ }; diff --git a/firmware/keyboard/ergodox/layout/common/definitions.h b/firmware/keyboard/ergodox/layout/common/definitions.h index e5956f8..fd1ea38 100644 --- a/firmware/keyboard/ergodox/layout/common/definitions.h +++ b/firmware/keyboard/ergodox/layout/common/definitions.h @@ -23,6 +23,7 @@ #include "../../../../../firmware/lib/usb.h" #include "../../../../../firmware/lib/usb/usage-page/keyboard.h" #include "../../../../../firmware/lib/layout/key-functions.h" +#include "../../../../../firmware/lib/layout/layer-stack.h" // ---------------------------------------------------------------------------- @@ -32,6 +33,10 @@ * Notes: * - Keys will be of the form * `key_t key = { &press_function, &release_function };` + * + * - The fact that keys are of this type (composed of two + * `void (*function)(void)` pointers) is assumed throughout most of these + * layout files */ typedef void (*key_t[2])(void); @@ -42,7 +47,28 @@ typedef void (*key_t[2])(void); * - The first dimension of the matrix (left blank in the typedef since it * varies between layouts) is "layers" */ -typedef key_t PROGMEM layout_t[][KB__ROWS][KB__COLUMNS]; +typedef const key_t PROGMEM layout_t[][OPT__KB__ROWS][OPT__KB__COLUMNS]; + +/** variables/layout/description + * The variable containing our layout matrix + */ +layout_t _layout; + +/** variables/sticky_key/description + * A pointer to the release function of the last sticky key pressed + * + * The function pointed to by this should be executed directly after executing + * the "press" function of the next key pressed. + * + * Notes: + * - In order for things to work right, sticky keys should either execute this + * stored function themselves before placing their own "release" function + * value here, or else save the value that's here and call it as part of + * their own "release" function. If this isn't done, and the key pressed + * directly before this was a sticky key as well, then the previous sticky + * key will never be released. + */ +void (*_sticky_key)(void); // ---------------------------------------------------------------------------- diff --git a/firmware/keyboard/ergodox/layout/common/exec_key.c.h b/firmware/keyboard/ergodox/layout/common/exec_key.c.h index 5691cb6..1ea567a 100644 --- a/firmware/keyboard/ergodox/layout/common/exec_key.c.h +++ b/firmware/keyboard/ergodox/layout/common/exec_key.c.h @@ -16,25 +16,32 @@ // ---------------------------------------------------------------------------- // ---------------------------------------------------------------------------- + #include "./definitions.h" // ---------------------------------------------------------------------------- -void kb__layout__exec_key_pointer(key_t * pointer) { // TODO -} +void kb__layout__exec_key(bool pressed, int8_t row, int8_t column) { + void (*function)(void); -void kb__layout__exec_key_location( bool pressed, // TODO - int8_t layer, - int8_t row, - int8_t column ) { - // - check for key redefinition in the EEPROM - // - if there is one, execute it, according to the appropriate rules - // - lookup key in PROGMEM - // - if it's transparent, look up the one below it, and so on - // - NULL key pointers are transparent - // - { NULL, 0, NULL, 0 } keys do nothing; this is the default, if no - // key can be found - // - call the press or release function, with the appropriate argument + for(uint8_t i=0; i + * Released under The MIT License (see "doc/licenses/MIT.md") + * Project located at + * ------------------------------------------------------------------------- */ + +/** description + * The `main()` interface for the rest of the program + * + * Prefix: `main__` + * + * Certain variables are declared here so that other functions can see (and + * perhaps modify) them, to accomplish things that may be difficult otherwise. + * If, for instance, a key-function needed to be called on every scan while + * they key was pressed instead of just on state-change: it could set its entry + * in `main__was_pressed` to `false` on every run. + */ + + +#ifndef ERGODOX_FIRMWARE__FIRMWARE__MAIN__H +#define ERGODOX_FIRMWARE__FIRMWARE__MAIN__H +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- + + +#include +#include + +// ---------------------------------------------------------------------------- + +/** variables/main__is_pressed/description + * A matrix of `bool`s indicating whether the key at a given position is + * currently pressed + */ +extern bool (* main__is_pressed) [OPT__KB__ROWS][OPT__KB__COLUMNS]; + +/** variables/main__was_pressed/description + * A matrix of `bool`s indicating whether the key at a given position was + * pressed on the previous scan + */ +extern bool (* main__was_pressed) [OPT__KB__ROWS][OPT__KB__COLUMNS]; + +/** variables/main__row/description + * Indicates which row is currently being tested for changes of key state + */ +extern uint8_t main__row; + +/** variables/main__col/description + * Indicates which column is currently being tested for changes of key state + */ +extern uint8_t main__col; + + +// ---------------------------------------------------------------------------- +// ---------------------------------------------------------------------------- +#endif // ERGODOX_FIRMWARE__FIRMWARE__MAIN__H +