Skip to content

shared/tinyusb: Fix build errors with CDC support disabled. #17708

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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: 9 additions & 4 deletions ports/esp32/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
#include "py/mphal.h"
#include "usb.h"

#if MICROPY_HW_USB_CDC
#include "esp_rom_gpio.h"
#if MICROPY_HW_ENABLE_USBDEV

#include "esp_mac.h"
#include "esp_private/usb_phy.h"

#include "shared/tinyusb/mp_usbd.h"

#if MICROPY_HW_USB_CDC
#include "esp_rom_gpio.h"
#include "esp_private/usb_phy.h"

static usb_phy_handle_t phy_hdl;


Expand Down Expand Up @@ -69,6 +72,8 @@ void usb_usj_mode(void) {
}
#endif

#endif // MICROPY_HW_USB_CDC

void mp_usbd_port_get_serial_number(char *serial_buf) {
// use factory default MAC as serial ID
uint8_t mac[8];
Expand All @@ -77,4 +82,4 @@ void mp_usbd_port_get_serial_number(char *serial_buf) {
mp_usbd_hex_str(serial_buf, mac, sizeof(mac));
}

#endif // MICROPY_HW_USB_CDC
#endif // MICROPY_HW_ENABLE_USBDEV
6 changes: 6 additions & 0 deletions ports/mimxrt/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ ringbuf_t stdin_ringbuf = {stdin_ringbuf_array, sizeof(stdin_ringbuf_array), 0,

uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
uintptr_t ret = 0;
#if MICROPY_HW_USB_CDC
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
#endif
#if MICROPY_PY_OS_DUPTERM
ret |= mp_os_dupterm_poll(poll_flags);
#endif
Expand All @@ -56,7 +58,9 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {

int mp_hal_stdin_rx_chr(void) {
for (;;) {
#if MICROPY_HW_USB_CDC
mp_usbd_cdc_poll_interfaces(0);
#endif
int c = ringbuf_get(&stdin_ringbuf);
if (c != -1) {
return c;
Expand All @@ -74,11 +78,13 @@ int mp_hal_stdin_rx_chr(void) {
mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
mp_uint_t ret = len;
bool did_write = false;
#if MICROPY_HW_USB_CDC
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
if (cdc_res > 0) {
did_write = true;
ret = MIN(cdc_res, ret);
}
#endif
#if MICROPY_PY_OS_DUPTERM
int dupterm_res = mp_os_dupterm_tx_strn(str, len);
if (dupterm_res >= 0) {
Expand Down
5 changes: 3 additions & 2 deletions ports/rp2/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
static uint64_t time_us_64_offset_from_epoch;
#endif

#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC
#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_HW_USB_CDC || MICROPY_PY_OS_DUPTERM_NOTIFY

#ifndef MICROPY_HW_STDIN_BUFFER_LEN
#define MICROPY_HW_STDIN_BUFFER_LEN 512
Expand Down Expand Up @@ -83,11 +83,12 @@ int mp_hal_stdin_rx_chr(void) {
#if MICROPY_HW_USB_CDC
mp_usbd_cdc_poll_interfaces(0);
#endif

#if MICROPY_HW_ENABLE_UART_REPL || MICROPY_PY_OS_DUPTERM_NOTIFY
int c = ringbuf_get(&stdin_ringbuf);
if (c != -1) {
return c;
}
#endif
#if MICROPY_PY_OS_DUPTERM
int dupterm_c = mp_os_dupterm_rx_chr();
if (dupterm_c >= 0) {
Expand Down
7 changes: 6 additions & 1 deletion ports/samd/mphalport.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ uint64_t mp_hal_ticks_us_64(void) {

uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
uintptr_t ret = 0;
#if MICROPY_HW_USB_CDC
ret |= mp_usbd_cdc_poll_interfaces(poll_flags);
#endif
#if MICROPY_PY_OS_DUPTERM
ret |= mp_os_dupterm_poll(poll_flags);
#endif
Expand All @@ -129,8 +131,9 @@ uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {

int mp_hal_stdin_rx_chr(void) {
for (;;) {

#if MICROPY_HW_USB_CDC
mp_usbd_cdc_poll_interfaces(0);
#endif
int c = ringbuf_get(&stdin_ringbuf);
if (c != -1) {
return c;
Expand All @@ -149,11 +152,13 @@ int mp_hal_stdin_rx_chr(void) {
mp_uint_t mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) {
mp_uint_t ret = len;
bool did_write = false;
#if MICROPY_HW_USB_CDC
mp_uint_t cdc_res = mp_usbd_cdc_tx_strn(str, len);
if (cdc_res > 0) {
did_write = true;
ret = MIN(cdc_res, ret);
}
#endif
#if MICROPY_PY_OS_DUPTERM
int dupterm_res = mp_os_dupterm_tx_strn(str, len);
if (dupterm_res >= 0) {
Expand Down
3 changes: 3 additions & 0 deletions shared/tinyusb/mp_usbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@
#ifndef NO_QSTR
#include "tusb.h"
#include "device/dcd.h"
#include "class/cdc/cdc_device.h"
#endif

// Initialise TinyUSB device.
static inline void mp_usbd_init_tud(void) {
tusb_init();
#if MICROPY_HW_USB_CDC
tud_cdc_configure_fifo_t cfg = { .rx_persistent = 0, .tx_persistent = 1 };
tud_cdc_configure_fifo(&cfg);
#endif
}

// Run the TinyUSB device task
Expand Down
2 changes: 2 additions & 0 deletions shared/tinyusb/mp_usbd_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,11 @@ static uint16_t runtime_dev_open(uint8_t rhport, tusb_desc_interface_t const *it
}

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

// Determine the total descriptor length of the interface(s) we are going to claim
uint8_t assoc_itf_count = _runtime_dev_count_itfs(itf_desc);
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy