]> git.gir.st - tmk_keyboard.git/blob - protocol/usb_hid/USB_Host_Shield_2.0/examples/HID/USBHID_desc/USBHID_desc.ino
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / usb_hid / USB_Host_Shield_2.0 / examples / HID / USBHID_desc / USBHID_desc.ino
1 #include <hid.h>
2 #include <hiduniversal.h>
3 #include <hidescriptorparser.h>
4 #include <usbhub.h>
5 #include "pgmstrings.h"
6
7 // Satisfy the IDE, which needs to see the include statment in the ino too.
8 #ifdef dobogusinclude
9 #include <spi4teensy3.h>
10 #include <SPI.h>
11 #endif
12
13 class HIDUniversal2 : public HIDUniversal
14 {
15 public:
16 HIDUniversal2(USB *usb) : HIDUniversal(usb) {};
17
18 protected:
19 uint8_t OnInitSuccessful();
20 };
21
22 uint8_t HIDUniversal2::OnInitSuccessful()
23 {
24 uint8_t rcode;
25
26 HexDumper<USBReadParser, uint16_t, uint16_t> Hex;
27 ReportDescParser Rpt;
28
29 if ((rcode = GetReportDescr(0, &Hex)))
30 goto FailGetReportDescr1;
31
32 if ((rcode = GetReportDescr(0, &Rpt)))
33 goto FailGetReportDescr2;
34
35 return 0;
36
37 FailGetReportDescr1:
38 USBTRACE("GetReportDescr1:");
39 goto Fail;
40
41 FailGetReportDescr2:
42 USBTRACE("GetReportDescr2:");
43 goto Fail;
44
45 Fail:
46 Serial.println(rcode, HEX);
47 Release();
48 return rcode;
49 }
50
51 USB Usb;
52 //USBHub Hub(&Usb);
53 HIDUniversal2 Hid(&Usb);
54 UniversalReportParser Uni;
55
56 void setup()
57 {
58 Serial.begin( 115200 );
59 #if !defined(__MIPSEL__)
60 while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
61 #endif
62 Serial.println("Start");
63
64 if (Usb.Init() == -1)
65 Serial.println("OSC did not start.");
66
67 delay( 200 );
68
69 if (!Hid.SetReportParser(0, &Uni))
70 ErrorMessage<uint8_t>(PSTR("SetReportParser"), 1 );
71 }
72
73 void loop()
74 {
75 Usb.Task();
76 }
77
Imprint / Impressum