]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/xt_io_avr.c
7775be7f3b18c29ac63823a307b790d68da8a6fe
[max/tmk_keyboard.git] / tmk_core / protocol / xt_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(XT_CLOCK_PORT) && \
7       defined(XT_CLOCK_PIN) && \
8       defined(XT_CLOCK_DDR) && \
9       defined(XT_CLOCK_BIT))
10 #   error "XT clock port setting is required in config.h"
11 #endif
12
13 #if !(defined(XT_DATA_PORT) && \
14       defined(XT_DATA_PIN) && \
15       defined(XT_DATA_DDR) && \
16       defined(XT_DATA_BIT))
17 #   error "XT data port setting is required in config.h"
18 #endif
19
20 bool clock_in(void)
21 {
22     XT_CLOCK_DDR  &= ~(1<<XT_CLOCK_BIT);
23     XT_CLOCK_PORT |=  (1<<XT_CLOCK_BIT);
24     _delay_us(1);
25     return XT_CLOCK_PIN&(1<<XT_CLOCK_BIT);
26 }
27
28 bool data_in(void)
29 {
30     XT_DATA_DDR  &= ~(1<<XT_DATA_BIT);
31     XT_DATA_PORT |=  (1<<XT_DATA_BIT);
32     _delay_us(1);
33     return XT_DATA_PIN&(1<<XT_DATA_BIT);
34 }
35
36 void clock_lo(void)
37 {
38     XT_CLOCK_PORT &= ~(1<<XT_CLOCK_BIT);
39     XT_CLOCK_DDR  |=  (1<<XT_CLOCK_BIT);
40 }
41
42 void data_lo(void)
43 {
44     XT_DATA_PORT &= ~(1<<XT_DATA_BIT);
45     XT_DATA_DDR  |=  (1<<XT_DATA_BIT);
46 }