From 84d5198ef9b4106fe61530211b5b5bb1a2fc52c8 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Wed, 20 Oct 2021 20:07:40 +0100 Subject: 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 --- tmk_core/protocol/ps2_io_avr.c | 49 ++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 28 deletions(-) (limited to 'tmk_core/protocol/ps2_io_avr.c') diff --git a/tmk_core/protocol/ps2_io_avr.c b/tmk_core/protocol/ps2_io_avr.c index a9ac5d338d..7c826fbf1a 100644 --- a/tmk_core/protocol/ps2_io_avr.c +++ b/tmk_core/protocol/ps2_io_avr.c @@ -1,14 +1,15 @@ #include -#include -#include +#include "ps2_io.h" +#include "gpio.h" +#include "wait.h" /* Check port settings for clock and data line */ -#if !(defined(PS2_CLOCK_PORT) && defined(PS2_CLOCK_PIN) && defined(PS2_CLOCK_DDR) && defined(PS2_CLOCK_BIT)) -# error "PS/2 clock port setting is required in config.h" +#if !(defined(PS2_CLOCK_PIN)) +# error "PS/2 clock setting is required in config.h" #endif -#if !(defined(PS2_DATA_PORT) && defined(PS2_DATA_PIN) && defined(PS2_DATA_DDR) && defined(PS2_DATA_BIT)) -# error "PS/2 data port setting is required in config.h" +#if !(defined(PS2_DATA_PIN)) +# error "PS/2 data setting is required in config.h" #endif /* @@ -17,21 +18,17 @@ void clock_init(void) {} void clock_lo(void) { - PS2_CLOCK_PORT &= ~(1 << PS2_CLOCK_BIT); - PS2_CLOCK_DDR |= (1 << PS2_CLOCK_BIT); + // Transition from input with pull-up to output low via Hi-Z instead of output high + writePinLow(PS2_CLOCK_PIN); + setPinOutput(PS2_CLOCK_PIN); } -void clock_hi(void) { - /* input with pull up */ - PS2_CLOCK_DDR &= ~(1 << PS2_CLOCK_BIT); - PS2_CLOCK_PORT |= (1 << PS2_CLOCK_BIT); -} +void clock_hi(void) { setPinInputHigh(PS2_CLOCK_PIN); } bool clock_in(void) { - PS2_CLOCK_DDR &= ~(1 << PS2_CLOCK_BIT); - PS2_CLOCK_PORT |= (1 << PS2_CLOCK_BIT); - _delay_us(1); - return PS2_CLOCK_PIN & (1 << PS2_CLOCK_BIT); + setPinInputHigh(PS2_CLOCK_PIN); + wait_us(1); + return readPin(PS2_CLOCK_PIN); } /* @@ -40,19 +37,15 @@ bool clock_in(void) { void data_init(void) {} void data_lo(void) { - PS2_DATA_PORT &= ~(1 << PS2_DATA_BIT); - PS2_DATA_DDR |= (1 << PS2_DATA_BIT); + // Transition from input with pull-up to output low via Hi-Z instead of output high + writePinLow(PS2_DATA_PIN); + setPinOutput(PS2_DATA_PIN); } -void data_hi(void) { - /* input with pull up */ - PS2_DATA_DDR &= ~(1 << PS2_DATA_BIT); - PS2_DATA_PORT |= (1 << PS2_DATA_BIT); -} +void data_hi(void) { setPinInputHigh(PS2_DATA_PIN); } bool data_in(void) { - PS2_DATA_DDR &= ~(1 << PS2_DATA_BIT); - PS2_DATA_PORT |= (1 << PS2_DATA_BIT); - _delay_us(1); - return PS2_DATA_PIN & (1 << PS2_DATA_BIT); + setPinInputHigh(PS2_DATA_PIN); + wait_us(1); + return readPin(PS2_DATA_PIN); } -- cgit v1.2.3