diff options
author | tmk <nobody@nowhere> | 2014-06-19 16:13:35 +0900 |
---|---|---|
committer | tmk <nobody@nowhere> | 2014-07-30 14:07:43 +0900 |
commit | 4c8e0fd0bd1712421f957ec5e0ca16fc6bbb3856 (patch) | |
tree | 2141d2e168ad043ea18bcb3aee3f3a03dd2a2f1b /protocol/ps2_io_avr.c | |
parent | 80c3ff5fa03429f1e4ea15032f665ceb88c9b8c3 (diff) | |
download | qmk_firmware-4c8e0fd0bd1712421f957ec5e0ca16fc6bbb3856.tar.gz qmk_firmware-4c8e0fd0bd1712421f957ec5e0ca16fc6bbb3856.zip |
Port ps2_usb to mbed
Diffstat (limited to 'protocol/ps2_io_avr.c')
-rw-r--r-- | protocol/ps2_io_avr.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/protocol/ps2_io_avr.c b/protocol/ps2_io_avr.c new file mode 100644 index 0000000000..be13d6696a --- /dev/null +++ b/protocol/ps2_io_avr.c @@ -0,0 +1,74 @@ +#include <stdbool.h> +#include <util/delay.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" +#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); +} |