aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/protocol/ibm4704.h
diff options
context:
space:
mode:
authortmk <hasu@tmk-kbd.com>2015-04-10 01:32:04 +0900
committertmk <hasu@tmk-kbd.com>2015-04-10 01:32:04 +0900
commit1a02ebcc612e9a9c0d87e02295c7258de3a70ccc (patch)
treee517f3c70bb2d542797e57d13e9023c84af230fb /tmk_core/protocol/ibm4704.h
parent6746e37088ce8ba03529c1226bd216705edb2b1f (diff)
parenta074364c3731d66b56d988c8a6c960a83ea0e0a1 (diff)
downloadqmk_firmware-1a02ebcc612e9a9c0d87e02295c7258de3a70ccc.tar.gz
qmk_firmware-1a02ebcc612e9a9c0d87e02295c7258de3a70ccc.zip
Merge commit 'a074364c3731d66b56d988c8a6c960a83ea0e0a1' as 'tmk_core'
Diffstat (limited to 'tmk_core/protocol/ibm4704.h')
-rw-r--r--tmk_core/protocol/ibm4704.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/tmk_core/protocol/ibm4704.h b/tmk_core/protocol/ibm4704.h
new file mode 100644
index 000000000..618cce6be
--- /dev/null
+++ b/tmk_core/protocol/ibm4704.h
@@ -0,0 +1,110 @@
1/*
2Copyright 2014 Jun WAKO <wakojun@gmail.com>
3*/
4#ifndef IBM4704_H
5#define IBM4704_H
6
7#define IBM4704_ERR_NONE 0
8#define IBM4704_ERR_PARITY 0x70
9
10
11void ibm4704_init(void);
12uint8_t ibm4704_send(uint8_t data);
13uint8_t ibm4704_recv_response(void);
14uint8_t ibm4704_recv(void);
15
16
17/* Check pin configuration */
18#if !(defined(IBM4704_CLOCK_PORT) && \
19 defined(IBM4704_CLOCK_PIN) && \
20 defined(IBM4704_CLOCK_DDR) && \
21 defined(IBM4704_CLOCK_BIT))
22# error "ibm4704 clock pin configuration is required in config.h"
23#endif
24
25#if !(defined(IBM4704_DATA_PORT) && \
26 defined(IBM4704_DATA_PIN) && \
27 defined(IBM4704_DATA_DDR) && \
28 defined(IBM4704_DATA_BIT))
29# error "ibm4704 data pin configuration is required in config.h"
30#endif
31
32
33/*--------------------------------------------------------------------
34 * static functions
35 *------------------------------------------------------------------*/
36static inline void clock_lo(void)
37{
38 IBM4704_CLOCK_PORT &= ~(1<<IBM4704_CLOCK_BIT);
39 IBM4704_CLOCK_DDR |= (1<<IBM4704_CLOCK_BIT);
40}
41static inline void clock_hi(void)
42{
43 /* input with pull up */
44 IBM4704_CLOCK_DDR &= ~(1<<IBM4704_CLOCK_BIT);
45 IBM4704_CLOCK_PORT |= (1<<IBM4704_CLOCK_BIT);
46}
47static inline bool clock_in(void)
48{
49 IBM4704_CLOCK_DDR &= ~(1<<IBM4704_CLOCK_BIT);
50 IBM4704_CLOCK_PORT |= (1<<IBM4704_CLOCK_BIT);
51 _delay_us(1);
52 return IBM4704_CLOCK_PIN&(1<<IBM4704_CLOCK_BIT);
53}
54static inline void data_lo(void)
55{
56 IBM4704_DATA_PORT &= ~(1<<IBM4704_DATA_BIT);
57 IBM4704_DATA_DDR |= (1<<IBM4704_DATA_BIT);
58}
59static inline void data_hi(void)
60{
61 /* input with pull up */
62 IBM4704_DATA_DDR &= ~(1<<IBM4704_DATA_BIT);
63 IBM4704_DATA_PORT |= (1<<IBM4704_DATA_BIT);
64}
65static inline bool data_in(void)
66{
67 IBM4704_DATA_DDR &= ~(1<<IBM4704_DATA_BIT);
68 IBM4704_DATA_PORT |= (1<<IBM4704_DATA_BIT);
69 _delay_us(1);
70 return IBM4704_DATA_PIN&(1<<IBM4704_DATA_BIT);
71}
72
73static inline uint16_t wait_clock_lo(uint16_t us)
74{
75 while (clock_in() && us) { asm(""); _delay_us(1); us--; }
76 return us;
77}
78static inline uint16_t wait_clock_hi(uint16_t us)
79{
80 while (!clock_in() && us) { asm(""); _delay_us(1); us--; }
81 return us;
82}
83static inline uint16_t wait_data_lo(uint16_t us)
84{
85 while (data_in() && us) { asm(""); _delay_us(1); us--; }
86 return us;
87}
88static inline uint16_t wait_data_hi(uint16_t us)
89{
90 while (!data_in() && us) { asm(""); _delay_us(1); us--; }
91 return us;
92}
93
94/* idle state that device can send */
95static inline void idle(void)
96{
97 clock_hi();
98 data_hi();
99}
100
101/* inhibit device to send
102 * keyboard checks Data line on start bit(Data:hi) and it stops sending if Data line is low.
103 */
104static inline void inhibit(void)
105{
106 clock_hi();
107 data_lo();
108}
109
110#endif