source: mainline/uspace/drv/usbhid/kbddev.h@ f8e4cb6

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

Ported usbhid driver to the new USB framework (#141).

Not tested thoroughly yet.

  • Property mode set to 100644
File size: 4.6 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 keyboard device structure and API.
34 */
35
36#ifndef USBHID_KBDDEV_H_
37#define USBHID_KBDDEV_H_
38
39#include <stdint.h>
40
41#include <fibril_synch.h>
42
43#include <usb/classes/hid.h>
44#include <usb/classes/hidparser.h>
45#include <ddf/driver.h>
46#include <usb/pipes.h>
47
48#include <usb/devdrv.h>
49
50//#include "hiddev.h"
51
52/*----------------------------------------------------------------------------*/
53/**
54 * Structure for keeping information needed for auto-repeat of keys.
55 */
56typedef struct {
57 /** Last pressed key. */
58 unsigned int key_new;
59 /** Key to be repeated. */
60 unsigned int key_repeated;
61 /** Delay before first repeat in microseconds. */
62 unsigned int delay_before;
63 /** Delay between repeats in microseconds. */
64 unsigned int delay_between;
65} usbhid_kbd_repeat_t;
66
67/**
68 * USB/HID keyboard device type.
69 *
70 * Holds a reference to generic USB/HID device structure and keyboard-specific
71 * data, such as currently pressed keys, modifiers and lock keys.
72 *
73 * Also holds a IPC phone to the console (since there is now no other way to
74 * communicate with it).
75 *
76 * @note Storing active lock keys in this structure results in their setting
77 * being device-specific.
78 */
79typedef struct usbhid_kbd_t {
80 /** Structure holding generic USB device information. */
81 //usbhid_dev_t *hid_dev;
82 usb_device_t *usb_dev;
83
84 /** Currently pressed keys (not translated to key codes). */
85 uint8_t *keys;
86 /** Count of stored keys (i.e. number of keys in the report). */
87 size_t key_count;
88 /** Currently pressed modifiers (bitmap). */
89 uint8_t modifiers;
90
91 /** Currently active modifiers including locks. Sent to the console. */
92 unsigned mods;
93
94 /** Currently active lock keys. */
95 unsigned lock_keys;
96
97 /** IPC phone to the console device (for sending key events). */
98 int console_phone;
99
100 /** Information for auto-repeat of keys. */
101 usbhid_kbd_repeat_t repeat;
102
103 /** Mutex for accessing the information about auto-repeat. */
104 fibril_mutex_t *repeat_mtx;
105
106 /** Report descriptor. */
107 uint8_t *report_desc;
108
109 /** Report descriptor size. */
110 size_t report_desc_size;
111
112 /** HID Report parser. */
113 usb_hid_report_parser_t *parser;
114
115 /** State of the structure (for checking before use).
116 *
117 * 0 - not initialized
118 * 1 - initialized
119 * -1 - ready for destroying
120 */
121 int initialized;
122} usbhid_kbd_t;
123
124/*----------------------------------------------------------------------------*/
125
126enum {
127 USBHID_KBD_POLL_EP_NO = 0,
128 USBHID_KBD_POLL_EP_COUNT = 1
129};
130
131usb_endpoint_description_t *usbhid_kbd_endpoints[USBHID_KBD_POLL_EP_COUNT + 1];
132
133ddf_dev_ops_t keyboard_ops;
134
135/*----------------------------------------------------------------------------*/
136
137usbhid_kbd_t *usbhid_kbd_new(void);
138
139int usbhid_kbd_init(usbhid_kbd_t *kbd_dev, usb_device_t *dev);
140
141bool usbhid_kbd_polling_callback(usb_device_t *dev, uint8_t *buffer,
142 size_t buffer_size, void *arg);
143
144void usbhid_kbd_polling_ended_callback(usb_device_t *dev, bool reason,
145 void *arg);
146
147int usbhid_kbd_is_initialized(const usbhid_kbd_t *kbd_dev);
148
149int usbhid_kbd_is_ready_to_destroy(const usbhid_kbd_t *kbd_dev);
150
151void usbhid_kbd_free(usbhid_kbd_t **kbd_dev);
152
153void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key);
154
155#endif /* USBHID_KBDDEV_H_ */
156
157/**
158 * @}
159 */
Note: See TracBrowser for help on using the repository browser.