Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer able to create custom USB HID devices. #5213

Closed
fasteddy516 opened this issue Aug 24, 2021 · 0 comments · Fixed by #5214
Closed

No longer able to create custom USB HID devices. #5213

fasteddy516 opened this issue Aug 24, 2021 · 0 comments · Fixed by #5214
Assignees
Milestone

Comments

@fasteddy516
Copy link

fasteddy516 commented Aug 24, 2021

CircuitPython version

Adafruit CircuitPython 7.0.0-beta.0 on 2021-08-24; Adafruit Metro M4 Express with samd51j19
Adafruit CircuitPython 7.0.0-beta.0 on 2021-08-24; Adafruit QT Py M0 with samd21e18

Code/REPL

"""boot.py"""
import usb_hid

# fmt: off
# This is only one example of a gamepad descriptor, and may not suit your needs.
GAMEPAD_REPORT_DESCRIPTOR = bytes((
    0x05, 0x01,  # Usage Page (Generic Desktop Ctrls)
    0x09, 0x05,  # Usage (Game Pad)
    0xA1, 0x01,  # Collection (Application)
    0x85, 0x04,  # Report ID (will be replaced at runtime)
    0x05, 0x09,  #   Usage Page (Button)
    0x19, 0x01,  #   Usage Minimum (Button 1)
    0x29, 0x10,  #   Usage Maximum (Button 16)
    0x15, 0x00,  #   Logical Minimum (0)
    0x25, 0x01,  #   Logical Maximum (1)
    0x75, 0x01,  #   Report Size (1)
    0x95, 0x10,  #   Report Count (16)
    0x81, 0x02,  #   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
    0x05, 0x01,  #   Usage Page (Generic Desktop Ctrls)
    0x15, 0x81,  #   Logical Minimum (-127)
    0x25, 0x7F,  #   Logical Maximum (127)
    0x09, 0x30,  #   Usage (X)
    0x09, 0x31,  #   Usage (Y)
    0x09, 0x32,  #   Usage (Z)
    0x09, 0x35,  #   Usage (Rz)
    0x75, 0x08,  #   Report Size (8)
    0x95, 0x04,  #   Report Count (4)
    0x81, 0x02,  #   Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
    0xC0,        # End Collection
))
# fmt: on

gamepad = usb_hid.Device(
    report_descriptor=GAMEPAD_REPORT_DESCRIPTOR,
    usage_page=0x01,  # Generic Desktop Control
    usage=0x05,  # Gamepad
    report_ids=(4,),
    in_report_lengths=(6,),  # This gamepad sends 6 bytes in its report.
    out_report_lengths=(0,),  # It does not receive any reports.
)

usb_hid.enable(
    (
        usb_hid.Device.KEYBOARD,
        usb_hid.Device.MOUSE,
        usb_hid.Device.CONSUMER_CONTROL,
        gamepad,
    )
)

Behavior

On the Metro M4 I get the following error in boot_out.txt:

Traceback (most recent call last):
  File "boot.py", line 38, in <module>
TypeError: '' object isn't subscriptable

On the QT-PY boot_out.txt is empty, and I get this message in the serial console:

You are in safe mode because:
CircuitPython core code crashed hard. Whoops!
Crash into the HardFault_Handler.
Please file an issue with the contents of your CIRCUITPY drive at
https://github.com/adafruit/circuitpython/issues

Description

I am unable to create custom USB HID devices after the API change from 7.0.0 alpha.x > beta.0.

I was trying to update my joystick library to use the updated API, but when I couldn't get that to work I tried just updating the gamepad example from the learn guide, ultimately with the same results. The code in question ran perfectly in the 7.0.0 alphas 3 through 6.

I'm not sure if this is a bug, or if I'm passing values incorrectly in the usb_hid.Device() call.

Additional information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants