source: mainline/uspace/drv/bus/usb/usbhid/usbhid.c@ 1c1b577

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1c1b577 was 93d2684, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

usbhid: Count max number of sub-drivers based on available subdrivers.

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