WIP - non-compiling keymap updates

Please see ARCHITECTURE-keymaps.org for general idea and TODO list.
This commit is contained in:
David Fenyes 2021-02-17 11:27:58 -06:00 committed by Dave
parent 99610395fc
commit daa6ff672f
8 changed files with 152 additions and 105 deletions

View File

@ -0,0 +1,31 @@
* Keymap architecture
** Keymap definition module
The keymap definition module defines:
*** The key mappings used by a keymap
*** The virtual devices required by the keymap
This includes definitions for LED's and I/O lines, including their initial
states, and default I/O operations such as toggle, pulse, etc.
*** Function hooks used by the keymap.
Specifies which functions are used for operations such as key scanning, I/O,
special keybindings, etc.
Any special functions or logic required by the keymap are also defined and used in the module.
** Keymap definition API
*** mapping keys
#include "asdf_keymaps.h"
**** asdf_keymaps_add_map() - called from
Assigns a specified keymap matrix (ptr to FLASH) to a given keymap and modifier type.
*** adding virtual devices - called from keymap setup routine
**** asdf_virtual_init()
***** Clears the virtual device table for the keymap
***** initialize first entry in virtual device table to NULL
**** asdf_virtual_add_device()
***** Accept a virtual device code, a physical device code, a default function, and a default initial value, and create a new entry in the virtual device table.
***** increment the virtual device table pointer and set next (last) entry to NULL
* Eliminate keymaps table and instead have table of keymap init routines with MAX_KEYMAPS entries
* keymap setup routine adds maps for each modifier to the keymap, now only rxcxMODIFIERS instead of rxcxmodifiersxkeymaps
* remove the keymap index from the add_map() call.
* select_keymap() will call setup routine for the given keymap.
* Each keymap sets its own num_rows and num_columns, per matrix for each modifier

View File

@ -45,7 +45,7 @@ typedef void (*asdf_hook_function_t)(void);
typedef struct {
asdf_hook_id_t hook_id;
asdf_hook_function_t hook_func;
} asdf_hook_initializer_t;
b} asdf_hook_initializer_t;
// PROCEDURE: asdf_hook_execute

View File

