From 73e2760d948fbceb503ab4218168da5478a2632d Mon Sep 17 00:00:00 2001 From: David Fenyes Date: Wed, 11 Mar 2020 01:50:27 -0500 Subject: [PATCH] Add more unit tests for virtual layer - use macros to designate which keymaps are used to setup the tests. --- firmware/asdf/src/Arch/asdf_arch_test.c | 37 +++++++------- .../src/Keymaps/asdf_keymap_defs_apple2.h | 48 ++++++++++++++----- .../asdf/src/Keymaps/asdf_keymap_defs_ascii.h | 47 ++++++++++++++---- .../asdf/src/Keymaps/asdf_keymap_defs_test.h | 32 +++++++++---- .../asdf/src/Keymaps/asdf_keymap_defs_test2.h | 33 +++++++++---- 5 files changed, 139 insertions(+), 58 deletions(-) diff --git a/firmware/asdf/src/Arch/asdf_arch_test.c b/firmware/asdf/src/Arch/asdf_arch_test.c index 98c792f..44c7d5d 100644 --- a/firmware/asdf/src/Arch/asdf_arch_test.c +++ b/firmware/asdf/src/Arch/asdf_arch_test.c @@ -108,24 +108,6 @@ static pulse_state_t pulse_transition_table[PD_ST_NUM_VALID_PULSE_STATES][NUM_PU static uint8_t outputs[NUM_REAL_OUTPUTS]; static pulse_state_t pulses[NUM_REAL_OUTPUTS]; -// PROCEDURE: asdf_arch_null_output -// INPUTS: (uint8_t) value - ignored -// OUTPUTS: none -// -// DESCRIPTION: Does nothing. -// -// SIDE EFFECTS: See above. -// -// NOTES: -// -// SCOPE: public -// -// COMPLEXITY: 2 -// -void asdf_arch_null_output(uint8_t value) -{ - (void) value; -} // PROCEDURE: pulse_detect // INPUTS: (pulse_state_t) current_state @@ -179,6 +161,25 @@ static void set_output(asdf_virtual_real_dev_t output_dev, uint8_t value) pulses[output_dev] = pulse_detect(pulses[output_dev], pulse_event); } +// PROCEDURE: asdf_arch_null_output +// INPUTS: (uint8_t) value - ignored +// OUTPUTS: none +// +// DESCRIPTION: Does nothing. +// +// SIDE EFFECTS: See above. +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 2 +// +void asdf_arch_null_output(uint8_t value) +{ + set_output(VMAP_NO_OUT, value); +} + // PROCEDURE: asdf_arch_led1_set // INPUTS: (uint8_t) value diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h index b091694..56387e3 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h @@ -50,36 +50,60 @@ #define ASDF_ASCII_NUM_ROWS 16 // DIP switches are row 15. #define ASDF_ASCII_NUM_COLS 8 +#define ACTION_RESET ACTION_VOUT1 #define VIRTUAL_RESET VOUT1 #define RESET_OUTPUT VMAP_OUT3_OC #define RESET_ACTIVE_VALUE 0 +#define ACTION_CLEAR ACTION_VOUT2 #define VIRTUAL_CLR_SCR VOUT2 -#define CLR_SCR_OUT VMAP_OUT1 +#define CLR_SCR_OUTPUT VMAP_OUT1 #define CLR_SCR_ACTIVE_VALUE 1 #define VIRTUAL_POWER_LED VLED1 #define POWER_LED VMAP_LED1 #define POWER_LED_INIT_VALUE 1 -#define ASDF_APPLE2_KEYMAP_INITIALIZER_LENGTH 4 -#define ASDF_APPLE2_KEYMAP_INITIALIZER \ +#define ASDF_APPLE2_KEYMAP_INITIALIZER_LENGTH 3 + + +// The PLAIN map uses the "power" button as a caps-lock, so map the CAPS LED to +// the power button LED. +#define ASDF_APPLE2_PLAIN_KEYMAP_INITIALIZER \ + { \ + { .virtual_device = VCAPS_LED, \ + .real_device = POWER_LED, \ + .initial_value = 0 }, \ + { .virtual_device = VIRTUAL_RESET, \ + .real_device = RESET_OUTPUT, \ + .function = V_PULSE, \ + .initial_value = !RESET_ACTIVE_VALUE }, \ + { .virtual_device = VIRTUAL_CLR_SCR, \ + .real_device = CLR_SCR_OUTPUT, \ + .function = V_PULSE, \ + .initial_value = !CLR_SCR_ACTIVE_VALUE } \ + } + +// The ALL CAPS map is the classic Apple II/II+ map. +#define ASDF_APPLE2_CAPS_KEYMAP_INITIALIZER \ { \ { .virtual_device = VIRTUAL_POWER_LED, \ - .real_device = POWER_LED, \ + .real_device = POWER_LED, \ .initial_value = POWER_LED_INIT_VALUE }, \ - { .virtual_device = VCAPS_LED, \ - .real_device = VMAP_LED3 }, \ - { .virtual_device = RESET_OUTPUT, \ - .real_device = VMAP_OUT1, \ + { .virtual_device = VIRTUAL_RESET, \ + .real_device = RESET_OUTPUT, \ .function = V_PULSE, \ - .initial_value = !CLR_SCR_ACTIVE_VALUE }, \ - { .virtual_device = CLR_SCR_OUT, \ - .real_device = VMAP_OUT3, \ + .initial_value = !RESET_ACTIVE_VALUE }, \ + { .virtual_device = VIRTUAL_CLR_SCR, \ + .real_device = CLR_SCR_OUTPUT, \ .function = V_PULSE, \ - .initial_value = !RESET_ACTIVE_VALUE } \ + .initial_value = !CLR_SCR_ACTIVE_VALUE } \ } + +#define ASDF_APPLE2_KEYMAP_INITIALIZER ASDF_APPLE2_PLAIN_KEYMAP_INITIALIZER, ASDF_APPLE2_CAPS_KEYMAP_INITIALIZER + + // TO ensure consistent DIP switch operation within the keymap, a // ASDF_APPLE2_DIP_SWITCHES macro is defined. Keeping the ACTION_MAPSEL0-3 // definitions in positions 0-3 ensures consistent map selection among all diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h index b8436ad..153cda1 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h @@ -51,24 +51,51 @@ #define POWER_LED VMAP_LED1 #define POWER_LED_INIT_VALUE 1 +#define CAPS_LED VMAP_LED3 +#define CAPS_LED_INIT_VALUE 0 + + #define ASDF_ASCII_KEYMAP_INITIALIZER_LENGTH 4 -#define ASDF_ASCII_KEYMAP_INITIALIZER \ + +#define ASDF_ASCII_PLAIN_KEYMAP_INITIALIZER \ { \ { .virtual_device = VIRTUAL_POWER_LED, \ - .real_device = POWER_LED, \ + .real_device = POWER_LED, \ .initial_value = POWER_LED_INIT_VALUE }, \ { .virtual_device = VCAPS_LED, \ - .real_device = VMAP_LED3 }, \ - { .virtual_device = RESET_OUTPUT, \ - .real_device = VMAP_OUT1, \ + .real_device = CAPS_LED, \ + .initial_value = CAPS_LED_INIT_VALUE }, \ + { .virtual_device = VIRTUAL_RESET, \ + .real_device = RESET_OUTPUT, \ .function = V_PULSE, \ - .initial_value = !CLR_SCR_ACTIVE_VALUE }, \ - { .virtual_device = CLR_SCR_OUT, \ - .real_device = VMAP_OUT3, \ - .function = V_PULSE, \ - .initial_value = !RESET_ACTIVE_VALUE } \ + .initial_value = !RESET_ACTIVE_VALUE }, \ + { .virtual_device = VIRTUAL_CLR_SCR, \ + .real_device = CLR_SCR_OUT, \ + .function = V_PULSE, \ + .initial_value = !CLR_SCR_ACTIVE_VALUE }, \ } +#define ASDF_ASCII_CAPS_KEYMAP_INITIALIZER \ + { \ + { .virtual_device = VIRTUAL_POWER_LED, \ + .real_device = POWER_LED, \ + .initial_value = POWER_LED_INIT_VALUE }, \ + { .virtual_device = VCAPS_LED, \ + .real_device = CAPS_LED, \ + .initial_value = CAPS_LED_INIT_VALUE }, \ + { .virtual_device = VIRTUAL_RESET, \ + .real_device = RESET_OUTPUT, \ + .function = V_PULSE, \ + .initial_value = !RESET_ACTIVE_VALUE }, \ + { .virtual_device = VIRTUAL_CLR_SCR, \ + .real_device = CLR_SCR_OUT, \ + .function = V_PULSE, \ + .initial_value = !CLR_SCR_ACTIVE_VALUE }, \ + } + + +#define ASDF_ASCII_KEYMAP_INITIALIZER ASDF_ASCII_PLAIN_KEYMAP_INITIALIZER, ASDF_ASCII_CAPS_KEYMAP_INITIALIZER + // TO ensure consistent DIP switch operation within the keymap, a // ASDF_ASCII_DIP_SWITCHES macro is defined. Keeping the ACTION_MAPSEL0-3 diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h index f94ab73..212820a 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h @@ -65,7 +65,7 @@ { ACTION_NOTHING, 'p', ';', '/', ASCII_SPACE, 'z', 'a', 'q' }, \ { ACTION_BREAK, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \ { ACTION_NOTHING, 'k', 'j', 'h', 'g', 'f', 'd', 's' }, \ - { ACTION_CLEAR, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \ + { ACTION_NOTHING, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \ /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'o', \ 'l', ASCII_PERIOD }, \ { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \ @@ -79,7 +79,7 @@ { ACTION_NOTHING, 'P', ';', '/', ASCII_SPACE, 'Z', 'A', 'Q' }, \ { ACTION_BREAK, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \ { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \ - { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ + { ACTION_NOTHING, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', \ 'L', ASCII_PERIOD }, \ { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \ @@ -94,7 +94,7 @@ { ACTION_NOTHING, 'P', '+', '?', ASCII_SPACE, 'Z', 'A', 'Q' }, \ { ACTION_BREAK, '>', 'M', 'N', 'B', 'V', 'C', 'X' }, \ { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \ - { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ + { ACTION_NOTHING, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', 'L', '<' }, \ { ASCII_TILDE, ASCII_RT_CURLY_BRACE, ASCII_LT_CURLY_BRACE, '=', '*', \ '0', ASCII_RT_PAREN, ASCII_LT_PAREN }, \ @@ -113,8 +113,8 @@ 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_CLEAR, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \ - ASCII_CTRL_T, ASCII_CTRL_R, ASCII_CTRL_E, ASCII_CTRL_W }, \ + { 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_SHIFT_LOCK, ASCII_CR, \ ASCII_LF, ASCII_CTRL_O, ASCII_CTRL_L, ACTION_NOTHING }, \ { ACTION_NOTHING, 0x1d, ASCII_ESC, ACTION_NOTHING, \ @@ -147,7 +147,12 @@ #define ASDF_TEST_PLAIN_MAP_INDEX ASDF_TEST_BASE + 0 #define ASDF_TEST_CAPS_MAP_INDEX ASDF_TEST_BASE + 1 -#define ASDF_TEST_KEYMAP_INITIALIZER_LENGTH 3 +#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 \ { \ { \ @@ -171,24 +176,33 @@ .function = V_PULSE, \ .initial_value = 0, \ }, \ + { /* first of double assignment attempt */ \ + .virtual_device = VOUT4, \ + .real_device = VMAP_LED1, \ + .initial_value = 0 \ + }, \ + { /* second of double assignment attempt */ \ + .virtual_device = VOUT5, .real_device = VMAP_LED1, .initial_value = 1 \ + } \ } + #define ASDF_TEST_KEYMAP_INITIALIZER_2 \ { \ { \ /* Triple assignment */ \ .virtual_device = VOUT1, \ - .real_device = VMAP_OUT1, \ + .real_device = VMAP_OUT1, \ .function = V_TOGGLE, \ .initial_value = 0, \ }, \ { \ .virtual_device = VOUT1, \ - .real_device = VMAP_OUT2, \ + .real_device = VMAP_OUT2, \ .function = V_TOGGLE, \ .initial_value = 1, \ }, \ { \ - .virtual_device = VOUT1, .real_device = VMAP_OUT3, .function = V_TOGGLE, .initial_value = 0, \ + .virtual_device = VOUT1, .real_device = VMAP_OUT3, .function = V_TOGGLE, .initial_value = 0, \ } \ } diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test2.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test2.h index 653a4e3..4d7110d 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test2.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test2.h @@ -66,7 +66,7 @@ { ACTION_NOTHING, 'p', ';', '/', ASCII_SPACE, 'z', 'a', 'q' }, \ { ACTION_BREAK, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \ { ACTION_NOTHING, 'k', 'j', 'h', 'g', 'f', 'd', 's' }, \ - { ACTION_CLEAR, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \ + { ACTION_NOTHING, 'i', 'u', 'y', 't', 'r', 'e', 'w' }, \ /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'o', \ 'l', ASCII_PERIOD }, \ { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \ @@ -80,7 +80,7 @@ { ACTION_NOTHING, 'P', ';', '/', ASCII_SPACE, 'Z', 'A', 'Q' }, \ { ACTION_BREAK, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \ { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \ - { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ + { ACTION_NOTHING, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ /**/ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', \ 'L', ASCII_PERIOD }, \ { ASCII_TILDE, ASCII_RT_SQUARE_BRACE, ASCII_LT_SQUARE_BRACE, '-', ':', '0', '9', '8' }, \ @@ -95,7 +95,7 @@ { ACTION_NOTHING, 'P', '+', '?', ASCII_SPACE, 'Z', 'A', 'Q' }, \ { ACTION_BREAK, '>', 'M', 'N', 'B', 'V', 'C', 'X' }, \ { ACTION_NOTHING, 'K', 'J', 'H', 'G', 'F', 'D', 'S' }, \ - { ACTION_CLEAR, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ + { ACTION_NOTHING, 'I', 'U', 'Y', 'T', 'R', 'E', 'W' }, \ { ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', 'L', '<' }, \ { ASCII_TILDE, ASCII_RT_CURLY_BRACE, ASCII_LT_CURLY_BRACE, '=', '*', \ '0', ASCII_RT_PAREN, ASCII_LT_PAREN }, \ @@ -114,8 +114,8 @@ 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_CLEAR, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \ - ASCII_CTRL_T, ASCII_CTRL_R, ASCII_CTRL_E, ASCII_CTRL_W }, \ + { 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_SHIFT_LOCK, ASCII_CR, \ ASCII_LF, ASCII_CTRL_O, ASCII_CTRL_L, ACTION_NOTHING }, \ { ACTION_NOTHING, 0x1d, ASCII_ESC, ACTION_NOTHING, \ @@ -148,17 +148,32 @@ #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 \ +#define ASDF_TEST2_KEYMAP_INITIALIZER_1 \ { \ - { .virtual_device = VCAPS_LED, .real_device = VMAP_LED2, .initial_value = 1 }, \ - { .virtual_device = VOUT1, .real_device = VMAP_OUT2, .initial_value = 1 }, \ + { .virtual_device = VCAPS_LED, .real_device = VMAP_LED1, .initial_value = 0 }, \ + { .virtual_device = VSHIFT_LED, .real_device = VMAP_LED2, .initial_value = 0 }, \ { .virtual_device = VOUT2, .real_device = VMAP_OUT3, .initial_value = 0 }, \ { \ - .virtual_device = VOUT2, .real_device = NUM_REAL_OUTPUTS, .initial_value = 0 \ + .virtual_device = VOUT2, .real_device = NUM_REAL_OUTPUTS, .initial_value = 0 \ } \ } +#define ASDF_TEST2_KEYMAP_INITIALIZER_2 \ + { \ + { .virtual_device = VCAPS_LED, .real_device = VMAP_LED1, .initial_value = 0 }, \ + { .virtual_device = VSHIFT_LED, .real_device = VMAP_LED2, .initial_value = 0 }, \ + { .virtual_device = VOUT2, .real_device = VMAP_OUT3, .initial_value = 0 }, \ + { \ + .virtual_device = VOUT2, .real_device = NUM_REAL_OUTPUTS, .initial_value = 0 \ + } \ + } + +#define ASDF_TEST2_KEYMAP_INITIALIZER \ + ASDF_TEST2_KEYMAP_INITIALIZER_1, ASDF_TEST2_KEYMAP_INITIALIZER_2 // The following preprocessor "code" permits various keymaps to be created and // included without generating a lot of complicating code dependencies. The use