summaryrefslogtreecommitdiff
path: root/examples/device/webusb/src/main.c
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-07-12 19:38:04 +0700
committerhathach <[email protected]>2019-07-12 19:38:04 +0700
commit2b7acd554a00f196394fdb91cd11a18e7981949f (patch)
tree825cc8a6d1eb87aa11766cda4d98d3be6b1c9f56 /examples/device/webusb/src/main.c
parentfdf39dd4aee82dc63d94a5a4e9423ecc15a268a1 (diff)
updating webusb with cdc
Diffstat (limited to 'examples/device/webusb/src/main.c')
-rw-r--r--examples/device/webusb/src/main.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/examples/device/webusb/src/main.c b/examples/device/webusb/src/main.c
index 6d96eba0b..59e934930 100644
--- a/examples/device/webusb/src/main.c
+++ b/examples/device/webusb/src/main.c
@@ -54,7 +54,7 @@ enum {
static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED;
void led_blinking_task(void);
-void midi_task(void);
+void cdc_task(void);
/*------------- MAIN -------------*/
int main(void)
@@ -66,6 +66,7 @@ int main(void)
while (1)
{
tud_task(); // tinyusb device task
+ cdc_task();
led_blinking_task();
}
@@ -108,6 +109,51 @@ void tud_resume_cb(void)
//--------------------------------------------------------------------+
+//--------------------------------------------------------------------+
+// USB CDC
+//--------------------------------------------------------------------+
+void cdc_task(void)
+{
+ if ( tud_cdc_connected() )
+ {
+ // 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<count; i++)
+ {
+ tud_cdc_write_char(buf[i]);
+
+ if ( buf[i] == '\r' ) tud_cdc_write_char('\n');
+ }
+
+ tud_cdc_write_flush();
+ }
+ }
+}
+
+// Invoked when cdc when line state changed e.g connected/disconnected
+void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts)
+{
+ (void) itf;
+
+ // connected
+ if ( dtr && rts )
+ {
+ // print initial message when connected
+ tud_cdc_write_str("\r\nTinyUSB CDC MSC HID device example\r\n");
+ }
+}
+
+// Invoked when CDC interface received data from host
+void tud_cdc_rx_cb(uint8_t itf)
+{
+ (void) itf;
+}
//--------------------------------------------------------------------+
// BLINKING TASK