diff options
Diffstat (limited to 'converter/usb_usb/main.cpp')
| -rw-r--r-- | converter/usb_usb/main.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/converter/usb_usb/main.cpp b/converter/usb_usb/main.cpp new file mode 100644 index 000000000..00d2d59b6 --- /dev/null +++ b/converter/usb_usb/main.cpp | |||
| @@ -0,0 +1,95 @@ | |||
| 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 | |||
| 7 | // USB HID host | ||
| 8 | #include "Usb.h" | ||
| 9 | #include "hid.h" | ||
| 10 | #include "hidboot.h" | ||
| 11 | #include "parser.h" | ||
| 12 | |||
| 13 | // LUFA | ||
| 14 | #include "lufa.h" | ||
| 15 | |||
| 16 | #include "debug.h" | ||
| 17 | #include "keyboard.h" | ||
| 18 | |||
| 19 | #include "leonardo_led.h" | ||
| 20 | |||
| 21 | |||
| 22 | static USB usb_host; | ||
| 23 | static HIDBoot<HID_PROTOCOL_KEYBOARD> kbd(&usb_host); | ||
| 24 | static KBDReportParser kbd_parser; | ||
| 25 | |||
| 26 | static void LUFA_setup(void) | ||
| 27 | { | ||
| 28 | /* Disable watchdog if enabled by bootloader/fuses */ | ||
| 29 | MCUSR &= ~(1 << WDRF); | ||
| 30 | wdt_disable(); | ||
| 31 | |||
| 32 | /* Disable clock division */ | ||
| 33 | clock_prescale_set(clock_div_1); | ||
| 34 | |||
| 35 | // Leonardo needs. Without this USB device is not recognized. | ||
| 36 | USB_Disable(); | ||
| 37 | |||
| 38 | USB_Init(); | ||
| 39 | |||
| 40 | // for Console_Task | ||
| 41 | USB_Device_EnableSOFEvents(); | ||
| 42 | } | ||
| 43 | |||
| 44 | static void HID_setup() | ||
| 45 | { | ||
| 46 | if (usb_host.Init() == -1) { | ||
| 47 | debug("HID init: failed\n"); | ||
| 48 | LED_TX_OFF; | ||
| 49 | } | ||
| 50 | |||
| 51 | _delay_ms(200); | ||
| 52 | |||
| 53 | kbd.SetReportParser(0, (HIDReportParser*)&kbd_parser); | ||
| 54 | } | ||
| 55 | |||
| 56 | int main(void) | ||
| 57 | { | ||
| 58 | // LED for debug | ||
| 59 | LED_TX_INIT; | ||
| 60 | LED_TX_ON; | ||
| 61 | |||
| 62 | print_enable = true; | ||
| 63 | debug_enable = true; | ||
| 64 | debug_matrix = true; | ||
| 65 | debug_keyboard = true; | ||
| 66 | debug_mouse = true; | ||
| 67 | |||
| 68 | host_set_driver(&lufa_driver); | ||
| 69 | keyboard_init(); | ||
| 70 | |||
| 71 | LUFA_setup(); | ||
| 72 | sei(); | ||
| 73 | |||
| 74 | // wait for startup of sendchar routine | ||
| 75 | while (USB_DeviceState != DEVICE_STATE_Configured) ; | ||
| 76 | if (debug_enable) { | ||
| 77 | _delay_ms(1000); | ||
| 78 | } | ||
| 79 | |||
| 80 | HID_setup(); | ||
| 81 | |||
| 82 | debug("init: done\n"); | ||
| 83 | for (;;) { | ||
| 84 | keyboard_proc(); | ||
| 85 | |||
| 86 | usb_host.Task(); | ||
| 87 | |||
| 88 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) | ||
| 89 | // LUFA Task for control request | ||
| 90 | USB_USBTask(); | ||
| 91 | #endif | ||
| 92 | } | ||
| 93 | |||
| 94 | return 0; | ||
| 95 | } | ||