@ -31,25 +31,11 @@
#include "asdf_modifiers.h"
// The keymap arrays organized as follows:
// * Each keymap matrix is a NUM_ROWS x NUM_COLS mapping of key to code for a given modifier.
// * `xm`Each keymap matrix is a NUM_ROWS x NUM_COLS mapping of key to code for a given modifier.
// * Each keymap contains a set of keymap matrices, one for each unique
// combination of modifier keys.
// * All the keymaps (NUM_KEYMAPS) are gathered in the keymap_matrixp[] array.
static asdf_keycode_matrix_t *keymap_matrix[ASDF_NUM_KEYMAPS][ASDF_MOD_NUM_MODIFIERS] = {};
// Each keymap (representing a keyboard configuration) has an associated set of
// virtual device initializers that set up the I/O and LED lines for the
// keyboard, unique to each keymap. This builds the virtual device initializer
// array from the initializer definitions in the keymap definition files.
static asdf_virtual_initializer_t
keymap_initializer_list[ASDF_NUM_KEYMAPS][ASDF_KEYMAP_INITIALIZER_LENGTH] = {};
// Each keymap (representing a keyboard configuration) has an associated set of
// function hooks unique to the keyboard defined by the map. This builds the
// function hook initializer array from the definitions in the keymap definition
// files.
static asdf_hook_initializer_t
keymap_hook_initializer_list[ASDF_NUM_KEYMAPS][ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH] = {};
static asdf_keycode_matrix_t *keymap_matrix[ASDF_MOD_NUM_MODIFIERS] = {};
// Index of the currently active keymap, initialized to zero in the init
// routine.
@ -62,15 +48,15 @@ static uint8_t vdev_index = 0;
// index of the current hook entry while building hook initializer table.
static uint8_t hook_index = 0;
// PROCEDURE: asdf_keymaps_add_map
// PROCEDURE: asdf_keymaps_register_keymap
// INPUTS: (uint8_t) keymap_index - index of the keymap to be modified
// (asdf_keycode_matrix_t *) matrix - pointer to the keycode matrix to add in to map
// (uint8_t) keymap_modifier - the modifier value for the keycode matrix being added
// (asdf_keymap_setup_function_t) keymap setup function - called on
// keymap change to setup up the keymap
//
// OUTPUTS: none
//
// DESCRIPTION: Called by keymap building modules. This routine adds a keymap
// matrix into a specific modifier position of the specified matrix.
// setup function into the keymap setup array.
//
// SIDE EFFECTS:
//
@ -80,83 +66,42 @@ static uint8_t hook_index = 0;
// SCOPE: public
//
// COMPLEXITY: 1
void asdf_keymaps_add_map(const uint8_t keymap_index, const asdf_keycode_matrix_t *matrix, const uint8_t modifier_index)
void asdf_keymaps_register(uint8_t keymap_index, asdf_keymap_setup_function_t keymap_setup_function);
{
if ((keymap_index < ASDF_NUM_KEYMAPS)
&& (modifier_index < ASDF_MOD_NUM_MODIFIERS)
&& (keymap_index < ASDF_NUM_KEYMAPS)) {
keymap_matrix[keymap_index][modifier_index] = (asdf_keycode_matrix_t *) matrix;
}
if (keymap_index < ASDF_NUM_KEYMAPS)
{
keymap_setup_functions[keymap_index] = keymap_setup_function;
}
}
// PROCEDURE: asdf_keymap_add_virtual_device
// INPUTS: (asdf_virtual_dev_t) virtual_dev: The virtual device being assigned
// (asdf_physical_dev_t) physical_dev: The physical device attached to the virtual device
// (asdf_virtual_function_t) function: the function associated with the virtual device
// (uint8_t) initial_value: The initial state of the virtual device
// PROCEDURE: asdf_keymaps_add_map
// INPUTS: (asdf_keycode_matrix_t *) matrix - pointer to the keycode matrix to add in to map
// (uint8_t) keymap_modifier - the modifier value for the keycode matrix being added
//
// OUTPUTS: none
//
// DESCRIPTION: Builds the virtual device initializer structure. Uses the
// arguments to build an entry in the virtual device initializer structure for
// the current keymap.
// DESCRIPTION: Called by keymap building modules. This routine adds a keymap to the current
// setup function into the keymap setup array.
//
// SIDE EFFECTS: See above.
// SIDE EFFECTS:
//
// NOTES:
// NOTES: If the keymap modifier index is not a valid keymap index then no
// action is performed.
//
// SCOPE: public
//
// COMPLEXITY: 1
//
void asdf_keymap_add_virtual_device(asdf_virtual_dev_t virtual_dev,
asdf_physical_dev_t physical_dev,
asdf_virtual_function_t function, uint8_t initial_value)
void asdf_keymaps_add_map(uint8_t num_rows, uint8_t num_cols, asdf_keycode_matrix_t *matrix, modifier_index_t modifier_index);
{
static uint8_t vdev_index = 0;
if (V_NULL == virtual_dev) {
vdev_index = 0;
}
else if (current_keymap_index < ASDF_NUM_KEYMAPS && vdev_index < ASDF_VIRTUAL_NUM_RESOURCES) {
keymap_initializer_list[current_keymap_index][vdev_index++].virtual_device = virtual_dev;
keymap_initializer_list[current_keymap_index][vdev_index++].physical_device = physical_dev;
keymap_initializer_list[current_keymap_index][vdev_index++].function = function;
keymap_initializer_list[current_keymap_index][vdev_index++].initial_value = initial_value;
}
if (modifier_index < ASDF_MOD_NUM_MODIFIERS)
{
keymaps[modifier_index].map = matrix;
keymaps[modifier_index].rows = num_rows;
keymaps[modifier_index].cols = num_cols;
}
}
// PROCEDURE: asdf_keymap_add_hook
// INPUTS: (asdf_hook_id_t) hook_id: type ID for the provided hook function
// (asdf_hook_function_t) function: the function associated with the hook.
//
// OUTPUTS: none
//
// DESCRIPTION: Builds the hook initializer table for the current keymap
//
// SIDE EFFECTS: See above.
//
// NOTES:
//
// SCOPE: public
//
// COMPLEXITY: 1
//
void asdf_keymap_add_hook(asdf_hook_id_t hook_id, asdf_hook_function_t function)
{
static uint8_t hook_entry_index = 0;
if (ASDF_HOOK_NULL == hook_id) {
hook_entry_index = 0;
}
else if (current_keymap_index < ASDF_NUM_KEYMAPS && hook_index < ASDF_NUM_HOOKS) {
keymap_hook_initializer_list[current_keymap_index][hook_entry_index].hook_id = hook_id;
keymap_hook_initializer_list[current_keymap_index][hook_entry_index].hook_func = function;
}
}
asdf_
// PROCEDURE: asdf_keymaps_select_keymap
// INPUTS: (uint8_t) index - index of the keymap number to select
// OUTPUTS: none
@ -182,21 +127,20 @@ void asdf_keymap_add_hook(asdf_hook_id_t hook_id, asdf_hook_function_t function)
void asdf_keymaps_select_keymap(uint8_t index)
{
if (index < ASDF_NUM_KEYMAPS) {
current_keymap_index = index;
asdf_arch_init();
// asdf_virtual_init((asdf_virtual_initializer_t *const) keymap_initializer_list[current_keymap_index]);
asdf_modifiers_init();
// asdf_hook_init((asdf_hook_initializer_t *const) keymap_hook_initializer_list[current_keymap_index]);
}
}
// PROCEDURE: asdf_keymaps_init
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Selects the base keymap.
// DESCRIPTION: initialize the keymap list
//
// SIDE EFFECTS: builds up the private map table.
// SIDE EFFECTS: See DESCRIPTION
//
// SCOPE: public
//
@ -210,9 +154,14 @@ void asdf_keymaps_select_keymap(uint8_t index)
//
void asdf_keymaps_init(void)
{
asdf_keymaps_select_keymap(0);
for (uint8_t i = 0; i < ASDF_NUM_KEYMAPS; i++) {
keymaps[i].setup_function = NULL;
keymaps[i].rows = 0;
keymaps[i].cols = 0;
}
}
// PROCEDURE: asdf_keymaps_map_select_0_clear
// INPUTS: none
// OUTPUTS: none

