source: mainline/uspace/drv/usbhid/usbhid.h@ 60c0573

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 60c0573 was 60c0573, checked in by Lubos Slovak <lubos.slovak@…>, 14 years ago

Preparation for HID subdrivers.

  • Preparation for registering subdriver callbacks based on some device identifiers.
  • HID driver now uses one general callback which calls all the registered subdriver callbacks.
  • Other callbacks for init, deinit and polling ended.
  • Setting boot keyboard and mouse callbacks separately (special cases).

TODO maybe also functions and function classes may be per-subdriver

(so a hybrid keyboard/pointing device may register itself as

both keyboard and mouse).

TODO the current keyboard and mouse subdrivers should fall back to the

booot protocol by default.

  • Property mode set to 100644
File size: 4.1 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_USBHID_H_
37#define USB_USBHID_H_
38
39#include <stdint.h>
40
41#include <usb/classes/hidparser.h>
42#include <ddf/driver.h>
43#include <usb/pipes.h>
44#include <usb/devdrv.h>
45#include <usb/classes/hid.h>
46
47struct usb_hid_dev;
48
49typedef int (*usb_hid_driver_init_t)(struct usb_hid_dev *);
50typedef void (*usb_hid_driver_deinit_t)(struct usb_hid_dev *);
51typedef bool (*usb_hid_driver_poll)(struct usb_hid_dev *, uint8_t *, size_t);
52typedef int (*usb_hid_driver_poll_ended)(struct usb_hid_dev *, bool reason);
53
54// TODO: add function and class name??
55typedef struct usb_hid_subdriver {
56 /** Function to be called when initializing HID device. */
57 usb_hid_driver_init_t init;
58 /** Function to be called when destroying the HID device structure. */
59 usb_hid_driver_deinit_t deinit;
60 /** Function to be called when data arrives from the device. */
61 usb_hid_driver_poll poll;
62 /** Function to be called when polling ends. */
63 usb_hid_driver_poll_ended poll_end;
64} usb_hid_subdriver_t;
65
66/*----------------------------------------------------------------------------*/
67/**
68 * Structure for holding general HID device data.
69 */
70typedef struct usb_hid_dev {
71 /** Structure holding generic USB device information. */
72 usb_device_t *usb_dev;
73
74 /** @todo What is this actually? */
75 ddf_dev_ops_t ops;
76
77 /** Index of the polling pipe in usb_hid_endpoints array. */
78 int poll_pipe_index;
79
80 /** Subdrivers. */
81 usb_hid_subdriver_t *subdrivers;
82
83 /** Number of subdrivers. */
84 int subdriver_count;
85
86 /** Report descriptor. */
87 uint8_t *report_desc;
88
89 /** Report descriptor size. */
90 size_t report_desc_size;
91
92 /** HID Report parser. */
93 usb_hid_report_parser_t *parser;
94
95 /** Arbitrary data (e.g. a special structure for handling keyboard). */
96 void *data;
97} usb_hid_dev_t;
98
99/*----------------------------------------------------------------------------*/
100
101enum {
102 USB_HID_KBD_POLL_EP_NO = 0,
103 USB_HID_MOUSE_POLL_EP_NO = 1,
104 USB_HID_GENERIC_POLL_EP_NO = 2,
105 USB_HID_POLL_EP_COUNT = 3
106};
107
108usb_endpoint_description_t *usb_hid_endpoints[USB_HID_POLL_EP_COUNT + 1];
109
110/*----------------------------------------------------------------------------*/
111
112usb_hid_dev_t *usb_hid_new(void);
113
114int usb_hid_init(usb_hid_dev_t *hid_dev, usb_device_t *dev);
115
116bool usb_hid_polling_callback(usb_device_t *dev, uint8_t *buffer,
117 size_t buffer_size, void *arg);
118
119void usb_hid_polling_ended_callback(usb_device_t *dev, bool reason,
120 void *arg);
121
122const char *usb_hid_get_function_name(const usb_hid_dev_t *hid_dev);
123
124const char *usb_hid_get_class_name(const usb_hid_dev_t *hid_dev);
125
126void usb_hid_free(usb_hid_dev_t **hid_dev);
127
128#endif /* USB_USBHID_H_ */
129
130/**
131 * @}
132 */
Note: See TracBrowser for help on using the repository browser.