config_common.h 12 KB

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