More keymap updates toward [#23] amd [#25]

App code now compiles clean, but test code still needs to be updated to set up
the test keymaps.  So, no passing tests yet.
This commit is contained in:
Dave 2021-02-19 14:10:25 -06:00
parent daa6ff672f
commit 14ad7c4cc2
11 changed files with 245 additions and 258 deletions

View File

@ -27,5 +27,14 @@
* 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.
* select_keymap() will call setup routine for the g
iven keymap.
* Each keymap sets its own num_rows and num_columns, per matrix for each modifier
* DIP SWITCHES
Note that the DIP switches are keys in the key matrix, which is initialized to
the all unpressed state at startup. Since the keymap is initialized to 0, the
keymap is consistent with the presumed initial state of the DIP switches. If
the DIP switches are not set to Keymap 0, then their position will be detected
as keypresses, and the correct keymap will be set.

View File

@ -44,7 +44,7 @@
// The key scanner keeps track of the last stable (debounced) state of each key
// in the matrix, one bit per key, 8 bits per row.
static asdf_cols_t last_stable_key_state[ASDF_NUM_ROWS];
static asdf_cols_t last_stable_key_state[ASDF_MAX_ROWS];
// Each key is debounced separately, supporting true N-key rollover, allowing a
// new key to be pressed when the previously pressed key is still debouncing.
@ -55,7 +55,7 @@ static asdf_cols_t last_stable_key_state[ASDF_NUM_ROWS];
// key presses and releases, and special handling for modifier keys, perhaps
// including separate debounce logic in the handlers for toggle keys such as
// CAPS_LOCK.
static uint8_t debounce_counters[ASDF_NUM_ROWS][ASDF_NUM_COLS];
static uint8_t debounce_counters[ASDF_MAX_ROWS][ASDF_MAX_COLS];
// Stores the last key pressed
static asdf_keycode_t last_key;
@ -401,9 +401,9 @@ void asdf_init(void)
// Initialize all the keys to the unpressed state, and initialze the debounce
// counters.
for (uint8_t row = 0; row < ASDF_NUM_ROWS; row++) {
for (uint8_t row = 0; row < ASDF_MAX_ROWS; row++) {
last_stable_key_state[row] = 0;
for (uint8_t col = 0; col < ASDF_NUM_COLS; col++) {
for (uint8_t col = 0; col < ASDF_MAX_COLS; col++) {
debounce_counters[row][col] = ASDF_DEBOUNCE_TIME_MS;
}
}
@ -509,18 +509,17 @@ static void asdf_handle_key_held_pressed(uint8_t row, uint8_t col)
//
void asdf_keyscan(void)
{
asdf_cols_t (*row_reader)(uint8_t) = (asdf_cols_t(*)(uint8_t)) asdf_hook_get(ASDF_HOOK_SCANNER);
asdf_hook_execute(ASDF_HOOK_EACH_SCAN);
for (uint8_t row = 0; row < ASDF_NUM_ROWS; row++) {
for (uint8_t row = 0; row < asdf_keymaps_num_rows(); row++) {
asdf_cols_t row_key_state = (*row_reader)(row);
asdf_cols_t changed = row_key_state ^ last_stable_key_state[row];
// loop over the bits until all changed or pressed keys in the row are handled.
for (uint8_t col = 0; (changed || row_key_state) && col < ASDF_NUM_COLS; col++) {
for (uint8_t col = 0; (changed || row_key_state) && col < asdf_keymaps_num_cols(); col++) {
if (changed & 1) {
// key state is different from last stable state
asdf_handle_key_press_or_release(row, col, row_key_state & 1);

View File

@ -49,6 +49,9 @@
// Data structure sizes:
// Max number of keymaps supported (defines size of keymap setup routine array)
#define ASDF_NUM_KEYMAPS 32
// Size of keymap initializer sequence. These sequences are defined in the
// keymap modules. This should be large enough to accommodate the largest
// initializer sequence among the included keymaps

View File

@ -132,11 +132,11 @@ asdf_hook_function_t asdf_hook_get(asdf_hook_id_t hook_id)
//
// NOTES:
//
// SCOPE: private
// SCOPE: public
//
// COMPLEXITY: 2
//
static void asdf_hook_assign(asdf_hook_id_t hook_id, asdf_hook_function_t func)
void asdf_hook_assign(asdf_hook_id_t hook_id, asdf_hook_function_t func)
{
if (asdf_hook_valid_id(hook_id)) {
hook_map[hook_id] = func;
@ -144,9 +144,7 @@ static void asdf_hook_assign(asdf_hook_id_t hook_id, asdf_hook_function_t func)
}
// PROCEDURE: asdf_hook_init
// INPUTS: (asdf_hook_initializer_t *) initializer_list - contains the hook
// initializer list for the selected keymap.
//
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Initializes function hooks for the selected keymap. If a
@ -161,7 +159,7 @@ static void asdf_hook_assign(asdf_hook_id_t hook_id, asdf_hook_function_t func)
//
// COMPLEXITY: 4
//
void asdf_hook_init(asdf_hook_initializer_t *const initializer_list)
void asdf_hook_init(void)
{
// initialize hooks to null function
for (uint8_t i = 0; i < ASDF_NUM_HOOKS; i++) {
@ -170,18 +168,6 @@ void asdf_hook_init(asdf_hook_initializer_t *const initializer_list)
hook_map[ASDF_HOOK_SCANNER] = (asdf_hook_function_t) ASDF_ARCH_DEFAULT_SCANNER;
hook_map[ASDF_HOOK_OUTPUT] = (asdf_hook_function_t) ASDF_ARCH_DEFAULT_OUTPUT;
// run through the keymap specific setup
for (uint8_t i = 0; i < ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH; i++) {
asdf_hook_id_t id = initializer_list[i].hook_id;
if (ASDF_HOOK_KEYMAP_SETUP == id) {
initializer_list[i].hook_func();
}
else {
asdf_hook_assign(initializer_list[i].hook_id, initializer_list[i].hook_func);
}
}
}
//-------|---------|---------+---------+---------+---------+---------+---------+

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;
b} asdf_hook_initializer_t;
} asdf_hook_initializer_t;
// PROCEDURE: asdf_hook_execute
@ -64,13 +64,21 @@ void asdf_hook_execute(asdf_hook_id_t hook_id);
asdf_hook_function_t asdf_hook_get(asdf_hook_id_t hook_id);
// PROCEDURE: asdf_hook_init
// INPUTS: (asdf_hook_initializer_t *) initializer_list - contains the hook
// initializer list for the selected keymap.
// INPUTS: none
// OUTPUTS: none
// DESCRIPTION: Initializes function hooks for the selected keymap. If a
// function is assigned to the "KEYMAP_SETUP" hook, then execute the function.
// There is no actual slot where KEYMAP_SETUP functions are stored.
void asdf_hook_init(asdf_hook_initializer_t *const initializer_list);
void asdf_hook_init(void);
// PROCEDURE: asdf_hook_assign
// INPUTS: (asdf_hook_id_t) hook_id: The hook for which to execute attache functions.
// (asdf_hook_function_t) func: function to be attached to the hook.
// OUTPUTS: none
// DESCRIPTION: If the hook ID is valid, map the function to the hook ID.
// Ignore if not valid.
void asdf_hook_assign(asdf_hook_id_t hook_id, asdf_hook_function_t func);
#endif /* !defined (ASDF_HOOKS_H) */

View File

@ -22,6 +22,7 @@
#include <stdint.h>
#include <stddef.h>
#include "asdf_config.h"
#include "asdf.h"
#include "asdf_arch.h"
#include "asdf_physical.h"
@ -31,24 +32,22 @@
#include "asdf_modifiers.h"
// The keymap arrays organized as follows:
// * `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_MOD_NUM_MODIFIERS] = {};
// * keymap_matrix - matrix of code mapppings for each physical keymap
// * rows = number of rows in the matrix
// * cols = number of cols in the matrix
// * one map structure for each modifier state.
static asdf_keycode_map_t keymaps[ASDF_MOD_NUM_MODIFIERS] = {};
// Index of the currently active keymap, initialized to zero in the init
// routine.
static uint8_t current_keymap_index = 0;
// List of keymap setup routines. Each keymap setup routine is responsible for
// populating the keymap matrices, setting up virtual devices, and setting up
// keymap-specific function hooks and initial conditions for the keymap.
static asdf_keymap_setup_function_t keymap_setup_function_lookup_table[ASDF_NUM_KEYMAPS];
// index of the current virtual device initializer entry while building virtual
// device initializer struct.
static uint8_t vdev_index = 0;
// index of the current hook entry while building hook initializer table.
static uint8_t hook_index = 0;
// The current keymap index. This is stored so bitwise operators on the keymap index can be performed.
static uint8_t current_keymap_index;
// PROCEDURE: asdf_keymaps_register_keymap
// PROCEDURE: asdf_keymaps_register
// INPUTS: (uint8_t) keymap_index - index of the keymap to be modified
// (asdf_keymap_setup_function_t) keymap setup function - called on
// keymap change to setup up the keymap
@ -66,17 +65,19 @@ static uint8_t hook_index = 0;
// SCOPE: public
//
// COMPLEXITY: 1
void asdf_keymaps_register(uint8_t keymap_index, asdf_keymap_setup_function_t keymap_setup_function);
void asdf_keymaps_register(uint8_t keymap_index, asdf_keymap_setup_function_t keymap_setup_function)
{
if (keymap_index < ASDF_NUM_KEYMAPS)
{
keymap_setup_functions[keymap_index] = keymap_setup_function;
keymap_setup_function_lookup_table[keymap_index] = keymap_setup_function;
}
}
// 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
// INPUTS: (asdf_keycode_matrix_t) matrix - pointer to the keycode matrix to add in to map
// (uint8_t) modifier_index - the modifier value for the keycode matrix being added
// (uint8_t) rows - number of rows in the keymap
// (uint8_t) cols - number of columns in the keymap
//
// OUTPUTS: none
//
@ -85,23 +86,84 @@ void asdf_keymaps_register(uint8_t keymap_index, asdf_keymap_setup_function_t ke
//
// SIDE EFFECTS:
//
// NOTES: If the keymap modifier index is not a valid keymap index then no
// NOTES: If the keymap modifier index, num_rows, or num_cols are not valid then no
// action is performed.
//
// SCOPE: public
//
// COMPLEXITY: 1
void asdf_keymaps_add_map(uint8_t num_rows, uint8_t num_cols, asdf_keycode_matrix_t *matrix, modifier_index_t modifier_index);
void asdf_keymaps_add_map(asdf_keycode_matrix_t matrix,
modifier_index_t modifier_index,
uint8_t num_rows, uint8_t num_cols)
{
if (modifier_index < ASDF_MOD_NUM_MODIFIERS)
if ((modifier_index < ASDF_MOD_NUM_MODIFIERS)
&& (num_rows <= ASDF_MAX_ROWS)
&& (num_cols <= ASDF_MAX_COLS))
{
keymaps[modifier_index].map = matrix;
keymaps[modifier_index].matrix_ptr = matrix;
keymaps[modifier_index].rows = num_rows;
keymaps[modifier_index].cols = num_cols;
}
}
asdf_
// PROCEDURE: asdf_keymaps_num_rows
// INPUTS: none
// OUTPUTS: uint8_t - returns number of rows in keymap for current modifier state
//
// DESCRIPTION: See OUTPUTS
//
// SIDE EFFECTS: none
//
// NOTES:
//
// SCOPE: publice
//
// COMPLEXITY: 1
//
uint8_t asdf_keymaps_num_rows(void)
{
return keymaps[asdf_modifier_index()].rows;
}
// PROCEDURE: asdf_keymaps_num_cols
// INPUTS: none
// OUTPUTS: uint8_t - returns number of columns in keymap for current modifier state
//
// DESCRIPTION: See OUTPUTS
//
// SIDE EFFECTS: none
//
// NOTES:
//
// SCOPE: publice
//
// COMPLEXITY: 1
//
uint8_t asdf_keymaps_num_cols(void)
{
return keymaps[asdf_modifier_index()].cols;
}
// PROCEDURE: asdf_keymaps_new
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Clear all keycode mapping matrices.
//
// SIDE EFFECTS: see DESCRIPTION
//
// SCOPE: private
//
// COMPLEXITY: 2
//
static void asdf_keymaps_new(void)
{
for (uint8_t i = 0; i < ASDF_MOD_NUM_MODIFIERS; i++) {
asdf_keymaps_add_map(NULL, i, 0, 0);
}
}
// PROCEDURE: asdf_keymaps_select_keymap
// INPUTS: (uint8_t) index - index of the keymap number to select
// OUTPUTS: none
@ -111,12 +173,9 @@ asdf_
// 1) assign the value to the global (to the module) current_keymap_index variable
// 2) execute the architecture-dependent init routine, to undo any settings
// from the previous keymap
// 3) initialize the virtual outputs for the selected keymap.
// 4) initialize the modifier key states.
// 3) execute the keymap-specific setup routine.
//
// SIDE EFFECTS:
// - May change the module-global current_keymap_index variable.
// - Architecture is initialized to default configuration.
// SIDE EFFECTS: See DESCRIPTION
//
// NOTES: If the requested index is not valid, then no action is performed.
//
@ -128,40 +187,48 @@ void asdf_keymaps_select_keymap(uint8_t index)
{
if (index < ASDF_NUM_KEYMAPS) {
asdf_arch_init();
// asdf_virtual_init((asdf_virtual_initializer_t *const) keymap_initializer_list[current_keymap_index]);
// asdf_hook_init((asdf_hook_initializer_t *const) keymap_hook_initializer_list[current_keymap_index]);
asdf_keymaps_new();
current_keymap_index = index;
keymap_setup_function_lookup_table[index]();
}
}
// PROCEDURE: ASDF_KEYMAPS_DUMMY_FUNCTION
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: null function to populate the keymap setup function table. Since
// this function does nothing, then selecting an unregistered keymap has no
// effect (i.e., the previous keymap persisits)
//
// SIDE EFFECTS: See Description
//
// SCOPE: private
//
// COMPLEXITY: 1
//
void asdf_keymaps_dummy_function(void) {}
// PROCEDURE: asdf_keymaps_init
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: initialize the keymap list
// DESCRIPTION: initialize the keymap list. Called at startup.
//
// SIDE EFFECTS: See DESCRIPTION
//
// SCOPE: public
//
// NOTES: Note that the DIP switches are keys in the key matrix, which is
// initialized to the all unpressed state at startup. Since the keymap is
// initialized to 0, the keymap is consistent with the presumed initial state of
// the DIP switches. If the DIP switches are not set to Keymap 0, then their
// position will be detected as keypresses, and the correct keymap will be set.
// COMPLEXITY: 1
//
void asdf_keymaps_init(void)
{
for (uint8_t i = 0; i < ASDF_NUM_KEYMAPS; i++) {
keymaps[i].setup_function = NULL;
keymaps[i].rows = 0;
keymaps[i].cols = 0;
keymap_setup_function_lookup_table[i] = &asdf_keymaps_dummy_function;
}
current_keymap_index = 0;
}
// PROCEDURE: asdf_keymaps_map_select_0_clear
// INPUTS: none
// OUTPUTS: none
@ -342,8 +409,8 @@ void asdf_keymaps_map_select_3_set(void)
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);
asdf_keycode_matrix_t matrix = keymaps[modifier_index].matrix_ptr;
return FLASH_READ_MATRIX_ELEMENT(matrix, row, col);
}
//-------|---------|---------+---------+---------+---------+---------+---------+

View File

@ -31,6 +31,7 @@
#include "asdf_hook.h"
#include "asdf_virtual.h"
#include "asdf_physical.h"
#include "asdf_modifiers.h"
// 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
@ -41,10 +42,12 @@
#define ASDF_KEYMAP_BIT_2 4
#define ASDF_KEYMAP_BIT_3 8
#define ASDF_MAX_ROWS 16
#define ASDF_MAX_COLS 8
// 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[][];
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.
@ -53,21 +56,48 @@ 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;
asdf_keycode_matrix_t matrix_ptr;
uint8_t rows;
uint8_t cols;
};
} asdf_keycode_map_t;
// PROCEDURE: asdf_keymaps_add_map
// PROCEDURE: asdf_keymaps_register
// INPUTS: (uint8_t) keymap_index - index of the keymap to be modified
// (asdf_keymap_setup_function) setup_function - pointer to keymap setup function
// (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
// 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, asdf_keymap_setup_function_t);
void asdf_keymaps_register(uint8_t keymap_index, asdf_keymap_setup_function_t keymap_setup_function);
// PROCEDURE: asdf_keymaps_add_map
// INPUTS: (asdf_keycode_matrix_t *) matrix - pointer to the keycode matrix to add in to map
// (uint8_t) modifier_index - the modifier value for the keycode matrix being added
// (uint8_t) rows - number of rows in the keymap
// (uint8_t) cols - number of columns in the keymap
// OUTPUTS: none
// DESCRIPTION: Called by keymap building modules. This routine adds a keymap to the current
// setup function into the keymap setup array.
// NOTES: If the keymap modifier index, num_rows, or num_cols are not valid then no
// action is performed.
void asdf_keymaps_add_map(asdf_keycode_matrix_t matrix,
modifier_index_t modifier_index,
uint8_t num_rows, uint8_t num_cols);
// PROCEDURE: asdf_keymaps_num_rows
// INPUTS: none
// OUTPUTS: uint8_t - returns number of rows in keymap for current modifier state
// DESCRIPTION: See OUTPUTS
uint8_t asdf_keymaps_num_rows(void);
// PROCEDURE: asdf_keymaps_num_cols
// INPUTS: none
// OUTPUTS: uint8_t - returns number of columns in keymap for current modifier state
// DESCRIPTION: See OUTPUTS
uint8_t asdf_keymaps_num_cols(void);
// PROCEDURE: asdf_keymaps_select_keymap
// INPUTS: (uint8_t) index - index of the keymap number to select
@ -84,7 +114,6 @@ void asdf_keymaps_select_keymap(uint8_t index);
// keymap index.
void asdf_keymaps_map_select_0_clear(void);
// PROCEDURE: asdf_keymaps_map_select_0_set
// INPUTS: none
// OUTPUTS: none

View File

@ -1,68 +0,0 @@
// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*-
//
// Unfified Keyboard Project
// ASDF keyboard firmware
//
// asdf_keymap_defs.h
//
// gathers up all the keymap definitions to be included in the firmware.
//
// Copyright 2019 David Fenyes
//
// This program is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation, either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <https://www.gnu.org/licenses/>.
// While there is nothing preventing a standard keyboard from having both a
// "Shift Lock" key and a "Caps Lock" key, usually only one will be present. For
// testing, both must be present to test their functionality.
#if !defined(ASDF_KEYMAP_DEFS_H)
#define ASDF_KEYMAP_DEFS_H
#include "asdf.h"
#include "test_asdf_lib.h"
#include "asdf_ascii.h"
#include "asdf_modifiers.h"
#include "Keymaps/asdf_keymap_defs_test.h"
#include "Keymaps/asdf_keymap_defs_test2.h"
#define ASDF_TEST_BASE 0
#define ASDF_TEST2_BASE (ASDF_TEST_BASE + ASDF_TEST_KEYMAPS_COUNT)
#define ASDF_NUM_KEYMAPS (ASDF_TEST_BASE + ASDF_TEST_KEYMAPS_COUNT + ASDF_TEST2_KEYMAPS_COUNT)
#define ASDF_KEYMAP_DEFS \
{ \
ASDF_TEST_KEYMAPS, ASDF_TEST2_KEYMAPS \
}
#define ASDF_KEYMAP_DECLARATIONS ASDF_TEST_DECLARATIONS ASDF_TEST2_DECLARATIONS
#define ASDF_KEYMAP_INITIALIZERS \
{ \
ASDF_TEST_KEYMAP_INITIALIZER, ASDF_TEST2_KEYMAP_INITIALIZER \
}
#define ASDF_KEYMAP_HOOK_INITIALIZERS \
{ \
ASDF_TEST_KEYMAP_HOOK_INITIALIZER, ASDF_TEST2_KEYMAP_HOOK_INITIALIZER \
}
typedef asdf_keycode_t keycode_matrix_t[ASDF_NUM_ROWS][ASDF_NUM_COLS];
#endif /* !defined (ASDF_KEYMAP_DEFS_H) */
//-------|---------|---------+---------+---------+---------+---------+---------+
// Above line is 80 columns, and should display completely in the editor.

View File

@ -29,15 +29,15 @@
#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;
static const asdf_keycode_matrix_t test_CTRL_matrix = ASDF_TEST_CTRL_MAP;
static const asdf_keycode_t test_PLAIN_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST_PLAIN_MAP;
static const asdf_keycode_t test_SHIFT_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST_SHIFT_MAP;
static const asdf_keycode_t test_CAPS_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST_CAPS_MAP;
static const asdf_keycode_t test_CTRL_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST_CTRL_MAP;
static const asdf_keycode_matrix_t test2_PLAIN_matrix = ASDF_TEST2_PLAIN_MAP;
static const asdf_keycode_matrix_t test2_SHIFT_matrix = ASDF_TEST2_SHIFT_MAP;
static const asdf_keycode_matrix_t test2_CAPS_matrix = ASDF_TEST2_CAPS_MAP;
static const asdf_keycode_matrix_t test2_CTRL_matrix = ASDF_TEST2_CTRL_MAP;
static const asdf_keycode_t test2_PLAIN_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST2_PLAIN_MAP;
static const asdf_keycode_t test2_SHIFT_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST2_SHIFT_MAP;
static const asdf_keycode_t test2_CAPS_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST2_CAPS_MAP;
static const asdf_keycode_t test2_CTRL_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST2_CTRL_MAP;
// PROCEDURE:
@ -56,46 +56,49 @@ static const asdf_keycode_matrix_t test2_CTRL_matrix = ASDF_TEST2_CTRL_MAP;
//
void test_keymaps_add_map(asdf_keycode_matrix_t matrix,
modifier_index_t modifier_index)
{
asdf_keymaps_add_map(matrix, modifier_index, (uint8_t) TEST_NUM_ROWS, (uint8_t) TEST_NUM_COLS);
}
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);
test_keymaps_add_map((asdf_keycode_matrix_t) test_PLAIN_matrix, MOD_PLAIN_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) test_CAPS_matrix, MOD_CAPS_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) test_SHIFT_matrix, MOD_SHIFT_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) 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);
test_keymaps_add_map((asdf_keycode_matrix_t) test_PLAIN_matrix, MOD_PLAIN_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) test_CAPS_matrix, MOD_CAPS_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) test_SHIFT_matrix, MOD_SHIFT_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) 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);
test_keymaps_add_map((asdf_keycode_matrix_t) test2_PLAIN_matrix, MOD_PLAIN_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) test2_CAPS_matrix, MOD_CAPS_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) test2_SHIFT_matrix, MOD_SHIFT_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) 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);
test_keymaps_add_map((asdf_keycode_matrix_t) test2_PLAIN_matrix, MOD_PLAIN_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) test2_CAPS_matrix, MOD_CAPS_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) test2_SHIFT_matrix, MOD_SHIFT_MAP);
test_keymaps_add_map((asdf_keycode_matrix_t) 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, \

View File

@ -54,9 +54,12 @@
#define SHIFT_MATRIX_1 RESERVED_3
#define CTRL_MATRIX_1 RESERVED_4
#define ASDF_LAST_ROW (ASDF_NUM_ROWS - 1)
#define TEST_NUM_ROWS 9
#define TEST_NUM_COLS 8
#define ASDF_TEST_MAP_DIP_SWITCHES \
[ASDF_LAST_ROW] = { ACTION_MAPSEL_0, ACTION_MAPSEL_1, ACTION_MAPSEL_2, ACTION_MAPSEL_3 }
[TEST_NUM_ROWS-1] = { ACTION_MAPSEL_0, ACTION_MAPSEL_1, ACTION_MAPSEL_2, ACTION_MAPSEL_3 }
#define ASDF_TEST_PLAIN_MAP \
{ \
@ -137,59 +140,6 @@
#define TRIPLE_TESTS_KEYMAP ASDF_TEST_CAPS_MAP_INDEX
#define ASDF_TEST_KEYMAP_INITIALIZER_LENGTH 5
#define ASDF_TEST_KEYMAP_INITIALIZER_1 \
{ \
{ \
/* 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 \
} \
}
#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, \
} \
}
#define ASDF_TEST_KEYMAP_INITIALIZER ASDF_TEST_KEYMAP_INITIALIZER_1, ASDF_TEST_KEYMAP_INITIALIZER_2
@ -231,11 +181,6 @@
#define SHIFT_MATRIX_2 RESERVED_7
#define CTRL_MATRIX_2 RESERVED_8
#define ASDF_LAST_ROW (ASDF_NUM_ROWS - 1)
#define ASDF_TEST_MAP_DIP_SWITCHES \
[ASDF_LAST_ROW] = { ACTION_MAPSEL_0, ACTION_MAPSEL_1, ACTION_MAPSEL_2, ACTION_MAPSEL_3 }
#define ASDF_TEST2_PLAIN_MAP \
{ \
{ PLAIN_MATRIX_2, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \

View File

@ -14,15 +14,15 @@
#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;
static const FLASH asdf_keycode_matrix_t test_CTRL_matrix = ASDF_TEST_CTRL_MAP;
static const FLASH asdf_keycode_t test_PLAIN_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST_PLAIN_MAP;
static const FLASH asdf_keycode_t test_SHIFT_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST_SHIFT_MAP;
static const FLASH asdf_keycode_t test_CAPS_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST_CAPS_MAP;
static const FLASH asdf_keycode_t test_CTRL_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST_CTRL_MAP;
static const FLASH asdf_keycode_matrix_t test2_PLAIN_matrix = ASDF_TEST2_PLAIN_MAP;
static const FLASH asdf_keycode_matrix_t test2_SHIFT_matrix = ASDF_TEST2_SHIFT_MAP;
static const FLASH asdf_keycode_matrix_t test2_CAPS_matrix = ASDF_TEST2_CAPS_MAP;
static const FLASH asdf_keycode_matrix_t test2_CTRL_matrix = ASDF_TEST2_CTRL_MAP;
static const FLASH asdf_keycode_t test2_PLAIN_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST2_PLAIN_MAP;
static const FLASH asdf_keycode_t test2_SHIFT_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST2_SHIFT_MAP;
static const FLASH asdf_keycode_t test2_CAPS_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST2_CAPS_MAP;
static const FLASH asdf_keycode_t test2_CTRL_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST2_CTRL_MAP;
// row: row number
// col: column number
@ -96,8 +96,8 @@ coord_t *find_code(asdf_keycode_t code)
uint32_t done = 0;
static coord_t location = { .row = -1, .col = -1 };
for (uint32_t row = 0; !done && (row < ASDF_NUM_ROWS); row++) {
for (uint32_t col = 0; !done && (col < ASDF_NUM_COLS); col++) {
for (uint32_t row = 0; !done && (row < TEST_NUM_ROWS); row++) {
for (uint32_t col = 0; !done && (col < TEST_NUM_COLS); col++) {
if (test_PLAIN_matrix[row][col] == code) {
done = 1;
location.row = row;
@ -113,7 +113,7 @@ void setUp(void)
{
coord_t *temp;
asdf_setup_test_plain_map();
setup_test_plain_map();
setup_test_caps_map();
setup_test2_plain_map();
setup_test2_caps_map();
@ -128,6 +128,12 @@ void setUp(void)
temp = find_code(TESTKEYMAP_TAG);
keymap_tag = *temp;
setup_test_plain_map();
setup_test_caps_map();
setup_test2_plain_map();
setup_test2_caps_map();
}
void tearDown(void) {}
@ -220,10 +226,10 @@ void keymap1_capsmap_plain_maps_to_caps(void)
void dip_switch_codes_are_in_last_row_test1_map(void)
{
coord_t dip_switches[NUM_DIPSWITCHES] = { { .row = ASDF_LAST_ROW, .col = 0 },
{ .row = ASDF_LAST_ROW, .col = 1 },
{ .row = ASDF_LAST_ROW, .col = 2 },
{ .row = ASDF_LAST_ROW, .col = 3 } };
coord_t dip_switches[NUM_DIPSWITCHES] = { { .row = (TEST_NUM_ROWS - 1), .col = 0 },
{ .row = (TEST_NUM_ROWS - 1), .col = 1 },
{ .row = (TEST_NUM_ROWS - 1), .col = 2 },
{ .row = (TEST_NUM_ROWS - 1), .col = 3 } };
for (uint8_t i = 0; i < NUM_DIPSWITCHES; i++) {
asdf_keycode_t code =
asdf_keymaps_get_code(dip_switches[i].row, dip_switches[i].col, ASDF_TEST_PLAIN_MAP_INDEX);
@ -233,10 +239,10 @@ void dip_switch_codes_are_in_last_row_test1_map(void)
void dip_switch_codes_are_in_last_row_test2_map(void)
{
coord_t dip_switches[NUM_DIPSWITCHES] = { { .row = ASDF_LAST_ROW, .col = 0 },
{ .row = ASDF_LAST_ROW, .col = 1 },
{ .row = ASDF_LAST_ROW, .col = 2 },
{ .row = ASDF_LAST_ROW, .col = 3 } };
coord_t dip_switches[NUM_DIPSWITCHES] = { { .row = (TEST_NUM_ROWS - 1), .col = 0 },
{ .row = (TEST_NUM_ROWS - 1), .col = 1 },
{ .row = (TEST_NUM_ROWS - 1), .col = 2 },
{ .row = (TEST_NUM_ROWS - 1), .col = 3 } };
for (uint8_t i = 0; i < NUM_DIPSWITCHES; i++) {
asdf_keycode_t code =
asdf_keymaps_get_code(dip_switches[i].row, dip_switches[i].col, ASDF_TEST2_PLAIN_MAP_INDEX);