usb_hid module allows you to output data as a HID device.
Tuple of all active HID device interfaces. The default set of devices is
Device.KEYBOARD, Device.MOUSE, Device.CONSUMER_CONTROL, On boards where
usb_hidis disabled by default,
devicesis an empty tuple.
disable() → None¶
Do not present any USB HID devices to the host computer. Can be called in
boot.py, before USB is connected. The HID composite device is normally enabled by default, but on some boards with limited endpoints, including STM32F4, it is disabled by default. You must turn off another USB device such as
storageto free up endpoints for use by
enable(devices: Optional[Sequence[Device]]) → None¶
Specify which USB HID devices that will be available. Can be called in
boot.py, before USB is connected.
devices (Sequence) –
devicesis empty, HID is disabled. The order of the
Devicesmay matter to the host. For instance, for MacOS, put the mouse device before any Gamepad or Digitizer HID device or else it will not work.
If you enable too many devices at once, you will run out of USB endpoints. The number of available endpoints varies by microcontroller. CircuitPython will go into safe mode after running boot.py to inform you if not enough endpoints are available.
Device(*, descriptor: _typing.ReadableBuffer, usage_page: int, usage: int, in_report_length: int, out_report_length: int = 0, report_id_index: Optional[int])¶
HID Device specification
report_descriptor (ReadableBuffer) – The USB HID Report descriptor bytes. The descriptor is not not verified for correctness; it is up to you to make sure it is not malformed.
usage_page (int) – The Usage Page value from the descriptor. Must match what is in the descriptor.
usage (int) – The Usage value from the descriptor. Must match what is in the descriptor.
in_report_length (int) – Size in bytes of the HID report sent to the host. “In” is with respect to the host.
out_report_length (int) – Size in bytes of the HID report received from the host. “Out” is with respect to the host. If no reports are expected, use 0.
report_id_index (int) – position of byte in descriptor that contains the Report ID. A Report ID will be assigned when the device is created. If there is no Report ID, use
Standard keyboard device supporting keycodes 0x00-0xDD, modifiers 0xE-0xE7, and five LED indicators.
Standard mouse device supporting five mouse buttons, X and Y relative movements from -127 to 127 in each report, and a relative mouse wheel change from -127 to 127 in each report.
Consumer Control device supporting sent values from 1-652, with no rollover.
The functionality of the device as an int. (read-only)
For example, Keyboard is 0x06 within the generic desktop usage page 0x01. Mouse is 0x02 within the same usage page.