Get virtual devices in new maps scheme to pass tests

Remove initialization from data structure.

Replace the previous virtual_init() with a virtual_init() that initializes the
data structures to a default state

Create virtual_sync() function to push the state of virtual devices to the
physical outputs.  Moved from the previous virtual_init() function.

The virtual device table is now built by direct calls to virtual_add() from the
setup function.

Toward issue [#23]
This commit is contained in:
Dave 2021-02-20 10:26:22 -06:00 committed by Dave
parent bcde21f3a8
commit b688f1c56f
6 changed files with 174 additions and 174 deletions

View File

@ -37,7 +37,6 @@
#include <stdint.h>
#include "asdf_config.h"
#include "asdf_physical.h"
#include "asdf_virtual.h"
#include "asdf_arch.h"
typedef enum {

View File

@ -184,7 +184,7 @@ static uint8_t valid_virtual_device(asdf_virtual_dev_t device)
//
// COMPLEXITY: 3
//
static void asdf_virtual_assign(asdf_virtual_dev_t virtual_out, asdf_physical_dev_t physical_out,
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)
{
if (valid_virtual_device(virtual_out)) {
@ -199,8 +199,7 @@ static void asdf_virtual_assign(asdf_virtual_dev_t virtual_out, asdf_physical_de
}
// PROCEDURE: asdf_virtual_init
// INPUTS: (asdf_virtual_initializer_t *) initializer_list - contains the
// initializer list for the selected keymap.
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Initializes the LED and output mapping
@ -213,7 +212,7 @@ static void asdf_virtual_assign(asdf_virtual_dev_t virtual_out, asdf_physical_de
//
// COMPLEXITY: 4
//
void asdf_virtual_init(asdf_virtual_initializer_t *const initializer_list)
void asdf_virtual_init(void)
{
// initialize the physical resource table every time virtual output table is
// initialized.
@ -224,16 +223,22 @@ void asdf_virtual_init(asdf_virtual_initializer_t *const initializer_list)
virtual_device_table[i].function = V_NOFUNC;
virtual_device_table[i].physical_device = PHYSICAL_NO_OUT;
}
}
// 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].physical_device,
initializer_list[i].function, initializer_list[i].initial_value);
}
// Now set all the initial LED and output values
// PROCEDURE: asdf_virtual_sync
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Synchronize the physical outputs with their controlling virtual devices.
//
// SIDE EFFECTS: see above
//
// SCOPE: public
//
// COMPLEXITY: 2
//
void asdf_virtual_sync(void)
{
for (uint8_t i = 0; i < ASDF_PHYSICAL_NUM_RESOURCES; i++) {
asdf_physical_assert((asdf_physical_dev_t) i);
}

View File

@ -80,12 +80,31 @@ void asdf_virtual_action(asdf_virtual_dev_t virtual_out, asdf_virtual_function_t
// function assigned to the virtual output at initialization.
void asdf_virtual_activate(asdf_virtual_dev_t virtual_out);
// PROCEDURE: asdf_virtual_assign
// INPUTS: (asdf_virtual_dev_t) virtual_out - virtual output to be paired with the physical resource
// (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 resource.
// OUTPUTS: none
// DESCRIPTION: map the virtual output specified by new_vout to physical_out, if
// both arguments are valid. Ignore if not valid.
// NOTES: if the virtual output is invalid, or the physical resource is invalid,
// or the physical resource is already assigned, then nothing happens.
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);
// PROCEDURE: asdf_virtual_init
// INPUTS: initializers
// OUTPUTS: none
// DESCRIPTION: Initializes the LED and output mapping
void asdf_virtual_init(asdf_virtual_initializer_t *const initializer_list);
void asdf_virtual_init(void);
// PROCEDURE: asdf_virtual_sync
// INPUTS: none
// OUTPUTS: none
// DESCRIPTION: Synchronize the physical outputs with their controlling virtual devices.
void asdf_virtual_sync(void);
#endif /* !defined (ASDF_VIRTUAL_H) */

View File

@ -1,4 +1,4 @@
// -*- mode: C; tab-width: 2 ; indent-tabs-mode: nil -*-
// -*- mode: C; tab-width: 2 ; indent-tabs-mode: nil -*-
//
// Unified Keyboard Project
// ASDF keyboard firmware
@ -40,28 +40,13 @@ static const asdf_keycode_t test2_CAPS_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = AS
static const asdf_keycode_t test2_CTRL_matrix[TEST_NUM_ROWS][TEST_NUM_COLS] = ASDF_TEST2_CTRL_MAP;
// PROCEDURE:
// INPUTS:
// OUTPUTS:
//
// DESCRIPTION:
//
// SIDE EFFECTS:
//
// NOTES:
//
// SCOPE:
//
// COMPLEXITY:
//
void test_keymaps_add_map (const asdf_keycode_t (*matrix)[TEST_NUM_COLS],
modifier_index_t modifier_index)
void test_keymaps_add_map(const asdf_keycode_t (*matrix)[TEST_NUM_COLS],
modifier_index_t modifier_index)
{
asdf_keymaps_add_map(&matrix[0][0], modifier_index, (uint8_t) TEST_NUM_ROWS, (uint8_t) TEST_NUM_COLS);
asdf_keymaps_add_map(&matrix[0][0], modifier_index, (uint8_t) TEST_NUM_ROWS,
(uint8_t) TEST_NUM_COLS);
}
void setup_test_plain_map(void)
{
@ -95,68 +80,75 @@ void setup_test2_caps_map(void)
test_keymaps_add_map(test2_CTRL_matrix, MOD_CTRL_MAP);
}
void setup_test_devs1(void)
void setup_test_vdevs_map0(void)
{
#define ASDF_TEST_KEYMAP_INITIALIZER_1 \
{ \
.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 \
} \
}
setup_test_plain_map();
asdf_virtual_init();
/* single assignment */
asdf_virtual_assign(VOUT1, PHYSICAL_OUT1, V_NOFUNC, 0);
/* single toggle */
asdf_virtual_assign(VOUT2, PHYSICAL_OUT2, V_TOGGLE, 0);
/* single pulse */
asdf_virtual_assign(VOUT3, PHYSICAL_OUT3, V_PULSE_SHORT, 0);
/* first of double assignment attempt */
asdf_virtual_assign(VOUT4, PHYSICAL_LED1, V_NOFUNC, 0);
/* second of double assignment attempt */
asdf_virtual_assign(VOUT5, PHYSICAL_LED1, V_NOFUNC, 1);
asdf_virtual_sync();
}
void setup_test_devs2(void)
void setup_test_vdevs_map1(void)
{
#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, \
} \
}
setup_test_caps_map();
asdf_virtual_init();
/* Triple assignment */
asdf_virtual_assign(VOUT1, PHYSICAL_OUT1, V_TOGGLE, 0);
asdf_virtual_assign(VOUT1, PHYSICAL_OUT2, V_TOGGLE, 1);
asdf_virtual_assign(VOUT1, PHYSICAL_OUT3, V_TOGGLE, 0);
asdf_virtual_sync();
}
void setup_test_vdevs_map2(void)
{
setup_test2_plain_map();
asdf_virtual_init();
asdf_virtual_assign(VCAPS_LED, PHYSICAL_LED1, V_NOFUNC, 0);
asdf_virtual_assign(VSHIFT_LED, PHYSICAL_LED2, V_NOFUNC, 0);
asdf_virtual_assign(VOUT2, PHYSICAL_OUT3, V_NOFUNC, 0);
asdf_virtual_assign(VOUT2, ASDF_PHYSICAL_NUM_RESOURCES, V_NOFUNC, 0);
asdf_virtual_sync();
}
void setup_test_vdevs_map3(void)
{
setup_test2_caps_map();
asdf_virtual_init();
asdf_virtual_assign(VCAPS_LED, PHYSICAL_LED1, V_NOFUNC, 0);
asdf_virtual_assign(VSHIFT_LED, PHYSICAL_LED2, V_NOFUNC, 0);
asdf_virtual_assign(VOUT2, PHYSICAL_OUT3, V_NOFUNC, 0);
asdf_virtual_assign(VOUT2, ASDF_PHYSICAL_NUM_RESOURCES, V_NOFUNC, 0);
asdf_virtual_sync();
}
//-------|---------|---------+---------+---------+---------+---------+---------+
// Above line is 80 columns, and should display completely in the editor.

