source: mainline/uspace/drv/bus/usb/usbhid/usbhid.h@ 193da9d6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 193da9d6 was 5f6e25e, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Leave it up to DDF to free driver-specific data. This makes it possible
to ensure soft state is not freed during calls to driver entry points.

This requires some driver changes:

  • minimum change is not to free() driver-data structures (ddf_fun_t.driver_data and ddf_dev_t.driver_data)
  • ideally allocate using ddf_dev_data_alloc(), ddf_fun_data_alloc()

I tried fixing existing drivers accordingly (mostly the minimalistic
change variant), but could have missed something.

  • Property mode set to 100644
File size: 4.9 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>
[dd3eda2]46#include <bool.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
[966acede]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;
[966acede]104
[61257f4]105 /** Index of the polling pipe in usb_hid_endpoints array. */
106 int poll_pipe_index;
[966acede]107
[60c0573]108 /** Subdrivers. */
109 usb_hid_subdriver_t *subdrivers;
110
111 /** Number of subdrivers. */
112 int subdriver_count;
[966acede]113
[61257f4]114 /** Report descriptor. */
115 uint8_t *report_desc;
[966acede]116
[61257f4]117 /** Report descriptor size. */
118 size_t report_desc_size;
[966acede]119
[61257f4]120 /** HID Report parser. */
[e60436b]121 usb_hid_report_t *report;
[966acede]122
[65c3794]123 uint8_t report_id;
124
[31cfee16]125 uint8_t *input_report;
126
127 size_t input_report_size;
[d1fb591]128 size_t max_input_report_size;
[8fb45e08]129
130 int report_nr;
[d022500]131};
[966acede]132
133/*----------------------------------------------------------------------------*/
134
135enum {
[61257f4]136 USB_HID_KBD_POLL_EP_NO = 0,
137 USB_HID_MOUSE_POLL_EP_NO = 1,
138 USB_HID_GENERIC_POLL_EP_NO = 2,
139 USB_HID_POLL_EP_COUNT = 3
[966acede]140};
141
142usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1];
143
144/*----------------------------------------------------------------------------*/
145
[61257f4]146usb_hid_dev_t *usb_hid_new(void);
147
148int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
[966acede]149
[60c0573]150bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
151 size_t buffer_size, void *arg);
152
[61257f4]153void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason,
[966acede]154 void *arg);
155
[8fb45e08]156void usb_hid_new_report(usb_hid_dev_t *hid_dev);
157
158int usb_hid_report_number(usb_hid_dev_t *hid_dev);
[dd3eda2]159
[5f6e25e]160void usb_hid_destroy(usb_hid_dev_t *hid_dev);
[61257f4]161
[ba358ed]162#endif /* USB_HID_USBHID_H_ */
[966acede]163
164/**
165 * @}
166 */
Note: See TracBrowser for help on using the repository browser.