added numpad (and a private key-function for layer masking)

tested on breadboard.  appears to work!
partial-rewrite
Ben Blazak 2012-07-05 15:48:18 -07:00
parent 6e087c7dd4
commit 039aba752b
8 changed files with 298 additions and 153 deletions

View File

@ -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 )

View File

@ -1,96 +0,0 @@
/* ----------------------------------------------------------------------------
* ergoDOX: keyboard matrix specific exports : private
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (MIT) (see "license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#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

View File

@ -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];

View File

@ -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

View File

@ -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

View File

@ -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_ROWS; row++)
for (uint8_t col=0; col<KB_COLUMNS; col++)
// if a key is set to a non-current layer, let it be
// if a key is set to a non-current layer, leave it
if ((*current_layers)[row][col] == *current_layer)
(*current_layers)[row][col] = value;
(*current_layers)[row][col] = layer;
(*current_layer) = value;
(*current_layer) = layer;
}
/*
* Set layer mask
* - Sets the specified key positions to the specified layer
*/
void _layer_set_mask(
uint8_t layer,
bool positions[KB_ROWS][KB_COLUMNS],
uint8_t (*current_layers)[KB_ROWS][KB_COLUMNS] ) {
// don't switch to out-of-bounds layers
if ( layer < 0 || layer >= KB_LAYERS )
return;
for (uint8_t row=0; row<KB_ROWS; row++)
for (uint8_t col=0; col<KB_COLUMNS; col++)
if (positions[row][col])
(*current_layers)[row][col] = layer;
}
/*
@ -203,7 +222,7 @@ void kbfun_press_release( KBFUN_FUNCTION_ARGS ) {
/*
* Toggle
* - Toggle the key on or off
* - Toggle the key pressed or unpressed
*/
void kbfun_toggle( KBFUN_FUNCTION_ARGS ) {
if (_is_pressed(keycode_))
@ -333,3 +352,62 @@ void kbfun_2_keys_capslock_press_release( KBFUN_FUNCTION_ARGS ) {
if (pressed_) keys_pressed++;
}
/*
* Activate Numpad
* - Sets num-lock (on for press, off for release) and shifts (without changing
* the overall current layer) the layer of the keys specified in this
* function to the value specified in the keymap
*
* Note
* - If a more than one layer mask of this type is used at the same time, the
* second will override the first, and any keys covered by both will be reset
* to the overall current layer when the second is released (even if the
* first is still pressed)
*/
#include "usb/usage-page/keyboard.h"
void kbfun_layermask_numpad_press_release( KBFUN_FUNCTION_ARGS ) {
// define layer mask
bool layer_mask[KB_ROWS][KB_COLUMNS] = MATRIX_LAYER(
// 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, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 0,
0, 1, 1, 1, 1, 0,
0, 0, 1, 1, 1, 1, 0,
0, 0, 0, 0, 0,
0,
0, 0,
0, 0, 0 );
// set numlock
if ( // if pressed and numlock off
(pressed_ && !(keyboard_leds & (1<<0))) ||
// if released and numlock on
(!pressed_ && (keyboard_leds & (1<<0))) ) {
// toggle numlock
_press_release(true, KEYPAD_NumLock_Clear);
usb_keyboard_send();
_press_release(false, KEYPAD_NumLock_Clear);
usb_keyboard_send();
}
// set layer mask
if (pressed_)
_layer_set_mask(keycode_, layer_mask, current_layers_);
else
_layer_set_mask(*current_layer_, layer_mask, current_layers_);
}

View File

@ -55,6 +55,7 @@
void kbfun_layer_inc_exec (KBFUN_FUNCTION_ARGS);
void kbfun_layer_dec_exec (KBFUN_FUNCTION_ARGS);
void kbfun_2_keys_capslock_press_release (KBFUN_FUNCTION_ARGS);
void kbfun_layermask_numpad_press_release (KBFUN_FUNCTION_ARGS);
#endif

View File

@ -38,6 +38,14 @@
// - spec sec 9.4.11 (Standard Device Requests / Synch Frame) (pg 260)
// TODO
// - read the hid usage tables .pdf
// - read the hid device class definition .pdf
// DONE
// - read the hid usage tables .pdf
// - i think this is more for reference and implementation than
// understanding. i've copied the relevant (i think) tables ones into
// headers. the unicode usage page, i'll have to look into more later: i'm
// not sure if it can be used with keyboards. if so though, i'll have to
// look on the unicode website, or elsewhere, coz this .pdf doesn't list
// anything about them out, it just references the unicode spec.