Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
Repozitorijs ir arhivēts. Tam var aplūkot failus un to var klonēt, bet nevar iesūtīt jaunas izmaiņas, kā arī atvērt jaunas problēmas/izmaiņu pieprasījumus.

keyboard.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. Copyright 2011,2012 Jun Wako <[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. #include "keyboard.h"
  15. #include "matrix.h"
  16. #include "keymap.h"
  17. #include "host.h"
  18. #include "led.h"
  19. #include "keycode.h"
  20. #include "timer.h"
  21. #include "print.h"
  22. #include "debug.h"
  23. #include "command.h"
  24. #include "util.h"
  25. #include "sendchar.h"
  26. #ifdef MOUSEKEY_ENABLE
  27. #include "mousekey.h"
  28. #endif
  29. void keyboard_init(void)
  30. {
  31. // TODO: to enable debug print magic key bind on boot time
  32. // TODO: configuration of sendchar impl
  33. print_sendchar_func = sendchar;
  34. timer_init();
  35. matrix_init();
  36. /* boot magic keys goes here */
  37. matrix_scan();
  38. #ifdef IS_BOOTMAGIC_BOOTLOADER
  39. /* kick up bootloader */
  40. if (IS_BOOTMAGIC_BOOTLOADER()) bootloader_jump();
  41. #endif
  42. #ifdef IS_BOOTMAGIC_DEBUG
  43. if (IS_BOOTMAGIC_DEBUG()) debug_enable = true;
  44. #endif
  45. #ifdef PS2_MOUSE_ENABLE
  46. ps2_mouse_init();
  47. #endif
  48. }
  49. /*
  50. * Do keyboard routine jobs: scan mantrix, light LEDs, ...
  51. * This is repeatedly called as fast as possible.
  52. */
  53. void keyboard_task(void)
  54. {
  55. static matrix_row_t matrix_prev[MATRIX_ROWS];
  56. static uint8_t led_status = 0;
  57. matrix_row_t matrix_row = 0;
  58. matrix_row_t matrix_change = 0;
  59. matrix_scan();
  60. for (int r = 0; r < MATRIX_ROWS; r++) {
  61. matrix_row = matrix_get_row(r);
  62. matrix_change = matrix_row ^ matrix_prev[r];
  63. if (matrix_change) {
  64. if (debug_matrix) matrix_print();
  65. for (int c = 0; c < MATRIX_COLS; c++) {
  66. if (matrix_change & (1<<c)) {
  67. action_exec((keyevent_t){
  68. .key.pos = (keypos_t){ .row = r, .col = c },
  69. .pressed = (matrix_row & (1<<c)),
  70. .time = (timer_read() | 1) /* NOTE: 0 means no event */
  71. });
  72. // record a processed key
  73. matrix_prev[r] ^= (1<<c);
  74. // process a key per task call
  75. goto MATRIX_LOOP_END;
  76. }
  77. }
  78. }
  79. }
  80. // call to update delaying layer when no real event
  81. action_exec((keyevent_t) {
  82. .key.pos = (keypos_t){ .row = 255, .col = 255 }, // assume this key doesn't exist
  83. .pressed = false,
  84. .time = 0,
  85. });
  86. MATRIX_LOOP_END:
  87. #ifdef MOUSEKEY_ENABLE
  88. // mousekey repeat & acceleration
  89. mousekey_task();
  90. #endif
  91. // update LED
  92. if (led_status != host_keyboard_leds()) {
  93. led_status = host_keyboard_leds();
  94. keyboard_set_leds(led_status);
  95. }
  96. return;
  97. }
  98. void keyboard_set_leds(uint8_t leds)
  99. {
  100. led_set(leds);
  101. }