From a6e0fd4a9f95719d4e01ebd25ca2d21c85dbcbf2 Mon Sep 17 00:00:00 2001 From: Gareth Coleman Date: Thu, 25 Apr 2024 10:48:51 +0100 Subject: [PATCH 1/5] add D pin mappings --- variants/unphone9/pins_arduino.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/variants/unphone9/pins_arduino.h b/variants/unphone9/pins_arduino.h index 1edec9650e2..c95ef081799 100644 --- a/variants/unphone9/pins_arduino.h +++ b/variants/unphone9/pins_arduino.h @@ -56,4 +56,13 @@ static const uint8_t T12 = 13; static const uint8_t T13 = 14; static const uint8_t T14 = 15; +static const uint8_t D5 = 14; +static const uint8_t D6 = 7; +static const uint8_t D9 = 15; +static const uint8_t D10 = 16; +static const uint8_t D11 = 17; +static const uint8_t D12 = 12; +static const uint8_t D13 = 13; +static const uint8_t D21 = 47; + #endif /* Pins_Arduino_h */ From 0c85934ba08357d2201f48529d6b56b99ffdaf7b Mon Sep 17 00:00:00 2001 From: Gareth Coleman Date: Mon, 29 Apr 2024 19:12:18 +0100 Subject: [PATCH 2/5] added macro flag to prevent redefinition --- variants/unphone9/pins_arduino.h | 1 + 1 file changed, 1 insertion(+) diff --git a/variants/unphone9/pins_arduino.h b/variants/unphone9/pins_arduino.h index c95ef081799..983feb2a556 100644 --- a/variants/unphone9/pins_arduino.h +++ b/variants/unphone9/pins_arduino.h @@ -64,5 +64,6 @@ static const uint8_t D11 = 17; static const uint8_t D12 = 12; static const uint8_t D13 = 13; static const uint8_t D21 = 47; +#define UNPHONE_D_PINS_MAPPED #endif /* Pins_Arduino_h */ From 55da09d5d9261d4508b82d2bb22c4d9dcea81c51 Mon Sep 17 00:00:00 2001 From: Unbinilium <15633984+Unbinilium@users.noreply.github.com> Date: Mon, 29 Apr 2024 23:14:22 +0800 Subject: [PATCH 3/5] fix(hal-uart): truncated tx/rx buffer size (uint16_t -> uint32_t) (#9554) --- cores/esp32/esp32-hal-uart.c | 4 ++-- cores/esp32/esp32-hal-uart.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/esp32/esp32-hal-uart.c b/cores/esp32/esp32-hal-uart.c index 91d3adea4f4..0aa5090b6bd 100644 --- a/cores/esp32/esp32-hal-uart.c +++ b/cores/esp32/esp32-hal-uart.c @@ -375,7 +375,7 @@ bool uartSetHwFlowCtrlMode(uart_t *uart, uart_hw_flowcontrol_t mode, uint8_t thr // This helper function will return true if a new IDF UART driver needs to be restarted and false if the current one can continue its execution bool _testUartBegin( - uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, + uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint32_t rx_buffer_size, uint32_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd ) { if (uart_nr >= SOC_UART_NUM) { @@ -397,7 +397,7 @@ bool _testUartBegin( } uart_t *uartBegin( - uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, + uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint32_t rx_buffer_size, uint32_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd ) { if (uart_nr >= SOC_UART_NUM) { diff --git a/cores/esp32/esp32-hal-uart.h b/cores/esp32/esp32-hal-uart.h index 1cd5411bf25..402b5785915 100644 --- a/cores/esp32/esp32-hal-uart.h +++ b/cores/esp32/esp32-hal-uart.h @@ -33,11 +33,11 @@ struct uart_struct_t; typedef struct uart_struct_t uart_t; bool _testUartBegin( - uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, + uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint32_t rx_buffer_size, uint32_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd ); uart_t *uartBegin( - uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint16_t rx_buffer_size, uint16_t tx_buffer_size, bool inverted, + uint8_t uart_nr, uint32_t baudrate, uint32_t config, int8_t rxPin, int8_t txPin, uint32_t rx_buffer_size, uint32_t tx_buffer_size, bool inverted, uint8_t rxfifo_full_thrhd ); void uartEnd(uint8_t uart_num); From ecbdb8cf60007547d37054799bd5512a3b30d36e Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 29 Apr 2024 12:15:40 -0300 Subject: [PATCH 4/5] feat (uart): change log level of UART events (#9563) Changes from Warning to Verbose UART errors/warnings in order to make debugging easier, specially with UART BREAK. --- cores/esp32/HardwareSerial.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 1fcb1531679..3d7c7068728 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -254,18 +254,18 @@ void HardwareSerial::_uartEventTask(void *args) { currentErr = UART_BUFFER_FULL_ERROR; break; case UART_BREAK: - log_w("UART%d RX break.", uart->_uart_nr); + log_v("UART%d RX break.", uart->_uart_nr); currentErr = UART_BREAK_ERROR; break; case UART_PARITY_ERR: - log_w("UART%d parity error.", uart->_uart_nr); + log_v("UART%d parity error.", uart->_uart_nr); currentErr = UART_PARITY_ERROR; break; case UART_FRAME_ERR: - log_w("UART%d frame error.", uart->_uart_nr); + log_v("UART%d frame error.", uart->_uart_nr); currentErr = UART_FRAME_ERROR; break; - default: log_w("UART%d unknown event type %d.", uart->_uart_nr, event.type); break; + default: log_v("UART%d unknown event type %d.", uart->_uart_nr, event.type); break; } if (currentErr != UART_NO_ERROR) { if (uart->_onReceiveErrorCB) { From 4c713625883760abe8b6c67904d4cb94241b74fc Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 29 Apr 2024 12:16:37 -0300 Subject: [PATCH 5/5] feat (hwcdc): ports changes made in 2.0.15 (#9565) * feat (hwcdc): ports changes made in 2.0.15 Ports many changes, fixes and improvements made in 2.0.15: - correct use of timeout - avoids problems with CDC ISR not reading data - fixes problems with transmitting many bytes to USB Host - changes how USB SOF and CDC connection is detected * feat (HWCDC) : port 2.0.15 Changed header for a few functions. * feat (HWCDC): port 2.0.15 upwards Fixes include file that is not necessary any more. - SOF is used directly now. * fix (HWCDC): removes left over Removes a left over function from previous 3.0.0 code. - just removing unused code. * ci(pre-commit): Apply automatic fixes * fix: typo and commentaries This fixes a few commentaries. Just a typo error. --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- cores/esp32/HWCDC.cpp | 257 ++++++++++++++++++++++++++---------------- cores/esp32/HWCDC.h | 6 +- 2 files changed, 162 insertions(+), 101 deletions(-) diff --git a/cores/esp32/HWCDC.cpp b/cores/esp32/HWCDC.cpp index 0b54b82d685..cd6ce46db55 100644 --- a/cores/esp32/HWCDC.cpp +++ b/cores/esp32/HWCDC.cpp @@ -29,7 +29,6 @@ #include "hal/usb_serial_jtag_ll.h" #pragma GCC diagnostic warning "-Wvolatile" #include "rom/ets_sys.h" -#include "driver/usb_serial_jtag.h" ESP_EVENT_DEFINE_BASE(ARDUINO_HW_CDC_EVENTS); @@ -40,8 +39,11 @@ static intr_handle_t intr_handle = NULL; static SemaphoreHandle_t tx_lock = NULL; static volatile bool connected = false; +static volatile unsigned long lastSOF_ms; +static volatile uint8_t SOF_TIMEOUT; + // timeout has no effect when USB CDC is unplugged -static uint32_t requested_tx_timeout_ms = 100; +static uint32_t tx_timeout_ms = 100; static esp_event_loop_handle_t arduino_hw_cdc_event_loop_handle = NULL; @@ -77,7 +79,7 @@ static void hw_cdc_isr_handler(void *arg) { if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY) { // Interrupt tells us the host picked up the data we sent. - if (!usb_serial_jtag_is_connected()) { + if (!HWCDC::isPlugged()) { connected = false; usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); // USB is unplugged, nothing to be done here @@ -132,19 +134,31 @@ static void hw_cdc_isr_handler(void *arg) { connected = false; } + if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_SOF) { + usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SOF); + lastSOF_ms = millis(); + } + if (xTaskWoken == pdTRUE) { portYIELD_FROM_ISR(); } } +inline bool HWCDC::isPlugged(void) { + return (lastSOF_ms + SOF_TIMEOUT) >= millis(); +} + bool HWCDC::isCDC_Connected() { static bool running = false; // USB may be unplugged - if (usb_serial_jtag_is_connected() == false) { + if (!isPlugged()) { connected = false; running = false; + SOF_TIMEOUT = 5; // SOF timeout when unplugged return false; + } else { + SOF_TIMEOUT = 50; // SOF timeout when plugged } if (connected) { @@ -155,21 +169,72 @@ bool HWCDC::isCDC_Connected() { if (running == false && !connected) { // enables it only once! usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); } + // this will feed CDC TX FIFO to trigger IN_EMPTY - uint8_t c = '\0'; - usb_serial_jtag_ll_write_txfifo(&c, sizeof(c)); usb_serial_jtag_ll_txfifo_flush(); running = true; return false; } +static void flushTXBuffer(const uint8_t *buffer, size_t size) { + if (!tx_ring_buf) { + return; + } + UBaseType_t uxItemsWaiting = 0; + vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); + size_t freeSpace = xRingbufferGetCurFreeSize(tx_ring_buf); + size_t ringbufferLength = freeSpace + uxItemsWaiting; + + if (buffer == NULL) { + // just flush the whole ring buffer and exit - used by HWCDC::flush() + size_t queued_size = 0; + uint8_t *queued_buff = (uint8_t *)xRingbufferReceiveUpTo(tx_ring_buf, &queued_size, 0, ringbufferLength); + if (queued_size && queued_buff != NULL) { + vRingbufferReturnItem(tx_ring_buf, (void *)queued_buff); + } + return; + } + if (size == 0) { + return; // nothing to do + } + if (freeSpace >= size) { + // there is enough space, just add the data to the ring buffer + if (xRingbufferSend(tx_ring_buf, (void *)buffer, size, 0) != pdTRUE) { + return; + } + } else { + // how many byte should be flushed to make space for the new data + size_t to_flush = size - freeSpace; + if (to_flush > ringbufferLength) { + to_flush = ringbufferLength; + } + size_t queued_size = 0; + uint8_t *queued_buff = (uint8_t *)xRingbufferReceiveUpTo(tx_ring_buf, &queued_size, 0, to_flush); + if (queued_size && queued_buff != NULL) { + vRingbufferReturnItem(tx_ring_buf, (void *)queued_buff); + } + // now add the new data that fits into the ring buffer + uint8_t *bptr = (uint8_t *)buffer; + if (size >= ringbufferLength) { + size = ringbufferLength; + bptr = (uint8_t *)buffer + (size - ringbufferLength); + } + if (xRingbufferSend(tx_ring_buf, (void *)bptr, size, 0) != pdTRUE) { + return; + } + } + // flushes CDC FIFO + usb_serial_jtag_ll_txfifo_flush(); +} + static void ARDUINO_ISR_ATTR cdc0_write_char(char c) { if (tx_ring_buf == NULL) { return; } - uint32_t tx_timeout_ms = 0; - if (HWCDC::isConnected()) { - tx_timeout_ms = requested_tx_timeout_ms; + if (!HWCDC::isConnected()) { + // just pop/push RingBuffer and apply FIFO policy + flushTXBuffer((const uint8_t *)&c, 1); + return; } if (xPortInIsrContext()) { xRingbufferSendFromISR(tx_ring_buf, (void *)(&c), 1, NULL); @@ -182,6 +247,8 @@ static void ARDUINO_ISR_ATTR cdc0_write_char(char c) { HWCDC::HWCDC() { perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DM, HWCDC::deinit); perimanSetBusDeinit(ESP32_BUS_TYPE_USB_DP, HWCDC::deinit); + lastSOF_ms = 0; + SOF_TIMEOUT = 5; } HWCDC::~HWCDC() { @@ -234,9 +301,9 @@ void HWCDC::begin(unsigned long baud) { log_e("HW CDC RX Buffer error"); } } - //TX Buffer default has 16 bytes if not preset + //TX Buffer default has 256 bytes if not preset if (tx_ring_buf == NULL) { - if (!setTxBufferSize(16)) { + if (!setTxBufferSize(256)) { log_e("HW CDC TX Buffer error"); } } @@ -265,7 +332,9 @@ void HWCDC::begin(unsigned long baud) { // Enable USB pad function USB_SERIAL_JTAG.conf0.usb_pad_enable = 1; usb_serial_jtag_ll_disable_intr_mask(USB_SERIAL_JTAG_LL_INTR_MASK); - usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET); + usb_serial_jtag_ll_ena_intr_mask( + USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT | USB_SERIAL_JTAG_INTR_BUS_RESET | USB_SERIAL_JTAG_INTR_SOF + ); if (!intr_handle && esp_intr_alloc(ETS_USB_SERIAL_JTAG_INTR_SOURCE, 0, hw_cdc_isr_handler, NULL, &intr_handle) != ESP_OK) { isr_log_e("HW USB CDC failed to init interrupts"); end(); @@ -300,7 +369,7 @@ void HWCDC::end() { } void HWCDC::setTxTimeoutMs(uint32_t timeout) { - requested_tx_timeout_ms = timeout; + tx_timeout_ms = timeout; } /* @@ -323,13 +392,9 @@ size_t HWCDC::setTxBufferSize(size_t tx_queue_len) { } int HWCDC::availableForWrite(void) { - uint32_t tx_timeout_ms = 0; if (tx_ring_buf == NULL || tx_lock == NULL) { return 0; } - if (HWCDC::isCDC_Connected()) { - tx_timeout_ms = requested_tx_timeout_ms; - } if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) { return 0; } @@ -338,76 +403,75 @@ int HWCDC::availableForWrite(void) { return a; } -static void flushTXBuffer() { - if (!tx_ring_buf) { - return; - } - UBaseType_t uxItemsWaiting = 0; - vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); - - size_t queued_size = 0; - uint8_t *queued_buff = (uint8_t *)xRingbufferReceiveUpTo(tx_ring_buf, &queued_size, 0, uxItemsWaiting); - if (queued_size && queued_buff != NULL) { - vRingbufferReturnItem(tx_ring_buf, (void *)queued_buff); - } - // flushes CDC FIFO - usb_serial_jtag_ll_txfifo_flush(); -} - size_t HWCDC::write(const uint8_t *buffer, size_t size) { - uint32_t tx_timeout_ms = 0; if (buffer == NULL || size == 0 || tx_ring_buf == NULL || tx_lock == NULL) { return 0; } - if (HWCDC::isCDC_Connected()) { - tx_timeout_ms = requested_tx_timeout_ms; - } else { - connected = false; - } if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) { return 0; } - size_t space = xRingbufferGetCurFreeSize(tx_ring_buf); - size_t to_send = size, so_far = 0; - - if (space > size) { - space = size; - } - // Non-Blocking method, Sending data to ringbuffer, and handle the data in ISR. - if (space > 0 && xRingbufferSend(tx_ring_buf, (void *)(buffer), space, 0) != pdTRUE) { - size = 0; + if (!isCDC_Connected()) { + // just pop/push RingBuffer and apply FIFO policy + flushTXBuffer(buffer, size); } else { - to_send -= space; - so_far += space; - // Now trigger the ISR to read data from the ring buffer. - usb_serial_jtag_ll_txfifo_flush(); - if (connected) { - usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - } + size_t space = xRingbufferGetCurFreeSize(tx_ring_buf); + size_t to_send = size, so_far = 0; - while (to_send) { - space = xRingbufferGetCurFreeSize(tx_ring_buf); - if (space > to_send) { - space = to_send; - } - // Blocking method, Sending data to ringbuffer, and handle the data in ISR. - if (xRingbufferSend(tx_ring_buf, (void *)(buffer + so_far), space, tx_timeout_ms / portTICK_PERIOD_MS) != pdTRUE) { - size = so_far; - break; - } - so_far += space; + if (space > size) { + space = size; + } + // Non-Blocking method, Sending data to ringbuffer, and handle the data in ISR. + if (space > 0 && xRingbufferSend(tx_ring_buf, (void *)(buffer), space, 0) != pdTRUE) { + size = 0; + } else { to_send -= space; + so_far += space; // Now trigger the ISR to read data from the ring buffer. usb_serial_jtag_ll_txfifo_flush(); if (connected) { usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); } + // tracks CDC trasmission progress to avoid hanging if CDC is unplugged while still sending data + size_t last_toSend = to_send; + uint32_t tries = tx_timeout_ms; // waits 1ms per sending data attempt, in case CDC is unplugged + while (connected && to_send) { + space = xRingbufferGetCurFreeSize(tx_ring_buf); + if (space > to_send) { + space = to_send; + } + // Blocking method, Sending data to ringbuffer, and handle the data in ISR. + if (xRingbufferSend(tx_ring_buf, (void *)(buffer + so_far), space, tx_timeout_ms / portTICK_PERIOD_MS) != pdTRUE) { + size = so_far; + log_w("write failed due to ring buffer full - timeout"); + break; + } + so_far += space; + to_send -= space; + // Now trigger the ISR to read data from the ring buffer. + usb_serial_jtag_ll_txfifo_flush(); + if (connected) { + usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); + } + if (last_toSend == to_send) { + // no progress in sending data... USB CDC is probably unplugged + tries--; + delay(1); + } else { + last_toSend = to_send; + tries = tx_timeout_ms; // reset the timeout + } + if (tries == 0) { // CDC isn't connected anymore... + size = so_far; + log_w("write failed due to waiting USB Host - timeout"); + connected = false; + } + } + } + // CDC was diconnected while sending data ==> flush the TX buffer keeping the last data + if (to_send && !usb_serial_jtag_ll_txfifo_writable()) { + connected = false; + flushTXBuffer(buffer + so_far, to_send); } - } - // CDC is disconnected ==> flush all data from TX buffer - if (to_send && !usb_serial_jtag_ll_txfifo_writable()) { - connected = false; - flushTXBuffer(); } xSemaphoreGive(tx_lock); return size; @@ -418,39 +482,40 @@ size_t HWCDC::write(uint8_t c) { } void HWCDC::flush(void) { - uint32_t tx_timeout_ms = 0; if (tx_ring_buf == NULL || tx_lock == NULL) { return; } - if (HWCDC::isCDC_Connected()) { - tx_timeout_ms = requested_tx_timeout_ms; - } else { - connected = false; - } if (xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS) { return; } - UBaseType_t uxItemsWaiting = 0; - vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); - if (uxItemsWaiting) { - // Now trigger the ISR to read data from the ring buffer. - usb_serial_jtag_ll_txfifo_flush(); - if (connected) { - usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); - } - } - uint8_t tries = 3; - while (tries && uxItemsWaiting) { - delay(5); - UBaseType_t lastUxItemsWaiting = uxItemsWaiting; + if (!isCDC_Connected()) { + flushTXBuffer(NULL, 0); + } else { + UBaseType_t uxItemsWaiting = 0; vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); - if (lastUxItemsWaiting == uxItemsWaiting) { - tries--; + if (uxItemsWaiting) { + // Now trigger the ISR to read data from the ring buffer. + usb_serial_jtag_ll_txfifo_flush(); + if (connected) { + usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); + } + } + uint32_t tries = tx_timeout_ms; // waits 1ms per ISR sending data attempt, in case CDC is unplugged + while (connected && tries && uxItemsWaiting) { + delay(1); + UBaseType_t lastUxItemsWaiting = uxItemsWaiting; + vRingbufferGetInfo(tx_ring_buf, NULL, NULL, NULL, NULL, &uxItemsWaiting); + if (lastUxItemsWaiting == uxItemsWaiting) { + tries--; + } + if (connected) { + usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY); + } + } + if (tries == 0) { // CDC isn't connected anymore... + connected = false; + flushTXBuffer(NULL, 0); // flushes all TX Buffer } - } - if (tries == 0) { // CDC isn't connected anymore... - connected = false; - flushTXBuffer(); } xSemaphoreGive(tx_lock); } diff --git a/cores/esp32/HWCDC.h b/cores/esp32/HWCDC.h index d2c73c832f1..ebfbf7c4d60 100644 --- a/cores/esp32/HWCDC.h +++ b/cores/esp32/HWCDC.h @@ -21,7 +21,6 @@ #include #include "esp_event.h" #include "Stream.h" -#include "driver/usb_serial_jtag.h" ESP_EVENT_DECLARE_BASE(ARDUINO_HW_CDC_EVENTS); @@ -70,10 +69,7 @@ class HWCDC : public Stream { size_t write(const uint8_t *buffer, size_t size); void flush(void); - inline static bool isPlugged(void) { - return usb_serial_jtag_is_connected(); - } - + static bool isPlugged(void); inline static bool isConnected(void) { return isCDC_Connected(); }