feat(usb_cdc): Add select functionality

This commit is contained in:
Guillaume Souchere
2025-07-29 10:14:19 +02:00
parent 8e094e7087
commit d5dca1a78d
13 changed files with 368 additions and 7 deletions
+39 -1
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -46,6 +46,8 @@
#include "esp32s3/rom/usb/chip_usb_dw_wrapper.h"
#endif
#include "esp_private/esp_vfs_cdcacm_select.h"
#define CDC_WORK_BUF_SIZE (ESP_ROM_CDC_ACM_WORK_BUF_MIN + CONFIG_ESP_CONSOLE_USB_CDC_RX_BUF_SIZE)
typedef enum {
@@ -55,6 +57,7 @@ typedef enum {
REBOOT_BOOTLOADER_DFU,
} reboot_type_t;
static bool s_usb_installed = false;
static reboot_type_t s_queue_reboot = REBOOT_NONE;
static int s_prev_rts_state;
static intr_handle_t s_usb_int_handle;
@@ -131,6 +134,18 @@ int esp_usb_console_osglue_wait_proc(int delay_us)
}
}
/* USB interrupt handler, forward the call to the ROM driver.
* Non-static to allow placement into IRAM by ldgen.
*/
static cdcacm_select_notif_callback_t s_cdcacm_select_notif_callback = NULL;
void cdcacm_set_select_notif_callback(cdcacm_select_notif_callback_t cdcacm_select_notif_callback)
{
if (esp_usb_console_is_installed()) {
s_cdcacm_select_notif_callback = cdcacm_select_notif_callback;
}
}
/* Called by ROM CDC ACM driver from interrupt context./
* Non-static to allow placement into IRAM by ldgen.
*/
@@ -168,6 +183,8 @@ void esp_usb_console_dfu_detach_cb(int timeout)
*/
void esp_usb_console_interrupt(void *arg)
{
BaseType_t xTaskWoken = 0;
usb_dc_check_poll_for_interrupts();
/* Restart can be requested from esp_usb_console_cdc_acm_cb or esp_usb_console_dfu_detach_cb */
if (s_queue_reboot != REBOOT_NONE) {
@@ -192,6 +209,21 @@ void esp_usb_console_interrupt(void *arg)
esp_restart_noos();
}
}
if (esp_usb_console_available_for_read() > 0) {
if (s_cdcacm_select_notif_callback != NULL) {
s_cdcacm_select_notif_callback(CDCACM_SELECT_READ_NOTIF, &xTaskWoken);
}
}
if (esp_usb_console_write_available()) {
if (s_cdcacm_select_notif_callback != NULL) {
s_cdcacm_select_notif_callback(CDCACM_SELECT_WRITE_NOTIF, &xTaskWoken);
}
}
if (xTaskWoken == pdTRUE) {
portYIELD_FROM_ISR();
}
}
/* Called as esp_timer callback when the restart timeout expires.
@@ -299,6 +331,7 @@ esp_err_t esp_usb_console_init(void)
esp_rom_install_channel_putc(1, &esp_usb_console_write_char);
#endif // CONFIG_ESP_CONSOLE_USB_CDC_SUPPORT_ETS_PRINTF
s_usb_installed = true;
return ESP_OK;
}
@@ -422,6 +455,11 @@ esp_err_t esp_usb_console_set_cb(esp_usb_console_cb_t rx_cb, esp_usb_console_cb_
return ESP_OK;
}
bool esp_usb_console_is_installed(void)
{
return s_usb_installed;
}
ssize_t esp_usb_console_available_for_read(void)
{
if (s_cdc_acm_device == NULL) {