diff options
| author | Jan Dümpelmann <[email protected]> | 2020-09-04 17:25:32 +0200 |
|---|---|---|
| committer | Jan Dümpelmann <[email protected]> | 2020-09-04 17:25:32 +0200 |
| commit | e09ebea7b99e3385bc1b1d326923b0a36003275d (patch) | |
| tree | 06977a6c14d86a3eaaf67d1e2e874b22368f3802 /examples | |
| parent | 9cc22b635c5c4b9426b1530c3623b899dc652302 (diff) | |
Remove tud_cdc_connected check from examples
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/device/cdc_dual_ports/src/main.c | 15 | ||||
| -rw-r--r-- | examples/device/cdc_msc/src/main.c | 29 | ||||
| -rw-r--r-- | examples/device/cdc_msc_freertos/src/main.c | 29 |
3 files changed, 32 insertions, 41 deletions
diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c index d6e38df85..813639179 100644 --- a/examples/device/cdc_dual_ports/src/main.c +++ b/examples/device/cdc_dual_ports/src/main.c @@ -83,18 +83,15 @@ static void cdc_task(void) for (itf = 0; itf < CFG_TUD_CDC; itf++) { - if ( tud_cdc_n_connected(itf) ) + if ( tud_cdc_n_available(itf) ) { - if ( tud_cdc_n_available(itf) ) - { - uint8_t buf[64]; + uint8_t buf[64]; - uint32_t count = tud_cdc_n_read(itf, buf, sizeof(buf)); + uint32_t count = tud_cdc_n_read(itf, buf, sizeof(buf)); - // echo back to both serial ports - echo_serial_port(0, buf, count); - echo_serial_port(1, buf, count); - } + // echo back to both serial ports + echo_serial_port(0, buf, count); + echo_serial_port(1, buf, count); } } } diff --git a/examples/device/cdc_msc/src/main.c b/examples/device/cdc_msc/src/main.c index a407e2ddd..bcf05eaac 100644 --- a/examples/device/cdc_msc/src/main.c +++ b/examples/device/cdc_msc/src/main.c @@ -105,34 +105,31 @@ void tud_resume_cb(void) //--------------------------------------------------------------------+ void cdc_task(void) { - if ( tud_cdc_connected() ) + // is data available to read from rx fifo + if ( tud_cdc_available() ) { - // connected and there are data available - if ( tud_cdc_available() ) - { - uint8_t buf[64]; - - // read and echo back - uint32_t count = tud_cdc_read(buf, sizeof(buf)); + uint8_t buf[64]; - for(uint32_t i=0; i<count; i++) - { - tud_cdc_write_char(buf[i]); + // read and echo back + uint32_t count = tud_cdc_read(buf, sizeof(buf)); - if ( buf[i] == '\r' ) tud_cdc_write_char('\n'); - } + for(uint32_t i=0; i<count; i++) + { + tud_cdc_write_char(buf[i]); - tud_cdc_write_flush(); + if ( buf[i] == '\r' ) tud_cdc_write_char('\n'); } + + tud_cdc_write_flush(); } } -// Invoked when cdc when line state changed e.g connected/disconnected +// Invoked when cdc line state changed e.g connected/disconnected void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { (void) itf; - // connected + // usually terminal software sets DTR and RTS when connected if ( dtr && rts ) { // print initial message when connected diff --git a/examples/device/cdc_msc_freertos/src/main.c b/examples/device/cdc_msc_freertos/src/main.c index 1371b84c3..712255880 100644 --- a/examples/device/cdc_msc_freertos/src/main.c +++ b/examples/device/cdc_msc_freertos/src/main.c @@ -168,25 +168,22 @@ void cdc_task(void* params) // RTOS forever loop while ( 1 ) { - if ( tud_cdc_connected() ) + // is data available to read from rx fifo + if ( tud_cdc_available() ) { - // connected and there are data available - if ( tud_cdc_available() ) - { - uint8_t buf[64]; - - // read and echo back - uint32_t count = tud_cdc_read(buf, sizeof(buf)); + uint8_t buf[64]; - for(uint32_t i=0; i<count; i++) - { - tud_cdc_write_char(buf[i]); + // read and echo back + uint32_t count = tud_cdc_read(buf, sizeof(buf)); - if ( buf[i] == '\r' ) tud_cdc_write_char('\n'); - } + for(uint32_t i=0; i<count; i++) + { + tud_cdc_write_char(buf[i]); - tud_cdc_write_flush(); + if ( buf[i] == '\r' ) tud_cdc_write_char('\n'); } + + tud_cdc_write_flush(); } // For ESP32-S2 this delay is essential to allow idle how to run and reset wdt @@ -194,12 +191,12 @@ void cdc_task(void* params) } } -// Invoked when cdc when line state changed e.g connected/disconnected +// Invoked when cdc line state changed e.g connected/disconnected void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) { (void) itf; - // connected + // usually terminal software sets DTR and RTS when connected if ( dtr && rts ) { // print initial message when connected |
