1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 17:32:44 +01:00

pkg/tinyusb: add DFU and DFU_RT to descriptors

This commit is contained in:
Gunar Schorcht 2022-11-24 15:01:17 +01:00
parent c254dc35fd
commit 7fa58f74dd
2 changed files with 89 additions and 3 deletions

View File

@ -41,6 +41,12 @@ enum {
TUSBD_ITF_CDC_1, /**< CDC1 Notification interface */ TUSBD_ITF_CDC_1, /**< CDC1 Notification interface */
TUSBD_ITF_CDC_1_DATA, /**< CDC1 Data interface */ TUSBD_ITF_CDC_1_DATA, /**< CDC1 Data interface */
#endif #endif
#if CONFIG_TUSBD_DFU_NUMOF
TUSBD_ITF_DFU, /**< DFU interface */
#endif
#if CONFIG_TUSBD_DFU_RT_NUMOF
TUSBD_ITF_DFU_RT, /**< DFU Runtime interface */
#endif
#if CONFIG_TUSBD_HID_NUMOF > 0 #if CONFIG_TUSBD_HID_NUMOF > 0
TUSBD_ITF_HID_0, /**< HID0 interface */ TUSBD_ITF_HID_0, /**< HID0 interface */
#endif #endif
@ -101,6 +107,13 @@ enum {
#if CONFIG_TUSBD_CDC_NUMOF > 1 #if CONFIG_TUSBD_CDC_NUMOF > 1
TUSBD_STR_IDX_CDC_1, TUSBD_STR_IDX_CDC_1,
#endif #endif
#if CONFIG_TUSBD_DFU_NUMOF
TUSBD_STR_IDX_DFU_SLOT_0,
TUSBD_STR_IDX_DFU_SLOT_1,
#endif
#if CONFIG_TUSBD_DFU_RT_NUMOF
TUSBD_STR_IDX_DFU_RT,
#endif
#if CONFIG_TUSBD_HID_NUMOF > 0 #if CONFIG_TUSBD_HID_NUMOF > 0
TUSBD_STR_IDX_HID_0, TUSBD_STR_IDX_HID_0,
#endif #endif
@ -117,9 +130,14 @@ enum {
}; };
#endif /* !defined(HAVE_TUSBD_STR_IDX_TYPE) */ #endif /* !defined(HAVE_TUSBD_STR_IDX_TYPE) */
/* only two slots are supported */
#define CONFIG_TUSBD_DFU_ALT_NUMOF 2
#if !defined(TUSBD_DESC_TOTAL_LEN) #if !defined(TUSBD_DESC_TOTAL_LEN)
#define TUSBD_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \ #define TUSBD_DESC_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \
(CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \ (CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \
(CONFIG_TUSBD_DFU_NUMOF * TUD_DFU_DESC_LEN(CONFIG_TUSBD_DFU_ALT_NUMOF)) + \
(CONFIG_TUSBD_DFU_RT_NUMOF * TUD_DFU_RT_DESC_LEN) + \
(CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \ (CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \
(CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \ (CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN)) (CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN))
@ -127,6 +145,8 @@ enum {
#define TUSBD_DESC_ALT_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \ #define TUSBD_DESC_ALT_TOTAL_LEN (TUD_CONFIG_DESC_LEN + \
(CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \ (CONFIG_TUSBD_CDC_NUMOF * TUD_CDC_DESC_LEN) + \
(CONFIG_TUSBD_DFU_NUMOF * TUD_DFU_DESC_LEN(CONFIG_TUSBD_DFU_ALT_NUMOF)) + \
(CONFIG_TUSBD_DFU_RT_NUMOF * TUD_DFU_RT_DESC_LEN) + \
(CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \ (CONFIG_TUSBD_HID_NUMOF * TUD_HID_INOUT_DESC_LEN) + \
(CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \ (CONFIG_TUSBD_MSC_NUMOF * TUD_MSC_DESC_LEN) + \
(CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN)) (CONFIG_TUSBD_VENDOR_NUMOF * TUD_VENDOR_DESC_LEN))

View File

@ -30,6 +30,10 @@
#include "tusb.h" #include "tusb.h"
#include "usb.h" #include "usb.h"
#ifdef MODULE_TINYUSB_DFU
#include "riotboot/usb_dfu.h"
#endif
#include "tinyusb_descriptors.h" #include "tinyusb_descriptors.h"
#define ENABLE_DEBUG 0 #define ENABLE_DEBUG 0
@ -40,16 +44,17 @@
#if (MODULE_TINYUSB_CLASS_AUDIO || \ #if (MODULE_TINYUSB_CLASS_AUDIO || \
MODULE_TINYUSB_CLASS_BTH || \ MODULE_TINYUSB_CLASS_BTH || \
MODULE_TINYUSB_CLASS_DFU || \
MODULE_TINYUSB_CLASS_DFU_RUNTIME || \
MODULE_TINYUSB_CLASS_MIDI || \ MODULE_TINYUSB_CLASS_MIDI || \
MODULE_TINYUSB_CLASS_NET_ECM_RNDIS || \ MODULE_TINYUSB_CLASS_NET_ECM_RNDIS || \
MODULE_TINYUSB_CLASS_NET_NCM || \ MODULE_TINYUSB_CLASS_NET_NCM || \
MODULE_TINYUSB_CLASS_USBTMC || \ MODULE_TINYUSB_CLASS_USBTMC || \
MODULE_TINYUSB_CLASS_VIDEO || \ MODULE_TINYUSB_CLASS_VIDEO || \
(CONFIG_TUSBD_CDC_NUMOF > 2) || \ (CONFIG_TUSBD_CDC_NUMOF > 2) || \
(CONFIG_TUSBD_DFU_NUMOF > 1) || \
(CONFIG_TUSBD_DFU_RT_NUMOF > 1) || \
(CONFIG_TUSBD_HID_NUMOF > 2) || \ (CONFIG_TUSBD_HID_NUMOF > 2) || \
(CONFIG_TUSBD_MSC_NUMOF > 1)) (CONFIG_TUSBD_MSC_NUMOF > 1) || \
(CONFIG_TUSBD_VENDOR_NUMOF > 1))
#error Using generic descriptors is not possible for the selected combination \ #error Using generic descriptors is not possible for the selected combination \
of device class interfaces. Custom descriptors have to be implemented. of device class interfaces. Custom descriptors have to be implemented.
#endif #endif
@ -226,6 +231,24 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id,
speed ? CONFIG_TUSBD_CDC_HS_EP_SIZE \ speed ? CONFIG_TUSBD_CDC_HS_EP_SIZE \
: CONFIG_TUSBD_CDC_FS_EP_SIZE) : CONFIG_TUSBD_CDC_FS_EP_SIZE)
#define _TUD_DFU_DESC(speed) \
/* Interface number, alternate count, starting string index, attributes,
* detach timeout, transfer size */ \
TUD_DFU_DESCRIPTOR(TUSBD_ITF_DFU, CONFIG_TUSBD_DFU_ALT_NUMOF, \
TUSBD_STR_IDX_DFU_SLOT_0, CONFIG_TUSBD_DFU_ATTR, \
CONFIG_TUSBD_DFU_DETACH_TIMEOUT, \
speed ? CONFIG_TUSBD_DFU_HS_XFER_SIZE \
: CONFIG_TUSBD_DFU_FS_XFER_SIZE)
#define _TUD_DFU_RT_DESC(speed) \
/* Interface number, alternate count, starting string index, attributes,
* detach timeout, transfer size */ \
TUD_DFU_RT_DESCRIPTOR(TUSBD_ITF_DFU_RT, \
TUSBD_STR_IDX_DFU_RT, DFU_ATTR_WILL_DETACH, \
CONFIG_TUSBD_DFU_RT_DETACH_TIMEOUT, \
speed ? CONFIG_TUSBD_DFU_RT_HS_XFER_SIZE \
: CONFIG_TUSBD_DFU_RT_FS_XFER_SIZE)
#define _TUD_HID_INOUT_DESC(speed, n) \ #define _TUD_HID_INOUT_DESC(speed, n) \
/* Interface number, string index, protocol, report descriptor len, /* Interface number, string index, protocol, report descriptor len,
* EP Out & EP In address, EP size, polling interval */ \ * EP Out & EP In address, EP size, polling interval */ \
@ -260,6 +283,12 @@ uint8_t const tusb_desc_fs_config[] = {
#if CONFIG_TUSBD_CDC_NUMOF > 1 #if CONFIG_TUSBD_CDC_NUMOF > 1
_TUD_CDC_DESC(_tusb_speed_fs, 1), _TUD_CDC_DESC(_tusb_speed_fs, 1),
#endif #endif
#if CONFIG_TUSBD_DFU_NUMOF
_TUD_DFU_DESC(_tusb_speed_fs),
#endif
#if CONFIG_TUSBD_DFU_RT_NUMOF
_TUD_DFU_RT_DESC(_tusb_speed_fs),
#endif
#if CONFIG_TUSBD_HID_NUMOF > 0 #if CONFIG_TUSBD_HID_NUMOF > 0
_TUD_HID_INOUT_DESC(_tusb_speed_fs, 0), _TUD_HID_INOUT_DESC(_tusb_speed_fs, 0),
#endif #endif
@ -284,6 +313,12 @@ uint8_t const tusb_desc_fs_config_alt[] = {
#if CONFIG_TUSBD_CDC_NUMOF > 1 #if CONFIG_TUSBD_CDC_NUMOF > 1
_TUD_CDC_DESC(_tusb_speed_fs, 1), _TUD_CDC_DESC(_tusb_speed_fs, 1),
#endif #endif
#if CONFIG_TUSBD_DFU_NUMOF
_TUD_DFU_DESC(_tusb_speed_fs),
#endif
#if CONFIG_TUSBD_DFU_RT_NUMOF
_TUD_DFU_RT_DESC(_tusb_speed_fs),
#endif
#if CONFIG_TUSBD_HID_NUMOF > 0 #if CONFIG_TUSBD_HID_NUMOF > 0
_TUD_HID_INOUT_DESC(_tusb_speed_fs, 0), _TUD_HID_INOUT_DESC(_tusb_speed_fs, 0),
#endif #endif
@ -313,6 +348,12 @@ uint8_t const tusb_desc_hs_config[] = {
#if CONFIG_TUSBD_CDC_NUMOF > 1 #if CONFIG_TUSBD_CDC_NUMOF > 1
_TUD_CDC_DESC(_tusb_speed_hs, 1), _TUD_CDC_DESC(_tusb_speed_hs, 1),
#endif #endif
#if CONFIG_TUSBD_DFU
_TUD_DFU_DESC(_tusb_speed_hs),
#endif
#if CONFIG_TUSBD_DFU_RT_NUMOF
_TUD_DFU_RT_DESC(_tusb_speed_hs),
#endif
#if CONFIG_TUSBD_HID_NUMOF > 0 #if CONFIG_TUSBD_HID_NUMOF > 0
_TUD_HID_INOUT_DESC(_tusb_speed_hs, 0), _TUD_HID_INOUT_DESC(_tusb_speed_hs, 0),
#endif #endif
@ -337,6 +378,12 @@ uint8_t const tusb_desc_hs_config_alt[] = {
#if CONFIG_TUSBD_CDC_NUMOF > 1 #if CONFIG_TUSBD_CDC_NUMOF > 1
_TUD_CDC_DESC(_tusb_speed_hs, 1), _TUD_CDC_DESC(_tusb_speed_hs, 1),
#endif #endif
#if CONFIG_TUSBD_DFU
_TUD_DFU_DESC(_tusb_speed_hs),
#endif
#if CONFIG_TUSBD_DFU_RT_NUMOF
_TUD_DFU_RT_DESC(_tusb_speed_hs),
#endif
#if CONFIG_TUSBD_HID_NUMOF > 0 #if CONFIG_TUSBD_HID_NUMOF > 0
_TUD_HID_INOUT_DESC(_tusb_speed_hs, 0), _TUD_HID_INOUT_DESC(_tusb_speed_hs, 0),
#endif #endif
@ -488,6 +535,18 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index)
#define CONFIG_TUSBD_CDC_1_STRING "TinyUSB CDC1" #define CONFIG_TUSBD_CDC_1_STRING "TinyUSB CDC1"
#endif #endif
#ifndef CONFIG_TUSBD_DFU_0_STRING
#define CONFIG_TUSBD_DFU_0_STRING USB_DFU_MODE_SLOT0_NAME
#endif
#ifndef CONFIG_TUSBD_DFU_1_STRING
#define CONFIG_TUSBD_DFU_1_STRING USB_DFU_MODE_SLOT1_NAME
#endif
#ifndef CONFIG_TUSBD_DFU_RT_STRING
#define CONFIG_TUSBD_DFU_RT_STRING USB_APP_MODE_SLOT_NAME
#endif
#ifndef CONFIG_TUSBD_HID_0_STRING #ifndef CONFIG_TUSBD_HID_0_STRING
#define CONFIG_TUSBD_HID_0_STRING "TinyUSB HID0 (Generic In/Out)" #define CONFIG_TUSBD_HID_0_STRING "TinyUSB HID0 (Generic In/Out)"
#endif #endif
@ -524,6 +583,13 @@ char const* tusb_string_desc_array[] = {
#if CONFIG_TUSBD_CDC_NUMOF > 1 #if CONFIG_TUSBD_CDC_NUMOF > 1
CONFIG_TUSBD_CDC_1_STRING, /* CDC Interface 1 */ CONFIG_TUSBD_CDC_1_STRING, /* CDC Interface 1 */
#endif #endif
#if CONFIG_TUSBD_DFU_NUMOF
CONFIG_TUSBD_DFU_0_STRING, /* DFU Firmware Slot 0 */
CONFIG_TUSBD_DFU_1_STRING, /* DFU Firmware Slot 1 */
#endif
#if CONFIG_TUSBD_DFU_RT_NUMOF
CONFIG_TUSBD_DFU_RT_STRING, /* APP mode */
#endif
#if CONFIG_TUSBD_HID_NUMOF > 0 #if CONFIG_TUSBD_HID_NUMOF > 0
CONFIG_TUSBD_HID_0_STRING, /* HID Interface 0 */ CONFIG_TUSBD_HID_0_STRING, /* HID Interface 0 */
#endif #endif