Skip to content

Commit 76e28e8

Browse files
authored
fixes api declaration
1 parent d7bca83 commit 76e28e8

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

Diff for: cores/esp32/HWCDC.cpp

+42-42
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static QueueHandle_t rx_queue = NULL;
3737
static uint8_t rx_data_buf[64] = {0};
3838
static intr_handle_t intr_handle = NULL;
3939
static SemaphoreHandle_t tx_lock = NULL;
40-
static volatile bool isConnected = false;
40+
static volatile bool connected = false;
4141

4242
// timeout has no effect when USB CDC is unplugged
4343
static uint32_t requested_tx_timeout_ms = 100;
@@ -79,12 +79,12 @@ static void hw_cdc_isr_handler(void *arg) {
7979
if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY) {
8080
// Interrupt tells us the host picked up the data we sent.
8181
if(!usb_serial_jtag_is_connected()) {
82-
isConnected = false;
82+
connected = false;
8383
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
8484
// USB is unplugged, nothing to be done here
8585
return;
8686
} else {
87-
isConnected = true;
87+
connected = true;
8888
}
8989
if (usb_serial_jtag_ll_txfifo_writable() == 1) {
9090
// We disable the interrupt here so that the interrupt won't be triggered if there is no data to send.
@@ -98,7 +98,7 @@ static void hw_cdc_isr_handler(void *arg) {
9898
usb_serial_jtag_ll_write_txfifo(queued_buff, queued_size);
9999
usb_serial_jtag_ll_txfifo_flush();
100100
vRingbufferReturnItemFromISR(tx_ring_buf, queued_buff, &xTaskWoken);
101-
if(isConnected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
101+
if(connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
102102
//send event?
103103
//ets_printf("TX:%u\n", queued_size);
104104
event.tx.len = queued_size;
@@ -122,58 +122,37 @@ static void hw_cdc_isr_handler(void *arg) {
122122
}
123123
event.rx.len = i;
124124
arduino_hw_cdc_event_post(ARDUINO_HW_CDC_EVENTS, ARDUINO_HW_CDC_RX_EVENT, &event, sizeof(arduino_hw_cdc_event_data_t), &xTaskWoken);
125-
isConnected = true;
125+
connected = true;
126126
}
127127

128128
if (usbjtag_intr_status & USB_SERIAL_JTAG_INTR_BUS_RESET) {
129129
usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_BUS_RESET);
130130
arduino_hw_cdc_event_post(ARDUINO_HW_CDC_EVENTS, ARDUINO_HW_CDC_BUS_RESET_EVENT, &event, sizeof(arduino_hw_cdc_event_data_t), &xTaskWoken);
131-
isConnected = false;
131+
connected = false;
132132
}
133133

134134
if (xTaskWoken == pdTRUE) {
135135
portYIELD_FROM_ISR();
136136
}
137137
}
138138

139-
static void ARDUINO_ISR_ATTR cdc0_write_char(char c) {
140-
uint32_t tx_timeout_ms = 0;
141-
if(isCDC_Connected()) {
142-
tx_timeout_ms = requested_tx_timeout_ms;
143-
}
144-
if(xPortInIsrContext()){
145-
xRingbufferSendFromISR(tx_ring_buf, (void*) (&c), 1, NULL);
146-
} else {
147-
xRingbufferSend(tx_ring_buf, (void*) (&c), 1, tx_timeout_ms / portTICK_PERIOD_MS);
148-
}
149-
usb_serial_jtag_ll_txfifo_flush();
150-
}
151-
152-
HWCDC::HWCDC() {
153-
154-
}
155-
156-
HWCDC::~HWCDC(){
157-
end();
158-
}
159-
160139
bool HWCDC::isCDC_Connected()
161140
{
162141
static bool running = false;
163142

164143
// USB may be unplugged
165144
if (usb_serial_jtag_is_connected() == false) {
166-
isConnected = false;
145+
connected = false;
167146
running = false;
168147
return false;
169148
}
170149

171-
if (isConnected) {
150+
if (connected) {
172151
running = false;
173152
return true;
174153
}
175154

176-
if (running == false && !isConnected) { // enables it only once!
155+
if (running == false && !connected) { // enables it only once!
177156
usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
178157
}
179158
// this will feed CDC TX FIFO to trigger IN_EMPTY
@@ -184,10 +163,31 @@ bool HWCDC::isCDC_Connected()
184163
return false;
185164
}
186165

166+
static void ARDUINO_ISR_ATTR cdc0_write_char(char c) {
167+
uint32_t tx_timeout_ms = 0;
168+
if(HWCDC::isConnected()) {
169+
tx_timeout_ms = requested_tx_timeout_ms;
170+
}
171+
if(xPortInIsrContext()){
172+
xRingbufferSendFromISR(tx_ring_buf, (void*) (&c), 1, NULL);
173+
} else {
174+
xRingbufferSend(tx_ring_buf, (void*) (&c), 1, tx_timeout_ms / portTICK_PERIOD_MS);
175+
}
176+
usb_serial_jtag_ll_txfifo_flush();
177+
}
178+
179+
HWCDC::HWCDC() {
180+
181+
}
182+
183+
HWCDC::~HWCDC(){
184+
end();
185+
}
186+
187187
// It should return <true> just when USB is plugged and CDC is connected.
188188
HWCDC::operator bool() const
189189
{
190-
return isCDC_Connected();
190+
return HWCDC::isCDC_Connected();
191191
}
192192

193193
void HWCDC::onEvent(esp_event_handler_t callback){
@@ -271,7 +271,7 @@ void HWCDC::end()
271271
arduino_hw_cdc_event_loop_handle = NULL;
272272
}
273273
HWCDC::deinit(this);
274-
isConnected = false;
274+
connected = false;
275275
}
276276

277277
void HWCDC::setTxTimeoutMs(uint32_t timeout){
@@ -303,7 +303,7 @@ int HWCDC::availableForWrite(void)
303303
if(tx_ring_buf == NULL || tx_lock == NULL){
304304
return 0;
305305
}
306-
if(isCDC_Connected()) {
306+
if(HWCDC::isCDC_Connected()) {
307307
tx_timeout_ms = requested_tx_timeout_ms;
308308
}
309309
if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){
@@ -335,10 +335,10 @@ size_t HWCDC::write(const uint8_t *buffer, size_t size)
335335
if(buffer == NULL || size == 0 || tx_ring_buf == NULL || tx_lock == NULL){
336336
return 0;
337337
}
338-
if(isCDC_Connected()) {
338+
if(HWCDC::isCDC_Connected()) {
339339
tx_timeout_ms = requested_tx_timeout_ms;
340340
} else {
341-
isConnected = false;
341+
connected = false;
342342
}
343343
if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){
344344
return 0;
@@ -358,7 +358,7 @@ size_t HWCDC::write(const uint8_t *buffer, size_t size)
358358
so_far += space;
359359
// Now trigger the ISR to read data from the ring buffer.
360360
usb_serial_jtag_ll_txfifo_flush();
361-
if(isConnected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
361+
if(connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
362362

363363
while(to_send){
364364
if(max_size > to_send){
@@ -373,12 +373,12 @@ size_t HWCDC::write(const uint8_t *buffer, size_t size)
373373
to_send -= max_size;
374374
// Now trigger the ISR to read data from the ring buffer.
375375
usb_serial_jtag_ll_txfifo_flush();
376-
if(isConnected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
376+
if(connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
377377
}
378378
}
379379
// CDC is diconnected ==> flush all data from TX buffer
380380
if(to_send && !usb_serial_jtag_ll_txfifo_writable()) {
381-
isConnected = false;
381+
connected = false;
382382
flushTXBuffer();
383383
}
384384
xSemaphoreGive(tx_lock);
@@ -396,10 +396,10 @@ void HWCDC::flush(void)
396396
if(tx_ring_buf == NULL || tx_lock == NULL){
397397
return;
398398
}
399-
if(isCDC_Connected()) {
399+
if(HWCDC::isCDC_Connected()) {
400400
tx_timeout_ms = requested_tx_timeout_ms;
401401
} else {
402-
isConnected = false;
402+
connected = false;
403403
}
404404
if(xSemaphoreTake(tx_lock, tx_timeout_ms / portTICK_PERIOD_MS) != pdPASS){
405405
return;
@@ -409,7 +409,7 @@ void HWCDC::flush(void)
409409
if(uxItemsWaiting){
410410
// Now trigger the ISR to read data from the ring buffer.
411411
usb_serial_jtag_ll_txfifo_flush();
412-
if(isConnected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
412+
if(connected) usb_serial_jtag_ll_ena_intr_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY);
413413
}
414414
uint8_t tries = 3;
415415
while(tries && uxItemsWaiting){
@@ -419,7 +419,7 @@ void HWCDC::flush(void)
419419
if (lastUxItemsWaiting == uxItemsWaiting) tries--;
420420
}
421421
if (tries == 0) { // CDC isn't connected anymore...
422-
isConnected = false;
422+
connected = false;
423423
flushTXBuffer();
424424
}
425425
xSemaphoreGive(tx_lock);

0 commit comments

Comments
 (0)