📄 chap_9.c
字号:
/**************************************************************************
特性设置
***************************************************************************/
void SetFeature(void)
{
UINT8 endp;
UINT8 bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
if (bRecipient == USB_RECIPIENT_DEVICE //设置远程唤醒功能
&& ControlData.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP)
{
bEPPflags.bits.remote_wakeup = 1;
ep0in_ack();
}
else if (bRecipient == USB_RECIPIENT_ENDPOINT //设置端点stall
&& ControlData.DeviceRequest.wValue == USB_FEATURE_ENDPOINT_STALL)
{
endp = (UINT8)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
if (ControlData.DeviceRequest.wIndex & (UINT8)USB_ENDPOINT_DIRECTION_MASK)
endp = endp * 2 + 1;
else
endp = endp * 2;
MUSBHSFC_SetEndpointStatus(endp, 1); // clear RX/TX stall for OUT/IN on EPn.
ep0in_ack();
}
else
stall_ep0();
}
/**************************************************************************
设置地址
***************************************************************************/
void set_address(void)
{
return;
}
#endif
/********************************************************************
Routine : UsbGetDescriptor
Input : Void
Output : Length of the descriptor that has got
Function : Get descriptors of the device according to the CHAPTER9
*********************************************************************/
UINT32 UsbGetDescriptor()
{
UINT32 total_len, req_len;
UINT16 type;
UINT16 index;
UINT8 *str_ptr = (UINT8 *)(scUsbDscr + 18 + 10 + (9 + 9 + 7 * 3) * 2);
UINT8 *fuspd_cfg_ptr = (UINT8 *)(scUsbDscr + 18 + 10 + 9 + 9 + 7 * 3); //全速配置描述符
UINT8 *hispd_cfg_ptr = (UINT8 *)(scUsbDscr + 18 + 10); //高速配置描述符
UINT8 *edp_ptr;
#ifdef DEBUG
//serial_printf("UsbGetDescriptor\n");
#endif
type = (SetupRequestData.wValue & 0xff00) >> 8;
index = (SetupRequestData.wValue & 0x00ff);
total_len = 0;
switch (type)
{
case DEV_DSCR_TYPE:
#ifdef DEBUG
serial_printf(" Device descriptor!\n");
#endif
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 0x12;
uControlDataSize = total_len;
memcpy(CtrlInBuffer, scUsbDscr, total_len);
if (bIsFullSpeed) //add by lxs for win2000 USB1.1 @2008.03.04
{
CtrlInBuffer[2] = 0x10;
CtrlInBuffer[3] = 0x01;
}
break;
case CFG_DSCR_TYPE:
#ifdef DEBUG
serial_printf(" Config descriptor!\n");
#endif
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 9 + 9 + 7 * 3;
uControlDataSize = total_len; //oli 2007-6-1 21:52
if (bIsFullSpeed)
{
memcpy(CtrlInBuffer, fuspd_cfg_ptr, total_len);
}
else
{
memcpy(CtrlInBuffer, hispd_cfg_ptr, total_len);
}
break;
case STR_DSCR_TYPE:
switch (index)
{
case 0:
#ifdef DEBUG
serial_printf(" String decscripotr 0!\n");
#endif
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 4;
uControlDataSize = total_len;
memcpy(CtrlInBuffer, str_ptr, total_len);
break;
case 1:
#ifdef DEBUG
serial_printf(" String decscripotr 1!\n");
#endif
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 18;
uControlDataSize = total_len;
memcpy(CtrlInBuffer, str_ptr + 4, total_len);
break;
case 2:
#ifdef DEBUG
serial_printf(" String decscripotr 2!\n");
#endif
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 18;
uControlDataSize = total_len;
memcpy(CtrlInBuffer, str_ptr + 4 + 18, total_len);
break;
case 3:
#ifdef DEBUG
serial_printf(" String decscripotr 3!\n");
#endif
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 18;
uControlDataSize = total_len;
memcpy(CtrlInBuffer, str_ptr + 4 + 18 + 18, total_len);
break;
default:
#ifdef DEBUG
serial_printf(" String decscripotr 4!\n");
#endif
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 18;
uControlDataSize = total_len;
memcpy(CtrlInBuffer, str_ptr + 4, total_len);
break;
}
break;
case INTF_DSCR_TYPE:
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 9;
if (bIsFullSpeed)
{
memcpy(CtrlInBuffer, fuspd_cfg_ptr + 9, total_len);
}
else
{
memcpy(CtrlInBuffer, hispd_cfg_ptr + 9, total_len);
}
break;
case EDP_DSCR_TYPE:
#ifdef DEBUG
serial_printf(" EndPoiint descriptor!\n");
#endif
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 7;
if (bIsFullSpeed)
{
edp_ptr = fuspd_cfg_ptr + 9 + 9;
}
else
{
edp_ptr = hispd_cfg_ptr + 9 + 9;
}
/* for each endpoint's descriptor */
/* endpoint number */
/* switch ( index ) {
case 0:
memcpy( CtrlInBuffer, edp_ptr, total_len );
break;
case 1:
memcpy( CtrlInBuffer, edp_ptr + 7, total_len );
break;
case 2:
memcpy( CtrlInBuffer, edp_ptr + 7 + 7, total_len );
break;
default:
bRequestError = YES;
break;
} */
memcpy(CtrlInBuffer, edp_ptr + (index * 7), total_len);
break;
case QUAL_DSCR_TYPE:
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
#ifdef DEBUG
serial_printf(" Qual descriptor!\n");
#endif
total_len = 10;
uControlDataSize = total_len;
memcpy(CtrlInBuffer, scUsbDscr + 0x12, total_len);
break;
case OTHERSPD_DSCR_TYPE:
#ifdef DEBUG
serial_printf(" Other speed descriptor!\n");
#endif
CtrlInBuffer = Ctr_buf; //oli 2007-6-1 22:17
total_len = 9 + 9 + 7 * 3;
if (bIsFullSpeed)
{
memcpy(CtrlInBuffer, fuspd_cfg_ptr, total_len);
}
else
{
memcpy(CtrlInBuffer, hispd_cfg_ptr, total_len);
}
break;
default:
#ifdef DEBUG
serial_printf(" Get decsriptor : request error!\n");
#endif
bRequestError = YES;
break;
}
if (bRequestError)
{
// write stall
TX0_STALL;
}
else
{
// start ctrl-in transfer
req_len = SetupRequestData.wLength;
}
UsbCtlSetZeroData(total_len);
if (req_len < total_len)
{
total_len = req_len;
uControlDataSize = total_len; //oli 2007-6-1 21:53
}
UsbWriteCtlEP(total_len, CtrlInBuffer);
return (total_len);
}
/**************************************************************************
获取配置状态
***************************************************************************/
#if 0
void GetConfiguration(void)
{
UINT8 c = bEPPflags.bits.configuration;
single_transmit(&c, 1);
}
/**************************************************************************
设置配置状态
***************************************************************************/
void SetConfiguration(void)
{
return;
}
/**************************************************************************
获取接口状态
***************************************************************************/
void GetInterface(void)
{
UINT8 txdat = bEPPflags.bits.Alter_Interface; //Only/Current interface = 0
if (ControlData.DeviceRequest.wValue == 0)
{
single_transmit(&txdat, 1);
}
}
/**************************************************************************
设置接口状态
***************************************************************************/
void SetInterface(void)
{
if (ControlData.DeviceRequest.wValue == 0x0100 && ControlData.DeviceRequest.wIndex == 0)
bEPPflags.bits.Alter_Interface = 1;
if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0x0100)
bEPPflags.bits.Alter_Interface = 0;
if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0)
bEPPflags.bits.Alter_Interface = 0;
ep0in_ack();
}
#endif
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -