config_common.h 12 KB

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