iPXE
usbkbd.h File Reference

USB keyboard driver. More...

#include <assert.h>
#include <ipxe/usb.h>
#include <ipxe/usbhid.h>

Go to the source code of this file.

Data Structures

struct  usb_keyboard_report
 A USB keyboard report. More...
struct  usb_keyboard
 A USB keyboard device. More...

Macros

#define USBKBD_PROTOCOL   1
 Keyboard protocol.
#define USBKBD_CTRL   ( USBKBD_CTRL_LEFT | USBKBD_CTRL_RIGHT )
 Either Ctrl key.
#define USBKBD_SHIFT   ( USBKBD_SHIFT_LEFT | USBKBD_SHIFT_RIGHT )
 Either Shift key.
#define USBKBD_ALT   ( USBKBD_ALT_LEFT | USBKBD_ALT_RIGHT )
 Either Alt key.
#define USBKBD_GUI   ( USBKBD_GUI_LEFT | USBKBD_GUI_RIGHT )
 Either GUI key.
#define USBKBD_IDLE_DURATION   10 /* 10 x 4ms = 40ms */
 Keyboard idle duration (in 4ms units)
#define USBKBD_HOLDOFF   12 /* 12 x 40ms = 480ms */
 Keyboard auto-repeat hold-off (in units of USBKBD_IDLE_DURATION)
#define USBKBD_INTR_MAX_FILL   8
 Interrupt endpoint maximum fill level.
#define USBKBD_BUFSIZE   8
 Keyboard buffer size.

Enumerations

enum  usb_keyboard_modifier {
  USBKBD_CTRL_LEFT = 0x01 , USBKBD_SHIFT_LEFT = 0x02 , USBKBD_ALT_LEFT = 0x04 , USBKBD_GUI_LEFT = 0x08 ,
  USBKBD_CTRL_RIGHT = 0x10 , USBKBD_SHIFT_RIGHT = 0x20 , USBKBD_ALT_RIGHT = 0x40 , USBKBD_GUI_RIGHT = 0x80
}
 USB modifier keys. More...
enum  usb_keycode {
  USBKBD_KEY_A = 0x04 , USBKBD_KEY_Z = 0x1d , USBKBD_KEY_1 = 0x1e , USBKBD_KEY_0 = 0x27 ,
  USBKBD_KEY_ENTER = 0x28 , USBKBD_KEY_SPACE = 0x2c , USBKBD_KEY_MINUS = 0x2d , USBKBD_KEY_SLASH = 0x38 ,
  USBKBD_KEY_CAPS_LOCK = 0x39 , USBKBD_KEY_F1 = 0x3a , USBKBD_KEY_UP = 0x52 , USBKBD_KEY_NUM_LOCK = 0x53 ,
  USBKBD_KEY_PAD_ENTER = 0x58 , USBKBD_KEY_PAD_1 = 0x59 , USBKBD_KEY_PAD_DOT = 0x63 , USBKBD_KEY_NON_US = 0x64
}
 USB keycodes. More...
enum  usb_keyboard_led { USBKBD_LED_NUM_LOCK = 0x01 , USBKBD_LED_CAPS_LOCK = 0x02 , USBKBD_LED_SCROLL_LOCK = 0x04 }
 USB keyboard LEDs. More...

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static unsigned int usbkbd_fill (struct usb_keyboard *kbd)
 Calculate keyboard buffer fill level.

Detailed Description

USB keyboard driver.

Definition in file usbkbd.h.

Macro Definition Documentation

◆ USBKBD_PROTOCOL

#define USBKBD_PROTOCOL   1

Keyboard protocol.

Definition at line 17 of file usbkbd.h.

◆ USBKBD_CTRL

#define USBKBD_CTRL   ( USBKBD_CTRL_LEFT | USBKBD_CTRL_RIGHT )

Either Ctrl key.

Definition at line 50 of file usbkbd.h.

Referenced by usbkbd_map().

◆ USBKBD_SHIFT

#define USBKBD_SHIFT   ( USBKBD_SHIFT_LEFT | USBKBD_SHIFT_RIGHT )

Either Shift key.

Definition at line 53 of file usbkbd.h.

Referenced by usbkbd_map().

◆ USBKBD_ALT

#define USBKBD_ALT   ( USBKBD_ALT_LEFT | USBKBD_ALT_RIGHT )

Either Alt key.

Definition at line 56 of file usbkbd.h.

◆ USBKBD_GUI

#define USBKBD_GUI   ( USBKBD_GUI_LEFT | USBKBD_GUI_RIGHT )

Either GUI key.

Definition at line 59 of file usbkbd.h.

◆ USBKBD_IDLE_DURATION

#define USBKBD_IDLE_DURATION   10 /* 10 x 4ms = 40ms */

Keyboard idle duration (in 4ms units)

This is a policy decision. We choose to use an autorepeat rate of approximately 40ms.

Definition at line 93 of file usbkbd.h.

Referenced by usbkbd_probe().

◆ USBKBD_HOLDOFF

#define USBKBD_HOLDOFF   12 /* 12 x 40ms = 480ms */

Keyboard auto-repeat hold-off (in units of USBKBD_IDLE_DURATION)

This is a policy decision. We choose to use an autorepeat delay of approximately 500ms.

