config_common.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* Copyright 2015-2017 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. #if defined(__AVR__)
  23. #include <avr/io.h>
  24. #define PORT_SHIFTER 4
  25. #if defined(__AVR_ATmega32U4__)
  26. #define pin_t uint8_t
  27. #define ADDRESS_BASE 0x00
  28. #define PINB_ADDRESS 0x3
  29. #define PINC_ADDRESS 0x6
  30. #define PIND_ADDRESS 0x9
  31. #define PINE_ADDRESS 0xC
  32. #define PINF_ADDRESS 0xF
  33. #elif defined(__AVR_ATmega32U2__)
  34. #define pin_t uint8_t
  35. #define ADDRESS_BASE 0x00
  36. #define PINB_ADDRESS 0x3
  37. #define PINC_ADDRESS 0x6
  38. #define PIND_ADDRESS 0x9
  39. #elif defined(__AVR_AT90USB1286__)
  40. #define pin_t uint8_t
  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 pin_t uint8_t
  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. #else
  56. #define pin_t uint16_t
  57. #define ADDRESS_BASE 0x0
  58. #endif
  59. /* I/O pins */
  60. // #define PINDEF(port, pin) (uint8_t)((((uint16_t)&PIN##port) << 4) + PIN##port##pin)
  61. //#define PINDEF(port, pin) ((pin_t)(((((uint16_t)&PIN##port) - __SFR_OFFSET)<< 4) + PIN##port##pin))
  62. #define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
  63. #ifdef PORTA
  64. #define A0 PINDEF(A, 0)
  65. #define A1 PINDEF(A, 1)
  66. #define A2 PINDEF(A, 1)
  67. #define A3 PINDEF(A, 3)
  68. #define A4 PINDEF(A, 4)
  69. #define A5 PINDEF(A, 5)
  70. #define A6 PINDEF(A, 6)
  71. #define A7 PINDEF(A, 7)
  72. #endif
  73. #ifdef PORTB
  74. #define B0 PINDEF(B, 0)
  75. #define B1 PINDEF(B, 1)
  76. #define B2 PINDEF(B, 2)
  77. #define B3 PINDEF(B, 3)
  78. #define B4 PINDEF(B, 4)
  79. #define B5 PINDEF(B, 5)
  80. #define B6 PINDEF(B, 6)
  81. #define B7 PINDEF(B, 7)
  82. #endif
  83. #ifdef PORTC
  84. #define C0 PINDEF(C, 0)
  85. #define C1 PINDEF(C, 1)
  86. #define C2 PINDEF(C, 2)
  87. #define C3 PINDEF(C, 3)
  88. #define C4 PINDEF(C, 4)
  89. #define C5 PINDEF(C, 5)
  90. #define C6 PINDEF(C, 6)
  91. #define C7 PINDEF(C, 7)
  92. #endif
  93. #ifdef PORTD
  94. #define D0 PINDEF(D, 0)
  95. #define D1 PINDEF(D, 1)
  96. #define D2 PINDEF(D, 2)
  97. #define D3 PINDEF(D, 3)
  98. #define D4 PINDEF(D, 4)
  99. #define D5 PINDEF(D, 5)
  100. #define D6 PINDEF(D, 6)
  101. #define D7 PINDEF(D, 7)
  102. #endif
  103. #ifdef PORTE
  104. #define E0 PINDEF(E, 0)
  105. #define E1 PINDEF(E, 1)
  106. #define E2 PINDEF(E, 2)
  107. #define E3 PINDEF(E, 3)
  108. #define E4 PINDEF(E, 4)
  109. #define E5 PINDEF(E, 5)
  110. #define E6 PINDEF(E, 6)
  111. #define E7 PINDEF(E, 7)
  112. #endif
  113. #ifdef PORTF
  114. #define F0 PINDEF(F, 0)
  115. #define F1 PINDEF(F, 1)
  116. #define F2 PINDEF(F, 2)
  117. #define F3 PINDEF(F, 3)
  118. #define F4 PINDEF(F, 4)
  119. #define F5 PINDEF(F, 5)
  120. #define F6 PINDEF(F, 6)
  121. #define F7 PINDEF(F, 7)
  122. #endif
  123. #endif
  124. #if defined(PROTOCOL_CHIBIOS)
  125. #include "hal.h"
  126. #define pin_t uint64_t
  127. #ifdef GPIOA
  128. #define A0 (GPIOA + 0)
  129. #define A1 (GPIOA + 1)
  130. #define A2 (GPIOA + 2)
  131. #define A3 (GPIOA + 3)
  132. #define A4 (GPIOA + 4)
  133. #define A5 (GPIOA + 5)
  134. #define A6 (GPIOA + 6)
  135. #define A7 (GPIOA + 7)
  136. #define A8 (GPIOA + 8)
  137. #define A9 (GPIOA + 9)
  138. #define A10 (GPIOA + 10)
  139. #define A11 (GPIOA + 11)
  140. #define A12 (GPIOA + 12)
  141. #define A13 (GPIOA + 13)
  142. #define A14 (GPIOA + 14)
  143. #define A15 (GPIOA + 15)
  144. #endif
  145. #ifdef GPIOB
  146. #define B0 (GPIOB + 0)
  147. #define B1 (GPIOB + 1)
  148. #define B2 (GPIOB + 2)
  149. #define B3 (GPIOB + 3)
  150. #define B4 (GPIOB + 4)
  151. #define B5 (GPIOB + 5)
  152. #define B6 (GPIOB + 6)
  153. #define B7 (GPIOB + 7)
  154. #define B8 (GPIOB + 8)
  155. #define B9 (GPIOB + 9)
  156. #define B10 (GPIOB + 10)
  157. #define B11 (GPIOB + 11)
  158. #define B12 (GPIOB + 12)
  159. #define B13 (GPIOB + 13)
  160. #define B14 (GPIOB + 14)
  161. #define B15 (GPIOB + 15)
  162. #endif
  163. #ifdef GPIOC
  164. #define C0 (GPIOC + 0)
  165. #define C1 (GPIOC + 1)
  166. #define C2 (GPIOC + 2)
  167. #define C3 (GPIOC + 3)
  168. #define C4 (GPIOC + 4)
  169. #define C5 (GPIOC + 5)
  170. #define C6 (GPIOC + 6)
  171. #define C7 (GPIOC + 7)
  172. #define C8 (GPIOC + 8)
  173. #define C9 (GPIOC + 9)
  174. #define C10 (GPIOC + 10)
  175. #define C11 (GPIOC + 11)
  176. #define C12 (GPIOC + 12)
  177. #define C13 (GPIOC + 13)
  178. #define C14 (GPIOC + 14)
  179. #define C15 (GPIOC + 15)
  180. #endif
  181. #endif
  182. /* USART configuration */
  183. #ifdef BLUETOOTH_ENABLE
  184. # ifdef __AVR_ATmega32U4__
  185. # define SERIAL_UART_BAUD 9600
  186. # define SERIAL_UART_DATA UDR1
  187. # define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
  188. # define SERIAL_UART_RXD_VECT USART1_RX_vect
  189. # define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
  190. # define SERIAL_UART_INIT() do { \
  191. /* baud rate */ \
  192. UBRR1L = SERIAL_UART_UBRR; \
  193. /* baud rate */ \
  194. UBRR1H = SERIAL_UART_UBRR >> 8; \
  195. /* enable TX */ \
  196. UCSR1B = _BV(TXEN1); \
  197. /* 8-bit data */ \
  198. UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
  199. sei(); \
  200. } while(0)
  201. # else
  202. # error "USART configuration is needed."
  203. # endif
  204. #endif
  205. #define API_SYSEX_MAX_SIZE 32
  206. #include "song_list.h"
  207. #endif