Skip to main content

Module human_interface

Module human_interface 

Source
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:

KindNameByte 1Bytes 2 to 7
1keyboardmodifier bitmask, see Modifiersup to six key usages from the HID Keyboard/Keypad page (0x07), 0 = none
2consumer controlconsumer usage (HID page 0x0C), little endian, 0 = releasemust be 0
3mousebuttons bitmask, see MouseButtonsx (i8), y (i8), wheel (i8), pan (i8) in bytes 2 to 5, bytes 6 and 7 must be 0
4system controlusage from the HID Generic Desktop page: 0x81 power down, 0x82 sleep, 0x83 wake up, 0 = releasemust be 0

A keyboard message is the full pressed state: an all-zero keyboard message releases all keys.

§Control commands (kind b'h')

NumberCommandDirectionInputOutputEffect
0x00GET_STATUSReadVersionAbiStatusAbiReturns 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.
MouseButtons
Mouse buttons bitmask: left, right, middle.
StatusAbi
Connection state and keyboard indicators of the computer. Output of GET_STATUS.
VersionAbi
Carries only the ABI version and a reserved field. Input of GET_STATUS.

Enums§

Error
Error of the message protocol.
Message
One message of the emulation device.

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.