USB -- STM32F103 USB VIDEO(视频)Camera同步传输讲解(九)

目录

链接快速定位

前沿  

1 描述符修改

1.1 设备描述符修改

1.2 配置描述符修改

1.3 字符串描述符修改

1.4 编译报错修改

2 增加功能函数

2.1 Camera功能模块介绍

2.2 USB复位函数修改

2.3 Speaker_Data_Setup函数修改

2.4 非零端点函数修改

2.5 JEPG数据获取

3 运行演示


链接快速定位

USB -- 初识USB协议(一)

源码下载请参考链接USB -- STM32-FS-USB-Device驱动代码简述(二)

USB -- STM32F103虚拟串口bulk传输讲解(三)

USB -- STM32F103自定义HID设备及HID上位机中断传输讲解(四)

USB -- STM32F103 U盘(MassStorage)SDIO接口SCSI协议Bulk传输讲解(五)

USB -- STM32F103 USB DFU设备固件升级(IAP)控制传输讲解(六)

USB -- STM32F103 USB AUDIO(音频)Speak同步传输(Out传输)讲解(七)

USB -- STM32F103 USB AUDIO(音频)Microphone同步传输(In传输)讲解(八)

Video参考手册

前沿  

        前面两节主要是对USB的基本概念做了简单讲解,学习USB的最本质目的还是要回到USB的应用方向,接下来的几章主要讲解USB的各类应用,包括:

        这里只讲怎么修改描述符和关键函数,具体含义请参考Video参考手册,我们这里使用《Audio_Speaker》例程进行修改。

1 描述符修改

        usb_desc.h文件的描述符宏定义如下:


/*预定义MJPEG视频帧率*/
#define IMG_MJPG_FRAMERATE      13
#define PACKET_SIZE             64

/*图像Size(Captured)*/
#define IMG_WIDTH                       320
#define IMG_HEIGHT                      240

#define MAKE_WORD(x)                (uint8_t)((x)&0xFF),(uint8_t)(((x)>>8)&0xFF)
#define MAKE_DWORD(x)               (uint8_t)((x)&0xFF),(uint8_t)(((x)>>8)&0xFF),(uint8_t)(((x)>>16)&0xFF),(uint8_t)(((x)>>24)&0xFF)

#define MIN_BIT_RATE            (100*320*IMG_MJPG_FRAMERATE)
#define MAX_BIT_RATE            (IMG_WIDTH*IMG_HEIGHT*IMG_MJPG_FRAMERATE)
#define MAX_FRAME_SIZE          (IMG_WIDTH*IMG_HEIGHT)          //最大每帧JPEG Byte数,对应Host要求的Buffer Size
#define FRAME_INTERVEL          (10000000ul/IMG_MJPG_FRAMERATE)     //帧间间隔时间,单位100ns

#define USB_ASSOCIATION_DESCRIPTOR_TYPE              0x0B
#define CAMERA_SIZ_DEVICE_DESC                       18
#define CAMERA_SIZ_CONFIG_DESC                       144
#define CAMERA_SIZ_STRING_LANGID                     0x04
#define CAMERA_SIZ_STRING_VENDOR                     0x26
#define CAMERA_SIZ_STRING_PRODUCT                    0x1C
#define CAMERA_SIZ_STRING_SERIAL                     0x1C

/* USB Descriptor Types */
#define USB_DEVICE_DESCRIPTOR_TYPE                    0x01
#define USB_CONFIGURATION_DESCRIPTOR_TYPE             0x02
#define USB_STRING_DESCRIPTOR_TYPE                    0x03
#define USB_INTERFACE_DESCRIPTOR_TYPE                 0x04
#define USB_ENDPOINT_DESCRIPTOR_TYPE                  0x05

1.1 设备描述符修改

const uint8_t Speaker_DeviceDescriptor[] =
{
    CAMERA_SIZ_DEVICE_DESC,          /* bLength */
    USB_DEVICE_DESCRIPTOR_TYPE,           /* bDescriptorType */
    0x00,          /* 2.00 */             /* bcdUSB */
    0x02,
    0xEF,                                 /* bDeviceClass */
    0x02,                                 /* bDeviceSubClass */
    0x01,                                 /* bDeviceProtocol */
    0x40,                                 /* bMaxPacketSize 40 */
    0x83,                                 /* idVendor */
    0x04,
    0x30,                                 /* idProduct  = 0x5730*/
    0x57,
    0x00,          /* 2.00 */             /* bcdDevice */
    0x02,
    1,                                    /* iManufacturer */
    2,                                    /* iProduct */
    3,                                    /* iSerialNumber */
    0x01                                  /* bNumConfigurations */
};

1.2 配置描述符修改

        这里包括:

  • 接口描述符
  • 功能描述符
  • 端点描述符
