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