host.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #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. static host_driver_t *driver;
  21. static uint16_t last_system_report = 0;
  22. static uint16_t last_consumer_report = 0;
  23. void host_set_driver(host_driver_t *d)
  24. {
  25. driver = d;
  26. }
  27. host_driver_t *host_get_driver(void)
  28. {
  29. return driver;
  30. }
  31. uint8_t host_keyboard_leds(void)
  32. {
  33. if (!driver) return 0;
  34. return (*driver->keyboard_leds)();
  35. }
  36. /* send report */
  37. void host_keyboard_send(report_keyboard_t *report)
  38. {
  39. if (!driver) return;
  40. (*driver->send_keyboard)(report);
  41. if (debug_keyboard) {
  42. dprint("keyboard_report: ");
  43. for (uint8_t i = 0; i < KEYBOARD_REPORT_SIZE; i++) {
  44. dprintf("%02X ", report->raw[i]);
  45. }
  46. dprint("\n");
  47. }
  48. }
  49. void host_mouse_send(report_mouse_t *report)
  50. {
  51. if (!driver) return;
  52. (*driver->send_mouse)(report);
  53. }
  54. void host_system_send(uint16_t report)
  55. {
  56. if (report == last_system_report) return;
  57. last_system_report = report;
  58. if (!driver) return;
  59. (*driver->send_system)(report);
  60. }
  61. void host_consumer_send(uint16_t report)
  62. {
  63. if (report == last_consumer_report) return;
  64. last_consumer_report = report;
  65. if (!driver) return;
  66. (*driver->send_consumer)(report);
  67. }
  68. uint16_t host_last_system_report(void)
  69. {
  70. return last_system_report;
  71. }
  72. uint16_t host_last_consumer_report(void)
  73. {
  74. return last_consumer_report;
  75. }