From 16dc913f748dc34c580ec86fbb7bfc0b78a2a50c Mon Sep 17 00:00:00 2001 From: David Fenyes Date: Wed, 19 Feb 2020 23:28:14 -0600 Subject: [PATCH] Added functions to change keymaps - asdf_keymaps_select_keymap() function to select a keymap - asdf_keymaps_select_n_{set|clear} functions to set a bit in keymap number, to support dip switches. --- firmware/asdf/src/asdf.c | 37 ++++++- firmware/asdf/src/asdf.h | 26 ++++- firmware/asdf/src/asdf_keymaps.c | 166 ++++++++++++++++++++++++++++++- firmware/asdf/src/asdf_keymaps.h | 74 +++++++++++++- firmware/asdf/src/main.c | 2 +- 5 files changed, 297 insertions(+), 8 deletions(-) diff --git a/firmware/asdf/src/asdf.c b/firmware/asdf/src/asdf.c index f2ec66c..04b8969 100644 --- a/firmware/asdf/src/asdf.c +++ b/firmware/asdf/src/asdf.c @@ -80,7 +80,7 @@ void asdf_put_code(asdf_keycode_t code) asdf_buffer_put(asdf_keycode_buffer, code); } -// PROCEDURE: asdf_get_code +// PROCEDURE: asdf_next_code // INPUTS: none // OUTPUTS: (asdf_keycode_t) returns next value in buffer. // @@ -94,7 +94,7 @@ void asdf_put_code(asdf_keycode_t code) // // COMPLEXITY: 1 // -asdf_keycode_t asdf_get_code(void) +asdf_keycode_t asdf_next_code(void) { return asdf_buffer_get(asdf_keycode_buffer); } @@ -164,6 +164,22 @@ static void asdf_activate_action(action_t keycode) asdf_send_reset(); break; } + case ACTION_MAPSEL_0: { + asdf_keymaps_map_select_0_set(); + break; + } + case ACTION_MAPSEL_1: { + asdf_keymaps_map_select_1_set(); + break; + } + case ACTION_MAPSEL_2: { + asdf_keymaps_map_select_2_set(); + break; + } + case ACTION_MAPSEL_3: { + asdf_keymaps_map_select_3_set(); + break; + } case ACTION_NOTHING: case ACTION_LOCAL: case ACTION_BREAK: @@ -218,6 +234,23 @@ static void asdf_deactivate_action(action_t keycode) } case ACTION_REPEAT: { asdf_repeat_deactivate(); + break; + } + case ACTION_MAPSEL_0: { + asdf_keymaps_map_select_0_clear(); + break; + } + case ACTION_MAPSEL_1: { + asdf_keymaps_map_select_1_clear(); + break; + } + case ACTION_MAPSEL_2: { + asdf_keymaps_map_select_2_clear(); + break; + } + case ACTION_MAPSEL_3: { + asdf_keymaps_map_select_3_clear(); + break; } case ACTION_NOTHING: case ACTION_LOCAL: diff --git a/firmware/asdf/src/asdf.h b/firmware/asdf/src/asdf.h index 16b785d..4a7d193 100644 --- a/firmware/asdf/src/asdf.h +++ b/firmware/asdf/src/asdf.h @@ -50,6 +50,10 @@ typedef enum { ACTION_HERE_IS, ACTION_CLEAR, ACTION_RESET, + ACTION_MAPSEL_0, + ACTION_MAPSEL_1, + ACTION_MAPSEL_2, + ACTION_MAPSEL_3, ACTION_FN_1, ACTION_FN_2, ACTION_FN_3, @@ -59,7 +63,23 @@ typedef enum { ACTION_FN_7, ACTION_FN_8, ACTION_FN_9, - ACTION_FN_10 + ACTION_FN_10, + RESERVED_1, + RESERVED_2, + RESERVED_3, + RESERVED_4, + RESERVED_5, + RESERVED_6, + RESERVED_7, + RESERVED_8, + RESERVED_9, + RESERVED_10, + RESERVED_11, + RESERVED_12, + RESERVED_13, + RESERVED_14, + RESERVED_15, + RESERVED_16 } action_t; @@ -85,11 +105,11 @@ void asdf_keyscan(void); // NOTES: If buffer is full, silently drop the code. void asdf_put_code(asdf_keycode_t code); -// PROCEDURE: asdf_get_code +// PROCEDURE: asdf_next_code // INPUTS: none // OUTPUTS: (asdf_keycode_t) returns next value in buffer. // DESCRIPTION: Takes a keycode argument and buffers for output. -asdf_keycode_t asdf_get_code(void); +asdf_keycode_t asdf_next_code(void); #endif // !defined (ASDF_H) diff --git a/firmware/asdf/src/asdf_keymaps.c b/firmware/asdf/src/asdf_keymaps.c index 9da3952..f5e4a4e 100644 --- a/firmware/asdf/src/asdf_keymaps.c +++ b/firmware/asdf/src/asdf_keymaps.c @@ -80,6 +80,167 @@ void asdf_keymaps_select_keymap(uint8_t index) // void asdf_keymaps_init(void) { + asdf_keymaps_select_keymap(0); +} + +// PROCEDURE: asdf_keymaps_map_select_0_clear +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: called when map select 0 switch is open. Clears the 0 bit in the +// keymap index. +// +// SIDE EFFECTS: changes selected keymap +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_keymaps_map_select_0_clear(void) +{ + asdf_keymaps_select_keymap(keymap_index & (~ASDF_KEYMAP_BIT_0)); +} + +// PROCEDURE: asdf_keymaps_map_select_0_set +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: called when map select 0 switch is closed. Sets the 0 bit in the +// keymap index. +// +// SIDE EFFECTS: changes selected keymap +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_keymaps_map_select_0_set(void) +{ + asdf_keymaps_select_keymap(keymap_index | ASDF_KEYMAP_BIT_0); +} + +// PROCEDURE: asdf_keymaps_map_select_1_clear +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: called when map select 1 switch is open. Clears the 1 bit in the +// keymap index. +// +// SIDE EFFECTS: changes selected keymap +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_keymaps_map_select_1_clear(void) +{ + asdf_keymaps_select_keymap(keymap_index & (~ASDF_KEYMAP_BIT_1)); +} + +// PROCEDURE: asdf_keymaps_map_select_1_set +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: called when map select 1 switch is closed. Sets the 1 bit in the +// keymap index. +// +// SIDE EFFECTS: changes selected keymap +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_keymaps_map_select_1_set(void) +{ + asdf_keymaps_select_keymap(keymap_index | ASDF_KEYMAP_BIT_1); +} + +// PROCEDURE: asdf_keymaps_map_select_2_clear +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: called when map select 2 switch is open. Clears the 2 bit in the +// keymap index. +// +// SIDE EFFECTS: changes selected keymap +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_keymaps_map_select_2_clear(void) +{ + asdf_keymaps_select_keymap(keymap_index & (~ASDF_KEYMAP_BIT_2)); +} + +// PROCEDURE: asdf_keymaps_map_select_2_set +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: called when map select 2 switch is closed. Sets the 2 bit in the +// keymap index. +// +// SIDE EFFECTS: changes selected keymap +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_keymaps_map_select_2_set(void) +{ + asdf_keymaps_select_keymap(keymap_index | ASDF_KEYMAP_BIT_2); +} + +// PROCEDURE: asdf_keymaps_map_select_3_clear +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: called when map select 3 switch is open. Clears the 3 bit in the +// keymap index. +// +// SIDE EFFECTS: changes selected keymap +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_keymaps_map_select_3_clear(void) +{ + asdf_keymaps_select_keymap(keymap_index & (~ASDF_KEYMAP_BIT_3)); +} + +// PROCEDURE: asdf_keymaps_map_select_3_set +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: called when map select 3 switch is closed. Sets the 3 bit in the +// keymap index. +// +// SIDE EFFECTS: changes selected keymap +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_keymaps_map_select_3_set(void) +{ + asdf_keymaps_select_keymap(keymap_index | ASDF_KEYMAP_BIT_3); } // PROCEDURE: asdf_keymaps_get_code @@ -94,12 +255,15 @@ void asdf_keymaps_init(void) // // SCOPE: public // +// NOTES: Since the first value in each row is the physical row number, we add 1 +// to the column number to read the code for a given row and column number. +// // COMPLEXITY: 1 // asdf_keycode_t asdf_keymaps_get_code(const uint8_t row, const uint8_t col, const uint8_t modifier_index) { - const keycode_matrix_t *matrix = modifier_matrix[modifier_index]; + const keycode_matrix_t *matrix = keymap_matrix[keymap_index][modifier_index]; return FLASH_READ_MATRIX_ELEMENT(*matrix, row, col); } diff --git a/firmware/asdf/src/asdf_keymaps.h b/firmware/asdf/src/asdf_keymaps.h index c612633..be29dfa 100644 --- a/firmware/asdf/src/asdf_keymaps.h +++ b/firmware/asdf/src/asdf_keymaps.h @@ -27,6 +27,78 @@ #if !defined(ASDF_KEYMAPS_H) #define ASDF_KEYMAPS_H + + +#define ASDF_KEYMAP_BIT_0 1 +#define ASDF_KEYMAP_BIT_1 2 +#define ASDF_KEYMAP_BIT_2 4 +#define ASDF_KEYMAP_BIT_3 8 + +// PROCEDURE: asdf_keymaps_select_keymap +// INPUTS: (uint8_t) index - index of the keymap number to select +// OUTPUTS: none +// DESCRIPTION: accepts a index value. If the requested keymap index is valid, +// then assign the value to the global (to the module) keymap_index variable. If +// requested index is not valid then do nothing. +void asdf_keymaps_select_keymap(uint8_t index); + +// PROCEDURE: asdf_keymaps_map_select_0_clear +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: called when map select 0 switch is open. Clears the 0 bit in the +// keymap index. +void asdf_keymaps_map_select_0_clear(void); + + +// PROCEDURE: asdf_keymaps_map_select_0_set +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: called when map select 0 switch is closed. Sets the 0 bit in the +// keymap index, if the resulting keymap index is valid. Otherwise do nothing. +void asdf_keymaps_map_select_0_set(void); + +// PROCEDURE: asdf_keymaps_map_select_1_clear +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: called when map select 1 switch is open. Clears the 1 bit in the +// keymap index. +void asdf_keymaps_map_select_1_clear(void); + +// PROCEDURE: asdf_keymaps_map_select_1_set +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: called when map select 1 switch is closed. Sets the 0 bit in the +// keymap index, if the resulting keymap index is valid. Otherwise do nothing. +void asdf_keymaps_map_select_1_set(void); + +// PROCEDURE: asdf_keymaps_map_select_2_clear +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: called when map select 2 switch is open. Clears the 2 bit in the +// keymap index. +void asdf_keymaps_map_select_2_clear(void); + +// PROCEDURE: asdf_keymaps_map_select_2_set +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: called when map select 2 switch is closed. Sets the 0 bit in the +// keymap index, if the resulting keymap index is valid. Otherwise do nothing. +void asdf_keymaps_map_select_2_set(void); + +// PROCEDURE: asdf_keymaps_map_select_3_clear +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: called when map select 3 switch is open. Clears the 3 bit in the +// keymap index. +void asdf_keymaps_map_select_3_clear(void); + +// PROCEDURE: asdf_keymaps_map_select_3_set +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: called when map select 3 switch is closed. Sets the 0 bit in the +// keymap index, if the resulting keymap index is valid. Otherwise do nothing. +void asdf_keymaps_map_select_3_set(void); + // PROCEDURE: asdf_keymaps_init // INPUTS: none // OUTPUTS: none @@ -34,7 +106,7 @@ // index, to avoid hard-coding constant index values. void asdf_keymaps_init(void); -// PROCEDURE: asdf_keymaps_get_code +// PROCEDURE: asdf_keymaps_get_`code // INPUTS: row, col: row and column of key that has been pressed // modifiers_index: index into the keymap array, based on modifier state // OUTPUTS: returns a key code. diff --git a/firmware/asdf/src/main.c b/firmware/asdf/src/main.c index 5485941..da28aa4 100644 --- a/firmware/asdf/src/main.c +++ b/firmware/asdf/src/main.c @@ -68,7 +68,7 @@ int main(void) while (1) { if (asdf_arch_tick()) { - asdf_keycode_t code = asdf_get_code(); + asdf_keycode_t code = asdf_next_code(); if (code != ASDF_INVALID_CODE) { asdf_arch_send_code(code);