iPXE
usbkbd.h
Go to the documentation of this file.
1#ifndef _USBKBD_H
2#define _USBKBD_H
3
4/** @file
5 *
6 * USB keyboard driver
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
12#include <assert.h>
13#include <ipxe/usb.h>
14#include <ipxe/usbhid.h>
15
16/** Keyboard protocol */
17#define USBKBD_PROTOCOL 1
18
19/** A USB keyboard report */
21 /** Modifier keys */
23 /** Reserved */
25 /** Keycodes */
27} __attribute__ (( packed ));
28
29/** USB modifier keys */
31 /** Left Ctrl key */
33 /** Left Shift key */
35 /** Left Alt key */
37 /** Left GUI key */
39 /** Right Ctrl key */
41 /** Right Shift key */
43 /** Right Alt key */
45 /** Right GUI key */
47};
48
49/** Either Ctrl key */
50#define USBKBD_CTRL ( USBKBD_CTRL_LEFT | USBKBD_CTRL_RIGHT )
51
52/** Either Shift key */
53#define USBKBD_SHIFT ( USBKBD_SHIFT_LEFT | USBKBD_SHIFT_RIGHT )
54
55/** Either Alt key */
56#define USBKBD_ALT ( USBKBD_ALT_LEFT | USBKBD_ALT_RIGHT )
57
58/** Either GUI key */
59#define USBKBD_GUI ( USBKBD_GUI_LEFT | USBKBD_GUI_RIGHT )
60
61/** USB keycodes */
80
81/** USB keyboard LEDs */
87
88/** Keyboard idle duration (in 4ms units)
89 *
90 * This is a policy decision. We choose to use an autorepeat rate of
91 * approximately 40ms.
92 */
93#define USBKBD_IDLE_DURATION 10 /* 10 x 4ms = 40ms */
94
95/** Keyboard auto-repeat hold-off (in units of USBKBD_IDLE_DURATION)
96 *
97 * This is a policy decision. We choose to use an autorepeat delay of
98 * approximately 500ms.
99 */
100#define USBKBD_HOLDOFF 12 /* 12 x 40ms = 480ms */
101
102/** Interrupt endpoint maximum fill level
103 *
104 * When idling, we are likely to poll the USB endpoint at only the
105 * 18.2Hz system timer tick rate. With a typical observed bInterval
106 * of 10ms (which will be rounded down to 8ms by the HCI drivers),
107 * this gives approximately 7 completions per poll.
108 */
109#define USBKBD_INTR_MAX_FILL 8
110
111/** Keyboard buffer size
112 *
113 * Must be a power of two.
114 */
115#define USBKBD_BUFSIZE 8
116
117/** A USB keyboard device */
119 /** Name */
120 const char *name;
121 /** List of all USB keyboards */
123
124 /** USB bus */
125 struct usb_bus *bus;
126 /** USB human interface device */
127 struct usb_hid hid;
128
129 /** Most recent keyboard report */
131 /** Most recently pressed non-modifier key (if any) */
132 unsigned int keycode;
133 /** Autorepeat hold-off time (in number of completions reported) */
134 unsigned int holdoff;
135
136 /** Keyboard LED state */
138 /** Keyboard LEDs changed */
140
141 /** Keyboard buffer
142 *
143 * This stores iPXE key values.
144 */
145 unsigned int key[USBKBD_BUFSIZE];
146 /** Keyboard buffer producer counter */
147 unsigned int prod;
148 /** Keyboard buffer consumer counter */
149 unsigned int cons;
150 /** Keyboard buffer sub-consumer counter
151 *
152 * This represents the index within the ANSI escape sequence
153 * corresponding to an iPXE key value.
154 */
155 unsigned int subcons;
156};
157
158/**
159 * Calculate keyboard buffer fill level
160 *
161 * @v kbd USB keyboard
162 * @ret fill Keyboard buffer fill level
163 */
164static inline __attribute__ (( always_inline )) unsigned int
165usbkbd_fill ( struct usb_keyboard *kbd ) {
166 unsigned int fill = ( kbd->prod - kbd->cons );
167
169 return fill;
170}
171
172#endif /* _USBKBD_H */
unsigned char uint8_t
Definition stdint.h:10
static int fill
Definition string.h:209
Assertions.
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define __attribute__(x)
Definition compiler.h:10
Universal Serial Bus (USB)
A doubly-linked list entry (or list head)
Definition list.h:19
A USB bus.
Definition usb.h:966
A USB human interface device.
Definition usbhid.h:51
A USB keyboard report.
Definition usbkbd.h:20
uint8_t modifiers
Modifier keys.
Definition usbkbd.h:22
uint8_t reserved
Reserved.
Definition usbkbd.h:24
uint8_t keycode[6]
Keycodes.
Definition usbkbd.h:26
A USB keyboard device.
Definition usbkbd.h:118
struct list_head list
List of all USB keyboards.
Definition usbkbd.h:122
unsigned int subcons
Keyboard buffer sub-consumer counter.
Definition usbkbd.h:155
struct usb_bus * bus
USB bus.
Definition usbkbd.h:125
unsigned int holdoff
Autorepeat hold-off time (in number of completions reported)
Definition usbkbd.h:134
unsigned int prod
Keyboard buffer producer counter.
Definition usbkbd.h:147
uint8_t leds
Keyboard LED state.
Definition usbkbd.h:137
unsigned int key[USBKBD_BUFSIZE]
Keyboard buffer.
Definition usbkbd.h:145
unsigned int cons
Keyboard buffer consumer counter.
Definition usbkbd.h:149
struct usb_hid hid
USB human interface device.
Definition usbkbd.h:127
struct usb_keyboard_report report
Most recent keyboard report.
Definition usbkbd.h:130
const char * name
Name.
Definition usbkbd.h:120
unsigned int keycode
Most recently pressed non-modifier key (if any)
Definition usbkbd.h:132
uint8_t leds_changed
Keyboard LEDs changed.
Definition usbkbd.h:139
USB human interface devices (HID)
static unsigned int usbkbd_fill(struct usb_keyboard *kbd)
Calculate keyboard buffer fill level.
Definition usbkbd.h:165
#define USBKBD_BUFSIZE
Keyboard buffer size.
Definition usbkbd.h:115
usb_keyboard_modifier
USB modifier keys.
Definition usbkbd.h:30
@ USBKBD_CTRL_RIGHT
Right Ctrl key.
Definition usbkbd.h:40
@ USBKBD_GUI_RIGHT
Right GUI key.
Definition usbkbd.h:46
@ USBKBD_SHIFT_RIGHT
Right Shift key.
Definition usbkbd.h:42
@ USBKBD_ALT_RIGHT
Right Alt key.
Definition usbkbd.h:44
@ USBKBD_SHIFT_LEFT
Left Shift key.
Definition usbkbd.h:34
@ USBKBD_CTRL_LEFT
Left Ctrl key.
Definition usbkbd.h:32
@ USBKBD_ALT_LEFT
Left Alt key.
Definition usbkbd.h:36
@ USBKBD_GUI_LEFT
Left GUI key.
Definition usbkbd.h:38
usb_keycode
USB keycodes.
Definition usbkbd.h:62
@ USBKBD_KEY_NUM_LOCK
Definition usbkbd.h:74
@ USBKBD_KEY_MINUS
Definition usbkbd.h:69
@ USBKBD_KEY_PAD_DOT
Definition usbkbd.h:77
@ USBKBD_KEY_PAD_ENTER
Definition usbkbd.h:75
@ USBKBD_KEY_CAPS_LOCK
Definition usbkbd.h:71
@ USBKBD_KEY_UP
Definition usbkbd.h:73
@ USBKBD_KEY_A
Definition usbkbd.h:63
@ USBKBD_KEY_SPACE
Definition usbkbd.h:68
@ USBKBD_KEY_PAD_1
Definition usbkbd.h:76
@ USBKBD_KEY_NON_US
Definition usbkbd.h:78
@ USBKBD_KEY_Z
Definition usbkbd.h:64
@ USBKBD_KEY_F1
Definition usbkbd.h:72
@ USBKBD_KEY_0
Definition usbkbd.h:66
@ USBKBD_KEY_ENTER
Definition usbkbd.h:67
@ USBKBD_KEY_1
Definition usbkbd.h:65
@ USBKBD_KEY_SLASH
Definition usbkbd.h:70
usb_keyboard_led
USB keyboard LEDs.
Definition usbkbd.h:82
@ USBKBD_LED_SCROLL_LOCK
Definition usbkbd.h:85
@ USBKBD_LED_CAPS_LOCK
Definition usbkbd.h:84
@ USBKBD_LED_NUM_LOCK
Definition usbkbd.h:83