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

@@ -124,10 +124,7 @@ enum
ITF_NUM_TOTAL
};
enum
{
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC*TUD_CDC_DESC_LEN + CFG_TUD_MSC*TUD_MSC_DESC_LEN + CFG_TUD_HID*TUD_HID_DESC_LEN
};
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_CDC*TUD_CDC_DESC_LEN + CFG_TUD_MSC*TUD_MSC_DESC_LEN + CFG_TUD_HID*TUD_HID_DESC_LEN)
#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number

View File

@@ -124,10 +124,7 @@ enum
ITF_NUM_TOTAL
};
enum
{
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + CFG_TUD_CDC*TUD_CDC_DESC_LEN + CFG_TUD_MSC*TUD_MSC_DESC_LEN + CFG_TUD_HID*TUD_HID_DESC_LEN
};
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + CFG_TUD_CDC*TUD_CDC_DESC_LEN + CFG_TUD_MSC*TUD_MSC_DESC_LEN + CFG_TUD_HID*TUD_HID_DESC_LEN)
#if CFG_TUSB_MCU == OPT_MCU_LPC175X_6X || CFG_TUSB_MCU == OPT_MCU_LPC177X_8X || CFG_TUSB_MCU == OPT_MCU_LPC40XX
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number

View File

@@ -92,10 +92,8 @@ enum
ITF_NUM_TOTAL
};
enum
{
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + TUD_HID_INOUT_DESC_LEN
};
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_HID_INOUT_DESC_LEN)
// Use Endpoint 2 instead of 1 due to NXP MCU
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number

View File

@@ -77,10 +77,7 @@ enum
ITF_NUM_TOTAL
};
enum
{
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + TUD_MIDI_DESC_LEN
};
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_MIDI_DESC_LEN)
// Use Endpoint 2 instead of 1 due to NXP MCU
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number

View File

@@ -75,10 +75,7 @@ enum
ITF_NUM_TOTAL
};
enum
{
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + TUD_MSC_DESC_LEN
};
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_MSC_DESC_LEN)
// Use Endpoint 2 instead of 1 due to NXP MCU
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number

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

View File

@@ -72,12 +72,16 @@
#define CFG_TUD_ENDOINT0_SIZE 64
//------------- CLASS -------------//
#define CFG_TUD_CDC 0
#define CFG_TUD_CDC 1
#define CFG_TUD_MSC 0
#define CFG_TUD_HID 0
#define CFG_TUD_MIDI 0
#define CFG_TUD_CUSTOM_CLASS 0
// CDC FIFO size of TX and RX
#define CFG_TUD_CDC_RX_BUFSIZE 64
#define CFG_TUD_CDC_TX_BUFSIZE 64
#ifdef __cplusplus
}
#endif

View File

@@ -41,7 +41,7 @@ tusb_desc_device_t const desc_device =
{
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0210, // at least 2.1 or 3.x
.bcdUSB = 0x0210, // at least 2.1 or 3.x for BOS & webUSB
// Use Interface Association Descriptor (IAD) for CDC
// As required by USB Specs IAD's subclass must be common class (2) and protocol must be IAD (1)
@@ -72,12 +72,21 @@ uint8_t const * tud_descriptor_device_cb(void)
// BOS Descriptor
//--------------------------------------------------------------------+
#define BOS_TOTAL_LEN (TUD_BOS_DESC_LEN + TUD_BOS_WEBUSB_DESC_LEN)
// BOS Descriptor is required for webUSB
uint8_t const desc_bos[] =
{
TUD_BOS_DESCRIPTOR(BOS_TOTAL_LEN, 1),
TUD_BOS_WEBUSB_DESCRIPTOR(0x01, 0)
};
uint8_t const * tud_descriptor_bos_cb(void)
{
return desc_bos;
}
//--------------------------------------------------------------------+
// Configuration Descriptor
//--------------------------------------------------------------------+
@@ -85,13 +94,11 @@ enum
{
ITF_NUM_CDC = 0,
ITF_NUM_CDC_DATA,
ITF_NUM_TOTAL
};
enum
{
CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN
};
#define CONFIG_TOTAL_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
// Use Endpoint 2 instead of 1 due to NXP MCU
// LPC 17xx and 40xx endpoint type (bulk/interrupt/iso) are fixed by its number