From f7a5f967054ff47861c84291b34a69c67bcf41c9 Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 7 Oct 2021 22:56:34 +0100 Subject: [PATCH 1/6] Align PS/2 GPIO --- docs/feature_ps2_mouse.md | 39 +++++-------- docs/ja/feature_ps2_mouse.md | 36 ++++-------- .../evyd13/gh80_3700/keymaps/ps2/config.h | 15 +++-- tmk_core/protocol.mk | 6 +- tmk_core/protocol/ps2_io.c | 52 +++++++++++++++++ tmk_core/protocol/ps2_io_avr.c | 58 ------------------- tmk_core/protocol/ps2_io_chibios.c | 55 ------------------ 7 files changed, 87 insertions(+), 174 deletions(-) create mode 100644 tmk_core/protocol/ps2_io.c delete mode 100644 tmk_core/protocol/ps2_io_avr.c delete mode 100644 tmk_core/protocol/ps2_io_chibios.c diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index 433a47fa9b89..a1ea1b565857 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -39,14 +39,8 @@ In your keyboard config.h: ```c #ifdef PS2_USE_BUSYWAIT -# define PS2_CLOCK_PORT PORTD -# define PS2_CLOCK_PIN PIND -# define PS2_CLOCK_DDR DDRD -# define PS2_CLOCK_BIT 1 -# define PS2_DATA_PORT PORTD -# define PS2_DATA_PIN PIND -# define PS2_DATA_DDR DDRD -# define PS2_DATA_BIT 2 +# define PS2_CLOCK_PIN D1 +# define PS2_DATA_PIN D2 #endif ``` @@ -65,14 +59,8 @@ In your keyboard config.h: ```c #ifdef PS2_USE_INT -#define PS2_CLOCK_PORT PORTD -#define PS2_CLOCK_PIN PIND -#define PS2_CLOCK_DDR DDRD -#define PS2_CLOCK_BIT 2 -#define PS2_DATA_PORT PORTD -#define PS2_DATA_PIN PIND -#define PS2_DATA_DDR DDRD -#define PS2_DATA_BIT 5 +#define PS2_CLOCK_PIN D2 +#define PS2_DATA_PIN D5 #define PS2_INT_INIT() do { \ EICRA |= ((1< +#include "gpio.h" +#include "ps2_io.h" + +/* Check port settings for clock and data line */ +#if !(defined(PS2_CLOCK_PIN)) +# error "PS/2 clock setting is required in config.h" +#endif + +#if !(defined(PS2_DATA_PIN)) +# error "PS/2 data setting is required in config.h" +#endif + +/* + * Clock + */ +void clock_init(void) {} + +void clock_lo(void) { + setPinOutput(PS2_CLOCK_PIN); + writePinLow(PS2_CLOCK_PIN); +} + +void clock_hi(void) { + setPinOutput(PS2_CLOCK_PIN); + writePinHigh(PS2_CLOCK_PIN); +} + +bool clock_in(void) { + setPinInputHigh(PS2_CLOCK_PIN); + return readPin(PS2_CLOCK_PIN); +} + +/* + * Data + */ +void data_init(void) {} + +void data_lo(void) { + setPinOutput(PS2_DATA_PIN); + writePinLow(PS2_DATA_PIN); +} + +void data_hi(void) { + setPinOutput(PS2_DATA_PIN); + writePinHigh(PS2_DATA_PIN); +} + +bool data_in(void) { + setPinInputHigh(PS2_DATA_PIN); + return readPin(PS2_DATA_PIN); +} diff --git a/tmk_core/protocol/ps2_io_avr.c b/tmk_core/protocol/ps2_io_avr.c deleted file mode 100644 index a9ac5d338d9b..000000000000 --- a/tmk_core/protocol/ps2_io_avr.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#include -#include - -/* 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" -#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" -#endif - -/* - * Clock - */ -void clock_init(void) {} - -void clock_lo(void) { - PS2_CLOCK_PORT &= ~(1 << PS2_CLOCK_BIT); - PS2_CLOCK_DDR |= (1 << PS2_CLOCK_BIT); -} - -void clock_hi(void) { - /* input with pull up */ - PS2_CLOCK_DDR &= ~(1 << PS2_CLOCK_BIT); - PS2_CLOCK_PORT |= (1 << PS2_CLOCK_BIT); -} - -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); -} - -/* - * Data - */ -void data_init(void) {} - -void data_lo(void) { - PS2_DATA_PORT &= ~(1 << PS2_DATA_BIT); - PS2_DATA_DDR |= (1 << PS2_DATA_BIT); -} - -void data_hi(void) { - /* input with pull up */ - PS2_DATA_DDR &= ~(1 << PS2_DATA_BIT); - PS2_DATA_PORT |= (1 << PS2_DATA_BIT); -} - -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); -} diff --git a/tmk_core/protocol/ps2_io_chibios.c b/tmk_core/protocol/ps2_io_chibios.c deleted file mode 100644 index b672bd1f47fa..000000000000 --- a/tmk_core/protocol/ps2_io_chibios.c +++ /dev/null @@ -1,55 +0,0 @@ -#include -#include "ps2_io.h" - -// chibiOS headers -#include "ch.h" -#include "hal.h" - -/* Check port settings for clock and data line */ -#if !(defined(PS2_CLOCK)) -# error "PS/2 clock setting is required in config.h" -#endif - -#if !(defined(PS2_DATA)) -# error "PS/2 data setting is required in config.h" -#endif - -/* - * Clock - */ -void clock_init(void) {} - -void clock_lo(void) { - palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_CLOCK, PAL_LOW); -} - -void clock_hi(void) { - palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_CLOCK, PAL_HIGH); -} - -bool clock_in(void) { - palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); - return palReadLine(PS2_CLOCK); -} - -/* - * Data - */ -void data_init(void) {} - -void data_lo(void) { - palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_DATA, PAL_LOW); -} - -void data_hi(void) { - palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_DATA, PAL_HIGH); -} - -bool data_in(void) { - palSetLineMode(PS2_DATA, PAL_MODE_INPUT); - return palReadLine(PS2_DATA); -} From 34feb72a14ff0afbbb5626e2589ef54849b1ecaa Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 7 Oct 2021 23:00:51 +0100 Subject: [PATCH 2/6] Align PS/2 GPIO --- tmk_core/protocol/ps2_interrupt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 780040d1526c..05132d775a27 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -74,16 +74,16 @@ void ps2_interrupt_service_routine(void); void palCallback(void *arg) { ps2_interrupt_service_routine(); } # define PS2_INT_INIT() \ - { palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); } \ + { palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_INPUT); } \ while (0) # define PS2_INT_ON() \ { \ - palEnableLineEvent(PS2_CLOCK, PAL_EVENT_MODE_FALLING_EDGE); \ - palSetLineCallback(PS2_CLOCK, palCallback, NULL); \ + palEnableLineEvent(PS2_CLOCK_PIN, PAL_EVENT_MODE_FALLING_EDGE); \ + palSetLineCallback(PS2_CLOCK_PIN, palCallback, NULL); \ } \ while (0) # define PS2_INT_OFF() \ - { palDisableLineEvent(PS2_CLOCK); } \ + { palDisableLineEvent(PS2_CLOCK_PIN); } \ while (0) #endif // PROTOCOL_CHIBIOS From 1864afeb9dfd26c9aae07f7e5f768825947970fe Mon Sep 17 00:00:00 2001 From: zvecr Date: Thu, 7 Oct 2021 23:07:55 +0100 Subject: [PATCH 3/6] refactor more keyboards --- keyboards/converter/ibm_terminal/config.h | 38 ++++++------------- .../handwired/108key_trackpoint/config.h | 15 ++++---- keyboards/handwired/promethium/config.h | 35 ++++++----------- keyboards/handwired/trackpoint/config.h | 15 ++++---- keyboards/kapcave/paladin64/config.h | 25 +++++------- 5 files changed, 45 insertions(+), 83 deletions(-) diff --git a/keyboards/converter/ibm_terminal/config.h b/keyboards/converter/ibm_terminal/config.h index 6895f08e7ae9..4614345cbf25 100644 --- a/keyboards/converter/ibm_terminal/config.h +++ b/keyboards/converter/ibm_terminal/config.h @@ -45,15 +45,13 @@ along with this program. If not, see . */ #ifdef PS2_USE_USART /* XCK for clock line */ -#define PS2_CLOCK_PORT PORTD -#define PS2_CLOCK_PIN PIND -#define PS2_CLOCK_DDR DDRD -#define PS2_CLOCK_BIT 5 -/* RXD for data line */ -#define PS2_DATA_PORT PORTD -#define PS2_DATA_PIN PIND -#define PS2_DATA_DDR DDRD -#define PS2_DATA_BIT 2 +#define PS2_CLOCK_PIN D5 +#define PS2_DATA_PIN D2 + +#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) +#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) +#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) +#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ @@ -93,15 +91,8 @@ along with this program. If not, see . */ #ifdef PS2_USE_INT /* uses INT1 for clock line(ATMega32U4) */ -#define PS2_CLOCK_PORT PORTD -#define PS2_CLOCK_PIN PIND -#define PS2_CLOCK_DDR DDRD -#define PS2_CLOCK_BIT 1 - -#define PS2_DATA_PORT PORTD -#define PS2_DATA_PIN PIND -#define PS2_DATA_DDR DDRD -#define PS2_DATA_BIT 0 +#define PS2_CLOCK_PIN D1 +#define PS2_DATA_PIN D0 #define PS2_INT_INIT() do { \ EICRA |= ((1<. * PS/2 Busywait configuration */ #ifdef PS2_USE_BUSYWAIT -#define PS2_CLOCK_PORT PORTD -#define PS2_CLOCK_PIN PIND -#define PS2_CLOCK_DDR DDRD -#define PS2_CLOCK_BIT 1 - -#define PS2_DATA_PORT PORTD -#define PS2_DATA_PIN PIND -#define PS2_DATA_DDR DDRD -#define PS2_DATA_BIT 0 +#define PS2_CLOCK_PIN D1 +#define PS2_DATA_PIN D0 #endif diff --git a/keyboards/handwired/108key_trackpoint/config.h b/keyboards/handwired/108key_trackpoint/config.h index b1ac790d7639..aaf2df753844 100644 --- a/keyboards/handwired/108key_trackpoint/config.h +++ b/keyboards/handwired/108key_trackpoint/config.h @@ -12,14 +12,13 @@ #define MATRIX_COLS 23 #ifdef PS2_USE_USART - #define PS2_CLOCK_PORT PORTD - #define PS2_CLOCK_PIN PIND - #define PS2_CLOCK_DDR DDRD - #define PS2_CLOCK_BIT 5 - #define PS2_DATA_PORT PORTD - #define PS2_DATA_PIN PIND - #define PS2_DATA_DDR DDRD - #define PS2_DATA_BIT 2 +#define PS2_CLOCK_PIN D5 +#define PS2_DATA_PIN D2 + +#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) +#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) +#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) +#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ diff --git a/keyboards/handwired/promethium/config.h b/keyboards/handwired/promethium/config.h index b146767d65de..8bc4362a26fe 100644 --- a/keyboards/handwired/promethium/config.h +++ b/keyboards/handwired/promethium/config.h @@ -224,27 +224,15 @@ enum led_sequence { /* PS/2 mouse */ #ifdef PS2_USE_BUSYWAIT -# define PS2_CLOCK_PORT PORTD -# define PS2_CLOCK_PIN PIND -# define PS2_CLOCK_DDR DDRD -# define PS2_CLOCK_BIT 3 -# define PS2_DATA_PORT PORTD -# define PS2_DATA_PIN PIND -# define PS2_DATA_DDR DDRD -# define PS2_DATA_BIT 2 +# define PS2_CLOCK_PIN D3 +# define PS2_DATA_PIN D2 #endif /* PS/2 mouse interrupt version */ #ifdef PS2_USE_INT /* uses INT1 for clock line(ATMega32U4) */ -# define PS2_CLOCK_PORT PORTD -# define PS2_CLOCK_PIN PIND -# define PS2_CLOCK_DDR DDRD -# define PS2_CLOCK_BIT 3 -# define PS2_DATA_PORT PORTD -# define PS2_DATA_PIN PIND -# define PS2_DATA_DDR DDRD -# define PS2_DATA_BIT 2 +# define PS2_CLOCK_PIN D3 +# define PS2_DATA_PIN D2 # define PS2_INT_INIT() \ do { \ @@ -264,14 +252,13 @@ enum led_sequence { /* PS/2 mouse USART version */ #ifdef PS2_USE_USART /* XCK for clock line and RXD for data line */ -# define PS2_CLOCK_PORT PORTD -# define PS2_CLOCK_PIN PIND -# define PS2_CLOCK_DDR DDRD -# define PS2_CLOCK_BIT 5 -# define PS2_DATA_PORT PORTD -# define PS2_DATA_PIN PIND -# define PS2_DATA_DDR DDRD -# define PS2_DATA_BIT 2 +#define PS2_CLOCK_PIN D5 +#define PS2_DATA_PIN D2 + +#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) +#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) +#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) +#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ diff --git a/keyboards/handwired/trackpoint/config.h b/keyboards/handwired/trackpoint/config.h index 1429136f403d..0cd6f9c78668 100644 --- a/keyboards/handwired/trackpoint/config.h +++ b/keyboards/handwired/trackpoint/config.h @@ -12,14 +12,13 @@ #define MATRIX_COLS 3 #ifdef PS2_USE_USART - #define PS2_CLOCK_PORT PORTD - #define PS2_CLOCK_PIN PIND - #define PS2_CLOCK_DDR DDRD - #define PS2_CLOCK_BIT 5 - #define PS2_DATA_PORT PORTD - #define PS2_DATA_PIN PIND - #define PS2_DATA_DDR DDRD - #define PS2_DATA_BIT 2 +#define PS2_CLOCK_PIN D5 +#define PS2_DATA_PIN D2 + +#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) +#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) +#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) +#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ diff --git a/keyboards/kapcave/paladin64/config.h b/keyboards/kapcave/paladin64/config.h index 2685be96cf86..98dbe1ecaefa 100755 --- a/keyboards/kapcave/paladin64/config.h +++ b/keyboards/kapcave/paladin64/config.h @@ -34,14 +34,13 @@ along with this program. If not, see . /* Only required if you add in a trackpoint hardware to the pcb */ #ifdef PS2_USE_USART - #define PS2_CLOCK_PORT PORTD - #define PS2_CLOCK_PIN PIND - #define PS2_CLOCK_DDR DDRD - #define PS2_CLOCK_BIT 5 - #define PS2_DATA_PORT PORTD - #define PS2_DATA_PIN PIND - #define PS2_DATA_DDR DDRD - #define PS2_DATA_BIT 2 +#define PS2_CLOCK_PIN D5 +#define PS2_DATA_PIN D2 + +#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) +#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) +#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) +#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling * edge */ @@ -77,14 +76,8 @@ along with this program. If not, see . #endif #ifdef PS2_USE_INT -#define PS2_CLOCK_PORT PORTD -#define PS2_CLOCK_PIN PIND -#define PS2_CLOCK_DDR DDRD -#define PS2_CLOCK_BIT 2 -#define PS2_DATA_PORT PORTD -#define PS2_DATA_PIN PIND -#define PS2_DATA_DDR DDRD -#define PS2_DATA_BIT 5 +#define PS2_CLOCK_PIN D2 +#define PS2_DATA_PIN D5 #define PS2_INT_INIT() do { \ EICRA |= ((1< Date: Thu, 7 Oct 2021 23:53:43 +0100 Subject: [PATCH 4/6] Remove more defines --- docs/feature_ps2_mouse.md | 5 ----- docs/ja/feature_ps2_mouse.md | 5 ----- keyboards/converter/ibm_terminal/config.h | 5 ----- keyboards/evyd13/gh80_3700/keymaps/ps2/config.h | 5 ----- keyboards/handwired/108key_trackpoint/config.h | 5 ----- keyboards/handwired/promethium/config.h | 5 ----- keyboards/handwired/trackpoint/config.h | 5 ----- keyboards/kapcave/paladin64/config.h | 5 ----- tmk_core/protocol/ps2_usart.c | 13 +++++++++++++ 9 files changed, 13 insertions(+), 40 deletions(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index a1ea1b565857..c980705ae7f9 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -118,11 +118,6 @@ In your keyboard config.h: #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 -#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) -#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) -#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) -#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) - /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ #define PS2_USART_INIT() do { \ diff --git a/docs/ja/feature_ps2_mouse.md b/docs/ja/feature_ps2_mouse.md index 18a40fa2dea4..569934c18762 100644 --- a/docs/ja/feature_ps2_mouse.md +++ b/docs/ja/feature_ps2_mouse.md @@ -99,11 +99,6 @@ PS2_USE_USART = yes #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 -#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) -#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) -#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) -#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) - /* 同期、奇数パリティ、1-bit ストップ、8-bit データ、立ち下がりエッジでサンプル */ /* CLOCK の DDR を入力としてスレーブに設定 */ #define PS2_USART_INIT() do { \ diff --git a/keyboards/converter/ibm_terminal/config.h b/keyboards/converter/ibm_terminal/config.h index 4614345cbf25..2cd36c5fb0ae 100644 --- a/keyboards/converter/ibm_terminal/config.h +++ b/keyboards/converter/ibm_terminal/config.h @@ -48,11 +48,6 @@ along with this program. If not, see . #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 -#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) -#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) -#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) -#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) - /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ #define PS2_USART_INIT() do { \ diff --git a/keyboards/evyd13/gh80_3700/keymaps/ps2/config.h b/keyboards/evyd13/gh80_3700/keymaps/ps2/config.h index 164a0d925c57..b77ac95d7d47 100644 --- a/keyboards/evyd13/gh80_3700/keymaps/ps2/config.h +++ b/keyboards/evyd13/gh80_3700/keymaps/ps2/config.h @@ -20,11 +20,6 @@ #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 -#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) -#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) -#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) -#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) - /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ #define PS2_USART_INIT() do { \ diff --git a/keyboards/handwired/108key_trackpoint/config.h b/keyboards/handwired/108key_trackpoint/config.h index aaf2df753844..b5bf98271afb 100644 --- a/keyboards/handwired/108key_trackpoint/config.h +++ b/keyboards/handwired/108key_trackpoint/config.h @@ -15,11 +15,6 @@ #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 -#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) -#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) -#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) -#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) - /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ #define PS2_USART_INIT() do { \ diff --git a/keyboards/handwired/promethium/config.h b/keyboards/handwired/promethium/config.h index 8bc4362a26fe..612675c63a07 100644 --- a/keyboards/handwired/promethium/config.h +++ b/keyboards/handwired/promethium/config.h @@ -255,11 +255,6 @@ enum led_sequence { #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 -#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) -#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) -#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) -#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) - /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ # define PS2_USART_INIT() \ diff --git a/keyboards/handwired/trackpoint/config.h b/keyboards/handwired/trackpoint/config.h index 0cd6f9c78668..cf8b5605f43a 100644 --- a/keyboards/handwired/trackpoint/config.h +++ b/keyboards/handwired/trackpoint/config.h @@ -15,11 +15,6 @@ #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 -#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) -#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) -#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) -#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) - /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling edge */ /* set DDR of CLOCK as input to be slave */ #define PS2_USART_INIT() do { \ diff --git a/keyboards/kapcave/paladin64/config.h b/keyboards/kapcave/paladin64/config.h index 98dbe1ecaefa..7c3d1a0fa111 100755 --- a/keyboards/kapcave/paladin64/config.h +++ b/keyboards/kapcave/paladin64/config.h @@ -37,11 +37,6 @@ along with this program. If not, see . #define PS2_CLOCK_PIN D5 #define PS2_DATA_PIN D2 -#define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) -#define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) -#define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) -#define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) - /* synchronous, odd parity, 1-bit stop, 8-bit data, sample at falling * edge */ /* set DDR of CLOCK as input to be slave */ diff --git a/tmk_core/protocol/ps2_usart.c b/tmk_core/protocol/ps2_usart.c index 6a66dc4a1e73..5f70083698fa 100644 --- a/tmk_core/protocol/ps2_usart.c +++ b/tmk_core/protocol/ps2_usart.c @@ -46,6 +46,19 @@ POSSIBILITY OF SUCH DAMAGE. #include "ps2_io.h" #include "print.h" +#ifndef PS2_CLOCK_DDR +# define PS2_CLOCK_DDR PORTx_ADDRESS(PS2_CLOCK_PIN) +#endif +#ifndef PS2_CLOCK_BIT +# define PS2_CLOCK_BIT (PS2_CLOCK_PIN & 0xF) +#endif +#ifndef PS2_DATA_DDR +# define PS2_DATA_DDR PORTx_ADDRESS(PS2_DATA_PIN) +#endif +#ifndef PS2_DATA_BIT +# define PS2_DATA_BIT (PS2_DATA_PIN & 0xF) +#endif + #define WAIT(stat, us, err) \ do { \ if (!wait_##stat(us)) { \ From 20825fe9a9f509e2a106d4a85ff2a053bd8a8f63 Mon Sep 17 00:00:00 2001 From: zvecr Date: Fri, 8 Oct 2021 17:23:59 +0100 Subject: [PATCH 5/6] Put back avr/chibios split --- tmk_core/protocol.mk | 6 +-- tmk_core/protocol/{ps2_io.c => ps2_io_avr.c} | 21 ++++---- tmk_core/protocol/ps2_io_chibios.c | 55 ++++++++++++++++++++ 3 files changed, 68 insertions(+), 14 deletions(-) rename tmk_core/protocol/{ps2_io.c => ps2_io_avr.c} (68%) create mode 100644 tmk_core/protocol/ps2_io_chibios.c diff --git a/tmk_core/protocol.mk b/tmk_core/protocol.mk index 6eb0cb907a12..b61f2f5463ab 100644 --- a/tmk_core/protocol.mk +++ b/tmk_core/protocol.mk @@ -8,19 +8,19 @@ endif ifeq ($(strip $(PS2_USE_BUSYWAIT)), yes) SRC += protocol/ps2_busywait.c - SRC += protocol/ps2_io.c + SRC += protocol/ps2_io_avr.c OPT_DEFS += -DPS2_USE_BUSYWAIT endif ifeq ($(strip $(PS2_USE_INT)), yes) SRC += protocol/ps2_interrupt.c - SRC += protocol/ps2_io.c + SRC += protocol/ps2_io_$(PLATFORM_KEY).c OPT_DEFS += -DPS2_USE_INT endif ifeq ($(strip $(PS2_USE_USART)), yes) SRC += protocol/ps2_usart.c - SRC += protocol/ps2_io.c + SRC += protocol/ps2_io_$(PLATFORM_KEY).c OPT_DEFS += -DPS2_USE_USART endif diff --git a/tmk_core/protocol/ps2_io.c b/tmk_core/protocol/ps2_io_avr.c similarity index 68% rename from tmk_core/protocol/ps2_io.c rename to tmk_core/protocol/ps2_io_avr.c index be9c83bad903..7c826fbf1aac 100644 --- a/tmk_core/protocol/ps2_io.c +++ b/tmk_core/protocol/ps2_io_avr.c @@ -1,6 +1,7 @@ #include -#include "gpio.h" #include "ps2_io.h" +#include "gpio.h" +#include "wait.h" /* Check port settings for clock and data line */ #if !(defined(PS2_CLOCK_PIN)) @@ -17,17 +18,16 @@ void clock_init(void) {} void clock_lo(void) { - setPinOutput(PS2_CLOCK_PIN); + // Transition from input with pull-up to output low via Hi-Z instead of output high writePinLow(PS2_CLOCK_PIN); -} - -void clock_hi(void) { setPinOutput(PS2_CLOCK_PIN); - writePinHigh(PS2_CLOCK_PIN); } +void clock_hi(void) { setPinInputHigh(PS2_CLOCK_PIN); } + bool clock_in(void) { setPinInputHigh(PS2_CLOCK_PIN); + wait_us(1); return readPin(PS2_CLOCK_PIN); } @@ -37,16 +37,15 @@ bool clock_in(void) { void data_init(void) {} void data_lo(void) { - setPinOutput(PS2_DATA_PIN); + // Transition from input with pull-up to output low via Hi-Z instead of output high writePinLow(PS2_DATA_PIN); -} - -void data_hi(void) { setPinOutput(PS2_DATA_PIN); - writePinHigh(PS2_DATA_PIN); } +void data_hi(void) { setPinInputHigh(PS2_DATA_PIN); } + bool data_in(void) { setPinInputHigh(PS2_DATA_PIN); + wait_us(1); return readPin(PS2_DATA_PIN); } diff --git a/tmk_core/protocol/ps2_io_chibios.c b/tmk_core/protocol/ps2_io_chibios.c new file mode 100644 index 000000000000..906d85d84840 --- /dev/null +++ b/tmk_core/protocol/ps2_io_chibios.c @@ -0,0 +1,55 @@ +#include +#include "ps2_io.h" + +// chibiOS headers +#include "ch.h" +#include "hal.h" + +/* Check port settings for clock and data line */ +#if !(defined(PS2_CLOCK_PIN)) +# error "PS/2 clock setting is required in config.h" +#endif + +#if !(defined(PS2_DATA_PIN)) +# error "PS/2 data setting is required in config.h" +#endif + +/* + * Clock + */ +void clock_init(void) {} + +void clock_lo(void) { + palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_CLOCK_PIN, PAL_LOW); +} + +void clock_hi(void) { + palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_CLOCK_PIN, PAL_HIGH); +} + +bool clock_in(void) { + palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_INPUT); + return palReadLine(PS2_CLOCK_PIN); +} + +/* + * Data + */ +void data_init(void) {} + +void data_lo(void) { + palSetLineMode(PS2_DATA_PIN, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_DATA_PIN, PAL_LOW); +} + +void data_hi(void) { + palSetLineMode(PS2_DATA_PIN, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_DATA_PIN, PAL_HIGH); +} + +bool data_in(void) { + palSetLineMode(PS2_DATA_PIN, PAL_MODE_INPUT); + return palReadLine(PS2_DATA_PIN); +} From 90b542aa2386c8a3b17de7e66cc471f1f74d9b73 Mon Sep 17 00:00:00 2001 From: zvecr Date: Fri, 8 Oct 2021 17:26:37 +0100 Subject: [PATCH 6/6] format --- tmk_core/protocol/ps2_interrupt.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tmk_core/protocol/ps2_interrupt.c b/tmk_core/protocol/ps2_interrupt.c index 05132d775a27..70debd02f7fa 100644 --- a/tmk_core/protocol/ps2_interrupt.c +++ b/tmk_core/protocol/ps2_interrupt.c @@ -73,16 +73,16 @@ static inline void pbuf_clear(void); void ps2_interrupt_service_routine(void); void palCallback(void *arg) { ps2_interrupt_service_routine(); } -# define PS2_INT_INIT() \ +# define PS2_INT_INIT() \ { palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_INPUT); } \ while (0) -# define PS2_INT_ON() \ - { \ +# define PS2_INT_ON() \ + { \ palEnableLineEvent(PS2_CLOCK_PIN, PAL_EVENT_MODE_FALLING_EDGE); \ palSetLineCallback(PS2_CLOCK_PIN, palCallback, NULL); \ - } \ + } \ while (0) -# define PS2_INT_OFF() \ +# define PS2_INT_OFF() \ { palDisableLineEvent(PS2_CLOCK_PIN); } \ while (0) #endif // PROTOCOL_CHIBIOS