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 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #ifndef TWO_HEADED_KIMERA
  96. #define EXP_COUNT 2
  97. #else
  98. #define EXP_COUNT 4
  99. #endif
  100. #define EXP_ADDR(n) ((0x20+(n))<<1)
  101. #define EXP_OUTPUT 0
  102. #define EXP_INPUT 1
  103. #define EXP_PORT_COUNT 2
  104. #define EXP_PIN_PER_PORT 8
  105. enum {
  106. EXP_COMM_INPUT_0 = 0,
  107. EXP_COMM_INPUT_1,
  108. EXP_COMM_OUTPUT_0,
  109. EXP_COMM_OUTPUT_1,
  110. EXP_COMM_INVERSION_0,
  111. EXP_COMM_INVERSION_1,
  112. EXP_COMM_CONFIG_0,
  113. EXP_COMM_CONFIG_1
  114. };
  115. #ifndef KIMERA_CORE
  116. #define PX_TO_EXP(x) (((x)>>5<<1)+((((x)>>3)&1)^(((x)>>4)&1)))
  117. #define PX_TO_PORT(x) (((x)>>4)&1)
  118. #else
  119. #define PX_TO_EXP(x) ((x)>>4)
  120. #define PX_TO_PORT(x) (((x)>>3)&1)
  121. #endif
  122. #define PX_TO_PIN(x) ((x)&7)
  123. #define PX_COUNT (EXP_PIN_PER_PORT * EXP_PORT_COUNT * EXP_COUNT)
  124. #ifdef KIMERA_C
  125. const uint16_t PROGMEM dummy[] = {
  126. };
  127. #endif
  128. /* Matrix Mapping in EEPROM */
  129. #define EECONFIG_ROW_COUNT (uint8_t *)16
  130. #define EECONFIG_COL_COUNT (uint8_t *)17
  131. #define EECONFIG_ROW_COL_MAPPING (uint8_t *)18
  132. #define UNCONFIGURED 0xFF
  133. /* Functions */
  134. void kimera_init(void);
  135. void wdt_init(void);
  136. uint8_t read_matrix_mapping(void);
  137. void write_matrix_mapping(void);
  138. void kimera_scan(void);
  139. uint8_t kimera_matrix_rows(void);
  140. uint8_t kimera_matrix_cols(void);
  141. matrix_row_t kimera_read_cols(uint8_t row);
  142. void kimera_unselect_rows(void);
  143. void kimera_select_row(uint8_t row);
  144. void expander_init(uint8_t exp);
  145. uint8_t expander_write(uint8_t exp, uint8_t command, uint8_t *data);
  146. uint8_t expander_read(uint8_t exp, uint8_t command, uint8_t *data);
  147. uint8_t expander_write_output(uint8_t exp, uint8_t *data);
  148. uint8_t expander_write_inversion(uint8_t exp, uint8_t *data);
  149. uint8_t expander_write_config(uint8_t exp, uint8_t *data);
  150. uint8_t expander_read_input(uint8_t exp, uint8_t *data);
  151. void init_data(uint8_t value);
  152. #endif