diff options
| -rw-r--r-- | examples/device/cdc_msc_hid/src/usb_descriptors.c | 5 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c | 5 | ||||
| -rw-r--r-- | examples/device/hid_generic_inout/src/usb_descriptors.c | 6 | ||||
| -rw-r--r-- | examples/device/midi_test/src/usb_descriptors.c | 5 | ||||
| -rw-r--r-- | examples/device/msc_dual_lun/src/usb_descriptors.c | 5 | ||||
| -rw-r--r-- | examples/device/webusb/src/main.c | 48 | ||||
| -rw-r--r-- | examples/device/webusb/src/tusb_config.h | 6 | ||||
| -rw-r--r-- | examples/device/webusb/src/usb_descriptors.c | 17 | ||||
| -rw-r--r-- | src/device/usbd.h | 25 |
9 files changed, 93 insertions, 29 deletions
diff --git a/examples/device/cdc_msc_hid/src/usb_descriptors.c b/examples/device/cdc_msc_hid/src/usb_descriptors.c index b06658c56..4220dc5fb 100644 --- a/examples/device/cdc_msc_hid/src/usb_descriptors.c +++ b/examples/device/cdc_msc_hid/src/usb_descriptors.c @@ -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 diff --git a/examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c b/examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c index 65c8cd712..4e1df9fb5 100644 --- a/examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c +++ b/examples/device/cdc_msc_hid_freertos/src/usb_descriptors.c @@ -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 diff --git a/examples/device/hid_generic_inout/src/usb_descriptors.c b/examples/device/hid_generic_inout/src/usb_descriptors.c index 516dab646..849c2be8a 100644 --- a/examples/device/hid_generic_inout/src/usb_descriptors.c +++ b/examples/device/hid_generic_inout/src/usb_descriptors.c @@ -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 diff --git a/examples/device/midi_test/src/usb_descriptors.c b/examples/device/midi_test/src/usb_descriptors.c index cffef0fb2..85cffffcc 100644 --- a/examples/device/midi_test/src/usb_descriptors.c +++ b/examples/device/midi_test/src/usb_descriptors.c @@ -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 diff --git a/examples/device/msc_dual_lun/src/usb_descriptors.c b/examples/device/msc_dual_lun/src/usb_descriptors.c index c4e171c06..585588a9c 100644 --- a/examples/device/msc_dual_lun/src/usb_descriptors.c +++ b/examples/device/msc_dual_lun/src/usb_descriptors.c @@ -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 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 diff --git a/examples/device/webusb/src/tusb_config.h b/examples/device/webusb/src/tusb_config.h index 37a988482..6c126a82f 100644 --- a/examples/device/webusb/src/tusb_config.h +++ b/examples/device/webusb/src/tusb_config.h @@ -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 diff --git a/examples/device/webusb/src/usb_descriptors.c b/examples/device/webusb/src/usb_descriptors.c index 188470eb5..3ea6f117f 100644 --- a/examples/device/webusb/src/usb_descriptors.c +++ b/examples/device/webusb/src/usb_descriptors.c @@ -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 diff --git a/src/device/usbd.h b/src/device/usbd.h index 8bd6adc35..943b1c79b 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -223,10 +223,31 @@ TU_ATTR_WEAK void tud_resume_cb(void); //------------- WebUSB -------------//
-#define TUD_WEBUSB_DESC_LEN
+// Descriptor Length
+#define TUD_BOS_WEBUSB_DESC_LEN 24
+
+// Vendor Code, iLandingPage
+#define TUD_BOS_WEBUSB_DESCRIPTOR(_vendor_code, _ipage) \
+ TUD_BOS_PLATFORM_DESCRIPTOR(TUD_BOS_WEBUSB_UUID, U16_TO_U8S_LE(0x0100), _vendor_code, _ipage)
+
+#define TUD_BOS_WEBUSB_UUID \
+ 0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47, \
+ 0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65
+
+#if 0
+//------------- Custom -------------//
+
+#define TUD_WEBUSB_DESC_LEN (9+7+7)
// Interface number, string index, EP Out & IN address, size & polling interval
-#define TUD_WEBUSB_DESCRIPTOR()
+#define TUD_WEBUSB_DESCRIPTOR(_itfnum, _stridx) \
+ /* Interface */\
+ 9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_VENDOR_SPECIFIC, 0x00, 0x00, _stridx,\
+ /* Endpoint Out */\
+ 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
+ /* Endpoint In */\
+ 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
+#endif
#ifdef __cplusplus
|
