1 /* Copyright 2015-2018 Jack Humbert
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.
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.
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/>.
19 /* diode directions */
22 #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
28 #define PORT_SHIFTER 4 // this may be 4 for all AVR chips
30 // If you want to add more to this list, reference the PINx definitions in these header
31 // files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr
33 #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__)
34 #define ADDRESS_BASE 0x00
35 #define PINB_ADDRESS 0x3
36 #define PINC_ADDRESS 0x6
37 #define PIND_ADDRESS 0x9
38 #define PINE_ADDRESS 0xC
39 #define PINF_ADDRESS 0xF
40 #elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__)
41 #define ADDRESS_BASE 0x00
42 #define PINB_ADDRESS 0x3
43 #define PINC_ADDRESS 0x6
44 #define PIND_ADDRESS 0x9
45 #elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__)
46 #define ADDRESS_BASE 0x00
47 #define PINA_ADDRESS 0x0
48 #define PINB_ADDRESS 0x3
49 #define PINC_ADDRESS 0x6
50 #define PIND_ADDRESS 0x9
51 #define PINE_ADDRESS 0xC
52 #define PINF_ADDRESS 0xF
53 #elif defined(__AVR_ATmega32A__)
54 #define ADDRESS_BASE 0x10
55 #define PIND_ADDRESS 0x0
56 #define PINC_ADDRESS 0x3
57 #define PINB_ADDRESS 0x6
58 #define PINA_ADDRESS 0x9
60 #error "Pins are not defined"
64 #define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
67 #define A0 PINDEF(A, 0)
68 #define A1 PINDEF(A, 1)
69 #define A2 PINDEF(A, 2)
70 #define A3 PINDEF(A, 3)
71 #define A4 PINDEF(A, 4)
72 #define A5 PINDEF(A, 5)
73 #define A6 PINDEF(A, 6)
74 #define A7 PINDEF(A, 7)
77 #define B0 PINDEF(B, 0)
78 #define B1 PINDEF(B, 1)
79 #define B2 PINDEF(B, 2)
80 #define B3 PINDEF(B, 3)
81 #define B4 PINDEF(B, 4)
82 #define B5 PINDEF(B, 5)
83 #define B6 PINDEF(B, 6)
84 #define B7 PINDEF(B, 7)
87 #define C0 PINDEF(C, 0)
88 #define C1 PINDEF(C, 1)
89 #define C2 PINDEF(C, 2)
90 #define C3 PINDEF(C, 3)
91 #define C4 PINDEF(C, 4)
92 #define C5 PINDEF(C, 5)
93 #define C6 PINDEF(C, 6)
94 #define C7 PINDEF(C, 7)
97 #define D0 PINDEF(D, 0)
98 #define D1 PINDEF(D, 1)
99 #define D2 PINDEF(D, 2)
100 #define D3 PINDEF(D, 3)
101 #define D4 PINDEF(D, 4)
102 #define D5 PINDEF(D, 5)
103 #define D6 PINDEF(D, 6)
104 #define D7 PINDEF(D, 7)
107 #define E0 PINDEF(E, 0)
108 #define E1 PINDEF(E, 1)
109 #define E2 PINDEF(E, 2)
110 #define E3 PINDEF(E, 3)
111 #define E4 PINDEF(E, 4)
112 #define E5 PINDEF(E, 5)
113 #define E6 PINDEF(E, 6)
114 #define E7 PINDEF(E, 7)
117 #define F0 PINDEF(F, 0)
118 #define F1 PINDEF(F, 1)
119 #define F2 PINDEF(F, 2)
120 #define F3 PINDEF(F, 3)
121 #define F4 PINDEF(F, 4)
122 #define F5 PINDEF(F, 5)
123 #define F6 PINDEF(F, 6)
124 #define F7 PINDEF(F, 7)
127 #elif defined(PROTOCOL_CHIBIOS)
128 // Defines mapping for Proton C replacement
129 #ifdef CONVERT_TO_PROTON_C
131 #define D3 PAL_LINE(GPIOA, 9)
132 #define D2 PAL_LINE(GPIOA, 10)
135 #define D1 PAL_LINE(GPIOB, 7)
136 #define D0 PAL_LINE(GPIOB, 6)
137 #define D4 PAL_LINE(GPIOB, 5)
138 #define C6 PAL_LINE(GPIOB, 4)
139 #define D7 PAL_LINE(GPIOB, 3)
140 #define E6 PAL_LINE(GPIOB, 2)
141 #define B4 PAL_LINE(GPIOB, 1)
142 #define B5 PAL_LINE(GPIOB, 0)
144 // Right side (front)
149 #define F4 PAL_LINE(GPIOA, 2)
150 #define F5 PAL_LINE(GPIOA, 1)
151 #define F6 PAL_LINE(GPIOA, 0)
152 #define F7 PAL_LINE(GPIOB, 8)
153 #define B1 PAL_LINE(GPIOB, 13)
154 #define B3 PAL_LINE(GPIOB, 14)
155 #define B2 PAL_LINE(GPIOB, 15)
156 #define B6 PAL_LINE(GPIOB, 9)
158 // LEDs (only D5/C13 uses an actual LED)
159 #ifdef CONVERT_TO_PROTON_C_RXLED
160 #define D5 PAL_LINE(GPIOC, 13)
161 #define B0 PAL_LINE(GPIOC, 13)
163 #define D5 PAL_LINE(GPIOC, 13)
164 #define B0 PAL_LINE(GPIOC, 14)
167 #define A0 PAL_LINE(GPIOA, 0)
168 #define A1 PAL_LINE(GPIOA, 1)
169 #define A2 PAL_LINE(GPIOA, 2)
170 #define A3 PAL_LINE(GPIOA, 3)
171 #define A4 PAL_LINE(GPIOA, 4)
172 #define A5 PAL_LINE(GPIOA, 5)
173 #define A6 PAL_LINE(GPIOA, 6)
174 #define A7 PAL_LINE(GPIOA, 7)
175 #define A8 PAL_LINE(GPIOA, 8)
176 #define A9 PAL_LINE(GPIOA, 9)
177 #define A10 PAL_LINE(GPIOA, 10)
178 #define A11 PAL_LINE(GPIOA, 11)
179 #define A12 PAL_LINE(GPIOA, 12)
180 #define A13 PAL_LINE(GPIOA, 13)
181 #define A14 PAL_LINE(GPIOA, 14)
182 #define A15 PAL_LINE(GPIOA, 15)
183 #define B0 PAL_LINE(GPIOB, 0)
184 #define B1 PAL_LINE(GPIOB, 1)
185 #define B2 PAL_LINE(GPIOB, 2)
186 #define B3 PAL_LINE(GPIOB, 3)
187 #define B4 PAL_LINE(GPIOB, 4)
188 #define B5 PAL_LINE(GPIOB, 5)
189 #define B6 PAL_LINE(GPIOB, 6)
190 #define B7 PAL_LINE(GPIOB, 7)
191 #define B8 PAL_LINE(GPIOB, 8)
192 #define B9 PAL_LINE(GPIOB, 9)
193 #define B10 PAL_LINE(GPIOB, 10)
194 #define B11 PAL_LINE(GPIOB, 11)
195 #define B12 PAL_LINE(GPIOB, 12)
196 #define B13 PAL_LINE(GPIOB, 13)
197 #define B14 PAL_LINE(GPIOB, 14)
198 #define B15 PAL_LINE(GPIOB, 15)
199 #define C0 PAL_LINE(GPIOC, 0)
200 #define C1 PAL_LINE(GPIOC, 1)
201 #define C2 PAL_LINE(GPIOC, 2)
202 #define C3 PAL_LINE(GPIOC, 3)
203 #define C4 PAL_LINE(GPIOC, 4)
204 #define C5 PAL_LINE(GPIOC, 5)
205 #define C6 PAL_LINE(GPIOC, 6)
206 #define C7 PAL_LINE(GPIOC, 7)
207 #define C8 PAL_LINE(GPIOC, 8)
208 #define C9 PAL_LINE(GPIOC, 9)
209 #define C10 PAL_LINE(GPIOC, 10)
210 #define C11 PAL_LINE(GPIOC, 11)
211 #define C12 PAL_LINE(GPIOC, 12)
212 #define C13 PAL_LINE(GPIOC, 13)
213 #define C14 PAL_LINE(GPIOC, 14)
214 #define C15 PAL_LINE(GPIOC, 15)
215 #define D0 PAL_LINE(GPIOD, 0)
216 #define D1 PAL_LINE(GPIOD, 1)
217 #define D2 PAL_LINE(GPIOD, 2)
218 #define D3 PAL_LINE(GPIOD, 3)
219 #define D4 PAL_LINE(GPIOD, 4)
220 #define D5 PAL_LINE(GPIOD, 5)
221 #define D6 PAL_LINE(GPIOD, 6)
222 #define D7 PAL_LINE(GPIOD, 7)
223 #define D8 PAL_LINE(GPIOD, 8)
224 #define D9 PAL_LINE(GPIOD, 9)
225 #define D10 PAL_LINE(GPIOD, 10)
226 #define D11 PAL_LINE(GPIOD, 11)
227 #define D12 PAL_LINE(GPIOD, 12)
228 #define D13 PAL_LINE(GPIOD, 13)
229 #define D14 PAL_LINE(GPIOD, 14)
230 #define D15 PAL_LINE(GPIOD, 15)
231 #define E0 PAL_LINE(GPIOE, 0)
232 #define E1 PAL_LINE(GPIOE, 1)
233 #define E2 PAL_LINE(GPIOE, 2)
234 #define E3 PAL_LINE(GPIOE, 3)
235 #define E4 PAL_LINE(GPIOE, 4)
236 #define E5 PAL_LINE(GPIOE, 5)
237 #define E6 PAL_LINE(GPIOE, 6)
238 #define E7 PAL_LINE(GPIOE, 7)
239 #define E8 PAL_LINE(GPIOE, 8)
240 #define E9 PAL_LINE(GPIOE, 9)
241 #define E10 PAL_LINE(GPIOE, 10)
242 #define E11 PAL_LINE(GPIOE, 11)
243 #define E12 PAL_LINE(GPIOE, 12)
244 #define E13 PAL_LINE(GPIOE, 13)
245 #define E14 PAL_LINE(GPIOE, 14)
246 #define E15 PAL_LINE(GPIOE, 15)
247 #define F0 PAL_LINE(GPIOF, 0)
248 #define F1 PAL_LINE(GPIOF, 1)
249 #define F2 PAL_LINE(GPIOF, 2)
250 #define F3 PAL_LINE(GPIOF, 3)
251 #define F4 PAL_LINE(GPIOF, 4)
252 #define F5 PAL_LINE(GPIOF, 5)
253 #define F6 PAL_LINE(GPIOF, 6)
254 #define F7 PAL_LINE(GPIOF, 7)
255 #define F8 PAL_LINE(GPIOF, 8)
256 #define F9 PAL_LINE(GPIOF, 9)
257 #define F10 PAL_LINE(GPIOF, 10)
258 #define F11 PAL_LINE(GPIOF, 11)
259 #define F12 PAL_LINE(GPIOF, 12)
260 #define F13 PAL_LINE(GPIOF, 13)
261 #define F14 PAL_LINE(GPIOF, 14)
262 #define F15 PAL_LINE(GPIOF, 15)
266 /* USART configuration */
267 #ifdef BLUETOOTH_ENABLE
268 # ifdef __AVR_ATmega32U4__
269 # define SERIAL_UART_BAUD 9600
270 # define SERIAL_UART_DATA UDR1
271 # define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
272 # define SERIAL_UART_RXD_VECT USART1_RX_vect
273 # define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
274 # define SERIAL_UART_INIT() do { \
276 UBRR1L = SERIAL_UART_UBRR; \
278 UBRR1H = SERIAL_UART_UBRR >> 8; \
280 UCSR1B = _BV(TXEN1); \
282 UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
286 # error "USART configuration is needed."
290 #define API_SYSEX_MAX_SIZE 32
292 #include "song_list.h"