View File

@ -44,18 +44,30 @@
// define the keycode matrices to be used by the keymaps. Each matrix is a
// mapping of row,column to keycode.
typedef asdf_keycode_t asdf_keycode_matrix_t[ASDF_NUM_ROWS][ASDF_NUM_COLS];
typedef asdf_keycode_t asdf_keycode_matrix_t[][];
// define the type for a keymap setup function. Keymaps are registerd by storing
// a keymap setup function in the keymap setup array.
typedef void (*asdf_keymap_setup_function_t)(void);
// define the struct for each keymap matrix in the keymap array. One per
// modifier state. Each keymap can have it's own row and column count.
typedef struct {
asdf_keycode_matrix_t *matrix;
uint8_t rows;
uint8_t cols;
};
// PROCEDURE: asdf_keymaps_add_map
// INPUTS: (uint8_t) keymap_index - index of the keymap to be modified
// (asdf_keycode_matrix_t *) matrix - pointer to the keycode matrix to add in to map
// (uint8_t) keymap_modifier - the modifier value for the keycode matrix being added
// (asdf_keymap_setup_function) setup_function - pointer to keymap setup function
// OUTPUTS: none
// DESCRIPTION: Called by keymap building modules. This routine adds a keymap
// matrix into a specific modifier position of the specified matrix.
// setup function into the keymap setup array.
// NOTES: If the keymap modifier index is not a valid keymap index then no
// action is performed.
void asdf_keymaps_add_map(uint8_t keymap_index, const asdf_keycode_matrix_t *matrix, uint8_t modifier_index);
void asdf_keymaps_add_map(uint8_t keymap_index, asdf_keymap_setup_function_t);
// PROCEDURE: asdf_keymaps_select_keymap
// INPUTS: (uint8_t) index - index of the keymap number to select

