source: mainline/uspace/drv/bus/usb/usbhid/usbhid.c@ 955e988

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 955e988 was 8e7c9fe, checked in by Jan Vesely <jano.vesely@…>, 11 years ago

merge mainline changes

most usb changes were reverted. blink and usbmass were fixed
known problems:
ehci won't initialize
usbmast asserts on unmount (happens on mainline too)

  • Property mode set to 100644
File size: 15.1 KB
RevLine 
[966acede]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>
[faa44e58]39#include <usb/hid/hid.h>
40#include <usb/hid/hidparser.h>
41#include <usb/hid/hidreport.h>
42#include <usb/hid/request.h>
[bb70637]43
[61257f4]44#include <errno.h>
[bb70637]45#include <macros.h>
[f76153ce]46#include <str_error.h>
[966acede]47
48#include "usbhid.h"
49
[61257f4]50#include "kbd/kbddev.h"
[dd10e07]51#include "generic/hiddev.h"
[e9f0348]52#include "mouse/mousedev.h"
[62bd8d3]53#include "subdrivers.h"
[61257f4]54
[966acede]55/* Array of endpoints expected on the device, NULL terminated. */
[b803845]56const usb_endpoint_description_t *usb_hid_endpoints[] = {
[fec47d4]57 &usb_hid_kbd_poll_endpoint_description,
58 &usb_hid_mouse_poll_endpoint_description,
[61257f4]59 &usb_hid_generic_poll_endpoint_description,
[966acede]60 NULL
61};
[76fbd9a]62
[60c0573]63static int usb_hid_set_boot_kbd_subdriver(usb_hid_dev_t *hid_dev)
[61257f4]64{
[3f8f09f]65 assert(hid_dev != NULL);
66 assert(hid_dev->subdriver_count == 0);
[cc29622]67
[3f8f09f]68 hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t));
[60c0573]69 if (hid_dev->subdrivers == NULL) {
70 return ENOMEM;
[61257f4]71 }
[3f8f09f]72 hid_dev->subdriver_count = 1;
73 // TODO 0 should be keyboard, but find a better way
74 hid_dev->subdrivers[0] = usb_hid_subdrivers[0].subdriver;
[cc29622]75
[60c0573]76 return EOK;
77}
[76fbd9a]78
[60c0573]79static int usb_hid_set_boot_mouse_subdriver(usb_hid_dev_t *hid_dev)
80{
[3f8f09f]81 assert(hid_dev != NULL);
82 assert(hid_dev->subdriver_count == 0);
[cc29622]83
[3f8f09f]84 hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t));
[60c0573]85 if (hid_dev->subdrivers == NULL) {
86 return ENOMEM;
[61257f4]87 }
[3f8f09f]88 hid_dev->subdriver_count = 1;
89 // TODO 2 should be mouse, but find a better way
[6f730278]90 hid_dev->subdrivers[0] = usb_hid_subdrivers[2].subdriver;
[cc29622]91
[60c0573]92 return EOK;
93}
[76fbd9a]94
[60c0573]95static int usb_hid_set_generic_hid_subdriver(usb_hid_dev_t *hid_dev)
96{
[07b9cbae]97 assert(hid_dev != NULL);
98 assert(hid_dev->subdriver_count == 0);
[cc29622]99
[3f8f09f]100 hid_dev->subdrivers = malloc(sizeof(usb_hid_subdriver_t));
[60c0573]101 if (hid_dev->subdrivers == NULL) {
102 return ENOMEM;
103 }
[3f8f09f]104 hid_dev->subdriver_count = 1;
[cc29622]105
[3f8f09f]106 /* Set generic hid subdriver routines */
107 hid_dev->subdrivers[0].init = usb_generic_hid_init;
108 hid_dev->subdrivers[0].poll = usb_generic_hid_polling_callback;
109 hid_dev->subdrivers[0].poll_end = NULL;
110 hid_dev->subdrivers[0].deinit = usb_generic_hid_deinit;
[cc29622]111
[60c0573]112 return EOK;
113}
[76fbd9a]114
[3f8f09f]115static bool usb_hid_ids_match(const usb_hid_dev_t *hid_dev,
[f76153ce]116 const usb_hid_subdriver_mapping_t *mapping)
117{
[945d66c]118 assert(hid_dev);
119 assert(hid_dev->usb_dev);
120 assert(mapping);
121 const usb_standard_device_descriptor_t *d =
[e2dfa86]122 &usb_device_descriptors(hid_dev->usb_dev)->device;
[945d66c]123
124 return (d->vendor_id == mapping->vendor_id)
125 && (d->product_id == mapping->product_id);
[f76153ce]126}
[76fbd9a]127
[3f8f09f]128static bool usb_hid_path_matches(usb_hid_dev_t *hid_dev,
[e3b5129]129 const usb_hid_subdriver_mapping_t *mapping)
[f76153ce]130{
131 assert(hid_dev != NULL);
[e3b5129]132 assert(mapping != NULL);
[cc29622]133
[f76153ce]134 usb_hid_report_path_t *usage_path = usb_hid_report_path();
135 if (usage_path == NULL) {
[1cbb4b7]136 usb_log_debug("Failed to create usage path.\n");
[f76153ce]137 return false;
138 }
[07b9cbae]139
140 for (int i = 0; mapping->usage_path[i].usage != 0
141 || mapping->usage_path[i].usage_page != 0; ++i) {
[3f8f09f]142 if (usb_hid_report_path_append_item(usage_path,
143 mapping->usage_path[i].usage_page,
[e3b5129]144 mapping->usage_path[i].usage) != EOK) {
[1cbb4b7]145 usb_log_debug("Failed to append to usage path.\n");
[f76153ce]146 usb_hid_report_path_free(usage_path);
147 return false;
148 }
149 }
[cc29622]150
[e3b5129]151 usb_log_debug("Compare flags: %d\n", mapping->compare);
[cc29622]152
[f3f9733]153 bool matches = false;
154 uint8_t report_id = mapping->report_id;
[dcb7d7cd]155
[19e0560e]156 do {
[f3f9733]157 usb_log_debug("Trying report id %u\n", report_id);
158 if (report_id != 0) {
[dcb7d7cd]159 usb_hid_report_path_set_report_id(usage_path,
[f3f9733]160 report_id);
[dcb7d7cd]161 }
162
[07b9cbae]163 const usb_hid_report_field_t *field =
164 usb_hid_report_get_sibling(
165 &hid_dev->report, NULL, usage_path, mapping->compare,
166 USB_HID_REPORT_TYPE_INPUT);
[a8c4e871]167
[f3f9733]168 usb_log_debug("Field: %p\n", field);
[dcb7d7cd]169
[f3f9733]170 if (field != NULL) {
171 matches = true;
172 break;
[dcb7d7cd]173 }
[a8c4e871]174
[f3f9733]175 report_id = usb_hid_get_next_report_id(
[a8c4e871]176 &hid_dev->report, report_id, USB_HID_REPORT_TYPE_INPUT);
[f3f9733]177 } while (!matches && report_id != 0);
[cc29622]178
[f76153ce]179 usb_hid_report_path_free(usage_path);
[cc29622]180
[f3f9733]181 return matches;
[f76153ce]182}
[76fbd9a]183
[3f8f09f]184static int usb_hid_save_subdrivers(usb_hid_dev_t *hid_dev,
[07b9cbae]185 const usb_hid_subdriver_t **subdrivers, unsigned count)
[60c0573]186{
[07b9cbae]187 assert(hid_dev);
188 assert(subdrivers);
[cc29622]189
[07b9cbae]190 if (count == 0) {
[f76153ce]191 hid_dev->subdriver_count = 0;
192 hid_dev->subdrivers = NULL;
193 return EOK;
194 }
[cc29622]195
[3f8f09f]196 /* +1 for generic hid subdriver */
197 hid_dev->subdrivers = calloc((count + 1), sizeof(usb_hid_subdriver_t));
[f76153ce]198 if (hid_dev->subdrivers == NULL) {
199 return ENOMEM;
200 }
[cc29622]201
[07b9cbae]202 for (unsigned i = 0; i < count; ++i) {
203 hid_dev->subdrivers[i] = *subdrivers[i];
[f76153ce]204 }
[cc29622]205
[3f8f09f]206 /* Add one generic HID subdriver per device */
[78bfae9]207 hid_dev->subdrivers[count].init = usb_generic_hid_init;
208 hid_dev->subdrivers[count].poll = usb_generic_hid_polling_callback;
[c5b6db53]209 hid_dev->subdrivers[count].deinit = usb_generic_hid_deinit;
[78bfae9]210 hid_dev->subdrivers[count].poll_end = NULL;
[cc29622]211
[78bfae9]212 hid_dev->subdriver_count = count + 1;
[cc29622]213
[60c0573]214 return EOK;
[61257f4]215}
[76fbd9a]216
[f76153ce]217static int usb_hid_find_subdrivers(usb_hid_dev_t *hid_dev)
218{
[e7df6cd]219 assert(hid_dev != NULL);
[cc29622]220
[f76153ce]221 const usb_hid_subdriver_t *subdrivers[USB_HID_MAX_SUBDRIVERS];
[07b9cbae]222 unsigned count = 0;
[cc29622]223
[07b9cbae]224 for (unsigned i = 0; i < USB_HID_MAX_SUBDRIVERS; ++i) {
225 const usb_hid_subdriver_mapping_t *mapping =
226 &usb_hid_subdrivers[i];
227 /* Check the vendor & product ID. */
[d0a6e54]228 if (mapping->vendor_id >= 0 && mapping->product_id < 0) {
[07b9cbae]229 usb_log_warning("Mapping[%d]: Missing Product ID for "
230 "Vendor ID %d\n", i, mapping->vendor_id);
[f76153ce]231 }
[d0a6e54]232 if (mapping->product_id >= 0 && mapping->vendor_id < 0) {
[07b9cbae]233 usb_log_warning("Mapping[%d]: Missing Vendor ID for "
234 "Product ID %d\n", i, mapping->product_id);
[f76153ce]235 }
[3f8f09f]236
[07b9cbae]237 bool matched = false;
[3f8f09f]238
[07b9cbae]239 /* Check ID match. */
240 if (mapping->vendor_id >= 0 && mapping->product_id >= 0) {
[777e336]241 usb_log_debug("Comparing device against vendor ID %u"
242 " and product ID %u.\n", mapping->vendor_id,
[f76153ce]243 mapping->product_id);
244 if (usb_hid_ids_match(hid_dev, mapping)) {
[4bb9fd2]245 usb_log_debug("IDs matched.\n");
[07b9cbae]246 matched = true;
[f76153ce]247 }
248 }
[3f8f09f]249
[07b9cbae]250 /* Check usage match. */
[f76153ce]251 if (mapping->usage_path != NULL) {
[1cbb4b7]252 usb_log_debug("Comparing device against usage path.\n");
[e3b5129]253 if (usb_hid_path_matches(hid_dev, mapping)) {
[2d1ba51]254 /* Does not matter if IDs were matched. */
[4bb9fd2]255 matched = true;
[f76153ce]256 }
257 }
[3f8f09f]258
[4bb9fd2]259 if (matched) {
[d1fb591]260 usb_log_debug("Subdriver matched.\n");
[4bb9fd2]261 subdrivers[count++] = &mapping->subdriver;
[f76153ce]262 }
263 }
[cc29622]264
[3f8f09f]265 /* We have all subdrivers determined, save them into the hid device */
[f76153ce]266 return usb_hid_save_subdrivers(hid_dev, subdrivers, count);
267}
[76fbd9a]268
[bb70637]269static int usb_hid_check_pipes(usb_hid_dev_t *hid_dev, usb_device_t *dev)
[966acede]270{
[3f8f09f]271 assert(hid_dev);
272 assert(dev);
[cc29622]273
[90df90c]274 static const struct {
[bb70637]275 const usb_endpoint_description_t *desc;
[90df90c]276 const char* description;
277 } endpoints[] = {
[bb70637]278 {&usb_hid_kbd_poll_endpoint_description, "Keyboard endpoint"},
279 {&usb_hid_mouse_poll_endpoint_description, "Mouse endpoint"},
280 {&usb_hid_generic_poll_endpoint_description, "Generic HID endpoint"},
[90df90c]281 };
282
[bb70637]283 for (unsigned i = 0; i < ARRAY_SIZE(endpoints); ++i) {
284 usb_endpoint_mapping_t *epm =
285 usb_device_get_mapped_ep_desc(dev, endpoints[i].desc);
286 if (epm && epm->present) {
[90df90c]287 usb_log_debug("Found: %s.\n", endpoints[i].description);
[bb70637]288 hid_dev->poll_pipe_mapping = epm;
[90df90c]289 return EOK;
290 }
[61257f4]291 }
[90df90c]292 return ENOTSUP;
[61257f4]293}
[76fbd9a]294
[d1fb591]295static int usb_hid_init_report(usb_hid_dev_t *hid_dev)
296{
[a8c4e871]297 assert(hid_dev != NULL);
[cc29622]298
[d1fb591]299 uint8_t report_id = 0;
300 size_t max_size = 0;
[cc29622]301
[a9cdca0]302 do {
[2002595]303 usb_log_debug("Getting size of the report.\n");
[a8c4e871]304 const size_t size =
305 usb_hid_report_byte_size(&hid_dev->report, report_id,
306 USB_HID_REPORT_TYPE_INPUT);
[8fb45e08]307 usb_log_debug("Report ID: %u, size: %zu\n", report_id, size);
308 max_size = (size > max_size) ? size : max_size;
[2002595]309 usb_log_debug("Getting next report ID\n");
[a8c4e871]310 report_id = usb_hid_get_next_report_id(&hid_dev->report,
[a9cdca0]311 report_id, USB_HID_REPORT_TYPE_INPUT);
312 } while (report_id != 0);
[cc29622]313
[d1fb591]314 usb_log_debug("Max size of input report: %zu\n", max_size);
[cc29622]315
[d1fb591]316 assert(hid_dev->input_report == NULL);
[cc29622]317
[3f8f09f]318 hid_dev->input_report = calloc(1, max_size);
[d1fb591]319 if (hid_dev->input_report == NULL) {
320 return ENOMEM;
321 }
[3f8f09f]322 hid_dev->max_input_report_size = max_size;
[cc29622]323
[d1fb591]324 return EOK;
325}
[76fbd9a]326
[555499da]327/*
328 * This functions initializes required structures from the device's descriptors
329 * and starts new fibril for polling the keyboard for events and another one for
330 * handling auto-repeat of keys.
331 *
332 * During initialization, the keyboard is switched into boot protocol, the idle
333 * rate is set to 0 (infinity), resulting in the keyboard only reporting event
334 * when a key is pressed or released. Finally, the LED lights are turned on
335 * according to the default setup of lock keys.
336 *
337 * @note By default, the keyboards is initialized with Num Lock turned on and
338 * other locks turned off.
339 *
340 * @param hid_dev Device to initialize, non-NULL.
341 * @param dev USB device, non-NULL.
342 * @return Error code.
343 */
[61257f4]344int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev)
345{
[555499da]346 assert(hid_dev);
347 assert(dev);
[cc29622]348
[61257f4]349 usb_log_debug("Initializing HID structure...\n");
[cc29622]350
[a8c4e871]351 usb_hid_report_init(&hid_dev->report);
[e5024111]352
[61257f4]353 /* The USB device should already be initialized, save it in structure */
354 hid_dev->usb_dev = dev;
[bb70637]355 hid_dev->poll_pipe_mapping = NULL;
[cc29622]356
[555499da]357 int rc = usb_hid_check_pipes(hid_dev, dev);
[61257f4]358 if (rc != EOK) {
359 return rc;
360 }
[a8c4e871]361
[f76153ce]362 /* Get the report descriptor and parse it. */
[07b9cbae]363 rc = usb_hid_process_report_descriptor(
364 hid_dev->usb_dev, &hid_dev->report, &hid_dev->report_desc,
365 &hid_dev->report_desc_size);
[cc29622]366
[07b9cbae]367 /* If report parsing went well, find subdrivers. */
[f76153ce]368 if (rc == EOK) {
[07b9cbae]369 usb_hid_find_subdrivers(hid_dev);
[f76153ce]370 } else {
[07b9cbae]371 usb_log_error("Failed to parse report descriptor: fallback.\n");
372 hid_dev->subdrivers = NULL;
373 hid_dev->subdriver_count = 0;
[f76153ce]374 }
[cc29622]375
[07b9cbae]376 usb_log_debug("Subdriver count(before trying boot protocol): %d\n",
377 hid_dev->subdriver_count);
378
379 /* No subdrivers, fall back to the boot protocol if available. */
380 if (hid_dev->subdriver_count == 0) {
381 assert(hid_dev->subdrivers == NULL);
382 usb_log_info("No subdrivers found to handle device, trying "
383 "boot protocol.\n");
384
[bb70637]385 switch (hid_dev->poll_pipe_mapping->interface->interface_protocol) {
386 case USB_HID_PROTOCOL_KEYBOARD:
[f76153ce]387 usb_log_info("Falling back to kbd boot protocol.\n");
388 rc = usb_kbd_set_boot_protocol(hid_dev);
389 if (rc == EOK) {
[07b9cbae]390 usb_hid_set_boot_kbd_subdriver(hid_dev);
[60c0573]391 }
[f76153ce]392 break;
[bb70637]393 case USB_HID_PROTOCOL_MOUSE:
[f76153ce]394 usb_log_info("Falling back to mouse boot protocol.\n");
395 rc = usb_mouse_set_boot_protocol(hid_dev);
396 if (rc == EOK) {
[07b9cbae]397 usb_hid_set_boot_mouse_subdriver(hid_dev);
[f76153ce]398 }
399 break;
400 default:
401 usb_log_info("Falling back to generic HID driver.\n");
[07b9cbae]402 usb_hid_set_generic_hid_subdriver(hid_dev);
[e9f0348]403 }
[61257f4]404 }
[cc29622]405
[07b9cbae]406 usb_log_debug("Subdriver count(after trying boot protocol): %d\n",
407 hid_dev->subdriver_count);
408
409 /* Still no subdrivers? */
410 if (hid_dev->subdriver_count == 0) {
411 assert(hid_dev->subdrivers == NULL);
412 usb_log_error(
413 "No subdriver for handling this device could be found.\n");
414 return ENOTSUP;
415 }
416
[ad22fa4]417 /* Initialize subdrivers */
[07b9cbae]418 bool ok = false;
[f317490]419 for (unsigned i = 0; i < hid_dev->subdriver_count; ++i) {
[07b9cbae]420 if (hid_dev->subdrivers[i].init != NULL) {
421 usb_log_debug("Initializing subdriver %d.\n",i);
422 const int pret = hid_dev->subdrivers[i].init(hid_dev,
423 &hid_dev->subdrivers[i].data);
424 if (pret != EOK) {
425 usb_log_warning("Failed to initialize"
426 " HID subdriver structure: %s.\n",
427 str_error(pret));
428 rc = pret;
[f76153ce]429 } else {
[07b9cbae]430 /* At least one subdriver initialized. */
[f76153ce]431 ok = true;
432 }
[07b9cbae]433 } else {
434 /* Does not need initialization. */
435 ok = true;
[f76153ce]436 }
437 }
[cc29622]438
[07b9cbae]439 if (ok) {
440 /* Save max input report size and
441 * allocate space for the report */
[2002595]442 rc = usb_hid_init_report(hid_dev);
443 if (rc != EOK) {
444 usb_log_error("Failed to initialize input report buffer"
445 ".\n");
446 }
[d1fb591]447 }
[cc29622]448
[61257f4]449 return rc;
450}
[76fbd9a]451
[3f8f09f]452bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
[60c0573]453 size_t buffer_size, void *arg)
454{
455 if (dev == NULL || arg == NULL || buffer == NULL) {
456 usb_log_error("Missing arguments to polling callback.\n");
457 return false;
458 }
[3f8f09f]459 usb_hid_dev_t *hid_dev = arg;
[cc29622]460
[d1fb591]461 assert(hid_dev->input_report != NULL);
[3f8f09f]462
[ae5f77d5]463 usb_log_debug("New data [%zu/%zu]: %s\n", buffer_size,
464 hid_dev->max_input_report_size,
465 usb_debug_str_buffer(buffer, buffer_size, 0));
[19e0560e]466
[2002595]467 if (hid_dev->max_input_report_size >= buffer_size) {
468 /*! @todo This should probably be atomic. */
469 memcpy(hid_dev->input_report, buffer, buffer_size);
470 hid_dev->input_report_size = buffer_size;
471 usb_hid_new_report(hid_dev);
472 }
[cc29622]473
[3f8f09f]474 /* Parse the input report */
475 const int rc = usb_hid_parse_report(
476 &hid_dev->report, buffer, buffer_size, &hid_dev->report_id);
[65c3794]477 if (rc != EOK) {
[4bfe063]478 usb_log_warning("Failure in usb_hid_parse_report():"
[65c3794]479 "%s\n", str_error(rc));
[a8c4e871]480 }
[cc29622]481
[60c0573]482 bool cont = false;
[3f8f09f]483 /* Continue if at least one of the subdrivers want to continue */
[f317490]484 for (unsigned i = 0; i < hid_dev->subdriver_count; ++i) {
[3f8f09f]485 if (hid_dev->subdrivers[i].poll != NULL) {
486 cont = cont || hid_dev->subdrivers[i].poll(
487 hid_dev, hid_dev->subdrivers[i].data);
[60c0573]488 }
489 }
[cc29622]490
[60c0573]491 return cont;
492}
[76fbd9a]493
[3f8f09f]494void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg)
[61257f4]495{
[3f8f09f]496 assert(dev);
497 assert(arg);
[cc29622]498
[3f8f09f]499 usb_hid_dev_t *hid_dev = arg;
[cc29622]500
[f317490]501 for (unsigned i = 0; i < hid_dev->subdriver_count; ++i) {
[60c0573]502 if (hid_dev->subdrivers[i].poll_end != NULL) {
[3f8f09f]503 hid_dev->subdrivers[i].poll_end(
504 hid_dev, hid_dev->subdrivers[i].data, reason);
[60c0573]505 }
506 }
[cc29622]507
[68dbe3e]508 hid_dev->running = false;
[61257f4]509}
[76fbd9a]510
[8fb45e08]511void usb_hid_new_report(usb_hid_dev_t *hid_dev)
[dd3eda2]512{
[8fb45e08]513 ++hid_dev->report_nr;
[dd3eda2]514}
[76fbd9a]515
[3f8f09f]516int usb_hid_report_number(const usb_hid_dev_t *hid_dev)
[dd3eda2]517{
[8fb45e08]518 return hid_dev->report_nr;
[dd3eda2]519}
[76fbd9a]520
[a8c4e871]521void usb_hid_deinit(usb_hid_dev_t *hid_dev)
[61257f4]522{
[3f8f09f]523 assert(hid_dev);
524 assert(hid_dev->subdrivers != NULL || hid_dev->subdriver_count == 0);
[cc29622]525
526
[aaf6155]527 usb_log_debug("Subdrivers: %p, subdriver count: %d\n",
[5f6e25e]528 hid_dev->subdrivers, hid_dev->subdriver_count);
[cc29622]529
[f317490]530 for (unsigned i = 0; i < hid_dev->subdriver_count; ++i) {
[5f6e25e]531 if (hid_dev->subdrivers[i].deinit != NULL) {
532 hid_dev->subdrivers[i].deinit(hid_dev,
533 hid_dev->subdrivers[i].data);
[60c0573]534 }
[61257f4]535 }
[cc29622]536
[cddd151]537 /* Free allocated structures */
538 free(hid_dev->subdrivers);
539 free(hid_dev->report_desc);
[61257f4]540
[cddd151]541 /* Destroy the parser */
[a8c4e871]542 usb_hid_report_deinit(&hid_dev->report);
[61257f4]543
[966acede]544}
545
546/**
547 * @}
548 */
Note: See TracBrowser for help on using the repository browser.