extmod/machine_usb_device: Add USBDevice.remote_wakeup method.

This simply exposes the TinyUSB function.

Signed-off-by: Felix Dörre <felix@dogcraft.de>
This commit is contained in:
Felix Dörre 2024-06-12 06:56:51 +00:00 committed by Damien George
parent bb6a4669b2
commit 57008a1e69
2 changed files with 13 additions and 0 deletions

View File

@ -215,6 +215,13 @@ Methods
drivers. Placing a different string at any of these indexes overrides that
string in the built-in driver.
.. method:: USBDevice.remote_wakeup(self)
Wake up host if we are in suspend mode and the REMOTE_WAKEUP feature
is enabled by the host. This has to be enabled in the USB attributes,
and on the host. Returns ``True`` if remote wakeup was enabled and
active and the host was woken up.
.. method:: USBDevice.submit_xfer(self, ep, buffer /)
Submit a USB transfer on endpoint number ``ep``. ``buffer`` must be

View File

@ -157,6 +157,11 @@ static mp_obj_t usb_device_active(size_t n_args, const mp_obj_t *args) {
}
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(usb_device_active_obj, 1, 2, usb_device_active);
static mp_obj_t usb_remote_wakeup(mp_obj_t self) {
return mp_obj_new_bool(tud_remote_wakeup());
}
static MP_DEFINE_CONST_FUN_OBJ_1(usb_remote_wakeup_obj, usb_remote_wakeup);
static mp_obj_t usb_device_stall(size_t n_args, const mp_obj_t *args) {
mp_obj_usb_device_t *self = (mp_obj_usb_device_t *)MP_OBJ_TO_PTR(args[0]);
int epnum = mp_obj_get_int(args[1]);
@ -272,6 +277,7 @@ static const mp_rom_map_elem_t usb_device_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_submit_xfer), MP_ROM_PTR(&usb_device_submit_xfer_obj) },
{ MP_ROM_QSTR(MP_QSTR_active), MP_ROM_PTR(&usb_device_active_obj) },
{ MP_ROM_QSTR(MP_QSTR_stall), MP_ROM_PTR(&usb_device_stall_obj) },
{ MP_ROM_QSTR(MP_QSTR_remote_wakeup), MP_ROM_PTR(&usb_remote_wakeup_obj) },
// Built-in driver constants
{ MP_ROM_QSTR(MP_QSTR_BUILTIN_NONE), MP_ROM_PTR(&mp_type_usb_device_builtin_none) },