Get new keymap scheme to pass keymap tests

Toward issue #23
This commit is contained in:
David Fenyes 2021-02-16 16:38:54 -06:00 committed by Dave
parent d6edb15734
commit 99610395fc
5 changed files with 74 additions and 49 deletions

View File

@ -62,19 +62,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_keymap
// INPUTS: (asdf_keycode_matrix_t *) matrix - keycode matrix to add in to map
// (uint8_t) keymap_modifier - the modifier value for the keycode matrix
// 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
//
// OUTPUTS: none
//
// DESCRIPTION: Called by keymap building modules. This routine is responsible
// for building the keymap matrix for all the supported keymaps, assigning
// keymaps for each modifier code in all the keymaps.
// The routine takes a pointer to a keycode matrix that maps each key in the
// physical keyboard matrix to a code. A modifier code parameter indicates which
// modifier combination activates the provided matrix.
// DESCRIPTION: Called by keymap building modules. This routine adds a keymap
// matrix into a specific modifier position of the specified matrix.
//
// SIDE EFFECTS:
//
@ -84,39 +80,16 @@ static uint8_t hook_index = 0;
// SCOPE: public
//
// COMPLEXITY: 1
void asdf_keymaps_add_map(asdf_keycode_matrix_t *matrix, uint8_t modifier_index)
void asdf_keymaps_add_map(const uint8_t keymap_index, const asdf_keycode_matrix_t *matrix, const uint8_t modifier_index)
{
if (modifier_index < ASDF_MOD_NUM_MODIFIERS && current_keymap_index < ASDF_NUM_KEYMAPS) {
keymap_matrix[current_keymap_index][modifier_index] = matrix;
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;
}
}
// PROCEDURE: asdf_keymaps_next();
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Called by keymap building modules to conclude a keymap. This is
// done after all modifier maps, hooks, and virtual devices have been defined.
//
// SIDE EFFECTS: 1) Causes asdf_keymaps_add_keymap() to increment the keymap index
// 2) Resets the virtual device table index for the next keymap
// 3) Resets the hook table index for the next keymap
//
// NOTES:
//
// SCOPE: public
//
// COMPLEXITY: 1
//
void asdf_keymaps_start_new(uint8_t new_keymap_index)
{
current_keymap_index = new_keymap_index;
asdf_keymap_add_virtual_device(V_NULL, PHYSICAL_NO_OUT, V_NOFUNC, 0);
asdf_keymap_add_hook(ASDF_HOOK_NULL, NULL);
}
// 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
@ -211,9 +184,9 @@ 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_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]);
// asdf_hook_init((asdf_hook_initializer_t *const) keymap_hook_initializer_list[current_keymap_index]);
}
}
@ -421,7 +394,6 @@ asdf_keycode_t asdf_keymaps_get_code(const uint8_t row, const uint8_t col,
const uint8_t modifier_index)
{
asdf_keycode_matrix_t *matrix = keymap_matrix[current_keymap_index][modifier_index];
return FLASH_READ_MATRIX_ELEMENT(*matrix, row, col);
}

View File

