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.

test.cpp 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include <avr/io.h>
  2. #include <avr/wdt.h>
  3. #include <avr/power.h>
  4. #include <util/delay.h>
  5. #include <Arduino.h>
  6. // USB HID host
  7. #include "Usb.h"
  8. #include "hid.h"
  9. #include "hidboot.h"
  10. #include "parser.h"
  11. // LUFA
  12. #include "lufa.h"
  13. #include "debug.h"
  14. #include "leonardo_led.h"
  15. static USB usb_host;
  16. static HIDBoot<HID_PROTOCOL_KEYBOARD> kbd(&usb_host);
  17. static KBDReportParser kbd_parser;
  18. static void LUFA_setup(void)
  19. {
  20. /* Disable watchdog if enabled by bootloader/fuses */
  21. MCUSR &= ~(1 << WDRF);
  22. wdt_disable();
  23. /* Disable clock division */
  24. clock_prescale_set(clock_div_1);
  25. // Leonardo needs. Without this USB device is not recognized.
  26. USB_Disable();
  27. USB_Init();
  28. // for Console_Task
  29. USB_Device_EnableSOFEvents();
  30. }
  31. static void HID_setup()
  32. {
  33. // Arduino Timer startup: wiring.c
  34. init();
  35. if (usb_host.Init() == -1) {
  36. debug("HID init: failed\n");
  37. LED_TX_OFF;
  38. }
  39. _delay_ms(200);
  40. kbd.SetReportParser(0, (HIDReportParser*)&kbd_parser);
  41. }
  42. int main(void)
  43. {
  44. // LED for debug
  45. LED_TX_INIT;
  46. LED_TX_ON;
  47. print_enable = true;
  48. debug_enable = true;
  49. debug_matrix = true;
  50. debug_keyboard = true;
  51. debug_mouse = true;
  52. LUFA_setup();
  53. sei();
  54. // wait for startup of sendchar routine
  55. while (USB_DeviceState != DEVICE_STATE_Configured) ;
  56. if (debug_enable) {
  57. _delay_ms(1000);
  58. }
  59. HID_setup();
  60. debug("init: done\n");
  61. for (;;) {
  62. usb_host.Task();
  63. #if !defined(INTERRUPT_CONTROL_ENDPOINT)
  64. // LUFA Task for control request
  65. USB_USBTask();
  66. #endif
  67. }
  68. return 0;
  69. }