Keyboard firmwares for Atmel AVR and Cortex-M
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.

main.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * (c) 2015 flabberast <[email protected]>
  3. *
  4. * Based on the following work:
  5. * - Guillaume Duc's raw hid example (MIT License)
  6. * https://github.com/guiduc/usb-hid-chibios-example
  7. * - PJRC Teensy examples (MIT License)
  8. * https://www.pjrc.com/teensy/usb_keyboard.html
  9. * - hasu's TMK keyboard code (GPL v2 and some code Modified BSD)
  10. * https://github.com/tmk/tmk_keyboard/
  11. * - ChibiOS demo code (Apache 2.0 License)
  12. * http://www.chibios.org
  13. *
  14. * Since some GPL'd code is used, this work is licensed under
  15. * GPL v2 or later.
  16. */
  17. #include "ch.h"
  18. #include "hal.h"
  19. #include "usb_main.h"
  20. /* TMK includes */
  21. #include "report.h"
  22. #include "host.h"
  23. #include "host_driver.h"
  24. #include "keyboard.h"
  25. #include "action.h"
  26. #include "led.h"
  27. #include "sendchar.h"
  28. #include "debug.h"
  29. #ifdef SLEEP_LED_ENABLE
  30. #include "sleep_led.h"
  31. #endif
  32. #include "suspend.h"
  33. /* -------------------------
  34. * TMK host driver defs
  35. * -------------------------
  36. */
  37. /* declarations */
  38. uint8_t keyboard_leds(void);
  39. void send_keyboard(report_keyboard_t *report);
  40. void send_mouse(report_mouse_t *report);
  41. void send_system(uint16_t data);
  42. void send_consumer(uint16_t data);
  43. /* host struct */
  44. host_driver_t chibios_driver = {
  45. keyboard_leds,
  46. send_keyboard,
  47. send_mouse,
  48. send_system,
  49. send_consumer
  50. };
  51. /* TESTING
  52. * Amber LED blinker thread, times are in milliseconds.
  53. */
  54. /* set this variable to non-zero anywhere to blink once */
  55. // uint8_t blinkLed = 0;
  56. // static THD_WORKING_AREA(waBlinkerThread, 128);
  57. // static THD_FUNCTION(blinkerThread, arg) {
  58. // (void)arg;
  59. // chRegSetThreadName("blinkOrange");
  60. // while(true) {
  61. // if(blinkLed) {
  62. // blinkLed = 0;
  63. // palSetPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
  64. // chThdSleepMilliseconds(100);
  65. // palClearPad(TEENSY_PIN13_IOPORT, TEENSY_PIN13);
  66. // }
  67. // chThdSleepMilliseconds(100);
  68. // }
  69. // }
  70. /* Main thread
  71. */
  72. int main(void) {
  73. /* ChibiOS/RT init */
  74. halInit();
  75. chSysInit();
  76. // TESTING
  77. // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL);
  78. /* Init USB */
  79. init_usb_driver(&USB_DRIVER);
  80. /* init printf */
  81. init_printf(NULL,sendchar_pf);
  82. /* Wait until the USB is active */
  83. while(USB_DRIVER.state != USB_ACTIVE)
  84. chThdSleepMilliseconds(50);
  85. print("USB configured.\n");
  86. /* init TMK modules */
  87. keyboard_init();
  88. host_set_driver(&chibios_driver);
  89. #ifdef SLEEP_LED_ENABLE
  90. sleep_led_init();
  91. #endif
  92. print("Keyboard start.\n");
  93. /* Main loop */
  94. while(true) {
  95. /* TODO: check for suspended event */
  96. keyboard_task();
  97. chThdSleepMilliseconds(5);
  98. }
  99. }