From 039aba752b1c18a5303d7232d3a293a272d232f3 Mon Sep 17 00:00:00 2001 From: Ben Blazak Date: Thu, 5 Jul 2012 15:48:18 -0700 Subject: [PATCH] added numpad (and a private key-function for layer masking) tested on breadboard. appears to work! --- src/keyboard/ergodox/layout/qwerty.c | 161 +++++++++++++++++-------- src/keyboard/ergodox/matrix--private.h | 96 --------------- src/keyboard/ergodox/matrix.c | 1 - src/keyboard/ergodox/matrix.h | 84 +++++++++++++ src/lib/key-functions--private.h | 4 + src/lib/key-functions.c | 94 +++++++++++++-- src/lib/key-functions.h | 1 + src/lib/usb/TODO.c | 10 +- 8 files changed, 298 insertions(+), 153 deletions(-) delete mode 100644 src/keyboard/ergodox/matrix--private.h diff --git a/src/keyboard/ergodox/layout/qwerty.c b/src/keyboard/ergodox/layout/qwerty.c index fb7d859..c29878f 100644 --- a/src/keyboard/ergodox/layout/qwerty.c +++ b/src/keyboard/ergodox/layout/qwerty.c @@ -15,7 +15,6 @@ #include "lib/key-functions.h" #include "../matrix.h" -#include "../matrix--private.h" #include "../layout.h" @@ -27,60 +26,84 @@ #define f_l_iex &kbfun_layer_inc_exec #define f_l_dex &kbfun_layer_dec_exec #define f_2kcap &kbfun_2_keys_capslock_press_release +#define f_lm_nu &kbfun_layermask_numpad_press_release uint8_t PROGMEM _kb_layout[KB_LAYERS][KB_ROWS][KB_COLUMNS] = { // ---------------------------------------------------------------------------- - LAYER( // layer 0: default + MATRIX_LAYER( // layer 0: default // unused 0, // left hand -_grave, _1, _2, _3, _4, _5, _equal, -_bracketL, _Q, _W, _E, _R, _T, _esc, -_tab, _A, _S, _D, _F, _G, -_shiftL, _Z, _X, _C, _V, _B, 1, -_guiL, _arrowL, _arrowU, _arrowD, _arrowR, - _bs, - _del, _ctrlL, - _end, _home, _altL, -// right hand - _backslash, _6, _7, _8, _9, _0, _dash, - _bracketL, _Y, _U, _I, _O, _P, _bracketR, - _H, _J, _K, _L, _semicolon, _quote, - 1, _N, _M, _comma, _period, _slash, _shiftR, - _arrowL, _arrowD, _arrowU, _arrowR, _guiR, - _space, -_ctrlR, _enter, -_altR, _pageU, _pageD ), -// ---------------------------------------------------------------------------- - LAYER( // layer 1: function and symbol keys -// unused -0, -// left hand -0, _F1, _F2, _F3, _F4, _F5, _F11, -0, _braceL_kp, _braceR_kp, _bracketL, _bracketR, 0, _esc, -0, _semicolon, _slash, _dash, 0, _colon_kp, -0, 0, 0, 0, 0, 0, 0, -0, _arrowL, _arrowU, _arrowD, _arrowR, + _grave, _1, _2, _3, _4, _5, _equal, +_bracketL, _Q, _W, _E, _R, _T, _esc, + _tab, _A, _S, _D, _F, _G, + _shiftL, _Z, _X, _C, _V, _B, 1, + _guiL, _arrowL, _arrowU, _arrowD, _arrowR, _bs, - _del, _ctrlL, - _end, _home, _altL, + _del, _ctrlL, + _end, _home, _altL, // right hand - _F12, _F6, _F7, _F8, _F9, _F10, 0, - 0, 0, _dash, _lt_kp, _gt_kp, _currencyUnit, 0, - _backslash, 0, _parenL_kp, _parenR_kp, _equal, 0, - 0, _mul_kp, 0, 0, 0, 0, 0, - _arrowL, _arrowD, _arrowU, _arrowR, 0, + _backslash, _6, _7, _8, _9, _0, _dash, + _bracketL, _Y, _U, _I, _O, _P, _bracketR, + _H, _J, _K, _L, _semicolon, _quote, + 1, _N, _M, _comma, _period, _slash, _shiftR, + _arrowL, _arrowD, _arrowU, _arrowR, _guiR, _space, _ctrlR, _enter, -_altR, _pageU, _pageD ) + _altR, _pageU, _pageD ), +// ---------------------------------------------------------------------------- + MATRIX_LAYER( // layer 1: function and symbol keys +// unused +0, +// left hand +0, _F1, _F2, _F3, _F4, _F5, _F11, +0, _braceL_kp, _braceR_kp, _bracketL, _bracketR, 0, _esc, +0, _semicolon, _slash, _dash, 0, _colon_kp, +2, 0, 0, 0, 0, 0, 0, +0, _arrowL, _arrowU, _arrowD, _arrowR, + _bs, + _del, _ctrlL, + _end, _home, _altL, +// right hand + _F12, _F6, _F7, _F8, _F9, _F10, 0, + 0, 0, _dash, _lt_kp, _gt_kp, _currencyUnit, 0, + _backslash, 0, _parenL_kp, _parenR_kp, _equal, 0, + 0, _mul_kp, 0, 0, 0, 0, 0, + _arrowL, _arrowD, _arrowU, _arrowR, 0, + _space, +_ctrlR, _enter, + _altR, _pageU, _pageD ), +// ---------------------------------------------------------------------------- + MATRIX_LAYER( // layer 2: numpad +// unused +0, +// left hand +0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, 0, 0, +0, 0, 0, 0, 0, + 0, + 0, 0, + 0, 0, 0, +// right hand +//------- ------- ------- ------- ------- ------- ------- + 0, 0, _7_kp, _8_kp, _9_kp, _div_kp, 0, + 0, 0, _4_kp, _5_kp, _6_kp, _mul_kp, 0, + 0, _1_kp, _2_kp, _3_kp, _sub_kp, 0, + 0, 0, _0_kp, _period, 0, _add_kp, 0, + 0, 0, 0, 0, 0, + 0, +0, 0, +0, 0, 0 ) // ---------------------------------------------------------------------------- }; kbfun_funptr_t PROGMEM _kb_layout_press[KB_LAYERS][KB_ROWS][KB_COLUMNS] = { // ---------------------------------------------------------------------------- - LAYER( // layer 0: default + MATRIX_LAYER( // layer 0: default // unused NULL, // left hand @@ -102,14 +125,14 @@ f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel, f_prrel, f_prrel,f_prrel,f_prrel ), // ---------------------------------------------------------------------------- - LAYER( // layer 1: function and symbol keys + MATRIX_LAYER( // layer 1: function and symbol keys // unused NULL, // left hand f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, -f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, NULL, +f_lm_nu,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, NULL, f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel, f_prrel, f_prrel, @@ -122,14 +145,36 @@ f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel, f_prrel, f_prrel, -f_prrel,f_prrel,f_prrel ) +f_prrel,f_prrel,f_prrel ), +// ---------------------------------------------------------------------------- + MATRIX_LAYER( // layer 2: numpad +// unused +NULL, +// left hand + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, + NULL, NULL, + NULL, NULL, NULL, +// right hand + NULL, NULL,f_prrel,f_prrel,f_prrel,f_prrel, NULL, + NULL, NULL,f_prrel,f_prrel,f_prrel,f_prrel, NULL, + NULL,f_prrel,f_prrel,f_prrel,f_prrel, NULL, + NULL, NULL,f_prrel,f_prrel,f_prrel,f_prrel, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, + NULL, NULL, + NULL, NULL, NULL ) // ---------------------------------------------------------------------------- }; kbfun_funptr_t PROGMEM _kb_layout_release[KB_LAYERS][KB_ROWS][KB_COLUMNS] = { // ---------------------------------------------------------------------------- - LAYER( // layer 0: default + MATRIX_LAYER( // layer 0: default // unused NULL, // left hand @@ -151,14 +196,14 @@ f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel, f_prrel, f_prrel,f_prrel,f_prrel ), // ---------------------------------------------------------------------------- - LAYER( // layer 1: function and symbol keys + MATRIX_LAYER( // layer 1: function and symbol keys // unused NULL, // left hand f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, -f_prrel,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, NULL, +f_lm_nu,f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, NULL, f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel, f_prrel, f_prrel, @@ -173,8 +218,30 @@ f_prrel,f_prrel,f_prrel,f_prrel,f_prrel, f_prrel, f_prrel, f_prrel,f_prrel,f_prrel ), // ---------------------------------------------------------------------------- - LAYER( // layer 2: nothing (just making sure unused functions don't - // get compiled out) + MATRIX_LAYER( // layer 2: numpad +// unused +NULL, +// left hand + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, + NULL, NULL, + NULL, NULL, NULL, +// right hand + NULL, NULL,f_prrel,f_prrel,f_prrel,f_prrel, NULL, + NULL, NULL,f_prrel,f_prrel,f_prrel,f_prrel, NULL, + NULL,f_prrel,f_prrel,f_prrel,f_prrel, NULL, + NULL, NULL,f_prrel,f_prrel,f_prrel,f_prrel, NULL, + NULL, NULL, NULL, NULL, NULL, + NULL, + NULL, NULL, + NULL, NULL, NULL ), +// ---------------------------------------------------------------------------- + MATRIX_LAYER( // layer 3: nothing (just making sure unused functions + // don't get compiled out) // unused NULL, // other @@ -185,7 +252,7 @@ f_l_dec, NULL, NULL, NULL, NULL, NULL, NULL, f_l_iex, NULL, NULL, NULL, NULL, NULL, NULL, f_l_dex, NULL, NULL, NULL, NULL, NULL, NULL, f_2kcap, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, +f_lm_nu, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) diff --git a/src/keyboard/ergodox/matrix--private.h b/src/keyboard/ergodox/matrix--private.h deleted file mode 100644 index 3094eca..0000000 --- a/src/keyboard/ergodox/matrix--private.h +++ /dev/null @@ -1,96 +0,0 @@ -/* ---------------------------------------------------------------------------- - * ergoDOX: keyboard matrix specific exports : private - * ---------------------------------------------------------------------------- - * Copyright (c) 2012 Ben Blazak - * Released under The MIT License (MIT) (see "license.md") - * Project located at - * ------------------------------------------------------------------------- */ - - -#ifndef MATRIX_h_PRIVATE - #define MATRIX_h_PRIVATE - - /* mapping from spatial position to matrix position - * - spatial position: where the key is spatially, relative to other - * keys both on the keyboard and in the layout - * - matrix position: the coordinate in the matrix to which a key is - * scanned by the update functions - * - * - location numbers are in the format `row##column`, where both 'row' - * and 'column' are single digit hex numbers corresponding to the - * matrix position (which also corresponds to the row and column pin - * labels used in the teensy and mcp23018 files) - * - coordinates not listed are unused - * - * --- other info ----------------------------------------------------- - * rows x columns = positions; assigned, unassigned - * per hand: 6 x 7 = 42; 38, 4 - * total: 12 x 7 = 84; 76, 8 - * - * left hand : cols 0..6, rows 6..B - * right hand : cols 0..6, rows 0..5 - * -------------------------------------------------------------------- - */ - #define LAYER( \ - /* for unused positions */ \ - na, \ - \ - /* left hand, spatial positions */ \ - kB6,kB5,kB4,kB3,kB2,kB1,kB0, \ - kA6,kA5,kA4,kA3,kA2,kA1,kA0, \ - k96,k95,k94,k93,k92,k91, \ - k86,k85,k84,k83,k82,k81,k80, \ - k76,k75,k74,k73,k72, \ - k64, \ - k63, k60, \ - k65,k62,k61, \ - \ - /* right hand, spatial positions */ \ - k50,k51,k52,k53,k54,k55,k56, \ - k40,k41,k42,k43,k44,k45,k46, \ - k31,k32,k33,k34,k35,k36, \ - k20,k21,k22,k23,k24,k25,k26, \ - k12,k13,k14,k15,k16, \ - k04, \ - k00, k03, \ - k01,k02,k05 ) \ - \ - /* matrix positions */ \ - { { k00,k01,k02,k03,k04,k05, na,}, \ - { na, na,k12,k13,k14,k15,k16,}, \ - { k20,k21,k22,k23,k24,k25,k26,}, \ - { na,k31,k32,k33,k34,k35,k36,}, \ - { k40,k41,k42,k43,k44,k45,k46,}, \ - { k50,k51,k52,k53,k54,k55,k56,}, \ - { k60,k61,k62,k63,k64,k65, na,}, \ - { na, na,k72,k73,k74,k75,k76,}, \ - { k80,k81,k82,k83,k84,k85,k86,}, \ - { na,k91,k92,k93,k94,k95,k96,}, \ - { kA0,kA1,kA2,kA3,kA4,kA5,kA6,}, \ - { kB0,kB1,kB2,kB3,kB4,kB5,kB6 } } - - - #define LAYER_SET_ALL(na, kxx) \ - LAYER( \ - na, \ - \ - kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ - kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ - kxx,kxx,kxx,kxx,kxx,kxx, \ - kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ - kxx,kxx,kxx,kxx,kxx, \ - kxx, \ - kxx, kxx, \ - kxx,kxx,kxx, \ - \ - kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ - kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ - kxx,kxx,kxx,kxx,kxx,kxx, \ - kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ - kxx,kxx,kxx,kxx,kxx, \ - kxx, \ - kxx, kxx, \ - kxx,kxx,kxx ) - -#endif - diff --git a/src/keyboard/ergodox/matrix.c b/src/keyboard/ergodox/matrix.c index d5e6b93..3a1f9e7 100644 --- a/src/keyboard/ergodox/matrix.c +++ b/src/keyboard/ergodox/matrix.c @@ -10,7 +10,6 @@ #include "lib/data-types.h" #include "matrix.h" -#include "matrix--private.h" static bool _kb_is_pressed[KB_ROWS][KB_COLUMNS]; diff --git a/src/keyboard/ergodox/matrix.h b/src/keyboard/ergodox/matrix.h index 600f311..1903a8f 100644 --- a/src/keyboard/ergodox/matrix.h +++ b/src/keyboard/ergodox/matrix.h @@ -18,5 +18,89 @@ extern bool (*kb_is_pressed)[KB_ROWS][KB_COLUMNS]; extern bool (*kb_was_pressed)[KB_ROWS][KB_COLUMNS]; + + /* mapping from spatial position to matrix position + * - spatial position: where the key is spatially, relative to other + * keys both on the keyboard and in the layout + * - matrix position: the coordinate in the matrix to which a key is + * scanned by the update functions + * + * - location numbers are in the format `row##column`, where both 'row' + * and 'column' are single digit hex numbers corresponding to the + * matrix position (which also corresponds to the row and column pin + * labels used in the teensy and mcp23018 files) + * - coordinates not listed are unused + * + * --- other info ----------------------------------------------------- + * rows x columns = positions; assigned, unassigned + * per hand: 6 x 7 = 42; 38, 4 + * total: 12 x 7 = 84; 76, 8 + * + * left hand : cols 0..6, rows 6..B + * right hand : cols 0..6, rows 0..5 + * -------------------------------------------------------------------- + */ + #define MATRIX_LAYER( \ + /* for unused positions */ \ + na, \ + \ + /* left hand, spatial positions */ \ + kB6,kB5,kB4,kB3,kB2,kB1,kB0, \ + kA6,kA5,kA4,kA3,kA2,kA1,kA0, \ + k96,k95,k94,k93,k92,k91, \ + k86,k85,k84,k83,k82,k81,k80, \ + k76,k75,k74,k73,k72, \ + k64, \ + k63, k60, \ + k65,k62,k61, \ + \ + /* right hand, spatial positions */ \ + k50,k51,k52,k53,k54,k55,k56, \ + k40,k41,k42,k43,k44,k45,k46, \ + k31,k32,k33,k34,k35,k36, \ + k20,k21,k22,k23,k24,k25,k26, \ + k12,k13,k14,k15,k16, \ + k04, \ + k00, k03, \ + k01,k02,k05 ) \ + \ + /* matrix positions */ \ + { { k00,k01,k02,k03,k04,k05, na,}, \ + { na, na,k12,k13,k14,k15,k16,}, \ + { k20,k21,k22,k23,k24,k25,k26,}, \ + { na,k31,k32,k33,k34,k35,k36,}, \ + { k40,k41,k42,k43,k44,k45,k46,}, \ + { k50,k51,k52,k53,k54,k55,k56,}, \ + { k60,k61,k62,k63,k64,k65, na,}, \ + { na, na,k72,k73,k74,k75,k76,}, \ + { k80,k81,k82,k83,k84,k85,k86,}, \ + { na,k91,k92,k93,k94,k95,k96,}, \ + { kA0,kA1,kA2,kA3,kA4,kA5,kA6,}, \ + { kB0,kB1,kB2,kB3,kB4,kB5,kB6 } } + + + #define MATRIX_LAYER_SET_ALL(na, kxx) \ + LAYER( \ + na, \ + \ + kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ + kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ + kxx,kxx,kxx,kxx,kxx,kxx, \ + kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ + kxx,kxx,kxx,kxx,kxx, \ + kxx, \ + kxx, kxx, \ + kxx,kxx,kxx, \ + \ + kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ + kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ + kxx,kxx,kxx,kxx,kxx,kxx, \ + kxx,kxx,kxx,kxx,kxx,kxx,kxx, \ + kxx,kxx,kxx,kxx,kxx, \ + kxx, \ + kxx, kxx, \ + kxx,kxx,kxx ) + + #endif diff --git a/src/lib/key-functions--private.h b/src/lib/key-functions--private.h index beaeb80..ee9c979 100644 --- a/src/lib/key-functions--private.h +++ b/src/lib/key-functions--private.h @@ -18,6 +18,10 @@ uint8_t value, uint8_t * current_layer, uint8_t (*current_layers_)[KB_ROWS][KB_COLUMNS] ); + void _layer_set_mask( + uint8_t layer, + bool positions[KB_ROWS][KB_COLUMNS], + uint8_t (*current_layers)[KB_ROWS][KB_COLUMNS] ); bool _is_pressed(uint8_t keycode); #endif diff --git a/src/lib/key-functions.c b/src/lib/key-functions.c index b7dc621..ded56a6 100644 --- a/src/lib/key-functions.c +++ b/src/lib/key-functions.c @@ -21,7 +21,7 @@ // ---------------------------------------------------------------------------- -// public functions not for key(press|release) +// public functions (not for keys) // ---------------------------------------------------------------------------- /* @@ -128,7 +128,7 @@ void _press_release(bool pressed, uint8_t keycode) { * and then sets the overall current layer * * Arguments - * - value: the new layer value + * - layer: the new layer value * - current_layer: (a pointer to) the overall current layer (see main.c) * - current_layers: (a pointer to a matrix of) the current layer for each key * (see main.c and lib/key-functions.h) @@ -139,21 +139,40 @@ void _press_release(bool pressed, uint8_t keycode) { * firmware enabled numlock) */ void _layer_set_current( - uint8_t value, + uint8_t layer, uint8_t * current_layer, uint8_t (*current_layers)[KB_ROWS][KB_COLUMNS] ) { // don't switch to out-of-bounds layers - if ( value < 0 || value >= KB_LAYERS ) + if ( layer < 0 || layer >= KB_LAYERS ) return; for (uint8_t row=0; row= KB_LAYERS ) + return; + + for (uint8_t row=0; row