Skip to content

Commit 2545d91

Browse files
committed
Merge commit 'd1607598faf4ce2ef8e1a0385f75036ffb50ea9b'
2 parents 84aff8a + d160759 commit 2545d91

File tree

6 files changed

+24
-7
lines changed

6 files changed

+24
-7
lines changed

ports/esp32/usb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
#include "py/mphal.h"
2929
#include "usb.h"
3030

31-
#if MICROPY_HW_USB_CDC
32-
#include "esp_rom_gpio.h"
31+
#if MICROPY_HW_ENABLE_USBDEV
32+
3333
#include "esp_mac.h"
34+
#include "esp_rom_gpio.h"
3435
#include "esp_private/usb_phy.h"
3536

3637
#include "shared/tinyusb/mp_usbd.h"
3738

3839
static usb_phy_handle_t phy_hdl;
3940

40-
4141
void usb_init(void) {
4242
// ref: https://github.com/espressif/esp-usb/blob/4b6a798d0bed444fff48147c8dcdbbd038e92892/device/esp_tinyusb/tinyusb.c
4343

@@ -77,4 +77,4 @@ void mp_usbd_port_get_serial_number(char *serial_buf) {
7777
mp_usbd_hex_str(serial_buf, mac, sizeof(mac));
7878
}
7979

80-
#endif // MICROPY_HW_USB_CDC
80+
#endif // MICROPY_HW_ENABLE_USBDEV

ports/mimxrt/mphalport.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0,
4747

4848
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
4949
uintptr_t ret = 0;
50+
#if MICROPY_HW_USB_CDC
5051
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
52+
#endif
5153
#if MICROPY_PY_OS_DUPTERM
5254
ret |= mp_os_dupterm_poll(poll_flags);
5355
#endif
@@ -56,7 +58,9 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
5658

5759
int mp_hal_stdin_rx_chr(void) {
5860
for (;;) {
61+
#if MICROPY_HW_USB_CDC
5962
mp_usbd_cdc_poll_interfaces(0);
63+
#endif
6064
int c = ringbuf_get(&stdin_ringbuf);
6165
if (c != -1) {
6266
return c;
@@ -74,11 +78,13 @@ int mp_hal_stdin_rx_chr(void) {
7478
mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
7579
mp_uint_t ret = len;
7680
bool did_write = false;
81+
#if MICROPY_HW_USB_CDC
7782
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
7883
if (cdc_res > 0) {
7984
did_write = true;
8085
ret = MIN(cdc_res, ret);
8186
}
87+
#endif
8288
#if MICROPY_PY_OS_DUPTERM
8389
int dupterm_res = mp_os_dupterm_tx_strn(str, len);
8490
if (dupterm_res >= 0) {

ports/rp2/mphalport.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
static uint64_t time_us_64_offset_from_epoch;
5151
#endif
5252

53-
#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC
53+
#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC || MICROPY_PY_OS_DUPTERM_NOTIFY
5454

5555
#ifndef MICROPY_HW_STDIN_BUFFER_LEN
5656
#define MICROPY_HW_STDIN_BUFFER_LEN 512
@@ -83,11 +83,12 @@ int mp_hal_stdin_rx_chr(void) {
8383
#if MICROPY_HW_USB_CDC
8484
mp_usbd_cdc_poll_interfaces(0);
8585
#endif
86-
86+
#if MICROPY_HW_USB_CDC || MICROPY_HW_ENABLE_UART_REPL || MICROPY_PY_OS_DUPTERM_NOTIFY
8787
int c = ringbuf_get(&stdin_ringbuf);
8888
if (c != -1) {
8989
return c;
9090
}
91+
#endif
9192
#if MICROPY_PY_OS_DUPTERM
9293
int dupterm_c = mp_os_dupterm_rx_chr();
9394
if (dupterm_c >= 0) {

ports/samd/mphalport.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ uint64_t mp_hal_ticks_us_64(void) {
120120

121121
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
122122
uintptr_t ret = 0;
123+
#if MICROPY_HW_USB_CDC
123124
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
125+
#endif
124126
#if MICROPY_PY_OS_DUPTERM
125127
ret |= mp_os_dupterm_poll(poll_flags);
126128
#endif
@@ -129,8 +131,9 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
129131

130132
int mp_hal_stdin_rx_chr(void) {
131133
for (;;) {
132-
134+
#if MICROPY_HW_USB_CDC
133135
mp_usbd_cdc_poll_interfaces(0);
136+
#endif
134137
int c = ringbuf_get(&stdin_ringbuf);
135138
if (c != -1) {
136139
return c;
@@ -149,11 +152,13 @@ int mp_hal_stdin_rx_chr(void) {
149152
mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
150153
mp_uint_t ret = len;
151154
bool did_write = false;
155+
#if MICROPY_HW_USB_CDC
152156
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
153157
if (cdc_res > 0) {
154158
did_write = true;
155159
ret = MIN(cdc_res, ret);
156160
}
161+
#endif
157162
#if MICROPY_PY_OS_DUPTERM
158163
int dupterm_res = mp_os_dupterm_tx_strn(str, len);
159164
if (dupterm_res >= 0) {

shared/tinyusb/mp_usbd.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,16 @@
3838
#ifndef NO_QSTR
3939
#include "tusb.h"
4040
#include "device/dcd.h"
41+
#include "class/cdc/cdc_device.h"
4142
#endif
4243

4344
// Initialise TinyUSB device.
4445
static inline void mp_usbd_init_tud(void) {
4546
tusb_init();
47+
#if MICROPY_HW_USB_CDC
4648
tud_cdc_configure_fifo_t cfg = { .rx_persistent = 0, .tx_persistent = 1 };
4749
tud_cdc_configure_fifo(&cfg);
50+
#endif
4851
}
4952

5053
// Run the TinyUSB device task

shared/tinyusb/mp_usbd_runtime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,11 @@ static uint16_t runtime_dev_open(uint8_t rhport, tusb_desc_interface_t const *it
267267
}
268268

269269
// If TinyUSB built-in drivers are enabled, don't claim any interface in the built-in range
270+
#if USBD_ITF_BUILTIN_MAX > 0
270271
if (mp_usb_device_builtin_enabled(usbd) && itf_desc->bInterfaceNumber < USBD_ITF_BUILTIN_MAX) {
271272
return 0;
272273
}
274+
#endif
273275

274276
// Determine the total descriptor length of the interface(s) we are going to claim
275277
uint8_t assoc_itf_count = _runtime_dev_count_itfs(itf_desc);

0 commit comments

Comments
 (0)