📄 drvusb.c
字号:
if (psEntry->pfnCtrlDataInCallback == NULL)
psEntry->pfnCtrlDataInCallback = DrvUSB_CtrlDataInDefault;
if (psEntry->pfnCtrlDataOutCallback == NULL)
psEntry->pfnCtrlDataOutCallback = DrvUSB_CtrlDataOutDefault;
}
return 0;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_CtrlSetupAck */
/* */
/* Parameters: */
/* pArgu [in] Parameter passed by g_sBusOps[] */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* When SETUP ack interrupt happen, this function will be called. */
/* it will call SETUP handler that DrvUSB_InstallCtrlHandler registered */
/* base on command category and command */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUSB_CtrlSetupAck(void * pArgu)
{
uint32_t i;
E_DRVUSB_STATE eUsbState;
S_DRVUSB_CTRL_CALLBACK_ENTRY *psEntry = 0;
S_DRVUSB_DEVICE *psDevice = &gsUsbDevice;
uint8_t * SetupBuffer;
volatile int32_t u32Delay;
DrvUSB_ClrCtrlReady();
/* check if after DEFAULT state (RESET) */
eUsbState = DrvUSB_GetUsbState();
if (eUsbState < eDRVUSB_DEFAULT)
{
DrvUSB_ClrCtrlReadyAndTrigStall();
return;
}
SetupBuffer = (uint8_t *)DrvUSB_GetSetupBuffer();
u32Delay = 0x1000;
while(u32Delay--);
for (i = 0; i < 8; i++)
{
psDevice->au8Setup[i] = SetupBuffer[i];
}
u32Delay = 0x1000;
while(u32Delay--);
for (i = 0; i < psDevice->CtrlCallbackSize; i++)
{
psEntry = psDevice->pCtrlCallback + i;
if (psEntry->pfnCtrlSetupCallback &&
psEntry->u8RequestType == (psDevice->au8Setup[0] & 0x60) &&
psEntry->u8Request == psDevice->au8Setup[1])
{
psEntry->pfnCtrlSetupCallback(psEntry->pVoid);
return;
}
}
DrvUSB_ClrCtrlReadyAndTrigStall();
return;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_CtrlDataInAck */
/* */
/* Parameters: */
/* pArgu [in] Parameter passed by g_sBusOps[] */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* When IN ack interrupt happen, this function will be called. */
/* it will call IN ACK handler that DrvUSB_InstallCtrlHandler registered */
/* base on command category and command */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUSB_CtrlDataInAck(void * pArgu)
{
uint32_t i;
S_DRVUSB_CTRL_CALLBACK_ENTRY *psEntry = 0;
S_DRVUSB_DEVICE *psDevice = &gsUsbDevice;
for (i = 0; i < psDevice->CtrlCallbackSize; i++)
{
psEntry = psDevice->pCtrlCallback + i;
if (psEntry->pfnCtrlDataInCallback &&
psEntry->u8RequestType == (psDevice->au8Setup[0] & 0x60) &&
psEntry->u8Request == psDevice->au8Setup[1])
{
psEntry->pfnCtrlDataInCallback(psEntry->pVoid);
return;
}
}
return;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_CtrlDataOutAck */
/* */
/* Parameters: */
/* pArgu [in] Parameter passed by g_sBusOps[] */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* When OUT ack interrupt happen, this function will be called. */
/* it will call OUT handler that DrvUSB_InstallCtrlHandler registered */
/* base on command category and command */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUSB_CtrlDataOutAck(void * pArgu)
{
uint32_t i;
S_DRVUSB_CTRL_CALLBACK_ENTRY *psEntry = 0;
S_DRVUSB_DEVICE *psDevice = &gsUsbDevice;
for (i = 0; i < psDevice->CtrlCallbackSize; i++)
{
psEntry = psDevice->pCtrlCallback + i;
if (psEntry->pfnCtrlDataOutCallback &&
psEntry->u8RequestType == (psDevice->au8Setup[0] & 0x60) &&
psEntry->u8Request == psDevice->au8Setup[1])
{
psEntry->pfnCtrlDataOutCallback(psEntry->pVoid);
return;
}
}
return;
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_CtrlDataInDefault */
/* */
/* Parameters: */
/* pVoid [in] Parameter passed by DrvUSB_InstallCtrlHandler */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* IN ACK default handler */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUSB_CtrlDataInDefault(void * pVoid)
{
S_DRVUSB_DEVICE *pInfraDevice = &gsUsbDevice;
if (pInfraDevice->au8Setup[0] & 0x80)
{
_DRVUSB_TRIG_EP(1, 0x00);
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_CtrlDataOutDefault */
/* */
/* Parameters: */
/* pVoid [in] Parameter passed by DrvUSB_InstallCtrlHandler */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* OUT ACK default handler. It is used to return zero data length */
/* packet when next IN token. */
/* */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUSB_CtrlDataOutDefault(void * pVoid)
{
S_DRVUSB_DEVICE *pInfraDevice = &gsUsbDevice;
if ((pInfraDevice->au8Setup[0] & 0x80) == 0)
{
DrvUSB_DataIn(0, NULL, 0);
}
}
/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_Reset */
/* */
/* Parameters: */
/* u32EpNum [in] EP number */
/* */
/* Returns: */
/* None */
/* */
/* Description: */
/* Restore CFGx and CFGPx register */
/* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -