📄 usb_common.c
字号:
* Return: UsbCommStatus_t
*
* Description: USB Clear Device feature implement
*
*************************************************************************/
static inline
UsbCommStatus_t UsbClearDevFeature(Int16U Feature,Int16U Index)
{
if((Index != 0) || (Feature != UsbDeviceRemoteWakeupSelector))
{
USB_T9W_TRACE_INFO("T9W UsbSetEpFeature()\n\r"
" Index (0==) - %d\n\r"
" Feature (1==) - %d\n\r",
Feature,Index);
return(UsbFault);
}
USB_T9M_TRACE_INFO("T9M UsbSetEpFeature()\n\r"
" Index - %d\n\r"
" Feature - %d\n\r",
Feature,Index);
UsbDevCtrl.Feature.RemoteWakeupEnable = 0;
return(UsbPass);
}
/*************************************************************************
* Function Name: UsbClearInterfaceFeature
* Parameters: Int16U Feature,Int16U Index
*
* Return: UsbCommStatus_t
*
* Description: USB Clear Interface feature implement
*
*************************************************************************/
static inline
UsbCommStatus_t UsbClearInterfaceFeature(Int16U Feature,Int16U Index)
{
USB_T9W_TRACE_INFO("T9W UsbClearInterfaceFeature() unsupported\n\r");
return(UsbFault);
}
/*************************************************************************
* Function Name: UsbClearEpFeature
* Parameters: Int16U Feature,Int16U Index
*
* Return: UsbCommStatus_t
*
* Description: USB Clear EP feature implement
*
*************************************************************************/
static inline
UsbCommStatus_t UsbClearEpFeature(Int16U Feature,Int16U Index)
{
USB_Endpoint_t UsbEpAdd;
if(((Index & 0x7F) > 16) || (Feature != UsbEpHaltSelector))
{
USB_T9W_TRACE_INFO("T9W UsbClearEpFeature()\n\r"
" Index (16<) - %d\n\r"
" Feature (0==) - %d\n\r",
Feature,Index);
return(UsbFault);
}
UsbEpAdd = USB_EpLogToPhysAdd(Index);
USB_SetStallEP(UsbEpAdd,FALSE);
if (UsbUserFun[UsbUserEpUnStall] != NULL)
{
UsbUserFun[UsbUserEpUnStall]((void *)UsbEpAdd);
}
USB_T9M_TRACE_INFO("T9M UsbClearEpFeature()\n\r"
" Index - %d\n\r"
" Feature - %d\n\r",
Feature,Index);
return(UsbPass);
}
/*************************************************************************
* Function Name: UsbClearFeature
* Parameters: none
*
* Return: none
*
* Description: USB Clear feature implement
*
*************************************************************************/
static inline
void UsbClearFeature (void)
{
if((UsbDevCtrl.State.DS >= UsbDevStatusAddress) &&
// Length must be 0
(UsbEp0SetupPacket.wLength.Word == 0))
{
switch(UsbEp0SetupPacket.mRequestType.Recipient)
{
case UsbRecipientDevice:
if(UsbClearDevFeature(UsbEp0SetupPacket.wValue.Word,UsbEp0SetupPacket.wIndex.Word) == UsbPass)
{
UsbEp0Ctrl.Counter = 0;
UsbEp0Ctrl.EpStatus.Status = UsbDataPhase;
}
else
{
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
break;
case UsbRecipientInterface:
if((UsbDevCtrl.State.DS > UsbDevStatusAddress) &&
(UsbClearInterfaceFeature(UsbEp0SetupPacket.wValue.Word,UsbEp0SetupPacket.wIndex.Word) == UsbPass))
{
UsbEp0Ctrl.Counter = 0;
UsbEp0Ctrl.EpStatus.Status = UsbDataPhase;
}
else
{
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
break;
case UsbRecipientEndpoint:
if(((UsbDevCtrl.State.DS > UsbDevStatusAddress) || ((UsbEp0SetupPacket.wIndex.Word & 0x7F) == 0)) &&
(UsbClearEpFeature(UsbEp0SetupPacket.wValue.Word,UsbEp0SetupPacket.wIndex.Word) == UsbPass))
{
UsbEp0Ctrl.Counter = 0;
UsbEp0Ctrl.EpStatus.Status = UsbDataPhase;
}
else
{
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
break;
default:
USB_T9W_TRACE_INFO("T9W UsbClearFeature() unknow recipient\n\r");
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
}
else
{
USB_T9W_TRACE_INFO("T9W UsbClearFeature()\n\r"
" State.DS (4>=) - %d\n\r"
" wLength.Word (0==) - %d\n\r",
UsbDevCtrl.State.DS,UsbEp0SetupPacket.wLength.Word);
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
}
/*************************************************************************
* Function Name: UsbSetFeature
* Parameters: Int16U Feature,Int16U Index
*
* Return: UsbCommStatus_t
*
* Description: USB Set Device feature implement
*
*************************************************************************/
static inline
UsbCommStatus_t UsbSetDevFeature(Int16U Feature,Int16U Index)
{
if((Index != 0) || (Feature != UsbDeviceRemoteWakeupSelector))
{
USB_T9W_TRACE_INFO("T9W UsbSetEpFeature()\n\r"
" Index (0==) - %d\n\r"
" Feature (1==) - %d\n\r",
Feature,Index);
return(UsbFault);
}
USB_T9M_TRACE_INFO("T9M UsbSetEpFeature()\n\r"
" Index - %d\n\r"
" Feature - %d\n\r",
Feature,Index);
UsbDevCtrl.Feature.RemoteWakeupEnable = 1;
return(UsbPass);
}
/*************************************************************************
* Function Name: UsbSetInterfaceFeature
* Parameters: Int16U Feature,Int16U Index
*
* Return: UsbCommStatus_t
*
* Description: USB Set Interface feature implement
*
*************************************************************************/
static inline
UsbCommStatus_t UsbSetInterfaceFeature(Int16U Feature,Int16U Index)
{
USB_T9W_TRACE_INFO("T9W UsbSetInterfaceFeature() unsupported\n\r");
return(UsbFault);
}
/*************************************************************************
* Function Name: UsbSetEpFeature
* Parameters: Int16U Feature,Int16U Index
*
* Return: UsbCommStatus_t
*
* Description: USB Set EP feature implement
*
*************************************************************************/
static inline
UsbCommStatus_t UsbSetEpFeature(Int16U Feature,Int16U Index)
{
USB_Endpoint_t UsbEpAdd;
if(((Index & 0x7F) > 16) || (Feature != UsbEpHaltSelector))
{
USB_T9W_TRACE_INFO("T9W UsbSetEpFeature()\n\r"
" Index (16<) - %d\n\r"
" Feature (0==) - %d\n\r",
Feature,Index);
return(UsbFault);
}
UsbEpAdd = USB_EpLogToPhysAdd(Index);
USB_SetStallEP(UsbEpAdd,TRUE);
if (UsbUserFun[UsbUserEpStall] != NULL)
{
UsbUserFun[UsbUserEpStall]((void *)UsbEpAdd);
}
USB_T9M_TRACE_INFO("T9M UsbSetEpFeature()\n\r"
" Index - %d\n\r"
" Feature - %d\n\r",
Feature,Index);
return(UsbPass);
}
/*************************************************************************
* Function Name: UsbSetFeature
* Parameters: none
*
* Return: none
*
* Description: USB Set feature implement
*
*************************************************************************/
static inline
void UsbSetFeature (void)
{
if((UsbDevCtrl.State.DS >= UsbDevStatusAddress) &&
// Length must be 0
(UsbEp0SetupPacket.wLength.Word == 0))
{
switch(UsbEp0SetupPacket.mRequestType.Recipient)
{
case UsbRecipientDevice:
if(UsbSetDevFeature(UsbEp0SetupPacket.wValue.Word,UsbEp0SetupPacket.wIndex.Word) == UsbPass)
{
UsbEp0Ctrl.Counter = 0;
UsbEp0Ctrl.EpStatus.Status = UsbDataPhase;
}
else
{
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
break;
case UsbRecipientInterface:
if((UsbDevCtrl.State.DS > UsbDevStatusAddress) &&
(UsbSetInterfaceFeature(UsbEp0SetupPacket.wValue.Word,UsbEp0SetupPacket.wIndex.Word) == UsbPass))
{
UsbEp0Ctrl.Counter = 0;
UsbEp0Ctrl.EpStatus.Status = UsbDataPhase;
}
else
{
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
break;
case UsbRecipientEndpoint:
if(((UsbDevCtrl.State.DS > UsbDevStatusAddress) || ((UsbEp0SetupPacket.wIndex.Lo & 0x7F) == 0)) &&
(UsbSetEpFeature(UsbEp0SetupPacket.wValue.Word,UsbEp0SetupPacket.wIndex.Word) == UsbPass))
{
UsbEp0Ctrl.Counter = 0;
UsbEp0Ctrl.EpStatus.Status = UsbDataPhase;
}
else
{
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
break;
default:
USB_T9W_TRACE_INFO("T9W UsbSetFeature() unknow recipient\n\r");
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
}
else
{
USB_T9W_TRACE_INFO("T9W UsbSetFeature()\n\r"
" State.DS (4>=) - %d\n\r"
" wLength.Word (0==) - %d\n\r",
UsbDevCtrl.State.DS,UsbEp0SetupPacket.wLength.Word);
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
}
/*************************************************************************
* Function Name: UsbSetAddress
* Parameters: none
*
* Return: none
*
* Description: USB Set address request implement
*
*************************************************************************/
static inline
void UsbSetAddress (void)
{
if((UsbDevCtrl.State.DS >= UsbDevStatusDefault) &&
(UsbEp0SetupPacket.mRequestType.Recipient == 0) &&
(UsbEp0SetupPacket.wIndex.Word == 0) &&
(UsbEp0SetupPacket.wLength.Word == 0) &&
(UsbEp0SetupPacket.wValue.Word < 128))
{
USB_T9M_TRACE_INFO("T9M UsbSetAddress()\n\r"
" Address - %d\n\r",
UsbEp0SetupPacket.wValue.Word);
UsbEp0Ctrl.Counter = 0;
UsbEp0Ctrl.EpStatus.Status = UsbDataPhase;
}
else
{
USB_T9W_TRACE_INFO("T9W UsbSetAddress()\n\r"
" State.DS (3>=) - %d\n\r"
" mRequestType.Recipient (0==) - %d\n\r"
" wIndex.Word (0==) - %d\n\r"
" wLength.Word (0==) - %d\n\r"
" wValue.Word (<128) - %d\n\r",
UsbDevCtrl.State.DS,UsbEp0SetupPacket.mRequestType.Recipient,
UsbEp0SetupPacket.wIndex.Word,UsbEp0SetupPacket.wLength.Word,
UsbEp0SetupPacket.wValue.Word);
UsbEp0Ctrl.EpStatus.Status = UsbEpStall;
}
}
/*************************************************************************
* Function Name: UsbGetDescriptorDevice
* Parameters: Int8U Index - must be 0
*
* Return: UsbCommStatus_t
*
* Description: USB get device's descriptor request implement
*
*************************************************************************/
static inline
UsbCommStatus_t UsbGetDescriptorDevice(Int8U Index)
{
if(Index == 0)
{
UsbEp0Ctrl.Counter = UsbStandardDeviceDescriptorStr.bLength;
UsbEp0Ctrl.EpStatus.NoZeroLength = FALSE;
if(UsbEp0Ctrl.Counter >= UsbEp0SetupPacket.wLength.Word)
{
UsbEp0Ctrl.Counter = UsbEp0SetupPacket.wLength.Word;
UsbEp0Ctrl.EpStatus.NoZeroLength = TRUE;
}
UsbEp0Ctrl.pData = (Int8U *)&UsbStandardDeviceDescriptorStr;
UsbEp0Ctrl.EpStatus.Status = UsbDataPhase;
return(UsbPass);
}
USB_T9W_TRACE_INFO("T9W UsbGetDescriptorConfiguration()\n\r"
" Index (0==) - %d\n\r",Index);
return(UsbFault);
}
/*************************************************************************
* Function Name: UsbGetDescriptorConfiguration
* Parameters: Int8U Index
*
* Return: UsbCommStatus_t
*
* Description: USB get configuration's descriptor request implement
*
*************************************************************************/
static inline
UsbCommStatus_t UsbGetDescriptorConfiguration(Int8U Index)
{
UsbStandardConfigurationDescriptor_t *pData;
for(pData = (UsbStandardConfigurationDescriptor_t *)UsbStandardConfigurationDescriptor;
pData->bLength;
pData=(UsbStandardConfigurationDescriptor_t*)((Int8U *)pData + pData->bLength))
{
if((pData->bDescriptorType == UsbDescriptorConfiguration) &&
((UsbStandardDeviceDescriptorStr.bNumConfigurations == 1) ||
(pData->bConfigurationValue == Index)))
{
break;
}
}
if(pData->bLength == 0)
{
USB_T9W_TRACE_INFO("T9W UsbGetDescriptorConfiguration()\n\r"
" pData->bLength (0==) - %d\n\r",
pData->bLength);
return(UsbFault);
}
UsbEp0Ctrl.Counter = ((UsbStandardConfigurationDescriptor_t*)pData)->wTotalLength;
UsbEp0Ctrl.EpStatus.NoZeroLength = FALSE;
if(UsbEp0Ctrl.Counter > UsbEp0SetupPacket.wLength.Word)
{
UsbEp0Ctrl.Counter = UsbEp0SetupPacket.wLength.Word;
UsbEp0Ctrl.EpStatus.NoZeroLength = TRUE;
}
UsbEp0Ctrl.pData = (Int8U *)pData;
UsbEp0Ctrl.EpStatus.Status = UsbDataPhase;
return(UsbPass);
}
/*************************************************************************
* Function Name: UsbGetDescriptorString
* Parameters: Int8U Index
*
* Return: UsbCommStatus_t
*
* Description: USB get string's descriptor request implement
*
*************************************************************************/
static inline
UsbCommStatus_t UsbGetDescriptorString(Int8U Index)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -