8000 WIP: tinyusb: Support Python-defined runtime USB devices. · micropython/micropython@e5acbe5 · GitHub
[go: up one dir, main page]

Skip to content

Commit e5acbe5

Browse files
committed
WIP: tinyusb: Support Python-defined runtime USB devices.
This work was funded through GitHub Sponsors.
1 parent 7579a3b commit e5acbe5

File tree

9 files changed

+459
-2
lines changed

9 files changed

+459
-2
lines changed

ports/rp2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ set(MICROPY_SOURCE_QSTR
138138
${MICROPY_DIR}/shared/readline/readline.c
139139
${MICROPY_DIR}/shared/runtime/mpirq.c
140140
${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
141+
${MICROPY_DIR}/shared/tinyusb/usbd.c
141142
${PROJECT_SOURCE_DIR}/machine_adc.c
142143
${PROJECT_SOURCE_DIR}/machine_i2c.c
143144
${PROJECT_SOURCE_DIR}/machine_i2s.c

ports/rp2/modmachine.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = {
250250
{ MP_ROM_QSTR(MP_QSTR_SoftSPI), MP_ROM_PTR(&mp_machine_soft_spi_type) },
251251
{ MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&machine_timer_type) },
252252
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&machine_uart_type) },
253+
#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
254+
{ MP_ROM_QSTR(MP_QSTR_USBD), MP_ROM_PTR(&mp_type_usbd) },
255+
#endif
253256
{ MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) },
254257

255258
{ MP_ROM_QSTR(MP_QSTR_PWRON_RESET), MP_ROM_INT(RP2_RESET_PWRON) },

ports/rp2/modmachine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ extern const mp_obj_type_t machine_spi_type;
1212
extern const mp_obj_type_t machine_timer_type;
1313
extern const mp_obj_type_t machine_uart_type;
1414
extern const mp_obj_type_t machine_wdt_type;
15+
extern const mp_obj_type_t mp_type_usbd;
1516

1617
void machine_pin_init(void);
1718
void machine_pin_deinit(void);

ports/rp2/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#define MICROPY_HW_MCU_NAME "RP2040"
4141
#define MICROPY_HW_ENABLE_UART_REPL (0) // useful if there is no USB
4242
#define MICROPY_HW_ENABLE_USBDEV (1)
43+
#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (1) // TODO: should probably disable this by default
4344

4445
#ifndef MICROPY_CONFIG_ROM_LEVEL
4546
#define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES)

py/runtime.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ void mp_init(void) {
167167
MP_STATE_VM(bluetooth) = MP_OBJ_NULL;
168168
#endif
169169

170+
#if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE
171+
MP_STATE_VM(usbd) = MP_OBJ_NULL;
172+
#endif
173+
170174
#if MICROPY_PY_THREAD_GIL
171175
mp_thread_mutex_init(&MP_STATE_VM(gil_mutex));
172176
#endif

shared/tinyusb/tusb_config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
#define CFG_TUD_MSC_BUFSIZE (MICROPY_FATFS_MAX_SS)
6060
#endif
6161

62+
#define USBD_RHPORT (0) // Currently only one port is supported
63+
6264
// Define static descriptor size and interface count based on the above config
6365

6466
#if CFG_TUD_MSC

0 commit comments

Comments
 (0)
0