View File

@ -49,13 +49,19 @@
// only 9 rows need be allocated.
#define TEST_NUM_ROWS 9
#define TEST_NUM_COLS 8
#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 PLAIN_MATRIX_2 RESERVED_5
#define CAPS_MATRIX_2 RESERVED_6
#define SHIFT_MATRIX_2 RESERVED_7
#define CTRL_MATRIX_2 RESERVED_8
#define TEST_NUM_ROWS 9
#define TEST_NUM_COLS 8
#define ASDF_TEST_MAP_DIP_SWITCHES \
[TEST_NUM_ROWS-1] = { ACTION_MAPSEL_0, ACTION_MAPSEL_1, ACTION_MAPSEL_2, ACTION_MAPSEL_3 }
@ -128,57 +134,6 @@
}
#define ASDF_TEST_PLAIN_MAP_INDEX 0
#define ASDF_TEST_CAPS_MAP_INDEX 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 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
#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_TEST2_PLAIN_MAP \
{ \
{ PLAIN_MATRIX_2, ACTION_SHIFT, ACTION_SHIFT, ACTION_NOTHING, \
@ -247,40 +202,58 @@
#define ASDF_TEST_PLAIN_MAP_INDEX 0
#define ASDF_TEST_CAPS_MAP_INDEX 1
#define ASDF_TEST2_PLAIN_MAP_INDEX 2
#define ASDF_TEST2_CAPS_MAP_INDEX 3
// keymap assignments for the virtual device tests
#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 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
// 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 \
{ \
@ -311,6 +284,10 @@ 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);

View File

@ -15,8 +15,16 @@ void setUp(void)
{
asdf_arch_init();
asdf_keymaps_init();
asdf_keymaps_register(ASDF_TEST_PLAIN_MAP_INDEX, &setup_test_vdevs_map0);
asdf_keymaps_register(ASDF_TEST_CAPS_MAP_INDEX, &setup_test_vdevs_map1);
asdf_keymaps_register(ASDF_TEST2_PLAIN_MAP_INDEX, &setup_test_vdevs_map2);
asdf_keymaps_register(ASDF_TEST2_CAPS_MAP_INDEX, &setup_test_vdevs_map3);
asdf_keymaps_select(0);
}
void tearDown(void) {}
// needed for keymap.
@ -96,7 +104,7 @@ void test_pulse_low_virtual_output(void)
// output.
void test_toggle_triple_output(void)
{
asdf_keymaps_select_keymap(TRIPLE_TESTS_KEYMAP);
asdf_keymaps_select(TRIPLE_TESTS_KEYMAP);
// check that initial values have been set:
TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1));
@ -118,7 +126,7 @@ void test_toggle_triple_output(void)
// output high and low
void test_set_triple_output(void)
{
asdf_keymaps_select_keymap(TRIPLE_TESTS_KEYMAP);
asdf_keymaps_select(TRIPLE_TESTS_KEYMAP);
// check that initial values have been set:
TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1));
@ -140,7 +148,7 @@ void test_set_triple_output(void)
// output high and low
void test_pulse_triple_output(void)
{
asdf_keymaps_select_keymap(TRIPLE_TESTS_KEYMAP);
asdf_keymaps_select(TRIPLE_TESTS_KEYMAP);
// check that initial values have been set:
TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1));
TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT2));
@ -171,7 +179,7 @@ void test_pulse_triple_output(void)
// output high and low
void test_activate_triple_output(void)
{
asdf_keymaps_select_keymap(TRIPLE_TESTS_KEYMAP);
asdf_keymaps_select(TRIPLE_TESTS_KEYMAP);
// check that initial values have been set:
TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_OUT1));
TEST_ASSERT_EQUAL_INT32(1, asdf_arch_check_output(PHYSICAL_OUT2));
@ -230,7 +238,7 @@ uint8_t *single_zero_array(asdf_physical_dev_t set_element)
void test_virtual_capslock_indicator(void)
{
asdf_keymaps_select_keymap(VCAPS_TEST_KEYMAP);
asdf_keymaps_select(VCAPS_TEST_KEYMAP);
// CAPS LED output should be initialized to zero:
TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED1));
@ -250,7 +258,7 @@ void test_virtual_capslock_indicator(void)
void test_virtual_shiftlock_indicator(void)
{
asdf_keymaps_select_keymap(VSHIFT_TEST_KEYMAP);
asdf_keymaps_select(VSHIFT_TEST_KEYMAP);
// CAPS LED output should be initialized to zero:
TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED2));
@ -271,7 +279,7 @@ void test_virtual_shiftlock_indicator(void)
void test_cant_assign_real_output_twice(void)
{
asdf_keymaps_select_keymap(DOUBLE_ASSIGN_TEST_KEYMAP);
asdf_keymaps_select(DOUBLE_ASSIGN_TEST_KEYMAP);
// initial value should be set to 0:
TEST_ASSERT_EQUAL_INT32(0, asdf_arch_check_output(PHYSICAL_LED1));