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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

main.c 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. host_driver_t chibios_driver = {
  38. keyboard_leds,
  39. send_keyboard,
  40. send_mouse,
  41. send_system,
  42. send_consumer
  43. };
  44. /* TESTING
  45. * Amber LED blinker thread, times are in milliseconds.
  46. */
  47. // uint8_t blinkLedState = 0;
  48. // static THD_WORKING_AREA(waThread1, 128);
  49. // static THD_FUNCTION(Thread1, arg) {
  50. // (void)arg;
  51. // chRegSetThreadName("blinker1");
  52. // while(true) {
  53. // if(blinkLedState) {
  54. // blinkLedState = 0;
  55. // palSetPad(GPIOC, GPIOC_LED_ORANGE);
  56. // chThdSleepMilliseconds(100);
  57. // palClearPad(GPIOC, GPIOC_LED_ORANGE);
  58. // }
  59. // chThdSleepMilliseconds(100);
  60. // }
  61. // }
  62. /* Main thread
  63. */
  64. int main(void) {
  65. /* ChibiOS/RT init */
  66. halInit();
  67. chSysInit();
  68. palSetPad(GPIOC, GPIOC_LED_BLUE);
  69. chThdSleepMilliseconds(400);
  70. palClearPad(GPIOC, GPIOC_LED_BLUE);
  71. // TESTING
  72. // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
  73. /* Init USB */
  74. init_usb_driver(&USB_DRIVER);
  75. /* init printf */
  76. init_printf(NULL,sendchar_pf);
  77. /* Wait until the USB is active */
  78. while(USB_DRIVER.state != USB_ACTIVE)
  79. chThdSleepMilliseconds(50);
  80. print("USB configured.\n");
  81. /* init TMK modules */
  82. keyboard_init();
  83. host_set_driver(&chibios_driver);
  84. #ifdef SLEEP_LED_ENABLE
  85. sleep_led_init();
  86. #endif
  87. print("Keyboard start.\n");
  88. /* Main loop */
  89. while(true) {
  90. /* TODO: check for suspended event */
  91. keyboard_task();
  92. chThdSleepMilliseconds(5);
  93. }
  94. }