Keyboard firmwares for Atmel AVR and Cortex-M
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. #include "rn42.h"
  8. #include "rn42_task.h"
  9. #include "serial.h"
  10. #include "keyboard.h"
  11. #include "keycode.h"
  12. #include "action.h"
  13. #include "action_util.h"
  14. #include "wait.h"
  15. #include "suart.h"
  16. #include "suspend.h"
  17. static int8_t sendchar_func(uint8_t c)
  18. {
  19. sendchar(c); // LUFA
  20. xmit(c); // SUART
  21. return 0;
  22. }
  23. static void SetupHardware(void)
  24. {
  25. /* Disable watchdog if enabled by bootloader/fuses */
  26. MCUSR &= ~(1 << WDRF);
  27. wdt_disable();
  28. /* Disable clock division */
  29. clock_prescale_set(clock_div_1);
  30. // Leonardo needs. Without this USB device is not recognized.
  31. USB_Disable();
  32. USB_Init();
  33. // for Console_Task
  34. USB_Device_EnableSOFEvents();
  35. print_set_sendchar(sendchar_func);
  36. // SUART PD0:output, PD1:input
  37. DDRD |= (1<<0);
  38. PORTD |= (1<<0);
  39. DDRD &= ~(1<<1);
  40. PORTD |= (1<<1);
  41. }
  42. int main(void) __attribute__ ((weak));
  43. int main(void)
  44. {
  45. SetupHardware();
  46. sei();
  47. /* wait for USB startup to get ready for debug output */
  48. uint8_t timeout = 255; // timeout when USB is not available(Bluetooth)
  49. while (timeout-- && USB_DeviceState != DEVICE_STATE_Configured) {
  50. wait_ms(4);
  51. #if defined(INTERRUPT_CONTROL_ENDPOINT)
  52. ;
  53. #else
  54. USB_USBTask();
  55. #endif
  56. }
  57. print("USB configured.\n");
  58. rn42_init();
  59. rn42_task_init();
  60. print("RN-42 init\n");
  61. /* init modules */
  62. keyboard_init();
  63. if (!rn42_rts()) {
  64. host_set_driver(&rn42_driver);
  65. } else {
  66. host_set_driver(&lufa_driver);
  67. }
  68. #ifdef SLEEP_LED_ENABLE
  69. sleep_led_init();
  70. #endif
  71. print("Keyboard start.\n");
  72. while (1) {
  73. while (USB_DeviceState == DEVICE_STATE_Suspended) {
  74. suspend_power_down();
  75. if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
  76. USB_Device_SendRemoteWakeup();
  77. }
  78. }
  79. keyboard_task();
  80. #if !defined(INTERRUPT_CONTROL_ENDPOINT)
  81. USB_USBTask();
  82. #endif
  83. rn42_task();
  84. }
  85. }