diff options
| author | Joel Challis <git@zvecr.com> | 2021-10-20 20:07:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-20 20:07:40 +0100 |
| commit | 84d5198ef9b4106fe61530211b5b5bb1a2fc52c8 (patch) | |
| tree | bcb35e8dbd2fab837fbe19b2dadd0e5df2d2e39a /tmk_core/protocol | |
| parent | 1fb2a0c74e926806f58fdbec990ca9aa7bb376a9 (diff) | |
| download | qmk_firmware-84d5198ef9b4106fe61530211b5b5bb1a2fc52c8.tar.gz qmk_firmware-84d5198ef9b4106fe61530211b5b5bb1a2fc52c8.zip | |
Align PS/2 GPIO defines (#14745)
* Align PS/2 GPIO
* Align PS/2 GPIO
* refactor more keyboards
* Remove more defines
* Put back avr/chibios split
* format
Diffstat (limited to 'tmk_core/protocol')
| -rw-r--r-- | tmk_core/protocol/ps2_interrupt.c | 18 | ||||
| -rw-r--r-- | tmk_core/protocol/ps2_io_avr.c | 49 | ||||
| -rw-r--r-- | tmk_core/protocol/ps2_io_chibios.c | 28 | ||||
| -rw-r--r-- | tmk_core/protocol/ps2_usart.c | 13 |
4 files changed, 57 insertions, 51 deletions
diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 780040d15..70debd02f 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c | |||
| @@ -73,17 +73,17 @@ static inline void pbuf_clear(void); | |||
| 73 | void ps2_interrupt_service_routine(void); | 73 | void ps2_interrupt_service_routine(void); |
| 74 | void palCallback(void *arg) { ps2_interrupt_service_routine(); } | 74 | void palCallback(void *arg) { ps2_interrupt_service_routine(); } |
| 75 | 75 | ||
| 76 | # define PS2_INT_INIT() \ | 76 | # define PS2_INT_INIT() \ |
| 77 | { palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); } \ | 77 | { palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_INPUT); } \ |
| 78 | while (0) | 78 | while (0) |
| 79 | # define PS2_INT_ON() \ | 79 | # define PS2_INT_ON() \ |
| 80 | { \ | 80 | { \ |
| 81 | palEnableLineEvent(PS2_CLOCK, PAL_EVENT_MODE_FALLING_EDGE); \ | 81 | palEnableLineEvent(PS2_CLOCK_PIN, PAL_EVENT_MODE_FALLING_EDGE); \ |
| 82 | palSetLineCallback(PS2_CLOCK, palCallback, NULL); \ | 82 | palSetLineCallback(PS2_CLOCK_PIN, palCallback, NULL); \ |
| 83 | } \ | 83 | } \ |
| 84 | while (0) | 84 | while (0) |
| 85 | # define PS2_INT_OFF() \ | 85 | # define PS2_INT_OFF() \ |
| 86 | { palDisableLineEvent(PS2_CLOCK); } \ | 86 | { palDisableLineEvent(PS2_CLOCK_PIN); } \ |
| 87 | while (0) | 87 | while (0) |
| 88 | #endif // PROTOCOL_CHIBIOS | 88 | #endif // PROTOCOL_CHIBIOS |
| 89 | 89 | ||
diff --git a/tmk_core/protocol/ps2_io_avr.c b/tmk_core/protocol/ps2_io_avr.c index a9ac5d338..7c826fbf1 100644 --- a/tmk_core/protocol/ps2_io_avr.c +++ b/tmk_core/protocol/ps2_io_avr.c | |||
| @@ -1,14 +1,15 @@ | |||
| 1 | #include <stdbool.h> | 1 | #include <stdbool.h> |
| 2 | #include <avr/io.h> | 2 | #include "ps2_io.h" |
| 3 | #include <util/delay.h> | 3 | #include "gpio.h" |
| 4 | #include "wait.h" | ||
| 4 | 5 | ||
| 5 | /* Check port settings for clock and data line */ | 6 | /* Check port settings for clock and data line */ |
| 6 | #if !(defined(PS2_CLOCK_PORT) && defined(PS2_CLOCK_PIN) && defined(PS2_CLOCK_DDR) && defined(PS2_CLOCK_BIT)) | 7 | #if !(defined(PS2_CLOCK_PIN)) |
| 7 | # error "PS/2 clock port setting is required in config.h" | 8 | # error "PS/2 clock setting is required in config.h" |
| 8 | #endif | 9 | #endif |
| 9 | 10 | ||
| 10 | #if !(defined(PS2_DATA_PORT) && defined(PS2_DATA_PIN) && defined(PS2_DATA_DDR) && defined(PS2_DATA_BIT)) | 11 | #if !(defined(PS2_DATA_PIN)) |
| 11 | # error "PS/2 data port setting is required in config.h" | 12 | # error "PS/2 data setting is required in config.h" |
| 12 | #endif | 13 | #endif |
| 13 | 14 | ||
| 14 | /* | 15 | /* |
| @@ -17,21 +18,17 @@ | |||
| 17 | void clock_init(void) {} | 18 | void clock_init(void) {} |
| 18 | 19 | ||
| 19 | void clock_lo(void) { | 20 | void clock_lo(void) { |
| 20 | PS2_CLOCK_PORT &= ~(1 << PS2_CLOCK_BIT); | 21 | // Transition from input with pull-up to output low via Hi-Z instead of output high |
| 21 | PS2_CLOCK_DDR |= (1 << PS2_CLOCK_BIT); | 22 | writePinLow(PS2_CLOCK_PIN); |
| 23 | setPinOutput(PS2_CLOCK_PIN); | ||
| 22 | } | 24 | } |
| 23 | 25 | ||
| 24 | void clock_hi(void) { | 26 | void clock_hi(void) { setPinInputHigh(PS2_CLOCK_PIN); } |
| 25 | /* input with pull up */ | ||
| 26 | PS2_CLOCK_DDR &= ~(1 << PS2_CLOCK_BIT); | ||
| 27 | PS2_CLOCK_PORT |= (1 << PS2_CLOCK_BIT); | ||
| 28 | } | ||
| 29 | 27 | ||
| 30 | bool clock_in(void) { | 28 | bool clock_in(void) { |
| 31 | PS2_CLOCK_DDR &= ~(1 << PS2_CLOCK_BIT); | 29 | setPinInputHigh(PS2_CLOCK_PIN); |
| 32 | PS2_CLOCK_PORT |= (1 << PS2_CLOCK_BIT); | 30 | wait_us(1); |
| 33 | _delay_us(1); | 31 | return readPin(PS2_CLOCK_PIN); |
| 34 | return PS2_CLOCK_PIN & (1 << PS2_CLOCK_BIT); | ||
| 35 | } | 32 | } |
| 36 | 33 | ||
| 37 | /* | 34 | /* |
| @@ -40,19 +37,15 @@ bool clock_in(void) { | |||
| 40 | void data_init(void) {} | 37 | void data_init(void) {} |
| 41 | 38 | ||
| 42 | void data_lo(void) { | 39 | void data_lo(void) { |
| 43 | PS2_DATA_PORT &= ~(1 << PS2_DATA_BIT); | 40 | // Transition from input with pull-up to output low via Hi-Z instead of output high |
| 44 | PS2_DATA_DDR |= (1 << PS2_DATA_BIT); | 41 | writePinLow(PS2_DATA_PIN); |
| 42 | setPinOutput(PS2_DATA_PIN); | ||
| 45 | } | 43 | } |
| 46 | 44 | ||
| 47 | void data_hi(void) { | 45 | void data_hi(void) { setPinInputHigh(PS2_DATA_PIN); } |
| 48 | /* input with pull up */ | ||
| 49 | PS2_DATA_DDR &= ~(1 << PS2_DATA_BIT); | ||
| 50 | PS2_DATA_PORT |= (1 << PS2_DATA_BIT); | ||
| 51 | } | ||
| 52 | 46 | ||
| 53 | bool data_in(void) { | 47 | bool data_in(void) { |
| 54 | PS2_DATA_DDR &= ~(1 << PS2_DATA_BIT); | 48 | setPinInputHigh(PS2_DATA_PIN); |
| 55 | PS2_DATA_PORT |= (1 << PS2_DATA_BIT); | 49 | wait_us(1); |
| 56 | _delay_us(1); | 50 | return readPin(PS2_DATA_PIN); |
| 57 | return PS2_DATA_PIN & (1 << PS2_DATA_BIT); | ||
| 58 | } | 51 | } |
diff --git a/tmk_core/protocol/ps2_io_chibios.c b/tmk_core/protocol/ps2_io_chibios.c index b672bd1f4..906d85d84 100644 --- a/tmk_core/protocol/ps2_io_chibios.c +++ b/tmk_core/protocol/ps2_io_chibios.c | |||
| @@ -6,11 +6,11 @@ | |||
| 6 | #include "hal.h" | 6 | #include "hal.h" |
| 7 | 7 | ||
| 8 | /* Check port settings for clock and data line */ | 8 | /* Check port settings for clock and data line */ |
| 9 | #if !(defined(PS2_CLOCK)) | 9 | #if !(defined(PS2_CLOCK_PIN)) |
| 10 | # error "PS/2 clock setting is required in config.h" | 10 | # error "PS/2 clock setting is required in config.h" |
| 11 | #endif | 11 | #endif |
| 12 | 12 | ||
| 13 | #if !(defined(PS2_DATA)) | 13 | #if !(defined(PS2_DATA_PIN)) |
| 14 | # error "PS/2 data setting is required in config.h" | 14 | # error "PS/2 data setting is required in config.h" |
| 15 | #endif | 15 | #endif |
| 16 | 16 | ||
| @@ -20,18 +20,18 @@ | |||
| 20 | void clock_init(void) {} | 20 | void clock_init(void) {} |
| 21 | 21 | ||
| 22 | void clock_lo(void) { | 22 | void clock_lo(void) { |
| 23 | palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); | 23 | palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_OUTPUT_OPENDRAIN); |
| 24 | palWriteLine(PS2_CLOCK, PAL_LOW); | 24 | palWriteLine(PS2_CLOCK_PIN, PAL_LOW); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | void clock_hi(void) { | 27 | void clock_hi(void) { |
| 28 | palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); | 28 | palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_OUTPUT_OPENDRAIN); |
| 29 | palWriteLine(PS2_CLOCK, PAL_HIGH); | 29 | palWriteLine(PS2_CLOCK_PIN, PAL_HIGH); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | bool clock_in(void) { | 32 | bool clock_in(void) { |
| 33 | palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); | 33 | palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_INPUT); |
| 34 | return palReadLine(PS2_CLOCK); | 34 | return palReadLine(PS2_CLOCK_PIN); |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | /* | 37 | /* |
| @@ -40,16 +40,16 @@ bool clock_in(void) { | |||
| 40 | void data_init(void) {} | 40 | void data_init(void) {} |
| 41 | 41 | ||
| 42 | void data_lo(void) { | 42 | void data_lo(void) { |
| 43 | palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); | 43 | palSetLineMode(PS2_DATA_PIN, PAL_MODE_OUTPUT_OPENDRAIN); |
| 44 | palWriteLine(PS2_DATA, PAL_LOW); | 44 | palWriteLine(PS2_DATA_PIN, PAL_LOW); |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | void data_hi(void) { | 47 | void data_hi(void) { |
| 48 | palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); | 48 | palSetLineMode(PS2_DATA_PIN, PAL_MODE_OUTPUT_OPENDRAIN); |
| 49 | palWriteLine(PS2_DATA, PAL_HIGH); | 49 | palWriteLine(PS2_DATA_PIN, PAL_HIGH); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | bool data_in(void) { | 52 | bool data_in(void) { |
| 53 | palSetLineMode(PS2_DATA, PAL_MODE_INPUT); | 53 | palSetLineMode(PS2_DATA_PIN, PAL_MODE_INPUT); |
| 54 | return palReadLine(PS2_DATA); | 54 | return palReadLine(PS2_DATA_PIN); |
| 55 | } | 55 | } |
diff --git a/tmk_core/protocol/ps2_usart.c b/tmk_core/protocol/ps2_usart.c index 6a66dc4a1..5f7008369 100644 --- a/tmk_core/protocol/ps2_usart.c +++ b/tmk_core/protocol/ps2_usart.c | |||
| @@ -46,6 +46,19 @@ POSSIBILITY OF SUCH DAMAGE. | |||
| 46 | #include "ps2_io.h" | 46 | #include "ps2_io.h" |
| 47 | #include "print.h" | 47 | #include "print.h" |
| 48 | 48 | ||
| 49 | #ifndef PS2_CLOCK_DDR | ||
| 50 | # define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) | ||
| 51 | #endif | ||
| 52 | #ifndef PS2_CLOCK_BIT | ||
| 53 | # define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) | ||
| 54 | #endif | ||
| 55 | #ifndef PS2_DATA_DDR | ||
| 56 | # define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) | ||
| 57 | #endif | ||
| 58 | #ifndef PS2_DATA_BIT | ||
| 59 | # define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) | ||
| 60 | #endif | ||
| 61 | |||
| 49 | #define WAIT(stat, us, err) \ | 62 | #define WAIT(stat, us, err) \ |
| 50 | do { \ | 63 | do { \ |
| 51 | if (!wait_##stat(us)) { \ | 64 | if (!wait_##stat(us)) { \ |
