USB_Host_Shield_2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hid.cpp
Go to the documentation of this file.
1 #include "hid.h"
2 
3 //get HID report descriptor
4 uint8_t HID::GetReportDescr( uint8_t ep, USBReadParser *parser )
5 {
6  const uint8_t constBufLen = 64;
7  uint8_t buf[constBufLen];
8 
9  uint8_t rcode = pUsb->ctrlReq( bAddress, ep, bmREQ_HIDREPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00,
10  HID_DESCRIPTOR_REPORT, 0x0000, 128, constBufLen, buf, (USBReadParser*)parser );
11 
12  //return ((rcode != hrSTALL) ? rcode : 0);
13  return rcode;
14 }
15 //uint8_t HID::getHidDescr( uint8_t ep, uint16_t nbytes, uint8_t* dataptr )
16 //{
17 // return( pUsb->ctrlReq( bAddress, ep, bmREQ_GET_DESCR, USB_REQUEST_GET_DESCRIPTOR, 0x00, HID_DESCRIPTOR_HID, 0x0000, nbytes, dataptr ));
18 //}
19 uint8_t HID::SetReport( uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr )
20 {
21  return( pUsb->ctrlReq( bAddress, ep, bmREQ_HIDOUT, HID_REQUEST_SET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL ));
22 }
23 uint8_t HID::GetReport( uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr )
24 {
25  return( pUsb->ctrlReq( bAddress, ep, bmREQ_HIDIN, HID_REQUEST_GET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL ));
26 }
27 uint8_t HID::GetIdle( uint8_t iface, uint8_t reportID, uint8_t* dataptr )
28 {
29  return( pUsb->ctrlReq( bAddress, 0, bmREQ_HIDIN, HID_REQUEST_GET_IDLE, reportID, 0, iface, 0x0001, 0x0001, dataptr, NULL ));
30 }
31 uint8_t HID::SetIdle( uint8_t iface, uint8_t reportID, uint8_t duration )
32 {
33  return( pUsb->ctrlReq( bAddress, 0, bmREQ_HIDOUT, HID_REQUEST_SET_IDLE, reportID, duration, iface, 0x0000, 0x0000, NULL, NULL ));
34 }
35 uint8_t HID::SetProtocol( uint8_t iface, uint8_t protocol )
36 {
37  return( pUsb->ctrlReq( bAddress, 0, bmREQ_HIDOUT, HID_REQUEST_SET_PROTOCOL, protocol, 0x00, iface, 0x0000, 0x0000, NULL, NULL ));
38 }
39 uint8_t HID::GetProtocol( uint8_t iface, uint8_t* dataptr )
40 {
41  return( pUsb->ctrlReq( bAddress, 0, bmREQ_HIDIN, HID_REQUEST_GET_PROTOCOL, 0x00, 0x00, iface, 0x0001, 0x0001, dataptr, NULL ));
42 }
43 
45 {
46  Notify(PSTR("Endpoint descriptor:"));
47  Notify(PSTR("\r\nLength:\t\t"));
48  PrintHex<uint8_t>(ep_ptr->bLength);
49  Notify(PSTR("\r\nType:\t\t"));
50  PrintHex<uint8_t>(ep_ptr->bDescriptorType);
51  Notify(PSTR("\r\nAddress:\t"));
52  PrintHex<uint8_t>(ep_ptr->bEndpointAddress);
53  Notify(PSTR("\r\nAttributes:\t"));
54  PrintHex<uint8_t>(ep_ptr->bmAttributes);
55  Notify(PSTR("\r\nMaxPktSize:\t"));
56  PrintHex<uint16_t>(ep_ptr->wMaxPacketSize);
57  Notify(PSTR("\r\nPoll Intrv:\t"));
58  PrintHex<uint8_t>(ep_ptr->bInterval);
59 }
60 
62 {
63  Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"));
64  Notify(PSTR("bDescLength:\t\t"));
65  PrintHex<uint8_t>(pDesc->bLength);
66 
67  Notify(PSTR("\r\nbDescriptorType:\t"));
68  PrintHex<uint8_t>(pDesc->bDescriptorType);
69 
70  Notify(PSTR("\r\nbcdHID:\t\t\t"));
71  PrintHex<uint16_t>(pDesc->bcdHID);
72 
73  Notify(PSTR("\r\nbCountryCode:\t\t"));
74  PrintHex<uint8_t>(pDesc->bCountryCode);
75 
76  Notify(PSTR("\r\nbNumDescriptors:\t"));
77  PrintHex<uint8_t>(pDesc->bNumDescriptors);
78 
79  Notify(PSTR("\r\nbDescrType:\t\t"));
80  PrintHex<uint8_t>(pDesc->bDescrType);
81 
82  Notify(PSTR("\r\nwDescriptorLength:\t"));
83  PrintHex<uint16_t>(pDesc->wDescriptorLength);
84 }