config_common.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include <avr/io.h>
  19. /* diode directions */
  20. #define COL2ROW 0
  21. #define ROW2COL 1
  22. #define CUSTOM_MATRIX 2 /* Disables built-in matrix scanning code */
  23. /* I/O pins */
  24. #define PINDEF(port, pin) (uint8_t)((((uint16_t)&PORT##port) << 4) + PIN##port##pin)
  25. #define PIN(p) (*((volatile uint8_t*)(p >> 4) + 0))
  26. #define PIN_VALUE(p) (PIN(p) & _BV(p & 0xF))
  27. #define DDR(p) (*((volatile uint8_t*)(p >> 4) + 1))
  28. #define DDR_OUTPUT(p) (DDR(p) |= _BV(p & 0xF))
  29. #define DDR_INPUT(p) (DDR(p) &= ~_BV(p & 0xF))
  30. #define PORT(p) (*((volatile uint8_t*)(p >> 4) + 2))
  31. #define PORT_HIGH(p) (PORT(p) |= _BV(p & 0xF))
  32. #define PORT_LOW(p) (PORT(p) &= ~_BV(p & 0xF))
  33. #ifdef PORTA
  34. #define A0 PINDEF(A, 0)
  35. #define A1 PINDEF(A, 1)
  36. #define A2 PINDEF(A, 1)
  37. #define A3 PINDEF(A, 3)
  38. #define A4 PINDEF(A, 4)
  39. #define A5 PINDEF(A, 5)
  40. #define A6 PINDEF(A, 6)
  41. #define A7 PINDEF(A, 7)
  42. #endif
  43. #ifdef PORTB
  44. #define B0 PINDEF(B, 0)
  45. #define B1 PINDEF(B, 1)
  46. #define B2 PINDEF(B, 2)
  47. #define B3 PINDEF(B, 3)
  48. #define B4 PINDEF(B, 4)
  49. #define B5 PINDEF(B, 5)
  50. #define B6 PINDEF(B, 6)
  51. #define B7 PINDEF(B, 7)
  52. #endif
  53. #ifdef PORTC
  54. #define C0 PINDEF(C, 0)
  55. #define C1 PINDEF(C, 1)
  56. #define C2 PINDEF(C, 2)
  57. #define C3 PINDEF(C, 3)
  58. #define C4 PINDEF(C, 4)
  59. #define C5 PINDEF(C, 5)
  60. #define C6 PINDEF(C, 6)
  61. #define C7 PINDEF(C, 7)
  62. #endif
  63. #ifdef PORTD
  64. #define D0 PINDEF(D, 0)
  65. #define D1 PINDEF(D, 1)
  66. #define D2 PINDEF(D, 2)
  67. #define D3 PINDEF(D, 3)
  68. #define D4 PINDEF(D, 4)
  69. #define D5 PINDEF(D, 5)
  70. #define D6 PINDEF(D, 6)
  71. #define D7 PINDEF(D, 7)
  72. #endif
  73. #ifdef PORTE
  74. #define E0 PINDEF(E, 0)
  75. #define E1 PINDEF(E, 1)
  76. #define E2 PINDEF(E, 2)
  77. #define E3 PINDEF(E, 3)
  78. #define E4 PINDEF(E, 4)
  79. #define E5 PINDEF(E, 5)
  80. #define E6 PINDEF(E, 6)
  81. #define E7 PINDEF(E, 7)
  82. #endif
  83. #ifdef PORTF
  84. #define F0 PINDEF(F, 0)
  85. #define F1 PINDEF(F, 1)
  86. #define F2 PINDEF(F, 2)
  87. #define F3 PINDEF(F, 3)
  88. #define F4 PINDEF(F, 4)
  89. #define F5 PINDEF(F, 5)
  90. #define F6 PINDEF(F, 6)
  91. #define F7 PINDEF(F, 7)
  92. #endif
  93. /* USART configuration */
  94. #ifdef BLUETOOTH_ENABLE
  95. # ifdef __AVR_ATmega32U4__
  96. # define SERIAL_UART_BAUD 9600
  97. # define SERIAL_UART_DATA UDR1
  98. # define SERIAL_UART_UBRR (F_CPU / (16UL * SERIAL_UART_BAUD) - 1)
  99. # define SERIAL_UART_RXD_VECT USART1_RX_vect
  100. # define SERIAL_UART_TXD_READY (UCSR1A & _BV(UDRE1))
  101. # define SERIAL_UART_INIT() do { \
  102. /* baud rate */ \
  103. UBRR1L = SERIAL_UART_UBRR; \
  104. /* baud rate */ \
  105. UBRR1H = SERIAL_UART_UBRR >> 8; \
  106. /* enable TX */ \
  107. UCSR1B = _BV(TXEN1); \
  108. /* 8-bit data */ \
  109. UCSR1C = _BV(UCSZ11) | _BV(UCSZ10); \
  110. sei(); \
  111. } while(0)
  112. # else
  113. # error "USART configuration is needed."
  114. # endif
  115. #endif
  116. #define API_SYSEX_MAX_SIZE 32
  117. #include "song_list.h"
  118. #endif