@ -32,10 +32,6 @@
#include "asdf_virtual.h"
#include "asdf_physical.h"
#define ASDF_NUM_KEYMAPS 6
#define ASDF_NUM_ROWS 13
#define ASDF_NUM_COLS 8
// Define the bit position of each keymap DIP switch. The DIP switch values at
// each bit position can be used to select the current keymap. This requires the
// DIP switches to be mapped to the asdf_keymaps_select_X_set() and
@ -50,6 +46,17 @@
// mapping of row,column to keycode.
typedef asdf_keycode_t asdf_keycode_matrix_t[ASDF_NUM_ROWS][ASDF_NUM_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
// OUTPUTS: none
// DESCRIPTION: Called by keymap building modules. This routine adds a keymap
// matrix into a specific modifier position of the specified matrix.
// 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);
// PROCEDURE: asdf_keymaps_select_keymap
// INPUTS: (uint8_t) index - index of the keymap number to select
// OUTPUTS: none

View File

@ -25,8 +25,10 @@
#include <test_asdf_keymap_defs.h>
#include "asdf_ascii.h"
#include "asdf_modifiers.h"
#include "asdf_keymaps.h"
static const asdf_keycode_matrix_t test_PLAIN_matrix = ASDF_TEST_PLAIN_MAP;
static const asdf_keycode_matrix_t test_SHIFT_matrix = ASDF_TEST_SHIFT_MAP;
static const asdf_keycode_matrix_t test_CAPS_matrix = ASDF_TEST_CAPS_MAP;
@ -54,6 +56,38 @@ static const asdf_keycode_matrix_t test2_CTRL_matrix = ASDF_TEST2_CTRL_MAP;
//
void setup_test_plain_map(void)
{
asdf_keymaps_add_map(ASDF_TEST_PLAIN_MAP_INDEX, &test_PLAIN_matrix, MOD_PLAIN_MAP);
asdf_keymaps_add_map(ASDF_TEST_PLAIN_MAP_INDEX, &test_CAPS_matrix, MOD_CAPS_MAP);
asdf_keymaps_add_map(ASDF_TEST_PLAIN_MAP_INDEX, &test_SHIFT_matrix, MOD_SHIFT_MAP);
asdf_keymaps_add_map(ASDF_TEST_PLAIN_MAP_INDEX, &test_CTRL_matrix, MOD_CTRL_MAP);
}
void setup_test_caps_map(void)
{
asdf_keymaps_add_map(ASDF_TEST_CAPS_MAP_INDEX, &test_PLAIN_matrix, MOD_PLAIN_MAP);
asdf_keymaps_add_map(ASDF_TEST_CAPS_MAP_INDEX, &test_CAPS_matrix, MOD_CAPS_MAP);
asdf_keymaps_add_map(ASDF_TEST_CAPS_MAP_INDEX, &test_SHIFT_matrix, MOD_SHIFT_MAP);
asdf_keymaps_add_map(ASDF_TEST_CAPS_MAP_INDEX, &test_CTRL_matrix, MOD_CTRL_MAP);
}
void setup_test2_plain_map(void)
{
asdf_keymaps_add_map(ASDF_TEST2_PLAIN_MAP_INDEX, &test2_PLAIN_matrix, MOD_PLAIN_MAP);
asdf_keymaps_add_map(ASDF_TEST2_PLAIN_MAP_INDEX, &test2_CAPS_matrix, MOD_CAPS_MAP);
asdf_keymaps_add_map(ASDF_TEST2_PLAIN_MAP_INDEX, &test2_SHIFT_matrix, MOD_SHIFT_MAP);
asdf_keymaps_add_map(ASDF_TEST2_PLAIN_MAP_INDEX, &test2_CTRL_matrix, MOD_CTRL_MAP);
}
void setup_test2_caps_map(void)
{
asdf_keymaps_add_map(ASDF_TEST2_CAPS_MAP_INDEX, &test2_PLAIN_matrix, MOD_PLAIN_MAP);
asdf_keymaps_add_map(ASDF_TEST2_CAPS_MAP_INDEX, &test2_CAPS_matrix, MOD_CAPS_MAP);
asdf_keymaps_add_map(ASDF_TEST2_CAPS_MAP_INDEX, &test2_SHIFT_matrix, MOD_SHIFT_MAP);
asdf_keymaps_add_map(ASDF_TEST2_CAPS_MAP_INDEX, &test2_CTRL_matrix, MOD_CTRL_MAP);
}

View File

@ -377,5 +377,12 @@
#endif /* !defined (TEST_ASDF_KEYMAP_DEFS_H) */
void setup_test_plain_map(void);
void setup_test_caps_map(void);
void setup_test2_plain_map(void);
void setup_test2_caps_map(void);
//-------|---------|---------+---------+---------+---------+---------+---------+
// Above line is 80 columns, and should display completely in the editor.

View File

@ -14,7 +14,6 @@
#define TESTKEYMAP_TAG PLAIN_MATRIX_1
#define NUM_DIPSWITCHES 4
static const FLASH asdf_keycode_matrix_t test_PLAIN_matrix = ASDF_TEST_PLAIN_MAP;
static const FLASH asdf_keycode_matrix_t test_SHIFT_matrix = ASDF_TEST_SHIFT_MAP;
static const FLASH asdf_keycode_matrix_t test_CAPS_matrix = ASDF_TEST_CAPS_MAP;
@ -114,6 +113,11 @@ void setUp(void)
{
coord_t *temp;
setup_test_plain_map();
setup_test_caps_map();
setup_test2_plain_map();
setup_test2_caps_map();
asdf_keymaps_init();
temp = find_code(TESTALPHA);
@ -284,7 +288,8 @@ void dip_switch_properly_clears_bits(void)
asdf_keycode_t result;
asdf_keymaps_select_keymap(i);
expected = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
sprintf(message,"map %d, expected: %d",i, expected);
TEST_MESSAGE(message);
// set as many keymap bits to '1' as possible.
asdf_keymaps_select_keymap(mask);
complicated_set_keymap(i);
@ -313,9 +318,9 @@ void dip_switch_invalid_keymap_has_no_effect(void)
map_id = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
TEST_ASSERT_EQUAL_INT32(PLAIN_MATRIX_1, map_id);
// selecting one above the highest keymap should have no effect
map_id = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
// selecting the highest possible keymap should have no effect
asdf_keymaps_select_keymap(UINT8_MAX);
map_id = asdf_keymaps_get_code(keymap_tag.row, keymap_tag.col, MOD_PLAIN_MAP);
TEST_ASSERT_EQUAL_INT32(PLAIN_MATRIX_1, map_id);
}