View File

@ -176,8 +176,9 @@ static uint8_t valid_virtual_device(asdf_virtual_dev_t device)
//
// SIDE EFFECTS: see above.
//
// NOTES: if the virtual output is invalid, or the physical resource is invalid, or
// the physical resource is already assigned, then nothing happens.
// NOTES:
// if the virtual output is invalid, or the physical resource is invalid, or
// the physical resource is already assigned, then nothing happens.
//
// SCOPE: private
//

View File

@ -88,8 +88,70 @@ void setup_test2_caps_map(void)
asdf_keymaps_add_map(ASDF_TEST2_CAPS_MAP_INDEX, &test2_CTRL_matrix, MOD_CTRL_MAP);
}
void setup_test_devs1(void)
{
#define ASDF_TEST_KEYMAP_INITIALIZER_1 \
{ \
asdf_virtual_init();
/* Single assignment */ \
.virtual_device = VOUT1, \
.physical_device = PHYSICAL_OUT1, \
.function = V_NOFUNC, \
.initial_value = 0, \
}, \
{ \
/* single toggle */ \
.virtual_device = VOUT2, \
.physical_device = PHYSICAL_OUT2, \
.function = V_TOGGLE, \
.initial_value = 0, \
}, \
{ \
/* single pulse */ \
.virtual_device = VOUT3, \
.physical_device = PHYSICAL_OUT3, \
.function = V_PULSE_SHORT, \
.initial_value = 0, \
}, \
{ /* first of double assignment attempt */ \
.virtual_device = VOUT4, \
.physical_device = PHYSICAL_LED1, \
.initial_value = 0 \
}, \
{ /* second of double assignment attempt */ \
.virtual_device = VOUT5, .physical_device = PHYSICAL_LED1, .initial_value = 1 \
} \
}
}
void setup_test_devs2(void)
{
#define ASDF_TEST_KEYMAP_INITIALIZER_2 \
{ \
{ \
/* Triple assignment */ \
.virtual_device = VOUT1, \
.physical_device = PHYSICAL_OUT1, \
.function = V_TOGGLE, \
.initial_value = 0, \
}, \
{ \
.virtual_device = VOUT1, \
.physical_device = PHYSICAL_OUT2, \
.function = V_TOGGLE, \
.initial_value = 1, \
}, \
{ \
.virtual_device = VOUT1, .physical_device = PHYSICAL_OUT3, .function = V_TOGGLE, \
.initial_value = 0, \
} \
}
}
//-------|---------|---------+---------+---------+---------+---------+---------+

View File

@ -113,7 +113,7 @@ void setUp(void)
{
coord_t *temp;
setup_test_plain_map();
asdf_setup_test_plain_map();
setup_test_caps_map();
setup_test2_plain_map();
setup_test2_caps_map();

View File

@ -8,7 +8,7 @@
#include "asdf_keymaps.h"
#include "asdf_config.h"
#include "test_asdf_lib.h"
#include "test_asdf_keymap_defs.h"
void setUp(void)
@ -25,13 +25,6 @@ asdf_cols_t asdf_arch_read_row(uint8_t row)
return (asdf_cols_t) row;
}
// check to see that the longest keymap initializer sequence initia is detected.
void test_inizializer_length_is_max_length(void)
{
TEST_ASSERT_EQUAL_INT32(max(ASDF_TEST_KEYMAP_INITIALIZER_LENGTH,
ASDF_TEST2_KEYMAP_INITIALIZER_LENGTH), ASDF_KEYMAP_INITIALIZER_LENGTH);
}
void test_single_virtual_output_is_initialized(void)
{
// initially on keymap 0. Test to see that OUT1 has been initialized to 0.
@ -300,7 +293,6 @@ void test_cant_assign_real_output_twice(void)
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_inizializer_length_is_max_length);
RUN_TEST(test_single_virtual_output_is_initialized);
RUN_TEST(test_uninitialized_virtual_out_is_default);
RUN_TEST(test_set_virtual_output);