From 93349ed6e9a36f7af2450e9050ee1461a2d9b384 Mon Sep 17 00:00:00 2001 From: David Fenyes Date: Mon, 16 Mar 2020 12:56:21 -0500 Subject: [PATCH] Add support for "hi-z when low" outputs The apple 1 CLEAR input requires a high-impedance inactive state to avoid conflict with the pin output of the 7404 at D12 (via CR4). So, to cover this condition most generally, this patch changes the adds a Hi-Z when low physical device for each output line, to complement the Hi-Z-when-high open collector emulation. The nomenclature is changed from OUT*_OC (emulated open collector) to OUT*_OPEN_HI and OUT*_OPEN_LO to indicate which condition gets the Hi-Z state. - added the set() functions to the asdf_arch_atmega328p.[ch] files and applied the above nomenclature. - Added the set() functions to the asdf_physical.[ch] files and applied the above nomenclature - Modified the SCREEN_CLEAR device to PHYSICAL_OUT1_OPEN_LO in the apple2 and ascii keymaps. - Changed the RESET from PHYSICAL_OUT1_OC to PHYSICAL_OUT1_OPEN_HI in the apple2 and ascii keymaps. --- firmware/asdf/src/Arch/asdf_arch_atmega328p.c | 83 +++++++++++++++++-- firmware/asdf/src/Arch/asdf_arch_atmega328p.h | 41 ++++++--- .../src/Keymaps/asdf_keymap_defs_apple2.h | 4 +- .../asdf/src/Keymaps/asdf_keymap_defs_ascii.h | 4 +- firmware/asdf/src/asdf_physical.c | 9 +- firmware/asdf/src/asdf_physical.h | 9 +- 6 files changed, 122 insertions(+), 28 deletions(-) diff --git a/firmware/asdf/src/Arch/asdf_arch_atmega328p.c b/firmware/asdf/src/Arch/asdf_arch_atmega328p.c index 9b87545..bf71b36 100644 --- a/firmware/asdf/src/Arch/asdf_arch_atmega328p.c +++ b/firmware/asdf/src/Arch/asdf_arch_atmega328p.c @@ -324,7 +324,7 @@ void asdf_arch_out1_set(uint8_t value) set_bit(&ASDF_OUT1_DDR, ASDF_OUT1_BIT); } -// PROCEDURE: asdf_arch_out1_hi_z_set +// PROCEDURE: asdf_arch_out1_open_hi_set // INPUTS: (uint8_t) value // OUTPUTS: none // @@ -338,7 +338,7 @@ void asdf_arch_out1_set(uint8_t value) // // COMPLEXITY: 2 // -void asdf_arch_out1_hi_z_set(uint8_t value) +void asdf_arch_out1_open_hi_set(uint8_t value) { if (value) { clear_bit(&ASDF_OUT1_DDR, ASDF_OUT1_BIT); @@ -350,6 +350,32 @@ void asdf_arch_out1_hi_z_set(uint8_t value) } } +// PROCEDURE: asdf_arch_out1_open_lo_set +// INPUTS: (uint8_t) value +// OUTPUTS: none +// +// DESCRIPTION: Sets the OUT1 bit to high if value is true, and hi-z if value is false. +// +// SIDE EFFECTS: See above. +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 2 +// +void asdf_arch_out1_open_lo_set(uint8_t value) +{ + if (value) { + set_bit(&ASDF_OUT1_PORT, ASDF_OUT1_BIT); + set_bit(&ASDF_OUT1_DDR, ASDF_OUT1_BIT); + } + else { + clear_bit(&ASDF_OUT1_DDR, ASDF_OUT1_BIT); + clear_bit(&ASDF_OUT1_PORT, ASDF_OUT1_BIT); + } +} + // PROCEDURE: asdf_arch_out2_set // INPUTS: (uint8_t) value // OUTPUTS: none @@ -395,7 +421,7 @@ void asdf_arch_null_output(uint8_t value) (void) value; } -// PROCEDURE: asdf_arch_out2_hi_z_set +// PROCEDURE: asdf_arch_out2_open_hi_set // INPUTS: (uint8_t) value // OUTPUTS: none // @@ -409,7 +435,26 @@ void asdf_arch_null_output(uint8_t value) // // COMPLEXITY: 2 // -void asdf_arch_out2_hi_z_set(uint8_t value) +void asdf_arch_out2_open_hi_set(uint8_t value) +{ + asdf_arch_null_output(value); +} + +// PROCEDURE: asdf_arch_out2_open_lo_set +// INPUTS: (uint8_t) value +// OUTPUTS: none +// +// DESCRIPTION: Sets the OUT2 bit to high if value is true, and hi-z if value is false. +// +// SIDE EFFECTS: See above. +// +// NOTES: Not supported for the ATMega-328 ASCII interface. +// +// SCOPE: public +// +// COMPLEXITY: 2 +// +void asdf_arch_out2_open_lo_set(uint8_t value) { asdf_arch_null_output(value); } @@ -439,7 +484,7 @@ void asdf_arch_out3_set(uint8_t value) set_bit(&ASDF_OUT3_DDR, ASDF_OUT3_BIT); } -// PROCEDURE: asdf_arch_out3_hi_z_set +// PROCEDURE: asdf_arch_out3_open_hi_set // INPUTS: (uint8_t) value // OUTPUTS: none // @@ -453,7 +498,7 @@ void asdf_arch_out3_set(uint8_t value) // // COMPLEXITY: 2 // -void asdf_arch_out3_hi_z_set(uint8_t value) +void asdf_arch_out3_open_hi_set(uint8_t value) { if (value) { clear_bit(&ASDF_OUT3_DDR, ASDF_OUT3_BIT); @@ -465,6 +510,32 @@ void asdf_arch_out3_hi_z_set(uint8_t value) } } +// PROCEDURE: asdf_arch_out3_open_lo_set +// INPUTS: (uint8_t) value +// OUTPUTS: none +// +// DESCRIPTION: Sets the OUT3 bit to high if value is true, and hi-z if value is false. +// +// SIDE EFFECTS: See above. +// +// NOTES: +// +// SCOPE: public +// +// COMPLEXITY: 2 +// +void asdf_arch_out3_open_lo_set(uint8_t value) +{ + if (value) { + set_bit(&ASDF_OUT3_PORT, ASDF_OUT3_BIT); + set_bit(&ASDF_OUT3_DDR, ASDF_OUT3_BIT); + } + else { + clear_bit(&ASDF_OUT3_DDR, ASDF_OUT3_BIT); + clear_bit(&ASDF_OUT3_PORT, ASDF_OUT3_BIT); + } +} + // PROCEDURE: asdf_arch_init_strobe // INPUTS: none // OUTPUTS: none diff --git a/firmware/asdf/src/Arch/asdf_arch_atmega328p.h b/firmware/asdf/src/Arch/asdf_arch_atmega328p.h index 756f45e..e9b3c77 100644 --- a/firmware/asdf/src/Arch/asdf_arch_atmega328p.h +++ b/firmware/asdf/src/Arch/asdf_arch_atmega328p.h @@ -279,11 +279,17 @@ void asdf_arch_led3_set(uint8_t value); // DESCRIPTION: Sets the OUT1 bit if value is true, and clear OUT1 if value is false. void asdf_arch_out1_set(uint8_t value); -// PROCEDURE: asdf_arch_out1_hi_z_set +// PROCEDURE: asdf_arch_out1_open_hi_set // INPUTS: (uint8_t) value // OUTPUTS: none // DESCRIPTION: Sets the OUT1 bit to hi-z if value is true, and low if value is false. -void asdf_arch_out1_hi_z_set(uint8_t value); +void asdf_arch_out1_open_hi_set(uint8_t value); + +// PROCEDURE: asdf_arch_out1_open_lo_set +// INPUTS: (uint8_t) value +// OUTPUTS: none +// DESCRIPTION: Sets the OUT1 bit to hi-z if value is true, and low if value is false. +void asdf_arch_out1_open_lo_set(uint8_t value); // PROCEDURE: asdf_arch_out2_set // INPUTS: (uint8_t) value @@ -291,25 +297,36 @@ void asdf_arch_out1_hi_z_set(uint8_t value); // DESCRIPTION: Sets the OUT2 bit if value is true, and clear OUT2 if value is false. void asdf_arch_out2_set(uint8_t value); +// PROCEDURE: asdf_arch_out2_open_hi_set +// INPUTS: (uint8_t) value +// OUTPUTS: none +// DESCRIPTION: Sets the OUT2 bit to hi-z if value is true, and low if value is false. +// NOTES: Not supported for the ATMega-328 ASCII interface. +void asdf_arch_out2_open_hi_set(uint8_t value); + +// PROCEDURE: asdf_arch_out2_open_lo_set +// INPUTS: (uint8_t) value +// OUTPUTS: none +// DESCRIPTION: Sets the OUT2 bit to high if value is true, and hi-z if value is false. +void asdf_arch_out2_open_lo_set(uint8_t value); + // PROCEDURE: asdf_arch_out3_set // INPUTS: (uint8_t) value // OUTPUTS: none // DESCRIPTION: Sets the OUT3 bit if value is true, and clear OUT3 if value is false. void asdf_arch_out3_set(uint8_t value); -// PROCEDURE: asdf_arch_out2_hi_z_set -// INPUTS: (uint8_t) value -// OUTPUTS: none -// DESCRIPTION: Sets the OUT2 bit to hi-z if value is true, and low if value is false. -// NOTES: Not supported for the ATMega-328 ASCII interface. -void asdf_arch_out2_hi_z_set(uint8_t value); - - -// PROCEDURE: asdf_arch_out3_hi_z_set +// PROCEDURE: asdf_arch_out3_open_hi_set // INPUTS: (uint8_t) value // OUTPUTS: none // DESCRIPTION: Sets the OUT3 bit to hi-z if value is true, and low if value is false. -void asdf_arch_out3_hi_z_set(uint8_t value); +void asdf_arch_out3_open_hi_set(uint8_t value); + +// PROCEDURE: asdf_arch_out3_open_lo_set +// INPUTS: (uint8_t) value +// OUTPUTS: none +// DESCRIPTION: Sets the OUT3 bit to hi-z if value is true, and low if value is false. +void asdf_arch_out3_open_lo_set(uint8_t value); // PROCEDURE: asdf_arch_read_row // INPUTS: (uint8_t) row: the row number to be scanned diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h index 73350ee..af3e207 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_apple2.h @@ -49,12 +49,12 @@ #define ACTION_RESET ACTION_VOUT1 #define VIRTUAL_RESET VOUT1 -#define RESET_OUTPUT PHYSICAL_OUT3_OC +#define RESET_OUTPUT PHYSICAL_OUT3_OPEN_HI #define RESET_ACTIVE_VALUE 0 #define ACTION_CLEAR ACTION_VOUT2 #define VIRTUAL_CLR_SCR VOUT2 -#define CLR_SCR_OUTPUT PHYSICAL_OUT1 +#define CLR_SCR_OUTPUT PHYSICAL_OUT1_OPEN_LO #define CLR_SCR_ACTIVE_VALUE 1 #define VIRTUAL_POWER_LED VLED1 diff --git a/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h b/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h index 43959b6..e697aa6 100644 --- a/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h +++ b/firmware/asdf/src/Keymaps/asdf_keymap_defs_ascii.h @@ -40,11 +40,11 @@ #define ACTION_BREAK ACTION_NOTHING #define VIRTUAL_RESET VOUT1 -#define RESET_OUTPUT PHYSICAL_OUT3_OC +#define RESET_OUTPUT PHYSICAL_OUT3_OPEN_HI #define RESET_ACTIVE_VALUE 0 #define VIRTUAL_CLR_SCR VOUT2 -#define CLR_SCR_OUT PHYSICAL_OUT1 +#define CLR_SCR_OUT PHYSICAL_OUT1_OPEN_LO #define CLR_SCR_ACTIVE_VALUE 1 #define VIRTUAL_POWER_LED VLED1 diff --git a/firmware/asdf/src/asdf_physical.c b/firmware/asdf/src/asdf_physical.c index d7aae8a..7ca0967 100644 --- a/firmware/asdf/src/asdf_physical.c +++ b/firmware/asdf/src/asdf_physical.c @@ -37,9 +37,12 @@ static void (*const physical_out_set[])(uint8_t) = { [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_OUT1_OPEN_HI] = &asdf_arch_out1_open_hi_set, // + [PHYSICAL_OUT2_OPEN_HI] = &asdf_arch_out2_open_hi_set, // + [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 // diff --git a/firmware/asdf/src/asdf_physical.h b/firmware/asdf/src/asdf_physical.h index e5c066f..d9066c9 100644 --- a/firmware/asdf/src/asdf_physical.h +++ b/firmware/asdf/src/asdf_physical.h @@ -34,11 +34,14 @@ typedef enum { PHYSICAL_NO_OUT = 0, PHYSICAL_OUT1, - PHYSICAL_OUT1_OC, + PHYSICAL_OUT1_OPEN_HI, + PHYSICAL_OUT1_OPEN_LO, PHYSICAL_OUT2, - PHYSICAL_OUT2_OC, + PHYSICAL_OUT2_OPEN_HI, + PHYSICAL_OUT2_OPEN_LO, PHYSICAL_OUT3, - PHYSICAL_OUT3_OC, + PHYSICAL_OUT3_OPEN_HI, + PHYSICAL_OUT3_OPEN_LO, PHYSICAL_LED1, PHYSICAL_LED2, PHYSICAL_LED3,