diff options
author | Joey Castillo <joeycastillo@utexas.edu> | 2022-05-08 20:19:20 -0400 |
---|---|---|
committer | Joey Castillo <joeycastillo@utexas.edu> | 2022-05-08 20:19:20 -0400 |
commit | 661e2b6a731da3b4b309b331bfbd40a29a69d7e9 (patch) | |
tree | 817515509e5e6e4d6c020d0a1042487b369dd43b /watch-library/hardware | |
parent | 838102a7e9ccfddf8f901def6cad35e66bf2d0fd (diff) | |
download | Sensor-Watch-661e2b6a731da3b4b309b331bfbd40a29a69d7e9.tar.gz Sensor-Watch-661e2b6a731da3b4b309b331bfbd40a29a69d7e9.tar.bz2 Sensor-Watch-661e2b6a731da3b4b309b331bfbd40a29a69d7e9.zip |
add ability to read from USB serial
Diffstat (limited to 'watch-library/hardware')
-rw-r--r-- | watch-library/hardware/watch/watch_private.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/watch-library/hardware/watch/watch_private.c b/watch-library/hardware/watch/watch_private.c index e4a03926..a0525d3c 100644 --- a/watch-library/hardware/watch/watch_private.c +++ b/watch-library/hardware/watch/watch_private.c @@ -255,8 +255,15 @@ int _write(int file, char *ptr, int len) { return 0; } -// this method could be overridden to read stuff from the USB console? but no need rn. -int _read(void) { +char buf[256] = {0}; + +int _read(int file, char *ptr, int len) { + (void)file; + int actual_length = strlen(buf); + if (actual_length) { + memcpy(ptr, buf, min(len, actual_length)); + return actual_length; + } return 0; } @@ -264,8 +271,18 @@ void USB_Handler(void) { tud_int_handler(0); } +static void cdc_task(void) { + if (tud_cdc_n_available(0)) { + tud_cdc_n_read(0, buf, sizeof(buf)); + } else { + memset(buf, 0, 64); + // buf[0] = 0; + } +} + void TC0_Handler(void) { tud_task(); + cdc_task(); TC0->COUNT8.INTFLAG.reg |= TC_INTFLAG_OVF; } |