Expand description
Human interface emulation device contract (/devices/human_interface/emulation, kind b'h').
A Xila device can act as a USB or Bluetooth keyboard, media remote and mouse toward the
computer it is connected to (shortcuts, screenshots, play/pause, volume). An application
writes messages to the device node. The upper half
(drivers_peripherals::human_interface) validates the message structure and forwards
HID reports to the target controller (peripherals::human_interface::HumanInterfaceController),
which every USB and Bluetooth Low Energy lower half implements. The shared HID report
descriptor lives in peripherals::human_interface.
§File contract
The node is write-only for reports: read fails with Unsupported. The connection
status is a control command, which WebAssembly guests reach through the fd_control
import of the Wasm host.
§Write
Each write contains one or more messages of exactly MESSAGE_SIZE (8) bytes. A write
whose length is not a multiple of 8 fails with InvalidArgument. Every message must
decode: an unknown kind in byte 0 or a non-zero reserved byte makes the message invalid.
Reserved bytes are written as zero on encode.
The upper half sends the messages of one write one by one and returns the number of
accepted bytes: when the first message is invalid or its report cannot be sent, the
write fails with an error; when a later message fails, the write returns the accepted
byte count, a multiple of MESSAGE_SIZE.
Byte 0 of a message is the kind:
| Kind | Name | Byte 1 | Bytes 2 to 7 |
|---|---|---|---|
1 | keyboard | modifier bitmask, see Modifiers | up to six key usages from the HID Keyboard/Keypad page (0x07), 0 = none |
2 | consumer control | consumer usage (HID page 0x0C), little endian, 0 = release | must be 0 |
3 | mouse | buttons bitmask, see MouseButtons | x (i8), y (i8), wheel (i8), pan (i8) in bytes 2 to 5, bytes 6 and 7 must be 0 |
4 | system control | usage from the HID Generic Desktop page: 0x81 power down, 0x82 sleep, 0x83 wake up, 0 = release | must be 0 |
A keyboard message is the full pressed state: an all-zero keyboard message releases all keys.
§Control commands (kind b'h')
| Number | Command | Direction | Input | Output | Effect |
|---|---|---|---|---|---|
0x00 | GET_STATUS | Read | VersionAbi | StatusAbi | Returns the connection state and the keyboard LED bitmask. |
Every struct starts with a version field equal to ABI_VERSION and carries zeroed
reserved fields. A wrong version or a non-zero reserved field is InvalidArgument.
Modules§
- consumer
- Consumer page (0x0C) usages: media remote controls.
- keyboard
- Keyboard/Keypad page (0x07) usages.
- system
- Generic Desktop page (0x01) system control usages.
Structs§
- GET_
STATUS - Messages
- Iterator over the messages of one write.
- Modifiers
- Keyboard modifier bitmask, HID standard order: left control, left shift, left alt, left GUI, then the right ones.
- Mouse
Buttons - Mouse buttons bitmask: left, right, middle.
- Status
Abi - Connection state and keyboard indicators of the computer. Output of
GET_STATUS. - Version
Abi - Carries only the ABI version and a reserved field. Input of
GET_STATUS.
Enums§
Constants§
- ABI_
VERSION - Version of every control ABI struct in this module.
- EMULATION_
PATH - Path of the emulation device node in the virtual file system.
- INDICATOR_
CAPS_ LOCK - Keyboard indicator bit 1: caps lock is on.
- INDICATOR_
NUM_ LOCK - Keyboard indicator bit 0: num lock is on.
- INDICATOR_
SCROLL_ LOCK - Keyboard indicator bit 2: scroll lock is on.
- KEY_
COUNT - Number of key usages in one keyboard message.
- KIND_
CONSUMER - Kind byte of a consumer control message. Also the report identifier of the consumer report.
- KIND_
KEYBOARD - Kind byte of a keyboard message. Also the report identifier of the keyboard report.
- KIND_
MOUSE - Kind byte of a mouse message. Also the report identifier of the mouse report.
- KIND_
SYSTEM - Kind byte of a system control message. Also the report identifier of the system report.
- MESSAGE_
SIZE - Size of one message in bytes.