1 | /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
|
---|
2 |
|
---|
3 | This software may be distributed and modified under the terms of the GNU
|
---|
4 | General Public License version 2 (GPL2) as published by the Free Software
|
---|
5 | Foundation and appearing in the file GPL2.TXT included in the packaging of
|
---|
6 | this file. Please note that GPL2 Section 2[b] requires that all works based
|
---|
7 | on this software must also be made publicly available under the terms of
|
---|
8 | the GPL2 ("Copyleft").
|
---|
9 |
|
---|
10 | Contact information
|
---|
11 | -------------------
|
---|
12 |
|
---|
13 | Circuits At Home, LTD
|
---|
14 | Web : http://www.circuitsathome.com
|
---|
15 | e-mail : support@circuitsathome.com
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include "hid.h"
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * \brief Get HID report descriptor and parse it.
|
---|
22 | *
|
---|
23 | * \param ep USB device endpoint.
|
---|
24 | * \param parser Parser used to decode report.
|
---|
25 | *
|
---|
26 | * \return 0 on success, error code otherwise.
|
---|
27 | */
|
---|
28 | uint32_t HID::GetReportDescr(uint32_t ep, USBReadParser *parser)
|
---|
29 | {
|
---|
30 | const uint32_t constBufLen = 64;
|
---|
31 | uint8_t buf[constBufLen];
|
---|
32 |
|
---|
33 | return (pUsb->ctrlReq(bAddress, ep, bmREQ_HIDREPORT, USB_REQUEST_GET_DESCRIPTOR, 0x00,
|
---|
34 | HID_DESCRIPTOR_REPORT, 0x0000, 128, constBufLen, buf, (USBReadParser*)parser));
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * \brief Set HID report descriptor.
|
---|
39 | *
|
---|
40 | * \param ep USB device endpoint.
|
---|
41 | * \param iface Interface number.
|
---|
42 | * \param report_type HID report type.
|
---|
43 | * \param report_id HID report ID.
|
---|
44 | * \param nbytes Buffer length.
|
---|
45 | * \param dataptr Buffer containing the HID report to send.
|
---|
46 | *
|
---|
47 | * \return 0 on success, error code otherwise.
|
---|
48 | */
|
---|
49 | uint32_t HID::SetReport(uint32_t ep, uint32_t iface, uint32_t report_type, uint32_t report_id, uint32_t nbytes, uint8_t* dataptr)
|
---|
50 | {
|
---|
51 | return (pUsb->ctrlReq(bAddress, ep, bmREQ_HIDOUT, HID_REQUEST_SET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL));
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * \brief Get HID report descriptor.
|
---|
56 | *
|
---|
57 | * \param ep USB device endpoint.
|
---|
58 | * \param iface Interface number.
|
---|
59 | * \param report_type HID report type.
|
---|
60 | * \param report_id HID report ID.
|
---|
61 | * \param nbytes Buffer length.
|
---|
62 | * \param dataptr Buffer containing the HID report to send.
|
---|
63 | *
|
---|
64 | * \return 0 on success, error code otherwise.
|
---|
65 | */
|
---|
66 | uint32_t HID::GetReport(uint32_t ep, uint32_t iface, uint32_t report_type, uint32_t report_id, uint32_t nbytes, uint8_t* dataptr)
|
---|
67 | {
|
---|
68 | return (pUsb->ctrlReq(bAddress, ep, bmREQ_HIDIN, HID_REQUEST_GET_REPORT, report_id, report_type, iface, nbytes, nbytes, dataptr, NULL));
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * \brief Get HID idle status.
|
---|
73 | *
|
---|
74 | * \param iface Interface number.
|
---|
75 | * \param report_id HID report ID.
|
---|
76 | * \param dataptr Buffer to receive data. Size must be >= 1.
|
---|
77 | *
|
---|
78 | * \return 0 on success, error code otherwise.
|
---|
79 | */
|
---|
80 | uint32_t HID::GetIdle(uint32_t iface, uint32_t report_id, uint8_t* dataptr)
|
---|
81 | {
|
---|
82 | return (pUsb->ctrlReq(bAddress, 0, bmREQ_HIDIN, HID_REQUEST_GET_IDLE, report_id, 0, iface, 0x0001, 0x0001, dataptr, NULL));
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | * \brief Set HID idle status.
|
---|
87 | *
|
---|
88 | * \param iface Interface number.
|
---|
89 | * \param report_id HID report ID.
|
---|
90 | * \param duration Status duration.
|
---|
91 | *
|
---|
92 | * \return 0 on success, error code otherwise.
|
---|
93 | */
|
---|
94 | uint32_t HID::SetIdle(uint32_t iface, uint32_t report_id, uint32_t duration)
|
---|
95 | {
|
---|
96 | return (pUsb->ctrlReq(bAddress, 0, bmREQ_HIDOUT, HID_REQUEST_SET_IDLE, report_id, duration, iface, 0x0000, 0x0000, NULL, NULL));
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * \brief Set HID protocol.
|
---|
101 | *
|
---|
102 | * \param iface Interface number.
|
---|
103 | * \param protocol Protocol value.
|
---|
104 | *
|
---|
105 | * \return 0 on success, error code otherwise.
|
---|
106 | */
|
---|
107 | uint32_t HID::SetProtocol(uint32_t iface, uint32_t protocol)
|
---|
108 | {
|
---|
109 | return (pUsb->ctrlReq(bAddress, 0, bmREQ_HIDOUT, HID_REQUEST_SET_PROTOCOL, protocol, 0x00, iface, 0x0000, 0x0000, NULL, NULL));
|
---|
110 | }
|
---|
111 |
|
---|
112 | /**
|
---|
113 | * \brief Get HID protocol.
|
---|
114 | *
|
---|
115 | * \param iface Interface number.
|
---|
116 | * \param dataptr Buffer used to store protocol value. Size must be >= 1.
|
---|
117 | *
|
---|
118 | * \return 0 on success, error code otherwise.
|
---|
119 | */
|
---|
120 | uint32_t HID::GetProtocol(uint32_t iface, uint8_t* dataptr)
|
---|
121 | {
|
---|
122 | return (pUsb->ctrlReq(bAddress, 0, bmREQ_HIDIN, HID_REQUEST_GET_PROTOCOL, 0x00, 0x00, iface, 0x0001, 0x0001, dataptr, NULL));
|
---|
123 | }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * \brief Print HID descriptor.
|
---|
127 | *
|
---|
128 | * \note TRACE_USBHOST macro must be enabled. See Usb.h for reference.
|
---|
129 | *
|
---|
130 | * \param pDesc Pointer to HID descriptor.
|
---|
131 | */
|
---|
132 | void HID::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc)
|
---|
133 | {
|
---|
134 | TRACE_USBHOST(printf("HID::PrintHidDescriptor : bDescLength: %d\r\n", pDesc->bLength);)
|
---|
135 | TRACE_USBHOST(printf("HID::PrintHidDescriptor : bDescriptorType: %d\r\n", pDesc->bDescriptorType);)
|
---|
136 | TRACE_USBHOST(printf("HID::PrintHidDescriptor : bcdHID: %d\r\n", pDesc->bcdHID);)
|
---|
137 | TRACE_USBHOST(printf("HID::PrintHidDescriptor : bCountryCode: %d\r\n", pDesc->bCountryCode);)
|
---|
138 | TRACE_USBHOST(printf("HID::PrintHidDescriptor : bNumDescriptors: %d\r\n", pDesc->bNumDescriptors);)
|
---|
139 | TRACE_USBHOST(printf("HID::PrintHidDescriptor : bDescrType: %d\r\n", pDesc->bDescrType);)
|
---|
140 | TRACE_USBHOST(printf("HID::PrintHidDescriptor : wDescriptorLength: %d\r\n", pDesc->wDescriptorLength);)
|
---|
141 | }
|
---|