diff --git a/firmware/asdf/src/Arch/asdf_arch_test.c b/firmware/asdf/src/Arch/asdf_arch_test.c index 44c7d5d..257d6c0 100644 --- a/firmware/asdf/src/Arch/asdf_arch_test.c +++ b/firmware/asdf/src/Arch/asdf_arch_test.c @@ -37,6 +37,7 @@ #include #include "asdf_keymap_defs.h" #include "asdf_config.h" +#include "asdf_physical.h" #include "asdf_virtual.h" #include "asdf_arch.h" @@ -105,8 +106,8 @@ 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]; +static uint8_t outputs[ASDF_PHYSICAL_NUM_RESOURCES]; +static pulse_state_t pulses[ASDF_PHYSICAL_NUM_RESOURCES]; // PROCEDURE: pulse_detect @@ -138,7 +139,7 @@ static pulse_state_t pulse_detect(pulse_state_t current_state, pulse_event_t eve // PROCEDURE: set_output -// INPUTS: (asdf_virtual_real_dev_t) output_dev - the output to set +// INPUTS: (asdf_physical_dev_t) output_dev - the output to set // (uint8_t) value - value to assert on the output // OUTPUTS: none // @@ -153,7 +154,7 @@ static pulse_state_t pulse_detect(pulse_state_t current_state, pulse_event_t eve // // COMPLEXITY: 1 // -static void set_output(asdf_virtual_real_dev_t output_dev, uint8_t value) +static void set_output(asdf_physical_dev_t output_dev, uint8_t value) { pulse_event_t pulse_event = value ? PULSE_EVENT_SET_HIGH : PULSE_EVENT_SET_LOW; @@ -177,7 +178,7 @@ static void set_output(asdf_virtual_real_dev_t output_dev, uint8_t value) // void asdf_arch_null_output(uint8_t value) { - set_output(VMAP_NO_OUT, value); + set_output(PHYSICAL_NO_OUT, value); } @@ -195,7 +196,7 @@ void asdf_arch_null_output(uint8_t value) // void asdf_arch_led1_set(uint8_t value) { - set_output(VMAP_LED1, value); + set_output(PHYSICAL_LED1, value); } // PROCEDURE: asdf_arch_led2_set @@ -212,7 +213,7 @@ void asdf_arch_led1_set(uint8_t value) // void asdf_arch_led2_set(uint8_t value) { - set_output(VMAP_LED2, value); + set_output(PHYSICAL_LED2, value); } // PROCEDURE: asdf_arch_led3_set @@ -229,7 +230,7 @@ void asdf_arch_led2_set(uint8_t value) // void asdf_arch_led3_set(uint8_t value) { - set_output(VMAP_LED3, value); + set_output(PHYSICAL_LED3, value); } // PROCEDURE: asdf_arch_out1_set @@ -248,7 +249,7 @@ void asdf_arch_led3_set(uint8_t value) // void asdf_arch_out1_set(uint8_t value) { - set_output(VMAP_OUT1, value); + set_output(PHYSICAL_OUT1, value); } // PROCEDURE: asdf_arch_out1_hi_z_set @@ -267,7 +268,7 @@ void asdf_arch_out1_set(uint8_t value) // void asdf_arch_out1_hi_z_set(uint8_t value) { - set_output(VMAP_OUT1_OC, value); + set_output(PHYSICAL_OUT1_OC, value); } // PROCEDURE: asdf_arch_out2_set @@ -284,7 +285,7 @@ void asdf_arch_out1_hi_z_set(uint8_t value) // void asdf_arch_out2_set(uint8_t value) { - set_output(VMAP_OUT2, value); + set_output(PHYSICAL_OUT2, value); } @@ -304,7 +305,7 @@ void asdf_arch_out2_set(uint8_t value) // void asdf_arch_out2_hi_z_set(uint8_t value) { - set_output(VMAP_OUT2_OC, value); + set_output(PHYSICAL_OUT2_OC, value); } // PROCEDURE: asdf_arch_out3_set @@ -323,7 +324,7 @@ void asdf_arch_out2_hi_z_set(uint8_t value) // void asdf_arch_out3_set(uint8_t value) { - set_output(VMAP_OUT3, value); + set_output(PHYSICAL_OUT3, value); } @@ -343,14 +344,14 @@ void asdf_arch_out3_set(uint8_t value) // void asdf_arch_out3_hi_z_set(uint8_t value) { - set_output(VMAP_OUT3_OC, value); + set_output(PHYSICAL_OUT3_OC, value); } // PROCEDURE: asdf_arch_check_output -// INPUTS:(asdf_virtual_real_dev_t) device - which device to check +// INPUTS:(asdf_physical_dev_t) device - which device to check // OUTPUTS: the value of the device setting. // -// DESCRIPTION: For a given real device, return the current setting (true or false) +// DESCRIPTION: For a given physical device, return the current setting (true or false) // // SIDE EFFECTS: none // @@ -360,16 +361,16 @@ void asdf_arch_out3_hi_z_set(uint8_t value) // // COMPLEXITY: 1 // -uint8_t asdf_arch_check_output(asdf_virtual_real_dev_t device) +uint8_t asdf_arch_check_output(asdf_physical_dev_t device) { return outputs[device]; } // PROCEDURE: asdf_arch_check_pulse -// INPUTS:(asdf_virtual_real_dev_t) device - which device to check +// INPUTS:(asdf_physical_dev_t) device - which device to check // OUTPUTS: the value of the device pulse detector // -// DESCRIPTION: For a given real device, return the state of the pulse detector +// DESCRIPTION: For a given physical device, return the state of the pulse detector // // SIDE EFFECTS: none // @@ -379,7 +380,7 @@ uint8_t asdf_arch_check_output(asdf_virtual_real_dev_t device) // // COMPLEXITY: 1 // -uint8_t asdf_arch_check_pulse(asdf_virtual_real_dev_t device) +uint8_t asdf_arch_check_pulse(asdf_physical_dev_t device) { return pulses[device]; } @@ -401,7 +402,7 @@ uint8_t asdf_arch_check_pulse(asdf_virtual_real_dev_t device) // void asdf_arch_pulse_delay(void) { - for (uint8_t i = 0; i < NUM_REAL_OUTPUTS; i++) { + for (uint8_t i = 0; i < ASDF_PHYSICAL_NUM_RESOURCES; i++) { pulses[i] = pulse_detect(pulses[i], PULSE_EVENT_DELAY); } } @@ -420,7 +421,7 @@ void asdf_arch_pulse_delay(void) // void asdf_arch_init(void) { - for (uint8_t i = 0; i < NUM_REAL_OUTPUTS; i++) { + for (uint8_t i = 0; i < ASDF_PHYSICAL_NUM_RESOURCES; i++) { outputs[i] = 0; pulses[i] = PD_ST_INITIAL_STATE; } diff --git a/firmware/asdf/src/Arch/asdf_arch_test.h b/firmware/asdf/src/Arch/asdf_arch_test.h index f66ecfa..27a9d00 100644 --- a/firmware/asdf/src/Arch/asdf_arch_test.h +++ b/firmware/asdf/src/Arch/asdf_arch_test.h @@ -71,6 +71,7 @@ #include #include "asdf_keymap_defs.h" #include "asdf_config.h" +#include "asdf_physical.h" #include "asdf_virtual.h" #include "asdf_arch.h" @@ -95,8 +96,6 @@ typedef enum { } pulse_state_t; -static uint8_t outputs[NUM_REAL_OUTPUTS]; - // PROCEDURE: asdf_arch_null_output // INPUTS: (uint8_t) value - ignored // OUTPUTS: none @@ -158,16 +157,16 @@ void asdf_arch_out3_set(uint8_t value); void asdf_arch_out3_hi_z_set(uint8_t value); // PROCEDURE: asdf_arch_check_output -// INPUTS:(asdf_virtual_real_dev_t) device - which device to check +// INPUTS:(asdf_physical_dev_t) device - which device to check // OUTPUTS: the value of the device setting. // DESCRIPTION: For a given real device, return the current setting (true or false) -uint8_t asdf_arch_check_output(asdf_virtual_real_dev_t device); +uint8_t asdf_arch_check_output(asdf_physical_dev_t device); // PROCEDURE: asdf_arch_check_pulse -// INPUTS:(asdf_virtual_real_dev_t) device - which device to check +// INPUTS:(asdf_physical_dev_t) device - which device to check // OUTPUTS: the value of the device pulse detector // DESCRIPTION: For a given real device, return the state of the pulse detector -uint8_t asdf_arch_check_pulse(asdf_virtual_real_dev_t device); +uint8_t asdf_arch_check_pulse(asdf_physical_dev_t device); // PROCEDURE: asdf_arch_pulse_delay // INPUTS: none @@ -176,6 +175,14 @@ uint8_t asdf_arch_check_pulse(asdf_virtual_real_dev_t device); // for each output. void asdf_arch_pulse_delay(void); +// PROCEDURE: asdf_arch_read_row +// INPUTS: (uint8_t) row: the row number to be scanned +// OUTPUTS: returns a word containing the emulated active (pressed) columns +// DESCRIPTION: reads the word from the key state emulation array and returns +// the value. The value is a binary representation of the keys pressed within +// the row, with 1=pressed, 0=released. +asdf_cols_t asdf_arch_read_row(uint8_t row); + // PROCEDURE: asdf_arch_init // INPUTS: none diff --git a/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_production.h b/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_production.h index 703082b..ca0a3f8 100644 --- a/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_production.h +++ b/firmware/asdf/src/Keymaps/asdf_all_keymap_defs_production.h @@ -31,6 +31,8 @@ #include "asdf.h" #include "asdf_ascii.h" +#include "asdf_physical.h" +#include "asdf_virtual.h" #include "asdf_modifiers.h" #include "Keymaps/asdf_keymap_defs_ascii.h" diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h index a520ba3..109a120 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h @@ -39,8 +39,6 @@ #if !defined(ASDF_KEYMAP_DEFS_APPLE2_H) #define ASDF_KEYMAP_DEFS_APPLE2_H -#include "../asdf_modifiers.h" - // Edit the number of rows and columns used in this map. If the number is less // than the maxium, the unused elements will be initialized to 0. @@ -50,22 +48,24 @@ #define ASDF_ASCII_NUM_ROWS 16 // DIP switches are row 15. #define ASDF_ASCII_NUM_COLS 8 +#define ACTION_BREAK ACTION_NOTHING + #define ACTION_RESET ACTION_VOUT1 #define VIRTUAL_RESET VOUT1 -#define RESET_OUTPUT VMAP_OUT3_OC +#define RESET_OUTPUT PHYSICAL_OUT3_OC #define RESET_ACTIVE_VALUE 0 #define ACTION_CLEAR ACTION_VOUT2 #define VIRTUAL_CLR_SCR VOUT2 -#define CLR_SCR_OUTPUT VMAP_OUT1 +#define CLR_SCR_OUTPUT PHYSICAL_OUT1 #define CLR_SCR_ACTIVE_VALUE 1 #define VIRTUAL_POWER_LED VLED1 -#define POWER_LED VMAP_LED1 +#define POWER_LED PHYSICAL_LED1 #define POWER_LED_INIT_VALUE 1 #define VIRTUAL_DISABLED_LED VLED2 -#define DISABLED_LED VMAP_LED3 +#define DISABLED_LED PHYSICAL_LED3 #define DISABLED_INIT_VALUE 0 #define ASDF_APPLE2_KEYMAP_INITIALIZER_LENGTH 4 @@ -76,17 +76,17 @@ #define ASDF_APPLE2_PLAIN_KEYMAP_INITIALIZER \ { \ { .virtual_device = VCAPS_LED, \ - .real_device = POWER_LED, \ + .physical_device = POWER_LED, \ .initial_value = 0 }, \ { .virtual_device = VIRTUAL_DISABLED_LED, \ - .real_device = DISABLED_LED, \ + .physical_device = DISABLED_LED, \ .initial_value = 0 }, \ { .virtual_device = VIRTUAL_RESET, \ - .real_device = RESET_OUTPUT, \ + .physical_device = RESET_OUTPUT, \ .function = V_PULSE, \ .initial_value = !RESET_ACTIVE_VALUE }, \ { .virtual_device = VIRTUAL_CLR_SCR, \ - .real_device = CLR_SCR_OUTPUT, \ + .physical_device = CLR_SCR_OUTPUT, \ .function = V_PULSE, \ .initial_value = !CLR_SCR_ACTIVE_VALUE } \ } @@ -95,17 +95,17 @@ #define ASDF_APPLE2_CAPS_KEYMAP_INITIALIZER \ { \ { .virtual_device = VIRTUAL_POWER_LED, \ - .real_device = POWER_LED, \ + .physical_device = POWER_LED, \ .initial_value = POWER_LED_INIT_VALUE }, \ { .virtual_device = VIRTUAL_DISABLED_LED, \ - .real_device = DISABLED_LED, \ + .physical_device = DISABLED_LED, \ .initial_value = 0 }, \ { .virtual_device = VIRTUAL_RESET, \ - .real_device = RESET_OUTPUT, \ + .physical_device = RESET_OUTPUT, \ .function = V_PULSE, \ .initial_value = !RESET_ACTIVE_VALUE }, \ { .virtual_device = VIRTUAL_CLR_SCR, \ - .real_device = CLR_SCR_OUTPUT, \ + .physical_device = CLR_SCR_OUTPUT, \ .function = V_PULSE, \ .initial_value = !CLR_SCR_ACTIVE_VALUE } \ } diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h index 153cda1..dbce413 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h @@ -31,46 +31,47 @@ #if !defined(ASDF_KEYMAP_DEFS_ASCII_H) #define ASDF_KEYMAP_DEFS_ASCII_H -#include "../asdf_modifiers.h" - // Edit the number of rows and columns used in this map. If the number is less // than the maxium, the unused elements will be initialized to 0. #define ASDF_ASCII_NUM_ROWS 16 // DIP switches are row 15. #define ASDF_ASCII_NUM_COLS 8 +#define ACTION_BREAK ACTION_NOTHING + #define VIRTUAL_RESET VOUT1 -#define RESET_OUTPUT VMAP_OUT3_OC +#define RESET_OUTPUT PHYSICAL_OUT3_OC #define RESET_ACTIVE_VALUE 0 #define VIRTUAL_CLR_SCR VOUT2 -#define CLR_SCR_OUT VMAP_OUT1 +#define CLR_SCR_OUT PHYSICAL_OUT1 #define CLR_SCR_ACTIVE_VALUE 1 #define VIRTUAL_POWER_LED VLED1 -#define POWER_LED VMAP_LED1 +#define POWER_LED PHYSICAL_LED1 #define POWER_LED_INIT_VALUE 1 -#define CAPS_LED VMAP_LED3 +#define CAPS_LED PHYSICAL_LED3 #define CAPS_LED_INIT_VALUE 0 + #define ASDF_ASCII_KEYMAP_INITIALIZER_LENGTH 4 #define ASDF_ASCII_PLAIN_KEYMAP_INITIALIZER \ { \ { .virtual_device = VIRTUAL_POWER_LED, \ - .real_device = POWER_LED, \ + .physical_device = POWER_LED, \ .initial_value = POWER_LED_INIT_VALUE }, \ { .virtual_device = VCAPS_LED, \ - .real_device = CAPS_LED, \ + .physical_device = CAPS_LED, \ .initial_value = CAPS_LED_INIT_VALUE }, \ { .virtual_device = VIRTUAL_RESET, \ - .real_device = RESET_OUTPUT, \ + .physical_device = RESET_OUTPUT, \ .function = V_PULSE, \ .initial_value = !RESET_ACTIVE_VALUE }, \ { .virtual_device = VIRTUAL_CLR_SCR, \ - .real_device = CLR_SCR_OUT, \ + .physical_device = CLR_SCR_OUT, \ .function = V_PULSE, \ .initial_value = !CLR_SCR_ACTIVE_VALUE }, \ } @@ -78,17 +79,17 @@ #define ASDF_ASCII_CAPS_KEYMAP_INITIALIZER \ { \ { .virtual_device = VIRTUAL_POWER_LED, \ - .real_device = POWER_LED, \ + .physical_device = POWER_LED, \ .initial_value = POWER_LED_INIT_VALUE }, \ { .virtual_device = VCAPS_LED, \ - .real_device = CAPS_LED, \ + .physical_device = CAPS_LED, \ .initial_value = CAPS_LED_INIT_VALUE }, \ { .virtual_device = VIRTUAL_RESET, \ - .real_device = RESET_OUTPUT, \ + .physical_device = RESET_OUTPUT, \ .function = V_PULSE, \ .initial_value = !RESET_ACTIVE_VALUE }, \ { .virtual_device = VIRTUAL_CLR_SCR, \ - .real_device = CLR_SCR_OUT, \ + .physical_device = CLR_SCR_OUT, \ .function = V_PULSE, \ .initial_value = !CLR_SCR_ACTIVE_VALUE }, \ } diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h index 212820a..0db6a1b 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test.h @@ -63,7 +63,7 @@ { 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_BREAK, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \ + { 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_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'o', \ @@ -77,7 +77,7 @@ { 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_BREAK, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \ + { 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_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', \ @@ -92,7 +92,7 @@ { 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_BREAK, '>', 'M', 'N', 'B', 'V', 'C', 'X' }, \ + { 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_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', 'L', '<' }, \ @@ -109,7 +109,7 @@ 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_BREAK, ASCII_COMMA, ASCII_CTRL_M, ASCII_CTRL_N, \ + { 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 }, \ @@ -158,31 +158,31 @@ { \ /* Single assignment */ \ .virtual_device = VOUT1, \ - .real_device = VMAP_OUT1, \ + .physical_device = PHYSICAL_OUT1, \ .function = V_NOFUNC, \ .initial_value = 0, \ }, \ { \ /* single toggle */ \ .virtual_device = VOUT2, \ - .real_device = VMAP_OUT2, \ + .physical_device = PHYSICAL_OUT2, \ .function = V_TOGGLE, \ .initial_value = 0, \ }, \ { \ /* single pulse */ \ .virtual_device = VOUT3, \ - .real_device = VMAP_OUT3, \ + .physical_device = PHYSICAL_OUT3, \ .function = V_PULSE, \ .initial_value = 0, \ }, \ { /* first of double assignment attempt */ \ .virtual_device = VOUT4, \ - .real_device = VMAP_LED1, \ + .physical_device = PHYSICAL_LED1, \ .initial_value = 0 \ }, \ { /* second of double assignment attempt */ \ - .virtual_device = VOUT5, .real_device = VMAP_LED1, .initial_value = 1 \ + .virtual_device = VOUT5, .physical_device = PHYSICAL_LED1, .initial_value = 1 \ } \ } @@ -191,18 +191,18 @@ { \ /* Triple assignment */ \ .virtual_device = VOUT1, \ - .real_device = VMAP_OUT1, \ + .physical_device = PHYSICAL_OUT1, \ .function = V_TOGGLE, \ .initial_value = 0, \ }, \ { \ .virtual_device = VOUT1, \ - .real_device = VMAP_OUT2, \ + .physical_device = PHYSICAL_OUT2, \ .function = V_TOGGLE, \ .initial_value = 1, \ }, \ { \ - .virtual_device = VOUT1, .real_device = VMAP_OUT3, .function = V_TOGGLE, .initial_value = 0, \ + .virtual_device = VOUT1, .physical_device = PHYSICAL_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 4d7110d..da8a273 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_test2.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_test2.h @@ -64,7 +64,7 @@ { 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_BREAK, ASCII_COMMA, 'm', 'n', 'b', 'v', 'c', 'x' }, \ + { 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_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'o', \ @@ -78,7 +78,7 @@ { 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_BREAK, ASCII_COMMA, 'M', 'N', 'B', 'V', 'C', 'X' }, \ + { 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_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', \ @@ -93,7 +93,7 @@ { 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_BREAK, '>', 'M', 'N', 'B', 'V', 'C', 'X' }, \ + { 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_SHIFT_LOCK, ASCII_CR, ASCII_LF, 'O', 'L', '<' }, \ @@ -110,7 +110,7 @@ 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_BREAK, ASCII_COMMA, ASCII_CTRL_M, ASCII_CTRL_N, \ + { 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 }, \ @@ -154,21 +154,21 @@ #define ASDF_TEST2_KEYMAP_INITIALIZER_LENGTH 4 #define ASDF_TEST2_KEYMAP_INITIALIZER_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 = 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, .real_device = NUM_REAL_OUTPUTS, .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, .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 = 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, .real_device = NUM_REAL_OUTPUTS, .initial_value = 0 \ + .virtual_device = VOUT2, .physical_device = ASDF_PHYSICAL_NUM_RESOURCES, .initial_value = 0 \ } \ } diff --git a/firmware/asdf/src/Makefile.app b/firmware/asdf/src/Makefile.app index a6aba56..75c89a1 100644 --- a/firmware/asdf/src/Makefile.app +++ b/firmware/asdf/src/Makefile.app @@ -68,7 +68,7 @@ MAKEDEPEND = $(CPP) $(DEPFLAGS) $(CPPFLAGS) $< \ | sort -u > $*.d SRC_FILES = main.c asdf.c asdf_modifiers.c asdf_repeat.c asdf_keymaps.c -SRC_FILES += asdf_buffer.c asdf_arch.c asdf_virtual.c +SRC_FILES += asdf_buffer.c asdf_arch.c asdf_virtual.c asdf_physical.c OBJ_FILES := $(SRC_FILES:.c=.o) DEP_FILES := $(SRC_FILES:%.c=$(DEP_DIR)/%.d) @@ -141,7 +141,8 @@ asdf.o: asdf.c asdf.h asdf_arch.h asdf_keymaps.h asdf_config.h asdf_keymap_defs. asdf_repeat.o: asdf_repeat.c asdf_repeat.h asdf_config.h asdf_buffer.o: asdf_buffer.c asdf.h asdf_config.h asdf_modifiers.o: asdf_modifiers.c asdf_modifiers.h -asdf_virtual.o: asdf_virtual.c asdf_virtual.h asdf_arch.h +asdf_virtual.o: asdf_virtual.c asdf_virtual.h asdf_arch.h asdf_physical.h +asdf_physical.o: asdf_physical.c asdf_virtual.h asdf_arch.h tags: $(SRC_FILES) etags $(SRC_FILES) diff --git a/firmware/asdf/src/Makefile.test b/firmware/asdf/src/Makefile.test index 0acc034..805b266 100644 --- a/firmware/asdf/src/Makefile.test +++ b/firmware/asdf/src/Makefile.test @@ -49,13 +49,13 @@ TEST1_DEPS = ./$(TEST1).c $(UNITY_DIR)/unity.c TEST1_BUILD = $(BUILD_DIR)/test_$(TEST1) TEST2 = asdf_modifiers -TEST2_SRC = $(TEST_DIR)/test_$(TEST2).c ./asdf_arch.c ./asdf_virtual.c +TEST2_SRC = $(TEST_DIR)/test_$(TEST2).c ./asdf_arch.c ./asdf_virtual.c ./asdf_physical.c TEST2_DEPS = ./$(TEST2).c $(UNITY_DIR)/unity.c TEST2_BUILD = $(BUILD_DIR)/test_$(TEST2) TEST3 = asdf_keymaps TEST3_SRC = $(TEST_DIR)/test_$(TEST3).c -TEST3_DEPS = ./$(TEST3).c $(UNITY_DIR)/unity.c ./asdf_virtual.c ./asdf_arch.c +TEST3_DEPS = ./$(TEST3).c $(UNITY_DIR)/unity.c ./asdf_physical.c ./asdf_virtual.c ./asdf_arch.c TEST3_BUILD = $(BUILD_DIR)/test_$(TEST3) TEST4 = asdf_buffer @@ -64,14 +64,14 @@ TEST4_DEPS = ./$(TEST4).c $(UNITY_DIR)/unity.c TEST4_BUILD = $(BUILD_DIR)/test_$(TEST4) TEST5 = asdf_virtual -TEST5_SRC = $(TEST_DIR)/test_$(TEST4).c -TEST5_DEPS = ./$(TEST4).c $(UNITY_DIR)/unity.c -TEST5_BUILD = $(BUILD_DIR)/test_$(TEST4) +TEST5_SRC = $(TEST_DIR)/test_$(TEST5).c +TEST5_DEPS = ./$(TEST5).c $(UNITY_DIR)/unity.c ./asdf_physical.c ./asdf_modifiers.c ./asdf_arch.c ./asdf_keymaps.c +TEST5_BUILD = $(BUILD_DIR)/test_$(TEST5) TEST6 = asdf -TEST6_SRC = $(TEST_DIR)/test_$(TEST5).c -TEST6_DEPS = ./$(TEST5).c $(UNITY_DIR)/unity.c ./asdf_arch.c ./$(TEST1).c $(TEST2).c $(TEST3).c $(TEST4).c -TEST6_BUILD = $(BUILD_DIR)/test_$(TEST5) +TEST6_SRC = $(TEST_DIR)/test_$(TEST6).c ./asdf_arch.c ./$(TEST1).c $(TEST2).c $(TEST3).c $(TEST4).c $(TEST5).c ./asdf_physical.c +TEST6_DEPS = ./$(TEST6).c $(UNITY_DIR)/unity.c +TEST6_BUILD = $(BUILD_DIR)/test_$(TEST6) .SUFFIXES: .SUFFIXES: .c .o .bin .hex @@ -130,7 +130,7 @@ test5: $(TEST5_BUILD) $(TEST5_BUILD) .PHONY: test6 -test5: $(TEST6_BUILD) +test6: $(TEST6_BUILD) $(TEST6_BUILD) diff --git a/firmware/asdf/src/asdf.c b/firmware/asdf/src/asdf.c index 2be69ba..597986b 100644 --- a/firmware/asdf/src/asdf.c +++ b/firmware/asdf/src/asdf.c @@ -33,6 +33,7 @@ #include #include "asdf.h" #include "asdf_ascii.h" +#include "asdf_physical.h" #include "asdf_virtual.h" #include "asdf_keymaps.h" #include "asdf_keymap_defs.h" @@ -210,8 +211,6 @@ static void asdf_activate_action(action_t keycode) break; } case ACTION_NOTHING: - case ACTION_LOCAL: - case ACTION_BREAK: case ACTION_HERE_IS: case ACTION_FN_1: case ACTION_FN_2: @@ -282,8 +281,6 @@ static void asdf_deactivate_action(action_t keycode) break; } case ACTION_NOTHING: - case ACTION_LOCAL: - case ACTION_BREAK: case ACTION_HERE_IS: case ACTION_FN_1: case ACTION_FN_2: @@ -295,7 +292,6 @@ static void asdf_deactivate_action(action_t keycode) case ACTION_FN_8: case ACTION_FN_9: case ACTION_FN_10: - case ACTION_CLEAR: default: break; } } diff --git a/firmware/asdf/src/asdf.h b/firmware/asdf/src/asdf.h index d1a1349..a271e3a 100644 --- a/firmware/asdf/src/asdf.h +++ b/firmware/asdf/src/asdf.h @@ -45,8 +45,6 @@ typedef enum { ACTION_CAPS, ACTION_CTRL, ACTION_REPEAT, - ACTION_LOCAL, - ACTION_BREAK, ACTION_HERE_IS, ACTION_MAPSEL_0, ACTION_MAPSEL_1, diff --git a/firmware/asdf/src/asdf_keymaps.c b/firmware/asdf/src/asdf_keymaps.c index a082ce8..c50c8f1 100644 --- a/firmware/asdf/src/asdf_keymaps.c +++ b/firmware/asdf/src/asdf_keymaps.c @@ -23,6 +23,7 @@ #include #include "asdf.h" #include "asdf_arch.h" +#include "asdf_physical.h" #include "asdf_virtual.h" #include "asdf_keymaps.h" #include "asdf_keymap_defs.h" diff --git a/firmware/asdf/src/asdf_modifiers.c b/firmware/asdf/src/asdf_modifiers.c index b21a3f0..ccce404 100644 --- a/firmware/asdf/src/asdf_modifiers.c +++ b/firmware/asdf/src/asdf_modifiers.c @@ -26,6 +26,7 @@ #include #include "asdf_modifiers.h" +#include "asdf_physical.h" #include "asdf_virtual.h" #include "asdf_arch.h" diff --git a/firmware/asdf/src/asdf_physical.c b/firmware/asdf/src/asdf_physical.c new file mode 100644 index 0000000..9d37d9a --- /dev/null +++ b/firmware/asdf/src/asdf_physical.c @@ -0,0 +1,273 @@ +// -*- mode: C; tab-width: 2 ; indent-tabs-mode: nil -*- +// +// Unified Keyboard Project +// ASDF keyboard firmware +// +// asdf_physical.c +// +// This file contains code to manage physical outputs and serves as an API +// between the virtual layer and the architecture specific code. +// +// 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 . +// + +#include +#include "asdf_physical.h" +#include "asdf_keymap_defs.h" +#include "asdf_config.h" +#include "asdf_arch.h" + + +// physical_out_set[] contains the set() function for each real output device. +static void (*const physical_out_set[])(uint8_t) = { + [PHYSICAL_NO_OUT] = &asdf_arch_null_output, // + [PHYSICAL_OUT1] = &asdf_arch_out1_set, // + [PHYSICAL_OUT2] = &asdf_arch_out2_set, // + [PHYSICAL_OUT3] = &asdf_arch_out3_set, // + [PHYSICAL_OUT1_OC] = &asdf_arch_out1_hi_z_set, // + [PHYSICAL_OUT2_OC] = &asdf_arch_out2_hi_z_set, // + [PHYSICAL_OUT3_OC] = &asdf_arch_out3_hi_z_set, // + [PHYSICAL_LED1] = &asdf_arch_led1_set, // + [PHYSICAL_LED2] = &asdf_arch_led2_set, // + [PHYSICAL_LED3] = &asdf_arch_led3_set // +}; + + +// For each virtual out, maintain a "shadow" register for the output value. This +// permits machine independent implementations of the toggle and pulse functions +// to be implemented in this module, requiring only a "set" function for each +// virtual output in the architecture-dependent layer. This implementation is +// not as efficient, but the timing is not critical, and the events are so +// infrequent that the benefits of the refactoring far outweigh any performance +// penalty. + +static struct { + uint8_t shadow; + asdf_physical_dev_t next; +} physical_device_table[ASDF_PHYSICAL_NUM_RESOURCES]; + + +// PROCEDURE: asdf_physical_set +// INPUTS: (asdf_physical_dev_t) physical_out: which real output to set or clear +// INPUTS: (uint8_t) value +// OUTPUTS: none +// +// DESCRIPTION: If the physical output is valid, set to high if value is true, low +// if false. +// +// SIDE EFFECTS: see above +// +// NOTES: No bounds checking. The caller must ensure a valid device +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_physical_set(asdf_physical_dev_t physical_out, uint8_t value) +{ + physical_out_set[physical_out](value); + physical_device_table[physical_out].shadow = value; +} + + +// PROCEDURE: asdf_physical_assert +// INPUTS: (asdf_physical_dev_t) physical_out: which physical output to set or clear +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: Assert the value of the physical output shadow register on the output. +// +// SIDE EFFECTS: see above +// +// NOTES: No bounds checking. Only called from initialization code. +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_physical_assert(asdf_physical_dev_t physical_out) +{ + uint8_t value = physical_device_table[physical_out].shadow; + physical_out_set[physical_out](value); +} + +// PROCEDURE: asdf_physical_toggle +// INPUTS: (asdf_physical_dev_t) physical_out: which physical output to toggle +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: Toggle the value of the physical output. +// +// SIDE EFFECTS: see above +// +// NOTES: No bounds checking. Only called from initialization code. +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +void asdf_physical_toggle(asdf_physical_dev_t physical_out) +{ + uint8_t value = physical_device_table[physical_out].shadow; + + asdf_physical_set(physical_out, !value); +} + +// PROCEDURE: valid_physical_device +// INPUTS: (asdf_physical_dev_t) device +// OUTPUTS: returns true (1) if the device is valid, false (0) if not valid. +// +// DESCRIPTION: test to see if device is a valid device value. +// +// SIDE EFFECTS: +// +// NOTES: +// +// SCOPE: private +// +// COMPLEXITY: 1 +// +static uint8_t valid_physical_device(asdf_physical_dev_t device) +{ + return (device > PHYSICAL_NO_OUT && device < ASDF_PHYSICAL_NUM_RESOURCES); +} + +// PROCEDURE: physical_device_is_available +// INPUTS: asdf_physical_dev_t requiested_device +// OUTPUTS: returns PHYSICAL_NO_OUT if device is alreay allocated. If not yet allocated, +// returns the index of the device in the available list before the requested +// device. +// +// DESCRIPTION: iterates through the linked list of available devices. If the +// requested_device is encountered, return the element before the requested +// device in the list. If the end of the list is reached, return PHYSICAL_NO_OUT. +// +// SIDE EFFECTS: none +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 2 +// +uint8_t physical_device_is_available(asdf_physical_dev_t device) +{ + asdf_physical_dev_t current_out = PHYSICAL_NO_OUT; + asdf_physical_dev_t next_out = physical_device_table[current_out].next; + + while (next_out != PHYSICAL_NO_OUT && next_out != device) { + current_out = next_out; + next_out = physical_device_table[current_out].next; + } + return (PHYSICAL_NO_OUT == next_out) ? ASDF_PHYSICAL_NUM_RESOURCES : current_out; +} + +// PROCEDURE: asdf_physical_next_device +// INPUTS: (asdf_physical_dev_t) device - the current physical device attached +// to the virtual device being operated on +// +// OUTPUTS: (asdf_physical_dev_t) returns the next physical device assigned to +// the virtual device. +// +// DESCRIPTION: See above. +// +// SIDE EFFECTS: None. +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 1 +// +asdf_physical_dev_t asdf_physical_next_device(asdf_physical_dev_t device) +{ + return physical_device_table[device].next; +} + +// PROCEDURE: asdf_physical_allocate + +// INPUTS: (asdf_physical_out_t) physical_out - the desired physical resource to allocate. +// (asdf_physical_out_t) tail - the list of physical devices to tack on +// to the requested resource, if available. +// +// OUTPUTS: (asdf_physical_out_t) returns TRUE if the allocation is succesful, +// FALSE (0) otherwise. +// +// DESCRIPTION: Check that the requested physical resource is valid and +// available. If so, then remove the resource from the physical resource table +// and assign an initial value, then return a TRUE (1). Return FALSE (0) if +// allocation was not successful. +// +// SIDE EFFECTS: see above. +// +// SCOPE: public +// +// COMPLEXITY: 2 +// +uint8_t asdf_physical_allocate(asdf_physical_dev_t physical_out, asdf_physical_dev_t tail, uint8_t initial_value) +{ + uint8_t success = 0; + asdf_physical_dev_t predecessor = physical_device_is_available(physical_out); + + if (valid_physical_device(physical_out) + && (ASDF_PHYSICAL_NUM_RESOURCES != predecessor)) { + + // remove from available list: + physical_device_table[predecessor].next = physical_device_table[physical_out].next; + + // tack the tail on to the physical device + + physical_device_table[physical_out].next = tail; + + // The physical device shadow value is set here. The shadow values are + // asserted to the outputs only after all the assignments have been + // performed. + physical_device_table[physical_out].shadow = initial_value; + + success = 1; + } + return success; +} + +// PROCEDURE: asdf_physical_init +// INPUTS: none +// OUTPUTS: none +// +// DESCRIPTION: Initialize physical device table +// +// SIDE EFFECTS: see above +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 2 +// +void asdf_physical_init(void) +{ + // initialize the linked list of free devices + for (uint8_t i = 0; i < ASDF_PHYSICAL_NUM_RESOURCES; i++) { + physical_device_table[i].shadow = ASDF_VIRTUAL_OUT_DEFAULT_VALUE; + physical_device_table[i].next = i + 1; // initialize pointer to next in table + } + // The last item in the table is left with a bogus next pointer (beyond the + // end of the array) after the above loop. Make the last element point to + // PHYSICAL_NO_OUT. + physical_device_table[ASDF_PHYSICAL_NUM_RESOURCES - 1].next = PHYSICAL_NO_OUT; // end of list. +} + +//-------|---------|---------+---------+---------+---------+---------+---------+ +// Above line is 80 columns, and should display completely in the editor. diff --git a/firmware/asdf/src/asdf_physical.h b/firmware/asdf/src/asdf_physical.h new file mode 100644 index 0000000..8d964bb --- /dev/null +++ b/firmware/asdf/src/asdf_physical.h @@ -0,0 +1,109 @@ +// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*- +// +// Unfified Keyboard Project +// ASDF keyboard firmware +// +// asdf_physical.h +// +// Definitions and prototypes for physical LED and virtual output resources. +// +// 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 . +// + +#if !defined(ASDF_PHYSICAL_H) +#define ASDF_PHYSICAL_H + + +// The asdf_virtual_real_dev_t enumerates real outputs that can be assigned to +// virtual outputs via the asdf_virtual_assign() function. The name is a bit +// confusing, containing virtual and real. The "virtual" part refers to the +// module and the "real_dev" part attempts to clarify that these are the +// hardware outputs implemented by the architecture-specific module. +typedef enum { + PHYSICAL_NO_OUT = 0, + PHYSICAL_OUT1, + PHYSICAL_OUT1_OC, + PHYSICAL_OUT2, + PHYSICAL_OUT2_OC, + PHYSICAL_OUT3, + PHYSICAL_OUT3_OC, + PHYSICAL_LED1, + PHYSICAL_LED2, + PHYSICAL_LED3, + ASDF_PHYSICAL_NUM_RESOURCES +} asdf_physical_dev_t; + +// PROCEDURE: asdf_physical_set +// INPUTS: (asdf_physical_dev_t) physical_out: which real output to set or clear +// INPUTS: (uint8_t) value +// OUTPUTS: none +// DESCRIPTION: If the physical output is valid, set to high if value is true, low +// if false. +void asdf_physical_set(asdf_physical_dev_t physical_out, uint8_t value); + +// PROCEDURE: asdf_physical_assert +// INPUTS: (asdf_physical_dev_t) physical_out: which physical output to set or clear +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: Assert the value of the physical output shadow register on the output. +void asdf_physical_assert(asdf_physical_dev_t physical_out); + +// PROCEDURE: asdf_physical_toggle +// INPUTS: (asdf_physical_dev_t) physical_out: which physical output to toggle +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: Toggle the value of the physical output. +void asdf_physical_toggle(asdf_physical_dev_t physical_out); + +// PROCEDURE: physical_device_is_available +// INPUTS: asdf_physical_dev_t requiested_device +// OUTPUTS: returns PHYSICAL_NO_OUT if device is alreay allocated. If not yet allocated, +// returns the index of the device in the available list before the requested +// device. +// DESCRIPTION: iterates through the linked list of available devices. If the +// requested_device is encountered, return the element before the requested +// device in the list. If the end of the list is reached, return PHYSICAL_NO_OUT. +uint8_t physical_device_is_available(asdf_physical_dev_t device); + +// PROCEDURE: asdf_physical_next_device +// INPUTS: (asdf_physical_dev_t) device - the current physical device attached +// to the virtual device being operated on +// OUTPUTS: (asdf_physical_dev_t) returns the next physical device assigned to +// the virtual device. +asdf_physical_dev_t asdf_physical_next_device(asdf_physical_dev_t device); + +// PROCEDURE: asdf_physical_allocate +// INPUTS: (asdf_physical_out_t) physical_out - the desired physical resource to allocate. +// (asdf_physical_out_t) tail - the list of physical devices to tack on +// to the requested resource, if available. +// OUTPUTS: (asdf_physical_out_t) returns TRUE if the allocation is succesful, +// FALSE (0) otherwise. +// DESCRIPTION: Check that the requested physical resource is valid and +// available. If so, then remove the resource from the physical resource table +// and assign an initial value, then return a TRUE (1). Return FALSE (0) if +// allocation was not successful. +uint8_t asdf_physical_allocate(asdf_physical_dev_t physical_out, asdf_physical_dev_t tail, uint8_t initial_value); + +// PROCEDURE: asdf_physical_init +// INPUTS: none +// OUTPUTS: none +// DESCRIPTION: Initialize physical device table +void asdf_physical_init(void); + + +#endif /* !defined (ASDF_PHYSICAL_H) */ + +//-------|---------|---------+---------+---------+---------+---------+---------+ +// Above line is 80 columns, and should display completely in the editor. diff --git a/firmware/asdf/src/asdf_virtual.c b/firmware/asdf/src/asdf_virtual.c index d45c78d..38c7727 100644 --- a/firmware/asdf/src/asdf_virtual.c +++ b/firmware/asdf/src/asdf_virtual.c @@ -28,194 +28,94 @@ // #include -#include +#include "asdf_physical.h" #include "asdf_virtual.h" #include "asdf_keymap_defs.h" #include "asdf_config.h" #include "asdf_arch.h" -// For each virtual out, maintain a "shadow" register for the output value. This -// permits machine independent implementations of the toggle and pulse functions -// to be implemented in this module, requiring only a "set" function for each -// virtual output in the architecture-dependent layer. This implementation is -// not as efficient, but the timing is not critical, and the events are so -// infrequent that the benefits of the refactoring far outweigh any performance -// penalty. - -typedef struct { - uint8_t shadow; - asdf_virtual_real_dev_t next; -} real_dev_t; - -typedef struct { - asdf_virtual_real_dev_t real_device; // Each virtual device points to a linked - // list of any number of real devices. - asdf_virtual_function_t function; -} virtual_dev_t; - - -static real_dev_t real_device_table[NUM_REAL_OUTPUTS]; - - -// vout_set[] contains the set() function for each real output device. -static void (*const vout_set[])(uint8_t) = { - [VMAP_NO_OUT] = &asdf_arch_null_output, // - [VMAP_OUT1] = &asdf_arch_out1_set, // - [VMAP_OUT2] = &asdf_arch_out2_set, // - [VMAP_OUT3] = &asdf_arch_out3_set, // - [VMAP_OUT1_OC] = &asdf_arch_out1_hi_z_set, // - [VMAP_OUT2_OC] = &asdf_arch_out2_hi_z_set, // - [VMAP_OUT3_OC] = &asdf_arch_out3_hi_z_set, // - [VMAP_LED1] = &asdf_arch_led1_set, // - [VMAP_LED2] = &asdf_arch_led2_set, // - [VMAP_LED3] = &asdf_arch_led3_set // -}; - -// virtual_out[] contains all the virtual outputs. An asdf_virtual_output_t +// virtual_device_table[] contains all the virtual outputs. An asdf_virtual_output_t // value is used to identify each element. Each element is a virtual device, -// containing an asdf_virtual_real_dev_t value indicating the real device (if +// containing an asdf_virtual_physical_dev_t value indicating the physical device (if // any) assigned to the virtual device. -static virtual_dev_t virtual_device_table[NUM_VIRTUAL_OUTPUTS]; - - -// PROCEDURE: asdf_virtual_real_set -// INPUTS: (asdf_virtual_real_dev_t) real_out: which real output to set or clear -// INPUTS: (uint8_t) value -// OUTPUTS: none -// -// DESCRIPTION: If the real output is valid, set to high if value is true, low -// if false. -// -// SIDE EFFECTS: see above -// -// NOTES: No bounds checking. The caller must ensure a valid device -// -// SCOPE: private -// -// COMPLEXITY: 1 -// -static void asdf_virtual_real_set(asdf_virtual_real_dev_t real_out, uint8_t value) -{ - vout_set[real_out](value); - real_device_table[real_out].shadow = value; -} - - -// PROCEDURE: asdf_virtual_real_assert -// INPUTS: (asdf_virtual_real_dev_t) real_out: which real output to set or clear -// INPUTS: none -// OUTPUTS: none -// -// DESCRIPTION: Assert the value of the real output shadow register on the output. -// -// SIDE EFFECTS: see above -// -// NOTES: No bounds checking. Only called from initialization code. -// -// SCOPE: private -// -// COMPLEXITY: 1 -// -static void asdf_virtual_real_assert(asdf_virtual_real_dev_t real_out) -{ - uint8_t value = real_device_table[real_out].shadow; - vout_set[real_out](value); -} - -// PROCEDURE: asdf_virtual_real_toggle -// INPUTS: (asdf_virtual_real_dev_t) real_out: which real output to toggle -// INPUTS: none -// OUTPUTS: none -// -// DESCRIPTION: Toggle the value of the real output. -// -// SIDE EFFECTS: see above -// -// NOTES: No bounds checking. Only called from initialization code. -// -// SCOPE: private -// -// COMPLEXITY: 1 -// -static void asdf_virtual_real_toggle(asdf_virtual_real_dev_t real_out) -{ - uint8_t value = real_device_table[real_out].shadow; - - asdf_virtual_real_set(real_out, !value); -} +static struct { + asdf_physical_dev_t physical_device; // Each virtual device points to a linked + // list of any number of physical devices. + asdf_virtual_function_t function; +} virtual_device_table[ASDF_VIRTUAL_NUM_RESOURCES]; // PROCEDURE: asdf_virtual_action // INPUTS: (asdf_virtual_output_t) virtual_out: which virtual output to modify // INPUTS: (asdf_virtual_function_t) function: what function to apply to the virtual output // OUTPUTS: none // -// DESCRIPTION: for each real output mapped to the virtual output, apply the +// DESCRIPTION: for each physical output mapped to the virtual output, apply the // specified function. // // SIDE EFFECTS: see above // -// NOTES: The virtual output points to a linked list of real devices. +// NOTES: The virtual output points to a linked list of physical devices. // // SCOPE: public // // COMPLEXITY: 7 // -void asdf_virtual_action(asdf_virtual_output_t virtual_out, asdf_virtual_function_t function) +void asdf_virtual_action(asdf_virtual_dev_t virtual_out, asdf_virtual_function_t function) { - asdf_virtual_real_dev_t device = virtual_device_table[virtual_out].real_device; + asdf_physical_dev_t device = virtual_device_table[virtual_out].physical_device; - while (VMAP_NO_OUT != device) { + while (PHYSICAL_NO_OUT != device) { switch (function) { case V_PULSE: { - asdf_virtual_real_toggle(device); + asdf_physical_toggle(device); asdf_arch_pulse_delay(); // yes we could omit the next two lines and fall through, but we will // spend a few bytes of redundant code for the sake of consistency and // readability. - asdf_virtual_real_toggle(device); + asdf_physical_toggle(device); break; } case V_TOGGLE: { - asdf_virtual_real_toggle(device); + asdf_physical_toggle(device); break; } case V_SET_HI: { - asdf_virtual_real_set(device, 1); + asdf_physical_set(device, 1); break; } case V_SET_LO: { - asdf_virtual_real_set(device, 0); + asdf_physical_set(device, 0); } case V_NOFUNC: default: break; } - device = real_device_table[device].next; + device = asdf_physical_next_device(device); } } // PROCEDURE: asdf_virtual_activate -// INPUTS: asdf_virtual_output_t: The virtual device to be activated +// INPUTS: asdf_virtual_dev_t: The virtual device to be activated // OUTPUTS: none // -// DESCRIPTION: for each real output mapped to the virtual output, apply the +// DESCRIPTION: for each physical output mapped to the virtual output, apply the // function assigned to the virtual output at initialization. // // SIDE EFFECTS: see above // -// NOTES: The virtual output points to a linked list of real devices. +// NOTES: The virtual output points to a linked list of physical devices. // // SCOPE: public // // COMPLEXITY: 1 // -void asdf_virtual_activate(asdf_virtual_output_t virtual_out) +void asdf_virtual_activate(asdf_virtual_dev_t virtual_out) { asdf_virtual_action(virtual_out, virtual_device_table[virtual_out].function); } // PROCEDURE: valid_virtual_device -// INPUTS: (asdf_virtual_output_t) device +// INPUTS: (asdf_virtual_dev_t) device // OUTPUTS: returns true (1) if the device is valid, false (0) if not valid. // // DESCRIPTION: test to see if device is a valid device value. @@ -228,98 +128,43 @@ void asdf_virtual_activate(asdf_virtual_output_t virtual_out) // // COMPLEXITY: 1 // -static uint8_t valid_virtual_device(asdf_virtual_output_t device) +static uint8_t valid_virtual_device(asdf_virtual_dev_t device) { - return (device > V_NULL && device < NUM_VIRTUAL_OUTPUTS); -} - -// PROCEDURE: valid_real_device -// INPUTS: (asdf_virtual_real_dev_t) device -// OUTPUTS: returns true (1) if the device is valid, false (0) if not valid. -// -// DESCRIPTION: test to see if device is a valid device value. -// -// SIDE EFFECTS: -// -// NOTES: -// -// SCOPE: private -// -// COMPLEXITY: 1 -// -static uint8_t valid_real_device(asdf_virtual_real_dev_t device) -{ - return (device > VMAP_NO_OUT && device < NUM_REAL_OUTPUTS); -} - -// PROCEDURE: real_device_is_available -// INPUTS: asdf_virtual_real_dev_t requiested_device -// OUTPUTS: returns VMAP_NO_OUT if device is alreay allocated. If not yet allocated, -// returns the index of the device in the available list before the requested -// device. -// -// DESCRIPTION: iterates through the linked list of available devices. If the -// requested_device is encountered, return the element before the requested -// device in the list. If the end of the list is reached, return VMAP_NO_OUT. -// -// SIDE EFFECTS: none -// -// NOTES: -// -// SCOPE: private -// -// COMPLEXITY: 3 -// -static uint8_t real_device_is_available(asdf_virtual_real_dev_t device) -{ - asdf_virtual_real_dev_t current_out = VMAP_NO_OUT; - asdf_virtual_real_dev_t next_out = real_device_table[current_out].next; - - while (next_out != VMAP_NO_OUT && next_out != device) { - current_out = next_out; - next_out = real_device_table[current_out].next; - } - return (VMAP_NO_OUT == next_out) ? NUM_REAL_OUTPUTS : current_out; + return (device > V_NULL && device < ASDF_VIRTUAL_NUM_RESOURCES); } // PROCEDURE: asdf_virtual_assign -// INPUTS: (asdf_vout_t) virtual_out -// (uint8_t) real_out +// INPUTS: (asdf_virtual_dev_t) virtual_out - virtual output to be paired with the physical output +// (asdf_physical_dev_t) physical_out to be assigned to the virtual output. +// (asdf_virtual_function_t) - the function to be applied to the virtual +// device when activated by a keypress. +// (uint8_t) initial_value - the initial state of the physical output. +// // OUTPUTS: none // -// DESCRIPTION: map the virtual output specified by new_vout to real_out, if +// DESCRIPTION: map the virtual output specified by new_vout to physical_out, if // both arguments are valid. Ignore if not valid. // // SIDE EFFECTS: see above. // -// NOTES: if the virtual device is invalid, or the real device is invalid, or -// the real device is already assigned, then nothing happens. +// NOTES: if the virtual device is invalid, or the physical device is invalid, or +// the physical device is already assigned, then nothing happens. // // SCOPE: private // // COMPLEXITY: 2 // -static void asdf_virtual_assign(asdf_virtual_output_t virtual_out, asdf_virtual_real_dev_t real_out, +static void asdf_virtual_assign(asdf_virtual_dev_t virtual_out, asdf_physical_dev_t physical_out, asdf_virtual_function_t function, uint8_t initial_value) { - asdf_virtual_real_dev_t predecessor = real_device_is_available(real_out); + if (valid_virtual_device(virtual_out)) { + asdf_physical_dev_t tail = virtual_device_table[virtual_out].physical_device; - if (valid_virtual_device(virtual_out) - && valid_real_device(real_out) - && (NUM_REAL_OUTPUTS != predecessor)) { - virtual_device_table[virtual_out].function = function; + if (asdf_physical_allocate(physical_out, tail, initial_value)) { - // remove from available list: - real_device_table[predecessor].next = real_device_table[real_out].next; - - // add real device to the list associated with the virtual device: - - real_device_table[real_out].next = virtual_device_table[virtual_out].real_device; - virtual_device_table[virtual_out].real_device = real_out; - - // The real device shadow value is set here. The shadow values are asserted to - // the outputs only after all the assignments have been performed. - real_device_table[real_out].shadow = initial_value; + virtual_device_table[virtual_out].physical_device = physical_out; + virtual_device_table[virtual_out].function = function; + } } } @@ -340,35 +185,27 @@ static void asdf_virtual_assign(asdf_virtual_output_t virtual_out, asdf_virtual_ // void asdf_virtual_init(asdf_virtual_initializer_t *const initializer_list) { + // initial the physical device table every time virtual device table is + // initialized. + asdf_physical_init(); // initialize list of virtual outputs - for (uint8_t i = 0; i < NUM_VIRTUAL_OUTPUTS; i++) { + for (uint8_t i = 0; i < ASDF_VIRTUAL_NUM_RESOURCES; i++) { virtual_device_table[i].function = V_NOFUNC; - virtual_device_table[i].real_device = VMAP_NO_OUT; + virtual_device_table[i].physical_device = PHYSICAL_NO_OUT; } - // initialize the linked list of free devices - for (uint8_t i = 0; i < NUM_REAL_OUTPUTS; i++) { - real_device_table[i].shadow = ASDF_VIRTUAL_OUT_DEFAULT_VALUE; - real_device_table[i].next = i + 1; // initialize pointer to next in table - } - // The last item in the table is left with a bogus next pointer (beyond the - // end of the array) after the above loop. Make the last element point to - // V_NULL. - real_device_table[NUM_REAL_OUTPUTS - 1].next = VMAP_NO_OUT; // end of list. - - // run through the keymap specific setup for (uint8_t i = 0; // i < ASDF_KEYMAP_INITIALIZER_LENGTH && initializer_list[i].virtual_device != V_NULL; i++) { - asdf_virtual_assign(initializer_list[i].virtual_device, initializer_list[i].real_device, + asdf_virtual_assign(initializer_list[i].virtual_device, initializer_list[i].physical_device, initializer_list[i].function, initializer_list[i].initial_value); } // Now set all the initial LED and output values - for (uint8_t i = 0; i < NUM_REAL_OUTPUTS; i++) { - asdf_virtual_real_assert((asdf_virtual_real_dev_t) i); + for (uint8_t i = 0; i < ASDF_PHYSICAL_NUM_RESOURCES; i++) { + asdf_physical_assert((asdf_physical_dev_t) i); } } diff --git a/firmware/asdf/src/asdf_virtual.h b/firmware/asdf/src/asdf_virtual.h index 6c9b0af..623d6b3 100644 --- a/firmware/asdf/src/asdf_virtual.h +++ b/firmware/asdf/src/asdf_virtual.h @@ -25,7 +25,6 @@ #if !defined(ASDF_VIRTUAL_H) #define ASDF_VIRTUAL_H - // These are "virtual" output identifiers that can be mapped to the real outputs using // keymap initializer commands. typedef enum { @@ -41,27 +40,9 @@ typedef enum { VLED3, VCAPS_LED, VSHIFT_LED, - NUM_VIRTUAL_OUTPUTS -} asdf_virtual_output_t; + ASDF_VIRTUAL_NUM_RESOURCES +} asdf_virtual_dev_t; -// The asdf_virtual_real_dev_t enumerates real outputs that can be assigned to -// virtual outputs via the asdf_virtual_assign() function. The name is a bit -// confusing, containing virtual and real. The "virtual" part refers to the -// module and the "real_dev" part attempts to clarify that these are the -// hardware outputs implemented by the architecture-specific module. -typedef enum { - VMAP_NO_OUT = 0, - VMAP_OUT1, - VMAP_OUT1_OC, - VMAP_OUT2, - VMAP_OUT2_OC, - VMAP_OUT3, - VMAP_OUT3_OC, - VMAP_LED1, - VMAP_LED2, - VMAP_LED3, - NUM_REAL_OUTPUTS -} asdf_virtual_real_dev_t; typedef enum { V_NOFUNC, @@ -69,32 +50,32 @@ typedef enum { V_SET_LO, V_PULSE, V_TOGGLE, - NUM_VIRTUAL_FUNCTIONS + ASDF_VIRTUAL_NUM_FUNCTIONS } asdf_virtual_function_t; // Each keymap specifies an array of initializer structs to configure virtual // devices, specifying the mapped real device and initial value. typedef struct { - asdf_virtual_output_t virtual_device; - asdf_virtual_real_dev_t real_device; + asdf_virtual_dev_t virtual_device; + asdf_physical_dev_t physical_device; asdf_virtual_function_t function; uint8_t initial_value; } asdf_virtual_initializer_t; // PROCEDURE: asdf_virtual_action -// INPUTS: (asdf_virtual_output_t) virtual_out: which virtual output to modify +// INPUTS: (asdf_virtual_dev_t) virtual_out: which virtual output to modify // INPUTS: (asdf_virtual_function_t) function: what function to apply to the virtual output // OUTPUTS: none // DESCRIPTION: for each real output mapped to the virtual output, apply the // specified function. -void asdf_virtual_action(asdf_virtual_output_t virtual_out, asdf_virtual_function_t function); +void asdf_virtual_action(asdf_virtual_dev_t virtual_out, asdf_virtual_function_t function); // PROCEDURE: asdf_virtual_activate -// INPUTS: asdf_virtual_output_t: The virtual device to be activated +// INPUTS: asdf_virtual_dev_t: The virtual device to be activated // OUTPUTS: none // DESCRIPTION: for each real output mapped to the virtual output, apply the // function assigned to the virtual output at initialization. -void asdf_virtual_activate(asdf_virtual_output_t virtual_out); +void asdf_virtual_activate(asdf_virtual_dev_t virtual_out); // PROCEDURE: asdf_virtual_init // INPUTS: initializers diff --git a/firmware/asdf/test/test_asdf_virtual.c b/firmware/asdf/test/test_asdf_virtual.c index ceee32a..4ee2197 100644 --- a/firmware/asdf/test/test_asdf_virtual.c +++ b/firmware/asdf/test/test_asdf_virtual.c @@ -39,68 +39,68 @@ void test_inizializer_length_is_max_length(void) void test_single_virtual_output_is_initialized(void) { // initially on keymap 0. Test to see that OUT1 has been initialized to 0. - TEST_ASSERT_EQUAL_INT32(asdf_arch_check_output(VMAP_OUT1), 0); + TEST_ASSERT_EQUAL_INT32(asdf_arch_check_output(PHYSICAL_OUT1), 0); // and verify that this is not just the default value - TEST_ASSERT_NOT_EQUAL(ASDF_VIRTUAL_OUT_DEFAULT_VALUE, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_NOT_EQUAL(ASDF_VIRTUAL_OUT_DEFAULT_VALUE, asdf_arch_check_output(PHYSICAL_OUT1)); } void test_uninitialized_virtual_out_is_default(void) { - TEST_ASSERT_EQUAL_INT32(ASDF_VIRTUAL_OUT_DEFAULT_VALUE, asdf_arch_check_output(VMAP_LED2)); + TEST_ASSERT_EQUAL_INT32(ASDF_VIRTUAL_OUT_DEFAULT_VALUE, asdf_arch_check_output(PHYSICAL_LED2)); } void test_set_virtual_output(void) { asdf_virtual_action(VOUT1, V_SET_LO); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); asdf_virtual_action(VOUT1, V_SET_HI); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT1)); } void test_toggle_virtual_output(void) { // start by setting vout1 to 0 asdf_virtual_action(VOUT1, V_SET_LO); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); // toggle high asdf_virtual_action(VOUT1, V_TOGGLE); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT1)); // toggle back low. asdf_virtual_action(VOUT1, V_TOGGLE); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); } void test_pulse_high_virtual_output(void) { asdf_virtual_action(VOUT1, V_SET_LO); - TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_LOW, asdf_arch_check_pulse(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_LOW, asdf_arch_check_pulse(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); asdf_virtual_action(VOUT1, V_PULSE); // output should be low - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); // high pulse should be detected. - TEST_ASSERT_EQUAL_INT32(PD_ST_PULSE_HIGH_DETECTED, asdf_arch_check_pulse(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(PD_ST_PULSE_HIGH_DETECTED, asdf_arch_check_pulse(PHYSICAL_OUT1)); } void test_pulse_low_virtual_output(void) { asdf_virtual_action(VOUT1, V_SET_HI); asdf_virtual_action(VOUT1, V_SET_HI); - TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_HIGH, asdf_arch_check_pulse(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_HIGH, asdf_arch_check_pulse(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT1)); asdf_virtual_action(VOUT1, V_PULSE); // output should be high - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT1)); // low pulse should be detected. - TEST_ASSERT_EQUAL_INT32(PD_ST_PULSE_LOW_DETECTED, asdf_arch_check_pulse(VMAP_OUT1)); + TEST_ASSERT_EQUAL_INT32(PD_ST_PULSE_LOW_DETECTED, asdf_arch_check_pulse(PHYSICAL_OUT1)); } // This test ties three real outputs to a virtual output and toggles the virtual @@ -110,19 +110,19 @@ void test_toggle_triple_output(void) asdf_keymaps_select_keymap(TRIPLE_TESTS_KEYMAP); // check that initial values have been set: - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT3)); asdf_virtual_activate(VOUT1); // funtion is set to toggle - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT3)); asdf_virtual_action(VOUT1, V_TOGGLE); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT3)); } // This test ties three real outputs to a virtual output and sets the virtual @@ -132,19 +132,19 @@ void test_set_triple_output(void) asdf_keymaps_select_keymap(TRIPLE_TESTS_KEYMAP); // check that initial values have been set: - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT3)); asdf_virtual_action(VOUT1, V_SET_HI); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT3)); asdf_virtual_action(VOUT1, V_SET_LO); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT3)); } // This test ties three real outputs to a virtual output and pulses the virtual @@ -153,34 +153,34 @@ void test_pulse_triple_output(void) { asdf_keymaps_select_keymap(TRIPLE_TESTS_KEYMAP); // check that initial values have been set: - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT3)); asdf_virtual_action(VOUT1, V_SET_HI); asdf_virtual_action(VOUT1, V_SET_HI); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT3)); - TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_HIGH, asdf_arch_check_pulse(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_HIGH, asdf_arch_check_pulse(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_HIGH, asdf_arch_check_pulse(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_HIGH, asdf_arch_check_pulse(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_HIGH, asdf_arch_check_pulse(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(PD_ST_STABLE_HIGH, asdf_arch_check_pulse(PHYSICAL_OUT3)); asdf_virtual_action(VOUT1, V_SET_LO); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT3)); - TEST_ASSERT_EQUAL_INT32(PD_ST_TRANSITION_LOW, asdf_arch_check_pulse(VMAP_OUT1)); - TEST_ASSERT_EQUAL_INT32(PD_ST_TRANSITION_LOW, asdf_arch_check_pulse(VMAP_OUT2)); - TEST_ASSERT_EQUAL_INT32(PD_ST_TRANSITION_LOW, asdf_arch_check_pulse(VMAP_OUT3)); + TEST_ASSERT_EQUAL_INT32(PD_ST_TRANSITION_LOW, asdf_arch_check_pulse(PHYSICAL_OUT1)); + TEST_ASSERT_EQUAL_INT32(PD_ST_TRANSITION_LOW, asdf_arch_check_pulse(PHYSICAL_OUT2)); + TEST_ASSERT_EQUAL_INT32(PD_ST_TRANSITION_LOW, asdf_arch_check_pulse(PHYSICAL_OUT3)); } uint8_t *output_array(void) { - static uint8_t outputs[NUM_REAL_OUTPUTS] = {}; - for (uint8_t i = 0; i < NUM_REAL_OUTPUTS; i++) { + static uint8_t outputs[ASDF_PHYSICAL_NUM_RESOURCES] = {}; + for (uint8_t i = 0; i < ASDF_PHYSICAL_NUM_RESOURCES; i++) { outputs[i] = asdf_arch_check_output(i); printf("output %d: %d\n", i, outputs[i]); } @@ -189,8 +189,8 @@ uint8_t *output_array(void) uint8_t *all_set_array(void) { - static uint8_t outputs[NUM_REAL_OUTPUTS] = {}; - for (uint8_t i = 0; i < NUM_REAL_OUTPUTS; i++) { + static uint8_t outputs[ASDF_PHYSICAL_NUM_RESOURCES] = {}; + for (uint8_t i = 0; i < ASDF_PHYSICAL_NUM_RESOURCES; i++) { outputs[i] = 1; } return outputs; @@ -198,17 +198,17 @@ uint8_t *all_set_array(void) uint8_t *all_zero_array(void) { - static uint8_t outputs[NUM_REAL_OUTPUTS] = {}; - for (uint8_t i = 0; i < NUM_REAL_OUTPUTS; i++) { + static uint8_t outputs[ASDF_PHYSICAL_NUM_RESOURCES] = {}; + for (uint8_t i = 0; i < ASDF_PHYSICAL_NUM_RESOURCES; i++) { outputs[i] = 0; } return outputs; } -uint8_t *single_zero_array(asdf_virtual_real_dev_t set_element) +uint8_t *single_zero_array(asdf_physical_dev_t set_element) { - static uint8_t outputs[NUM_REAL_OUTPUTS] = {}; - for (uint8_t i = 0; i < NUM_REAL_OUTPUTS; i++) { + static uint8_t outputs[ASDF_PHYSICAL_NUM_RESOURCES] = {}; + for (uint8_t i = 0; i < ASDF_PHYSICAL_NUM_RESOURCES; i++) { outputs[i] = 1; } outputs[set_element] = 0; @@ -222,20 +222,20 @@ void test_virtual_capslock_indicator(void) asdf_keymaps_select_keymap(VCAPS_TEST_KEYMAP); // CAPS LED output should be initialized to zero: - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_LED1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED1)); // emulate capslock press and release. Should set LED1 asdf_modifier_capslock_activate(); asdf_modifier_capslock_deactivate(); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_LED1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_LED1)); // emulate capslock press and release. clear LED1 asdf_modifier_capslock_activate(); asdf_modifier_capslock_deactivate(); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_LED1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED1)); } void test_virtual_shiftlock_indicator(void) @@ -244,20 +244,20 @@ void test_virtual_shiftlock_indicator(void) asdf_keymaps_select_keymap(VSHIFT_TEST_KEYMAP); // CAPS LED output should be initialized to zero: - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_LED2)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED2)); // emulate shiftlock press and release. Should set LED2 asdf_modifier_shiftlock_activate(); asdf_modifier_shiftlock_deactivate(); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_LED2)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_LED2)); // emulate shift press and release. clear LED2 asdf_modifier_shift_activate(); asdf_modifier_shift_deactivate(); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_LED2)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED2)); } @@ -266,20 +266,20 @@ void test_cant_assign_real_output_twice(void) asdf_keymaps_select_keymap(DOUBLE_ASSIGN_TEST_KEYMAP); // initial value should be set to 0: - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_LED1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED1)); // set LED1 high from valid VOUT4 asdf_virtual_action(VOUT4, V_SET_HI); - TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(VMAP_LED1)); + TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_LED1)); // set LED1 low from valid VOUT4 asdf_virtual_action(VOUT4, V_SET_LO); - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_LED1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED1)); // set LED1 high from invalid VOUT5 asdf_virtual_action(VOUT5, V_SET_HI); // Should not have changed. - TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(VMAP_LED1)); + TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED1)); } int main(void)