(working; got a lot done in keys.c.h and with the layout!)

partial-rewrite
Ben Blazak 2013-04-05 23:17:05 -07:00
parent f7ba0b6497
commit 03c07e0a99
11 changed files with 506 additions and 401 deletions

View File

@ -5,13 +5,12 @@
* ------------------------------------------------------------------------- */
/** description
* A place for all things common to the other default files, including
* `#include`s.
* A central place for the `#include`s relevant to the layout files
*/
#ifndef ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__COMMON__H
#define ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__COMMON__H
#ifndef ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__DEFINITIONS__H
#define ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__DEFINITIONS__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@ -25,8 +24,28 @@
#include "../../../../../firmware/lib/usb/usage-page/keyboard.h"
#include "../../../../../firmware/lib/layout/key-functions.h"
// ----------------------------------------------------------------------------
/** typedefs/key_t/description
* The type we will use for our "key"s
*
* Notes:
* - Keys will be of the form
* `key_t key = { &press_function, &release_function };`
*/
typedef void (*key_t[2])(void);
/** typedefs/layout_t/description
* The type we will use for our layout matrix
*
* Notes:
* - 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];
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__COMMON__H
#endif // ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__DEFINITIONS__H

View File

@ -5,27 +5,21 @@
* ------------------------------------------------------------------------- */
/** description
* A default way to execute keys. Meant to be included by the layout using it
* (and nowhere else, since it's actual code).
* A default way to execute keys.
*
* Notes:
* - This oddish setup is used to allow layouts to easily change some default
* things without having to deal with all of them.
* Meant to be included *only* by the layout using it.
*/
#ifndef ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__EXEC_KEY__C__H
#define ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__EXEC_KEY__C__H
#ifndef ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__EXEC_KEY__C__H
#define ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__EXEC_KEY__C__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include "./common.h"
#include "./definitions.h"
// ----------------------------------------------------------------------------
extern KEY_T layout[][KB__ROWS][KB__COLUMNS];
// ----------------------------------------------------------------------------
void kb__layout__exec_key_pointer(key_t * pointer) { // TODO
}
@ -46,5 +40,5 @@ void kb__layout__exec_key_location( bool pressed, // TODO
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__EXEC_KEY__C__H
#endif // ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__EXEC_KEY__C__H

View File

@ -0,0 +1,302 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* This file implements and extends the definitions in ".../lib/layout/keys.h"
* and extends the definitions in ".../lib/layout/key-functions.h"
*
* Meant to be included *only* by the layout using it.
*
* TODO: put a note about where to look for more information if people are
* trying to learn more about how to make key functions (probably, the usb,
* key_functions, and keys headers; and others?)
*/
// TODO: implement chords (as in, for a chorded key layout)
// TODO: implement sticky keys
#ifndef ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__KEYS__C__H
#define ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__KEYS__C__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include "./definitions.h"
// ----------------------------------------------------------------------------
/** macros/P/description
* Expand `name` into the corresponding "press" function name
*/
#define P(name) keys__press__##name
/** macros/R/description
* Expand `name` into the corresponding "release" function name
*/
#define R(name) keys__release__##name
/** macros/K/description
* Expand into a "key" suitable for putting into the layout matrix
*/
#define K(name) { &P(name), &R(name) }
/** macros/KF/description
* Expand `name` into the corresponding "key_functions" function name
*/
#define KF(name) key_functions__##name
// ----------------------------------------------------------------------------
/** macros/KEYS__DEFAULT/description
* Define the functions for a default key (i.e. a normal key that presses and
* releases a keycode as you'd expect)
*
* Needed by ".../lib/layout/keys.h"
*/
#define KEYS__DEFAULT(name, value) \
void P(name) (void) { KF(press)(value); } \
void R(name) (void) { KF(release)(value); }
/** macros/KEYS__SHIFTED/description
* Define the functions for a "shifted" key (i.e. a key that sends a "shift"
* along with the keycode)
*
* Needed by ".../lib/layout/keys.h"
*/
#define KEYS__SHIFTED(name, value) \
void P(name) (void) { KF(press)(KEY__LeftShift); \
KF(press)(value); } \
void R(name) (void) { KF(release)(value); \
KF(release)(KEY__LeftShift); }
/** macros/KEYS__LAYER__PUSH_POP/description
* Define the functions for a layer push-pop key (i.e. a layer shift key).
*
* Naming Convention:
* - Example: In the name `lpupo1l1`, we have the following:
* - `l` : this is a layer key
* - `pu` : it pushes the layer element onto the stack on "press"
* - `po` : it pops the layer element out of the stack on "release"
* - `1` : it pushes and pops the layer element with `layer_id` = 1
* - `l` : (separate the `layer_id` from the `layer_number`)
* - `1` : it pushes a layer element with `layer_number` = 1
*
* - The first and second number do not have to be the same (that is, the
* `layer_id` and `layer_number` can be different; there may be situations
* where you want or need this).
*
* - Only one of `pu` or `po` is necessary. A key with only `pu` should *only*
* push the layer onto the stack, not pop anything out of it. A key with
* only `po` should *only* pop the layer out of the stack.
*
* Notes:
* - To save space, if you define a push-pop function, the push (only) and pop
* (only) functions may be defined as follows (using the example `lpupo1l1`
* from above):
*
* #define keys__press__lpu1l1 P(lpupo1l1)
* #define keys__release__lpu1l1 P(nop)
* #define keys__press__lpo1l1 R(lpupo1l1)
* #define keys__release__lpo1l1 P(nop)
*
* - It is recommended (as a general rule) to allocate `layer_id`s as follows:
* - 0-9 : leave alone (for use in default layer key definitions)
* - 10-19 : for custom things like 'numPush' and 'numPop'
*/
#define KEYS__LAYER__PUSH_POP(ID, LAYER) \
void P(l##ID##pupo##LAYER) (void) { layer_stack__push(ID, LAYER); } \
void R(l##ID##pupo##LAYER) (void) { layer_stack__pop_id(ID); }
/** macros/(group) layer : number pad/description
* Define function for pushing and popping the number pad (namely `numPush`,
* `numPop`, and `numPuPo`)
*
* Members:
* - `KEYS__LAYER__NUM_PU_PO`
* - `KEYS__LAYER__NUM_PUSH`
* - `KEYS__LAYER__NUM_POP`
*
* These macros are meant to be used (if necessary) in the layout file, since
* they need to know the layer on which the number pad has been placed.
*/
#define KEYS__LAYER__NUM_PU_PO(ID, LAYER) \
void P(numPuPo) (void) { layer_stack__push(ID, LAYER); \
KF(press)(KEY__LockingNumLock); \
usb__kb__send_report(); \
KF(release)(KEY__LockingNumLock); \
usb__kb__send_report(); } \
void R(numPuPo) (void) { layer_stack__pop_id(ID); \
KF(press)(KEY__LockingNumLock); \
usb__kb__send_report(); \
KF(release)(KEY__LockingNumLock); \
usb__kb__send_report(); }
#define KEYS__LAYER__NUM_PUSH(LAYER, ID) \
void P(numPush) (void) { layer_stack__push(ID, LAYER); \
KF(press)(KEY__LockingNumLock); } \
void R(numPush) (void) { KF(release)(KEY__LockingNumLock); }
#define KEYS__LAYER__NUM_POP(LAYER, ID) \
void P(numPop) (void) { layer_stack__pop_id(ID); \
KF(press)(KEY__LockingNumLock); } \
void R(numPop) (void) { KF(release)(KEY__LockingNumLock); }
// ----------------------------------------------------------------------------
/** functions/key__functions__2_keys_caps/description
* Press the given keycode, and also press "capslock" if this is the second
* consecutive time this function has been called with `pressed == true`.
*
* Notes:
* - Meant to be used with the left and right "shift" keys.
*/
void KF(2_keys_capslock)(bool pressed, uint8_t keycode) {
static counter = 0;
if (pressed) {
counter++;
KF(press)(keycode);
}
if (counter == 2 && pressed) {
KF(toggle_capslock)();
}
if (!pressed) {
counter--;
KF(release)(keycode);
}
}
// ----------------------------------------------------------------------------
// --- default key definitions ------------------------------------------------
#include "../../../../firmware/lib/layout/keys.h"
// --- special meaning --------------------------------------------------------
/** keys/transp/description
* transparent
*
* This key signals to the firmware (specifically the
* `kb__layout__exec_key_location()` function) that it should look for what key
* to "press" or "release" by going down the layer-stack until it finds a
* non-transparent key at the same position.
*
* Notes:
* - Keys may be half transparent; that is, the "press" part of a key may be
* transparent while the "release" part isn't, or vice versa. I expect this
* to be fairly uncommon though.
*/
#define keys__press__transp NULL
#define keys__release__transp NULL
/** keys/nop/desctiption
* no operation
*
* This key does nothing (and is not transparent).
*/
void P(nop) (void) {}
void R(nop) (void) {}
// --- special keycode --------------------------------------------------------
KEYS__DEFAULT( power, KEY__Power );
KEYS__DEFAULT( volumeU, KEY__VolumeUp );
KEYS__DEFAULT( volumeD, KEY__VolumeDown );
KEYS__DEFAULT( mute, KEY__Mute );
// --- special function -------------------------------------------------------
/** keys/shL2kcaps/description
* left shift + toggle capslock (if both shifts are pressed)
*
* This key always generates a left shift. If the `shR2kcaps` is pressed at
* the same time, "capslock" will be toggled.
*/
void P(shL2kcaps) (void) { KF(2_keys_capslock)(true, KEY__LeftShift); }
void R(shL2kcaps) (void) { KF(2_keys_capslock)(false, KEY__LeftShift); }
/** keys/shR2kcaps/description
* right shift + toggle capslock (if both shifts are pressed)
*
* This key always generates a right shift. If the `shL2kcaps` is pressed at
* the same time, "capslock" will be toggled.
*/
void P(shR2kcaps) (void) { KF(2_keys_capslock)(true, KEY__RightShift); }
void R(shR2kcaps) (void) { KF(2_keys_capslock)(false, KEY__RightShift); }
/** keys/btldr/description
* jump to the bootloader
*
* This prepares the Teensy to load a new firmware. If you press this without
* meaning to, you must turn your keyboard off then on again (usually by
* unplugging it, then plugging it back in)
*/
void P(btldr) (void) { KF(jump_to_bootloader)(); }
void R(btldr) (void) {}
// ----------------------------------------------------------------------------
// --- layer ------------------------------------------------------------------
// note: these are just some default layer key definitions; no need to stick to
// them if they're inconvenient
KEYS__LAYER__PUSH_POP(0, 0);
#define keys__press__lpu0l0 P(lpupo0l0)
#define keys__release__lpu0l0 P(nop)
#define keys__press__lpo0l0 R(lpupo0l0)
#define keys__release__lpo0l0 P(nop)
KEYS__LAYER__PUSH_POP(1, 1);
#define keys__press__lpu1l1 P(lpupo1l1)
#define keys__release__lpu1l1 P(nop)
#define keys__press__lpo1l1 R(lpupo1l1)
#define keys__release__lpo1l1 P(nop)
KEYS__LAYER__PUSH_POP(2, 2);
#define keys__press__lpu2l2 P(lpupo2l2)
#define keys__release__lpu2l2 P(nop)
#define keys__press__lpo2l2 R(lpupo2l2)
#define keys__release__lpo2l2 P(nop)
KEYS__LAYER__PUSH_POP(3, 3);
#define keys__press__lpu3l3 P(lpupo3l3)
#define keys__release__lpu3l3 P(nop)
#define keys__press__lpo3l3 R(lpupo3l3)
#define keys__release__lpo3l3 P(nop)
KEYS__LAYER__PUSH_POP(4, 4);
#define keys__press__lpu4l4 P(lpupo4l4)
#define keys__release__lpu4l4 P(nop)
#define keys__press__lpo4l4 R(lpupo4l4)
#define keys__release__lpo4l4 P(nop)
KEYS__LAYER__PUSH_POP(5, 5);
#define keys__press__lpu5l5 P(lpupo5l5)
#define keys__release__lpu5l5 P(nop)
#define keys__press__lpo5l5 R(lpupo5l5)
#define keys__release__lpo5l5 P(nop)
KEYS__LAYER__PUSH_POP(6, 6);
#define keys__press__lpu6l6 P(lpupo6l6)
#define keys__release__lpu6l6 P(nop)
#define keys__press__lpo6l6 R(lpupo6l6)
#define keys__release__lpo6l6 P(nop)
KEYS__LAYER__PUSH_POP(7, 7);
#define keys__press__lpu7l7 P(lpupo7l7)
#define keys__release__lpu7l7 P(nop)
#define keys__press__lpo7l7 R(lpupo7l7)
#define keys__release__lpo7l7 P(nop)
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__KEYS__C__H

View File

@ -9,8 +9,8 @@
*/
#ifndef ERGODOX_FIRMWARE__FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__MATRIX__H
#define ERGODOX_FIRMWARE__FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__MATRIX__H
#ifndef ERGODOX_FIRMWARE__FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__MATRIX__H
#define ERGODOX_FIRMWARE__FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__MATRIX__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
@ -46,40 +46,43 @@
* right hand : rows 0..5, cols 7..D
* ----------------------------------------------------
*/
#define MATRIX_LAYER( \
/* for unused positions */ \
na, \
\
/* left hand, spatial positions */ \
k50,k51,k52,k53,k54,k55,k56, \
k40,k41,k42,k43,k44,k45,k46, \
k30,k31,k32,k33,k34,k35, \
k20,k21,k22,k23,k24,k25,k26, \
k10,k11,k12,k13,k14, \
k05,k06, \
k15,k16,k04, \
k03,k02,k01, \
\
/* right hand, spatial positions */ \
k57,k58,k59,k5A,k5B,k5C,k5D, \
k47,k48,k49,k4A,k4B,k4C,k4D, \
k38,k39,k3A,k3B,k3C,k3D, \
k27,k28,k29,k2A,k2B,k2C,k2D, \
k19,k1A,k1B,k1C,k1D, \
k07,k08, \
k09,k17,k18, \
k0C,k0B,k0A ) \
\
/* matrix positions */ \
{{ na,k01,k02,k03,k04,k05,k06, k07,k08,k09,k0A,k0B,k0C, na }, \
{ k10,k11,k12,k13,k14,k15,k16, k17,k18,k19,k1A,k1B,k1C,k1D }, \
{ k20,k21,k22,k23,k24,k25,k26, k27,k28,k29,k2A,k2B,k2C,k2D }, \
{ k30,k31,k32,k33,k34,k35, na, na,k38,k39,k3A,k3B,k3C,k3D }, \
{ k40,k41,k42,k43,k44,k45,k46, k47,k48,k49,k4A,k4B,k4C,k4D }, \
{ k50,k51,k52,k53,k54,k55,k56, k57,k58,k59,k5A,k5B,k5C,k5D }}
#define MATRIX_LAYER( \
/* the name of a macro to call on all arguments */ \
M, \
\
/* for unused positions */ \
na, \
\
/* left hand, spatial positions */ \
k50,k51,k52,k53,k54,k55,k56, \
k40,k41,k42,k43,k44,k45,k46, \
k30,k31,k32,k33,k34,k35, \
k20,k21,k22,k23,k24,k25,k26, \
k10,k11,k12,k13,k14, \
k05,k06, \
k15,k16,k04, \
k03,k02,k01, \
\
/* right hand, spatial positions */ \
k57,k58,k59,k5A,k5B,k5C,k5D, \
k47,k48,k49,k4A,k4B,k4C,k4D, \
k38,k39,k3A,k3B,k3C,k3D, \
k27,k28,k29,k2A,k2B,k2C,k2D, \
k19,k1A,k1B,k1C,k1D, \
k07,k08, \
k09,k17,k18, \
k0C,k0B,k0A ) \
\
/* matrix positions */ \
{{ M( na),M(k01),M(k02),M(k03),M(k04),M(k05),M(k06), M(k07),M(k08),M(k09),M(k0A),M(k0B),M(k0C),M( na) }, \
{ M(k10),M(k11),M(k12),M(k13),M(k14),M(k15),M(k16), M(k17),M(k18),M(k19),M(k1A),M(k1B),M(k1C),M(k1D) }, \
{ M(k20),M(k21),M(k22),M(k23),M(k24),M(k25),M(k26), M(k27),M(k28),M(k29),M(k2A),M(k2B),M(k2C),M(k2D) }, \
{ M(k30),M(k31),M(k32),M(k33),M(k34),M(k35),M( na), M( na),M(k38),M(k39),M(k3A),M(k3B),M(k3C),M(k3D) }, \
{ M(k40),M(k41),M(k42),M(k43),M(k44),M(k45),M(k46), M(k47),M(k48),M(k49),M(k4A),M(k4B),M(k4C),M(k4D) }, \
{ M(k50),M(k51),M(k52),M(k53),M(k54),M(k55),M(k56), M(k57),M(k58),M(k59),M(k5A),M(k5B),M(k5C),M(k5D) }}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__MATRIX__H
#endif // ERGODOX_FIRMWARE__FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__COMMON__MATRIX__H

View File

@ -1,114 +0,0 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* This file implements and extends the definitions in ".../lib/layout/keys.h"
*/
#ifndef ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__KEYS__H
#define ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__KEYS__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include "./common.h"
// ----------------------------------------------------------------------------
#define P(name) keys__press__##name
#define R(name) keys__release__##name
#define F(name) keys__function__##name
// "key"; to help with putting the keys into the layout matrix
#define K(name) { &P(name), &R(name) }
// ----------------------------------------------------------------------------
// note: needed by ".../lib/layout/keys.h"
#define KEYS__DEFAULT(name, value) \
void P(name) (void) { F(press)(value); } \
void R(name) (void) { F(release)(value); }
// note: needed by ".../lib/layout/keys.h"
#define KEYS__SHIFTED(name, value) \
void P(name) (void) { F(press)(KEY__LeftShift); \
F(press)(value); } \
void R(name) (void) { F(release)(value); \
F(release)(KEY__LeftShift); }
// ----------------------------------------------------------------------------
void F(press) (uint8_t keycode) { usb__kb__set_key(true, keycode); }
void F(release) (uint8_t keycode) { usb__kb__set_key(false, keycode); }
void F(toggle)(uint8_t keycode) {
if (usb__kb__read_key(keycode))
usb__kb__set_key(false, keycode);
else
usb__kb__set_key(true, keycode);
}
void F(2_keys_caps)(bool pressed, uint8_t keycode) {
static counter = 0;
if (pressed) {
counter++;
kf__press(keycode);
}
if (counter == 2 && pressed) {
kf__toggle_capslock();
}
if (!pressed) {
counter--;
kf__release(keycode);
}
}
// ----------------------------------------------------------------------------
// --- default key definitions ------------------------------------------------
#include "../../../../firmware/lib/layout/keys.h"
// --- special meaning --------------------------------------------------------
// transp : transparent
#define keys__press__transp NULL
#define keys__release__transp NULL
// nop : no operation
void P(nop) (void) {}
void R(nop) (void) {}
// --- special keycode --------------------------------------------------------
KEYS__DEFAULT( power, KEY__Power );
KEYS__DEFAULT( volumeU, KEY__VolumeUp );
KEYS__DEFAULT( volumeD, KEY__VolumeDown );
KEYS__DEFAULT( mute, KEY__Mute );
// --- special function -------------------------------------------------------
// shL2kcaps : left shift + toggle capslock (if both shifts are pressed)
void P(shL2kcaps) (void) { F(2_keys_caps)(true, KEY__LeftShift); }
void R(shL2kcaps) (void) { F(2_keys_caps)(false, KEY__LeftShift); }
// shR2kcaps : right shift + toggle capslock (if both shifts are pressed)
void P(shR2kcaps) (void) { F(2_keys_caps)(true, KEY__RightShift); }
void R(shR2kcaps) (void) { F()2_keys_caps(false, KEY__RightShift); }
// btldr : jump to the bootloader
void P(btldr) (void) { kf__jump_to_bootloader(); }
void R(btldr) (void) {}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__KEYBOARD__ERGODOX__LAYOUT__DEFAULT__KEYS__H

View File

@ -9,10 +9,13 @@
* the symbol keys on the function layer was taken from the Arensito layout.
*
* Implements the "layout" section of '.../firmware/keyboard.h'
*
* TODO: put a note about where to look for more information if people are
* trying to make their own layout
*/
#include "./default/common.h"
#include "./common/definitions.h"
// ----------------------------------------------------------------------------
@ -51,135 +54,116 @@ void kb__led__logical_off(char led) {
// keys
// ----------------------------------------------------------------------------
#include "./default/keys.h"
#include "./common/keys.c.h"
// layer
KEY_T L0pu1 = { &kf__layer__push, 0x0001, NULL, 0 };
KEY_T L0po = { &kf__layer__pop, 0x0000, NULL, 0 };
KEY_T L0pu1po = { &kf__layer__push, 0x0001, &kf__layer__pop, 0x0001 };
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 };
KEYS__LAYER__NUM_PUSH(10, 3);
KEYS__LAYER__NUM_POP(10);
// ----------------------------------------------------------------------------
// layout
// ----------------------------------------------------------------------------
#include "./default/matrix.h"
#include "./common/matrix.h"
KEY_T layout[][KB__ROWS][KB__COLUMNS] = {
layout_t layout = {
// ............................................................................
MATRIX_LAYER( // layer 0 : default
// unused
NA,
// macro, unused,
K, nop,
// left hand ...... ......... ......... ......... ......... ......... .........
Equal, K1, K2, K3, K4, K5, Esc,
Bkslash, Q, W, E, R, T, L0pu1,
Tab, A, S, D, F, G,
Sh2KCapL, Z, X, C, V, B, L0pu1po,
GUIL, Grave, Bkslash, ArrowL, ArrowR,
CtrlL, AltL,
NA, NA, Home,
Bs, Del, End,
equal, 1, 2, 3, 4, 5, esc,
bkslash, q, w, e, r, t, lpu1l1,
tab, a, s, d, f, g,
sh2KCapL, z, x, c, v, b, lpupo1l1,
guiL, grave, bkslash, arrowL, arrowR,
ctrlL, altL,
nop, nop, home,
bs, del, end,
// right hand ..... ......... ......... ......... ......... ......... .........
NumPush, K6, K7, K8, K9, K0, Dash,
// capslock)
BrktL, Y, U, I, O, P, BrktR,
H, J, K, L, Semicol, Quote,
L0pu1po, N, M, Comma, Period, Slash, Sh2KCapR,
ArrowL, ArrowD, ArrowU, ArrowR, GUIR,
AltR, CtrlR,
PageU, NA, NA,
PageD, Enter, Space ),
numPush, 6, 7, 8, 9, 0, dash,
brktL, y, u, i, o, p, brktR,
h, j, k, l, semicol, quote,
lpupo1l1, n, m, comma, period, slash, sh2KCapR,
arrowL, arrowD, arrowU, arrowR, guiR,
altR, ctrlR,
pageU, nop, nop,
pageD, enter, space ),
// ............................................................................
MATRIX_LAYER( // layer 1 : function and symbol keys
// unused
NA,
// macro, unused,
K, nop,
// left hand ...... ......... ......... ......... ......... ......... .........
NA, F1, F2, F3, F4, F5, F11,
Transp, BraceL, BraceR, BrktL, BrktR, NA, L0po,
Transp, Semicol, Slash, Dash, KP0, Colon,
Transp, KP6, KP7, KP8, KP9, Plus, L1pu2po,
Transp, Transp, Transp, Transp, Transp,
Transp, Transp,
Transp, Transp, Transp,
Transp, Transp, Transp,
nop, F1, F2, F3, F4, F5, F11,
transp, braceL, braceR, brktL, brktR, nop, lpo1l1,
transp, semicol, slash, dash, kp0, colon,
transp, kp6, kp7, kp8, kp9, plus, lpupo2l2,
transp, transp, transp, transp, transp,
transp, transp,
transp, transp, transp,
transp, transp, transp,
// right hand ..... ......... ......... ......... ......... ......... .........
F12, F6, F7, F8, F9, F10, Power,
Transp, NA, Undersc, LessThan, GrtrThan, Dollar, VolumeU,
Bkslash, KP1, ParenL, ParenR, Equal, VolumeD,
L1pu2po, Asterisk, KP2, KP3, KP4, KP5, Mute,
Transp, Transp, Transp, Transp, Transp,
Transp, Transp,
Transp, Transp, Transp,
Transp, Transp, Transp ),
F12, F6, F7, F8, F9, F10, power,
transp, nop, undersc, lessThan, grtrThan, dollar, volumeU,
bkslash, kp1, parenL, parenR, equal, volumeD,
lpupo2l2, asterisk, kp2, kp3, kp4, kp5, mute,
transp, transp, transp, transp, transp,
transp, transp,
transp, transp, transp,
transp, transp, transp ),
// ............................................................................
MATRIX_LAYER( // layer 2 : keyboard functions
// unused
NA,
// macro, unused,
K, nop,
// left hand ...... ......... ......... ......... ......... ......... .........
Btldr, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA,
NA, NA,
NA, NA, NA,
NA, NA, NA,
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 ..... ......... ......... ......... ......... ......... .........
NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA,
NA, NA,
NA, NA, NA,
NA, NA, NA ),
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 3 : numpad
// unused
NA,
// 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,
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 ),
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 ),
// ............................................................................
};

