10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
14 #include <ipxe/usbhid.h>
16 /** Keyboard protocol */
17 #define USBKBD_PROTOCOL 1
19 /** A USB keyboard report */
20 struct usb_keyboard_report {
27 } __attribute__ (( packed ));
29 /** USB modifier keys */
30 enum usb_keyboard_modifier {
32 USBKBD_CTRL_LEFT = 0x01,
34 USBKBD_SHIFT_LEFT = 0x02,
36 USBKBD_ALT_LEFT = 0x04,
38 USBKBD_GUI_LEFT = 0x08,
40 USBKBD_CTRL_RIGHT = 0x10,
41 /** Right Shift key */
42 USBKBD_SHIFT_RIGHT = 0x20,
44 USBKBD_ALT_RIGHT = 0x40,
46 USBKBD_GUI_RIGHT = 0x80,
49 /** Either Ctrl key */
50 #define USBKBD_CTRL ( USBKBD_CTRL_LEFT | USBKBD_CTRL_RIGHT )
52 /** Either Shift key */
53 #define USBKBD_SHIFT ( USBKBD_SHIFT_LEFT | USBKBD_SHIFT_RIGHT )
56 #define USBKBD_ALT ( USBKBD_ALT_LEFT | USBKBD_ALT_RIGHT )
59 #define USBKBD_GUI ( USBKBD_GUI_LEFT | USBKBD_GUI_RIGHT )
67 USBKBD_KEY_ENTER = 0x28,
68 USBKBD_KEY_SPACE = 0x2c,
69 USBKBD_KEY_MINUS = 0x2d,
70 USBKBD_KEY_SLASH = 0x38,
71 USBKBD_KEY_CAPSLOCK = 0x39,
75 /** Keyboard idle duration (in 4ms units)
77 * This is a policy decision. We choose to use an autorepeat rate of
80 #define USBKBD_IDLE_DURATION 10 /* 10 x 4ms = 40ms */
82 /** Keyboard auto-repeat hold-off (in units of USBKBD_IDLE_DURATION)
84 * This is a policy decision. We choose to use an autorepeat delay of
85 * approximately 500ms.
87 #define USBKBD_HOLDOFF 12 /* 12 x 40ms = 480ms */
89 /** Interrupt endpoint maximum fill level
91 * When idling, we are likely to poll the USB endpoint at only the
92 * 18.2Hz system timer tick rate. With a typical observed bInterval
93 * of 10ms (which will be rounded down to 8ms by the HCI drivers),
94 * this gives approximately 7 completions per poll.
96 #define USBKBD_INTR_MAX_FILL 8
98 /** Keyboard buffer size
100 * Must be a power of two.
102 #define USBKBD_BUFSIZE 8
104 /** A USB keyboard device */
105 struct usb_keyboard {
108 /** List of all USB keyboards */
109 struct list_head list;
113 /** USB human interface device */
116 /** Most recent keyboard report */
117 struct usb_keyboard_report report;
118 /** Most recently pressed non-modifier key (if any) */
119 unsigned int keycode;
120 /** Autorepeat hold-off time (in number of completions reported) */
121 unsigned int holdoff;
125 * This stores iPXE key values.
127 unsigned int key[USBKBD_BUFSIZE];
128 /** Keyboard buffer producer counter */
130 /** Keyboard buffer consumer counter */
132 /** Keyboard buffer sub-consumer counter
134 * This represents the index within the ANSI escape sequence
135 * corresponding to an iPXE key value.
137 unsigned int subcons;
141 * Calculate keyboard buffer fill level
143 * @v kbd USB keyboard
144 * @ret fill Keyboard buffer fill level
146 static inline __attribute__ (( always_inline )) unsigned int
147 usbkbd_fill ( struct usb_keyboard *kbd ) {
148 unsigned int fill = ( kbd->prod - kbd->cons );
150 assert ( fill <= USBKBD_BUFSIZE );
154 #endif /* _USBKBD_H */