source: mainline/uspace/drv/usbhid/usbhid.c@ 9843942

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9843942 was f3f9733, checked in by Lubos Slovak <lubos.slovak@…>, 14 years ago

Modified subdriver matching with report IDs

  • Property mode set to 100644
File size: 20.8 KB
Line 
1/*
2 * Copyright (c) 2011 Lubos Slovak
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup drvusbhid
30 * @{
31 */
32/**
33 * @file
34 * USB HID driver API.
35 */
36
37#include <usb/debug.h>
38#include <usb/classes/classes.h>
39#include <usb/hid/hid.h>
40#include <usb/hid/hidparser.h>
41#include <usb/hid/hidreport.h>
42#include <usb/hid/request.h>
43#include <errno.h>
44#include <str_error.h>
45
46#include "usbhid.h"
47
48#include "kbd/kbddev.h"
49#include "generic/hiddev.h"
50#include "mouse/mousedev.h"
51#include "subdrivers.h"
52
53/*----------------------------------------------------------------------------*/
54
55/* Array of endpoints expected on the device, NULL terminated. */
56usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1] = {
57 &usb_hid_kbd_poll_endpoint_description,
58 &usb_hid_mouse_poll_endpoint_description,
59 &usb_hid_generic_poll_endpoint_description,
60 NULL
61};
62
63static const int USB_HID_MAX_SUBDRIVERS = 10;
64
65/** @todo What happens if this is not fibril local? */
66//static fibril_local bool report_number;
67
68/*----------------------------------------------------------------------------*/
69
70static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev)
71{
72 assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
73
74 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
75 sizeof(usb_hid_subdriver_t));
76 if (hid_dev->subdrivers == NULL) {
77 return ENOMEM;
78 }
79
80 assert(hid_dev->subdriver_count >= 0);
81
82 // set the init callback
83 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_kbd_init;
84
85 // set the polling callback
86 hid_dev->subdrivers[hid_dev->subdriver_count].poll =
87 usb_kbd_polling_callback;
88
89 // set the polling ended callback
90 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
91
92 // set the deinit callback
93 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_kbd_deinit;
94
95 // set subdriver count
96 ++hid_dev->subdriver_count;
97
98 return EOK;
99}
100
101/*----------------------------------------------------------------------------*/
102
103static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev)
104{
105 assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
106
107 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
108 sizeof(usb_hid_subdriver_t));
109 if (hid_dev->subdrivers == NULL) {
110 return ENOMEM;
111 }
112
113 assert(hid_dev->subdriver_count >= 0);
114
115 // set the init callback
116 hid_dev->subdrivers[hid_dev->subdriver_count].init = usb_mouse_init;
117
118 // set the polling callback
119 hid_dev->subdrivers[hid_dev->subdriver_count].poll =
120 usb_mouse_polling_callback;
121
122 // set the polling ended callback
123 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
124
125 // set the deinit callback
126 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = usb_mouse_deinit;
127
128 // set subdriver count
129 ++hid_dev->subdriver_count;
130
131 return EOK;
132}
133
134/*----------------------------------------------------------------------------*/
135
136static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev)
137{
138 assert(hid_dev != NULL && hid_dev->subdriver_count == 0);
139
140 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc(
141 sizeof(usb_hid_subdriver_t));
142 if (hid_dev->subdrivers == NULL) {
143 return ENOMEM;
144 }
145
146 assert(hid_dev->subdriver_count >= 0);
147
148 // set the init callback
149 hid_dev->subdrivers[hid_dev->subdriver_count].init =
150 usb_generic_hid_init;
151
152 // set the polling callback
153 hid_dev->subdrivers[hid_dev->subdriver_count].poll =
154 usb_generic_hid_polling_callback;
155
156 // set the polling ended callback
157 hid_dev->subdrivers[hid_dev->subdriver_count].poll_end = NULL;
158
159 // set the deinit callback
160 hid_dev->subdrivers[hid_dev->subdriver_count].deinit = NULL;
161
162 // set subdriver count
163 ++hid_dev->subdriver_count;
164
165 return EOK;
166}
167
168/*----------------------------------------------------------------------------*/
169
170static bool usb_hid_ids_match(usb_hid_dev_t *hid_dev,
171 const usb_hid_subdriver_mapping_t *mapping)
172{
173 assert(hid_dev != NULL);
174 assert(hid_dev->usb_dev != NULL);
175
176 return (hid_dev->usb_dev->descriptors.device.vendor_id
177 == mapping->vendor_id
178 && hid_dev->usb_dev->descriptors.device.product_id
179 == mapping->product_id);
180}
181
182/*----------------------------------------------------------------------------*/
183
184static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev,
185 const usb_hid_subdriver_mapping_t *mapping)
186{
187 assert(hid_dev != NULL);
188 assert(mapping != NULL);
189
190 usb_hid_report_path_t *usage_path = usb_hid_report_path();
191 if (usage_path == NULL) {
192 usb_log_debug("Failed to create usage path.\n");
193 return false;
194 }
195 int i = 0;
196 while (mapping->usage_path[i].usage != 0
197 || mapping->usage_path[i].usage_page != 0) {
198 if (usb_hid_report_path_append_item(usage_path,
199 mapping->usage_path[i].usage_page,
200 mapping->usage_path[i].usage) != EOK) {
201 usb_log_debug("Failed to append to usage path.\n");
202 usb_hid_report_path_free(usage_path);
203 return false;
204 }
205 ++i;
206 }
207
208// if (mapping->report_id >= 0) {
209// usb_hid_report_path_set_report_id(usage_path,
210// mapping->report_id);
211// }
212
213 assert(hid_dev->report != NULL);
214
215 usb_log_debug("Compare flags: %d\n", mapping->compare);
216// size_t size = usb_hid_report_size(hid_dev->report, 0,
217// USB_HID_REPORT_TYPE_INPUT);
218// size_t size = 0;
219
220 bool matches = false;
221
222// usb_hid_report_description_t *report_des =
223// usb_hid_report_find_description(hid_dev->report,
224// mapping->report_id, USB_HID_REPORT_TYPE_INPUT);
225 uint8_t report_id = mapping->report_id;
226
227 /*while(report_des != NULL)*/do {
228
229// if((mapping->report_id) == 0 && (report_des->report_id != 0)) {
230// usb_hid_report_path_set_report_id(usage_path,
231// report_des->report_id);
232// }
233
234 usb_log_debug("Trying report id %u\n", report_id);
235
236 if (report_id != 0) {
237 usb_hid_report_path_set_report_id(usage_path,
238 report_id);
239 }
240
241 usb_hid_report_field_t *field = usb_hid_report_get_sibling(
242 hid_dev->report,
243 NULL, usage_path, mapping->compare,
244 USB_HID_REPORT_TYPE_INPUT);
245
246 usb_log_debug("Field: %p\n", field);
247
248 if (field != NULL) {
249// size++;
250// field = usb_hid_report_get_sibling(hid_dev->report,
251// field, usage_path, mapping->compare,
252// USB_HID_REPORT_TYPE_INPUT);
253 matches = true;
254 break;
255 }
256
257 report_id = usb_hid_get_next_report_id(
258 hid_dev->report, report_id,
259 USB_HID_REPORT_TYPE_INPUT);
260
261// if((mapping->report_id == 0) && (report_des->report_id != 0)) {
262// uint8_t report_id = usb_hid_get_next_report_id(
263// hid_dev->report, report_des->report_id,
264// USB_HID_REPORT_TYPE_INPUT);
265
266// if(report_id == 0) {
267// break;
268// }
269
270// report_des = usb_hid_report_find_description(
271// hid_dev->report, report_id,
272// USB_HID_REPORT_TYPE_INPUT);
273// }
274// else {
275// break;
276// }
277 } while (!matches && report_id != 0);
278
279// usb_log_debug("Size of the input report: %zu\n", size);
280 usb_hid_report_path_free(usage_path);
281
282 return matches;
283}
284
285/*----------------------------------------------------------------------------*/
286
287static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev,
288 const usb_hid_subdriver_t **subdrivers, int count)
289{
290 int i;
291
292 if (count <= 0) {
293 hid_dev->subdriver_count = 0;
294 hid_dev->subdrivers = NULL;
295 return EOK;
296 }
297
298 // add one generic HID subdriver per device
299
300 hid_dev->subdrivers = (usb_hid_subdriver_t *)malloc((count + 1) *
301 sizeof(usb_hid_subdriver_t));
302 if (hid_dev->subdrivers == NULL) {
303 return ENOMEM;
304 }
305
306 for (i = 0; i < count; ++i) {
307 hid_dev->subdrivers[i].init = subdrivers[i]->init;
308 hid_dev->subdrivers[i].deinit = subdrivers[i]->deinit;
309 hid_dev->subdrivers[i].poll = subdrivers[i]->poll;
310 hid_dev->subdrivers[i].poll_end = subdrivers[i]->poll_end;
311 }
312
313 hid_dev->subdrivers[count].init = usb_generic_hid_init;
314 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback;
315 hid_dev->subdrivers[count].deinit = NULL;
316 hid_dev->subdrivers[count].poll_end = NULL;
317
318 hid_dev->subdriver_count = count + 1;
319
320 return EOK;
321}
322
323/*----------------------------------------------------------------------------*/
324
325static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev)
326{
327 assert(hid_dev != NULL);
328
329 const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS];
330
331 int i = 0, count = 0;
332 const usb_hid_subdriver_mapping_t *mapping = &usb_hid_subdrivers[i];
333
334 bool ids_matched;
335 bool matched;
336
337 while (count < USB_HID_MAX_SUBDRIVERS &&
338 (mapping->usage_path != NULL
339 || mapping->vendor_id >= 0 || mapping->product_id >= 0)) {
340 // check the vendor & product ID
341 if (mapping->vendor_id >= 0 && mapping->product_id < 0) {
342 usb_log_warning("Missing Product ID for Vendor ID %d\n",
343 mapping->vendor_id);
344 return EINVAL;
345 }
346 if (mapping->product_id >= 0 && mapping->vendor_id < 0) {
347 usb_log_warning("Missing Vendor ID for Product ID %d\n",
348 mapping->product_id);
349 return EINVAL;
350 }
351
352 ids_matched = false;
353 matched = false;
354
355 if (mapping->vendor_id >= 0) {
356 assert(mapping->product_id >= 0);
357 usb_log_debug("Comparing device against vendor ID %u"
358 " and product ID %u.\n", mapping->vendor_id,
359 mapping->product_id);
360 if (usb_hid_ids_match(hid_dev, mapping)) {
361 usb_log_debug("IDs matched.\n");
362 ids_matched = true;
363 }
364 }
365
366 if (mapping->usage_path != NULL) {
367 usb_log_debug("Comparing device against usage path.\n");
368 if (usb_hid_path_matches(hid_dev, mapping)) {
369 // does not matter if IDs were matched
370 matched = true;
371 }
372 } else {
373 // matched only if IDs were matched and there is no path
374 matched = ids_matched;
375 }
376
377 if (matched) {
378 usb_log_debug("Subdriver matched.\n");
379 subdrivers[count++] = &mapping->subdriver;
380 }
381
382 mapping = &usb_hid_subdrivers[++i];
383 }
384
385 // we have all subdrivers determined, save them into the hid device
386 return usb_hid_save_subdrivers(hid_dev, subdrivers, count);
387}
388
389/*----------------------------------------------------------------------------*/
390
391static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
392{
393 assert(hid_dev != NULL && dev != NULL);
394
395 int rc = EOK;
396
397 if (dev->pipes[USB_HID_KBD_POLL_EP_NO].present) {
398 usb_log_debug("Found keyboard endpoint.\n");
399 // save the pipe index
400 hid_dev->poll_pipe_index = USB_HID_KBD_POLL_EP_NO;
401 } else if (dev->pipes[USB_HID_MOUSE_POLL_EP_NO].present) {
402 usb_log_debug("Found mouse endpoint.\n");
403 // save the pipe index
404 hid_dev->poll_pipe_index = USB_HID_MOUSE_POLL_EP_NO;
405 } else if (dev->pipes[USB_HID_GENERIC_POLL_EP_NO].present) {
406 usb_log_debug("Found generic HID endpoint.\n");
407 // save the pipe index
408 hid_dev->poll_pipe_index = USB_HID_GENERIC_POLL_EP_NO;
409 } else {
410 usb_log_error("None of supported endpoints found - probably"
411 " not a supported device.\n");
412 rc = ENOTSUP;
413 }
414
415 return rc;
416}
417
418/*----------------------------------------------------------------------------*/
419
420static int usb_hid_init_report(usb_hid_dev_t *hid_dev)
421{
422 assert(hid_dev != NULL && hid_dev->report != NULL);
423
424 uint8_t report_id = 0;
425 size_t size;/* = usb_hid_report_byte_size(hid_dev->report, report_id,
426 USB_HID_REPORT_TYPE_INPUT);*/
427
428 size_t max_size = 0;
429
430 do {
431 usb_log_debug("Getting size of the report.\n");
432 size = usb_hid_report_byte_size(hid_dev->report, report_id,
433 USB_HID_REPORT_TYPE_INPUT);
434 usb_log_debug("Report ID: %u, size: %zu\n", report_id, size);
435 max_size = (size > max_size) ? size : max_size;
436 usb_log_debug("Getting next report ID\n");
437 report_id = usb_hid_get_next_report_id(hid_dev->report,
438 report_id, USB_HID_REPORT_TYPE_INPUT);
439 } while (report_id != 0);
440
441 usb_log_debug("Max size of input report: %zu\n", max_size);
442
443 hid_dev->max_input_report_size = max_size;
444 assert(hid_dev->input_report == NULL);
445
446 hid_dev->input_report = malloc(max_size);
447 if (hid_dev->input_report == NULL) {
448 return ENOMEM;
449 }
450 memset(hid_dev->input_report, 0, max_size);
451
452 return EOK;
453}
454
455/*----------------------------------------------------------------------------*/
456
457usb_hid_dev_t *usb_hid_new(void)
458{
459 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)calloc(1,
460 sizeof(usb_hid_dev_t));
461
462 if (hid_dev == NULL) {
463 usb_log_fatal("No memory!\n");
464 return NULL;
465 }
466
467 hid_dev->report = (usb_hid_report_t *)(malloc(sizeof(
468 usb_hid_report_t)));
469 if (hid_dev->report == NULL) {
470 usb_log_fatal("No memory!\n");
471 free(hid_dev);
472 return NULL;
473 }
474
475 hid_dev->poll_pipe_index = -1;
476
477 return hid_dev;
478}
479
480/*----------------------------------------------------------------------------*/
481
482int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev)
483{
484 int rc, i;
485
486 usb_log_debug("Initializing HID structure...\n");
487
488 if (hid_dev == NULL) {
489 usb_log_error("Failed to init HID structure: no structure given"
490 ".\n");
491 return EINVAL;
492 }
493
494 if (dev == NULL) {
495 usb_log_error("Failed to init HID structure: no USB device"
496 " given.\n");
497 return EINVAL;
498 }
499
500 /* The USB device should already be initialized, save it in structure */
501 hid_dev->usb_dev = dev;
502
503 rc = usb_hid_check_pipes(hid_dev, dev);
504 if (rc != EOK) {
505 //usb_hid_free(&hid_dev);
506 return rc;
507 }
508
509 /* Get the report descriptor and parse it. */
510 rc = usb_hid_process_report_descriptor(hid_dev->usb_dev,
511 hid_dev->report, &hid_dev->report_desc, &hid_dev->report_desc_size);
512
513 bool fallback = false;
514
515 if (rc == EOK) {
516 // try to find subdrivers that may want to handle this device
517 rc = usb_hid_find_subdrivers(hid_dev);
518 if (rc != EOK || hid_dev->subdriver_count == 0) {
519 // try to fall back to the boot protocol if available
520 usb_log_info("No subdrivers found to handle this"
521 " device.\n");
522 fallback = true;
523 assert(hid_dev->subdrivers == NULL);
524 assert(hid_dev->subdriver_count == 0);
525 }
526 } else {
527 usb_log_error("Failed to parse Report descriptor.\n");
528 // try to fall back to the boot protocol if available
529 fallback = true;
530 }
531
532 if (fallback) {
533 // fall back to boot protocol
534 switch (hid_dev->poll_pipe_index) {
535 case USB_HID_KBD_POLL_EP_NO:
536 usb_log_info("Falling back to kbd boot protocol.\n");
537 rc = usb_kbd_set_boot_protocol(hid_dev);
538 if (rc == EOK) {
539 rc = usb_hid_set_boot_kbd_subdriver(hid_dev);
540 }
541 break;
542 case USB_HID_MOUSE_POLL_EP_NO:
543 usb_log_info("Falling back to mouse boot protocol.\n");
544 rc = usb_mouse_set_boot_protocol(hid_dev);
545 if (rc == EOK) {
546 rc = usb_hid_set_boot_mouse_subdriver(hid_dev);
547 }
548 break;
549 default:
550 assert(hid_dev->poll_pipe_index
551 == USB_HID_GENERIC_POLL_EP_NO);
552
553 /* TODO: this has no meaning if the report descriptor
554 is not parsed */
555 usb_log_info("Falling back to generic HID driver.\n");
556 rc = usb_hid_set_generic_hid_subdriver(hid_dev);
557 }
558 }
559
560 if (rc != EOK) {
561 usb_log_error("No subdriver for handling this device could be"
562 " initialized: %s.\n", str_error(rc));
563 usb_log_debug("Subdriver count: %d\n",
564 hid_dev->subdriver_count);
565 //usb_hid_free(&hid_dev);
566
567 } else {
568 bool ok = false;
569
570 usb_log_debug("Subdriver count: %d\n",
571 hid_dev->subdriver_count);
572
573 for (i = 0; i < hid_dev->subdriver_count; ++i) {
574 if (hid_dev->subdrivers[i].init != NULL) {
575 usb_log_debug("Initializing subdriver %d.\n",i);
576 rc = hid_dev->subdrivers[i].init(hid_dev,
577 &hid_dev->subdrivers[i].data);
578 if (rc != EOK) {
579 usb_log_warning("Failed to initialize"
580 " HID subdriver structure.\n");
581 } else {
582 // at least one subdriver initialized
583 ok = true;
584 }
585 } else {
586 ok = true;
587 }
588 }
589
590 rc = (ok) ? EOK : -1; // what error to report
591 }
592
593
594 if (rc == EOK) {
595 // save max input report size and allocate space for the report
596 rc = usb_hid_init_report(hid_dev);
597 if (rc != EOK) {
598 usb_log_error("Failed to initialize input report buffer"
599 ".\n");
600 }
601 }
602
603
604 return rc;
605}
606
607/*----------------------------------------------------------------------------*/
608
609bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
610 size_t buffer_size, void *arg)
611{
612 int i;
613
614 if (dev == NULL || arg == NULL || buffer == NULL) {
615 usb_log_error("Missing arguments to polling callback.\n");
616 return false;
617 }
618
619 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
620
621// int allocated = (hid_dev->input_report != NULL);
622 assert(hid_dev->input_report != NULL);
623 usb_log_debug("Max input report size: %zu, buffer size: %zu\n",
624 hid_dev->max_input_report_size, buffer_size);
625 //assert(hid_dev->max_input_report_size >= buffer_size);
626 if (hid_dev->max_input_report_size >= buffer_size) {
627 /*! @todo This should probably be atomic. */
628 memcpy(hid_dev->input_report, buffer, buffer_size);
629 hid_dev->input_report_size = buffer_size;
630 usb_hid_new_report(hid_dev);
631 }
632
633 bool cont = false;
634
635 // continue if at least one of the subdrivers want to continue
636 for (i = 0; i < hid_dev->subdriver_count; ++i) {
637 if (hid_dev->subdrivers[i].poll != NULL
638 && hid_dev->subdrivers[i].poll(hid_dev,
639 hid_dev->subdrivers[i].data, buffer, buffer_size)) {
640 cont = true;
641 }
642 }
643
644 return cont;
645}
646
647/*----------------------------------------------------------------------------*/
648
649void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason,
650 void *arg)
651{
652 int i;
653
654 if (dev == NULL || arg == NULL) {
655 return;
656 }
657
658 usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)arg;
659
660 for (i = 0; i < hid_dev->subdriver_count; ++i) {
661 if (hid_dev->subdrivers[i].poll_end != NULL) {
662 hid_dev->subdrivers[i].poll_end(hid_dev,
663 hid_dev->subdrivers[i].data, reason);
664 }
665 }
666
667 usb_hid_free(&hid_dev);
668}
669
670/*----------------------------------------------------------------------------*/
671
672//const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev)
673//{
674// switch (hid_dev->poll_pipe_index) {
675// case USB_HID_KBD_POLL_EP_NO:
676// return HID_KBD_FUN_NAME;
677// break;
678// case USB_HID_MOUSE_POLL_EP_NO:
679// return HID_MOUSE_FUN_NAME;
680// break;
681// default:
682// return HID_GENERIC_FUN_NAME;
683// }
684//}
685
686/*----------------------------------------------------------------------------*/
687
688//const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev)
689//{
690// // this means that only boot protocol keyboards will be connected
691// // to the console; there is probably no better way to do this
692
693// switch (hid_dev->poll_pipe_index) {
694// case USB_HID_KBD_POLL_EP_NO:
695// return HID_KBD_CLASS_NAME;
696// break;
697// case USB_HID_MOUSE_POLL_EP_NO:
698// return HID_MOUSE_CLASS_NAME;
699// break;
700// default:
701// return HID_GENERIC_CLASS_NAME;
702// }
703//}
704
705/*----------------------------------------------------------------------------*/
706
707void usb_hid_new_report(usb_hid_dev_t *hid_dev)
708{
709 ++hid_dev->report_nr;
710}
711
712/*----------------------------------------------------------------------------*/
713
714int usb_hid_report_number(usb_hid_dev_t *hid_dev)
715{
716 return hid_dev->report_nr;
717}
718
719/*----------------------------------------------------------------------------*/
720
721//void usb_hid_report_received(void)
722//{
723// ++report_number;
724//}
725
726/*----------------------------------------------------------------------------*/
727
728//bool usb_hid_report_ready(void)
729//{
730// return !report_received;
731//}
732
733/*----------------------------------------------------------------------------*/
734
735void usb_hid_free(usb_hid_dev_t **hid_dev)
736{
737 int i;
738
739 if (hid_dev == NULL || *hid_dev == NULL) {
740 return;
741 }
742
743 usb_log_debug("Subdrivers: %p, subdriver count: %d\n",
744 (*hid_dev)->subdrivers, (*hid_dev)->subdriver_count);
745
746 assert((*hid_dev)->subdrivers != NULL
747 || (*hid_dev)->subdriver_count == 0);
748
749 for (i = 0; i < (*hid_dev)->subdriver_count; ++i) {
750 if ((*hid_dev)->subdrivers[i].deinit != NULL) {
751 (*hid_dev)->subdrivers[i].deinit(*hid_dev,
752 (*hid_dev)->subdrivers[i].data);
753 }
754 }
755
756 // free the subdrivers info
757 if ((*hid_dev)->subdrivers != NULL) {
758 free((*hid_dev)->subdrivers);
759 }
760
761 // destroy the parser
762 if ((*hid_dev)->report != NULL) {
763 usb_hid_free_report((*hid_dev)->report);
764 }
765
766 if ((*hid_dev)->report_desc != NULL) {
767 free((*hid_dev)->report_desc);
768 }
769
770 free(*hid_dev);
771 *hid_dev = NULL;
772}
773
774/**
775 * @}
776 */
Note: See TracBrowser for help on using the repository browser.