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.

270 lines
6.5 KiB

[Keyboard] Orion Locking Indicator LED Support (#7683) * add indicator lighting support thanks to Keebology tracing * set the correct number of underglow LEDs * add comments and skeletal structure for layer indicator LEDs * add backlight areas pins * update readme * we can't turn leds on based on zones, so we use multiple backlight pin support instead to turn them ALL on and control them. * add comments to backlight setting * make a more useful default keymap that can also be used for testing * add duck orion to list * add indicator led support * update readme * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * add the appropriate header files * fix indent so Drashna will not die * Update keyboards/duck/orion/v3/v3.c Co-Authored-By: James Young <18669334+noroadsleft@users.noreply.github.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: fauxpark <fauxpark@gmail.com>
4 years ago
[Keyboard] Orion Locking Indicator LED Support (#7683) * add indicator lighting support thanks to Keebology tracing * set the correct number of underglow LEDs * add comments and skeletal structure for layer indicator LEDs * add backlight areas pins * update readme * we can't turn leds on based on zones, so we use multiple backlight pin support instead to turn them ALL on and control them. * add comments to backlight setting * make a more useful default keymap that can also be used for testing * add duck orion to list * add indicator led support * update readme * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * add the appropriate header files * fix indent so Drashna will not die * Update keyboards/duck/orion/v3/v3.c Co-Authored-By: James Young <18669334+noroadsleft@users.noreply.github.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: fauxpark <fauxpark@gmail.com>
4 years ago
[Keyboard] Orion Locking Indicator LED Support (#7683) * add indicator lighting support thanks to Keebology tracing * set the correct number of underglow LEDs * add comments and skeletal structure for layer indicator LEDs * add backlight areas pins * update readme * we can't turn leds on based on zones, so we use multiple backlight pin support instead to turn them ALL on and control them. * add comments to backlight setting * make a more useful default keymap that can also be used for testing * add duck orion to list * add indicator led support * update readme * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * add the appropriate header files * fix indent so Drashna will not die * Update keyboards/duck/orion/v3/v3.c Co-Authored-By: James Young <18669334+noroadsleft@users.noreply.github.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: fauxpark <fauxpark@gmail.com>
4 years ago
[Keyboard] Orion Locking Indicator LED Support (#7683) * add indicator lighting support thanks to Keebology tracing * set the correct number of underglow LEDs * add comments and skeletal structure for layer indicator LEDs * add backlight areas pins * update readme * we can't turn leds on based on zones, so we use multiple backlight pin support instead to turn them ALL on and control them. * add comments to backlight setting * make a more useful default keymap that can also be used for testing * add duck orion to list * add indicator led support * update readme * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * add the appropriate header files * fix indent so Drashna will not die * Update keyboards/duck/orion/v3/v3.c Co-Authored-By: James Young <18669334+noroadsleft@users.noreply.github.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: fauxpark <fauxpark@gmail.com>
4 years ago
[Keyboard] Orion Locking Indicator LED Support (#7683) * add indicator lighting support thanks to Keebology tracing * set the correct number of underglow LEDs * add comments and skeletal structure for layer indicator LEDs * add backlight areas pins * update readme * we can't turn leds on based on zones, so we use multiple backlight pin support instead to turn them ALL on and control them. * add comments to backlight setting * make a more useful default keymap that can also be used for testing * add duck orion to list * add indicator led support * update readme * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/duck/orion/v3/matrix.c Co-Authored-By: Drashna Jaelre <drashna@live.com> * add the appropriate header files * fix indent so Drashna will not die * Update keyboards/duck/orion/v3/v3.c Co-Authored-By: James Young <18669334+noroadsleft@users.noreply.github.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/keymaps/default/keymap.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/duck/orion/v3/readme.md Co-Authored-By: fauxpark <fauxpark@gmail.com> Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: fauxpark <fauxpark@gmail.com>
4 years ago
  1. /*
  2. Copyright 2019 MechMerlin <mechmerlin@gmail.com>
  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. #include "quantum.h"
  15. #ifndef DEBOUNCE
  16. # define DEBOUNCE 5
  17. #endif
  18. static uint8_t debouncing = DEBOUNCE;
  19. /* matrix state(1:on, 0:off) */
  20. static matrix_row_t matrix[MATRIX_ROWS];
  21. static matrix_row_t matrix_debouncing[MATRIX_ROWS];
  22. static uint8_t read_rows(uint8_t col);
  23. static void init_rows(void);
  24. static void unselect_cols(void);
  25. static void select_col(uint8_t col);
  26. __attribute__ ((weak))
  27. void matrix_init_kb(void) {
  28. matrix_init_user();
  29. }
  30. __attribute__ ((weak))
  31. void matrix_scan_kb(void) {
  32. matrix_scan_user();
  33. }
  34. __attribute__ ((weak))
  35. void matrix_init_user(void) {
  36. }
  37. __attribute__ ((weak))
  38. void matrix_scan_user(void) {
  39. }
  40. void indicator_init_ports(void) {
  41. // Num LED
  42. gpio_set_pin_output(B4);
  43. // Caps Lock
  44. gpio_set_pin_output(B0);
  45. // Scroll Lock
  46. gpio_set_pin_output(D7);
  47. }
  48. void matrix_init(void) {
  49. indicator_init_ports();
  50. unselect_cols();
  51. init_rows();
  52. for (uint8_t i=0; i < MATRIX_ROWS; i++) {
  53. matrix[i] = 0;
  54. matrix_debouncing[i] = 0;
  55. }
  56. matrix_init_kb();
  57. }
  58. uint8_t matrix_scan(void) {
  59. for (uint8_t col = 0; col < MATRIX_COLS; col++) {
  60. select_col(col);
  61. _delay_us(3);
  62. uint8_t rows = read_rows(col);
  63. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  64. bool prev_bit = matrix_debouncing[row] & ((matrix_row_t)1<<col);
  65. bool curr_bit = rows & (1<<row);
  66. if (prev_bit != curr_bit) {
  67. matrix_debouncing[row] ^= ((matrix_row_t)1<<col);
  68. if (debouncing) {
  69. dprint("bounce!: "); dprintf("%02X", debouncing); dprintln();
  70. }
  71. debouncing = DEBOUNCE;
  72. }
  73. }
  74. unselect_cols();
  75. }
  76. if (debouncing) {
  77. if (--debouncing) {
  78. _delay_ms(1);
  79. } else {
  80. for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
  81. matrix[i] = matrix_debouncing[i];
  82. }
  83. }
  84. }
  85. matrix_scan_kb();
  86. return 1;
  87. }
  88. inline matrix_row_t matrix_get_row(uint8_t row) {
  89. return matrix[row];
  90. }
  91. void matrix_print(void) {
  92. print("\nr/c 0123456789ABCDEF\n");
  93. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  94. xprintf("%02X: %032lb\n", row, bitrev32(matrix_get_row(row)));
  95. }
  96. }
  97. /* Row pin configuration - diode connected
  98. * row: 0 1 2 3 4 5
  99. * pin: PD0 PD1 PD2 PD3 PD5 PB7
  100. *
  101. * Backspace uses its own pin PE2 on the column pin, row pin is grounded
  102. */
  103. static void init_rows(void) {
  104. DDRD &= ~0b00101111;
  105. PORTD &= ~0b00101111;
  106. DDRB &= ~0b10000000;
  107. PORTB &= ~0b10000000;
  108. DDRE &= ~0b00000100;
  109. PORTE |= 0b00000100;
  110. }
  111. static uint8_t read_rows(uint8_t col) {
  112. return (PIND&(1<<0) ? (1<<0) : 0) |
  113. (PIND&(1<<1) ? (1<<1) : 0) |
  114. (PIND&(1<<2) ? (1<<2) : 0) |
  115. (PIND&(1<<3) ? (1<<3) : 0) |
  116. (PIND&(1<<5) ? (1<<4) : 0) |
  117. (PINB&(1<<7) ? (1<<5) : 0) |
  118. (col== 17 ? ((PINE&(1<<2) ? 0 : (1<<1))) : 0);
  119. }
  120. uint8_t read_fwkey(void)
  121. {
  122. return PINE&(1<<2) ? 0 : (1<<2);
  123. }
  124. /* Columns 0 - 15
  125. *
  126. * atmega32u4 decoder pin
  127. * PC6 U1 E3
  128. * PB6 U2 E3
  129. * PF0 U1, U2 A0
  130. * PF1 U1, U2 A1
  131. * PC7 U1, U2 A2
  132. *
  133. * These columns uses two 74HC237D 3 to 8 bit demultiplexers.
  134. * col / pin: PC6 PB6 PF0 PF1 PC7 Decoder Pin
  135. * 0: 1 0 0 0 0 U1 Y0
  136. * 1: 1 0 1 0 0 U1 Y1
  137. * 2: 1 0 0 1 0 U1 Y2
  138. * 3: 1 0 1 1 0 U1 Y3
  139. * 4: 1 0 0 0 1 U1 Y4
  140. * 5: 1 0 1 0 1 U1 Y5
  141. * 6: 1 0 0 1 1 U1 Y6
  142. * 7: 1 0 1 1 1 U1 Y7
  143. *
  144. * 8: 0 1 0 0 0 U2 Y0
  145. * 9: 0 1 1 0 0 U2 Y1
  146. * 10: 0 1 0 1 0 U2 Y2
  147. * 11: 0 1 1 1 0 U2 Y3
  148. * 12: 0 1 0 0 1 U2 Y4
  149. * 13: 0 1 1 0 1 U2 Y5
  150. * 14: 0 1 0 1 1 U2 Y6
  151. * 15: 0 1 1 1 1 U2 Y7
  152. *
  153. */
  154. static void unselect_cols(void) {
  155. DDRB |= 0b01100000;
  156. PORTB &= ~0b01100000;
  157. DDRC |= 0b11000000;
  158. PORTC &= ~0b11000000;
  159. DDRF |= 0b00000011;
  160. PORTF &= ~0b00000011;
  161. }
  162. static void select_col(uint8_t col) {
  163. switch (col) {
  164. case 0:
  165. PORTC |= 0b01000000;
  166. break;
  167. case 1:
  168. PORTC |= 0b01000000;
  169. PORTF |= 0b00000001;
  170. break;
  171. case 2:
  172. PORTC |= 0b01000000;
  173. PORTF |= 0b00000010;
  174. break;
  175. case 3:
  176. PORTC |= 0b01000000;
  177. PORTF |= 0b00000011;
  178. break;
  179. case 4:
  180. PORTC |= 0b11000000;
  181. break;
  182. case 5:
  183. PORTC |= 0b11000000;
  184. PORTF |= 0b00000001;
  185. break;
  186. case 6:
  187. PORTC |= 0b11000000;
  188. PORTF |= 0b00000010;
  189. break;
  190. case 7:
  191. PORTC |= 0b11000000;
  192. PORTF |= 0b00000011;
  193. break;
  194. case 8:
  195. PORTB |= 0b01000000;
  196. break;
  197. case 9:
  198. PORTB |= 0b01000000;
  199. PORTF |= 0b00000001;
  200. break;
  201. case 10:
  202. PORTB |= 0b01000000;
  203. PORTF |= 0b00000010;
  204. break;
  205. case 11:
  206. PORTB |= 0b01000000;
  207. PORTF |= 0b00000011;
  208. break;
  209. case 12:
  210. PORTB |= 0b01000000;
  211. PORTC |= 0b10000000;
  212. break;
  213. case 13:
  214. PORTB |= 0b01000000;
  215. PORTF |= 0b00000001;
  216. PORTC |= 0b10000000;
  217. break;
  218. case 14:
  219. PORTB |= 0b01000000;
  220. PORTF |= 0b00000010;
  221. PORTC |= 0b10000000;
  222. break;
  223. case 15:
  224. PORTB |= 0b01000000;
  225. PORTF |= 0b00000011;
  226. PORTC |= 0b10000000;
  227. break;
  228. case 16:
  229. PORTB |= 0b00100000;
  230. break;
  231. }
  232. }