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