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