]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/ergodox_ez/ergodox_ez.h
Redox: move curly brackets one row down. (#4364)
[qmk_firmware.git] / keyboards / ergodox_ez / ergodox_ez.h
1 #ifndef ERGODOX_EZ_H
2 #define ERGODOX_EZ_H
3
4 #include "quantum.h"
5 #include <stdint.h>
6 #include <stdbool.h>
7 #include "i2c_master.h"
8 #include <util/delay.h>
9
10 #define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
11 #define CPU_16MHz       0x00
12
13 // I2C aliases and register addresses (see "mcp23018.md")
14 #define I2C_ADDR        0b0100000
15 #define I2C_ADDR_WRITE  ( (I2C_ADDR<<1) | I2C_WRITE )
16 #define I2C_ADDR_READ   ( (I2C_ADDR<<1) | I2C_READ  )
17 #define IODIRA          0x00            // i/o direction register
18 #define IODIRB          0x01
19 #define GPPUA           0x0C            // GPIO pull-up resistor register
20 #define GPPUB           0x0D
21 #define GPIOA           0x12            // general purpose i/o port register (write modifies OLAT)
22 #define GPIOB           0x13
23 #define OLATA           0x14            // output latch register
24 #define OLATB           0x15
25
26 extern i2c_status_t mcp23018_status;
27 #define ERGODOX_EZ_I2C_TIMEOUT 100
28
29 void init_ergodox(void);
30 void ergodox_blink_all_leds(void);
31 uint8_t init_mcp23018(void);
32 uint8_t ergodox_left_leds_update(void);
33
34 #ifndef LED_BRIGHTNESS_LO
35 #define LED_BRIGHTNESS_LO       15
36 #endif
37 #ifndef LED_BRIGHTNESS_HI
38 #define LED_BRIGHTNESS_HI       255
39 #endif
40
41
42 inline void ergodox_board_led_on(void)      { DDRD |=  (1<<6); PORTD |=  (1<<6); }
43 inline void ergodox_right_led_1_on(void)    { DDRB |=  (1<<5); PORTB |=  (1<<5); }
44 inline void ergodox_right_led_2_on(void)    { DDRB |=  (1<<6); PORTB |=  (1<<6); }
45 inline void ergodox_right_led_3_on(void)    { DDRB |=  (1<<7); PORTB |=  (1<<7); }
46 inline void ergodox_right_led_on(uint8_t led) { DDRB |= (1<<(led+4)); PORTB |= (1<<(led+4)); }
47
48 inline void ergodox_board_led_off(void)     { DDRD &= ~(1<<6); PORTD &= ~(1<<6); }
49 inline void ergodox_right_led_1_off(void)   { DDRB &= ~(1<<5); PORTB &= ~(1<<5); }
50 inline void ergodox_right_led_2_off(void)   { DDRB &= ~(1<<6); PORTB &= ~(1<<6); }
51 inline void ergodox_right_led_3_off(void)   { DDRB &= ~(1<<7); PORTB &= ~(1<<7); }
52 inline void ergodox_right_led_off(uint8_t led) { DDRB &= ~(1<<(led+4)); PORTB &= ~(1<<(led+4)); }
53
54 #ifdef LEFT_LEDS
55 bool ergodox_left_led_1;
56 bool ergodox_left_led_2;
57 bool ergodox_left_led_3;
58
59 inline void ergodox_left_led_1_on(void)    { ergodox_left_led_1 = 1; }
60 inline void ergodox_left_led_2_on(void)    { ergodox_left_led_2 = 1; }
61 inline void ergodox_left_led_3_on(void)    { ergodox_left_led_3 = 1; }
62
63 inline void ergodox_left_led_1_off(void)    { ergodox_left_led_1 = 0; }
64 inline void ergodox_left_led_2_off(void)    { ergodox_left_led_2 = 0; }
65 inline void ergodox_left_led_3_off(void)    { ergodox_left_led_3 = 0; }
66 #endif // LEFT_LEDS
67
68 inline void ergodox_led_all_on(void)
69 {
70     ergodox_board_led_on();
71     ergodox_right_led_1_on();
72     ergodox_right_led_2_on();
73     ergodox_right_led_3_on();
74 #ifdef LEFT_LEDS
75     ergodox_left_led_1_on();
76     ergodox_left_led_2_on();
77     ergodox_left_led_3_on();
78 #endif // LEFT_LEDS
79 }
80
81 inline void ergodox_led_all_off(void)
82 {
83     ergodox_board_led_off();
84     ergodox_right_led_1_off();
85     ergodox_right_led_2_off();
86     ergodox_right_led_3_off();
87 #ifdef LEFT_LEDS
88     ergodox_left_led_1_off();
89     ergodox_left_led_2_off();
90     ergodox_left_led_3_off();
91 #endif // LEFT_LEDS
92 }
93
94 inline void ergodox_right_led_1_set(uint8_t n)    { OCR1A = n; }
95 inline void ergodox_right_led_2_set(uint8_t n)    { OCR1B = n; }
96 inline void ergodox_right_led_3_set(uint8_t n)    { OCR1C = n; }
97 inline void ergodox_right_led_set(uint8_t led, uint8_t n)  {
98     (led == 1) ? (OCR1A = n) :
99     (led == 2) ? (OCR1B = n) :
100                  (OCR1C = n);
101 }
102
103 inline void ergodox_led_all_set(uint8_t n)
104 {
105     ergodox_right_led_1_set(n);
106     ergodox_right_led_2_set(n);
107     ergodox_right_led_3_set(n);
108 }
109
110 /*
111  *   LEFT HAND: LINES 115-122
112  *  RIGHT HAND: LINES 124-131
113  */
114 #define LAYOUT_ergodox(                                         \
115                                                                 \
116     k00,k01,k02,k03,k04,k05,k06,                                \
117     k10,k11,k12,k13,k14,k15,k16,                                \
118     k20,k21,k22,k23,k24,k25,                                    \
119     k30,k31,k32,k33,k34,k35,k36,                                \
120     k40,k41,k42,k43,k44,                                        \
121                             k55,k56,                            \
122                                 k54,                            \
123                         k53,k52,k51,                            \
124                                                                 \
125         k07,k08,k09,k0A,k0B,k0C,k0D,                            \
126         k17,k18,k19,k1A,k1B,k1C,k1D,                            \
127             k28,k29,k2A,k2B,k2C,k2D,                            \
128         k37,k38,k39,k3A,k3B,k3C,k3D,                            \
129                 k49,k4A,k4B,k4C,k4D,                            \
130     k57,k58,                                                    \
131     k59,                                                        \
132     k5C,k5B,k5A )                                               \
133                                                                 \
134    /* matrix positions */                                       \
135    {                                                            \
136     { k00, k10, k20, k30, k40, KC_NO },   \
137     { k01, k11, k21, k31, k41, k51 },   \
138     { k02, k12, k22, k32, k42, k52 },   \
139     { k03, k13, k23, k33, k43, k53 },   \
140     { k04, k14, k24, k34, k44, k54 },   \
141     { k05, k15, k25, k35, KC_NO, k55 },   \
142     { k06, k16, KC_NO, k36, KC_NO, k56 },   \
143                                                                  \
144     { k07, k17, KC_NO, k37,KC_NO, k57 },   \
145     { k08, k18, k28, k38,KC_NO, k58 },   \
146     { k09, k19, k29, k39, k49, k59 },   \
147     { k0A, k1A, k2A, k3A, k4A, k5A },   \
148     { k0B, k1B, k2B, k3B, k4B, k5B },   \
149     { k0C, k1C, k2C, k3C, k4C, k5C },   \
150     { k0D, k1D, k2D, k3D, k4D, KC_NO }    \
151    }
152
153 /*
154  *   LEFT HAND: LINES 158-165
155  *  RIGHT HAND: LINES 167-174
156  */
157 #define LAYOUT_ergodox_80(                                      \
158                                                                 \
159     k00,k01,k02,k03,k04,k05,k06,                                \
160     k10,k11,k12,k13,k14,k15,k16,                                \
161     k20,k21,k22,k23,k24,k25,                                    \
162     k30,k31,k32,k33,k34,k35,k36,                                \
163     k40,k41,k42,k43,k44,                                        \
164                             k55,k56,                            \
165                         k45,k46,k54,                            \
166                         k53,k52,k51,                            \
167                                                                 \
168         k07,k08,k09,k0A,k0B,k0C,k0D,                            \
169         k17,k18,k19,k1A,k1B,k1C,k1D,                            \
170             k28,k29,k2A,k2B,k2C,k2D,                            \
171         k37,k38,k39,k3A,k3B,k3C,k3D,                            \
172                 k49,k4A,k4B,k4C,k4D,                            \
173     k57,k58,                                                    \
174     k59,k47,k48,                                                \
175     k5C,k5B,k5A )                                               \
176                                                                 \
177    /* matrix positions */                                       \
178    {                                                            \
179     { k00, k10, k20, k30, k40, KC_NO },   \
180     { k01, k11, k21, k31, k41, k51 },   \
181     { k02, k12, k22, k32, k42, k52 },   \
182     { k03, k13, k23, k33, k43, k53 },   \
183     { k04, k14, k24, k34, k44, k54 },   \
184     { k05, k15, k25, k35, k45, k55 },   \
185     { k06, k16, KC_NO, k36, k46, k56 },   \
186                                                                  \
187     { k07, k17, KC_NO, k37, k47, k57 },   \
188     { k08, k18, k28, k38, k48, k58 },   \
189     { k09, k19, k29, k39, k49, k59 },   \
190     { k0A, k1A, k2A, k3A, k4A, k5A },   \
191     { k0B, k1B, k2B, k3B, k4B, k5B },   \
192     { k0C, k1C, k2C, k3C, k4C, k5C },   \
193     { k0D, k1D, k2D, k3D, k4D, KC_NO }    \
194    }
195
196 /*  ---------- LEFT HAND -----------   ---------- RIGHT HAND ---------- */
197 #define LAYOUT_ergodox_pretty(                                           \
198     L00,L01,L02,L03,L04,L05,L06,           R00,R01,R02,R03,R04,R05,R06,  \
199     L10,L11,L12,L13,L14,L15,L16,           R10,R11,R12,R13,R14,R15,R16,  \
200     L20,L21,L22,L23,L24,L25,                   R21,R22,R23,R24,R25,R26,  \
201     L30,L31,L32,L33,L34,L35,L36,           R30,R31,R32,R33,R34,R35,R36,  \
202     L40,L41,L42,L43,L44,                           R42,R43,R44,R45,R46,  \
203                             L55,L56,   R50,R51,                          \
204                                 L54,   R52,                              \
205                         L53,L52,L51,   R55,R54,R53 )                     \
206                                           \
207    /* matrix positions */                 \
208     {                                     \
209     { L00, L10, L20, L30, L40, KC_NO },   \
210     { L01, L11, L21, L31, L41, L51 },     \
211     { L02, L12, L22, L32, L42, L52 },     \
212     { L03, L13, L23, L33, L43, L53 },     \
213     { L04, L14, L24, L34, L44, L54 },     \
214     { L05, L15, L25, L35, KC_NO, L55 },   \
215     { L06, L16, KC_NO, L36, KC_NO, L56 }, \
216                                           \
217     { R00, R10, KC_NO, R30,KC_NO, R50 },  \
218     { R01, R11, R21, R31,KC_NO, R51 },    \
219     { R02, R12, R22, R32, R42, R52 },     \
220     { R03, R13, R23, R33, R43, R53 },     \
221     { R04, R14, R24, R34, R44, R54 },     \
222     { R05, R15, R25, R35, R45, R55 },     \
223     { R06, R16, R26, R36, R46, KC_NO }    \
224     }
225
226 /*  ---------- LEFT HAND -----------   ---------- RIGHT HAND ---------- */
227 #define LAYOUT_ergodox_pretty_80(                                        \
228     L00,L01,L02,L03,L04,L05,L06,           R00,R01,R02,R03,R04,R05,R06,  \
229     L10,L11,L12,L13,L14,L15,L16,           R10,R11,R12,R13,R14,R15,R16,  \
230     L20,L21,L22,L23,L24,L25,                   R21,R22,R23,R24,R25,R26,  \
231     L30,L31,L32,L33,L34,L35,L36,           R30,R31,R32,R33,R34,R35,R36,  \
232     L40,L41,L42,L43,L44,                           R42,R43,R44,R45,R46,  \
233                             L55,L56,   R50,R51,                          \
234                         L45,L46,L54,   R52,R40,R41,                      \
235                         L53,L52,L51,   R55,R54,R53 )                     \
236                                           \
237       /* matrix positions */              \
238     {                                     \
239     { L00, L10, L20, L30, L40, KC_NO },   \
240     { L01, L11, L21, L31, L41, L51 },     \
241     { L02, L12, L22, L32, L42, L52 },     \
242     { L03, L13, L23, L33, L43, L53 },     \
243     { L04, L14, L24, L34, L44, L54 },     \
244     { L05, L15, L25, L35, L45, L55 },     \
245     { L06, L16, KC_NO, L36, L46, L56 },   \
246                                           \
247     { R00, R10, KC_NO, R30, R40, R50 },   \
248     { R01, R11, R21, R31, R41, R51 },     \
249     { R02, R12, R22, R32, R42, R52 },     \
250     { R03, R13, R23, R33, R43, R53 },     \
251     { R04, R14, R24, R34, R44, R54 },     \
252     { R05, R15, R25, R35, R45, R55 },     \
253     { R06, R16, R26, R36, R46, KC_NO }    \
254     }
255
256 #endif