summaryrefslogtreecommitdiff
path: root/tmk_core/protocol/ps2_io_avr.c
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-10-20 20:07:40 +0100
committerGitHub <noreply@github.com>2021-10-20 20:07:40 +0100
commit84d5198ef9b4106fe61530211b5b5bb1a2fc52c8 (patch)
treebcb35e8dbd2fab837fbe19b2dadd0e5df2d2e39a /tmk_core/protocol/ps2_io_avr.c
parent1fb2a0c74e926806f58fdbec990ca9aa7bb376a9 (diff)
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/ps2_io_avr.c')
-rw-r--r--tmk_core/protocol/ps2_io_avr.c49
1 files changed, 21 insertions, 28 deletions
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 <stdbool.h>
-#include <avr/io.h>
-#include <util/delay.h>
+#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);
}