View File

@ -5,13 +5,9 @@
* ------------------------------------------------------------------------- */
/** description
* Some generally useful key-functions, and related definitions
* Some generally useful functions to aid in creating keys
*
* Prefix: `kf__`
*
* Notes:
* - Several of these functions depend on the fact that (on an AVR) pointers
* are 16-bit.
* Prefix: `key_functions__`
*/
@ -24,30 +20,16 @@
// ----------------------------------------------------------------------------
typedef void (*kf__function_pointer_t)(uint16_t value);
// basic
void key_functions__press (uint8_t keycode);
void key_functions__release (uint8_t keycode);
void key_functions__toggle (uint8_t keycode);
// ----------------------------------------------------------------------------
// TODO: switch to using two functions per key. pay *careful* attention to how
// much space the functions are likely to use, lol (but, a function that simply
// calls another function with one argument looks like it might be only 4
// bytes? which is just fine)
//
// also, think about how to best implement
// - macros
// - chords
// - sticky keys
// TODO: kf__macro__eeprom
// - this should probably go into its own little place in 'lib'; it'll need a
// function to write the macro to memory, code to keep track of what's
// written in the eeprom, and stuff like that
//
// device
void kf__jump_to_bootloader (uint16_t ignore);
void key_functions__jump_to_bootloader (void);
// special
void kf__toggle_capslock (uint16_t ignore);
void key_functions__toggle_capslock (void);
// ----------------------------------------------------------------------------
@ -60,157 +42,56 @@ void kf__toggle_capslock (uint16_t ignore);
// === documentation ==========================================================
// ============================================================================
// ----------------------------------------------------------------------------
// typedefs -------------------------------------------------------------------
// ----------------------------------------------------------------------------
// === kf__function_pointer_t ===
/** typedefs/kf__function_pointer_t/description
* The pointer type for all key-functions
*
* Notes:
* - All key-functions must have the same type so that we can easily store
* pointers to them, and call them using the pointers without knowing which
* function specifically is being pointed to.
*/
// ----------------------------------------------------------------------------
// functions ------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// basic ----------------------------------------------------------------------
// === kf__press() ===
/** functions/kf__press/description
// === key_functions__press() ===
/** functions/key_functions__press/description
* Generate a normal keypress (and send the USB report).
*
* Arguments:
* - `keycode`: The keycode to "press"
*/
// === kf__release() ===
/** functions/kf__release/description
// === key_functions__release() ===
/** functions/key_functions__release/description
* Generate a normal keyrelease (and send the USB report).
*
* Arguments:
* - `keycode`: The keycode to "release"
*/
// === kf__toggle() ===
/** functions/kf__toggle/description
// === key_functions__toggle() ===
/** functions/key_functions__toggle/description
* Toggle the key pressed or unpressed.
*
* Arguments:
* - `keycode`: The keycode to "toggle"
*/
// === kf__layer__push() ===
/** functions/kf__layer__push/description
* If no other layer element with the given ID exists, push a layer element
* with the given ID and layer number to the top of the stack. If a layer
* element with the given ID does already exist, update that element with the
* given layer number.
*
* Arguments:
* - `id__layer`:
* - `id`: The high byte of this `uint16_t` argument. The ID of the layer
* element to push.
* - `layer`: The low byte of this `uint16_t` argument. The layer number
* of the layer to push.
*/
// === kf__layer__pop() ===
/** functions/kf__layer__pop/description
* Pop the layer element with the given ID out of the layer stack (no matter
* where it is, but without touching the order of any of the other elements),
* if it exists.
*
* Arguments:
* - `id__layer`:
* - `id`: The high byte of this `uint16_t` argument. The ID of the layer
* element to pop.
* - `ignore`: The low byte of this `uint16_t` argument. To be ignored.
*/
// === kf__macro__sram() ===
/** functions/kf__macro__sram/description
* Execute the macro at the given location in SRAM.
*
* Arguments:
* - `pointer`: A pointer to the location in SRAM where the macro begins
*
* Notes:
* - Macros are arrays of `uint16_t`s with the following format:
* - `[0]`: A count of how many ("function pointer", "argument") pairs
* follow
* - `[1]`: A pointer to a key-function
* - `[2]`: The argument to be passed to the preceding key-function
* - ...
*/
// === kf__macro__progmem() ===
/** functions/kf__macro__progmem/description
* Execute the macro at the given location in PROGMEM.
*
* Arguments:
* - `pointer`: A pointer to the location in PROGMEM where the macro begins
*
* Notes:
* - Macros are arrays of `uint16_t`s with the following format:
* - `[0]`: A count of how many ("function pointer", "argument") pairs
* follow
* - `[1]`: A pointer to a key-function
* - `[2]`: The argument to be passed to the preceding key-function
* - ...
*/
// === kf__macro__eeprom() ===
/** functions/kf__macro__eeprom/description
* Execute the macro at the given location in the EEPROM.
*
* Arguments:
* - `pointer`: A pointer to the location in the EEPROM where the macro begins
*
* Notes:
* - Macros are arrays of `uint16_t`s with the following format:
* - `[0]`: A count of how many ("function pointer", "argument") pairs
* follow
* - `[1]`: A pointer to a key-function
* - `[2]`: The argument to be passed to the preceding key-function
* - ...
*/
// ----------------------------------------------------------------------------
// device ---------------------------------------------------------------------
// === kf__jump_to_bootloader() ===
/** functions/kf__jump_to_bootloader/description
// === key_functions__jump_to_bootloader() ===
/** functions/key_functions__jump_to_bootloader/description
* For reflashing the controller.
*
* Arguments:
* - `ignore`: [ignore]
*/
// ----------------------------------------------------------------------------
// special --------------------------------------------------------------------
// === kf__toggle_capslock() ===
/** functions/kf__toggle_capslock/description
// === key_functions__toggle_capslock() ===
/** functions/key_functions__toggle_capslock/description
* Toggle the state of 'capslock'
*
* Arguments:
* - `ignore`: [ignore]
*
* Notes:
* - This requires special handling because neither of the shift keys may be
* active when 'capslock' is pressed, or it will not register properly. This
* function disables both shift keys, toggles 'capslock', and then restores
* the state of both shift keys before exiting.
* the state of both shift keys.
*/

