From 8b9c0f6fd2cfbac919c9c77ac91780a74545ac37 Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 16 Jun 2018 14:08:28 +0700 Subject: [PATCH] add Custom Interface change interface descriptor --- lib/tinyusb | 2 +- src/make_common.mk | 9 +-- src/segger/nrf52840_bootloader.emProject | 4 ++ src/tusb_config.h | 2 + src/tusb_descriptors.c | 77 +++++++++++++++++------- src/tusb_descriptors.h | 18 +++++- 6 files changed, 83 insertions(+), 29 deletions(-) diff --git a/lib/tinyusb b/lib/tinyusb index 2b85a8f..5692b84 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 2b85a8fd460dd75cc12b11c9de137bf33f910cc7 +Subproject commit 5692b84ddf3326a3cde48b09f7123cd5ec0e93cc diff --git a/src/make_common.mk b/src/make_common.mk index c44596b..1871dbc 100644 --- a/src/make_common.mk +++ b/src/make_common.mk @@ -125,6 +125,7 @@ C_SOURCE_FILES += $(TUSB_PATH)/common/tusb_fifo.c C_SOURCE_FILES += $(TUSB_PATH)/device/usbd.c C_SOURCE_FILES += $(TUSB_PATH)/class/cdc/cdc_device.c C_SOURCE_FILES += $(TUSB_PATH)/class/msc/msc_device.c +C_SOURCE_FILES += $(TUSB_PATH)/class/custom/custom_device.c C_SOURCE_FILES += $(TUSB_PATH)/tusb.c #****************************************************************************** @@ -271,10 +272,10 @@ all: @echo Making Feather52840 board @echo ---------------------- @$(MAKE) -s -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e feather52840 - @$(MAKE) -s -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e clean - @echo Making Metro52 board - @echo -------------------- - @$(MAKE) -s -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e metro52 + #@$(MAKE) -s -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e clean + #@echo Making Metro52 board + #@echo -------------------- + #@$(MAKE) -s -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e metro52 #target for printing all targets help: diff --git a/src/segger/nrf52840_bootloader.emProject b/src/segger/nrf52840_bootloader.emProject index ddd1446..34e2412 100644 --- a/src/segger/nrf52840_bootloader.emProject +++ b/src/segger/nrf52840_bootloader.emProject @@ -185,6 +185,10 @@ + + + + diff --git a/src/tusb_config.h b/src/tusb_config.h index 0c3ffe5..d33efb8 100644 --- a/src/tusb_config.h +++ b/src/tusb_config.h @@ -67,6 +67,8 @@ #define CFG_TUD_MSC 1 #define CFG_TUD_CDC 1 +#define CFG_TUD_CUSTOM_CLASS 1 + /*------------------------------------------------------------------*/ /* CLASS DRIVER diff --git a/src/tusb_descriptors.c b/src/tusb_descriptors.c index 04a1f16..13f3ce0 100644 --- a/src/tusb_descriptors.c +++ b/src/tusb_descriptors.c @@ -82,7 +82,7 @@ app_descriptor_configuration_t const desc_configuration = .bConfigurationValue = 1, .iConfiguration = 0x00, .bmAttributes = TUSB_DESC_CONFIG_ATT_BUS_POWER, - .bMaxPower = TUSB_DESC_CONFIG_POWER_MA(500) + .bMaxPower = TUSB_DESC_CONFIG_POWER_MA(100) }, #if CFG_TUD_CDC @@ -114,7 +114,7 @@ app_descriptor_configuration_t const desc_configuration = .bInterfaceClass = TUSB_CLASS_CDC, .bInterfaceSubClass = CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, .bInterfaceProtocol = CDC_COMM_PROTOCOL_ATCOMMAND, - .iInterface = 0x00 + .iInterface = 0x04 }, .header = @@ -202,7 +202,7 @@ app_descriptor_configuration_t const desc_configuration = #if CFG_TUD_MSC .msc = { - .interface = + .itf = { .bLength = sizeof(tusb_desc_interface_t), .bDescriptorType = TUSB_DESC_INTERFACE, @@ -212,7 +212,7 @@ app_descriptor_configuration_t const desc_configuration = .bInterfaceClass = TUSB_CLASS_MSC, .bInterfaceSubClass = MSC_SUBCLASS_SCSI, .bInterfaceProtocol = MSC_PROTOCOL_BOT, - .iInterface = 0x07 + .iInterface = 0x05 }, .ep_out = @@ -234,6 +234,44 @@ app_descriptor_configuration_t const desc_configuration = .wMaxPacketSize = { .size = MSC_EDPT_SIZE}, .bInterval = 1 } + }, +#endif + +#if CFG_TUD_CUSTOM_CLASS + .cus = + { + .itf = + { + .bLength = sizeof(tusb_desc_interface_t), + .bDescriptorType = TUSB_DESC_INTERFACE, + .bInterfaceNumber = ITF_NUM_CUS, + .bAlternateSetting = 0x00, + .bNumEndpoints = 2, + .bInterfaceClass = TUSB_CLASS_VENDOR_SPECIFIC, + .bInterfaceSubClass = 0, + .bInterfaceProtocol = 0, + .iInterface = 0x06 + }, + + .ep_out = + { + .bLength = sizeof(tusb_desc_endpoint_t), + .bDescriptorType = TUSB_DESC_ENDPOINT, + .bEndpointAddress = CUS_EDPT_OUT, + .bmAttributes = { .xfer = TUSB_XFER_BULK }, + .wMaxPacketSize = { .size = CUS_EDPT_SIZE}, + .bInterval = 1 + }, + + .ep_in = + { + .bLength = sizeof(tusb_desc_endpoint_t), + .bDescriptorType = TUSB_DESC_ENDPOINT, + .bEndpointAddress = CUS_EDPT_IN, + .bmAttributes = { .xfer = TUSB_XFER_BULK }, + .wMaxPacketSize = { .size = CUS_EDPT_SIZE}, + .bInterval = 1 + } } #endif }; @@ -253,38 +291,33 @@ uint16_t const * const string_descriptor_arr [] = }, [1] = (uint16_t []) { // manufacturer - ENDIAN_BE16_FROM( STRING_LEN_UNICODE(11), TUSB_DESC_STRING), - 't', 'i', 'n', 'y', 'u', 's', 'b', '.', 'o', 'r', 'g' // len = 11 + ENDIAN_BE16_FROM( STRING_LEN_UNICODE(19), TUSB_DESC_STRING), + 'A','d','a','f','r','u','i','t',' ','I','n','d','u','s','t','r','i','e','s' }, [2] = (uint16_t []) { // product - ENDIAN_BE16_FROM( STRING_LEN_UNICODE(14), TUSB_DESC_STRING), - 't', 'i', 'n', 'y', 'u', 's', 'b', ' ', 'd', 'e', 'v', 'i', 'c', 'e' // len = 14 + ENDIAN_BE16_FROM( STRING_LEN_UNICODE(18), TUSB_DESC_STRING), + 'B','l','u','e','f','r','u','i','t',' ','n','R','F','5','2','8','4','0' }, - [3] = (uint16_t []) { // serials + [3] = (uint16_t []) { // serials TODO use chip ID ENDIAN_BE16_FROM( STRING_LEN_UNICODE(4), TUSB_DESC_STRING), '1', '2', '3', '4' // len = 4 }, [4] = (uint16_t []) { // CDC Interface - ENDIAN_BE16_FROM( STRING_LEN_UNICODE(3), TUSB_DESC_STRING), - 'c', 'd', 'c' // len = 3 + ENDIAN_BE16_FROM( STRING_LEN_UNICODE(16), TUSB_DESC_STRING), + 'B','l','u','e','f','r','u','i','t',' ','S','e','r','i','a','l' }, - [5] = (uint16_t []) { // Keyboard Interface - ENDIAN_BE16_FROM( STRING_LEN_UNICODE(5), TUSB_DESC_STRING), - 'm', 'o', 'u', 's', 'e' // len = 5 + [5] = (uint16_t []) { // MSC Interface + ENDIAN_BE16_FROM( STRING_LEN_UNICODE(17), TUSB_DESC_STRING), + 'B','l','u','e','f','r','u','i','t',' ','S','t','o','r','a','g','e' }, - [6] = (uint16_t []) { // Keyboard Interface - ENDIAN_BE16_FROM( STRING_LEN_UNICODE(8), TUSB_DESC_STRING), - 'k', 'e', 'y', 'b', 'o', 'a', 'r', 'd' // len = 8 - }, - - [7] = (uint16_t []) { // MSC Interface - ENDIAN_BE16_FROM( STRING_LEN_UNICODE(3), TUSB_DESC_STRING), - 'm', 's', 'c' // len = 3 + [6] = (uint16_t []) { // Custom Interface + ENDIAN_BE16_FROM( STRING_LEN_UNICODE(16), TUSB_DESC_STRING), + 'B','l','u','e','f','r','u','i','t',' ','C','u','s','t','o','m' } }; diff --git a/src/tusb_descriptors.h b/src/tusb_descriptors.h index 00aeee1..a4cdc6d 100644 --- a/src/tusb_descriptors.h +++ b/src/tusb_descriptors.h @@ -58,9 +58,10 @@ #define ITF_NUM_CDC 0 #define ITF_NUM_MSC 2 +#define ITF_NUM_CUS 3 // total number of interfaces -#define ITF_TOTAL (CFG_TUD_CDC*2 + CFG_TUD_MSC) +#define ITF_TOTAL (CFG_TUD_CDC*2 + CFG_TUD_MSC + CFG_TUD_CUSTOM_CLASS) //--------------------------------------------------------------------+ // Endpoints Address & Max Packet Size @@ -79,6 +80,10 @@ #define MSC_EDPT_IN EDPT_IN(3) #define MSC_EDPT_SIZE 64 +#define CUS_EDPT_OUT EDPT_OUT(4) +#define CUS_EDPT_IN EDPT_IN(4) +#define CUS_EDPT_SIZE 64 + //--------------------------------------------------------------------+ // CONFIGURATION DESCRIPTOR @@ -110,12 +115,21 @@ typedef struct ATTR_PACKED #if CFG_TUD_MSC struct ATTR_PACKED { - tusb_desc_interface_t interface; + tusb_desc_interface_t itf; tusb_desc_endpoint_t ep_out; tusb_desc_endpoint_t ep_in; }msc; #endif +#if CFG_TUD_CUSTOM_CLASS + struct ATTR_PACKED + { + tusb_desc_interface_t itf; + tusb_desc_endpoint_t ep_out; + tusb_desc_endpoint_t ep_in; + }cus; +#endif + } app_descriptor_configuration_t;