Keyboard firmwares for Atmel AVR and Cortex-M
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <stdint.h>
  15. #include <avr/interrupt.h>
  16. #include "keycode.h"
  17. #include "host.h"
  18. #include "util.h"
  19. #include "debug.h"
  20. #ifdef NKRO_ENABLE
  21. bool keyboard_nkro = false;
  22. #endif
  23. report_mouse_t mouse_report = {};
  24. static host_driver_t *driver;
  25. static uint16_t last_system_report = 0;
  26. static uint16_t last_consumer_report = 0;
  27. void host_set_driver(host_driver_t *d)
  28. {
  29. driver = d;
  30. }
  31. host_driver_t *host_get_driver(void)
  32. {
  33. return driver;
  34. }
  35. uint8_t host_keyboard_leds(void)
  36. {
  37. if (!driver) return 0;
  38. return (*driver->keyboard_leds)();
  39. }
  40. /* send report */
  41. void host_keyboard_send(report_keyboard_t *report)
  42. {
  43. if (!driver) return;
  44. (*driver->send_keyboard)(report);
  45. if (debug_keyboard) {
  46. dprint("keyboard_report: ");
  47. for (uint8_t i = 0; i < REPORT_SIZE; i++) {
  48. dprintf("%02X ", report->raw[i]);
  49. }
  50. dprint("\n");
  51. }
  52. }
  53. void host_mouse_send(report_mouse_t *report)
  54. {
  55. if (!driver) return;
  56. (*driver->send_mouse)(report);
  57. }
  58. void host_system_send(uint16_t report)
  59. {
  60. if (report == last_system_report) return;
  61. last_system_report = report;
  62. if (!driver) return;
  63. (*driver->send_system)(report);
  64. }
  65. void host_consumer_send(uint16_t report)
  66. {
  67. if (report == last_consumer_report) return;
  68. last_consumer_report = report;
  69. if (!driver) return;
  70. (*driver->send_consumer)(report);
  71. }
  72. uint8_t host_mouse_in_use(void)
  73. {
  74. return (mouse_report.buttons | mouse_report.x | mouse_report.y | mouse_report.v | mouse_report.h);
  75. }
  76. uint16_t host_last_sysytem_report(void)
  77. {
  78. return last_system_report;
  79. }
  80. uint16_t host_last_consumer_report(void)
  81. {
  82. return last_consumer_report;
  83. }