config_common.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. #ifndef CONFIG_DEFINITIONS_H
  17. #define CONFIG_DEFINITIONS_H
  18. /* diode directions */
  19. #define COL2ROW 0
  20. #define ROW2COL 1
  21. #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
  22. #ifdef __AVR__
  23. #include <avr/io.h>
  24. #define LINE_TYPE uint8_t
  25. /* I/O pins */
  26. #ifndef F0
  27. #define B0 0x30
  28. #define B1 0x31
  29. #define B2 0x32
  30. #define B3 0x33
  31. #define B4 0x34
  32. #define B5 0x35
  33. #define B6 0x36
  34. #define B7 0x37
  35. #define C0 0x60
  36. #define C1 0x61
  37. #define C2 0x62
  38. #define C3 0x63
  39. #define C4 0x64
  40. #define C5 0x65
  41. #define C6 0x66
  42. #define C7 0x67
  43. #define D0 0x90
  44. #define D1 0x91
  45. #define D2 0x92
  46. #define D3 0x93
  47. #define D4 0x94
  48. #define D5 0x95
  49. #define D6 0x96
  50. #define D7 0x97
  51. #define E0 0xC0
  52. #define E1 0xC1
  53. #define E2 0xC2
  54. #define E3 0xC3
  55. #define E4 0xC4
  56. #define E5 0xC5
  57. #define E6 0xC6
  58. #define E7 0xC7
  59. #define F0 0xF0
  60. #define F1 0xF1
  61. #define F2 0xF2
  62. #define F3 0xF3
  63. #define F4 0xF4
  64. #define F5 0xF5
  65. #define F6 0xF6
  66. #define F7 0xF7
  67. #define A0 0x00
  68. #define A1 0x01
  69. #define A2 0x02
  70. #define A3 0x03
  71. #define A4 0x04
  72. #define A5 0x05
  73. #define A6 0x06
  74. #define A7 0x07
  75. #endif
  76. #define setPadMode(line, mode) _SFR_IO8((line >> 4) + 1) mode _BV(line & 0xF)
  77. #define setPad(line) _SFR_IO8((line >> 4) + 2) |= _BV(line & 0xF)
  78. #define clearPad(line) _SFR_IO8((line >> 4) + 2) &= ~_BV(line & 0xF)
  79. #define readPad(line) (_SFR_IO8(line >> 4) & _BV(line & 0xF))
  80. #define PAD_MODE_INPUT &= ~
  81. #define PAD_MODE_OUTPUT |=
  82. #else
  83. #include "hal.h"
  84. #define LINE_TYPE ioline_t
  85. #define A0 PAL_LINE(GPIOA, 0)
  86. #define A1 PAL_LINE(GPIOA, 1)
  87. #define A2 PAL_LINE(GPIOA, 2)
  88. #define A3 PAL_LINE(GPIOA, 3)
  89. #define A4 PAL_LINE(GPIOA, 4)
  90. #define A5 PAL_LINE(GPIOA, 5)
  91. #define A6 PAL_LINE(GPIOA, 6)
  92. #define A7 PAL_LINE(GPIOA, 7)
  93. #define A8 PAL_LINE(GPIOA, 8)
  94. #define A9 PAL_LINE(GPIOA, 9)
  95. #define A10 PAL_LINE(GPIOA, 10)
  96. #define A11 PAL_LINE(GPIOA, 11)
  97. #define A12 PAL_LINE(GPIOA, 12)
  98. #define A13 PAL_LINE(GPIOA, 13)
  99. #define A14 PAL_LINE(GPIOA, 14)
  100. #define A15 PAL_LINE(GPIOA, 15)
  101. #define B0 PAL_LINE(GPIOB, 0)
  102. #define B1 PAL_LINE(GPIOB, 1)
  103. #define B2 PAL_LINE(GPIOB, 2)
  104. #define B3 PAL_LINE(GPIOB, 3)
  105. #define B4 PAL_LINE(GPIOB, 4)
  106. #define B5 PAL_LINE(GPIOB, 5)
  107. #define B6 PAL_LINE(GPIOB, 6)
  108. #define B7 PAL_LINE(GPIOB, 7)
  109. #define B8 PAL_LINE(GPIOB, 8)
  110. #define B9 PAL_LINE(GPIOB, 9)
  111. #define B10 PAL_LINE(GPIOB, 10)
  112. #define B11 PAL_LINE(GPIOB, 11)
  113. #define B12 PAL_LINE(GPIOB, 12)
  114. #define B13 PAL_LINE(GPIOB, 13)
  115. #define B14 PAL_LINE(GPIOB, 14)
  116. #define B15 PAL_LINE(GPIOB, 15)
  117. #define C0 PAL_LINE(GPIOC, 0)
  118. #define C1 PAL_LINE(GPIOC, 1)
  119. #define C2 PAL_LINE(GPIOC, 2)
  120. #define C3 PAL_LINE(GPIOC, 3)
  121. #define C4 PAL_LINE(GPIOC, 4)
  122. #define C5 PAL_LINE(GPIOC, 5)
  123. #define C6 PAL_LINE(GPIOC, 6)
  124. #define C7 PAL_LINE(GPIOC, 7)
  125. #define C8 PAL_LINE(GPIOC, 8)
  126. #define C9 PAL_LINE(GPIOC, 9)
  127. #define C10 PAL_LINE(GPIOC, 10)
  128. #define C11 PAL_LINE(GPIOC, 11)
  129. #define C12 PAL_LINE(GPIOC, 12)
  130. #define C13 PAL_LINE(GPIOC, 13)
  131. #define C14 PAL_LINE(GPIOC, 14)
  132. #define C15 PAL_LINE(GPIOC, 15)
  133. #define D0 PAL_LINE(GPIOD, 0)
  134. #define D1 PAL_LINE(GPIOD, 1)
  135. #define D2 PAL_LINE(GPIOD, 2)
  136. #define D3 PAL_LINE(GPIOD, 3)
  137. #define D4 PAL_LINE(GPIOD, 4)
  138. #define D5 PAL_LINE(GPIOD, 5)
  139. #define D6 PAL_LINE(GPIOD, 6)
  140. #define D7 PAL_LINE(GPIOD, 7)
  141. #define D8 PAL_LINE(GPIOD, 8)
  142. #define D9 PAL_LINE(GPIOD, 9)
  143. #define D10 PAL_LINE(GPIOD, 10)
  144. #define D11 PAL_LINE(GPIOD, 11)
  145. #define D12 PAL_LINE(GPIOD, 12)
  146. #define D13 PAL_LINE(GPIOD, 13)
  147. #define D14 PAL_LINE(GPIOD, 14)
  148. #define D15 PAL_LINE(GPIOD, 15)
  149. #define E0 PAL_LINE(GPIOE, 0)
  150. #define E1 PAL_LINE(GPIOE, 1)
  151. #define E2 PAL_LINE(GPIOE, 2)
  152. #define E3 PAL_LINE(GPIOE, 3)
  153. #define E4 PAL_LINE(GPIOE, 4)
  154. #define E5 PAL_LINE(GPIOE, 5)
  155. #define E6 PAL_LINE(GPIOE, 6)
  156. #define E7 PAL_LINE(GPIOE, 7)
  157. #define E8 PAL_LINE(GPIOE, 8)
  158. #define E9 PAL_LINE(GPIOE, 9)
  159. #define E10 PAL_LINE(GPIOE, 10)
  160. #define E11 PAL_LINE(GPIOE, 11)
  161. #define E12 PAL_LINE(GPIOE, 12)
  162. #define E13 PAL_LINE(GPIOE, 13)
  163. #define E14 PAL_LINE(GPIOE, 14)
  164. #define E15 PAL_LINE(GPIOE, 15)
  165. #define F0 PAL_LINE(GPIOF, 0)
  166. #define F1 PAL_LINE(GPIOF, 1)
  167. #define F2 PAL_LINE(GPIOF, 2)
  168. #define F3 PAL_LINE(GPIOF, 3)
  169. #define F4 PAL_LINE(GPIOF, 4)
  170. #define F5 PAL_LINE(GPIOF, 5)
  171. #define F6 PAL_LINE(GPIOF, 6)
  172. #define F7 PAL_LINE(GPIOF, 7)
  173. #define F8 PAL_LINE(GPIOF, 8)
  174. #define F9 PAL_LINE(GPIOF, 9)
  175. #define F10 PAL_LINE(GPIOF, 10)
  176. #define F11 PAL_LINE(GPIOF, 11)
  177. #define F12 PAL_LINE(GPIOF, 12)
  178. #define F13 PAL_LINE(GPIOF, 13)
  179. #define F14 PAL_LINE(GPIOF, 14)
  180. #define F15 PAL_LINE(GPIOF, 15)
  181. #define setPadMode(line, mode) palSetPadMode(PAL_PORT(line), PAL_PAD(line), mode)
  182. #define setPad(line) palSetPad(PAL_PORT(line), PAL_PAD(line))
  183. #define clearPad(line) palClearPad(PAL_PORT(line), PAL_PAD(line))
  184. #define readPad(line) palReadPad(PAL_PORT(line), PAL_PAD(line))
  185. #define PAD_MODE_INPUT PAL_MODE_INPUT_PULLUP
  186. #endif
  187. /* USART configuration */
  188. #ifdef BLUETOOTH_ENABLE
  189. # ifdef __AVR_ATmega32U4__
  190. # define SERIAL_UART_BAUD 9600
  191. # define SERIAL_UART_DATA UDR1
  192. # define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
  193. # define SERIAL_UART_RXD_VECT USART1_RX_vect
  194. # define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
  195. # define SERIAL_UART_INIT() do { \
  196. /* baud rate */ \
  197. UBRR1L = SERIAL_UART_UBRR; \
  198. /* baud rate */ \
  199. UBRR1H = SERIAL_UART_UBRR >> 8; \
  200. /* enable TX */ \
  201. UCSR1B = _BV(TXEN1); \
  202. /* 8-bit data */ \
  203. UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
  204. sei(); \
  205. } while(0)
  206. # else
  207. # error "USART configuration is needed."
  208. # endif
  209. #endif
  210. #define API_SYSEX_MAX_SIZE 32
  211. #include "song_list.h"
  212. #endif