/* USB Configuration Descriptor */
/*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
const uint8_t Speaker_ConfigDescriptor[] =
{
    /* Configuration 1 */
    0x09,                                 /* bLength */
    USB_CONFIGURATION_DESCRIPTOR_TYPE,    /* bDescriptorType */
    0x90,                                 /* wTotalLength  110 bytes*/
    0x00,
    0x02,                                 /* bNumInterfaces */
    0x01,                                 /* bConfigurationValue */
    0x00,                                 /* iConfiguration */
    0xC0,                                 /* bmAttributes Self Powered*/
    0xFA,                                 /* bMaxPower = 500 mA*/
    /* 09 byte*/

    /* 1. Standard Video Interface Collection IAD */
    0x08,                                 /* bLength */
    USB_ASSOCIATION_DESCRIPTOR_TYPE,      /* bDescriptorType */
    0x00,                                 /* bFirstInterface: Interface number of the VideoControl interface that is associated with this function*/
    0x02,                                 /* Number of contiguous Video interfaces that are associated with this function */
    0x0E,                                 /* bFunction Class: CC_VIDEO*/
    0x03,                                 /* bFunction sub Class: SC_VIDEO_INTERFACE_COLLECTION */
    0x00,                                 /* bFunction protocol : PC_PROTOCOL_UNDEFINED*/
    0x02,                                 /* iFunction */
    /* 08 bytes, total size 17*/

    /* 2. Standard VideoControl Interface Descriptor */
    0x09,                                 /* bLength */
    0x04,                                 /* bDescriptorType */
    0x00,                                 /* bInterfaceNumber */
    0x00,                                 /* bAlternateSetting */
    0x00,                                 /* bNumEndpoints */
    0x0e,                                 /* bInterfaceClass : CC_VIDEO */
    0x01,                                 /* bInterfaceSubClass : SC_VIDEOCONTROL */
    0x00,                                 /* bInterfaceProtocol : PC_PROTOCOL_UNDEFINED */
    0x02,                                 /* iInterface */
    /* 09 bytes, total size 26*/

    /* 2.1. Class-specific VideoControl Interface Descriptor */
    0x0d,                                 /* bLength */
    0x24,                                 /* bDescriptorType : CS_INTERFACE */
    0x01,                                 /* bDescriptorSubType : VC_HEADER subtype */
    0x00,                                 /* bcdUVC : Revision of class specification that this device is based upon. For this example, the device complies with Video Class specification version 1.0 */
    0x01,
    0x1e,                                 /* wTotalLength : Total size of class-specific descriptors*/
    0x00,
    0x00, 0x60, 0xe3, 0x16,               /* dwClockFrequency : 0x16e36000 -> 24,000,000 == 24MHz*/
    0x01,                                 /* bInCollection : Number of streaming interfaces. */
    0x01,                                 /* baInterfaceNr(1) : VideoStreaming interface 1 belongs to this VideoControl interface.*/
    /* 13 Bytes, totoal size 39 */

    /* 2.2. Video Input Terminal Descriptor (Composite) */
    0x08,                                 /* bLength */
    0x24,                                 /* bDescriptorType : CS_INTERFACE */
    0x02,                                 /* bDescriptorSubType : VC_INPUT_TERMINAL subtype */
    0x02,                                 /* bTerminalID: ID of this input terminal */
    0x01, 0x04,                           /* wTerminalType: 0x0401 COMPOSITE_CONNECTOR type. This terminal is the composite connector. */
    0x00,                                 /* bAssocTerminal: No association */
    0x00,                                 /* iTerminal: Unused*/
    /* 8 Bytes, totoal size 47 */

    /* 2.3. Video Output Terminal Descriptor */
    0x09,                                 /* bLength */
    0x24,                                 /* bDescriptorType : CS_INTERFACE */
    0x03,                                 /* bDescriptorSubType : VC_OUTPUT_TERMINAL subtype */
    0x03,                                 /* bTerminalID: ID of this output terminal */
    0x01, 0x01,                           /* wTerminalType: 0x0101 TT_STREAMING type. This terminal is a USB streaming terminal. */
    0x00,                                 /* bAssocTerminal: No association */
    0x02,                                 /* bSourceID: The input pin of this unit is connected to the output pin of unit 2. */
    0x00,                                 /* iTerminal: Unused*/
    /* 9 bytes, total size 56 */

    /* 3. Standard VideoStream Interface Descriptor*/
    0x09,                                 /* bLength */
    0x04,                                 /* bDescriptorType : INTERFACE */
    0x01,                                 /* bInterfaceNumber */
    0x00,                                 /* bAlternateSetting */
    0x00,                                 /* bNumEndpoints : 0 endpoints – no bandwidth used*/
    0x0e,                                 /* bInterfaceClass : CC_VIDEO */
    0x02,                                 /* bInterfaceSubClass : SC_VIDEOSTREAMING */
    0x00,                                 /* bInterfaceProtocol : PC_PROTOCOL_UNDEFINED */
    0x00,                                 /* iInterface : unused */
    /* 9 bytes, total size 65 */

    /* 3.1 Class-specific VideoStream Header Descriptor (Input) */
    0x0e,                                 /* bLength */
    0x24,                                 /* bDescriptorType : CS_INTERFACE */
    0x01,                               
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰糖葫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值