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.

120 lines
2.4 KiB

  1. /*
  2. Copyright 2011,2012 Jun Wako <wakojun@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. Ported to QMK by Techsock <info@techsock.com>
  15. */
  16. #include <stdint.h>
  17. #include <avr/io.h>
  18. #include <util/delay.h>
  19. #include "print.h"
  20. #include "util.h"
  21. #include "debug.h"
  22. #include "host.h"
  23. #include "m0110.h"
  24. #include "matrix.h"
  25. #include "report.h"
  26. #include "timer.h"
  27. #define CAPS 0x39
  28. #define CAPS_BREAK (CAPS | 0x80)
  29. #define ROW(key) ((key)>>3&0x0F)
  30. #define COL(key) ((key)&0x07)
  31. static bool is_modified = false;
  32. // matrix state buffer(1:on, 0:off)
  33. static uint8_t *matrix;
  34. static uint8_t _matrix0[MATRIX_ROWS];
  35. static void register_key(uint8_t key);
  36. __attribute__ ((weak))
  37. void matrix_init_kb(void) {
  38. matrix_init_user();
  39. }
  40. __attribute__ ((weak))
  41. void matrix_scan_kb(void) {
  42. matrix_scan_user();
  43. }
  44. __attribute__ ((weak))
  45. void matrix_init_user(void) {
  46. }
  47. __attribute__ ((weak))
  48. void matrix_scan_user(void) {
  49. }
  50. void matrix_init(void)
  51. {
  52. m0110_init();
  53. // initialize matrix state: all keys off
  54. for (uint8_t i=0; i < MATRIX_ROWS; i++) _matrix0[i] = 0x00;
  55. matrix = _matrix0;
  56. matrix_init_quantum();
  57. return;
  58. }
  59. uint8_t matrix_scan(void)
  60. {
  61. uint8_t key;
  62. is_modified = false;
  63. key = m0110_recv_key();
  64. if (key == M0110_NULL) {
  65. return 0;
  66. } else if (key == M0110_ERROR) {
  67. return 0;
  68. } else {
  69. is_modified = true;
  70. register_key(key);
  71. }
  72. if (debug_enable) {
  73. print("["); print_hex8(key); print("]\n");
  74. }
  75. matrix_scan_quantum();
  76. return 1;
  77. }
  78. void matrix_print(void){
  79. }
  80. inline
  81. uint8_t matrix_get_row(uint8_t row)
  82. {
  83. return matrix[row];
  84. }
  85. inline
  86. static void register_key(uint8_t key)
  87. {
  88. if (key&0x80) {
  89. matrix[ROW(key)] &= ~(1<<COL(key));
  90. } else {
  91. matrix[ROW(key)] |= (1<<COL(key));
  92. }
  93. }