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.

160 lines
4.0 KiB

Add Uni660 Keyboard (#8018) * UniGo66 keyboard added * UniGo66 keyboard added * case correction of unigo66 files * create sirius folder * Update keyboards/sirius/unigo66/rules.mk Co-Authored-By: danielhklein <danielklein@utexas.edu> * Update keyboards/sirius/unigo66/keymaps/danielhklein/keymap.c Co-Authored-By: danielhklein <danielklein@utexas.edu> * Update keyboards/sirius/unigo66/keymaps/default/config.h Co-Authored-By: danielhklein <danielklein@utexas.edu> * Update keyboards/sirius/unigo66/keymaps/danielhklein/config.h Co-Authored-By: danielhklein <danielklein@utexas.edu> * debugging * correct keymap to layout * readme * remove common config * suggested changes to config.h * default keymap cleanup * bug fixes * add uni660 keyboard * remove zip * remove redundant rules.mk * remove redundant via keymap * Update keyboards/sirius/uni660/config.h Co-Authored-By: Drashna Jaelre <drashna@live.com> * Update keyboards/sirius/uni660/config.h Co-Authored-By: Drashna Jaelre <drashna@live.com> * remove unnecessary functions * fix if * add back via keymap, remove old eeprom code * Update keyboards/sirius/uni660/uni660.h Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.h Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.h Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/rules.mk Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/rules.mk Co-Authored-By: fauxpark <fauxpark@gmail.com> * changes requested for qmk * Update keyboards/sirius/uni660/rules.mk Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/rules.mk Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/rules.mk Co-Authored-By: fauxpark <fauxpark@gmail.com> * debouncing and other minor changes * Update keyboards/sirius/uni660/uni660.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.c Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.h Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.h Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.h Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.h Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.h Co-Authored-By: fauxpark <fauxpark@gmail.com> * Update keyboards/sirius/uni660/uni660.h Co-Authored-By: fauxpark <fauxpark@gmail.com> Co-authored-by: James Young <18669334+noroadsleft@users.noreply.github.com> Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: fauxpark <fauxpark@gmail.com>
4 years ago
  1. /*
  2. Copyright 2012 Jun Wako
  3. Copyright 2014 Jack Humbert
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #if defined(__AVR__)
  18. #include <avr/io.h>
  19. #endif
  20. #include "wait.h"
  21. #include "print.h"
  22. #include "debug.h"
  23. #include "util.h"
  24. #include "matrix.h"
  25. #include "timer.h"
  26. #include "debounce.h"
  27. #if (MATRIX_COLS <= 8)
  28. # define print_matrix_header() print("\nr/c 01234567\n")
  29. # define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
  30. # define matrix_bitpop(i) bitpop(matrix[i])
  31. # define ROW_SHIFTER ((uint8_t)1)
  32. #elif (MATRIX_COLS <= 16)
  33. # define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
  34. # define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
  35. # define matrix_bitpop(i) bitpop16(matrix[i])
  36. # define ROW_SHIFTER ((uint16_t)1)
  37. #elif (MATRIX_COLS <= 32)
  38. # define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
  39. # define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
  40. # define matrix_bitpop(i) bitpop32(matrix[i])
  41. # define ROW_SHIFTER ((uint32_t)1)
  42. #endif
  43. /* matrix state(1:on, 0:off) */
  44. static matrix_row_t matrix[MATRIX_ROWS];
  45. __attribute__ ((weak))
  46. void matrix_init_kb(void) {
  47. matrix_init_user();
  48. }
  49. __attribute__ ((weak))
  50. void matrix_scan_kb(void) {
  51. matrix_scan_user();
  52. }
  53. __attribute__ ((weak))
  54. void matrix_init_user(void) {
  55. }
  56. __attribute__ ((weak))
  57. void matrix_scan_user(void) {
  58. }
  59. inline
  60. uint8_t matrix_rows(void) {
  61. return MATRIX_ROWS;
  62. }
  63. inline
  64. uint8_t matrix_cols(void) {
  65. return MATRIX_COLS;
  66. }
  67. void matrix_init(void) {
  68. debounce_init(MATRIX_ROWS);
  69. matrix_init_quantum();
  70. }
  71. uint8_t matrix_scan(void)
  72. {
  73. bool matrix_has_changed = false;
  74. SERIAL_UART_INIT();
  75. uint32_t timeout = 0;
  76. //the s character requests the RF slave to send the matrix
  77. SERIAL_UART_DATA = 's';
  78. //trust the external keystates entirely, erase the last data
  79. uint8_t uart_data[17] = {0};
  80. //there are 16 bytes corresponding to 16 columns, and an end byte
  81. for (uint8_t i = 0; i < 17; i++) {
  82. //wait for the serial data, timeout if it's been too long
  83. //this only happened in testing with a loose wire, but does no
  84. //harm to leave it in here
  85. while(!SERIAL_UART_RXD_PRESENT){
  86. timeout++;
  87. if (timeout > 10000){
  88. break;
  89. }
  90. }
  91. uart_data[i] = SERIAL_UART_DATA;
  92. }
  93. //check for the end packet, the key state bytes use the LSBs, so 0xE0
  94. //will only show up here if the correct bytes were recieved
  95. if (uart_data[10] == 0xE0)
  96. {
  97. //shifting and transferring the keystates to the QMK matrix variable
  98. for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
  99. matrix[i] = (uint16_t) uart_data[i*2] | (uint16_t) uart_data[i*2+1] << 8;
  100. }
  101. }
  102. debounce(matrix, matrix, MATRIX_ROWS, matrix_has_changed);
  103. matrix_scan_quantum();
  104. return matrix_has_changed;
  105. }
  106. inline
  107. bool matrix_is_on(uint8_t row, uint8_t col)
  108. {
  109. return (matrix[row] & ((matrix_row_t)1<<col));
  110. }
  111. inline
  112. matrix_row_t matrix_get_row(uint8_t row)
  113. {
  114. return matrix[row];
  115. }
  116. void matrix_print(void)
  117. {
  118. print_matrix_header();
  119. for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
  120. phex(row); print(": ");
  121. print_matrix_row(row);
  122. print("\n");
  123. }
  124. }
  125. uint8_t matrix_key_count(void)
  126. {
  127. uint8_t count = 0;
  128. for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
  129. count += matrix_bitpop(i);
  130. }
  131. return count;
  132. }