initial check in based on SVN revision 575
This commit is contained in:
134
usb/include/usb.h
Normal file
134
usb/include/usb.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef __USB_H__
|
||||
#define __USB_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include "fsl_common.h"
|
||||
#include "fsl_os_abstraction.h"
|
||||
#include "usb_misc.h"
|
||||
#include "usb_spec.h"
|
||||
|
||||
/*!
|
||||
* @addtogroup usb_drv
|
||||
* @{
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/*! @brief Defines USB stack major version */
|
||||
#define USB_STACK_VERSION_MAJOR (2UL)
|
||||
/*! @brief Defines USB stack minor version */
|
||||
#define USB_STACK_VERSION_MINOR (7UL)
|
||||
/*! @brief Defines USB stack bugfix version */
|
||||
#define USB_STACK_VERSION_BUGFIX (0U)
|
||||
|
||||
/*! @brief USB stack version definition */
|
||||
#define USB_MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
|
||||
|
||||
#define MAKE_VERSION(major, minor, bugfix) (((major) << 16) | ((minor) << 8) | (bugfix))
|
||||
|
||||
/*! @brief USB stack component version definition, changed with component in yaml together */
|
||||
#define USB_STACK_COMPONENT_VERSION \
|
||||
MAKE_VERSION(USB_STACK_VERSION_MAJOR, USB_STACK_VERSION_MINOR, USB_STACK_VERSION_BUGFIX)
|
||||
|
||||
/*
|
||||
* Component ID used by tools
|
||||
*
|
||||
* FSL_COMPONENT_ID "middleware.usb.stack_common"
|
||||
*/
|
||||
|
||||
/*! @brief USB error code */
|
||||
typedef enum _usb_status
|
||||
{
|
||||
kStatus_USB_Success = 0x00U, /*!< Success */
|
||||
kStatus_USB_Error, /*!< Failed */
|
||||
|
||||
kStatus_USB_Busy, /*!< Busy */
|
||||
kStatus_USB_InvalidHandle, /*!< Invalid handle */
|
||||
kStatus_USB_InvalidParameter, /*!< Invalid parameter */
|
||||
kStatus_USB_InvalidRequest, /*!< Invalid request */
|
||||
kStatus_USB_ControllerNotFound, /*!< Controller cannot be found */
|
||||
kStatus_USB_InvalidControllerInterface, /*!< Invalid controller interface */
|
||||
|
||||
kStatus_USB_NotSupported, /*!< Configuration is not supported */
|
||||
kStatus_USB_Retry, /*!< Enumeration get configuration retry */
|
||||
kStatus_USB_TransferStall, /*!< Transfer stalled */
|
||||
kStatus_USB_TransferFailed, /*!< Transfer failed */
|
||||
kStatus_USB_AllocFail, /*!< Allocation failed */
|
||||
kStatus_USB_LackSwapBuffer, /*!< Insufficient swap buffer for KHCI */
|
||||
kStatus_USB_TransferCancel, /*!< The transfer cancelled */
|
||||
kStatus_USB_BandwidthFail, /*!< Allocate bandwidth failed */
|
||||
kStatus_USB_MSDStatusFail, /*!< For MSD, the CSW status means fail */
|
||||
kStatus_USB_EHCIAttached,
|
||||
kStatus_USB_EHCIDetached,
|
||||
kStatus_USB_DataOverRun, /*!< The amount of data returned by the endpoint exceeded
|
||||
either the size of the maximum data packet allowed
|
||||
from the endpoint or the remaining buffer size. */
|
||||
} usb_status_t;
|
||||
|
||||
/*! @brief USB host handle type define */
|
||||
typedef void *usb_host_handle;
|
||||
|
||||
/*! @brief USB device handle type define. For device stack it is the whole device handle; for host stack it is the
|
||||
* attached device instance handle*/
|
||||
typedef void *usb_device_handle;
|
||||
|
||||
/*! @brief USB OTG handle type define */
|
||||
typedef void *usb_otg_handle;
|
||||
|
||||
/*! @brief USB controller ID */
|
||||
typedef enum _usb_controller_index
|
||||
{
|
||||
kUSB_ControllerKhci0 = 0U, /*!< KHCI 0U */
|
||||
kUSB_ControllerKhci1 = 1U, /*!< KHCI 1U, Currently, there are no platforms which have two KHCI IPs, this is reserved
|
||||
to be used in the future. */
|
||||
kUSB_ControllerEhci0 = 2U, /*!< EHCI 0U */
|
||||
kUSB_ControllerEhci1 = 3U, /*!< EHCI 1U, Currently, there are no platforms which have two EHCI IPs, this is reserved
|
||||
to be used in the future. */
|
||||
|
||||
kUSB_ControllerLpcIp3511Fs0 = 4U, /*!< LPC USB IP3511 FS controller 0 */
|
||||
kUSB_ControllerLpcIp3511Fs1 = 5U, /*!< LPC USB IP3511 FS controller 1, there are no platforms which have two IP3511
|
||||
IPs, this is reserved to be used in the future. */
|
||||
|
||||
kUSB_ControllerLpcIp3511Hs0 = 6U, /*!< LPC USB IP3511 HS controller 0 */
|
||||
kUSB_ControllerLpcIp3511Hs1 = 7U, /*!< LPC USB IP3511 HS controller 1, there are no platforms which have two IP3511
|
||||
IPs, this is reserved to be used in the future. */
|
||||
|
||||
kUSB_ControllerOhci0 = 8U, /*!< OHCI 0U */
|
||||
kUSB_ControllerOhci1 = 9U, /*!< OHCI 1U, Currently, there are no platforms which have two OHCI IPs, this is reserved
|
||||
to be used in the future. */
|
||||
|
||||
kUSB_ControllerIp3516Hs0 = 10U, /*!< IP3516HS 0U */
|
||||
kUSB_ControllerIp3516Hs1 = 11U, /*!< IP3516HS 1U, Currently, there are no platforms which have two IP3516HS IPs,
|
||||
this is reserved to be used in the future. */
|
||||
kUSB_ControllerDwc30 = 12U, /*!< DWC3 0U */
|
||||
kUSB_ControllerDwc31 = 13U, /*!< DWC3 1U Currently, there are no platforms which have two Dwc IPs, this is reserved
|
||||
to be used in the future.*/
|
||||
} usb_controller_index_t;
|
||||
|
||||
/**
|
||||
* @brief USB stack version fields
|
||||
*/
|
||||
typedef struct _usb_version
|
||||
{
|
||||
uint8_t major; /*!< Major */
|
||||
uint8_t minor; /*!< Minor */
|
||||
uint8_t bugfix; /*!< Bug fix */
|
||||
} usb_version_t;
|
||||
|
||||
/*******************************************************************************
|
||||
* API
|
||||
******************************************************************************/
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif /* __USB_H__ */
|
||||
501
usb/include/usb_misc.h
Normal file
501
usb/include/usb_misc.h
Normal file
@@ -0,0 +1,501 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016, 2019 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef __USB_MISC_H__
|
||||
#define __USB_MISC_H__
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/*! @brief Define big endian */
|
||||
#define USB_BIG_ENDIAN (0U)
|
||||
/*! @brief Define little endian */
|
||||
#define USB_LITTLE_ENDIAN (1U)
|
||||
|
||||
/*! @brief Define current endian */
|
||||
#ifndef ENDIANNESS
|
||||
#define ENDIANNESS USB_LITTLE_ENDIAN
|
||||
#endif
|
||||
/*! @brief Define default timeout value */
|
||||
#if (defined(USE_RTOS) && (USE_RTOS > 0))
|
||||
#define USB_OSA_WAIT_TIMEOUT (osaWaitForever_c)
|
||||
#else
|
||||
#define USB_OSA_WAIT_TIMEOUT (0U)
|
||||
#endif /* (defined(USE_RTOS) && (USE_RTOS > 0)) */
|
||||
|
||||
/*! @brief Define USB printf */
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern int DbgConsole_Printf(const char *fmt_s, ...);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if defined(SDK_DEBUGCONSOLE) && (SDK_DEBUGCONSOLE < 1)
|
||||
#define usb_echo printf
|
||||
#else
|
||||
#define usb_echo DbgConsole_Printf
|
||||
#endif
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
|
||||
#ifndef STRUCT_PACKED
|
||||
#define STRUCT_PACKED __packed
|
||||
#endif
|
||||
|
||||
#ifndef STRUCT_UNPACKED
|
||||
#define STRUCT_UNPACKED
|
||||
#endif
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
#ifndef STRUCT_PACKED
|
||||
#define STRUCT_PACKED
|
||||
#endif
|
||||
|
||||
#ifndef STRUCT_UNPACKED
|
||||
#define STRUCT_UNPACKED __attribute__((__packed__))
|
||||
#endif
|
||||
|
||||
#elif defined(__CC_ARM) || (defined(__ARMCC_VERSION))
|
||||
|
||||
#ifndef STRUCT_PACKED
|
||||
#define STRUCT_PACKED _Pragma("pack(1U)")
|
||||
#endif
|
||||
|
||||
#ifndef STRUCT_UNPACKED
|
||||
#define STRUCT_UNPACKED _Pragma("pack()")
|
||||
#endif
|
||||
|
||||
#elif (defined(__DSC__) || defined(__CW__))
|
||||
|
||||
#ifndef STRUCT_PACKED
|
||||
#define STRUCT_PACKED
|
||||
#endif
|
||||
|
||||
#ifndef STRUCT_UNPACKED
|
||||
#define STRUCT_UNPACKED __attribute__((packed))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define USB_SHORT_GET_LOW(x) (((uint16_t)x) & 0xFFU)
|
||||
#define USB_SHORT_GET_HIGH(x) ((uint8_t)(((uint16_t)x) >> 8U) & 0xFFU)
|
||||
|
||||
#define USB_LONG_GET_BYTE0(x) ((uint8_t)(((uint32_t)(x))) & 0xFFU)
|
||||
#define USB_LONG_GET_BYTE1(x) ((uint8_t)(((uint32_t)(x)) >> 8U) & 0xFFU)
|
||||
#define USB_LONG_GET_BYTE2(x) ((uint8_t)(((uint32_t)(x)) >> 16U) & 0xFFU)
|
||||
#define USB_LONG_GET_BYTE3(x) ((uint8_t)(((uint32_t)(x)) >> 24U) & 0xFFU)
|
||||
|
||||
#define USB_MEM4_ALIGN_MASK (0x03U)
|
||||
|
||||
/* accessory macro */
|
||||
#define USB_MEM4_ALIGN(n) ((n + 3U) & (0xFFFFFFFCu))
|
||||
#define USB_MEM32_ALIGN(n) ((n + 31U) & (0xFFFFFFE0u))
|
||||
#define USB_MEM64_ALIGN(n) ((n + 63U) & (0xFFFFFFC0u))
|
||||
|
||||
/* big/little endian */
|
||||
#define SWAP2BYTE_CONST(n) ((((n)&0x00FFU) << 8U) | (((n)&0xFF00U) >> 8U))
|
||||
#define SWAP4BYTE_CONST(n) \
|
||||
((((n)&0x000000FFU) << 24U) | (((n)&0x0000FF00U) << 8U) | (((n)&0x00FF0000U) >> 8U) | (((n)&0xFF000000U) >> 24U))
|
||||
|
||||
#define USB_ASSIGN_VALUE_ADDRESS_LONG_BY_BYTE(n, m) \
|
||||
{ \
|
||||
*((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
|
||||
*((uint8_t *)&(n) + 1) = *((uint8_t *)&(m) + 1); \
|
||||
*((uint8_t *)&(n) + 2) = *((uint8_t *)&(m) + 2); \
|
||||
*((uint8_t *)&(n) + 3) = *((uint8_t *)&(m) + 3); \
|
||||
}
|
||||
|
||||
#define USB_ASSIGN_VALUE_ADDRESS_SHORT_BY_BYTE(n, m) \
|
||||
{ \
|
||||
*((uint8_t *)&(n)) = *((uint8_t *)&(m)); \
|
||||
*((uint8_t *)&(n) + 1) = *((uint8_t *)&(m) + 1); \
|
||||
}
|
||||
|
||||
#define USB_ASSIGN_MACRO_VALUE_ADDRESS_LONG_BY_BYTE(n, m) \
|
||||
{ \
|
||||
*((uint8_t *)&(n)) = (uint8_t)m; \
|
||||
*((uint8_t *)&(n) + 1) = (uint8_t)(m >> 8); \
|
||||
*((uint8_t *)&(n) + 2) = (uint8_t)(m >> 16); \
|
||||
*((uint8_t *)&(n) + 3) = (uint8_t)(m >> 24); \
|
||||
}
|
||||
|
||||
#define USB_ASSIGN_MACRO_VALUE_ADDRESS_SHORT_BY_BYTE(n, m) \
|
||||
{ \
|
||||
*((uint8_t *)&(n)) = (uint8_t)m; \
|
||||
*((uint8_t *)&(n) + 1) = (uint8_t)(m >> 8); \
|
||||
}
|
||||
|
||||
#if (ENDIANNESS == USB_BIG_ENDIAN)
|
||||
|
||||
#define USB_SHORT_TO_LITTLE_ENDIAN(n) SWAP2BYTE_CONST(n)
|
||||
#define USB_LONG_TO_LITTLE_ENDIAN(n) SWAP4BYTE_CONST(n)
|
||||
#define USB_SHORT_FROM_LITTLE_ENDIAN(n) SWAP2BYTE_CONST(n)
|
||||
#define USB_LONG_FROM_LITTLE_ENDIAN(n) SWAP2BYTE_CONST(n)
|
||||
|
||||
#define USB_SHORT_TO_BIG_ENDIAN(n) (n)
|
||||
#define USB_LONG_TO_BIG_ENDIAN(n) (n)
|
||||
#define USB_SHORT_FROM_BIG_ENDIAN(n) (n)
|
||||
#define USB_LONG_FROM_BIG_ENDIAN(n) (n)
|
||||
|
||||
#define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
|
||||
{ \
|
||||
m[3] = (uint8_t)((((uint32_t)(n)) >> 24U) & 0xFFU); \
|
||||
m[2] = (uint8_t)((((uint32_t)(n)) >> 16U) & 0xFFU); \
|
||||
m[1] = (uint8_t)((((uint32_t)(n)) >> 8U) & 0xFFU); \
|
||||
m[0] = (uint8_t)(((uint32_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
|
||||
((uint32_t)((((uint32_t)n[3]) << 24U) | (((uint32_t)n[2]) << 16U) | (((uint32_t)n[1]) << 8U) | \
|
||||
(((uint32_t)n[0]) << 0U)))
|
||||
|
||||
#define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
|
||||
{ \
|
||||
m[0] = ((((uint32_t)(n)) >> 24U) & 0xFFU); \
|
||||
m[1] = ((((uint32_t)(n)) >> 16U) & 0xFFU); \
|
||||
m[2] = ((((uint32_t)(n)) >> 8U) & 0xFFU); \
|
||||
m[3] = (((uint32_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
|
||||
((uint32_t)((((uint32_t)n[0]) << 24U) | (((uint32_t)n[1]) << 16U) | (((uint32_t)n[2]) << 8U) | \
|
||||
(((uint32_t)n[3]) << 0U)))
|
||||
|
||||
#define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
|
||||
{ \
|
||||
m[1] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
|
||||
m[0] = (((uint16_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[1]) << 8U) | (((uint16_t)n[0]) << 0U)))
|
||||
|
||||
#define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
|
||||
{ \
|
||||
m[0] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
|
||||
m[1] = (((uint16_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[0]) << 8U) | (((uint16_t)n[1]) << 0U)))
|
||||
|
||||
#define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
|
||||
{ \
|
||||
*((uint8_t *)&(m) + 3) = ((((uint32_t)(n)) >> 24U) & 0xFFU); \
|
||||
*((uint8_t *)&(m) + 2) = ((((uint32_t)(n)) >> 16U) & 0xFFU); \
|
||||
*((uint8_t *)&(m) + 1) = ((((uint32_t)(n)) >> 8U) & 0xFFU); \
|
||||
*((uint8_t *)&(m) + 0) = (((uint32_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
|
||||
((uint32_t)(((uint32_t)(*((uint8_t *)&(n) + 3)) << 24U) | ((uint32_t)(*((uint8_t *)&(n) + 2)) << 16U) | \
|
||||
((uint32_t)(*((uint8_t *)&(n) + 1)) << 8U) | ((uint32_t)(*((uint8_t *)&(n))) << 0U)))
|
||||
|
||||
#define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
|
||||
{ \
|
||||
*((uint8_t *)&(m) + 1) = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
|
||||
*((uint8_t *)&(m)) = ((((uint16_t)(n))) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) \
|
||||
((uint16_t)((uint16_t)(*((uint8_t *)&(n) + 1)) << 8U) | ((uint16_t)(*((uint8_t *)&(n)))))
|
||||
|
||||
#else
|
||||
|
||||
#define USB_SHORT_TO_LITTLE_ENDIAN(n) (n)
|
||||
#define USB_LONG_TO_LITTLE_ENDIAN(n) (n)
|
||||
#define USB_SHORT_FROM_LITTLE_ENDIAN(n) (n)
|
||||
#define USB_LONG_FROM_LITTLE_ENDIAN(n) (n)
|
||||
|
||||
#define USB_SHORT_TO_BIG_ENDIAN(n) SWAP2BYTE_CONST(n)
|
||||
#define USB_LONG_TO_BIG_ENDIAN(n) SWAP4BYTE_CONST(n)
|
||||
#define USB_SHORT_FROM_BIG_ENDIAN(n) SWAP2BYTE_CONST(n)
|
||||
#define USB_LONG_FROM_BIG_ENDIAN(n) SWAP4BYTE_CONST(n)
|
||||
|
||||
#define USB_LONG_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
|
||||
{ \
|
||||
m[3] = (uint8_t)((((uint32_t)(n)) >> 24U) & 0xFFU); \
|
||||
m[2] = (uint8_t)((((uint32_t)(n)) >> 16U) & 0xFFU); \
|
||||
m[1] = (uint8_t)((((uint32_t)(n)) >> 8U) & 0xFFU); \
|
||||
m[0] = (uint8_t)(((uint32_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_LONG_FROM_LITTLE_ENDIAN_ADDRESS(n) \
|
||||
((uint32_t)((((uint32_t)n[3]) << 24U) | (((uint32_t)n[2]) << 16U) | (((uint32_t)n[1]) << 8U) | \
|
||||
(((uint32_t)n[0]) << 0U)))
|
||||
|
||||
#define USB_LONG_TO_BIG_ENDIAN_ADDRESS(n, m) \
|
||||
{ \
|
||||
m[0] = ((((uint32_t)(n)) >> 24U) & 0xFFU); \
|
||||
m[1] = ((((uint32_t)(n)) >> 16U) & 0xFFU); \
|
||||
m[2] = ((((uint32_t)(n)) >> 8U) & 0xFFU); \
|
||||
m[3] = (((uint32_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_LONG_FROM_BIG_ENDIAN_ADDRESS(n) \
|
||||
((uint32_t)((((uint32_t)n[0]) << 24U) | (((uint32_t)n[1]) << 16U) | (((uint32_t)n[2]) << 8U) | \
|
||||
(((uint32_t)n[3]) << 0U)))
|
||||
|
||||
#define USB_SHORT_TO_LITTLE_ENDIAN_ADDRESS(n, m) \
|
||||
{ \
|
||||
m[1] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
|
||||
m[0] = (((uint16_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_SHORT_FROM_LITTLE_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[1]) << 8U) | (((uint16_t)n[0]) << 0U)))
|
||||
|
||||
#define USB_SHORT_TO_BIG_ENDIAN_ADDRESS(n, m) \
|
||||
{ \
|
||||
m[0] = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
|
||||
m[1] = (((uint16_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_SHORT_FROM_BIG_ENDIAN_ADDRESS(n) ((uint16_t)((((uint16_t)n[0]) << 8U) | (((uint16_t)n[1]) << 0U)))
|
||||
|
||||
#define USB_LONG_TO_LITTLE_ENDIAN_DATA(n, m) \
|
||||
{ \
|
||||
*((uint8_t *)&(m) + 3) = ((((uint32_t)(n)) >> 24U) & 0xFFU); \
|
||||
*((uint8_t *)&(m) + 2) = ((((uint32_t)(n)) >> 16U) & 0xFFU); \
|
||||
*((uint8_t *)&(m) + 1) = ((((uint32_t)(n)) >> 8U) & 0xFFU); \
|
||||
*((uint8_t *)&(m) + 0) = (((uint32_t)(n)) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_LONG_FROM_LITTLE_ENDIAN_DATA(n) \
|
||||
((uint32_t)(((uint32_t)(*((uint8_t *)&(n) + 3)) << 24U) | ((uint32_t)(*((uint8_t *)&(n) + 2)) << 16U) | \
|
||||
((uint32_t)(*((uint8_t *)&(n) + 1)) << 8U) | ((uint32_t)(*((uint8_t *)&(n))) << 0U)))
|
||||
|
||||
#define USB_SHORT_TO_LITTLE_ENDIAN_DATA(n, m) \
|
||||
{ \
|
||||
*((uint8_t *)&(m) + 1) = ((((uint16_t)(n)) >> 8U) & 0xFFU); \
|
||||
*((uint8_t *)&(m)) = ((((uint16_t)(n))) & 0xFFU); \
|
||||
}
|
||||
|
||||
#define USB_SHORT_FROM_LITTLE_ENDIAN_DATA(n) \
|
||||
((uint16_t)(((uint16_t)(*(((uint8_t *)&(n)) + 1)) << 8U) | ((uint16_t)(*((uint8_t *)&(n))))))
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The following MACROs (USB_GLOBAL, USB_BDT, USB_RAM_ADDRESS_ALIGNMENT, etc) are only used for USB device stack.
|
||||
* The USB device global variables are put into the section m_usb_global and m_usb_bdt
|
||||
* by using the MACRO USB_GLOBAL and USB_BDT. In this way, the USB device
|
||||
* global variables can be linked into USB dedicated RAM by USB_STACK_USE_DEDICATED_RAM.
|
||||
* The MACRO USB_STACK_USE_DEDICATED_RAM is used to decide the USB stack uses dedicated RAM or not. The value of
|
||||
* the macro can be set as 0, USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL, or USB_STACK_DEDICATED_RAM_TYPE_BDT.
|
||||
* The MACRO USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL means USB device global variables, including USB_BDT and
|
||||
* USB_GLOBAL, are put into the USB dedicated RAM. This feature can only be enabled when the USB dedicated RAM
|
||||
* is not less than 2K Bytes.
|
||||
* The MACRO USB_STACK_DEDICATED_RAM_TYPE_BDT means USB device global variables, only including USB_BDT, are put
|
||||
* into the USB dedicated RAM, the USB_GLOBAL will be put into .bss section. This feature is used for some SOCs,
|
||||
* the USB dedicated RAM size is not more than 512 Bytes.
|
||||
*/
|
||||
#define USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL 1
|
||||
#define USB_STACK_DEDICATED_RAM_TYPE_BDT 2
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
|
||||
#define USB_WEAK_VAR __attribute__((weak))
|
||||
#define USB_WEAK_FUN __attribute__((weak))
|
||||
/* disable misra 19.13 */
|
||||
_Pragma("diag_suppress=Pm120")
|
||||
#define USB_ALIGN_PRAGMA(x) _Pragma(#x)
|
||||
_Pragma("diag_default=Pm120")
|
||||
|
||||
#define USB_RAM_ADDRESS_ALIGNMENT(n) USB_ALIGN_PRAGMA(data_alignment = n)
|
||||
_Pragma("diag_suppress=Pm120")
|
||||
#define USB_LINK_SECTION_PART(str) _Pragma(#str)
|
||||
#define USB_LINK_DMA_INIT_DATA(sec) USB_LINK_SECTION_PART(location = #sec)
|
||||
#define USB_LINK_USB_GLOBAL _Pragma("location = \"m_usb_global\"")
|
||||
#define USB_LINK_USB_BDT _Pragma("location = \"m_usb_bdt\"")
|
||||
#define USB_LINK_USB_GLOBAL_BSS
|
||||
#define USB_LINK_USB_BDT_BSS
|
||||
_Pragma("diag_default=Pm120")
|
||||
#define USB_LINK_DMA_NONINIT_DATA _Pragma("location = \"m_usb_dma_noninit_data\"")
|
||||
#define USB_LINK_NONCACHE_NONINIT_DATA _Pragma("location = \"NonCacheable\"")
|
||||
#elif defined(__CC_ARM) || (defined(__ARMCC_VERSION))
|
||||
|
||||
#define USB_WEAK_VAR __attribute__((weak))
|
||||
#define USB_WEAK_FUN __attribute__((weak))
|
||||
#define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
|
||||
#define USB_LINK_DMA_INIT_DATA(sec) __attribute__((section(#sec)))
|
||||
#if defined(__CC_ARM)
|
||||
#define USB_LINK_USB_GLOBAL __attribute__((section("m_usb_global"))) __attribute__((zero_init))
|
||||
#else
|
||||
#define USB_LINK_USB_GLOBAL __attribute__((section(".bss.m_usb_global")))
|
||||
#endif
|
||||
#if defined(__CC_ARM)
|
||||
#define USB_LINK_USB_BDT __attribute__((section("m_usb_bdt"))) __attribute__((zero_init))
|
||||
#else
|
||||
#define USB_LINK_USB_BDT __attribute__((section(".bss.m_usb_bdt")))
|
||||
#endif
|
||||
#define USB_LINK_USB_GLOBAL_BSS
|
||||
#define USB_LINK_USB_BDT_BSS
|
||||
#if defined(__CC_ARM)
|
||||
#define USB_LINK_DMA_NONINIT_DATA __attribute__((section("m_usb_dma_noninit_data"))) __attribute__((zero_init))
|
||||
#else
|
||||
#define USB_LINK_DMA_NONINIT_DATA __attribute__((section(".bss.m_usb_dma_noninit_data")))
|
||||
#endif
|
||||
#if defined(__CC_ARM)
|
||||
#define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section("NonCacheable"))) __attribute__((zero_init))
|
||||
#else
|
||||
#define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section(".bss.NonCacheable")))
|
||||
#endif
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
|
||||
#define USB_WEAK_VAR __attribute__((weak))
|
||||
#define USB_WEAK_FUN __attribute__((weak))
|
||||
#define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
|
||||
#define USB_LINK_DMA_INIT_DATA(sec) __attribute__((section(#sec)))
|
||||
#define USB_LINK_USB_GLOBAL __attribute__((section("m_usb_global, \"aw\", %nobits @")))
|
||||
#define USB_LINK_USB_BDT __attribute__((section("m_usb_bdt, \"aw\", %nobits @")))
|
||||
#define USB_LINK_USB_GLOBAL_BSS
|
||||
#define USB_LINK_USB_BDT_BSS
|
||||
#define USB_LINK_DMA_NONINIT_DATA __attribute__((section("m_usb_dma_noninit_data, \"aw\", %nobits @")))
|
||||
#define USB_LINK_NONCACHE_NONINIT_DATA __attribute__((section("NonCacheable, \"aw\", %nobits @")))
|
||||
|
||||
#elif (defined(__DSC__) && defined(__CW__))
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#define USB_WEAK_VAR __attribute__((weak))
|
||||
#define USB_WEAK_FUN __attribute__((weak))
|
||||
#define USB_RAM_ADDRESS_ALIGNMENT(n) __attribute__((aligned(n)))
|
||||
#define USB_LINK_USB_BDT_BSS
|
||||
#define USB_LINK_USB_GLOBAL_BSS
|
||||
#else
|
||||
#error The tool-chain is not supported.
|
||||
#endif
|
||||
|
||||
#if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
|
||||
(defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
|
||||
|
||||
#if ((defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE)) && (defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)))
|
||||
#define USB_CACHE_LINESIZE MAX(FSL_FEATURE_L2CACHE_LINESIZE_BYTE, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
|
||||
#elif (defined(FSL_FEATURE_L2CACHE_LINESIZE_BYTE))
|
||||
#define USB_CACHE_LINESIZE MAX(FSL_FEATURE_L2CACHE_LINESIZE_BYTE, 0)
|
||||
#elif (defined(FSL_FEATURE_L1DCACHE_LINESIZE_BYTE))
|
||||
#define USB_CACHE_LINESIZE MAX(0, FSL_FEATURE_L1DCACHE_LINESIZE_BYTE)
|
||||
#else
|
||||
#define USB_CACHE_LINESIZE 4U
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define USB_CACHE_LINESIZE 4U
|
||||
#endif
|
||||
|
||||
#if (((defined(USB_DEVICE_CONFIG_LPCIP3511FS)) && (USB_DEVICE_CONFIG_LPCIP3511FS > 0U)) || \
|
||||
((defined(USB_DEVICE_CONFIG_LPCIP3511HS)) && (USB_DEVICE_CONFIG_LPCIP3511HS > 0U)))
|
||||
#define USB_DATA_ALIGN 64U
|
||||
#else
|
||||
#define USB_DATA_ALIGN 4U
|
||||
#endif
|
||||
|
||||
#if (USB_CACHE_LINESIZE > USB_DATA_ALIGN)
|
||||
#define USB_DATA_ALIGN_SIZE USB_CACHE_LINESIZE
|
||||
#else
|
||||
#define USB_DATA_ALIGN_SIZE USB_DATA_ALIGN
|
||||
#endif
|
||||
|
||||
#define USB_DATA_ALIGN_SIZE_MULTIPLE(n) (((n) + USB_DATA_ALIGN_SIZE - 1U) & (~(USB_DATA_ALIGN_SIZE - 1U)))
|
||||
|
||||
#if defined(USB_STACK_USE_DEDICATED_RAM) && (USB_STACK_USE_DEDICATED_RAM == USB_STACK_DEDICATED_RAM_TYPE_BDT_GLOBAL)
|
||||
|
||||
#define USB_GLOBAL USB_LINK_USB_GLOBAL
|
||||
#define USB_BDT USB_LINK_USB_BDT
|
||||
|
||||
#if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
|
||||
(defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
|
||||
#define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
|
||||
#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(m_usb_dma_init_data)
|
||||
#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#else
|
||||
#if (defined(DATA_SECTION_IS_CACHEABLE) && (DATA_SECTION_IS_CACHEABLE))
|
||||
#define USB_DMA_DATA_NONINIT_SUB USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(NonCacheable.init)
|
||||
#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#else
|
||||
#define USB_DMA_DATA_NONINIT_SUB
|
||||
#define USB_DMA_DATA_INIT_SUB
|
||||
#define USB_CONTROLLER_DATA USB_LINK_USB_GLOBAL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif defined(USB_STACK_USE_DEDICATED_RAM) && (USB_STACK_USE_DEDICATED_RAM == USB_STACK_DEDICATED_RAM_TYPE_BDT)
|
||||
|
||||
#define USB_BDT USB_LINK_USB_BDT
|
||||
|
||||
#if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
|
||||
(defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
|
||||
#define USB_GLOBAL USB_LINK_DMA_NONINIT_DATA
|
||||
#define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
|
||||
#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(m_usb_dma_init_data)
|
||||
#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#else
|
||||
#if (defined(DATA_SECTION_IS_CACHEABLE) && (DATA_SECTION_IS_CACHEABLE))
|
||||
#define USB_GLOBAL USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#define USB_DMA_DATA_NONINIT_SUB USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(NonCacheable.init)
|
||||
#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#else
|
||||
#define USB_GLOBAL USB_LINK_USB_GLOBAL_BSS
|
||||
#define USB_DMA_DATA_NONINIT_SUB
|
||||
#define USB_DMA_DATA_INIT_SUB
|
||||
#define USB_CONTROLLER_DATA
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
|
||||
(defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
|
||||
|
||||
#define USB_GLOBAL USB_LINK_DMA_NONINIT_DATA
|
||||
#define USB_BDT USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#define USB_DMA_DATA_NONINIT_SUB USB_LINK_DMA_NONINIT_DATA
|
||||
#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(m_usb_dma_init_data)
|
||||
#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
|
||||
|
||||
#else
|
||||
|
||||
#if (defined(DATA_SECTION_IS_CACHEABLE) && (DATA_SECTION_IS_CACHEABLE))
|
||||
#define USB_GLOBAL USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#define USB_BDT USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#define USB_DMA_DATA_NONINIT_SUB USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#define USB_DMA_DATA_INIT_SUB USB_LINK_DMA_INIT_DATA(NonCacheable.init)
|
||||
#define USB_CONTROLLER_DATA USB_LINK_NONCACHE_NONINIT_DATA
|
||||
#else
|
||||
#define USB_GLOBAL USB_LINK_USB_GLOBAL_BSS
|
||||
#define USB_BDT USB_LINK_USB_BDT_BSS
|
||||
#define USB_DMA_DATA_NONINIT_SUB
|
||||
#define USB_DMA_DATA_INIT_SUB
|
||||
#define USB_CONTROLLER_DATA
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#define USB_DMA_NONINIT_DATA_ALIGN(n) USB_RAM_ADDRESS_ALIGNMENT(n) USB_DMA_DATA_NONINIT_SUB
|
||||
#define USB_DMA_INIT_DATA_ALIGN(n) USB_RAM_ADDRESS_ALIGNMENT(n) USB_DMA_DATA_INIT_SUB
|
||||
|
||||
#if (defined(USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_DEVICE_CONFIG_BUFFER_PROPERTY_CACHEABLE)) || \
|
||||
(defined(USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE) && (USB_HOST_CONFIG_BUFFER_PROPERTY_CACHEABLE))
|
||||
#define USB_DMA_DATA_NONCACHEABLE USB_LINK_NONCACHE_NONINIT_DATA
|
||||
|
||||
#else
|
||||
#define USB_DMA_DATA_NONCACHEABLE
|
||||
#endif
|
||||
|
||||
#define USB_GLOBAL_DEDICATED_RAM USB_LINK_USB_GLOBAL
|
||||
|
||||
/* #define USB_RAM_ADDRESS_NONCACHEREG_ALIGNMENT(n, var) AT_NONCACHEABLE_SECTION_ALIGN(var, n) */
|
||||
/* #define USB_RAM_ADDRESS_NONCACHEREG(var) AT_NONCACHEABLE_SECTION(var) */
|
||||
|
||||
#endif /* __USB_MISC_H__ */
|
||||
299
usb/include/usb_spec.h
Normal file
299
usb/include/usb_spec.h
Normal file
@@ -0,0 +1,299 @@
|
||||
/*
|
||||
* Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef __USB_SPEC_H__
|
||||
#define __USB_SPEC_H__
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
|
||||
/* USB speed (the value cannot be changed because EHCI QH use the value directly)*/
|
||||
#define USB_SPEED_FULL (0x00U)
|
||||
#define USB_SPEED_LOW (0x01U)
|
||||
#define USB_SPEED_HIGH (0x02U)
|
||||
#define USB_SPEED_SUPER (0x04U)
|
||||
|
||||
/* Set up packet structure */
|
||||
typedef struct _usb_setup_struct
|
||||
{
|
||||
uint8_t bmRequestType;
|
||||
uint8_t bRequest;
|
||||
uint16_t wValue;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
} usb_setup_struct_t;
|
||||
|
||||
/* USB standard descriptor endpoint type */
|
||||
#define USB_ENDPOINT_CONTROL (0x00U)
|
||||
#define USB_ENDPOINT_ISOCHRONOUS (0x01U)
|
||||
#define USB_ENDPOINT_BULK (0x02U)
|
||||
#define USB_ENDPOINT_INTERRUPT (0x03U)
|
||||
|
||||
/* USB standard descriptor transfer direction (cannot change the value because iTD use the value directly) */
|
||||
#define USB_OUT (0U)
|
||||
#define USB_IN (1U)
|
||||
|
||||
/* USB standard descriptor length */
|
||||
#define USB_DESCRIPTOR_LENGTH_DEVICE (0x12U)
|
||||
#define USB_DESCRIPTOR_LENGTH_CONFIGURE (0x09U)
|
||||
#define USB_DESCRIPTOR_LENGTH_INTERFACE (0x09U)
|
||||
#define USB_DESCRIPTOR_LENGTH_ENDPOINT (0x07U)
|
||||
#define USB_DESCRIPTOR_LENGTH_ENDPOINT_COMPANION (0x06U)
|
||||
#define USB_DESCRIPTOR_LENGTH_DEVICE_QUALITIER (0x0AU)
|
||||
#define USB_DESCRIPTOR_LENGTH_OTG_DESCRIPTOR (5U)
|
||||
#define USB_DESCRIPTOR_LENGTH_BOS_DESCRIPTOR (5U)
|
||||
#define USB_DESCRIPTOR_LENGTH_DEVICE_CAPABILITY_USB20_EXTENSION (0x07U)
|
||||
#define USB_DESCRIPTOR_LENGTH_DEVICE_CAPABILITY_SUPERSPEED (0x0AU)
|
||||
|
||||
/* USB Device Capability Type Codes */
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY_WIRELESS (0x01U)
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY_USB20_EXTENSION (0x02U)
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY_SUPERSPEED (0x03U)
|
||||
|
||||
/* USB standard descriptor type */
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE (0x01U)
|
||||
#define USB_DESCRIPTOR_TYPE_CONFIGURE (0x02U)
|
||||
#define USB_DESCRIPTOR_TYPE_STRING (0x03U)
|
||||
#define USB_DESCRIPTOR_TYPE_INTERFACE (0x04U)
|
||||
#define USB_DESCRIPTOR_TYPE_ENDPOINT (0x05U)
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE_QUALITIER (0x06U)
|
||||
#define USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION (0x07U)
|
||||
#define USB_DESCRIPTOR_TYPE_INTERFAACE_POWER (0x08U)
|
||||
#define USB_DESCRIPTOR_TYPE_OTG (0x09U)
|
||||
#define USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION (0x0BU)
|
||||
#define USB_DESCRIPTOR_TYPE_BOS (0x0F)
|
||||
#define USB_DESCRIPTOR_TYPE_DEVICE_CAPABILITY (0x10)
|
||||
|
||||
#define USB_DESCRIPTOR_TYPE_HID (0x21U)
|
||||
#define USB_DESCRIPTOR_TYPE_HID_REPORT (0x22U)
|
||||
#define USB_DESCRIPTOR_TYPE_HID_PHYSICAL (0x23U)
|
||||
|
||||
#define USB_DESCRIPTOR_TYPE_ENDPOINT_COMPANION (0x30U)
|
||||
|
||||
/* USB standard request type */
|
||||
#define USB_REQUEST_TYPE_DIR_MASK (0x80U)
|
||||
#define USB_REQUEST_TYPE_DIR_SHIFT (7U)
|
||||
#define USB_REQUEST_TYPE_DIR_OUT (0x00U)
|
||||
#define USB_REQUEST_TYPE_DIR_IN (0x80U)
|
||||
|
||||
#define USB_REQUEST_TYPE_TYPE_MASK (0x60U)
|
||||
#define USB_REQUEST_TYPE_TYPE_SHIFT (5U)
|
||||
#define USB_REQUEST_TYPE_TYPE_STANDARD (0U)
|
||||
#define USB_REQUEST_TYPE_TYPE_CLASS (0x20U)
|
||||
#define USB_REQUEST_TYPE_TYPE_VENDOR (0x40U)
|
||||
|
||||
#define USB_REQUEST_TYPE_RECIPIENT_MASK (0x1FU)
|
||||
#define USB_REQUEST_TYPE_RECIPIENT_SHIFT (0U)
|
||||
#define USB_REQUEST_TYPE_RECIPIENT_DEVICE (0x00U)
|
||||
#define USB_REQUEST_TYPE_RECIPIENT_INTERFACE (0x01U)
|
||||
#define USB_REQUEST_TYPE_RECIPIENT_ENDPOINT (0x02U)
|
||||
#define USB_REQUEST_TYPE_RECIPIENT_OTHER (0x03U)
|
||||
|
||||
/* USB standard request */
|
||||
#define USB_REQUEST_STANDARD_GET_STATUS (0x00U)
|
||||
#define USB_REQUEST_STANDARD_CLEAR_FEATURE (0x01U)
|
||||
#define USB_REQUEST_STANDARD_SET_FEATURE (0x03U)
|
||||
#define USB_REQUEST_STANDARD_SET_ADDRESS (0x05U)
|
||||
#define USB_REQUEST_STANDARD_GET_DESCRIPTOR (0x06U)
|
||||
#define USB_REQUEST_STANDARD_SET_DESCRIPTOR (0x07U)
|
||||
#define USB_REQUEST_STANDARD_GET_CONFIGURATION (0x08U)
|
||||
#define USB_REQUEST_STANDARD_SET_CONFIGURATION (0x09U)
|
||||
#define USB_REQUEST_STANDARD_GET_INTERFACE (0x0AU)
|
||||
#define USB_REQUEST_STANDARD_SET_INTERFACE (0x0BU)
|
||||
#define USB_REQUEST_STANDARD_SYNCH_FRAME (0x0CU)
|
||||
|
||||
/* USB standard request GET Status */
|
||||
#define USB_REQUEST_STANDARD_GET_STATUS_DEVICE_SELF_POWERED_SHIFT (0U)
|
||||
#define USB_REQUEST_STANDARD_GET_STATUS_DEVICE_REMOTE_WARKUP_SHIFT (1U)
|
||||
|
||||
#define USB_REQUEST_STANDARD_GET_STATUS_ENDPOINT_HALT_MASK (0x01U)
|
||||
#define USB_REQUEST_STANDARD_GET_STATUS_ENDPOINT_HALT_SHIFT (0U)
|
||||
|
||||
#define USB_REQUEST_STANDARD_GET_STATUS_OTG_STATUS_SELECTOR (0xF000U)
|
||||
|
||||
/* USB standard request CLEAR/SET feature */
|
||||
#define USB_REQUEST_STANDARD_FEATURE_SELECTOR_ENDPOINT_HALT (0U)
|
||||
#define USB_REQUEST_STANDARD_FEATURE_SELECTOR_DEVICE_REMOTE_WAKEUP (1U)
|
||||
#define USB_REQUEST_STANDARD_FEATURE_SELECTOR_DEVICE_TEST_MODE (2U)
|
||||
#define USB_REQUEST_STANDARD_FEATURE_SELECTOR_B_HNP_ENABLE (3U)
|
||||
#define USB_REQUEST_STANDARD_FEATURE_SELECTOR_A_HNP_SUPPORT (4U)
|
||||
#define USB_REQUEST_STANDARD_FEATURE_SELECTOR_A_ALT_HNP_SUPPORT (5U)
|
||||
|
||||
/* USB standard descriptor configure bmAttributes */
|
||||
#define USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_MASK (0x80U)
|
||||
#define USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_SHIFT (7U)
|
||||
|
||||
#define USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_SELF_POWERED_MASK (0x40U)
|
||||
#define USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_SELF_POWERED_SHIFT (6U)
|
||||
|
||||
#define USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_REMOTE_WAKEUP_MASK (0x20U)
|
||||
#define USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_REMOTE_WAKEUP_SHIFT (5U)
|
||||
|
||||
/* USB standard descriptor endpoint bmAttributes */
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_MASK (0x80U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT (7U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_OUT (0U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_IN (0x80U)
|
||||
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ADDRESS_NUMBER_MASK (0x0FU)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ADDRESS_NUMBER_SHFIT (0U)
|
||||
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_TYPE_MASK (0x03U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_NUMBER_SHFIT (0U)
|
||||
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_SYNC_TYPE_MASK (0x0CU)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_SYNC_TYPE_SHFIT (2U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_SYNC_TYPE_NO_SYNC (0x00U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_SYNC_TYPE_ASYNC (0x04U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_SYNC_TYPE_ADAPTIVE (0x08U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_SYNC_TYPE_SYNC (0x0CU)
|
||||
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_USAGE_TYPE_MASK (0x30U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_USAGE_TYPE_SHFIT (4U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_USAGE_TYPE_DATA_ENDPOINT (0x00U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_USAGE_TYPE_FEEDBACK_ENDPOINT (0x10U)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_ATTRIBUTE_USAGE_TYPE_IMPLICIT_FEEDBACK_DATA_ENDPOINT (0x20U)
|
||||
|
||||
#define USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_SIZE_MASK (0x07FFu)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_MULT_TRANSACTIONS_MASK (0x1800u)
|
||||
#define USB_DESCRIPTOR_ENDPOINT_MAXPACKETSIZE_MULT_TRANSACTIONS_SHFIT (11U)
|
||||
|
||||
/* USB standard descriptor otg bmAttributes */
|
||||
#define USB_DESCRIPTOR_OTG_ATTRIBUTES_SRP_MASK (0x01u)
|
||||
#define USB_DESCRIPTOR_OTG_ATTRIBUTES_HNP_MASK (0x02u)
|
||||
#define USB_DESCRIPTOR_OTG_ATTRIBUTES_ADP_MASK (0x04u)
|
||||
|
||||
/* USB standard descriptor device capability usb20 extension bmAttributes */
|
||||
#define USB_DESCRIPTOR_DEVICE_CAPABILITY_USB20_EXTENSION_LPM_MASK (0x02U)
|
||||
#define USB_DESCRIPTOR_DEVICE_CAPABILITY_USB20_EXTENSION_LPM_SHIFT (1U)
|
||||
#define USB_DESCRIPTOR_DEVICE_CAPABILITY_USB20_EXTENSION_BESL_MASK (0x04U)
|
||||
#define USB_DESCRIPTOR_DEVICE_CAPABILITY_USB20_EXTENSION_BESL_SHIFT (2U)
|
||||
|
||||
/* Language structure */
|
||||
typedef struct _usb_language
|
||||
{
|
||||
uint8_t **string; /* The Strings descriptor array */
|
||||
uint32_t *length; /* The strings descriptor length array */
|
||||
uint16_t languageId; /* The language id of current language */
|
||||
} usb_language_t;
|
||||
|
||||
typedef struct _usb_language_list
|
||||
{
|
||||
uint8_t *languageString; /* The String 0U pointer */
|
||||
uint32_t stringLength; /* The String 0U Length */
|
||||
usb_language_t *languageList; /* The language list */
|
||||
uint8_t count; /* The language count */
|
||||
} usb_language_list_t;
|
||||
|
||||
typedef struct _usb_descriptor_common
|
||||
{
|
||||
uint8_t bLength; /* Size of this descriptor in bytes */
|
||||
uint8_t bDescriptorType; /* DEVICE Descriptor Type */
|
||||
uint8_t bData[1]; /* Data */
|
||||
} usb_descriptor_common_t;
|
||||
|
||||
typedef struct _usb_descriptor_device
|
||||
{
|
||||
uint8_t bLength; /* Size of this descriptor in bytes */
|
||||
uint8_t bDescriptorType; /* DEVICE Descriptor Type */
|
||||
uint8_t bcdUSB[2]; /* UUSB Specification Release Number in Binary-Coded Decimal, e.g. 0x0200U */
|
||||
uint8_t bDeviceClass; /* Class code */
|
||||
uint8_t bDeviceSubClass; /* Sub-Class code */
|
||||
uint8_t bDeviceProtocol; /* Protocol code */
|
||||
uint8_t bMaxPacketSize0; /* Maximum packet size for endpoint zero */
|
||||
uint8_t idVendor[2]; /* Vendor ID (assigned by the USB-IF) */
|
||||
uint8_t idProduct[2]; /* Product ID (assigned by the manufacturer) */
|
||||
uint8_t bcdDevice[2]; /* Device release number in binary-coded decimal */
|
||||
uint8_t iManufacturer; /* Index of string descriptor describing manufacturer */
|
||||
uint8_t iProduct; /* Index of string descriptor describing product */
|
||||
uint8_t iSerialNumber; /* Index of string descriptor describing the device serial number */
|
||||
uint8_t bNumConfigurations; /* Number of possible configurations */
|
||||
} usb_descriptor_device_t;
|
||||
|
||||
typedef struct _usb_descriptor_configuration
|
||||
{
|
||||
uint8_t bLength; /* Descriptor size in bytes = 9U */
|
||||
uint8_t bDescriptorType; /* CONFIGURATION type = 2U or 7U */
|
||||
uint8_t wTotalLength[2]; /* Length of concatenated descriptors */
|
||||
uint8_t bNumInterfaces; /* Number of interfaces, this configuration. */
|
||||
uint8_t bConfigurationValue; /* Value to set this configuration. */
|
||||
uint8_t iConfiguration; /* Index to configuration string */
|
||||
uint8_t bmAttributes; /* Configuration characteristics */
|
||||
uint8_t bMaxPower; /* Maximum power from bus, 2 mA units */
|
||||
} usb_descriptor_configuration_t;
|
||||
|
||||
typedef struct _usb_descriptor_interface
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bInterfaceNumber;
|
||||
uint8_t bAlternateSetting;
|
||||
uint8_t bNumEndpoints;
|
||||
uint8_t bInterfaceClass;
|
||||
uint8_t bInterfaceSubClass;
|
||||
uint8_t bInterfaceProtocol;
|
||||
uint8_t iInterface;
|
||||
} usb_descriptor_interface_t;
|
||||
|
||||
typedef struct _usb_descriptor_endpoint
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bEndpointAddress;
|
||||
uint8_t bmAttributes;
|
||||
uint8_t wMaxPacketSize[2];
|
||||
uint8_t bInterval;
|
||||
} usb_descriptor_endpoint_t;
|
||||
|
||||
typedef struct _usb_descriptor_endpoint_companion
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bMaxBurst;
|
||||
uint8_t bmAttributes;
|
||||
uint8_t wBytesPerInterval[2];
|
||||
} usb_descriptor_endpoint_companion_t;
|
||||
|
||||
typedef struct _usb_descriptor_binary_device_object_store
|
||||
{
|
||||
uint8_t bLength; /* Descriptor size in bytes = 5U */
|
||||
uint8_t bDescriptorType; /* BOS Descriptor type = 0FU*/
|
||||
uint8_t wTotalLength[2]; /*Length of this descriptor and all of its sub descriptors*/
|
||||
uint8_t bNumDeviceCaps; /*The number of separate device capability descriptors in the BOS*/
|
||||
} usb_descriptor_bos_t;
|
||||
|
||||
typedef struct _usb_descriptor_usb20_extension
|
||||
{
|
||||
uint8_t bLength; /* Descriptor size in bytes = 7U */
|
||||
uint8_t bDescriptorType; /* DEVICE CAPABILITY Descriptor type = 0x10U*/
|
||||
uint8_t bDevCapabilityType; /*Length of this descriptor and all of its sub descriptors*/
|
||||
uint8_t bmAttributes[4]; /*Bitmap encoding of supported device level features.*/
|
||||
} usb_descriptor_usb20_extension_t;
|
||||
typedef struct _usb_descriptor_super_speed_device_capability
|
||||
{
|
||||
uint8_t bLength;
|
||||
uint8_t bDescriptorType;
|
||||
uint8_t bDevCapabilityType;
|
||||
uint8_t bmAttributes;
|
||||
uint8_t wSpeedsSupported[2];
|
||||
uint8_t bFunctionalitySupport;
|
||||
uint8_t bU1DevExitLat;
|
||||
uint8_t wU2DevExitLat[2];
|
||||
} usb_bos_device_capability_susperspeed_desc_t;
|
||||
typedef union _usb_descriptor_union
|
||||
{
|
||||
usb_descriptor_common_t common; /* Common descriptor */
|
||||
usb_descriptor_device_t device; /* Device descriptor */
|
||||
usb_descriptor_configuration_t configuration; /* Configuration descriptor */
|
||||
usb_descriptor_interface_t interface; /* Interface descriptor */
|
||||
usb_descriptor_endpoint_t endpoint; /* Endpoint descriptor */
|
||||
usb_descriptor_endpoint_companion_t endpointCompanion; /* Endpoint companion descriptor */
|
||||
} usb_descriptor_union_t;
|
||||
|
||||
#endif /* __USB_SPEC_H__ */
|
||||
Reference in New Issue
Block a user