23
23
24
24
HID_& HID ()
25
25
{
26
- static HID_ obj;
27
- return obj;
26
+ static HID_ obj;
27
+ return obj;
28
28
}
29
29
30
30
int HID_::getInterface (uint8_t * interfaceCount)
31
31
{
32
- *interfaceCount += 1 ; // uses 1
33
- HIDDescriptor hidInterface = {
34
- D_INTERFACE (pluggedInterface, 2 , USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
35
- D_HIDREPORT (descriptorSize),
36
- D_ENDPOINT (USB_ENDPOINT_IN (HID_TX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x14 ),
32
+ *interfaceCount += 1 ; // uses 1
33
+ HIDDescriptor hidInterface = {
34
+ D_INTERFACE (pluggedInterface, 2 , USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE),
35
+ D_HIDREPORT (descriptorSize),
36
+ D_ENDPOINT (USB_ENDPOINT_IN (HID_TX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x14 ),
37
37
D_ENDPOINT (USB_ENDPOINT_OUT (HID_RX), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x0A )
38
- };
39
- return USB_SendControl (0 , &hidInterface, sizeof (hidInterface));
38
+ };
39
+ return USB_SendControl (0 , &hidInterface, sizeof (hidInterface));
40
40
}
41
41
42
42
// Since this function is not exposed in USBCore API, had to replicate here.
@@ -76,27 +76,27 @@ int HID_::getDescriptor(USBSetup& setup)
76
76
}
77
77
}
78
78
79
- // Check if this is a HID Class Descriptor request
80
- if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0 ; }
81
- if (HID_REPORT_DESCRIPTOR_TYPE != t) { return 0 ; }
82
-
83
- // In a HID Class Descriptor wIndex cointains the interface number
84
- if (setup.wIndex != pluggedInterface) { return 0 ; }
85
-
86
- int total = 0 ;
87
- HIDSubDescriptor* node;
88
- for (node = rootNode; node; node = node->next ) {
89
- int res = USB_SendControl (TRANSFER_PGM, node->data , node->length );
90
- if (res == -1 )
91
- return -1 ;
92
- total += res;
93
- }
94
-
95
- // Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol
96
- // due to the USB specs, but Windows and Linux just assumes its in report mode.
97
- protocol = HID_REPORT_PROTOCOL;
98
-
99
- return total;
79
+ // Check if this is a HID Class Descriptor request
80
+ if (setup.bmRequestType != REQUEST_DEVICETOHOST_STANDARD_INTERFACE) { return 0 ; }
81
+ if (HID_REPORT_DESCRIPTOR_TYPE != t) { return 0 ; }
82
+
83
+ // In a HID Class Descriptor wIndex cointains the interface number
84
+ if (setup.wIndex != pluggedInterface) { return 0 ; }
85
+
86
+ int total = 0 ;
87
+ HIDSubDescriptor* node;
88
+ for (node = rootNode; node; node = node->next ) {
89
+ int res = USB_SendControl (TRANSFER_PGM, node->data , node->length );
90
+ if (res == -1 )
91
+ return -1 ;
92
+ total += res;
93
+ }
94
+
95
+ // Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol
96
+ // due to the USB specs, but Windows and Linux just assumes its in report mode.
97
+ protocol = HID_REPORT_PROTOCOL;
98
+
99
+ return total;
100
100
}
101
101
102
102
uint8_t HID_::getShortName (char *name)
@@ -111,27 +111,27 @@ uint8_t HID_::getShortName(char *name)
111
111
112
112
// default serial number
113
113
114
- name[0 ] = ' H' ;
115
- name[1 ] = ' I' ;
116
- name[2 ] = ' D' ;
117
- name[3 ] = ' A' + (descriptorSize & 0x0F );
118
- name[4 ] = ' A' + ((descriptorSize >> 4 ) & 0x0F );
119
- return 5 ;
114
+ name[0 ] = ' H' ;
115
+ name[1 ] = ' I' ;
116
+ name[2 ] = ' D' ;
117
+ name[3 ] = ' A' + (descriptorSize & 0x0F );
118
+ name[4 ] = ' A' + ((descriptorSize >> 4 ) & 0x0F );
119
+ return 5 ;
120
120
}
121
121
}
122
122
123
123
void HID_::AppendDescriptor (HIDSubDescriptor *node)
124
124
{
125
- if (!rootNode) {
126
- rootNode = node;
127
- } else {
128
- HIDSubDescriptor *current = rootNode;
129
- while (current->next ) {
130
- current = current->next ;
131
- }
132
- current->next = node;
133
- }
134
- descriptorSize += node->length ;
125
+ if (!rootNode) {
126
+ rootNode = node;
127
+ } else {
128
+ HIDSubDescriptor *current = rootNode;
129
+ while (current->next ) {
130
+ current = current->next ;
131
+ }
132
+ current->next = node;
133
+ }
134
+ descriptorSize += node->length ;
135
135
}
136
136
137
137
int HID_::SetFeature (uint16_t id, const void * data, int len)
@@ -174,11 +174,11 @@ bool HID_::LockFeature(uint16_t id, bool lock) {
174
174
175
175
int HID_::SendReport (uint16_t id, const void * data, int len)
176
176
{
177
- auto ret = USB_Send (HID_TX, &id, 1 );
178
- if (ret < 0 ) return ret;
179
- auto ret2 = USB_Send (HID_TX | TRANSFER_RELEASE, data, len);
180
- if (ret2 < 0 ) return ret2;
181
- return ret + ret2;
177
+ auto ret = USB_Send (HID_TX, &id, 1 );
178
+ if (ret < 0 ) return ret;
179
+ auto ret2 = USB_Send (HID_TX | TRANSFER_RELEASE, data, len);
180
+ if (ret2 < 0 ) return ret2;
181
+ return ret + ret2;
182
182
}
183
183
184
184
HIDReport* HID_::GetFeature (uint16_t id)
@@ -195,16 +195,16 @@ HIDReport* HID_::GetFeature(uint16_t id)
195
195
196
196
bool HID_::setup (USBSetup& setup)
197
197
{
198
- if (pluggedInterface != setup.wIndex ) {
199
- return false ;
200
- }
198
+ if (pluggedInterface != setup.wIndex ) {
199
+ return false ;
200
+ }
201
201
202
- uint8_t request = setup.bRequest ;
203
- uint8_t requestType = setup.bmRequestType ;
202
+ uint8_t request = setup.bRequest ;
203
+ uint8_t requestType = setup.bmRequestType ;
204
204
205
- if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE)
206
- {
207
- if (request == HID_GET_REPORT) {
205
+ if (requestType == REQUEST_DEVICETOHOST_CLASS_INTERFACE)
206
+ {
207
+ if (request == HID_GET_REPORT) {
208
208
209
209
if (setup.wValueH == HID_REPORT_TYPE_FEATURE)
210
210
{
@@ -219,31 +219,31 @@ bool HID_::setup(USBSetup& setup)
219
219
return false ;
220
220
221
221
}
222
- return true ;
223
- }
224
- if (request == HID_GET_PROTOCOL) {
225
- // TODO: Send8(protocol);
226
- return true ;
227
- }
228
- if (request == HID_GET_IDLE) {
229
- // TODO: Send8(idle);
230
- }
231
- }
232
-
233
- if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE)
234
- {
235
- if (request == HID_SET_PROTOCOL) {
236
- // The USB Host tells us if we are in boot or report mode.
237
- // This only works with a real boot compatible device.
238
- protocol = setup.wValueL ;
239
- return true ;
240
- }
241
- if (request == HID_SET_IDLE) {
242
- idle = setup.wValueL ;
243
- return true ;
244
- }
245
- if (request == HID_SET_REPORT)
246
- {
222
+ return true ;
223
+ }
224
+ if (request == HID_GET_PROTOCOL) {
225
+ // TODO: Send8(protocol);
226
+ return true ;
227
+ }
228
+ if (request == HID_GET_IDLE) {
229
+ // TODO: Send8(idle);
230
+ }
231
+ }
232
+
233
+ if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE)
234
+ {
235
+ if (request == HID_SET_PROTOCOL) {
236
+ // The USB Host tells us if we are in boot or report mode.
237
+ // This only works with a real boot compatible device.
238
+ protocol = setup.wValueL ;
239
+ return true ;
240
+ }
241
+ if (request == HID_SET_IDLE) {
242
+ idle = setup.wValueL ;
243
+ return true ;
244
+ }
245
+ if (request == HID_SET_REPORT)
246
+ {
247
247
if (setup.wValueH == HID_REPORT_TYPE_FEATURE)
248
248
{
249
249
@@ -259,24 +259,24 @@ bool HID_::setup(USBSetup& setup)
259
259
260
260
}
261
261
262
- }
263
- }
262
+ }
263
+ }
264
264
265
- return false ;
265
+ return false ;
266
266
}
267
267
268
268
HID_::HID_ (void ) : PluggableUSBModule(2 , 1 , epType),
269
269
rootNode(NULL ), descriptorSize(0 ),
270
270
protocol(HID_REPORT_PROTOCOL), idle(1 )
271
271
{
272
- epType[0 ] = EP_TYPE_INTERRUPT_IN;
272
+ epType[0 ] = EP_TYPE_INTERRUPT_IN;
273
273
epType[1 ] = EP_TYPE_INTERRUPT_OUT;
274
- PluggableUSB ().plug (this );
274
+ PluggableUSB ().plug (this );
275
275
}
276
276
277
277
int HID_::begin (void )
278
278
{
279
- return 0 ;
279
+ return 0 ;
280
280
}
281
281
282
282
#endif /* if defined(USBCON) */
0 commit comments