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.cpp 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <avr/io.h>
  2. #include <avr/wdt.h>
  3. #include <avr/power.h>
  4. #include <util/delay.h>
  5. // LUFA
  6. #include "lufa.h"
  7. #include "sendchar.h"
  8. #include "debug.h"
  9. #include "keyboard.h"
  10. #include "led.h"
  11. /* LED ping configuration */
  12. #define TMK_LED
  13. //#define LEONARDO_LED
  14. #if defined(TMK_LED)
  15. // For TMK converter and Teensy
  16. #define LED_TX_INIT (DDRD |= (1<<6))
  17. #define LED_TX_ON (PORTD |= (1<<6))
  18. #define LED_TX_OFF (PORTD &= ~(1<<6))
  19. #define LED_TX_TOGGLE (PORTD ^= (1<<6))
  20. #elif defined(LEONARDO_LED)
  21. // For Leonardo(TX LED)
  22. #define LED_TX_INIT (DDRD |= (1<<5))
  23. #define LED_TX_ON (PORTD &= ~(1<<5))
  24. #define LED_TX_OFF (PORTD |= (1<<5))
  25. #define LED_TX_TOGGLE (PORTD ^= (1<<5))
  26. #else
  27. #define LED_TX_INIT
  28. #define LED_TX_ON
  29. #define LED_TX_OFF
  30. #define LED_TX_TOGGLE
  31. #endif
  32. static void LUFA_setup(void)
  33. {
  34. /* Disable watchdog if enabled by bootloader/fuses */
  35. MCUSR &= ~(1 << WDRF);
  36. wdt_disable();
  37. /* Disable clock division */
  38. clock_prescale_set(clock_div_1);
  39. // Leonardo needs. Without this USB device is not recognized.
  40. USB_Disable();
  41. USB_Init();
  42. // for Console_Task
  43. USB_Device_EnableSOFEvents();
  44. print_set_sendchar(sendchar);
  45. }
  46. int main(void)
  47. {
  48. // LED for debug
  49. LED_TX_INIT;
  50. LED_TX_ON;
  51. debug_enable = true;
  52. debug_keyboard = true;
  53. host_set_driver(&lufa_driver);
  54. keyboard_init();
  55. LUFA_setup();
  56. /* NOTE: Don't insert time consuming job here.
  57. * It'll cause unclear initialization failure when DFU reset(worm start).
  58. */
  59. sei();
  60. // wait for startup of sendchar routine
  61. while (USB_DeviceState != DEVICE_STATE_Configured) ;
  62. if (debug_enable) {
  63. _delay_ms(1000);
  64. }
  65. debug("init: done\n");
  66. for (;;) {
  67. keyboard_task();
  68. #if !defined(INTERRUPT_CONTROL_ENDPOINT)
  69. // LUFA Task for control request
  70. USB_USBTask();
  71. #endif
  72. }
  73. return 0;
  74. }