source: mainline/uspace/drv/hid/usbhid/usbhid.h@ 61e27e80

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

usbhid: no need to expose polling callbacks

  • Property mode set to 100644
File size: 4.4 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
49typedef struct usb_hid_dev usb_hid_dev_t;
50typedef struct usb_hid_subdriver usb_hid_subdriver_t;
51
52/** Subdriver initialization callback.
53 *
54 * @param dev Backing USB HID device.
55 * @param data Custom subdriver data (pointer where to store them).
56 * @return Error code.
57 */
58typedef int (*usb_hid_driver_init_t)(usb_hid_dev_t *dev, void **data);
59
60/** Subdriver deinitialization callback.
61 *
62 * @param dev Backing USB HID device.
63 * @param data Custom subdriver data.
64 */
65typedef void (*usb_hid_driver_deinit_t)(usb_hid_dev_t *dev, void *data);
66
67/** Subdriver callback on data from device.
68 *
69 * @param dev Backing USB HID device.
70 * @param data Custom subdriver data.
71 * @return Whether to continue polling (typically true always).
72 */
73typedef bool (*usb_hid_driver_poll_t)(usb_hid_dev_t *dev, void *data);
74
75/** Subdriver callback after communication with the device ceased.
76 *
77 * @param dev Backing USB HID device.
78 * @param data Custom subdriver data.
79 * @param ended_due_to_errors Whether communication ended due to errors in
80 * communication (true) or deliberately by driver (false).
81 */
82typedef void (*usb_hid_driver_poll_ended_t)(usb_hid_dev_t *dev, void *data,
83 bool ended_due_to_errors);
84
85struct usb_hid_subdriver {
86 /** Function to be called when initializing HID device. */
87 usb_hid_driver_init_t init;
88 /** Function to be called when destroying the HID device structure. */
89 usb_hid_driver_deinit_t deinit;
90 /** Function to be called when data arrives from the device. */
91 usb_hid_driver_poll_t poll;
92 /** Function to be called when polling ends. */
93 usb_hid_driver_poll_ended_t poll_end;
94 /** Arbitrary data needed by the subdriver. */
95 void *data;
96};
97
98
99/**
100 * Structure for holding general HID device data.
101 */
102struct usb_hid_dev {
103 /** Structure holding generic USB device information. */
104 usb_device_t *usb_dev;
105
106 /** Endpont mapping of the polling pipe. */
107 usb_endpoint_mapping_t *poll_pipe_mapping;
108
109 /** Device polling structure. */
110 usb_polling_t polling;
111
112 /** Subdrivers. */
113 usb_hid_subdriver_t *subdrivers;
114
115 /** Number of subdrivers. */
116 unsigned subdriver_count;
117
118 /** Report descriptor. */
119 uint8_t *report_desc;
120
121 /** Report descriptor size. */
122 size_t report_desc_size;
123
124 /** HID Report parser. */
125 usb_hid_report_t report;
126
127 uint8_t report_id;
128
129 uint8_t *input_report;
130
131 size_t input_report_size;
132 size_t max_input_report_size;
133
134 int report_nr;
135 volatile bool running;
136};
137
138extern const usb_endpoint_description_t *usb_hid_endpoints[];
139
140int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
141
142void usb_hid_deinit(usb_hid_dev_t *hid_dev);
143
144void usb_hid_new_report(usb_hid_dev_t *hid_dev);
145
146int usb_hid_report_number(const usb_hid_dev_t *hid_dev);
147
148#endif /* USB_HID_USBHID_H_ */
149
150/**
151 * @}
152 */
Note: See TracBrowser for help on using the repository browser.