mirror of
https://github.com/osiweb/unified_retro_keyboard.git
synced 2024-11-22 19:33:46 +00:00
Clean up physical device structures
- include callback function in device table instead of separate array.
This commit is contained in:
parent
60c00e636c
commit
80cb50eb7e
@ -31,36 +31,39 @@
|
|||||||
#include "asdf_arch.h"
|
#include "asdf_arch.h"
|
||||||
|
|
||||||
|
|
||||||
// physical_out_set[] contains the set() function for each real output device.
|
// For each physical resource, there is a handler and a "shadow" register for the output value.
|
||||||
static void (*const physical_out_set[])(uint8_t) = {
|
//
|
||||||
[PHYSICAL_NO_OUT] = &asdf_arch_null_output, //
|
// For line outputs, the shadow register permits machine independent
|
||||||
[PHYSICAL_OUT1] = &asdf_arch_out1_set, //
|
// implementations of the toggle and pulse functions to be implemented in this
|
||||||
[PHYSICAL_OUT2] = &asdf_arch_out2_set, //
|
// module, requiring only a "set" function for each physical resource in the
|
||||||
[PHYSICAL_OUT3] = &asdf_arch_out3_set, //
|
// architecture-dependent layer. This implementation is not as efficient, but
|
||||||
[PHYSICAL_OUT1_OPEN_HI] = &asdf_arch_out1_open_hi_set, //
|
// the timing is not critical, and the events are so infrequent that the
|
||||||
[PHYSICAL_OUT2_OPEN_HI] = &asdf_arch_out2_open_hi_set, //
|
// benefits of the refactoring far outweigh any performance penalty.
|
||||||
[PHYSICAL_OUT3_OPEN_HI] = &asdf_arch_out3_open_hi_set, //
|
|
||||||
[PHYSICAL_OUT1_OPEN_LO] = &asdf_arch_out1_open_lo_set, //
|
|
||||||
[PHYSICAL_OUT2_OPEN_LO] = &asdf_arch_out2_open_lo_set, //
|
|
||||||
[PHYSICAL_OUT3_OPEN_LO] = &asdf_arch_out3_open_lo_set, //
|
|
||||||
[PHYSICAL_LED1] = &asdf_arch_led1_set, //
|
|
||||||
[PHYSICAL_LED2] = &asdf_arch_led2_set, //
|
|
||||||
[PHYSICAL_LED3] = &asdf_arch_led3_set //
|
|
||||||
};
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
// For each physical resource, maintain a "shadow" register for the output value. This
|
void (*handler)(uint8_t);
|
||||||
// permits machine independent implementations of the toggle and pulse functions
|
|
||||||
// to be implemented in this module, requiring only a "set" function for each
|
|
||||||
// physical resource 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;
|
uint8_t shadow;
|
||||||
asdf_physical_dev_t next;
|
asdf_physical_dev_t next;
|
||||||
} physical_device_table[ASDF_PHYSICAL_NUM_RESOURCES];
|
} physical_device_table_entry_t;
|
||||||
|
|
||||||
|
|
||||||
|
// physical_handler[] contains the set() function for each real output device.
|
||||||
|
static physical_device_table_entry_t physical_device_table[ASDF_PHYSICAL_NUM_RESOURCES] = {
|
||||||
|
[PHYSICAL_NO_OUT] = {.handler = &asdf_arch_null_output,},
|
||||||
|
[PHYSICAL_OUT1] = {.handler = &asdf_arch_out1_set,},
|
||||||
|
[PHYSICAL_OUT2] = {.handler = &asdf_arch_out2_set,},
|
||||||
|
[PHYSICAL_OUT3] = {.handler = &asdf_arch_out3_set,},
|
||||||
|
[PHYSICAL_OUT1_OPEN_HI] = {.handler = &asdf_arch_out1_open_hi_set,},
|
||||||
|
[PHYSICAL_OUT2_OPEN_HI] = {.handler = &asdf_arch_out2_open_hi_set,},
|
||||||
|
[PHYSICAL_OUT3_OPEN_HI] = {.handler = &asdf_arch_out3_open_hi_set,},
|
||||||
|
[PHYSICAL_OUT1_OPEN_LO] = {.handler = &asdf_arch_out1_open_lo_set,},
|
||||||
|
[PHYSICAL_OUT2_OPEN_LO] = {.handler = &asdf_arch_out2_open_lo_set,},
|
||||||
|
[PHYSICAL_OUT3_OPEN_LO] = {.handler = &asdf_arch_out3_open_lo_set,},
|
||||||
|
[PHYSICAL_LED1] = {.handler = &asdf_arch_led1_set,},
|
||||||
|
[PHYSICAL_LED2] = {.handler = &asdf_arch_led2_set,},
|
||||||
|
[PHYSICAL_LED3] = {.handler = &asdf_arch_led3_set,},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// PROCEDURE: asdf_physical_set
|
// PROCEDURE: asdf_physical_set
|
||||||
@ -81,7 +84,7 @@ static struct {
|
|||||||
//
|
//
|
||||||
void asdf_physical_set(asdf_physical_dev_t physical_out, uint8_t value)
|
void asdf_physical_set(asdf_physical_dev_t physical_out, uint8_t value)
|
||||||
{
|
{
|
||||||
physical_out_set[physical_out](value);
|
physical_device_table[physical_out].handler(value);
|
||||||
physical_device_table[physical_out].shadow = value;
|
physical_device_table[physical_out].shadow = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +107,7 @@ void asdf_physical_set(asdf_physical_dev_t physical_out, uint8_t value)
|
|||||||
void asdf_physical_assert(asdf_physical_dev_t physical_out)
|
void asdf_physical_assert(asdf_physical_dev_t physical_out)
|
||||||
{
|
{
|
||||||
uint8_t value = physical_device_table[physical_out].shadow;
|
uint8_t value = physical_device_table[physical_out].shadow;
|
||||||
physical_out_set[physical_out](value);
|
physical_device_table[physical_out].handler(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PROCEDURE: asdf_physical_toggle
|
// PROCEDURE: asdf_physical_toggle
|
||||||
|
Loading…
Reference in New Issue
Block a user