diff options
| author | hathach <[email protected]> | 2020-01-11 12:59:02 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2020-01-11 12:59:02 +0700 |
| commit | 08da3e80b7d93c31ee0b679bcb9d05722abfe182 (patch) | |
| tree | 2a6331bcecc77d26cfec4730589c1958fdefd3ec | |
| parent | 242a2b6126f00cb3d8ffe6bf6245f801709910ed (diff) | |
echo to both serial at once
| -rw-r--r-- | examples/device/cdc_dual_ports/src/main.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/examples/device/cdc_dual_ports/src/main.c b/examples/device/cdc_dual_ports/src/main.c index 87e66b95e..d6e38df85 100644 --- a/examples/device/cdc_dual_ports/src/main.c +++ b/examples/device/cdc_dual_ports/src/main.c @@ -50,7 +50,9 @@ int main(void) return 0; } -static void echo_all(uint8_t itf, uint8_t buf[], uint32_t count) +// echo to either Serial0 or Serial1 +// with Serial0 as all lower case, Serial1 as all upper case +static void echo_serial_port(uint8_t itf, uint8_t buf[], uint32_t count) { for(uint32_t i=0; i<count; i++) { @@ -64,7 +66,7 @@ static void echo_all(uint8_t itf, uint8_t buf[], uint32_t count) // echo back additional ports as upper case if (islower(buf[i])) buf[i] -= 'a' - 'A'; } - + tud_cdc_n_write_char(itf, buf[i]); if ( buf[i] == '\r' ) tud_cdc_n_write_char(itf, '\n'); @@ -89,8 +91,9 @@ static void cdc_task(void) uint32_t count = tud_cdc_n_read(itf, buf, sizeof(buf)); - // echo back to cdc - echo_all(itf, buf, count); + // echo back to both serial ports + echo_serial_port(0, buf, count); + echo_serial_port(1, buf, count); } } } |
