From 952e425986cc95a4066f1f2b79e7b0a8368432e3 Mon Sep 17 00:00:00 2001 From: Dave Date: Sun, 21 Feb 2021 11:58:24 -0600 Subject: [PATCH] New map scheme passes all tests. (Issue #25) --- firmware/asdf/src/asdf_config.h | 12 +- firmware/asdf/test/asdf_keymap_defs_test.h | 275 -------------------- firmware/asdf/test/asdf_keymap_defs_test2.h | 239 ----------------- firmware/asdf/test/test_asdf_buffer.c | 4 +- firmware/asdf/test/test_asdf_hook.c | 36 +-- firmware/asdf/test/test_asdf_keymap_defs.c | 30 ++- firmware/asdf/test/test_asdf_keymap_defs.h | 74 +----- firmware/asdf/test/test_asdf_lib.h | 2 +- 8 files changed, 56 insertions(+), 616 deletions(-) delete mode 100644 firmware/asdf/test/asdf_keymap_defs_test.h delete mode 100644 firmware/asdf/test/asdf_keymap_defs_test2.h diff --git a/firmware/asdf/src/asdf_config.h b/firmware/asdf/src/asdf_config.h index 2dc238c..8c5139d 100644 --- a/firmware/asdf/src/asdf_config.h +++ b/firmware/asdf/src/asdf_config.h @@ -52,18 +52,8 @@ // Max number of keymaps supported (defines size of keymap setup routine array) #define ASDF_NUM_KEYMAPS 16 -// 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 -#define ASDF_KEYMAP_INITIALIZER_LENGTH 6 - -// Size of keymap hook function initializer list. These lists are defined in the -// keymap modules. This should be large enough to accommodate the largest list -// among the included keymaps -#define ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH 2 - // size of the keycode output buffer. -#define ASDF_KEYCODE_BUFFER_SIZE 16 +#define ASDF_KEYCODE_BUFFER_SIZE 64 // key debounce period (in msec) #define ASDF_DEBOUNCE_TIME_MS 10 diff --git a/firmware/asdf/test/asdf_keymap_defs_test.h b/firmware/asdf/test/asdf_keymap_defs_test.h deleted file mode 100644 index 35598dd..0000000 --- a/firmware/asdf/test/asdf_keymap_defs_test.h +++ /dev/null @@ -1,275 +0,0 @@ -// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*- -// -// Unfified Keyboard Project -// ASDF keyboard firmware -// -// asdf_keymaps.h -// -// 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 . - -// 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_TEST_H) -#define ASDF_KEYMAP_DEFS_TEST_H - -#define ASDF_TEST_NUM_ROWS 9 -#define ASDF_TEST_NUM_COLS 8 - -// The first value in each row serves two purposes: -// -// 1) Indicate a valid row of codes if the value is nonzero. -// 2) Indicate the physical row number corresponding to the keymap row. -// -// Multiple keymaps may be combined, some of which use more rows than other -// keymaps. The keymap with the most rows determines how many rows are allocated -// for each keymap. Since each keymap only initializes the rows it uses, then -// the shorter keymaps may have multiple uninitialized rows that should not be -// scanned. The C99 standard guarantees that all elements no explicitly -// initialized shall be initialized to 0 (C99 Standard 6.7.8.21). Therefore, -// keymap rows starting with a 0 are not valid and are not scanned. -// -// Some hardware may contain blank physical rows To avoid having unused empty -// rows, the first column of each row indicates the physical row. For example, 8 -// rows of switches (0-7), and a bank of DIP switches on row 15. In this case, -// only 9 rows need be allocated. - - -#define PLAIN_MATRIX_1 RESERVED_1 -#define CAPS_MATRIX_1 RESERVED_2 -#define SHIFT_MATRIX_1 RESERVED_3 -#define CTRL_MATRIX_1 RESERVED_4 - -#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_TEST_PLAIN_MAP \ - { \ - { PLAIN_MATRIX_1, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \ - ACTION_CAPS, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \ - { ACTION_NOTHING, 'p', ';', '/', ASCII_SPACE, 'z', 'a', 'q' }, \ - { ACTION_NOTHING, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \ - { ACTION_NOTHING, 'k', 'j', 'h', 'g', 'f', 'd', 's' }, \ - { ACTION_NOTHING, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \ - /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFTLOCK_ON, ASCII_CR, ASCII_LF, 'o', \ - 'l', ASCII_PERIOD }, \ - { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \ - { ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' }, ASDF_TEST_MAP_DIP_SWITCHES \ - } - -#define ASDF_TEST_CAPS_MAP \ - { \ - { CAPS_MATRIX_1, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \ - ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \ - { ACTION_NOTHING, 'P', ';', '/', ASCII_SPACE, 'Z', 'A', 'Q' }, \ - { ACTION_NOTHING, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \ - { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \ - { ACTION_NOTHING, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ - /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFTLOCK_ON, ASCII_CR, ASCII_LF, 'O', \ - 'L', ASCII_PERIOD }, \ - { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \ - { ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' }, ASDF_TEST_MAP_DIP_SWITCHES \ - } - -#define ASDF_TEST_SHIFT_MAP \ - { \ - \ - { SHIFT_MATRIX_1, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \ - ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_VERT_BAR }, \ - { ACTION_NOTHING, 'P', '+', '?', ASCII_SPACE, 'Z', 'A', 'Q' }, \ - { ACTION_NOTHING, '>', 'M', 'N', 'B', 'V', 'C', 'X' }, \ - { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \ - { ACTION_NOTHING, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ - { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFTLOCK_ON, ASCII_CR, ASCII_LF, 'O', 'L', '<' }, \ - { ASCII_TILDE, ASCII_RT_CURLY_BRACE, ASCII_LT_CURLY_BRACE, '=', '*', \ - '0', ASCII_RT_PAREN, ASCII_LT_PAREN }, \ - { ACTION_NOTHING, ASCII_SINGLE_QUOTE, '&', '%', '$', '#', ASCII_DOUBLE_QUOTE, '!' }, \ - ASDF_TEST_MAP_DIP_SWITCHES \ - } - - -#define ASDF_TEST_CTRL_MAP \ - { \ - { CTRL_MATRIX_1, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \ - ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, 0x1c }, \ - { ACTION_NOTHING, ASCII_CTRL_P, ACTION_NOTHING, ACTION_NOTHING, \ - ASCII_SPACE, ASCII_CTRL_Z, ASCII_CTRL_A, ASCII_CTRL_Q }, \ - { ACTION_NOTHING, ASCII_COMMA, ASCII_CTRL_M, ASCII_CTRL_N, \ - ASCII_CTRL_B, ASCII_CTRL_V, ASCII_CTRL_C, ASCII_CTRL_X }, \ - { ACTION_NOTHING, ASCII_CTRL_K, ASCII_CTRL_J, ASCII_CTRL_H, \ - ASCII_CTRL_G, ASCII_CTRL_F, ASCII_CTRL_D, ASCII_CTRL_S }, \ - { ACTION_NOTHING, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \ - ASCII_CTRL_T, ASCII_CTRL_R, ASCII_CTRL_E, ASCII_CTRL_W }, \ - { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFTLOCK_ON, ASCII_CR, \ - ASCII_LF, ASCII_CTRL_O, ASCII_CTRL_L, ACTION_NOTHING }, \ - { ACTION_NOTHING, 0x1d, ASCII_ESC, ACTION_NOTHING, \ - ACTION_NOTHING, ACTION_FN_1, ACTION_FN_9, ACTION_FN_8 }, \ - { ACTION_NOTHING, ACTION_FN_7, ACTION_FN_6, ACTION_FN_5, \ - ACTION_FN_4, ACTION_FN_3, ACTION_FN_2, ACTION_FN_2 }, \ - ASDF_TEST_MAP_DIP_SWITCHES \ - } - - -#define ASDF_TEST_DECLARATIONS \ - static const FLASH keycode_matrix_t test_PLAIN_matrix = ASDF_TEST_PLAIN_MAP; \ - static const FLASH keycode_matrix_t test_SHIFT_matrix = ASDF_TEST_SHIFT_MAP; \ - static const FLASH keycode_matrix_t test_CAPS_matrix = ASDF_TEST_CAPS_MAP; \ - static const FLASH keycode_matrix_t test_CTRL_matrix = ASDF_TEST_CTRL_MAP; - -#define ASDF_TEST_MAP_DEFS \ - { \ - &test_PLAIN_matrix, &test_SHIFT_matrix, &test_CAPS_matrix, &test_CTRL_matrix \ - } - -#define ASDF_TEST_CAPS_MAP_DEFS \ - { \ - &test_CAPS_matrix, &test_SHIFT_matrix, &test_CAPS_matrix, &test_CTRL_matrix \ - } - -#define ASDF_TEST_KEYMAPS ASDF_TEST_MAP_DEFS, ASDF_TEST_CAPS_MAP_DEFS - -#define ASDF_TEST_KEYMAPS_COUNT 2 -#define ASDF_TEST_PLAIN_MAP_INDEX ASDF_TEST_BASE + 0 -#define ASDF_TEST_CAPS_MAP_INDEX ASDF_TEST_BASE + 1 - -#define SINGLE_TESTS_KEYMAP ASDF_TEST_PLAIN_MAP_INDEX -#define DOUBLE_ASSIGN_TEST_KEYMAP ASDF_TEST_PLAIN_MAP_INDEX - -#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 - -#define ASDF_TEST_KEYMAP_HOOK_INITIALIZER_LENGTH 2 - -#define ASDF_TEST_KEYMAP_HOOK_INITIALIZER_1 \ - { \ - { \ - .hook_id = ASDF_HOOK_KEYMAP_SETUP, \ - .hook_func = &test_hook_1, \ - }, \ - { \ - .hook_id = ASDF_HOOK_KEYMAP_SETUP, \ - .hook_func = &test_hook_2, \ - }, \ - } - -#define ASDF_TEST_KEYMAP_HOOK_INITIALIZER_2 \ - { \ - { \ - .hook_id = ASDF_HOOK_KEYMAP_SETUP, \ - .hook_func = &test_hook_3, \ - }, \ - { \ - .hook_id = ASDF_HOOK_KEYMAP_SETUP, \ - .hook_func = &test_hook_4, \ - }, \ - } - -#define ASDF_TEST_KEYMAP_HOOK_INITIALIZER \ - ASDF_TEST_KEYMAP_HOOK_INITIALIZER_1, ASDF_TEST_KEYMAP_HOOK_INITIALIZER_2 - - -// The following preprocessor "code" permits various keymaps to be created and -// included without generating a lot of complicating code dependencies. The use -// of macros in this way is a bit ugly, I realize, and stretches the intention -// of the C preprocessor. The C preprocessor is used to store a bit of state to -// keep track of the number and ordering of the keymaps as they are added, and -// to keep track of the array sizes to be allocated at compile time. - - -#if !defined(ASDF_NUM_ROWS) || (ASDF_NUM_ROWS < ASDF_TEST_NUM_ROWS) -#undef ASDF_NUM_ROWS -#define ASDF_NUM_ROWS ASDF_TEST_NUM_ROWS -#endif - -#if !defined(ASDF_NUM_COLS) || (ASDF_NUM_COLS < ASDF_TEST_NUM_COLS) -#undef ASDF_NUM_COLS -#define ASDF_NUM_COLS ASDF_TEST_NUM_COLS -#endif - -#if !defined(ASDF_KEYMAP_INITIALIZER_LENGTH) \ - || (ASDF_KEYMAP_INITIALIZER_LENGTH < ASDF_TEST_KEYMAP_INITIALIZER_LENGTH) -#undef ASDF_KEYMAP_INITIALIZER_LENGTH -#define ASDF_KEYMAP_INITIALIZER_LENGTH ASDF_TEST_KEYMAP_INITIALIZER_LENGTH -#endif - -#if !defined(ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH) \ - || (ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH < ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_LENGTH) -#undef ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH -#define ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_LENGTH -#endif - -#endif /* !defined (ASDF_KEYMAP_DEFS_TEST_H) */ - -//-------|---------|---------+---------+---------+---------+---------+---------+ -// Above line is 80 columns, and should display completely in the editor. diff --git a/firmware/asdf/test/asdf_keymap_defs_test2.h b/firmware/asdf/test/asdf_keymap_defs_test2.h deleted file mode 100644 index a26512d..0000000 --- a/firmware/asdf/test/asdf_keymap_defs_test2.h +++ /dev/null @@ -1,239 +0,0 @@ -// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*- -// -// Unfified Keyboard Project -// ASDF keyboard firmware -// -// asdf_keymaps.h -// -// 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 . - -// 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_TEST2_H) -#define ASDF_KEYMAP_DEFS_TEST2_H - -#define ASDF_TEST2_NUM_ROWS 16 -#define ASDF_TEST2_NUM_COLS 8 - -// The first value in each row serves two purposes: -// -// 1) Indicate a valid row of codes if the value is nonzero. -// 2) Indicate the physical row number corresponding to the keymap row. -// -// Multiple keymaps may be combined, some of which use more rows than other -// keymaps. The keymap with the most rows determines how many rows are allocated -// for each keymap. Since each keymap only initializes the rows it uses, then -// the shorter keymaps may have multiple uninitialized rows that should not be -// scanned. The C99 standard guarantees that all elements no explicitly -// initialized shall be initialized to 0 (C99 Standard 6.7.8.21). Therefore, -// keymap rows starting with a 0 are not valid and are not scanned. -// -// Some hardware may contain blank physical rows To avoid having unused empty -// rows, the first column of each row indicates the physical row. For example, 8 -// rows of switches (0-7), and a bank of DIP switches on row 15. In this case, -// only 9 rows need be allocated. - - -#define PLAIN_MATRIX_2 RESERVED_5 -#define CAPS_MATRIX_2 RESERVED_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, \ - ACTION_CAPS, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \ - { ACTION_NOTHING, 'p', ';', '/', ASCII_SPACE, 'z', 'a', 'q' }, \ - { ACTION_NOTHING, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \ - { ACTION_NOTHING, 'k', 'j', 'h', 'g', 'f', 'd', 's' }, \ - { ACTION_NOTHING, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \ - /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFTLOCK_ON, ASCII_CR, ASCII_LF, 'o', \ - 'l', ASCII_PERIOD }, \ - { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \ - { ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' }, ASDF_TEST_MAP_DIP_SWITCHES \ - } - -#define ASDF_TEST2_CAPS_MAP \ - { \ - { CAPS_MATRIX_2, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \ - ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_BACKSLASH }, \ - { ACTION_NOTHING, 'P', ';', '/', ASCII_SPACE, 'Z', 'A', 'Q' }, \ - { ACTION_NOTHING, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \ - { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \ - { ACTION_NOTHING, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ - /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFTLOCK_ON, ASCII_CR, ASCII_LF, 'O', \ - 'L', ASCII_PERIOD }, \ - { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \ - { ACTION_NOTHING, '7', '6', '5', '4', '3', '2', '1' }, ASDF_TEST_MAP_DIP_SWITCHES \ - } - -#define ASDF_TEST2_SHIFT_MAP \ - { \ - \ - { SHIFT_MATRIX_2, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \ - ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, ASCII_VERT_BAR }, \ - { ACTION_NOTHING, 'P', '+', '?', ASCII_SPACE, 'Z', 'A', 'Q' }, \ - { ACTION_NOTHING, '>', 'M', 'N', 'B', 'V', 'C', 'X' }, \ - { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \ - { ACTION_NOTHING, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ - { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFTLOCK_ON, ASCII_CR, ASCII_LF, 'O', 'L', '<' }, \ - { ASCII_TILDE, ASCII_RT_CURLY_BRACE, ASCII_LT_CURLY_BRACE, '=', '*', \ - '0', ASCII_RT_PAREN, ASCII_LT_PAREN }, \ - { ACTION_NOTHING, ASCII_SINGLE_QUOTE, '&', '%', '$', '#', ASCII_DOUBLE_QUOTE, '!' }, \ - ASDF_TEST_MAP_DIP_SWITCHES \ - } - - -#define ASDF_TEST2_CTRL_MAP \ - { \ - { CTRL_MATRIX_2, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \ - ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, 0x1c }, \ - { ACTION_NOTHING, ASCII_CTRL_P, ACTION_NOTHING, ACTION_NOTHING, \ - ASCII_SPACE, ASCII_CTRL_Z, ASCII_CTRL_A, ASCII_CTRL_Q }, \ - { ACTION_NOTHING, ASCII_COMMA, ASCII_CTRL_M, ASCII_CTRL_N, \ - ASCII_CTRL_B, ASCII_CTRL_V, ASCII_CTRL_C, ASCII_CTRL_X }, \ - { ACTION_NOTHING, ASCII_CTRL_K, ASCII_CTRL_J, ASCII_CTRL_H, \ - ASCII_CTRL_G, ASCII_CTRL_F, ASCII_CTRL_D, ASCII_CTRL_S }, \ - { ACTION_NOTHING, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \ - ASCII_CTRL_T, ASCII_CTRL_R, ASCII_CTRL_E, ASCII_CTRL_W }, \ - { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFTLOCK_ON, ASCII_CR, \ - ASCII_LF, ASCII_CTRL_O, ASCII_CTRL_L, ACTION_NOTHING }, \ - { ACTION_NOTHING, 0x1d, ASCII_ESC, ACTION_NOTHING, \ - ACTION_NOTHING, ACTION_FN_1, ACTION_FN_9, ACTION_FN_8 }, \ - { ACTION_NOTHING, ACTION_FN_7, ACTION_FN_6, ACTION_FN_5, \ - ACTION_FN_4, ACTION_FN_3, ACTION_FN_2, ACTION_FN_2 }, \ - ASDF_TEST_MAP_DIP_SWITCHES \ - } - - -#define ASDF_TEST2_DECLARATIONS \ - static const FLASH keycode_matrix_t test2_PLAIN_matrix = ASDF_TEST2_PLAIN_MAP; \ - static const FLASH keycode_matrix_t test2_SHIFT_matrix = ASDF_TEST2_SHIFT_MAP; \ - static const FLASH keycode_matrix_t test2_CAPS_matrix = ASDF_TEST2_CAPS_MAP; \ - static const FLASH keycode_matrix_t test2_CTRL_matrix = ASDF_TEST2_CTRL_MAP; - -#define ASDF_TEST2_MAP_DEFS \ - { \ - &test2_PLAIN_matrix, &test2_SHIFT_matrix, &test2_CAPS_matrix, &test2_CTRL_matrix \ - } - -#define ASDF_TEST2_CAPS_MAP_DEFS \ - { \ - &test2_CAPS_matrix, &test2_SHIFT_matrix, &test2_CAPS_matrix, &test2_CTRL_matrix \ - } - -#define ASDF_TEST2_KEYMAPS ASDF_TEST2_MAP_DEFS, ASDF_TEST2_CAPS_MAP_DEFS - -#define ASDF_TEST2_KEYMAPS_COUNT 2 -#define ASDF_TEST2_PLAIN_MAP_INDEX (ASDF_TEST2_BASE + 0) -#define ASDF_TEST2_CAPS_MAP_INDEX (ASDF_TEST2_BASE + 1) -#define VCAPS_TEST_KEYMAP ASDF_TEST2_PLAIN_MAP_INDEX -#define VSHIFT_TEST_KEYMAP ASDF_TEST2_PLAIN_MAP_INDEX - -#define ASDF_TEST2_KEYMAP_INITIALIZER_LENGTH 4 -#define ASDF_TEST2_KEYMAP_INITIALIZER_1 \ - { \ - { .virtual_device = VCAPS_LED, .physical_device = PHYSICAL_LED1, .initial_value = 0 }, \ - { .virtual_device = VSHIFT_LED, .physical_device = PHYSICAL_LED2, .initial_value = 0 }, \ - { .virtual_device = VOUT2, .physical_device = PHYSICAL_OUT3, .initial_value = 0 }, \ - { \ - .virtual_device = VOUT2, .physical_device = ASDF_PHYSICAL_NUM_RESOURCES, .initial_value = 0 \ - } \ - } - -#define ASDF_TEST2_KEYMAP_INITIALIZER_2 \ - { \ - { .virtual_device = VCAPS_LED, .physical_device = PHYSICAL_LED1, .initial_value = 0 }, \ - { .virtual_device = VSHIFT_LED, .physical_device = PHYSICAL_LED2, .initial_value = 0 }, \ - { .virtual_device = VOUT2, .physical_device = PHYSICAL_OUT3, .initial_value = 0 }, \ - { \ - .virtual_device = VOUT2, .physical_device = ASDF_PHYSICAL_NUM_RESOURCES, .initial_value = 0 \ - } \ - } - -#define ASDF_TEST2_KEYMAP_INITIALIZER \ - ASDF_TEST2_KEYMAP_INITIALIZER_1, ASDF_TEST2_KEYMAP_INITIALIZER_2 - - -#define ASDF_TEST_ALTERNATE_SCANNER_MAP (ASDF_TEST2_BASE + 0) -#define ASDF_TEST_ALTERNATE_OUTPUT_MAP (ASDF_TEST2_BASE + 0) -#define ASDF_TEST_EACH_SCAN_MAP (ASDF_TEST2_BASE + 1) -#define ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_LENGTH 2 -#define ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_1 \ - { \ - { \ - .hook_id = ASDF_HOOK_SCANNER, \ - .hook_func = (asdf_hook_function_t) test_hook_read_row, \ - }, \ - { \ - .hook_id = ASDF_HOOK_OUTPUT, \ - .hook_func = (asdf_hook_function_t) test_hook_output, \ - }, \ - } - -#define ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_2 \ - { \ - { \ - .hook_id = ASDF_HOOK_EACH_SCAN, \ - .hook_func = (asdf_hook_function_t) test_hook_each_scan, \ - }, \ - } - -#define ASDF_TEST2_KEYMAP_HOOK_INITIALIZER \ - ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_1, ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_2 - - -// The following preprocessor "code" permits various keymaps to be created and -// included without generating a lot of complicating code dependencies. The use -// of macros in this way is a bit ugly, I realize, and stretches the intention -// of the C preprocessor. The C preprocessor is used to store a bit of state to -// keep track of the number and ordering of the keymaps as they are added, and -// to keep track of the array sizes to be allocated at compile time. - - -#if !defined(ASDF_NUM_ROWS) || (ASDF_NUM_ROWS < ASDF_TEST2_NUM_ROWS) -#undef ASDF_NUM_ROWS -#define ASDF_NUM_ROWS ASDF_TEST2_NUM_ROWS -#endif - -#if !defined(ASDF_NUM_COLS) || (ASDF_NUM_COLS < ASDF_TEST2_NUM_COLS) -#undef ASDF_NUM_COLS -#define ASDF_NUM_COLS ASDF_TEST2_NUM_COLS -#endif - -#if !defined(ASDF_KEYMAP_INITIALIZER_LENGTH) \ - || (ASDF_KEYMAP_INITIALIZER_LENGTH < ASDF_TEST2_KEYMAP_INITIALIZER_LENGTH) -#undef ASDF_KEYMAP_INITIALIZER_LENGTH -#define ASDF_KEYMAP_INITIALIZER_LENGTH ASDF_TEST2_KEYMAP_INITIALIZER_LENGTH -#endif - -#if !defined(ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH) \ - || (ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH < ASDF_TEST_KEYMAP_HOOK_INITIALIZER_LENGTH) -#undef ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH -#define ASDF_KEYMAP_HOOK_INITIALIZER_LENGTH ASDF_TEST_KEYMAP_HOOK_INITIALIZER_LENGTH -#endif - -#endif /* !defined (ASDF_KEYMAP_DEFS_TEST2_H) */ - -//-------|---------|---------+---------+---------+---------+---------+---------+ -// Above line is 80 columns, and should display completely in the editor. diff --git a/firmware/asdf/test/test_asdf_buffer.c b/firmware/asdf/test/test_asdf_buffer.c index cd20f8e..0763336 100644 --- a/firmware/asdf/test/test_asdf_buffer.c +++ b/firmware/asdf/test/test_asdf_buffer.c @@ -10,7 +10,9 @@ #define MAX_BUFFER ASDF_BUFFER_POOL_SIZE #define HALF_BUFFER (ASDF_BUFFER_POOL_SIZE / 2) -static const char test_string[] = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static const char test_string[] = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + static const char * const more_strings[] = { "abcdefghijkl", "12345", diff --git a/firmware/asdf/test/test_asdf_hook.c b/firmware/asdf/test/test_asdf_hook.c index 2caac03..02f79e5 100644 --- a/firmware/asdf/test/test_asdf_hook.c +++ b/firmware/asdf/test/test_asdf_hook.c @@ -12,6 +12,7 @@ #include "asdf_repeat.h" #include "asdf_hook.h" #include "test_asdf_lib.h" +#include "test_asdf_keymap_defs.h" //ASDF_TEST_DECLARATIONS; @@ -28,6 +29,14 @@ void setUp(void) test_hook_clear(); asdf_keymaps_init(); asdf_init(); + + asdf_keymaps_register(ASDF_TEST_PLAIN_MAP_INDEX, &setup_test_hooks_map0); + asdf_keymaps_register(ASDF_TEST_CAPS_MAP_INDEX, &setup_test_hooks_map1); + asdf_keymaps_register(ASDF_TEST2_PLAIN_MAP_INDEX, &setup_test_hooks_map2); + asdf_keymaps_register(ASDF_TEST2_CAPS_MAP_INDEX, &setup_test_hooks_map3); + + asdf_keymaps_select(0); + } void tearDown(void) {} @@ -37,7 +46,7 @@ typedef asdf_cols_t (*scanner_func_t)(uint8_t); void test_default_scan_hook_is_default_scanner(void) { - scanner_func_t testfunc = (scanner_func_t) asdf_hook_get(ASDF_HOOK_SCANNER); + scanner_func_t testfunc = (scanner_func_t) asdf_hook_get(ASDF_HOOK_SCANNER); asdf_cols_t testval = 0; // make sure the pointer points to the correct function @@ -51,7 +60,7 @@ void test_default_scan_hook_is_default_scanner(void) // test_alternate_scan_hook void test_alternate_scan_hook(void) { - asdf_keymaps_select_keymap(ASDF_TEST_ALTERNATE_SCANNER_MAP); + asdf_keymaps_select(ASDF_TEST_ALTERNATE_SCANNER_MAP); scanner_func_t testfunc = (scanner_func_t) asdf_hook_get(ASDF_HOOK_SCANNER); asdf_cols_t testval = 0; @@ -69,7 +78,7 @@ void test_each_scan_hook_is_executed_each_scan(void) { test_hook_clear(); - asdf_keymaps_select_keymap(ASDF_TEST_EACH_SCAN_MAP); + asdf_keymaps_select(ASDF_TEST_EACH_SCAN_MAP); TEST_ASSERT_EQUAL_INT(0, test_hook_readback()); for (int i = 0; i < NUM_SCAN_TEST_REPS; i++) { asdf_keyscan(); @@ -77,25 +86,6 @@ void test_each_scan_hook_is_executed_each_scan(void) TEST_ASSERT_EQUAL_INT(NUM_SCAN_TEST_REPS, test_hook_readback()); } -// Check that setup hooks are executed immediately -void test_setup_hook_is_executed_immediately(void) -{ - test_hook_clear(); - asdf_keymaps_select_keymap(0); - uint32_t expected = TEST_HOOK_VAL1 | TEST_HOOK_VAL2; - TEST_ASSERT_EQUAL_INT(expected, test_hook_readback()); -} - -// Check that setup hooks are executed properly after selecting nonzero map -void test_setup_hook_is_executed_immediately_when_selecting_nonzero_map(void) -{ - test_hook_clear(); - asdf_keymaps_select_keymap(1); - uint32_t expected = TEST_HOOK_VAL3 | TEST_HOOK_VAL4; - TEST_ASSERT_EQUAL_INT(expected, test_hook_readback()); -} - - int main(void) @@ -103,8 +93,6 @@ int main(void) UNITY_BEGIN(); RUN_TEST(test_default_scan_hook_is_default_scanner); RUN_TEST(test_alternate_scan_hook); - RUN_TEST(test_setup_hook_is_executed_immediately); - RUN_TEST(test_setup_hook_is_executed_immediately_when_selecting_nonzero_map); RUN_TEST(test_each_scan_hook_is_executed_each_scan); return UNITY_END(); } diff --git a/firmware/asdf/test/test_asdf_keymap_defs.c b/firmware/asdf/test/test_asdf_keymap_defs.c index b951a57..3d71f57 100644 --- a/firmware/asdf/test/test_asdf_keymap_defs.c +++ b/firmware/asdf/test/test_asdf_keymap_defs.c @@ -27,7 +27,7 @@ #include "asdf_ascii.h" #include "asdf_modifiers.h" #include "asdf_keymaps.h" - +#include "test_asdf_lib.h" 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; @@ -147,7 +147,35 @@ void setup_test_vdevs_map3(void) asdf_virtual_sync(); } +void setup_test_hooks_map0(void) +{ + setup_test_plain_map(); + asdf_hook_init(); +} +void setup_test_hooks_map1(void) +{ + setup_test_caps_map(); + asdf_hook_init(); +} + +void setup_test_hooks_map2(void) +{ + setup_test2_plain_map(); + + asdf_hook_init(); + asdf_hook_assign(ASDF_HOOK_SCANNER, (void (*)(void)) &test_hook_read_row); + asdf_hook_assign(ASDF_HOOK_OUTPUT, (void (*)(void)) &test_hook_output); + +} + +void setup_test_hooks_map3(void) +{ + setup_test2_caps_map(); + + asdf_hook_init(); + asdf_hook_assign(ASDF_HOOK_EACH_SCAN, &test_hook_each_scan); +} //-------|---------|---------+---------+---------+---------+---------+---------+ diff --git a/firmware/asdf/test/test_asdf_keymap_defs.h b/firmware/asdf/test/test_asdf_keymap_defs.h index f528bb7..a145c6a 100644 --- a/firmware/asdf/test/test_asdf_keymap_defs.h +++ b/firmware/asdf/test/test_asdf_keymap_defs.h @@ -214,82 +214,28 @@ #define VCAPS_TEST_KEYMAP ASDF_TEST2_PLAIN_MAP_INDEX #define VSHIFT_TEST_KEYMAP ASDF_TEST2_PLAIN_MAP_INDEX - // keymap assignments for the hook mechanism tests -#define ASDF_TEST_ALTERNATE_SCANNER_MAP (ASDF_TEST2_BASE + 0) -#define ASDF_TEST_ALTERNATE_OUTPUT_MAP (ASDF_TEST2_BASE + 0) -#define ASDF_TEST_EACH_SCAN_MAP (ASDF_TEST2_BASE + 1) - - -#define ASDF_TEST_KEYMAP_HOOK_INITIALIZER_LENGTH 2 - -#define ASDF_TEST_KEYMAP_HOOK_INITIALIZER_1 \ - { \ - { \ - .hook_id = ASDF_HOOK_KEYMAP_SETUP, \ - .hook_func = &test_hook_1, \ - }, \ - { \ - .hook_id = ASDF_HOOK_KEYMAP_SETUP, \ - .hook_func = &test_hook_2, \ - }, \ - } - -#define ASDF_TEST_KEYMAP_HOOK_INITIALIZER_2 \ - { \ - { \ - .hook_id = ASDF_HOOK_KEYMAP_SETUP, \ - .hook_func = &test_hook_3, \ - }, \ - { \ - .hook_id = ASDF_HOOK_KEYMAP_SETUP, \ - .hook_func = &test_hook_4, \ - }, \ - } - -#define ASDF_TEST_KEYMAP_HOOK_INITIALIZER \ - ASDF_TEST_KEYMAP_HOOK_INITIALIZER_1, ASDF_TEST_KEYMAP_HOOK_INITIALIZER_2 - - - - - -#define ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_LENGTH 2 -#define ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_1 \ - { \ - { \ - .hook_id = ASDF_HOOK_SCANNER, \ - .hook_func = (asdf_hook_function_t) test_hook_read_row, \ - }, \ - { \ - .hook_id = ASDF_HOOK_OUTPUT, \ - .hook_func = (asdf_hook_function_t) test_hook_output, \ - }, \ - } - -#define ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_2 \ - { \ - { \ - .hook_id = ASDF_HOOK_EACH_SCAN, \ - .hook_func = (asdf_hook_function_t) test_hook_each_scan, \ - }, \ - } - -#define ASDF_TEST2_KEYMAP_HOOK_INITIALIZER \ - ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_1, ASDF_TEST2_KEYMAP_HOOK_INITIALIZER_2 - -#endif /* !defined (TEST_ASDF_KEYMAP_DEFS_H) */ +#define ASDF_TEST_ALTERNATE_SCANNER_MAP ASDF_TEST2_PLAIN_MAP_INDEX +#define ASDF_TEST_ALTERNATE_OUTPUT_MAP ASDF_TEST2_PLAIN_MAP_INDEX +#define ASDF_TEST_EACH_SCAN_MAP ASDF_TEST2_CAPS_MAP_INDEX void setup_test_plain_map(void); void setup_test_caps_map(void); void setup_test2_plain_map(void); void setup_test2_caps_map(void); + void setup_test_vdevs_map0(void); void setup_test_vdevs_map1(void); void setup_test_vdevs_map2(void); void setup_test_vdevs_map3(void); +void setup_test_hooks_map0(void); +void setup_test_hooks_map1(void); +void setup_test_hooks_map2(void); +void setup_test_hooks_map3(void); + +#endif /* !defined (TEST_ASDF_KEYMAP_DEFS_H) */ //-------|---------|---------+---------+---------+---------+---------+---------+ // Above line is 80 columns, and should display completely in the editor. diff --git a/firmware/asdf/test/test_asdf_lib.h b/firmware/asdf/test/test_asdf_lib.h index 45fb05f..478fc2e 100644 --- a/firmware/asdf/test/test_asdf_lib.h +++ b/firmware/asdf/test/test_asdf_lib.h @@ -1,4 +1,5 @@ #if !defined(TEST_ASDF_LIB_H) +#define TEST_ASDF_LIB_H #define TEST_HOOK_VAL1 1 #define TEST_HOOK_VAL2 2 @@ -19,5 +20,4 @@ uint8_t test_hook_read_row(uint8_t val); void test_hook_output(uint8_t val); -#define TEST_ASDF_LIB_H #endif // if !defined(TEST_ASDF_LIB_H)