config_common.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
  21. #ifdef __AVR__
  22. #ifndef __ASSEMBLER__
  23. #include <avr/io.h>
  24. #endif
  25. #define PORT_SHIFTER 4 // this may be 4 for all AVR chips
  26. // If you want to add more to this list, reference the PINx definitions in these header
  27. // files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr
  28. #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__)
  29. #define ADDRESS_BASE 0x00
  30. #define PINB_ADDRESS 0x3
  31. #define PINC_ADDRESS 0x6
  32. #define PIND_ADDRESS 0x9
  33. #define PINE_ADDRESS 0xC
  34. #define PINF_ADDRESS 0xF
  35. #elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__)
  36. #define ADDRESS_BASE 0x00
  37. #define PINB_ADDRESS 0x3
  38. #define PINC_ADDRESS 0x6
  39. #define PIND_ADDRESS 0x9
  40. #elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__)
  41. #define ADDRESS_BASE 0x00
  42. #define PINA_ADDRESS 0x0
  43. #define PINB_ADDRESS 0x3
  44. #define PINC_ADDRESS 0x6
  45. #define PIND_ADDRESS 0x9
  46. #define PINE_ADDRESS 0xC
  47. #define PINF_ADDRESS 0xF
  48. #elif defined(__AVR_ATmega32A__)
  49. #define ADDRESS_BASE 0x10
  50. #define PIND_ADDRESS 0x0
  51. #define PINC_ADDRESS 0x3
  52. #define PINB_ADDRESS 0x6
  53. #define PINA_ADDRESS 0x9
  54. #else
  55. #error "Pins are not defined"
  56. #endif
  57. /* I/O pins */
  58. #define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
  59. #ifdef PORTA
  60. #define A0 PINDEF(A, 0)
  61. #define A1 PINDEF(A, 1)
  62. #define A2 PINDEF(A, 2)
  63. #define A3 PINDEF(A, 3)
  64. #define A4 PINDEF(A, 4)
  65. #define A5 PINDEF(A, 5)
  66. #define A6 PINDEF(A, 6)
  67. #define A7 PINDEF(A, 7)
  68. #endif
  69. #ifdef PORTB
  70. #define B0 PINDEF(B, 0)
  71. #define B1 PINDEF(B, 1)
  72. #define B2 PINDEF(B, 2)
  73. #define B3 PINDEF(B, 3)
  74. #define B4 PINDEF(B, 4)
  75. #define B5 PINDEF(B, 5)
  76. #define B6 PINDEF(B, 6)
  77. #define B7 PINDEF(B, 7)
  78. #endif
  79. #ifdef PORTC
  80. #define C0 PINDEF(C, 0)
  81. #define C1 PINDEF(C, 1)
  82. #define C2 PINDEF(C, 2)
  83. #define C3 PINDEF(C, 3)
  84. #define C4 PINDEF(C, 4)
  85. #define C5 PINDEF(C, 5)
  86. #define C6 PINDEF(C, 6)
  87. #define C7 PINDEF(C, 7)
  88. #endif
  89. #ifdef PORTD
  90. #define D0 PINDEF(D, 0)
  91. #define D1 PINDEF(D, 1)
  92. #define D2 PINDEF(D, 2)
  93. #define D3 PINDEF(D, 3)
  94. #define D4 PINDEF(D, 4)
  95. #define D5 PINDEF(D, 5)
  96. #define D6 PINDEF(D, 6)
  97. #define D7 PINDEF(D, 7)
  98. #endif
  99. #ifdef PORTE
  100. #define E0 PINDEF(E, 0)
  101. #define E1 PINDEF(E, 1)
  102. #define E2 PINDEF(E, 2)
  103. #define E3 PINDEF(E, 3)
  104. #define E4 PINDEF(E, 4)
  105. #define E5 PINDEF(E, 5)
  106. #define E6 PINDEF(E, 6)
  107. #define E7 PINDEF(E, 7)
  108. #endif
  109. #ifdef PORTF
  110. #define F0 PINDEF(F, 0)
  111. #define F1 PINDEF(F, 1)
  112. #define F2 PINDEF(F, 2)
  113. #define F3 PINDEF(F, 3)
  114. #define F4 PINDEF(F, 4)
  115. #define F5 PINDEF(F, 5)
  116. #define F6 PINDEF(F, 6)
  117. #define F7 PINDEF(F, 7)
  118. #endif
  119. #elif defined(PROTOCOL_CHIBIOS)
  120. #define A0 PAL_LINE(GPIOA, 0)
  121. #define A1 PAL_LINE(GPIOA, 1)
  122. #define A2 PAL_LINE(GPIOA, 2)
  123. #define A3 PAL_LINE(GPIOA, 3)
  124. #define A4 PAL_LINE(GPIOA, 4)
  125. #define A5 PAL_LINE(GPIOA, 5)
  126. #define A6 PAL_LINE(GPIOA, 6)
  127. #define A7 PAL_LINE(GPIOA, 7)
  128. #define A8 PAL_LINE(GPIOA, 8)
  129. #define A9 PAL_LINE(GPIOA, 9)
  130. #define A10 PAL_LINE(GPIOA, 10)
  131. #define A11 PAL_LINE(GPIOA, 11)
  132. #define A12 PAL_LINE(GPIOA, 12)
  133. #define A13 PAL_LINE(GPIOA, 13)
  134. #define A14 PAL_LINE(GPIOA, 14)
  135. #define A15 PAL_LINE(GPIOA, 15)
  136. #define B0 PAL_LINE(GPIOB, 0)
  137. #define B1 PAL_LINE(GPIOB, 1)
  138. #define B2 PAL_LINE(GPIOB, 2)
  139. #define B3 PAL_LINE(GPIOB, 3)
  140. #define B4 PAL_LINE(GPIOB, 4)
  141. #define B5 PAL_LINE(GPIOB, 5)
  142. #define B6 PAL_LINE(GPIOB, 6)
  143. #define B7 PAL_LINE(GPIOB, 7)
  144. #define B8 PAL_LINE(GPIOB, 8)
  145. #define B9 PAL_LINE(GPIOB, 9)
  146. #define B10 PAL_LINE(GPIOB, 10)
  147. #define B11 PAL_LINE(GPIOB, 11)
  148. #define B12 PAL_LINE(GPIOB, 12)
  149. #define B13 PAL_LINE(GPIOB, 13)
  150. #define B14 PAL_LINE(GPIOB, 14)
  151. #define B15 PAL_LINE(GPIOB, 15)
  152. #define C0 PAL_LINE(GPIOC, 0)
  153. #define C1 PAL_LINE(GPIOC, 1)
  154. #define C2 PAL_LINE(GPIOC, 2)
  155. #define C3 PAL_LINE(GPIOC, 3)
  156. #define C4 PAL_LINE(GPIOC, 4)
  157. #define C5 PAL_LINE(GPIOC, 5)
  158. #define C6 PAL_LINE(GPIOC, 6)
  159. #define C7 PAL_LINE(GPIOC, 7)
  160. #define C8 PAL_LINE(GPIOC, 8)
  161. #define C9 PAL_LINE(GPIOC, 9)
  162. #define C10 PAL_LINE(GPIOC, 10)
  163. #define C11 PAL_LINE(GPIOC, 11)
  164. #define C12 PAL_LINE(GPIOC, 12)
  165. #define C13 PAL_LINE(GPIOC, 13)
  166. #define C14 PAL_LINE(GPIOC, 14)
  167. #define C15 PAL_LINE(GPIOC, 15)
  168. #define D0 PAL_LINE(GPIOD, 0)
  169. #define D1 PAL_LINE(GPIOD, 1)
  170. #define D2 PAL_LINE(GPIOD, 2)
  171. #define D3 PAL_LINE(GPIOD, 3)
  172. #define D4 PAL_LINE(GPIOD, 4)
  173. #define D5 PAL_LINE(GPIOD, 5)
  174. #define D6 PAL_LINE(GPIOD, 6)
  175. #define D7 PAL_LINE(GPIOD, 7)
  176. #define D8 PAL_LINE(GPIOD, 8)
  177. #define D9 PAL_LINE(GPIOD, 9)
  178. #define D10 PAL_LINE(GPIOD, 10)
  179. #define D11 PAL_LINE(GPIOD, 11)
  180. #define D12 PAL_LINE(GPIOD, 12)
  181. #define D13 PAL_LINE(GPIOD, 13)
  182. #define D14 PAL_LINE(GPIOD, 14)
  183. #define D15 PAL_LINE(GPIOD, 15)
  184. #define E0 PAL_LINE(GPIOE, 0)
  185. #define E1 PAL_LINE(GPIOE, 1)
  186. #define E2 PAL_LINE(GPIOE, 2)
  187. #define E3 PAL_LINE(GPIOE, 3)
  188. #define E4 PAL_LINE(GPIOE, 4)
  189. #define E5 PAL_LINE(GPIOE, 5)
  190. #define E6 PAL_LINE(GPIOE, 6)
  191. #define E7 PAL_LINE(GPIOE, 7)
  192. #define E8 PAL_LINE(GPIOE, 8)
  193. #define E9 PAL_LINE(GPIOE, 9)
  194. #define E10 PAL_LINE(GPIOE, 10)
  195. #define E11 PAL_LINE(GPIOE, 11)
  196. #define E12 PAL_LINE(GPIOE, 12)
  197. #define E13 PAL_LINE(GPIOE, 13)
  198. #define E14 PAL_LINE(GPIOE, 14)
  199. #define E15 PAL_LINE(GPIOE, 15)
  200. #define F0 PAL_LINE(GPIOF, 0)
  201. #define F1 PAL_LINE(GPIOF, 1)
  202. #define F2 PAL_LINE(GPIOF, 2)
  203. #define F3 PAL_LINE(GPIOF, 3)
  204. #define F4 PAL_LINE(GPIOF, 4)
  205. #define F5 PAL_LINE(GPIOF, 5)
  206. #define F6 PAL_LINE(GPIOF, 6)
  207. #define F7 PAL_LINE(GPIOF, 7)
  208. #define F8 PAL_LINE(GPIOF, 8)
  209. #define F9 PAL_LINE(GPIOF, 9)
  210. #define F10 PAL_LINE(GPIOF, 10)
  211. #define F11 PAL_LINE(GPIOF, 11)
  212. #define F12 PAL_LINE(GPIOF, 12)
  213. #define F13 PAL_LINE(GPIOF, 13)
  214. #define F14 PAL_LINE(GPIOF, 14)
  215. #define F15 PAL_LINE(GPIOF, 15)
  216. #endif
  217. /* USART configuration */
  218. #ifdef BLUETOOTH_ENABLE
  219. # ifdef __AVR_ATmega32U4__
  220. # define SERIAL_UART_BAUD 9600
  221. # define SERIAL_UART_DATA UDR1
  222. # define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
  223. # define SERIAL_UART_RXD_VECT USART1_RX_vect
  224. # define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
  225. # define SERIAL_UART_INIT() do { \
  226. /* baud rate */ \
  227. UBRR1L = SERIAL_UART_UBRR; \
  228. /* baud rate */ \
  229. UBRR1H = SERIAL_UART_UBRR >> 8; \
  230. /* enable TX */ \
  231. UCSR1B = _BV(TXEN1); \
  232. /* 8-bit data */ \
  233. UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
  234. sei(); \
  235. } while(0)
  236. # else
  237. # error "USART configuration is needed."
  238. # endif
  239. #endif
  240. #define API_SYSEX_MAX_SIZE 32
  241. #include "song_list.h"