]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/config_common.h
Force backlight on when led matrix is enabled
[qmk_firmware.git] / quantum / config_common.h
1 /* Copyright 2015-2018 Jack Humbert
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  */
16
17 #pragma once
18
19 /* diode directions */
20 #define COL2ROW       0
21 #define ROW2COL       1
22 #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
23
24 // useful for direct pin mapping
25 #define NO_PIN (~0)
26
27 #ifdef __AVR__
28     #ifndef __ASSEMBLER__
29       #include <avr/io.h>
30     #endif
31     #define PORT_SHIFTER 4 // this may be 4 for all AVR chips
32
33     // If you want to add more to this list, reference the PINx definitions in these header
34     // files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr
35
36     #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__)
37         #define ADDRESS_BASE 0x00
38         #define PINB_ADDRESS 0x3
39         #define PINC_ADDRESS 0x6
40         #define PIND_ADDRESS 0x9
41         #define PINE_ADDRESS 0xC
42         #define PINF_ADDRESS 0xF
43     #elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__)
44         #define ADDRESS_BASE 0x00
45         #define PINB_ADDRESS 0x3
46         #define PINC_ADDRESS 0x6
47         #define PIND_ADDRESS 0x9
48     #elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__)
49         #define ADDRESS_BASE 0x00
50         #define PINA_ADDRESS 0x0
51         #define PINB_ADDRESS 0x3
52         #define PINC_ADDRESS 0x6
53         #define PIND_ADDRESS 0x9
54         #define PINE_ADDRESS 0xC
55         #define PINF_ADDRESS 0xF
56     #elif defined(__AVR_ATmega32A__)
57         #define ADDRESS_BASE 0x10
58         #define PIND_ADDRESS 0x0
59         #define PINC_ADDRESS 0x3
60         #define PINB_ADDRESS 0x6
61         #define PINA_ADDRESS 0x9
62     #else
63         #error "Pins are not defined"
64     #endif
65
66     /* I/O pins */
67     #define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
68
69     #ifdef PORTA
70         #define A0 PINDEF(A, 0)
71         #define A1 PINDEF(A, 1)
72         #define A2 PINDEF(A, 2)
73         #define A3 PINDEF(A, 3)
74         #define A4 PINDEF(A, 4)
75         #define A5 PINDEF(A, 5)
76         #define A6 PINDEF(A, 6)
77         #define A7 PINDEF(A, 7)
78     #endif
79     #ifdef PORTB
80         #define B0 PINDEF(B, 0)
81         #define B1 PINDEF(B, 1)
82         #define B2 PINDEF(B, 2)
83         #define B3 PINDEF(B, 3)
84         #define B4 PINDEF(B, 4)
85         #define B5 PINDEF(B, 5)
86         #define B6 PINDEF(B, 6)
87         #define B7 PINDEF(B, 7)
88     #endif
89     #ifdef PORTC
90         #define C0 PINDEF(C, 0)
91         #define C1 PINDEF(C, 1)
92         #define C2 PINDEF(C, 2)
93         #define C3 PINDEF(C, 3)
94         #define C4 PINDEF(C, 4)
95         #define C5 PINDEF(C, 5)
96         #define C6 PINDEF(C, 6)
97         #define C7 PINDEF(C, 7)
98     #endif
99     #ifdef PORTD
100         #define D0 PINDEF(D, 0)
101         #define D1 PINDEF(D, 1)
102         #define D2 PINDEF(D, 2)
103         #define D3 PINDEF(D, 3)
104         #define D4 PINDEF(D, 4)
105         #define D5 PINDEF(D, 5)
106         #define D6 PINDEF(D, 6)
107         #define D7 PINDEF(D, 7)
108     #endif
109     #ifdef PORTE
110         #define E0 PINDEF(E, 0)
111         #define E1 PINDEF(E, 1)
112         #define E2 PINDEF(E, 2)
113         #define E3 PINDEF(E, 3)
114         #define E4 PINDEF(E, 4)
115         #define E5 PINDEF(E, 5)
116         #define E6 PINDEF(E, 6)
117         #define E7 PINDEF(E, 7)
118     #endif
119     #ifdef PORTF
120         #define F0 PINDEF(F, 0)
121         #define F1 PINDEF(F, 1)
122         #define F2 PINDEF(F, 2)
123         #define F3 PINDEF(F, 3)
124         #define F4 PINDEF(F, 4)
125         #define F5 PINDEF(F, 5)
126         #define F6 PINDEF(F, 6)
127         #define F7 PINDEF(F, 7)
128     #endif
129
130 #elif defined(PROTOCOL_CHIBIOS)
131   // Defines mapping for Proton C replacement
132   #ifdef CONVERT_TO_PROTON_C
133     // Left side (front)
134     #define D3 PAL_LINE(GPIOA, 9)
135     #define D2 PAL_LINE(GPIOA, 10)
136     //      GND
137     //      GND
138     #define D1 PAL_LINE(GPIOB, 7)
139     #define D0 PAL_LINE(GPIOB, 6)
140     #define D4 PAL_LINE(GPIOB, 5)
141     #define C6 PAL_LINE(GPIOB, 4)
142     #define D7 PAL_LINE(GPIOB, 3)
143     #define E6 PAL_LINE(GPIOB, 2)
144     #define B4 PAL_LINE(GPIOB, 1)
145     #define B5 PAL_LINE(GPIOB, 0)
146
147     // Right side (front)
148     //      RAW
149     //      GND
150     //      RESET
151     //      VCC
152     #define F4 PAL_LINE(GPIOA, 2)
153     #define F5 PAL_LINE(GPIOA, 1)
154     #define F6 PAL_LINE(GPIOA, 0)
155     #define F7 PAL_LINE(GPIOB, 8)
156     #define B1 PAL_LINE(GPIOB, 13)
157     #define B3 PAL_LINE(GPIOB, 14)
158     #define B2 PAL_LINE(GPIOB, 15)
159     #define B6 PAL_LINE(GPIOB, 9)
160
161     // LEDs (only D5/C13 uses an actual LED)
162     #ifdef CONVERT_TO_PROTON_C_RXLED
163       #define D5 PAL_LINE(GPIOC, 13)
164       #define B0 PAL_LINE(GPIOC, 13)
165     #else
166       #define D5 PAL_LINE(GPIOC, 13)
167       #define B0 PAL_LINE(GPIOC, 14)
168     #endif
169   #else
170     #define A0  PAL_LINE(GPIOA, 0)
171     #define A1  PAL_LINE(GPIOA, 1)
172     #define A2  PAL_LINE(GPIOA, 2)
173     #define A3  PAL_LINE(GPIOA, 3)
174     #define A4  PAL_LINE(GPIOA, 4)
175     #define A5  PAL_LINE(GPIOA, 5)
176     #define A6  PAL_LINE(GPIOA, 6)
177     #define A7  PAL_LINE(GPIOA, 7)
178     #define A8  PAL_LINE(GPIOA, 8)
179     #define A9  PAL_LINE(GPIOA, 9)
180     #define A10 PAL_LINE(GPIOA, 10)
181     #define A11 PAL_LINE(GPIOA, 11)
182     #define A12 PAL_LINE(GPIOA, 12)
183     #define A13 PAL_LINE(GPIOA, 13)
184     #define A14 PAL_LINE(GPIOA, 14)
185     #define A15 PAL_LINE(GPIOA, 15)
186     #define B0  PAL_LINE(GPIOB, 0)
187     #define B1  PAL_LINE(GPIOB, 1)
188     #define B2  PAL_LINE(GPIOB, 2)
189     #define B3  PAL_LINE(GPIOB, 3)
190     #define B4  PAL_LINE(GPIOB, 4)
191     #define B5  PAL_LINE(GPIOB, 5)
192     #define B6  PAL_LINE(GPIOB, 6)
193     #define B7  PAL_LINE(GPIOB, 7)
194     #define B8  PAL_LINE(GPIOB, 8)
195     #define B9  PAL_LINE(GPIOB, 9)
196     #define B10 PAL_LINE(GPIOB, 10)
197     #define B11 PAL_LINE(GPIOB, 11)
198     #define B12 PAL_LINE(GPIOB, 12)
199     #define B13 PAL_LINE(GPIOB, 13)
200     #define B14 PAL_LINE(GPIOB, 14)
201     #define B15 PAL_LINE(GPIOB, 15)
202     #define C0  PAL_LINE(GPIOC, 0)
203     #define C1  PAL_LINE(GPIOC, 1)
204     #define C2  PAL_LINE(GPIOC, 2)
205     #define C3  PAL_LINE(GPIOC, 3)
206     #define C4  PAL_LINE(GPIOC, 4)
207     #define C5  PAL_LINE(GPIOC, 5)
208     #define C6  PAL_LINE(GPIOC, 6)
209     #define C7  PAL_LINE(GPIOC, 7)
210     #define C8  PAL_LINE(GPIOC, 8)
211     #define C9  PAL_LINE(GPIOC, 9)
212     #define C10 PAL_LINE(GPIOC, 10)
213     #define C11 PAL_LINE(GPIOC, 11)
214     #define C12 PAL_LINE(GPIOC, 12)
215     #define C13 PAL_LINE(GPIOC, 13)
216     #define C14 PAL_LINE(GPIOC, 14)
217     #define C15 PAL_LINE(GPIOC, 15)
218     #define D0  PAL_LINE(GPIOD, 0)
219     #define D1  PAL_LINE(GPIOD, 1)
220     #define D2  PAL_LINE(GPIOD, 2)
221     #define D3  PAL_LINE(GPIOD, 3)
222     #define D4  PAL_LINE(GPIOD, 4)
223     #define D5  PAL_LINE(GPIOD, 5)
224     #define D6  PAL_LINE(GPIOD, 6)
225     #define D7  PAL_LINE(GPIOD, 7)
226     #define D8  PAL_LINE(GPIOD, 8)
227     #define D9  PAL_LINE(GPIOD, 9)
228     #define D10 PAL_LINE(GPIOD, 10)
229     #define D11 PAL_LINE(GPIOD, 11)
230     #define D12 PAL_LINE(GPIOD, 12)
231     #define D13 PAL_LINE(GPIOD, 13)
232     #define D14 PAL_LINE(GPIOD, 14)
233     #define D15 PAL_LINE(GPIOD, 15)
234     #define E0  PAL_LINE(GPIOE, 0)
235     #define E1  PAL_LINE(GPIOE, 1)
236     #define E2  PAL_LINE(GPIOE, 2)
237     #define E3  PAL_LINE(GPIOE, 3)
238     #define E4  PAL_LINE(GPIOE, 4)
239     #define E5  PAL_LINE(GPIOE, 5)
240     #define E6  PAL_LINE(GPIOE, 6)
241     #define E7  PAL_LINE(GPIOE, 7)
242     #define E8  PAL_LINE(GPIOE, 8)
243     #define E9  PAL_LINE(GPIOE, 9)
244     #define E10 PAL_LINE(GPIOE, 10)
245     #define E11 PAL_LINE(GPIOE, 11)
246     #define E12 PAL_LINE(GPIOE, 12)
247     #define E13 PAL_LINE(GPIOE, 13)
248     #define E14 PAL_LINE(GPIOE, 14)
249     #define E15 PAL_LINE(GPIOE, 15)
250     #define F0  PAL_LINE(GPIOF, 0)
251     #define F1  PAL_LINE(GPIOF, 1)
252     #define F2  PAL_LINE(GPIOF, 2)
253     #define F3  PAL_LINE(GPIOF, 3)
254     #define F4  PAL_LINE(GPIOF, 4)
255     #define F5  PAL_LINE(GPIOF, 5)
256     #define F6  PAL_LINE(GPIOF, 6)
257     #define F7  PAL_LINE(GPIOF, 7)
258     #define F8  PAL_LINE(GPIOF, 8)
259     #define F9  PAL_LINE(GPIOF, 9)
260     #define F10 PAL_LINE(GPIOF, 10)
261     #define F11 PAL_LINE(GPIOF, 11)
262     #define F12 PAL_LINE(GPIOF, 12)
263     #define F13 PAL_LINE(GPIOF, 13)
264     #define F14 PAL_LINE(GPIOF, 14)
265     #define F15 PAL_LINE(GPIOF, 15)
266   #endif
267 #endif
268
269 /* USART configuration */
270 #ifdef BLUETOOTH_ENABLE
271 #   ifdef __AVR_ATmega32U4__
272 #      define SERIAL_UART_BAUD 9600
273 #      define SERIAL_UART_DATA UDR1
274 #      define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
275 #      define SERIAL_UART_RXD_VECT USART1_RX_vect
276 #      define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
277 #      define SERIAL_UART_INIT() do { \
278             /* baud rate */ \
279             UBRR1L = SERIAL_UART_UBRR; \
280             /* baud rate */ \
281             UBRR1H = SERIAL_UART_UBRR >> 8; \
282             /* enable TX */ \
283             UCSR1B = _BV(TXEN1); \
284             /* 8-bit data */ \
285             UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
286             sei(); \
287         } while(0)
288 #   else
289 #       error "USART configuration is needed."
290 #   endif
291 #endif
292
293 #define API_SYSEX_MAX_SIZE 32
294
295 #include "song_list.h"