View File

@ -0,0 +1,34 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2012, 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* Implements the "basic" section of
* ".../firmware/lib/layout/key-functions.h"
*/
#include <stdbool.h>
#include <stdint.h>
#include "../../../../firmware/lib/usb.h"
#include "../../../../firmware/lib/usb/usage-page/keyboard.h"
// ----------------------------------------------------------------------------
void key_functions__press(uint8_t keycode) {
usb__kb__set_key(true, keycode);
}
void key_functions__release(uint8_t keycode) {
usb__kb__set_key(false, keycode);
}
void key_functions__toggle(uint8_t keycode) {
if (usb__kb__read_key(keycode))
usb__kb__set_key(false, keycode);
else
usb__kb__set_key(true, keycode);
}

View File

@ -7,6 +7,7 @@
/** description
* Implements the "device" section of
* ".../firmware/lib/layout/key-functions.h"
* for the ATMega23U4
*/

View File

@ -12,4 +12,5 @@
SRC += $(wildcard *.c)
SRC += $(wildcard device/$(MCU).c)

View File

@ -12,7 +12,7 @@
* order to centralize a bit of code that would otherwise be duplicated by most
* layouts.
*
* Prefixes: `KEYS__`, [none]
* Prefixes: `keys__`, [none]
*
* Usage: `#define` `KEYS__DEFAULT` and `KEYS__SHIFTED` before `#include`ing.
*/