source: mainline/uspace/drv/hid/usbhid/usbhid.h@ 71f211f

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 71f211f was 71f211f, checked in by Petr Manek <petr.manek@…>, 8 years ago

usbdev: refactor polling data structs

Symbols related to USB device endpoint polling have been moved around
and renamed in this commit.

usb_device_auto_polling_t, which has the semantics of a configuration
parameter struct, has been renamed to usb_device_polling_config_t.

usb_device_auto_polling() is now called usb_device_poll().

A new data structure, usb_device_polling_t, has been introduced to
serve as a user handle to the active polling process (WIP).

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