Definition at line 100 of file usbkbd.h.

Referenced by usbkbd_report().

◆ USBKBD_INTR_MAX_FILL

#define USBKBD_INTR_MAX_FILL   8

Interrupt endpoint maximum fill level.

When idling, we are likely to poll the USB endpoint at only the 18.2Hz system timer tick rate. With a typical observed bInterval of 10ms (which will be rounded down to 8ms by the HCI drivers), this gives approximately 7 completions per poll.

Definition at line 109 of file usbkbd.h.

Referenced by usbkbd_probe().

◆ USBKBD_BUFSIZE

#define USBKBD_BUFSIZE   8

Keyboard buffer size.

Must be a power of two.

Definition at line 115 of file usbkbd.h.

Referenced by usbkbd_consume(), usbkbd_fill(), and usbkbd_produce().

Enumeration Type Documentation

◆ usb_keyboard_modifier

USB modifier keys.

Enumerator
USBKBD_CTRL_LEFT 

Left Ctrl key.

USBKBD_SHIFT_LEFT 

Left Shift key.

USBKBD_ALT_LEFT 

Left Alt key.

USBKBD_GUI_LEFT 

Left GUI key.

USBKBD_CTRL_RIGHT 

Right Ctrl key.

USBKBD_SHIFT_RIGHT 

Right Shift key.

USBKBD_ALT_RIGHT 

Right Alt key.

USBKBD_GUI_RIGHT 

Right GUI key.

Definition at line 30 of file usbkbd.h.

30 {
31 /** Left Ctrl key */
32 USBKBD_CTRL_LEFT = 0x01,
33 /** Left Shift key */
34 USBKBD_SHIFT_LEFT = 0x02,
35 /** Left Alt key */
36 USBKBD_ALT_LEFT = 0x04,
37 /** Left GUI key */
38 USBKBD_GUI_LEFT = 0x08,
39 /** Right Ctrl key */
40 USBKBD_CTRL_RIGHT = 0x10,
41 /** Right Shift key */
42 USBKBD_SHIFT_RIGHT = 0x20,
43 /** Right Alt key */
44 USBKBD_ALT_RIGHT = 0x40,
45 /** Right GUI key */
46 USBKBD_GUI_RIGHT = 0x80,
47};
@ 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.

Enumerator
USBKBD_KEY_A 
USBKBD_KEY_Z 
USBKBD_KEY_1 
USBKBD_KEY_0 
USBKBD_KEY_ENTER 
USBKBD_KEY_SPACE 
USBKBD_KEY_MINUS 
USBKBD_KEY_SLASH 
USBKBD_KEY_CAPS_LOCK 
USBKBD_KEY_F1 
USBKBD_KEY_UP 
USBKBD_KEY_NUM_LOCK 
USBKBD_KEY_PAD_ENTER 
USBKBD_KEY_PAD_1 
USBKBD_KEY_PAD_DOT 
USBKBD_KEY_NON_US 

Definition at line 62 of file usbkbd.h.

62 {
63 USBKBD_KEY_A = 0x04,
64 USBKBD_KEY_Z = 0x1d,
65 USBKBD_KEY_1 = 0x1e,
66 USBKBD_KEY_0 = 0x27,
67 USBKBD_KEY_ENTER = 0x28,
68 USBKBD_KEY_SPACE = 0x2c,
69 USBKBD_KEY_MINUS = 0x2d,
70 USBKBD_KEY_SLASH = 0x38,
72 USBKBD_KEY_F1 = 0x3a,
73 USBKBD_KEY_UP = 0x52,
76 USBKBD_KEY_PAD_1 = 0x59,
77 USBKBD_KEY_PAD_DOT = 0x63,
78 USBKBD_KEY_NON_US = 0x64,
79};
@ 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.

Enumerator
USBKBD_LED_NUM_LOCK 
USBKBD_LED_CAPS_LOCK 
USBKBD_LED_SCROLL_LOCK 

Definition at line 82 of file usbkbd.h.

82 {
86};
@ USBKBD_LED_SCROLL_LOCK
Definition usbkbd.h:85
@ USBKBD_LED_CAPS_LOCK
Definition usbkbd.h:84
@ USBKBD_LED_NUM_LOCK
Definition usbkbd.h:83

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ usbkbd_fill()

unsigned int usbkbd_fill ( struct usb_keyboard * kbd)
inlinestatic

Calculate keyboard buffer fill level.

Parameters
kbdUSB keyboard
Return values
fillKeyboard buffer fill level

Definition at line 165 of file usbkbd.h.

165 {
166 unsigned int fill = ( kbd->prod - kbd->cons );
167
169 return fill;
170}
static int fill
Definition string.h:209
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
unsigned int prod
Keyboard buffer producer counter.
Definition usbkbd.h:147
unsigned int cons
Keyboard buffer consumer counter.
Definition usbkbd.h:149
#define USBKBD_BUFSIZE
Keyboard buffer size.
Definition usbkbd.h:115

References assert, usb_keyboard::cons, fill, usb_keyboard::prod, and USBKBD_BUFSIZE.

Referenced by usbkbd_consume(), usbkbd_getchar(), usbkbd_iskey(), and usbkbd_produce().