diff options
Diffstat (limited to 'tmk_core')
-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 780040d152..70debd02f7 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); void ps2_interrupt_service_routine(void); void palCallback(void *arg) { ps2_interrupt_service_routine(); } -# define PS2_INT_INIT() \ - { palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); } \ +# define PS2_INT_INIT() \ + { 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); \ - } \ +# 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() \ - { palDisableLineEvent(PS2_CLOCK); } \ +# define PS2_INT_OFF() \ + { palDisableLineEvent(PS2_CLOCK_PIN); } \ while (0) #endif // PROTOCOL_CHIBIOS 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); } diff --git a/tmk_core/protocol/ps2_io_chibios.c b/tmk_core/protocol/ps2_io_chibios.c index b672bd1f47..906d85d848 100644 --- a/tmk_core/protocol/ps2_io_chibios.c +++ b/tmk_core/protocol/ps2_io_chibios.c @@ -6,11 +6,11 @@ #include "hal.h" /* Check port settings for clock and data line */ -#if !(defined(PS2_CLOCK)) +#if !(defined(PS2_CLOCK_PIN)) # error "PS/2 clock setting is required in config.h" #endif -#if !(defined(PS2_DATA)) +#if !(defined(PS2_DATA_PIN)) # error "PS/2 data setting is required in config.h" #endif @@ -20,18 +20,18 @@ void clock_init(void) {} void clock_lo(void) { - palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_CLOCK, PAL_LOW); + palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_CLOCK_PIN, PAL_LOW); } void clock_hi(void) { - palSetLineMode(PS2_CLOCK, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_CLOCK, PAL_HIGH); + palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_CLOCK_PIN, PAL_HIGH); } bool clock_in(void) { - palSetLineMode(PS2_CLOCK, PAL_MODE_INPUT); - return palReadLine(PS2_CLOCK); + palSetLineMode(PS2_CLOCK_PIN, PAL_MODE_INPUT); + return palReadLine(PS2_CLOCK_PIN); } /* @@ -40,16 +40,16 @@ bool clock_in(void) { void data_init(void) {} void data_lo(void) { - palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_DATA, PAL_LOW); + palSetLineMode(PS2_DATA_PIN, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_DATA_PIN, PAL_LOW); } void data_hi(void) { - palSetLineMode(PS2_DATA, PAL_MODE_OUTPUT_OPENDRAIN); - palWriteLine(PS2_DATA, PAL_HIGH); + palSetLineMode(PS2_DATA_PIN, PAL_MODE_OUTPUT_OPENDRAIN); + palWriteLine(PS2_DATA_PIN, PAL_HIGH); } bool data_in(void) { - palSetLineMode(PS2_DATA, PAL_MODE_INPUT); - return palReadLine(PS2_DATA); + palSetLineMode(PS2_DATA_PIN, PAL_MODE_INPUT); + return palReadLine(PS2_DATA_PIN); } diff --git a/tmk_core/protocol/ps2_usart.c b/tmk_core/protocol/ps2_usart.c index 6a66dc4a1e..5f70083698 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)) { \ |