公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

基于CX3的UVC摄像头应用学习笔记-五 (UVC 图像属性控制)

lock attach
Attachments are accessible only for community members.

基于CX3的UVC摄像头应用学习笔记-五 (UVC 图像属性控制)

YangyangC_06
Employee
Employee
750 replies posted 500 replies posted 250 replies posted

在本篇blog中,我们学习如何在UVC 应用中实现对图像属性的控制。本篇笔记中应用到的 固件 为 第四篇笔记​ 的附件,硬件 为 CX3 Denebola 板。

从 UVC 1.5 协议上可以看到,亮度控制属于 processing unit的内容,必需支持的控制命令有 SET_CUR、GET_CUR、GET_MIN、GET_MAX、GET_RES、GET_INFO 和 GET_DEF。

BaiduShurufa_2019-6-13_10-11-21.png

首先,在cycx3_uvcdscr.c 描述符文件中找到 processing unit 描述符部分

    /* Processing Unit Descriptor */

    0x0D,                               /* Descriptor size */

    CX3_CS_INTRFC_DESCR,                /* Class specific interface desc type */

    0x05,                               /* Processing Unit Descriptor type: VC_PROCESSING_UNIT*/

    0x02,                               /* ID of this unit */

    0x01,                               /* Source ID: 1: Conencted to input terminal */

    0x00, 0x40,                         /* Digital multiplier */

    0x03,                               /* Size of controls field for this terminal: 3 bytes */

    0x00, 0x00, 0x00,                   /* No controls supported */

    0x00,                               /* String desc index: Not used */

    0x00,                               /* Analog Video Standards Supported: None */

 

查询 UVC 协议可以看到,Byte 8/9/10 用来指定UVC支持哪些控制属性。

BaiduShurufa_2019-6-13_10-21-50.png

可以看到,bit[0] 用来指定是否支持亮度控制,所以这里我们将 bit[0] 设置为1.

    /* Processing Unit Descriptor */

    0x0D,                               /* Descriptor size */

    CX3_CS_INTRFC_DESCR,                /* Class specific interface desc type */

    0x05,                               /* Processing Unit Descriptor type: VC_PROCESSING_UNIT*/

    0x02,                               /* ID of this unit */

    0x01,                               /* Source ID: 1: Conencted to input terminal */

    0x00, 0x40,                         /* Digital multiplier */

    0x03,                               /* Size of controls field for this terminal: 3 bytes */

    0x01, 0x00, 0x00,                   /* Brigntness control is supported */

    0x00,                               /* String desc index: Not used */

    0x00,                               /* Analog Video Standards Supported: None */

 

在函数 CyCx3UvcAppUSBSetupCB 中添加如下代码

#ifdef Add_brightness_control

/* Handle Video control commands here*/

        status =  HandleVCInterfaceRequest(wIndex, wValue, bRequest);

            if (status != CY_U3P_SUCCESS)

            {

                CyU3PDebugPrint (4, "\n\rUSBStpCB:VCI SendEP0Data = %d", status);

                isHandled=CyFalse;

            }

            else

            isHandled = CyTrue;

 

#endif

添加 定义

#ifdef Add_brightness_control

 

CyU3PReturnStatus_t HandleVCInterfaceRequest(uint16_t wIndex, uint16_t wValue,uint8_t bRequest)

{

CyU3PReturnStatus_t status = CY_U3P_ERROR_BAD_ARGUMENT;

  if (CY_U3P_GET_MSB(wIndex) == CX3_UVC_VC_PROCESSING_UNIT_ID) /*Video Control- Camera Teminal*/

  {

    CyU3PDebugPrint(4,"\n\r\n\rLine:%d\tVC:T ID 0x%x CS 0x%x Req 0x%x ", __LINE__,CY_U3P_GET_MSB(wIndex), wValue, bRequest);

    switch (wValue)

    {

    case CX3_UVC_PU_BRIGHTNESS_CONTROL: /*LED control*/

        CyU3PDebugPrint(4,"\r\n Brightness control\n");

      status = HandleBrightnessControlReq(bRequest);

      break;

    default:

//       glerrorstatus = VC_ERROR_CODE_INVALID_CONTROL;

      break;

    }

  }

return status;

}

CyU3PReturnStatus_t HandleBrightnessControlReq(uint8_t bRequest)

{

CyU3PReturnStatus_t status=1;

uint16_t readCount;

uint8_t WrBuff[2]={0,0},RdBuff;

switch(bRequest)

{

case CX3_USB_UVC_GET_CUR_REQ:

WrBuff[0] = Brightness.CurrentVal;

        CyU3PDebugPrint(4,"\r\nLine:%d  UVC Brightness get cur %d\n",__LINE__,WrBuff);

break;

case CX3_USB_UVC_SET_CUR_REQ:

        status = CyU3PUsbGetEP0Data (2, &WrBuff[0], &readCount);

CyU3PDebugPrint(4,"\r\n Line:%d UVC brightness set cur %d\n",__LINE__,WrBuff);

return status;

break;

case CX3_USB_UVC_GET_MIN_REQ:

WrBuff[0] = Brightness.MinVal;

        CyU3PDebugPrint(4,"\r\n Line:%d UVC brightness get Min %d\n",__LINE__,WrBuff);

break;

case CX3_USB_UVC_GET_MAX_REQ:

WrBuff[0] = Brightness.MinVal;

        CyU3PDebugPrint(4,"\r\n Line:%d UVC brightness get Max %d\n",__LINE__,WrBuff);

break;

case CX3_USB_UVC_GET_RES_REQ:

WrBuff[0] = Brightness.Res;

        CyU3PDebugPrint(4,"\r\n Line:%d UVC brightness get RES %d\n",__LINE__,WrBuff);

break;

case CX3_USB_UVC_GET_INFO_REQ:

WrBuff[0] = Brightness.Info;

        CyU3PDebugPrint(4,"\r\n Line:%d UVC brightness get INFO %d\n",__LINE__,WrBuff);

        break;

case CX3_USB_UVC_GET_DEF_REQ:

WrBuff[0] = Brightness.DefaultVal;

        CyU3PDebugPrint(4,"\r\n Line:%d UVC brightness get default %d\n",__LINE__,WrBuff);

break;

case CX3_USB_UVC_GET_LEN_REQ:

WrBuff[0] = 2;

        CyU3PDebugPrint(4,"\r\n Line:%d UVC brightness get len %d\n",__LINE__,WrBuff);

break;

default:

CyU3PUsbStall(0,CyTrue,CyFalse);

break;

}

status = CyU3PUsbSendEP0Data(2,(uint8_t*)&WrBuff);

if (status != 0)

{

CyU3PDebugPrint(4,"\n\r Send EP0 Data failed = 0x%X", status);

}

return status;

}

#endif


关于其他必要的变量定义和函数声明,请参考附件工程。编译工程并下载到Demo板中,在E-cam viewer属性面板中我们可以看到 亮度控制已经使能。

BaiduShurufa_2019-6-13_14-1-10.png

 

更多细节信息,请参考附件工程。

添加其他控制属性的步骤和亮度控制的步骤方法一致,这里就不再重复。

附件
1883 次查看