📄 usb_t9.c
字号:
(Int8U *)&UsbStandardDeviceDescriptorStr,
USB_T9_Size(UsbStandardDeviceDescriptorStr.bLength,UsbEp0SetupPacket.wLength.Word),
(void*)USB_StatusHandler);
return(UsbPass);
}
return(UsbFault);
}
/*************************************************************************
* Function Name: UsbGetDescriptorConfiguration
* Parameters: Int8U Index
*
* Return: UsbCommStatus_t
*
* Description: USB get configuration's descriptor request implement
*
*************************************************************************/
inline static
UsbCommStatus_t UsbGetDescriptorConfiguration(Int8U Index)
{
pUsbStandardConfigurationDescriptor_t pCfg;
if (Index >= UsbStandardDeviceDescriptorStr.bNumConfigurations)
{
return(UsbFault);
}
#if USB_HIGH_SPEED > 0
pCfg = (pUsbStandardConfigurationDescriptor_t)(*(Int8U **)UsbDescArray[(UsbDevCtrl.HighSpeed?USB_HS_CFG_ARRAY:USB_FS_CFG_ARRAY)] + Index);
#else
pCfg = (pUsbStandardConfigurationDescriptor_t)(*(Int8U **)UsbDescArray[USB_FS_CFG_ARRAY] + Index);
#endif // USB_HIGH_SPEED > 0
USB_IO_Data(CTRL_ENP_IN,
(pInt8U)pCfg,
USB_T9_Size(pCfg->wTotalLength,UsbEp0SetupPacket.wLength.Word),
(void*)USB_StatusHandler);
return(UsbPass);
}
/*************************************************************************
* Function Name: UsbGetDescriptorString
* Parameters: Int8U Index
*
* Return: UsbCommStatus_t
*
* Description: USB get string's descriptor request implement
*
*************************************************************************/
inline static
UsbCommStatus_t UsbGetDescriptorString(Int8U Index)
{
Int8U **ppData;
#if USB_HIGH_SPEED > 0
pInt8U pLangStr = (pInt8U)UsbDescArray[(UsbDevCtrl.HighSpeed?USB_HS_LANG_STR:USB_FS_LANG_STR)];
#else
pInt8U pLangStr = (pInt8U)UsbDescArray[USB_FS_LANG_STR];
#endif // USB_HIGH_SPEED > 0
Int32U i;
if(Index == 0)
{
USB_IO_Data(CTRL_ENP_IN,
pLangStr,
USB_T9_Size(pLangStr[UsbDescLengthOffset],UsbEp0SetupPacket.wLength.Word),
(void*)USB_StatusHandler);
}
else
{
Int32U LanguagesOffset = 0;
// Find Languages index
for(i = 2; i < pLangStr[UsbDescLengthOffset]; i+=2)
{
if((pLangStr[i] == UsbEp0SetupPacket.wIndex.Lo) &&
(pLangStr[i+1] == UsbEp0SetupPacket.wIndex.Hi))
{
break;
}
++LanguagesOffset;
}
if(i >= pLangStr[UsbDescLengthOffset])
{
return(UsbFault);
}
// Find String index
#if USB_HIGH_SPEED > 0
for(ppData = (*((Int8U***)UsbDescArray[(UsbDevCtrl.HighSpeed?USB_HS_STR_ARRAY:USB_FS_STR_ARRAY)] + LanguagesOffset));
#else
for(ppData = (*((Int8U***)UsbDescArray[USB_FS_STR_ARRAY] + LanguagesOffset));
#endif // USB_HIGH_SPEED > 0
ppData ;
++ppData)
{
if(--Index == 0)
{
break;
}
}
if(ppData == NULL)
{
return(UsbFault);
}
USB_IO_Data(CTRL_ENP_IN,
(pInt8U)*ppData,
USB_T9_Size(*(*ppData+UsbDescLengthOffset),UsbEp0SetupPacket.wLength.Word),
(void*)USB_StatusHandler);
}
return(UsbPass);
}
#if USB_HIGH_SPEED > 0
/*************************************************************************
* Function Name: UsbGetQualifierDescriptor
* Parameters: 眍礤
*
* Return: UsbCommStatus_t
*
* Description: USB get device's qualifier descriptor request implement
*
*************************************************************************/
inline static
UsbCommStatus_t UsbGetQualifierDescriptor(Int8U Index)
{
USB_IO_Data(CTRL_ENP_IN,
(Int8U *)&UsbQualifierDescriptor,
USB_T9_Size(UsbQualifierDescriptor.bLength,UsbEp0SetupPacket.wLength.Word),
(void*)USB_StatusHandler);
return(UsbPass);
}
/*************************************************************************
* Function Name: UsbGetOtherSpeedDescriptor
* Parameters: Int8U Index
*
* Return: UsbCommStatus_t
*
* Description: USB get device's other descriptor request implement
*
*************************************************************************/
inline static
UsbCommStatus_t UsbGetOtherSpeedDescriptorConfiguration(Int8U Index)
{
pUsbStandardConfigurationDescriptor_t pCfg;
if (Index >= UsbStandardDeviceDescriptorStr.bNumConfigurations)
{
return(UsbFault);
}
pCfg = (pUsbStandardConfigurationDescriptor_t)(*(Int8U **)UsbDescArray[(UsbDevCtrl.HighSpeed?USB_HS_OTHER_CFG_ARRAY:USB_FS_OTHER_CFG_ARRAY)] + Index);
USB_IO_Data(CTRL_ENP_IN,
(pInt8U)pCfg,
USB_T9_Size(pCfg->wTotalLength,UsbEp0SetupPacket.wLength.Word),
(void*)USB_StatusHandler);
return(UsbPass);
}
#endif // USB_HIGH_SPEED > 0
/*************************************************************************
* Function Name: UsbGetDescriptor
* Parameters: none
*
* Return: none
*
* Description: USB get descriptor request implement
*
*************************************************************************/
inline static
void UsbGetDescriptor (void)
{
if(UsbDevCtrl.State.DS >= UsbDevStatusDefault)
{
switch(UsbEp0SetupPacket.wValue.Hi)
{
case UsbDescriptorDevice:
if(UsbGetDescriptorDevice(UsbEp0SetupPacket.wValue.Lo) != UsbPass)
{
USB_T9_ERROR_REQUEST();
}
else
{
}
break;
case UsbDescriptorConfiguration:
if(UsbGetDescriptorConfiguration(UsbEp0SetupPacket.wValue.Lo) != UsbPass)
{
USB_T9_ERROR_REQUEST();
}
else
{
}
break;
case UsbDescriptorString:
if(UsbGetDescriptorString(UsbEp0SetupPacket.wValue.Lo) != UsbPass)
{
USB_T9_ERROR_REQUEST();
}
else
{
}
break;
#if USB_HIGH_SPEED > 0
case UsbDescriptorDeviceQualifier:
if(UsbGetQualifierDescriptor(UsbEp0SetupPacket.wValue.Lo) != UsbPass)
{
USB_T9_ERROR_REQUEST();
}
else
{
}
break;
case UsbDescriptorOtherSeedConfiguration:
if(UsbGetOtherSpeedDescriptorConfiguration(UsbEp0SetupPacket.wValue.Lo) != UsbPass)
{
USB_T9_ERROR_REQUEST();
}
else
{
}
break;
#endif // USB_HIGH_SPEED > 0
default:
if (USB_GET_DESCRIPTOR_HOOK(&UsbEp0SetupPacket) != UsbPass)
{
USB_T9_ERROR_REQUEST();
}
else
{
}
}
}
else
{
USB_T9_ERROR_REQUEST();
}
}
/*************************************************************************
* Function Name: UsbSetDescriptor
* Parameters: none
*
* Return: none
*
* Description: USB Set descriptor
*
*************************************************************************/
inline static
void UsbSetDescriptor(void)
{
if(UsbDevCtrl.State.DS >= UsbDevStatusAddress)
{
// This request is valid only for Address state and Configured state.
// If supported
USB_T9_ERROR_REQUEST();
}
else
{
USB_T9_ERROR_REQUEST();
}
}
/*************************************************************************
* Function Name: UsbGetConfiguration
* Parameters: none
*
* Return: none
*
* Description: USB Get configuration implement
*
*************************************************************************/
inline static
void UsbGetConfiguration(void)
{
if((UsbDevCtrl.State.DS >= UsbDevStatusAddress) &&
(UsbEp0SetupPacket.wValue.Word == 0) &&
(UsbEp0SetupPacket.wIndex.Word == 0) &&
(UsbEp0SetupPacket.wLength.Word == 1))
{
InData = UsbCoreReq(UsbCoreReqConfiquration);
USB_IO_Data(CTRL_ENP_IN,(pInt8U)&InData,1,(void*)USB_StatusHandler);
}
else
{
USB_T9_ERROR_REQUEST();
}
}
/*************************************************************************
* Function Name: UsbSetConfiguration
* Parameters: none
*
* Return: none
*
* Description: USB Set configuration implement
*
*************************************************************************/
inline static
void UsbSetConfiguration(void)
{
if((UsbDevCtrl.State.DS >= UsbDevStatusAddress) &&
(UsbEp0SetupPacket.wIndex.Word == 0) &&
(UsbEp0SetupPacket.wLength.Word == 0) &&
(UsbSetConfigurtonState(UsbEp0SetupPacket.wValue.Lo) == UsbPass))
{
USB_StatusHandler(CTRL_ENP_OUT);
}
else
{
USB_T9_ERROR_REQUEST();
}
}
/*************************************************************************
* Function Name: UsbGetInterface
* Parameters: none
*
* Return: none
*
* Description: Implement get interface request
*
*************************************************************************/
inline static
void UsbGetInterface (void)
{
if((UsbDevCtrl.State.DS == UsbDevStatusConfigured) &&
(UsbEp0SetupPacket.wIndex.Word <= UsbDevCtrl.Interfaces) &&
(UsbEp0SetupPacket.wLength.Word == 1) &&
(UsbEp0SetupPacket.wValue.Word == 0))
{
USB_IO_Data(CTRL_ENP_IN,
(pInt8U)&UsbDevCtrl.AlternateSetting[UsbEp0SetupPacket.wIndex.Word],
1,
(void*)USB_StatusHandler);
}
else
{
USB_T9_ERROR_REQUEST();
}
}
/*************************************************************************
* Function Name: UsbSetInterface
* Parameters: none
*
* Return: none
*
* Description: Implement set interface request
*
*************************************************************************/
inline static
void UsbSetInterface (void)
{
pUsbStandardInterfaceDescriptor_t pInterface, pInterfaceCurrent;
if((UsbDevCtrl.State.DS == UsbDevStatusConfigured) &&
(UsbEp0SetupPacket.wLength.Word == 0))
{
// Whether the interface is exist into current configuration?
if((pInterface = UsbFindInterface(UsbDevCtrl.pCnfg,
UsbEp0SetupPacket.wIndex.Word,
UsbEp0SetupPacket.wValue.Word)) == NULL)
{
USB_T9_ERROR_REQUEST();
return;
}
// deconfigure current alternative setting EPs
pInterfaceCurrent = UsbFindInterface(UsbDevCtrl.pCnfg,
UsbEp0SetupPacket.wIndex.Word,
UsbDevCtrl.AlternateSetting[UsbEp0SetupPacket.wIndex.Word]);
assert(pInterfaceCurrent);
UsbEpInterfaceCnfg(pInterfaceCurrent,FALSE);
// set new alternative settings
UsbDevCtrl.AlternateSetting[UsbEp0SetupPacket.wIndex.Word] = UsbEp0SetupPacket.wValue.Word;
// configure EPs
UsbEpInterfaceCnfg(pInterface,TRUE);
USB_CONFIGURE_HOOK(&UsbDevCtrl);
USB_IO_Data(CTRL_ENP_IN,NULL,0,(void*)USB_StatusHandler);
}
else
{
USB_T9_ERROR_REQUEST();
}
}
/*************************************************************************
* Function Name: UsbEpInterfaceCnfg
* Parameters: pUsbStandardInterfaceDescriptor_t pInterface
* Boolean Configure
*
* Return: none
*
* Description: Configure/deconfigure EPs of a certain interface
*
*************************************************************************/
const UsbEP_ExtData_t * USB_EP_ExtFind(Int8U EP)
{
#if USB_HIGH_SPEED > 0
const UsbEP_ExtDesc_t ** pEP_ExtCfg = ((UsbEP_ExtDesc_t **)UsbDescArray[(UsbDevCtrl.HighSpeed?USB_HS_EP_EXT_ARRAY:USB_FS_EP_EXT_ARRAY)]);
#else
UsbEP_ExtDesc_t ** pEP_ExtCfg = ((UsbEP_ExtDesc_t **)UsbDescArray[USB_FS_EP_EXT_ARRAY]);
#endif
while(*pEP_ExtCfg)
{
if ((*pEP_ExtCfg)->Configuration == UsbDevCtrl.Configuration &&
(*pEP_ExtCfg)->EndpointAddress == EP)
{
return(&((*pEP_ExtCfg)->EP_ExtData));
}
++pEP_ExtCfg;
}
return(NULL);
}
/*************************************************************************
* Function Name: UsbEpInterfaceCnfg
* Parameters: pUsbStandardInterfaceDescriptor_t pInterface
* Boolean Configure
*
* Return: none
*
* Description: Configure/deconfigure EPs of a certain interface
*
*************************************************************************/
static
void UsbEpInterfaceCnfg(pUsbStandardInterfaceDescriptor_t pInterface,
Boolean Configure)
{
pUsbStandardEpDescriptor_t pEp = NULL;
const UsbEP_ExtData_t * pUsbEP_ExtData;
assert(pInterface);
while((pEp = UsbFindEP(pInterface,pEp)) != NULL)
{
pUsbEP_ExtData = USB_EP_ExtFind(pEp->bEndpointAddress);
assert(pUsbEP_ExtData);
USB_RealizeEp(pEp,pUsbEP_ExtData,Configure);
}
}
/*************************************************************************
* Function Name: UsbSynchFrame
* Parameters: none
*
* Return: none
*
* Description: Implement synch frame request
*
*************************************************************************/
inline static
void UsbSynchFrame (void)
{
if( USB_SOF_EVENT &&
(UsbDevCtrl.State.DS == UsbDevStatusConfigured) &&
(UsbEp0SetupPacket.wLength.Word == 2) &&
(UsbEp0SetupPacket.wValue.Word == 0))
{
#if USB_SOF_EVENT > 0
InData = USB_GetFrameNumb();
#else
InData = 0;
#endif
USB_IO_Data(CTRL_ENP_IN,(pInt8U)&InData,2,(void*)USB_StatusHandler);
}
else
{
USB_T9_ERROR_REQUEST();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -