updating webusb with cdc

This commit is contained in:
hathach
2019-07-12 19:38:04 +07:00
parent fdf39dd4ae
commit 2b7acd554a
9 changed files with 93 additions and 29 deletions

View File

@@ -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