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 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <avr/io.h>
  2. #include <avr/power.h>
  3. #include <avr/wdt.h>
  4. #include "lufa.h"
  5. #include "print.h"
  6. #include "sendchar.h"
  7. static void SetupHardware(void)
  8. {
  9. /* Disable watchdog if enabled by bootloader/fuses */
  10. MCUSR &= ~(1 << WDRF);
  11. wdt_disable();
  12. /* Disable clock division */
  13. clock_prescale_set(clock_div_1);
  14. // Leonardo needs. Without this USB device is not recognized.
  15. USB_Disable();
  16. USB_Init();
  17. // for Console_Task
  18. USB_Device_EnableSOFEvents();
  19. print_set_sendchar(sendchar);
  20. }
  21. int main(void) __attribute__ ((weak));
  22. int main(void)
  23. {
  24. SetupHardware();
  25. sei();
  26. /* wait for USB startup & debug output */
  27. while (USB_DeviceState != DEVICE_STATE_Configured) {
  28. #if defined(INTERRUPT_CONTROL_ENDPOINT)
  29. ;
  30. #else
  31. USB_USBTask();
  32. #endif
  33. }
  34. print("USB configured.\n");
  35. /* init modules */
  36. keyboard_init();
  37. host_set_driver(&lufa_driver);
  38. #ifdef SLEEP_LED_ENABLE
  39. sleep_led_init();
  40. #endif
  41. print("Keyboard start.\n");
  42. while (1) {
  43. while (USB_DeviceState == DEVICE_STATE_Suspended) {
  44. suspend_power_down();
  45. if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
  46. USB_Device_SendRemoteWakeup();
  47. }
  48. }
  49. keyboard_task();
  50. #if !defined(INTERRUPT_CONTROL_ENDPOINT)
  51. USB_USBTask();
  52. #endif
  53. }
  54. }