diff options
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 000000000..be13d6696 --- /dev/null +++ b/protocol/ps2_io_avr.c | |||
| @@ -0,0 +1,74 @@ | |||
| 1 | #include <stdbool.h> | ||
| 2 | #include <util/delay.h> | ||
| 3 | |||
| 4 | /* Check port settings for clock and data line */ | ||
| 5 | #if !(defined(PS2_CLOCK_PORT) && \ | ||
| 6 | defined(PS2_CLOCK_PIN) && \ | ||
| 7 | defined(PS2_CLOCK_DDR) && \ | ||
| 8 | defined(PS2_CLOCK_BIT)) | ||
| 9 | # error "PS/2 clock port setting is required in config.h" | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #if !(defined(PS2_DATA_PORT) && \ | ||
| 13 | defined(PS2_DATA_PIN) && \ | ||
| 14 | defined(PS2_DATA_DDR) && \ | ||
| 15 | defined(PS2_DATA_BIT)) | ||
| 16 | # error "PS/2 data port setting is required in config.h" | ||
| 17 | #endif | ||
| 18 | |||
| 19 | |||
| 20 | /* | ||
| 21 | * Clock | ||
| 22 | */ | ||
| 23 | void clock_init(void) | ||
| 24 | { | ||
| 25 | } | ||
| 26 | |||
| 27 | void clock_lo(void) | ||
| 28 | { | ||
| 29 | PS2_CLOCK_PORT &= ~(1<<PS2_CLOCK_BIT); | ||
| 30 | PS2_CLOCK_DDR |= (1<<PS2_CLOCK_BIT); | ||
| 31 | } | ||
| 32 | |||
| 33 | void clock_hi(void) | ||
| 34 | { | ||
| 35 | /* input with pull up */ | ||
| 36 | PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); | ||
| 37 | PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT); | ||
| 38 | } | ||
| 39 | |||
| 40 | bool clock_in(void) | ||
| 41 | { | ||
| 42 | PS2_CLOCK_DDR &= ~(1<<PS2_CLOCK_BIT); | ||
| 43 | PS2_CLOCK_PORT |= (1<<PS2_CLOCK_BIT); | ||
| 44 | _delay_us(1); | ||
| 45 | return PS2_CLOCK_PIN&(1<<PS2_CLOCK_BIT); | ||
| 46 | } | ||
| 47 | |||
| 48 | /* | ||
| 49 | * Data | ||
| 50 | */ | ||
| 51 | void data_init(void) | ||
| 52 | { | ||
| 53 | } | ||
| 54 | |||
| 55 | void data_lo(void) | ||
| 56 | { | ||
| 57 | PS2_DATA_PORT &= ~(1<<PS2_DATA_BIT); | ||
| 58 | PS2_DATA_DDR |= (1<<PS2_DATA_BIT); | ||
| 59 | } | ||
| 60 | |||
| 61 | void data_hi(void) | ||
| 62 | { | ||
| 63 | /* input with pull up */ | ||
| 64 | PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); | ||
| 65 | PS2_DATA_PORT |= (1<<PS2_DATA_BIT); | ||
| 66 | } | ||
| 67 | |||
| 68 | bool data_in(void) | ||
| 69 | { | ||
| 70 | PS2_DATA_DDR &= ~(1<<PS2_DATA_BIT); | ||
| 71 | PS2_DATA_PORT |= (1<<PS2_DATA_BIT); | ||
| 72 | _delay_us(1); | ||
| 73 | return PS2_DATA_PIN&(1<<PS2_DATA_BIT); | ||
| 74 | } | ||
