Skip to content

Commit c985a0b

Browse files
robert-hhdpgeorge
authored andcommitted
nrf/drivers/usb: Add a tud_cdc_rx_cb() callback to check interrupt char.
1 parent 60539ea commit c985a0b

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

ports/nrf/drivers/usb/usb_cdc.c

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
extern void tusb_hal_nrf_power_event(uint32_t event);
4848

49-
static void cdc_task(void);
49+
static void cdc_task(bool tx);
5050

5151
static uint8_t rx_ringbuf_array[1024];
5252
static uint8_t tx_ringbuf_array[1024];
@@ -121,7 +121,7 @@ static int cdc_tx_char(void) {
121121
return ringbuf_get((ringbuf_t*)&tx_ringbuf);
122122
}
123123

124-
static void cdc_task(void)
124+
static void cdc_task(bool tx)
125125
{
126126
if ( tud_cdc_connected() ) {
127127
// connected and there are data available
@@ -138,24 +138,30 @@ static void cdc_task(void)
138138
}
139139
}
140140

141-
int chars = 0;
142-
while (cdc_tx_any()) {
143-
if (chars < 64) {
144-
tud_cdc_write_char(cdc_tx_char());
145-
chars++;
146-
} else {
147-
chars = 0;
148-
tud_cdc_write_flush();
141+
if (tx) {
142+
int chars = 0;
143+
while (cdc_tx_any()) {
144+
if (chars < 64) {
145+
tud_cdc_write_char(cdc_tx_char());
146+
chars++;
147+
} else {
148+
chars = 0;
149+
tud_cdc_write_flush();
150+
}
149151
}
150-
}
151152

152-
tud_cdc_write_flush();
153+
tud_cdc_write_flush();
154+
}
153155
}
154156
}
155157

156158
static void usb_cdc_loop(void) {
157159
tud_task();
158-
cdc_task();
160+
cdc_task(true);
161+
}
162+
163+
void tud_cdc_rx_cb(uint8_t itf) {
164+
cdc_task(false);
159165
}
160166

161167
int usb_cdc_init(void)

0 commit comments

Comments
 (0)