diff options
| author | hathach <[email protected]> | 2022-12-21 11:47:07 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2022-12-21 11:47:07 +0700 |
| commit | b3e63c335af9345e505575e5bc8ba0281ac73692 (patch) | |
| tree | de6a372a540ea2246b05b11dd27762efeacf4348 /examples | |
| parent | cb2af4c0bc096e57c3486945eda43dbc26b3829a (diff) | |
updat cdc host app
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/host/cdc_msc_hid/src/cdc_app.c | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/examples/host/cdc_msc_hid/src/cdc_app.c b/examples/host/cdc_msc_hid/src/cdc_app.c index 29da02abc..123cb33f0 100644 --- a/examples/host/cdc_msc_hid/src/cdc_app.c +++ b/examples/host/cdc_msc_hid/src/cdc_app.c @@ -25,6 +25,7 @@ */ #include "tusb.h" +#include "bsp/board.h" //--------------------------------------------------------------------+ // MACRO TYPEDEF CONSTANT ENUM DECLARATION @@ -33,19 +34,61 @@ //------------- IMPLEMENTATION -------------// +size_t get_console_inputs(uint8_t* buf, size_t bufsize) +{ + size_t count = 0; + while (count < bufsize) + { + int ch = board_getchar(); + if ( ch <= 0 ) break; + + buf[count] = (uint8_t) ch; + count++; + } + + return count; +} + void cdc_app_task(void) { + uint8_t buf[64+1]; // +1 for extra null character + memset(buf, 0, sizeof(buf)); + size_t count = get_console_inputs(buf, sizeof(buf)-1); + + // loop over all mounted interfaces + for(size_t idx=0; idx<CFG_TUH_CDC; idx++) + { + if ( tuh_cdc_mounted(idx) ) + { + // console --> cdc interfaces + if (count) + { + tuh_cdc_write(idx, buf, count); + tuh_cdc_write_flush(idx); + } + + // cdc interfaces -> console + if ( tuh_cdc_read_available(idx) ) + { + printf((char*) buf); + } + } + } } -void tuh_cdc_mount_cb(uint8_t dev_addr) +void tuh_cdc_mount_cb(uint8_t idx) { - (void) dev_addr; - printf("A CDC device is mounted\r\n"); + tuh_cdc_itf_info_t itf_info; + tuh_cdc_itf_get_info(idx, &itf_info); + + printf("CDC Interface is mounted: device address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.bInterfaceNumber); } -void tuh_cdc_umount_cb(uint8_t dev_addr) +void tuh_cdc_umount_cb(uint8_t idx) { - (void) dev_addr; - printf("A CDC device is unmounted\r\n"); + tuh_cdc_itf_info_t itf_info; + tuh_cdc_itf_get_info(idx, &itf_info); + + printf("CDC Interface is unmounted: device address = %u, itf_num = %u\r\n", itf_info.daddr, itf_info.bInterfaceNumber); } |
