You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

295 lines
9.2 KiB

8 years ago
Simplify split_common Code significantly (#4772) * Eliminate separate slave loop Both master and slave run the standard keyboard_task main loop now. * Refactor i2c/serial specific code Simplify some of the preprocessor mess by using common function names. * Fix missing #endif * Move direct pin mapping support from miniaxe to split_common For boards with more pins than sense--sorry, switches. * Reordering and reformatting only * Don't run matrix_scan_quantum on slave side * Clean up the offset/slaveOffset calculations * Cut undebounced matrix size in half * Refactor debouncing * Minor fixups * Split split_common transport and debounce code into their own files Can now be replaced with custom versions per keyboard using CUSTOM_TRANSPORT = yes and CUSTOM_DEBOUNCE = yes * Refactor debounce for non-split keyboards too * Update handwired/xealous to build using new split_common * Fix debounce breaking basic test * Dodgy method to allow a split kb to only include one of i2c/serial SPLIT_TRANSPORT = serial or SPLIT_TRANSPORT = i2c will include only that driver code in the binary. SPLIT_TRANSPORT = custom (or anything else) will include neither, the keyboard must supply it's own code if SPLIT_TRANSPORT is not defined then the original behaviour (include both avr i2c and serial code) is maintained. This could be better but it would require explicitly updating all the existing split keyboards. * Enable LTO to get lets_split/sockets under the line * Add docs for SPLIT_TRANSPORT, CUSTOM_MATRIX, CUSTOM_DEBOUNCE * Remove avr-specific sei() from split matrix_setup Not needed now that slave doesn't have a separate main loop. Both sides (on avr) call sei() in lufa's main() after exiting keyboard_setup(). * Fix QUANTUM_LIB_SRC references and simplify SPLIT_TRANSPORT. * Add comments and fix formatting.
5 years ago
8 years ago
8 years ago
8 years ago
  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. // useful for direct pin mapping
  22. #define NO_PIN (~0)
  23. #ifdef __AVR__
  24. #ifndef __ASSEMBLER__
  25. #include <avr/io.h>
  26. #endif
  27. #define PORT_SHIFTER 4 // this may be 4 for all AVR chips
  28. // If you want to add more to this list, reference the PINx definitions in these header
  29. // files: https://github.com/vancegroup-mirrors/avr-libc/tree/master/avr-libc/include/avr
  30. #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__)
  31. #define ADDRESS_BASE 0x00
  32. #define PINB_ADDRESS 0x3
  33. #define PINC_ADDRESS 0x6
  34. #define PIND_ADDRESS 0x9
  35. #define PINE_ADDRESS 0xC
  36. #define PINF_ADDRESS 0xF
  37. #elif defined(__AVR_ATmega32U2__) || defined(__AVR_ATmega16U2__)
  38. #define ADDRESS_BASE 0x00
  39. #define PINB_ADDRESS 0x3
  40. #define PINC_ADDRESS 0x6
  41. #define PIND_ADDRESS 0x9
  42. #elif defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB646__)
  43. #define ADDRESS_BASE 0x00
  44. #define PINA_ADDRESS 0x0
  45. #define PINB_ADDRESS 0x3
  46. #define PINC_ADDRESS 0x6
  47. #define PIND_ADDRESS 0x9
  48. #define PINE_ADDRESS 0xC
  49. #define PINF_ADDRESS 0xF
  50. #elif defined(__AVR_ATmega32A__)
  51. #define ADDRESS_BASE 0x10
  52. #define PIND_ADDRESS 0x0
  53. #define PINC_ADDRESS 0x3
  54. #define PINB_ADDRESS 0x6
  55. #define PINA_ADDRESS 0x9
  56. #else
  57. #error "Pins are not defined"
  58. #endif
  59. /* I/O pins */
  60. #define PINDEF(port, pin) ((PIN##port##_ADDRESS << PORT_SHIFTER) | pin)
  61. #ifdef PORTA
  62. #define A0 PINDEF(A, 0)
  63. #define A1 PINDEF(A, 1)
  64. #define A2 PINDEF(A, 2)
  65. #define A3 PINDEF(A, 3)
  66. #define A4 PINDEF(A, 4)
  67. #define A5 PINDEF(A, 5)
  68. #define A6 PINDEF(A, 6)
  69. #define A7 PINDEF(A, 7)
  70. #endif
  71. #ifdef PORTB
  72. #define B0 PINDEF(B, 0)
  73. #define B1 PINDEF(B, 1)
  74. #define B2 PINDEF(B, 2)
  75. #define B3 PINDEF(B, 3)
  76. #define B4 PINDEF(B, 4)
  77. #define B5 PINDEF(B, 5)
  78. #define B6 PINDEF(B, 6)
  79. #define B7 PINDEF(B, 7)
  80. #endif
  81. #ifdef PORTC
  82. #define C0 PINDEF(C, 0)
  83. #define C1 PINDEF(C, 1)
  84. #define C2 PINDEF(C, 2)
  85. #define C3 PINDEF(C, 3)
  86. #define C4 PINDEF(C, 4)
  87. #define C5 PINDEF(C, 5)
  88. #define C6 PINDEF(C, 6)
  89. #define C7 PINDEF(C, 7)
  90. #endif
  91. #ifdef PORTD
  92. #define D0 PINDEF(D, 0)
  93. #define D1 PINDEF(D, 1)
  94. #define D2 PINDEF(D, 2)
  95. #define D3 PINDEF(D, 3)
  96. #define D4 PINDEF(D, 4)
  97. #define D5 PINDEF(D, 5)
  98. #define D6 PINDEF(D, 6)
  99. #define D7 PINDEF(D, 7)
  100. #endif
  101. #ifdef PORTE
  102. #define E0 PINDEF(E, 0)
  103. #define E1 PINDEF(E, 1)
  104. #define E2 PINDEF(E, 2)
  105. #define E3 PINDEF(E, 3)
  106. #define E4 PINDEF(E, 4)
  107. #define E5 PINDEF(E, 5)
  108. #define E6 PINDEF(E, 6)
  109. #define E7 PINDEF(E, 7)
  110. #endif
  111. #ifdef PORTF
  112. #define F0 PINDEF(F, 0)
  113. #define F1 PINDEF(F, 1)
  114. #define F2 PINDEF(F, 2)
  115. #define F3 PINDEF(F, 3)
  116. #define F4 PINDEF(F, 4)
  117. #define F5 PINDEF(F, 5)
  118. #define F6 PINDEF(F, 6)
  119. #define F7 PINDEF(F, 7)
  120. #endif
  121. #elif defined(PROTOCOL_CHIBIOS)
  122. // Defines mapping for Proton C replacement
  123. #ifdef CONVERT_TO_PROTON_C
  124. // Left side (front)
  125. #define D3 PAL_LINE(GPIOA, 9)
  126. #define D2 PAL_LINE(GPIOA, 10)
  127. // GND
  128. // GND
  129. #define D1 PAL_LINE(GPIOB, 7)
  130. #define D0 PAL_LINE(GPIOB, 6)
  131. #define D4 PAL_LINE(GPIOB, 5)
  132. #define C6 PAL_LINE(GPIOB, 4)
  133. #define D7 PAL_LINE(GPIOB, 3)
  134. #define E6 PAL_LINE(GPIOB, 2)
  135. #define B4 PAL_LINE(GPIOB, 1)
  136. #define B5 PAL_LINE(GPIOB, 0)
  137. // Right side (front)
  138. // RAW
  139. // GND
  140. // RESET
  141. // VCC
  142. #define F4 PAL_LINE(GPIOA, 2)
  143. #define F5 PAL_LINE(GPIOA, 1)
  144. #define F6 PAL_LINE(GPIOA, 0)
  145. #define F7 PAL_LINE(GPIOB, 8)
  146. #define B1 PAL_LINE(GPIOB, 13)
  147. #define B3 PAL_LINE(GPIOB, 14)
  148. #define B2 PAL_LINE(GPIOB, 15)
  149. #define B6 PAL_LINE(GPIOB, 9)
  150. // LEDs (only D5/C13 uses an actual LED)
  151. #ifdef CONVERT_TO_PROTON_C_RXLED
  152. #define D5 PAL_LINE(GPIOC, 13)
  153. #define B0 PAL_LINE(GPIOC, 13)
  154. #else
  155. #define D5 PAL_LINE(GPIOC, 13)
  156. #define B0 PAL_LINE(GPIOC, 14)
  157. #endif
  158. #else
  159. #define A0 PAL_LINE(GPIOA, 0)
  160. #define A1 PAL_LINE(GPIOA, 1)
  161. #define A2 PAL_LINE(GPIOA, 2)
  162. #define A3 PAL_LINE(GPIOA, 3)
  163. #define A4 PAL_LINE(GPIOA, 4)
  164. #define A5 PAL_LINE(GPIOA, 5)
  165. #define A6 PAL_LINE(GPIOA, 6)
  166. #define A7 PAL_LINE(GPIOA, 7)
  167. #define A8 PAL_LINE(GPIOA, 8)
  168. #define A9 PAL_LINE(GPIOA, 9)
  169. #define A10 PAL_LINE(GPIOA, 10)
  170. #define A11 PAL_LINE(GPIOA, 11)
  171. #define A12 PAL_LINE(GPIOA, 12)
  172. #define A13 PAL_LINE(GPIOA, 13)
  173. #define A14 PAL_LINE(GPIOA, 14)
  174. #define A15 PAL_LINE(GPIOA, 15)
  175. #define B0 PAL_LINE(GPIOB, 0)
  176. #define B1 PAL_LINE(GPIOB, 1)
  177. #define B2 PAL_LINE(GPIOB, 2)
  178. #define B3 PAL_LINE(GPIOB, 3)
  179. #define B4 PAL_LINE(GPIOB, 4)
  180. #define B5 PAL_LINE(GPIOB, 5)
  181. #define B6 PAL_LINE(GPIOB, 6)
  182. #define B7 PAL_LINE(GPIOB, 7)
  183. #define B8 PAL_LINE(GPIOB, 8)
  184. #define B9 PAL_LINE(GPIOB, 9)
  185. #define B10 PAL_LINE(GPIOB, 10)
  186. #define B11 PAL_LINE(GPIOB, 11)
  187. #define B12 PAL_LINE(GPIOB, 12)
  188. #define B13 PAL_LINE(GPIOB, 13)
  189. #define B14 PAL_LINE(GPIOB, 14)
  190. #define B15 PAL_LINE(GPIOB, 15)
  191. #define C0 PAL_LINE(GPIOC, 0)
  192. #define C1 PAL_LINE(GPIOC, 1)
  193. #define C2 PAL_LINE(GPIOC, 2)
  194. #define C3 PAL_LINE(GPIOC, 3)
  195. #define C4 PAL_LINE(GPIOC, 4)
  196. #define C5 PAL_LINE(GPIOC, 5)
  197. #define C6 PAL_LINE(GPIOC, 6)
  198. #define C7 PAL_LINE(GPIOC, 7)
  199. #define C8 PAL_LINE(GPIOC, 8)
  200. #define C9 PAL_LINE(GPIOC, 9)
  201. #define C10 PAL_LINE(GPIOC, 10)
  202. #define C11 PAL_LINE(GPIOC, 11)
  203. #define C12 PAL_LINE(GPIOC, 12)
  204. #define C13 PAL_LINE(GPIOC, 13)
  205. #define C14 PAL_LINE(GPIOC, 14)
  206. #define C15 PAL_LINE(GPIOC, 15)
  207. #define D0 PAL_LINE(GPIOD, 0)
  208. #define D1 PAL_LINE(GPIOD, 1)
  209. #define D2 PAL_LINE(GPIOD, 2)
  210. #define D3 PAL_LINE(GPIOD, 3)
  211. #define D4 PAL_LINE(GPIOD, 4)
  212. #define D5 PAL_LINE(GPIOD, 5)
  213. #define D6 PAL_LINE(GPIOD, 6)
  214. #define D7 PAL_LINE(GPIOD, 7)
  215. #define D8 PAL_LINE(GPIOD, 8)
  216. #define D9 PAL_LINE(GPIOD, 9)
  217. #define D10 PAL_LINE(GPIOD, 10)
  218. #define D11 PAL_LINE(GPIOD, 11)
  219. #define D12 PAL_LINE(GPIOD, 12)
  220. #define D13 PAL_LINE(GPIOD, 13)
  221. #define D14 PAL_LINE(GPIOD, 14)
  222. #define D15 PAL_LINE(GPIOD, 15)
  223. #define E0 PAL_LINE(GPIOE, 0)
  224. #define E1 PAL_LINE(GPIOE, 1)
  225. #define E2 PAL_LINE(GPIOE, 2)
  226. #define E3 PAL_LINE(GPIOE, 3)
  227. #define E4 PAL_LINE(GPIOE, 4)
  228. #define E5 PAL_LINE(GPIOE, 5)
  229. #define E6 PAL_LINE(GPIOE, 6)
  230. #define E7 PAL_LINE(GPIOE, 7)
  231. #define E8 PAL_LINE(GPIOE, 8)
  232. #define E9 PAL_LINE(GPIOE, 9)
  233. #define E10 PAL_LINE(GPIOE, 10)
  234. #define E11 PAL_LINE(GPIOE, 11)
  235. #define E12 PAL_LINE(GPIOE, 12)
  236. #define E13 PAL_LINE(GPIOE, 13)
  237. #define E14 PAL_LINE(GPIOE, 14)
  238. #define E15 PAL_LINE(GPIOE, 15)
  239. #define F0 PAL_LINE(GPIOF, 0)
  240. #define F1 PAL_LINE(GPIOF, 1)
  241. #define F2 PAL_LINE(GPIOF, 2)
  242. #define F3 PAL_LINE(GPIOF, 3)
  243. #define F4 PAL_LINE(GPIOF, 4)
  244. #define F5 PAL_LINE(GPIOF, 5)
  245. #define F6 PAL_LINE(GPIOF, 6)
  246. #define F7 PAL_LINE(GPIOF, 7)
  247. #define F8 PAL_LINE(GPIOF, 8)
  248. #define F9 PAL_LINE(GPIOF, 9)
  249. #define F10 PAL_LINE(GPIOF, 10)
  250. #define F11 PAL_LINE(GPIOF, 11)
  251. #define F12 PAL_LINE(GPIOF, 12)
  252. #define F13 PAL_LINE(GPIOF, 13)
  253. #define F14 PAL_LINE(GPIOF, 14)
  254. #define F15 PAL_LINE(GPIOF, 15)
  255. #endif
  256. #endif
  257. /* USART configuration */
  258. #ifdef BLUETOOTH_ENABLE
  259. # ifdef __AVR_ATmega32U4__
  260. # define SERIAL_UART_BAUD 9600
  261. # define SERIAL_UART_DATA UDR1
  262. # define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
  263. # define SERIAL_UART_RXD_VECT USART1_RX_vect
  264. # define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
  265. # define SERIAL_UART_INIT() do { \
  266. /* baud rate */ \
  267. UBRR1L = SERIAL_UART_UBRR; \
  268. /* baud rate */ \
  269. UBRR1H = SERIAL_UART_UBRR >> 8; \
  270. /* enable TX */ \
  271. UCSR1B = _BV(TXEN1); \
  272. /* 8-bit data */ \
  273. UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
  274. sei(); \
  275. } while(0)
  276. # else
  277. # error "USART configuration is needed."
  278. # endif
  279. #endif
  280. #define API_SYSEX_MAX_SIZE 32
  281. #include "song_list.h"