diff options
| author | hathach <[email protected]> | 2019-07-30 10:24:36 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2019-07-30 10:24:36 +0700 |
| commit | 1e7f1de4d766e846ec43d5b345a7dc545d98335b (patch) | |
| tree | e09333dd599e92d0686ca5e2bcf928b1cf60165a /src/common | |
| parent | 1ee9ef4f2b7c6acfab6c398a4f57ca22036958f7 (diff) | |
| parent | 00a9e492cdf04ea17379218996d2713bcaaaff51 (diff) | |
Merge pull request #89 from hathach/develop
resolve #35 (vendor class), implement #86 (webusb)
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/tusb_common.h | 5 | ||||
| -rw-r--r-- | src/common/tusb_types.h | 118 | ||||
| -rw-r--r-- | src/common/tusb_verify.h | 42 |
3 files changed, 114 insertions, 51 deletions
diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index c77be2a9f..ee77b62f1 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -146,9 +146,10 @@ static inline bool tu_bit_test (uint32_t value, uint8_t n) { return (value & * Nth position is the same as the number of arguments
* - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma)
*------------------------------------------------------------------*/
-#ifndef VA_ARGS_NUM_
+#ifndef TU_ARGS_NUM
+
+#define TU_ARGS_NUM(...) NARG_(_0, ##__VA_ARGS__,_RSEQ_N())
-#define VA_ARGS_NUM_(...) NARG_(_0, ##__VA_ARGS__,_RSEQ_N())
#define NARG_(...) _GET_NTH_ARG(__VA_ARGS__)
#define _GET_NTH_ARG( \
_1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h index fd6e435e6..8358d7e66 100644 --- a/src/common/tusb_types.h +++ b/src/common/tusb_types.h @@ -69,7 +69,7 @@ typedef enum }tusb_dir_t;
-/// USB Descriptor Types (section 9.4 table 9-5)
+/// USB Descriptor Types
typedef enum
{
TUSB_DESC_DEVICE = 0x01,
@@ -84,29 +84,35 @@ typedef enum TUSB_DESC_DEBUG = 0x0A,
TUSB_DESC_INTERFACE_ASSOCIATION = 0x0B,
+ TUSB_DESC_BOS = 0x0F,
+ TUSB_DESC_DEVICE_CAPABILITY = 0x10,
+
// Class Specific Descriptor
TUSB_DESC_CS_DEVICE = 0x21,
TUSB_DESC_CS_CONFIGURATION = 0x22,
TUSB_DESC_CS_STRING = 0x23,
TUSB_DESC_CS_INTERFACE = 0x24,
TUSB_DESC_CS_ENDPOINT = 0x25,
+
+ TUSB_DESC_SUPERSPEED_ENDPOINT_COMPANION = 0x30,
+ TUSB_DESC_SUPERSPEED_ISO_ENDPOINT_COMPANION = 0x31
}tusb_desc_type_t;
typedef enum
{
- TUSB_REQ_GET_STATUS =0 , ///< 0
- TUSB_REQ_CLEAR_FEATURE , ///< 1
- TUSB_REQ_RESERVED , ///< 2
- TUSB_REQ_SET_FEATURE , ///< 3
- TUSB_REQ_RESERVED2 , ///< 4
- TUSB_REQ_SET_ADDRESS , ///< 5
- TUSB_REQ_GET_DESCRIPTOR , ///< 6
- TUSB_REQ_SET_DESCRIPTOR , ///< 7
- TUSB_REQ_GET_CONFIGURATION , ///< 8
- TUSB_REQ_SET_CONFIGURATION , ///< 9
- TUSB_REQ_GET_INTERFACE , ///< 10
- TUSB_REQ_SET_INTERFACE , ///< 11
- TUSB_REQ_SYNCH_FRAME ///< 12
+ TUSB_REQ_GET_STATUS = 0 ,
+ TUSB_REQ_CLEAR_FEATURE = 1 ,
+ TUSB_REQ_RESERVED = 2 ,
+ TUSB_REQ_SET_FEATURE = 3 ,
+ TUSB_REQ_RESERVED2 = 4 ,
+ TUSB_REQ_SET_ADDRESS = 5 ,
+ TUSB_REQ_GET_DESCRIPTOR = 6 ,
+ TUSB_REQ_SET_DESCRIPTOR = 7 ,
+ TUSB_REQ_GET_CONFIGURATION = 8 ,
+ TUSB_REQ_SET_CONFIGURATION = 9 ,
+ TUSB_REQ_GET_INTERFACE = 10 ,
+ TUSB_REQ_SET_INTERFACE = 11 ,
+ TUSB_REQ_SYNCH_FRAME = 12
}tusb_request_code_t;
typedef enum
@@ -168,6 +174,26 @@ typedef enum MISC_PROTOCOL_IAD = 1
}misc_protocol_type_t;
+typedef enum
+{
+ DEVICE_CAPABILITY_WIRELESS_USB = 0x01,
+ DEVICE_CAPABILITY_USB20_EXTENSION = 0x02,
+ DEVICE_CAPABILITY_SUPERSPEED_USB = 0x03,
+ DEVICE_CAPABILITY_CONTAINER_id = 0x04,
+ DEVICE_CAPABILITY_PLATFORM = 0x05,
+ DEVICE_CAPABILITY_POWER_DELIVERY = 0x06,
+ DEVICE_CAPABILITY_BATTERY_INFO = 0x07,
+ DEVICE_CAPABILITY_PD_CONSUMER_PORT = 0x08,
+ DEVICE_CAPABILITY_PD_PROVIDER_PORT = 0x09,
+ DEVICE_CAPABILITY_SUPERSPEED_PLUS = 0x0A,
+ DEVICE_CAPABILITY_PRECESION_TIME_MEASUREMENT = 0x0B,
+ DEVICE_CAPABILITY_WIRELESS_USB_EXT = 0x0C,
+ DEVICE_CAPABILITY_BILLBOARD = 0x0D,
+ DEVICE_CAPABILITY_AUTHENTICATION = 0x0E,
+ DEVICE_CAPABILITY_BILLBOARD_EX = 0x0F,
+ DEVICE_CAPABILITY_CONFIGURATION_SUMMARY = 0x10
+}device_capability_type_t;
+
enum {
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = TU_BIT(5),
TUSB_DESC_CONFIG_ATT_SELF_POWERED = TU_BIT(6),
@@ -201,11 +227,25 @@ enum INTERFACE_INVALID_NUMBER = 0xff
};
+
+enum
+{
+ MS_OS_20_SET_HEADER_DESCRIPTOR = 0x00,
+ MS_OS_20_SUBSET_HEADER_CONFIGURATION = 0x01,
+ MS_OS_20_SUBSET_HEADER_FUNCTION = 0x02,
+ MS_OS_20_FEATURE_COMPATBLE_ID = 0x03,
+ MS_OS_20_FEATURE_REG_PROPERTY = 0x04,
+ MS_OS_20_FEATURE_MIN_RESUME_TIME = 0x05,
+ MS_OS_20_FEATURE_MODEL_ID = 0x06,
+ MS_OS_20_FEATURE_CCGP_DEVICE = 0x07,
+ MS_OS_20_FEATURE_VENDOR_REVISION = 0x08
+}microsoft_os_20_type_t;
+
//--------------------------------------------------------------------+
-// STANDARD DESCRIPTORS
+// USB Descriptors
//--------------------------------------------------------------------+
-/// USB Standard Device Descriptor (section 9.6.1, table 9-8)
+/// USB Device Descriptor
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes.
@@ -227,7 +267,16 @@ typedef struct TU_ATTR_PACKED uint8_t bNumConfigurations ; ///< Number of possible configurations.
} tusb_desc_device_t;
-/// USB Standard Configuration Descriptor (section 9.6.1 table 9-10) */
+// USB Binary Device Object Store (BOS) Descriptor
+typedef struct TU_ATTR_PACKED
+{
+ uint8_t bLength ; ///< Size of this descriptor in bytes
+ uint8_t bDescriptorType ; ///< CONFIGURATION Descriptor Type
+ uint16_t wTotalLength ; ///< Total length of data returned for this descriptor
+ uint8_t bNumDeviceCaps ; ///< Number of device capability descriptors in the BOS
+} tusb_desc_bos_t;
+
+/// USB Configuration Descriptor
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
@@ -241,7 +290,7 @@ typedef struct TU_ATTR_PACKED uint8_t bMaxPower ; ///< Maximum power consumption of the USB device from the bus in this specific configuration when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA).
} tusb_desc_configuration_t;
-/// USB Standard Interface Descriptor (section 9.6.1 table 9-12)
+/// USB Interface Descriptor
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
@@ -256,7 +305,7 @@ typedef struct TU_ATTR_PACKED uint8_t iInterface ; ///< Index of string descriptor describing this interface
} tusb_desc_interface_t;
-/// USB Standard Endpoint Descriptor (section 9.6.1 table 9-13)
+/// USB Endpoint Descriptor
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
@@ -280,7 +329,7 @@ typedef struct TU_ATTR_PACKED uint8_t bInterval ; ///< Interval for polling endpoint for data transfers. Expressed in frames or microframes depending on the device operating speed (i.e., either 1 millisecond or 125 us units). \n- For full-/high-speed isochronous endpoints, this value must be in the range from 1 to 16. The bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$). \n- For full-/low-speed interrupt endpoints, the value of this field may be from 1 to 255. \n- For high-speed interrupt endpoints, the bInterval value is used as the exponent for a \f$ 2^(bInterval-1) \f$ value; e.g., a bInterval of 4 means a period of 8 (\f$ 2^(4-1) \f$) . This value must be from 1 to 16. \n- For high-speed bulk/control OUT endpoints, the bInterval must specify the maximum NAK rate of the endpoint. A value of 0 indicates the endpoint never NAKs. Other values indicate at most 1 NAK each bInterval number of microframes. This value must be in the range from 0 to 255. \n Refer to Chapter 5 of USB 2.0 specification for more information.
} tusb_desc_endpoint_t;
-/// USB Other Speed Configuration Descriptor (section 9.6.1 table 9-11)
+/// USB Other Speed Configuration Descriptor
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of descriptor
@@ -294,7 +343,7 @@ typedef struct TU_ATTR_PACKED uint8_t bMaxPower ; ///< Same as Configuration descriptor
} tusb_desc_other_speed_t;
-/// USB Device Qualifier Descriptor (section 9.6.1 table 9-9)
+/// USB Device Qualifier Descriptor
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of descriptor
@@ -325,20 +374,33 @@ typedef struct TU_ATTR_PACKED uint8_t iFunction ; ///< Index of the string descriptor describing the interface association.
} tusb_desc_interface_assoc_t;
-/// USB Header Descriptor
+// USB String Descriptor
typedef struct TU_ATTR_PACKED
{
uint8_t bLength ; ///< Size of this descriptor in bytes
uint8_t bDescriptorType ; ///< Descriptor Type
-} tusb_desc_header_t;
+ uint16_t unicode_string[];
+} tusb_desc_string_t;
+// USB Binary Device Object Store (BOS)
typedef struct TU_ATTR_PACKED
{
- uint8_t bLength ; ///< Size of this descriptor in bytes
- uint8_t bDescriptorType ; ///< Descriptor Type
- uint16_t unicode_string[];
-} tusb_desc_string_t;
+ uint8_t bLength;
+ uint8_t bDescriptorType ;
+ uint8_t bDevCapabilityType;
+ uint8_t bReserved;
+ uint8_t PlatformCapabilityUUID[16];
+ uint8_t CapabilityData[];
+} tusb_desc_bos_platform_t;
+// USB WebuSB URL Descriptor
+typedef struct TU_ATTR_PACKED
+{
+ uint8_t bLength;
+ uint8_t bDescriptorType;
+ uint8_t bScheme;
+ char url[];
+} tusb_desc_webusb_url_t;
/*------------------------------------------------------------------*/
/* Types
@@ -415,7 +477,7 @@ static inline uint8_t tu_desc_len(void const* desc) #define TUD_DESC_STR_HEADER(_chr_count) ( (uint16_t) ( (TUSB_DESC_STRING << 8 ) | TUD_DESC_STRLEN(_chr_count)) )
// Convert comma-separated string to descriptor unicode format
-#define TUD_DESC_STRCONV( ... ) (const uint16_t[]) { TUD_DESC_STR_HEADER(VA_ARGS_NUM_(__VA_ARGS__)), __VA_ARGS__ }
+#define TUD_DESC_STRCONV( ... ) (const uint16_t[]) { TUD_DESC_STR_HEADER(TU_ARGS_NUM(__VA_ARGS__)), __VA_ARGS__ }
#ifdef __cplusplus
}
diff --git a/src/common/tusb_verify.h b/src/common/tusb_verify.h index eecc95ccb..08ddf78ad 100644 --- a/src/common/tusb_verify.h +++ b/src/common/tusb_verify.h @@ -51,8 +51,8 @@ //--------------------------------------------------------------------+ #if CFG_TUSB_DEBUG #include <stdio.h> - #define _MESS_ERR(_err) printf("%s: %d: failed, error = %s\n", __func__, __LINE__, tusb_strerr[_err]) - #define _MESS_FAILED() printf("%s: %d: failed\n", __func__, __LINE__) + #define _MESS_ERR(_err) printf("%s: %d: failed, error = %s\n", __func__, __LINE__, tusb_strerr[_err]) + #define _MESS_FAILED() printf("%s: %d: failed\n", __func__, __LINE__) #else #define _MESS_ERR(_err) #define _MESS_FAILED() @@ -61,11 +61,11 @@ // Halt CPU (breakpoint) when hitting error, only apply for Cortex M3, M4, M7 #if defined(__ARM_ARCH_7M__) || defined (__ARM_ARCH_7EM__) -#define TU_BREAKPOINT() \ - do {\ - volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL); /* Cortex M CoreDebug->DHCSR */ \ - if ( (*ARM_CM_DHCSR) & 1UL ) __asm("BKPT #0\n"); /* Only halt mcu if debugger is attached */\ - } while(0) +#define TU_BREAKPOINT() do \ +{ \ + volatile uint32_t* ARM_CM_DHCSR = ((volatile uint32_t*) 0xE000EDF0UL); /* Cortex M CoreDebug->DHCSR */ \ + if ( (*ARM_CM_DHCSR) & 1UL ) __asm("BKPT #0\n"); /* Only halt mcu if debugger is attached */ \ +} while(0) #else #define TU_BREAKPOINT() @@ -80,22 +80,23 @@ #define GET_4TH_ARG(arg1, arg2, arg3, arg4, ...) arg4 /*------------- Generator for TU_VERIFY and TU_VERIFY_HDLR -------------*/ -#define TU_VERIFY_DEFINE(_cond, _handler, _ret) do { if ( !(_cond) ) { _handler; return _ret; } } while(0) +#define TU_VERIFY_DEFINE(_cond, _handler, _ret) do \ +{ \ + if ( !(_cond) ) { _handler; return _ret; } \ +} while(0) /*------------- Generator for TU_VERIFY_ERR and TU_VERIFY_ERR_HDLR -------------*/ -#define TU_VERIFY_ERR_DEF2(_error, _handler) \ - do { \ - uint32_t _err = (uint32_t)(_error); \ - if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _err; }\ - } while(0) - -#define TU_VERIFY_ERR_DEF3(_error, _handler, _ret) \ - do { \ - uint32_t _err = (uint32_t)(_error); \ - if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _ret; }\ - } while(0) - +#define TU_VERIFY_ERR_DEF2(_error, _handler) do \ +{ \ + uint32_t _err = (uint32_t)(_error); \ + if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _err; } \ +} while(0) +#define TU_VERIFY_ERR_DEF3(_error, _handler, _ret) do \ +{ \ + uint32_t _err = (uint32_t)(_error); \ + if ( 0 != _err ) { _MESS_ERR(_err); _handler; return _ret; } \ +} while(0) /*------------------------------------------------------------------*/ @@ -141,7 +142,6 @@ #define TU_VERIFY_ERR_HDLR(...) GET_4TH_ARG(__VA_ARGS__, TU_VERIFY_ERR_HDLR_3ARGS, TU_VERIFY_ERR_HDLR_2ARGS)(__VA_ARGS__) - /*------------------------------------------------------------------*/ /* ASSERT * basically TU_VERIFY with TU_BREAKPOINT() as handler |
