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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

kimera.h 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. Copyright 2014 Kai Ryu <[email protected]>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef KIMERA_H
  15. #define KIMERA_H
  16. #include <stdint.h>
  17. #include <avr/pgmspace.h>
  18. #include "matrix.h"
  19. /*
  20. U1 (Pro Micro)
  21. ,----------------.
  22. TX --| TX0(PD3) RAW |--
  23. RX --| RX1(PD2) GND |--
  24. --| GND RESET |-- RST
  25. --| GND VCC |--
  26. SDA --| 2(PD1) (PF4)A3 |--
  27. SCL --| 3(PD0) (PF5)A2 |--
  28. (INT) --| 4(PD4) (PF6)A1 |--
  29. --| 5(PC6) (PF7)A0 |--
  30. --| 6(PD7) (PB1)15 |-- SCK
  31. LED2 --| 7(PE6) (PB3)14 |-- MISO
  32. LED1 --| 8(PB4) (PB2)16 |-- MOSI
  33. LED3 --| 9(PB5) (PB6)10 |-- LED4
  34. `----------------'
  35. */
  36. #ifndef KIMERA_CORE
  37. #define LED1_PORT PORTB
  38. #define LED1_PIN PINB
  39. #define LED1_DDR DDRB
  40. #define LED1_BIT PB4
  41. #define LED2_PORT PORTE
  42. #define LED2_PIN PINE
  43. #define LED2_DDR DDRE
  44. #define LED2_BIT PE6
  45. #define LED3_PORT PORTB
  46. #define LED3_PIN PINB
  47. #define LED3_DDR DDRB
  48. #define LED3_BIT PB5
  49. #define LED4_PORT PORTB
  50. #define LED4_PIN PINB
  51. #define LED4_DDR DDRB
  52. #define LED4_BIT PB6
  53. #define LED4_OCR OCR1B
  54. #else
  55. #define LED1_PORT PORTB
  56. #define LED1_PIN PINB
  57. #define LED1_DDR DDRB
  58. #define LED1_BIT PB5
  59. #define LED2_PORT PORTB
  60. #define LED2_PIN PINB
  61. #define LED2_DDR DDRB
  62. #define LED2_BIT PB6
  63. #define LED3_PORT PORTC
  64. #define LED3_PIN PINC
  65. #define LED3_DDR DDRC
  66. #define LED3_BIT PC6
  67. #define LED4_PORT PORTC
  68. #define LED4_PIN PINC
  69. #define LED4_DDR DDRC
  70. #define LED4_BIT PC7
  71. #define LED4_OCR OCR4D
  72. #endif
  73. /*
  74. IC1 (PCA9555) IC2 (PCA9555)
  75. ,----------. ,----------.
  76. SDA --| SDA P00 |-- P1 SDA --| SDA P00 |-- P9
  77. SCL --| SCL P01 |-- P2 SCL --| SCL P01 |-- P10
  78. INT --| INT P02 |-- P3 INT --| INT P02 |-- P11
  79. | P03 |-- P4 | P03 |-- P12
  80. GND --| A0 P04 |-- P5 VCC --| A0 P04 |-- P13
  81. SJ1 --| A1 P05 |-- P6 SJ1 --| A1 P05 |-- P14
  82. SJ2 --| A2 P06 |-- P7 SJ2 --| A2 P06 |-- P15
  83. | P07 |-- P8 | P07 |-- P16
  84. | | | |
  85. | P10 |-- P25 | P10 |-- P17
  86. | P11 |-- P26 | P11 |-- P18
  87. | P12 |-- P27 | P12 |-- P19
  88. | P13 |-- P28 | P13 |-- P20
  89. | P14 |-- P29 | P14 |-- P21
  90. | P15 |-- P30 | P15 |-- P22
  91. | P16 |-- P31 | P16 |-- P23
  92. | P17 |-- P32 | P17 |-- P24
  93. `----------' `----------'
  94. */
  95. #define EXP_COUNT 4
  96. #define EXP_ADDR(n) ((0x20+(n))<<1)
  97. #define EXP_OUTPUT 0
  98. #define EXP_INPUT 1
  99. #define EXP_PORT_COUNT 2
  100. #define EXP_PIN_PER_PORT 8
  101. enum {
  102. EXP_COMM_INPUT_0 = 0,
  103. EXP_COMM_INPUT_1,
  104. EXP_COMM_OUTPUT_0,
  105. EXP_COMM_OUTPUT_1,
  106. EXP_COMM_INVERSION_0,
  107. EXP_COMM_INVERSION_1,
  108. EXP_COMM_CONFIG_0,
  109. EXP_COMM_CONFIG_1
  110. };
  111. #ifndef KIMERA_CORE
  112. #define PX_TO_EXP(x) (((x)>>5<<1)+((((x)>>3)&1)^(((x)>>4)&1)))
  113. #define PX_TO_PORT(x) (((x)>>4)&1)
  114. #else
  115. #define PX_TO_EXP(x) ((x)>>4)
  116. #define PX_TO_PORT(x) (((x)>>3)&1)
  117. #endif
  118. #define PX_TO_PIN(x) ((x)&7)
  119. #define PX_COUNT (EXP_PIN_PER_PORT * EXP_PORT_COUNT * EXP_COUNT)
  120. #ifdef KIMERA_C
  121. const uint16_t PROGMEM dummy[] = {
  122. };
  123. #endif
  124. /* Matrix Mapping in EEPROM */
  125. #define EECONFIG_ROW_COUNT (uint8_t *)16
  126. #define EECONFIG_COL_COUNT (uint8_t *)17
  127. #define EECONFIG_ROW_COL_MAPPING (uint8_t *)18
  128. #define UNCONFIGURED 0xFF
  129. enum {
  130. COMBINING_NONE = 0,
  131. COMBINING_COL,
  132. COMBINING_ROW
  133. };
  134. #define COMBINING_BIT (0x80)
  135. /* Functions */
  136. void kimera_init(void);
  137. void kimera_scan(void);
  138. uint8_t kimera_matrix_rows(void);
  139. uint8_t kimera_matrix_cols(void);
  140. void kimera_read_cols(void);
  141. uint8_t kimera_get_col(uint8_t row, uint8_t col);
  142. matrix_row_t kimera_read_row(uint8_t row);
  143. void kimera_unselect_rows(void);
  144. void kimera_select_row(uint8_t row);
  145. #endif