10000 wakeup feature for usb_hid package · Issue #8774 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content
wakeup feature for usb_hid package  #8774
Closed
@meesokim

Description

@meesokim

usb_hid packages support keyboard, mouse, consumer_contol features based on tinyusb. The examples of tinyusb can support wakeup in host sleep mode but Circuitpython usb_hid packages has no code to support it. I added some code from tinyusb example to Circuitpython usb implementation code. I tested this modification on esp32s2 board and works fine as I expected.

Here are the diff file.


diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c
index b28de9c1b1..7d0e6eff3a 100644
--- a/shared-module/usb_hid/Device.c
+++ b/shared-module/usb_hid/Device.c
@@ -229,12 +229,16 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t *
         RUN_BACKGROUND_TASKS;
     }

-    if (!tud_hid_ready()) {
-        mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("USB busy"));
-    }
+    if (!tud_suspended()) {
+        if (!tud_hid_ready()) {
+            mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("USB busy"));
+        }

-    if (!tud_hid_report(report_id, report, len)) {
-        mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("USB error"));
+        if (!tud_hid_report(report_id, report, len)) {
+            mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("USB error"));
+        }
+    } else {
+        tud_remote_wakeup();
     }
 }

diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c
index 811f61724f..9f932ddbfe 100644
--- a/supervisor/shared/usb/usb_desc.c
+++ b/supervisor/shared/usb/usb_desc.c
@@ -105,7 +105,7 @@ static const uint8_t configuration_descriptor_template[] = {
 #define CONFIG_NUM_INTERFACES_INDEX (4)
     0x01,        // 5 bConfigurationValue
     0x00,        // 6 iConfiguration (String Index)
-    0x80,        // 7 bmAttributes
+    0x80 | TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP,        // 7 bmAttributes
     0x32,        // 8 bMaxPower 100mA
 };

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0