]> Repositories - Adafruit_Blinka-hackapet.git/commitdiff
Merge pull request #562 from fivetide/usb_hid 7.1.1
authorMelissa LeBlanc-Williams <melissa@adafruit.com>
Mon, 7 Mar 2022 16:22:40 +0000 (08:22 -0800)
committerGitHub <noreply@github.com>
Mon, 7 Mar 2022 16:22:40 +0000 (08:22 -0800)
solve issues with multiple hid devices on one gadget

README.rst
src/usb_hid.py

index 8f3aa290927d82c1ad7bb809e84730f2e92c40c8..3e21f93d5c5c086d24c3ad086335c18723fcc7b5 100755 (executable)
@@ -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
 <https://circuitpython.readthedocs.io/projects/blinka/en/latest/index.html>`_.
index 8286b558e7dac500fe7a7a01732821759da680da..113ac83a2fbebe05d836b8925749b67ebf3acfb7 100644 (file)
@@ -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.