修改原来端点描述符
/* Standard video streaming interface descriptor (Alternate setting 1) */
0x09, /* Descriptor size */
CY_U3P_USB_INTRFC_DESCR, /* Interface Descriptor type */
0x01, /* Interface number: 1 */
0x01, /* Alternate setting number: 0 */
0x01, /* Number of end points: 1 Bulk Endpoint */
0x0E, /* Interface class : CC_VIDEO */
0x02, /* Interface sub class : SC_VIDEOSTREAMING */
0x00, /* Interface protocol code : PC_PROTOCOL_UNDEFINED */
0x00, /* Interface descriptor string index */
/* 视频传输端点描述符 Endpoint Descriptor for BULK Streaming Video Data */
0x07, /* Descriptor size */
CY_U3P_USB_ENDPNT_DESCR, /* Endpoint Descriptor Type */
CX3_EP_BULK_VIDEO, /* Endpoint address and description: EP 3 IN */
0x05, /* ISO endpoint type */
0x00, /* LS Byte of maximum packet size. */
0x04, /* MS Byte of maximum packet size. */
0x01, /* Servicing interval for data transfers */
/* Super Speed Endpoint Companion Descriptor */
0x06, /* Descriptor size */
CY_U3P_SS_EP_COMPN_DESCR, /* SS Endpoint Companion Descriptor Type */
CY_FX_PKTS_PER_BURST-1, /* Max no. of packets in a burst 0-15,从0开始计数 */
CY_FX_BURST_PER_SOF-1, /* Mult setting: Number of bursts per service interval. */
CY_U3P_GET_LSB(CY_FX_PKTS_MAX_SIZE),/* LS Byte of data per interval. */
CY_U3P_GET_MSB(CY_FX_PKTS_MAX_SIZE) /* MS Byte of data per interval. */
打开cycx3_uvc.h文件中调试CX3_DEBUG_ENABLED
打印信息如下
bType=0x0,bTarget=0x1,bRequest=0xB,wValue=0x0,wIndex=0x1,wLength=0x0 //设置接口请求
UsbCB: IF = 1, ALT = 0
bType=0x0,bTarget=0x1,bRequest=0x0,wValue=0x0,wIndex=0x0,wLength=0x2 //获取接口状态, 程序中返回[0,0]
bType=0x0,bTarget=0x1,bRequest=0xB,wValue=0x0,wIndex=0x1,wLength=0x0//设置接口请求
UsbCB: IF = 1, ALT = 0
...中间是ucv类请求
bType=0x0,bTarget=0x1,bRequest=0x3,wValue=0x0,wIndex=0x100,wLength=0x0 //设置特性请求, 接口号=0x100不知道是什么
StpCB:In SET_FTR 0::1 //设置接口事件
bType=0x0,bTarget=0x1,bRequest=0x3,wValue=0x0,wIndex=0x0,wLength=0x0
StpCB:In SET_FTR 0::1
bType=0x0,bTarget=0x1,bRequest=0x3,wValue=0x0,wIndex=0x100,wLength=0x0
StpCB:In SET_FTR 0::1
bType=0x0,bTarget=0x1,bRequest=0x3,wValue=0x0,wIndex=0x0,wLength=0x0
StpCB:In SET_FTR 0::1
bType=0x0,bTarget=0x1,bRequest=0x3,wValue=0x0,wIndex=0x100,wLength=0x0
StpCB:In SET_FTR 0::1
Setup事件函数
static CyBool_t
CyCx3AppUSBSetupCB (
uint32_t setupdat0, /* SETUP Data 0 */
uint32_t setupdat1 /* SETUP Data 1 */
)
{
CyU3PReturnStatus_t status = CY_U3P_SUCCESS;
uint8_t bRequest, bType,bRType, bTarget;
uint16_t wValue, wIndex;
uint8_t ep0Buf[2];
uint8_t temp = 0;
CyBool_t isHandled = CyFalse;
uint8_t *ctrl_src = 0;
#ifdef STILL_CAPTURE_ENABLE
uint32_t eventFlag;
uint16_t readCount = 0;
#endif
#if CX3_DEBUG_ENABLED
uint16_t wLength;
#endif
/* Decode the fields from the setup request. */
//D7数据传送方向 0=主机到设备 1=设备到主机;
bRType = (setupdat0 & CY_U3P_USB_REQUEST_TYPE_MASK);//获取第一字节
bType = (bRType & CY_U3P_USB_TYPE_MASK);//D6~5请求类型 0=标准 1=类 2=厂商 3=保留
bTarget = (bRType & CY_U3P_USB_TARGET_MASK);//D4~0请求的接收者 0=设备 1=接口 2=端点 3=其他
bRequest = ((setupdat0 & CY_U3P_USB_REQUEST_MASK) >> CY_U3P_USB_REQUEST_POS);//请求代码0 获取状态,1清除特性,3设置特性
wValue = ((setupdat0 & CY_U3P_USB_VALUE_MASK) >> CY_U3P_USB_VALUE_POS);//数值域
wIndex = ((setupdat1 & CY_U3P_USB_INDEX_MASK) >> CY_U3P_USB_INDEX_POS);//索引域
#if CX3_DEBUG_ENABLED
wLength = ((setupdat1 & CY_U3P_USB_LENGTH_MASK) >> CY_U3P_USB_LENGTH_POS);
// CyU3PDebugPrint(4, "bRType = 0x%x, bRequest = 0x%x, wValue = 0x%x, wIndex = 0x%x, wLength= 0x%x\r\n",
// bRType, bRequest, wValue, wIndex, wLength);
CyU3PDebugPrint(4, "bType=0x%x,bTarget=0x%x,bRequest=0x%x,wValue=0x%x,wIndex=0x%x,wLength=0x%x\r\n",
bType, bTarget, bRequest, wValue, wIndex, wLength);
#endif
/* ClearFeature(Endpoint_Halt) received on the Streaming Endpoint. Stop Streaming */
//端点清除特性 bTarget=2,bRequest=1,wIndex=0x83,wValue=0
if((bTarget == CY_U3P_USB_TARGET_ENDPT) && (bRequest == CY_U3P_USB_SC_CLEAR_FEATURE)
&& (wIndex == CX3_EP_BULK_VIDEO) && (wValue == CY_U3P_USBX_FS_EP_HALT))
{
if ((glIsApplnActive) && (glIsStreamingStarted))
{
glIsClearFeature = CyTrue;
CyCx3AppStop();
CyU3PDebugPrint(4, "ClearFeature AppStop\r\n");
}
return CyFalse;
}
//获取设备状态bRType=0x80
if(bRType == CY_U3P_USB_GS_DEVICE)
{
/* Make sure that we bring the link back to U0, so that the ERDY can be sent. */
if (CyU3PUsbGetSpeed () == CY_U3P_SUPER_SPEED)
CyU3PUsbSetLinkPowerState (CyU3PUsbLPM_U0);
}
//接口设置/清除特性 bTarget=1,bRequest=3 || bRequest=1
if ( (bTarget == CY_U3P_USB_TARGET_INTF) && ((bRequest == CY_U3P_USB_SC_SET_FEATURE) || (bRequest == CY_U3P_USB_SC_CLEAR_FEATURE)) //接口的设置/清除特性
&& (wValue == 0) )
{
#if CX3_DEBUG_ENABLED
CyU3PDebugPrint (4, "StpCB:In SET_FTR %d::%d\r\n", glIsApplnActive, glIsConfigured);
#endif
if ( glIsConfigured )
CyU3PUsbAckSetup ();
else
CyU3PUsbStall (0, CyTrue, CyFalse);
return CyTrue;
}
//获取接口状态请求 bTarget=1,bRequest=0
if( (bRequest == CY_U3P_USB_SC_GET_STATUS) && (bTarget == CY_U3P_USB_TARGET_INTF) )
{
/* We support only interface 0. */
if (wIndex == 0) //接口0
{
ep0Buf[0] = 0;//返回接口0和1状态
ep0Buf[1] = 0;
CyU3PUsbSendEP0Data (0x02, ep0Buf);
}
else
CyU3PUsbStall (0, CyTrue, CyFalse);
return CyTrue;
}
/* Check for UVC Class Requests */
if ( bType == CY_U3P_USB_CLASS_RQT )//类请求0x20,bRType D6-5 = 1
{
//uvc类请求省略代码
}
return isHandled;
}
USB事件回调掉函数
static void
CyCx3AppUSBEventCB (
CyU3PUsbEventType_t evtype, /* Event type */
uint16_t evdata /* Event data */
)
{
uint8_t interface = 0, altSetting = 0;
switch (evtype)
{
case CY_U3P_USB_EVENT_SUSPEND:
/* Suspend the device with Wake On Bus Activity set */
glIsStreamingStarted = CyFalse;
CyU3PEventSet (&glCx3Event, CX3_USB_SUSP_EVENT_FLAG, CYU3P_EVENT_OR);
break;
case CY_U3P_USB_EVENT_SETINTF:
/* Start the video streamer application if the
* interface requested was 1. If not, stop the
* streamer. */
interface = CY_U3P_GET_MSB(evdata);
altSetting = CY_U3P_GET_LSB(evdata);
/* Make sure that the endpoint toggles/sequence numbers are cleared. */
glIsClearFeature = CyTrue;
#if CX3_DEBUG_ENABLED
CyU3PDebugPrint(4,"UsbCB: IF = %d, ALT = %d\r\n", interface, altSetting);
#endif
glIsStreamingStarted = CyFalse;
/* Stop the application before re-starting. */
if (glIsApplnActive)
{
CyCx3AppStop ();
}
//if ((altSetting == CX3_APP_STREAM_INTERFACE) && (interface == 1))
if ( (altSetting != 0) && (interface == 1) )
{
// /* Stop the application before re-starting. */
// if (glIsApplnActive)
// {
// CyCx3AppStop ();
// }
CyCx3AppStart ();
}
break;
/* Intentional Fall-through all cases */
case CY_U3P_USB_EVENT_SETCONF:
{
glIsStreamingStarted = CyFalse;
if(glIsApplnActive)
CyCx3AppStop ();
if(evdata!=0)
glIsConfigured = CyTrue;
break;
}
case CY_U3P_USB_EVENT_RESET:
case CY_U3P_USB_EVENT_DISCONNECT:
case CY_U3P_USB_EVENT_CONNECT:
glIsStreamingStarted = CyFalse;
// if ( evtype == CY_U3P_USB_EVENT_SETCONF )//设置配置
// glIsConfigured = CyTrue;
// else
// glIsConfigured = CyFalse;
/* Stop the video streamer application and enable LPM. */
CyU3PUsbLPMEnable ();
if (glIsApplnActive)
{
#if CX3_DEBUG_ENABLED
CyU3PDebugPrint (4, "\n\rUsbCB:Call AppStop");
#endif
CyCx3AppStop ();
}
break;
case CY_U3P_USB_EVENT_SOF_ITP://SOF事件,在3.0和2.0中125us一次,同步传输在这里提交缓冲区
break;
default:
break;
}
}
现在问题是不能打开视频流了, 请求大神解答
|
|