-2

我正在 Atmega32U4 上实现 USB 网络摄像头。

我想我设法在控制端点上实现了事务,或多或少正确,因为所有描述符都在系统中传输并且设备报告正确。

问题是当我尝试从设备发送视频数据时,似乎什么都没有通过。

我实现数据传输的方式(根据datasheet的22.14节)如下:

  while (len > 0) {
    while (1) {
      cli();
      _select_endpoint(VIDEO_STREAMING_ENDPOINT);
      if (bit_is_set(UEINTX, TXINI) && bit_is_set(UEINTX, FIFOCON))
        break;
      sei();
      _delay_ms(1);
    }
    _clear_TXINI();
    while (bit_is_set(UEINTX, RWAL) && len > 0) {
      UEDATX = *buff++;
      --len;
    }
    _clear_FIFOCON();
    sei();
  }

在调试时,我注意到在第一个循环期间银行充满了数据,但数据没有传输到主机。它在 TXINI,FIFOCON 部分永远循环。Wireshark 中除了控制请求外,什么都没有显示。我不确定我是否在 MCU 寄存器上配置错误,所以它没有根据请求向主机发送数据,或者在描述符、状态等中,所以主机没有请求数据。

我可能搞砸了什么?

lsusb -v

Bus 001 Device 077: ID 6431:deb2 majkrzak majkrzak
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass          239 Miscellaneous Device
  bDeviceSubClass         2 
  bDeviceProtocol         1 Interface Association
  bMaxPacketSize0        32
  idVendor           0x6431 
  idProduct          0xdeb2 
  bcdDevice            0.00
  iManufacturer           1 majkrzak
  iProduct                1 majkrzak
  iSerial                 1 majkrzak
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x00a0
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          1 majkrzak
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Association:
      bLength                 8
      bDescriptorType        11
      bFirstInterface         0
      bInterfaceCount         2
      bFunctionClass         14 Video
      bFunctionSubClass       3 Video Interface Collection
      bFunctionProtocol       0 
      iFunction               1 majkrzak
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass        14 Video
      bInterfaceSubClass      1 Video Control
      bInterfaceProtocol      1 
      iInterface              1 majkrzak
      VideoControl Interface Descriptor:
        bLength                13
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdUVC               1.50
        wTotalLength       0x0028
        dwClockFrequency       16.000000MHz
        bInCollection           1
        baInterfaceNr( 0)       1
      VideoControl Interface Descriptor:
        bLength                18
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID             1
        wTerminalType      0x0201 Camera Sensor
        bAssocTerminal          2
        iTerminal               1 majkrzak
        wObjectiveFocalLengthMin      0
        wObjectiveFocalLengthMax      0
        wOcularFocalLength            0
        bControlSize                  3
        bmControls           0x00000000
      VideoControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID             2
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          1
        bSourceID               1
        iTerminal               1 majkrzak
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass        14 Video
      bInterfaceSubClass      2 Video Streaming
      bInterfaceProtocol      1 
      iInterface              1 majkrzak
      VideoStreaming Interface Descriptor:
        bLength                            13
        bDescriptorType                    36
        bDescriptorSubtype                  1 (INPUT_HEADER)
        bNumFormats                         1
        wTotalLength                   0x0055
        bEndpointAddress                 0x81  EP 1 IN
        bmInfo                              0
        bTerminalLink                       2
        bStillCaptureMethod                 0
        bTriggerSupport                     0
        bTriggerUsage                       0
        bControlSize                        0
        bmaControls( 0)                    27
      VideoStreaming Interface Descriptor:
        bLength                            27
        bDescriptorType                    36
        bDescriptorSubtype                  4 (FORMAT_UNCOMPRESSED)
        bFormatIndex                        1
        bNumFrameDescriptors                1
        guidFormat                            {32595559-0000-0010-8000-00aa00389b71}
        bBitsPerPixel                       8
        bDefaultFrameIndex                  0
        bAspectRatioX                       1
        bAspectRatioY                       1
        bmInterlaceFlags                 0x00
          Interlaced stream or variable: No
          Fields per frame: 2 fields
          Field 1 first: No
          Field pattern: Field 1 only
        bCopyProtect                        0
      VideoStreaming Interface Descriptor:
        bLength                            38
        bDescriptorType                    36
        bDescriptorSubtype                  5 (FRAME_UNCOMPRESSED)
        bFrameIndex                         1
        bmCapabilities                   0x02
          Still image unsupported
          Fixed frame-rate
        wWidth                             16
        wHeight                            16
        dwMinBitRate                   262144
        dwMaxBitRate                   262144
        dwMaxVideoFrameBufferSize         768
        dwDefaultFrameInterval        1000000
        bFrameIntervalType                  0
        dwMinFrameInterval            1000000
        dwMaxFrameInterval            1000000
        dwFrameIntervalStep                 0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0020  1x 32 bytes
        bInterval               1
Device Status:     0x0000
  (Bus Powered)

编辑

我制作了一个简单的脚本,pyusb用于从端点提取数据并且它可以工作。Wireshark 正在显示交易,因此这意味着在这种uvcvideo情况下根本不会提取数据。我当时肯定搞砸了描述符。

4

1 回答 1

0

uvc 驱动程序没有为设备提取任何数据的原因是您将dwMaxVideoFrameSize和设置dwMaxPayloadTransferSize0. 将其设置为适合您的情况的足够高的值,它将起作用。

于 2021-12-30T16:58:56.007 回答