source: mainline/uspace/drv/bus/usb/usbhid/usbhid.h@ 8b415cc

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

usb: Rework polling to accept either ep numbers or descriptions.

Switch usbhub and usbhid to new polling.

  • Property mode set to 100644
File size: 4.5 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/** @file
33 * USB HID driver API.
34 */
35
[ba358ed]36#ifndef USB_HID_USBHID_H_
37#define USB_HID_USBHID_H_
[966acede]38
39#include <stdint.h>
40
[faa44e58]41#include <usb/hid/hidparser.h>
[966acede]42#include <ddf/driver.h>
[7d521e24]43#include <usb/dev/pipes.h>
44#include <usb/dev/driver.h>
[faa44e58]45#include <usb/hid/hid.h>
[3e6a98c5]46#include <stdbool.h>
[966acede]47
[d022500]48typedef struct usb_hid_dev usb_hid_dev_t;
49typedef struct usb_hid_subdriver usb_hid_subdriver_t;
[60c0573]50
[a22004f]51/** Subdriver initialization callback.
52 *
53 * @param dev Backing USB HID device.
54 * @param data Custom subdriver data (pointer where to store them).
55 * @return Error code.
56 */
[d022500]57typedef int (*usb_hid_driver_init_t)(usb_hid_dev_t *dev, void **data);
[a22004f]58
59/** Subdriver deinitialization callback.
60 *
61 * @param dev Backing USB HID device.
62 * @param data Custom subdriver data.
63 */
[d022500]64typedef void (*usb_hid_driver_deinit_t)(usb_hid_dev_t *dev, void *data);
[a22004f]65
66/** Subdriver callback on data from device.
67 *
68 * @param dev Backing USB HID device.
69 * @param data Custom subdriver data.
70 * @return Whether to continue polling (typically true always).
71 */
[d022500]72typedef bool (*usb_hid_driver_poll_t)(usb_hid_dev_t *dev, void *data);
[a22004f]73
74/** Subdriver callback after communication with the device ceased.
75 *
76 * @param dev Backing USB HID device.
77 * @param data Custom subdriver data.
78 * @param ended_due_to_errors Whether communication ended due to errors in
79 * communication (true) or deliberately by driver (false).
80 */
81typedef void (*usb_hid_driver_poll_ended_t)(usb_hid_dev_t *dev, void *data,
82 bool ended_due_to_errors);
[60c0573]83
[d022500]84struct usb_hid_subdriver {
[60c0573]85 /** Function to be called when initializing HID device. */
86 usb_hid_driver_init_t init;
87 /** Function to be called when destroying the HID device structure. */
88 usb_hid_driver_deinit_t deinit;
89 /** Function to be called when data arrives from the device. */
[65c3794]90 usb_hid_driver_poll_t poll;
[60c0573]91 /** Function to be called when polling ends. */
[65c3794]92 usb_hid_driver_poll_ended_t poll_end;
[65b458c4]93 /** Arbitrary data needed by the subdriver. */
94 void *data;
[d022500]95};
[60c0573]96
[76fbd9a]97
[61257f4]98/**
99 * Structure for holding general HID device data.
100 */
[d022500]101struct usb_hid_dev {
[61257f4]102 /** Structure holding generic USB device information. */
103 usb_device_t *usb_dev;
[cc29622]104
[bb70637]105 /** Endpont mapping of the polling pipe. */
106 usb_endpoint_mapping_t *poll_pipe_mapping;
[cc29622]107
[60c0573]108 /** Subdrivers. */
109 usb_hid_subdriver_t *subdrivers;
[cc29622]110
[60c0573]111 /** Number of subdrivers. */
[f317490]112 unsigned subdriver_count;
[cc29622]113
[61257f4]114 /** Report descriptor. */
115 uint8_t *report_desc;
[966acede]116
[61257f4]117 /** Report descriptor size. */
118 size_t report_desc_size;
[cc29622]119
[61257f4]120 /** HID Report parser. */
[a8c4e871]121 usb_hid_report_t report;
[cc29622]122
[65c3794]123 uint8_t report_id;
[cc29622]124
[31cfee16]125 uint8_t *input_report;
[cc29622]126
[31cfee16]127 size_t input_report_size;
[d1fb591]128 size_t max_input_report_size;
[cc29622]129
[8fb45e08]130 int report_nr;
[2a5b62b]131 volatile bool running;
[d022500]132};
[966acede]133
[b803845]134extern const usb_endpoint_description_t *usb_hid_endpoints[];
[966acede]135
[61257f4]136int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
[3f8f09f]137
[a8c4e871]138void usb_hid_deinit(usb_hid_dev_t *hid_dev);
[966acede]139
[a8c4e871]140bool usb_hid_polling_callback(usb_device_t *dev,
141 uint8_t *buffer, size_t buffer_size, void *arg);
[60c0573]142
[a8c4e871]143void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason, void *arg);
[966acede]144
[8fb45e08]145void usb_hid_new_report(usb_hid_dev_t *hid_dev);
146
[3f8f09f]147int usb_hid_report_number(const usb_hid_dev_t *hid_dev);
[dd3eda2]148
[ba358ed]149#endif /* USB_HID_USBHID_H_ */
[966acede]150
151/**
152 * @}
153 */
Note: See TracBrowser for help on using the repository browser.