@@ -138,7 +138,7 @@ static void hw_cdc_isr_handler(void *arg) {
138
138
139
139
static void ARDUINO_ISR_ATTR cdc0_write_char (char c) {
140
140
uint32_t tx_timeout_ms = 0 ;
141
- if (usb_serial_jtag_is_connected ()) {
141
+ if (isCDC_Connected ()) {
142
142
tx_timeout_ms = requested_tx_timeout_ms;
143
143
}
144
144
if (xPortInIsrContext ()){
@@ -157,9 +157,7 @@ HWCDC::~HWCDC(){
157
157
end ();
158
158
}
159
159
160
-
161
- // It should return <true> just when USB is plugged and CDC is connected.
162
- HWCDC::operator bool () const
160
+ bool HWCDC::isCDC_Connected ()
163
161
{
164
162
static bool running = false ;
165
163
@@ -183,7 +181,13 @@ HWCDC::operator bool() const
183
181
usb_serial_jtag_ll_write_txfifo (&c, sizeof (c));
184
182
usb_serial_jtag_ll_txfifo_flush ();
185
183
running = true ;
186
- return false ;
184
+ return false ;
185
+ }
186
+
187
+ // It should return <true> just when USB is plugged and CDC is connected.
188
+ HWCDC::operator bool () const
189
+ {
190
+ return isCDC_Connected ();
187
191
}
188
192
189
193
void HWCDC::onEvent (esp_event_handler_t callback){
@@ -299,7 +303,7 @@ int HWCDC::availableForWrite(void)
299
303
if (tx_ring_buf == NULL || tx_lock == NULL ){
300
304
return 0 ;
301
305
}
302
- if (usb_serial_jtag_is_connected ()) {
306
+ if (isCDC_Connected ()) {
303
307
tx_timeout_ms = requested_tx_timeout_ms;
304
308
}
305
309
if (xSemaphoreTake (tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){
@@ -331,7 +335,7 @@ size_t HWCDC::write(const uint8_t *buffer, size_t size)
331
335
if (buffer == NULL || size == 0 || tx_ring_buf == NULL || tx_lock == NULL ){
332
336
return 0 ;
333
337
}
334
- if (usb_serial_jtag_is_connected ()) {
338
+ if (isCDC_Connected ()) {
335
339
tx_timeout_ms = requested_tx_timeout_ms;
336
340
} else {
337
341
isConnected = false ;
@@ -392,7 +396,7 @@ void HWCDC::flush(void)
392
396
if (tx_ring_buf == NULL || tx_lock == NULL ){
393
397
return ;
394
398
}
395
- if (usb_serial_jtag_is_connected ()) {
399
+ if (isCDC_Connected ()) {
396
400
tx_timeout_ms = requested_tx_timeout_ms;
397
401
} else {
398
402
isConnected = false ;
0 commit comments