Strip out unnecessary callbacks and code in USBD driver

This is important for the bootloader. There's a bunch of stuff here we
don't need that unnecessarily bloats the code.
This commit is contained in:
Doug Brown 2023-08-06 20:35:27 -07:00 committed by Doug Brown
parent 2a96427047
commit 2c35f61c88
2 changed files with 2 additions and 111 deletions

View File

@ -58,10 +58,7 @@ static volatile uint32_t s_USBD_u32CtrlOutToggle = 0ul;
const S_USBD_INFO_T *g_USBD_sINFO; /*!< A pointer for USB information structure */
VENDOR_REQ g_USBD_pfnVendorRequest = NULL; /*!< USB Vendor Request Functional Pointer */
CLASS_REQ g_USBD_pfnClassRequest = NULL; /*!< USB Class Request Functional Pointer */
SET_INTERFACE_REQ g_USBD_pfnSetInterface = NULL; /*!< USB Set Interface Functional Pointer */
SET_CONFIG_CB g_USBD_pfnSetConfigCallback = NULL; /*!< USB Set configuration callback function pointer */
uint32_t g_USBD_u32EpStallLock = 0ul; /*!< Bit map flag to lock specified EP when SET_FEATURE */
/**
@ -69,16 +66,14 @@ uint32_t g_USBD_u32EpStallLock = 0ul; /*!< Bit map flag to lock s
*
* @param[in] param The structure of USBD information.
* @param[in] pfnClassReq USB Class request callback function.
* @param[in] pfnSetInterface USB Set Interface request callback function.
*
*
* @details This function will enable USB controller, USB PHY transceiver and pull-up resistor of USB_D+ pin. USB PHY will drive SE0 to bus.
*/
void USBD_Open(const S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface)
void USBD_Open(const S_USBD_INFO_T *param, CLASS_REQ pfnClassReq)
{
g_USBD_sINFO = param;
g_USBD_pfnClassRequest = pfnClassReq;
g_USBD_pfnSetInterface = pfnSetInterface;
/* get EP0 maximum packet size */
s_USBD_u32CtrlMaxPktSize = g_USBD_sINFO->gu8DevDesc[7];
@ -159,16 +154,6 @@ void USBD_ProcessSetupPacket(void)
break;
}
case REQ_VENDOR: /* Vendor */
{
if (g_USBD_pfnVendorRequest != NULL)
{
g_USBD_pfnVendorRequest();
}
break;
}
default: /* reserved */
{
/* Setup error, stall the device */
@ -239,58 +224,6 @@ void USBD_GetDescriptor(void)
break;
}
/* Get BOS Descriptor */
case DESC_BOS:
{
if (g_USBD_sINFO->gu8BosDesc)
{
u32Len = USBD_Minimum(u32Len, LEN_BOS + LEN_DEVCAP);
USBD_PrepareCtrlIn((uint8_t *)g_USBD_sINFO->gu8BosDesc, u32Len);
}
else
{
USBD_SET_EP_STALL(EP0);
USBD_SET_EP_STALL(EP1);
}
break;
}
/* Get HID Descriptor */
case DESC_HID:
{
/* CV3.0 HID Class Descriptor Test,
Need to indicate index of the HID Descriptor within gu8ConfigDescriptor, specifically HID Composite device. */
uint32_t u32ConfigDescOffset; /* u32ConfigDescOffset is configuration descriptor offset (HID descriptor start index) */
u32Len = USBD_Minimum(u32Len, LEN_HID);
DBG_PRINTF("Get HID desc, %d\n", u32Len);
u32ConfigDescOffset = g_USBD_sINFO->gu32ConfigHidDescIdx[g_USBD_au8SetupPacket[4]];
USBD_PrepareCtrlIn((uint8_t *)&g_USBD_sINFO->gu8ConfigDesc[u32ConfigDescOffset], u32Len);
break;
}
/* Get Report Descriptor */
case DESC_HID_RPT:
{
DBG_PRINTF("Get HID report, %d\n", u32Len);
if (u32Len > g_USBD_sINFO->gu32HidReportSize[g_USBD_au8SetupPacket[4]])
{
u32Len = g_USBD_sINFO->gu32HidReportSize[g_USBD_au8SetupPacket[4]];
if ((u32Len % s_USBD_u32CtrlMaxPktSize) == 0ul)
{
s_USBD_u8CtrlInZeroFlag = (uint8_t)1ul;
}
}
USBD_PrepareCtrlIn((uint8_t *)g_USBD_sINFO->gu8HidReportDesc[g_USBD_au8SetupPacket[4]], u32Len);
break;
}
/* Get String Descriptor */
case DESC_STRING:
{
@ -499,9 +432,6 @@ void USBD_StandardRequest(void)
{
s_USBD_u32UsbConfig = g_USBD_au8SetupPacket[2];
if (g_USBD_pfnSetConfigCallback)
g_USBD_pfnSetConfigCallback();
/* Status stage */
USBD_SET_DATA1(EP0);
USBD_SET_PAYLOAD_LEN(EP0, 0ul);
@ -535,11 +465,6 @@ void USBD_StandardRequest(void)
{
s_USBD_u32UsbAltInterface = g_USBD_au8SetupPacket[2];
if (g_USBD_pfnSetInterface != NULL)
{
g_USBD_pfnSetInterface(s_USBD_u32UsbAltInterface);
}
/* Status stage */
USBD_SET_DATA1(EP0);
USBD_SET_PAYLOAD_LEN(EP0, 0ul);
@ -740,32 +665,6 @@ void USBD_SwReset(void)
USBD_SET_ADDR(0ul);
}
/**
* @brief USBD Set Vendor Request
*
* @param[in] pfnVendorReq Vendor Request Callback Function
*
*
* @details This function is used to set USBD vendor request callback function
*/
void USBD_SetVendorRequest(VENDOR_REQ pfnVendorReq)
{
g_USBD_pfnVendorRequest = pfnVendorReq;
}
/**
* @brief The callback function which called when get SET CONFIGURATION request
*
* @param[in] pfnSetConfigCallback Callback function pointer for SET CONFIGURATION request
*
*
* @details This function is used to set the callback function which will be called at SET CONFIGURATION request.
*/
void USBD_SetConfigCallback(SET_CONFIG_CB pfnSetConfigCallback)
{
g_USBD_pfnSetConfigCallback = pfnSetConfigCallback;
}
/**
* @brief EP stall lock function to avoid stall clear by USB SET FEATURE request.

View File

@ -44,10 +44,6 @@ typedef struct s_usbd_info
uint8_t *gu8DevDesc; /*!< Pointer for USB Device Descriptor */
uint8_t *gu8ConfigDesc; /*!< Pointer for USB Configuration Descriptor */
uint8_t **gu8StringDesc; /*!< Pointer for USB String Descriptor pointers */
uint8_t **gu8HidReportDesc; /*!< Pointer for USB HID Report Descriptor */
uint8_t *gu8BosDesc; /*!< Pointer for USB BOS Descriptor */
uint32_t *gu32HidReportSize; /*!< Pointer for HID Report descriptor Size */
uint32_t *gu32ConfigHidDescIdx; /*!< Pointer for HID Descriptor start index */
} S_USBD_INFO_T; /*!< Device description structure */
extern const S_USBD_INFO_T gsInfo;
@ -637,12 +633,10 @@ extern volatile uint8_t g_USBD_u8RemoteWakeupEn;
typedef void (*VENDOR_REQ)(void); /*!< Functional pointer type definition for Vendor class */
typedef void (*CLASS_REQ)(void); /*!< Functional pointer type declaration for USB class request callback handler */
typedef void (*SET_INTERFACE_REQ)(uint32_t u32AltInterface); /*!< Functional pointer type declaration for USB set interface request callback handler */
typedef void (*SET_CONFIG_CB)(void); /*!< Functional pointer type declaration for USB set configuration request callback handler */
/*--------------------------------------------------------------------*/
void USBD_Open(const S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface);
void USBD_Open(const S_USBD_INFO_T *param, CLASS_REQ pfnClassReq);
void USBD_Start(void);
void USBD_GetSetupPacket(uint8_t *buf);
void USBD_ProcessSetupPacket(void);
@ -652,8 +646,6 @@ void USBD_CtrlIn(void);
void USBD_PrepareCtrlOut(uint8_t *pu8Buf, uint32_t u32Size);
void USBD_CtrlOut(void);
void USBD_SwReset(void);
void USBD_SetVendorRequest(VENDOR_REQ pfnVendorReq);
void USBD_SetConfigCallback(SET_CONFIG_CB pfnSetConfigCallback);
void USBD_LockEpStall(uint32_t u32EpBitmap);
/** @} end of group USBD_EXPORTED_FUNCTIONS */