From 0baa3b5528257d2d8c3ada5842885d83b9acbb75 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Wed, 13 Mar 2024 10:38:05 +1100 Subject: [PATCH] rp2: Enable support for Python USB devices. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/rp2/CMakeLists.txt | 2 ++ ports/rp2/main.c | 4 ++++ ports/rp2/mpconfigport.h | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 392fed29b1..b605faaf21 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -108,6 +108,7 @@ set(MICROPY_SOURCE_LIB ${MICROPY_DIR}/shared/tinyusb/mp_cdc_common.c ${MICROPY_DIR}/shared/tinyusb/mp_usbd.c ${MICROPY_DIR}/shared/tinyusb/mp_usbd_descriptor.c + ${MICROPY_DIR}/shared/tinyusb/mp_usbd_runtime.c ) set(MICROPY_SOURCE_DRIVERS @@ -146,6 +147,7 @@ set(MICROPY_SOURCE_QSTR ${MICROPY_DIR}/shared/readline/readline.c ${MICROPY_DIR}/shared/runtime/mpirq.c ${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c + ${MICROPY_DIR}/shared/tinyusb/mp_usbd_runtime.c ${MICROPY_PORT_DIR}/machine_adc.c ${MICROPY_PORT_DIR}/machine_i2c.c ${MICROPY_PORT_DIR}/machine_pin.c diff --git a/ports/rp2/main.c b/ports/rp2/main.c index 70a67066fc..40374faff9 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c @@ -221,6 +221,10 @@ int main(int argc, char **argv) { mp_thread_deinit(); #endif soft_timer_deinit(); + #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + mp_usbd_deinit(); + #endif + gc_sweep_all(); mp_deinit(); } diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index c11d2fa69d..a29692d0be 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -52,6 +52,10 @@ #ifndef MICROPY_HW_USB_MSC #define MICROPY_HW_USB_MSC (0) #endif + +#ifndef MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE +#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (1) // Support machine.USBDevice +#endif #endif #ifndef MICROPY_CONFIG_ROM_LEVEL