From: Melissa LeBlanc-Williams Date: Mon, 7 Mar 2022 16:22:40 +0000 (-0800) Subject: Merge pull request #562 from fivetide/usb_hid X-Git-Tag: 7.1.1 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/70b2c4be7ea920982168bb03fc55aa5b0563639c?hp=ef2657eaa1caf3262c6bbe1f2df5b6ed08f72162 Merge pull request #562 from fivetide/usb_hid solve issues with multiple hid devices on one gadget --- diff --git a/README.rst b/README.rst index 8f3aa29..3e21f93 100755 --- a/README.rst +++ b/README.rst @@ -32,6 +32,7 @@ for devices or hosts running CPython or MicroPython. Working code exists to emul * **pulseio** - contains classes that provide access to basic pulse IO (PWM) * **pwmio** - contains classes that provide access to basic pulse IO (PWM) * **rainbowio** - provides the colorwheel() function +* **usb_hid** - act as a hid-device using usb_gadget kernel driver For details, see the `Blinka API reference `_. diff --git a/src/usb_hid.py b/src/usb_hid.py index 8286b55..113ac83 100644 --- a/src/usb_hid.py +++ b/src/usb_hid.py @@ -261,7 +261,7 @@ Device.MOUSE = Device( ), usage_page=0x1, usage=0x02, - report_ids=[2], + report_ids=[0x02], in_report_lengths=[4], out_report_lengths=[0], ) @@ -450,7 +450,7 @@ Device.BOOT_MOUSE = Device( ), usage_page=0x1, usage=0x02, - report_ids=[1], + report_ids=[0], in_report_lengths=[4], out_report_lengths=[0], ) @@ -641,8 +641,8 @@ def enable(requested_devices: Sequence[Device], boot_device: int = 0) -> None: # $ echo 120 > configs/c.1/MaxPower # """ - for i, device in enumerate(requested_devices): - config_root = "%s/configs/device.%s" % (this.gadget_root, i + 1) + for device in requested_devices: + config_root = "%s/configs/device.1" % this.gadget_root Path("%s/" % config_root).mkdir(parents=True, exist_ok=True) Path("%s/strings/0x409" % config_root).mkdir(parents=True, exist_ok=True) Path("%s/strings/0x409/configuration" % config_root).write_text( @@ -702,7 +702,12 @@ def enable(requested_devices: Sequence[Device], boot_device: int = 0) -> None: # e.g.:: # # $ ln -s functions/ncm.usb0 configs/c.1 """ - Path("%s/hid.usb%s" % (config_root, report_id)).symlink_to(function_root) + try: + Path("%s/hid.usb%s" % (config_root, report_id)).symlink_to( + function_root + ) + except FileNotFoundError: + pass # """ 5. Enabling the gadget # ---------------------- # Such a gadget must be finally enabled so that the USB host can enumerate it.