diff options
| author | hathach <[email protected]> | 2022-12-21 12:47:00 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2022-12-21 12:47:00 +0700 |
| commit | 84a483f5ea7446a5cc1a9fe957379dd1f0a6fd4c (patch) | |
| tree | 1fd1e9a96ec3fc6a259b08a1ffa5dcee6d315d6e /examples | |
| parent | edc559cb4d9c0c940387b514f2e66c4a2f3a9c1c (diff) | |
add more host cdc API
tuh_cdc_write_available(), tuh_cdc_read_flush(), tuh_cdc_rx_cb()
callback
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/host/cdc_msc_hid/src/cdc_app.c | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/examples/host/cdc_msc_hid/src/cdc_app.c b/examples/host/cdc_msc_hid/src/cdc_app.c index db652efde..23ea05b2b 100644 --- a/examples/host/cdc_msc_hid/src/cdc_app.c +++ b/examples/host/cdc_msc_hid/src/cdc_app.c @@ -54,8 +54,8 @@ void cdc_app_task(void) uint8_t buf[64+1]; // +1 for extra null character uint32_t const bufsize = sizeof(buf)-1; - uint32_t console_count = get_console_inputs(buf, bufsize); - buf[console_count] = 0; + uint32_t count = get_console_inputs(buf, bufsize); + buf[count] = 0; // loop over all mounted interfaces for(uint8_t idx=0; idx<CFG_TUH_CDC; idx++) @@ -63,25 +63,28 @@ void cdc_app_task(void) if ( tuh_cdc_mounted(idx) ) { // console --> cdc interfaces - if (console_count) + if (count) { - tuh_cdc_write(idx, buf, console_count); + tuh_cdc_write(idx, buf, count); tuh_cdc_write_flush(idx); } - - // cdc interfaces -> console - if ( tuh_cdc_read_available(idx) ) - { - uint8_t buf_cdc[64+1]; - uint32_t cdc_count = tuh_cdc_read(idx, buf_cdc, sizeof(buf_cdc)-1); - buf_cdc[cdc_count] = 0; - - printf((char*) buf_cdc); - } } } } +// Invoked when received new data +void tuh_cdc_rx_cb(uint8_t idx) +{ + uint8_t buf[64+1]; // +1 for extra null character + uint32_t const bufsize = sizeof(buf)-1; + + // forward cdc interfaces -> console + uint32_t count = tuh_cdc_read(idx, buf, bufsize); + buf[count] = 0; + + printf((char*) buf); +} + void tuh_cdc_mount_cb(uint8_t idx) { tuh_cdc_itf_info_t itf_info; |
