8000 shared-module/usb_hid: allow HID to wake sleeping host computer by dhalbert · Pull Request #8830 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

shared-module/usb_hid: allow HID to wake sleeping host computer #8830

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

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions shared-bindings/usb_hid/Device.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
//| in_report_lengths=(5, 2),
//| out_report_lengths=(6, 0),
//| )
//|
//| The HID device is able to wake up a suspended (sleeping) host computer.
//| See `send_report()` for details.
//| """
//| ...
//| KEYBOARD: Device
Expand Down Expand Up @@ -166,6 +169,16 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args
//| """Send an HID report. If the device descriptor specifies zero or one report id's,
//| you can supply `None` (the default) as the value of ``report_id``.
//| Otherwise you must specify which report id to use when sending the report.
//|
//| If the USB host is suspended (sleeping), then `send_report()` will request that the host wake up.
//| The ``report`` itself will be discarded, to prevent unwanted extraneous characters,
//| mouse clicks, etc.
//|
//| Note: Host operating systems allow enabling and disabling specific devices
//| and kinds of devices to do wakeup.
//| The defaults are different for different operating systems.
//| For instance, on Linux, only the primary keyboard may be enabled.
//| In addition, there may be USB wakeup settings in the host computer BIOS/UEFI.
//| """
//| ...
STATIC mp_obj_t usb_hid_device_send_report(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
Expand Down
14 changes: 9 additions & 5 deletions shared-module/usb_hid/Device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion supervisor/shared/usb/usb_desc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

Expand Down
0