From e09ebea7b99e3385bc1b1d326923b0a36003275d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20D=C3=BCmpelmann?= Date: Fri, 4 Sep 2020 17:25:32 +0200 Subject: [PATCH] Remove tud_cdc_connected check from examples --- examples/device/cdc_dual_ports/src/main.c | 15 ++++------ examples/device/cdc_msc/src/main.c | 31 ++++++++++----------- examples/device/cdc_msc_freertos/src/main.c | 31 ++++++++++----------- 3 files changed, 34 insertions(+), 43 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)); + + for(uint32_t i=0; i