diff --git a/src/board/system76/addw2/include/board/keymap.h b/src/board/system76/addw2/include/board/keymap.h index 3365d34..4d94498 100644 --- a/src/board/system76/addw2/include/board/keymap.h +++ b/src/board/system76/addw2/include/board/keymap.h @@ -46,4 +46,12 @@ // Keymap extern uint16_t __xdata KEYMAP[KM_LAY][KM_OUT][KM_IN]; +// Position of physical Esc key in the matrix +#define MATRIX_ESC_INPUT 7 +#define MATRIX_ESC_OUTPUT 7 + +// Position of physical Fn key in the matrix +#define MATRIX_FN_INPUT 3 +#define MATRIX_FN_OUTPUT 17 + #endif // _BOARD_KEYMAP_H diff --git a/src/board/system76/bonw14/include/board/keymap.h b/src/board/system76/bonw14/include/board/keymap.h index a6f9984..f755148 100644 --- a/src/board/system76/bonw14/include/board/keymap.h +++ b/src/board/system76/bonw14/include/board/keymap.h @@ -48,4 +48,12 @@ // Keymap extern uint16_t __xdata KEYMAP[KM_LAY][KM_OUT][KM_IN]; +// Position of physical Esc key in the matrix +#define MATRIX_ESC_INPUT 0 +#define MATRIX_ESC_OUTPUT 6 + +// Position of physical Fn key in the matrix +#define MATRIX_FN_INPUT 0 +#define MATRIX_FN_OUTPUT 4 + #endif // _BOARD_KEYMAP_H diff --git a/src/board/system76/common/kbscan.c b/src/board/system76/common/kbscan.c index 1bb81bd..a3c61bd 100644 --- a/src/board/system76/common/kbscan.c +++ b/src/board/system76/common/kbscan.c @@ -27,6 +27,14 @@ uint16_t kbscan_repeat_delay = 500; uint8_t sci_extra = 0; +static inline bool matrix_position_is_esc(int row, int col) { + return (row == MATRIX_ESC_OUTPUT) && (col == MATRIX_ESC_INPUT); +} + +static inline bool matrix_position_is_fn(int row, int col) { + return (row == MATRIX_FN_OUTPUT) && (col == MATRIX_FN_INPUT); +} + void kbscan_init(void) { KSOCTRL = 0x05; KSICTRLR = 0x04; @@ -185,16 +193,12 @@ bool kbscan_press(uint16_t key, bool pressed, uint8_t * layer) { case (KT_NORMAL): if (kbscan_enabled) { kbc_scancode(&KBC, key, pressed); - if ((key & 0xFF) == K_ESC) - kbscan_esc_held = pressed; } break; case (KT_FN): if (layer != NULL) { if (pressed) *layer = 1; else *layer = 0; - - kbscan_fn_held = pressed; } else { // In the case no layer can be set, reset bit return false; @@ -332,6 +336,12 @@ void kbscan_event(void) { debounce = true; debounce_time = time_get(); + // Check keys used for config reset + if (matrix_position_is_esc(i, j)) + kbscan_esc_held = new_b; + if (matrix_position_is_fn(i, j)) + kbscan_fn_held = new_b; + // Handle key press/release if (new_b) { // On a press, cache the layer the key was pressed on diff --git a/src/board/system76/darp5/include/board/keymap.h b/src/board/system76/darp5/include/board/keymap.h index 3365d34..4d94498 100644 --- a/src/board/system76/darp5/include/board/keymap.h +++ b/src/board/system76/darp5/include/board/keymap.h @@ -46,4 +46,12 @@ // Keymap extern uint16_t __xdata KEYMAP[KM_LAY][KM_OUT][KM_IN]; +// Position of physical Esc key in the matrix +#define MATRIX_ESC_INPUT 7 +#define MATRIX_ESC_OUTPUT 7 + +// Position of physical Fn key in the matrix +#define MATRIX_FN_INPUT 3 +#define MATRIX_FN_OUTPUT 17 + #endif // _BOARD_KEYMAP_H diff --git a/src/board/system76/galp3-c/include/board/keymap.h b/src/board/system76/galp3-c/include/board/keymap.h index 2a21a4d..44e5819 100644 --- a/src/board/system76/galp3-c/include/board/keymap.h +++ b/src/board/system76/galp3-c/include/board/keymap.h @@ -44,4 +44,12 @@ // Keymap extern uint16_t __xdata KEYMAP[KM_LAY][KM_OUT][KM_IN]; +// Position of physical Esc key in the matrix +#define MATRIX_ESC_INPUT 7 +#define MATRIX_ESC_OUTPUT 7 + +// Position of physical Fn key in the matrix +#define MATRIX_FN_INPUT 0 +#define MATRIX_FN_OUTPUT 6 + #endif // _BOARD_KEYMAP_H diff --git a/src/board/system76/gaze15/include/board/keymap.h b/src/board/system76/gaze15/include/board/keymap.h index 3365d34..4d94498 100644 --- a/src/board/system76/gaze15/include/board/keymap.h +++ b/src/board/system76/gaze15/include/board/keymap.h @@ -46,4 +46,12 @@ // Keymap extern uint16_t __xdata KEYMAP[KM_LAY][KM_OUT][KM_IN]; +// Position of physical Esc key in the matrix +#define MATRIX_ESC_INPUT 7 +#define MATRIX_ESC_OUTPUT 7 + +// Position of physical Fn key in the matrix +#define MATRIX_FN_INPUT 3 +#define MATRIX_FN_OUTPUT 17 + #endif // _BOARD_KEYMAP_H diff --git a/src/board/system76/lemp9/include/board/keymap.h b/src/board/system76/lemp9/include/board/keymap.h index 439c260..a335a87 100644 --- a/src/board/system76/lemp9/include/board/keymap.h +++ b/src/board/system76/lemp9/include/board/keymap.h @@ -45,4 +45,12 @@ // Keymap extern uint16_t __xdata KEYMAP[KM_LAY][KM_OUT][KM_IN]; +// Position of physical Esc key in the matrix +#define MATRIX_ESC_INPUT 7 +#define MATRIX_ESC_OUTPUT 7 + +// Position of physical Fn key in the matrix +#define MATRIX_FN_INPUT 0 +#define MATRIX_FN_OUTPUT 6 + #endif // _BOARD_KEYMAP_H diff --git a/src/board/system76/oryp5/include/board/keymap.h b/src/board/system76/oryp5/include/board/keymap.h index 3365d34..4d94498 100644 --- a/src/board/system76/oryp5/include/board/keymap.h +++ b/src/board/system76/oryp5/include/board/keymap.h @@ -46,4 +46,12 @@ // Keymap extern uint16_t __xdata KEYMAP[KM_LAY][KM_OUT][KM_IN]; +// Position of physical Esc key in the matrix +#define MATRIX_ESC_INPUT 7 +#define MATRIX_ESC_OUTPUT 7 + +// Position of physical Fn key in the matrix +#define MATRIX_FN_INPUT 3 +#define MATRIX_FN_OUTPUT 17 + #endif // _BOARD_KEYMAP_H diff --git a/src/board/system76/oryp6/include/board/keymap.h b/src/board/system76/oryp6/include/board/keymap.h index 3365d34..4d94498 100644 --- a/src/board/system76/oryp6/include/board/keymap.h +++ b/src/board/system76/oryp6/include/board/keymap.h @@ -46,4 +46,12 @@ // Keymap extern uint16_t __xdata KEYMAP[KM_LAY][KM_OUT][KM_IN]; +// Position of physical Esc key in the matrix +#define MATRIX_ESC_INPUT 7 +#define MATRIX_ESC_OUTPUT 7 + +// Position of physical Fn key in the matrix +#define MATRIX_FN_INPUT 3 +#define MATRIX_FN_OUTPUT 17 + #endif // _BOARD_KEYMAP_H