USB composite equipment and working method thereof
Technical Field
The invention belongs to the field of electronic circuit design, and particularly relates to a USB composite device and a working method thereof.
Background
In the prior art, for some video input devices, such as mini DV, automobile data recorder, aerial photography device, etc., the collected images are stored in the TF/SD card after video compression. For the scheme without the display screen, if pictures or videos need to be browsed, the contents in the TF/SD card need to be copied to a computer for viewing. However, the computer provided by the prior art generally has no TF/SD card reader interface, so that a USB card reader needs to be purchased additionally, and the application is inconvenient, uneconomical and environment-friendly.
Disclosure of Invention
The embodiment of the invention aims to provide a USB composite device, and aims to solve the problems that in the prior art, when contents of TF/SD cards of certain video input devices are read, a USB card reader needs to be purchased additionally, and the application is inconvenient, uneconomic and environment-friendly.
The embodiment of the present invention is implemented as follows, a USB composite device, where the USB composite device includes a camera, a USB controller, and a USB interface connected to the USB controller, and the USB composite device further includes:
the external TF/SD card and the SD card read-write module for reading and writing the contents of the inserted TF/SD card;
the CSI module is connected with the camera and used for collecting data of an image sensor in the camera;
the video compression circuit is connected with the CSI module and used for compressing the data acquired by the CSI module;
the video compression circuit, the SD card read-write module and the USB controller are connected, the SD card read-write module is controlled to write the data processed by the video compression circuit into the TF/SD card, and when the USB interface is connected with a host and used as a storage device, the SD card read-write module is matched with the USB controller to realize the read-write operation of the TF/SD card, and when the USB interface is connected with the host and used as a video device, the USB interface is matched with the USB controller to synchronously transmit the data processed by the video compression circuit to a main controller on the host.
Another object of an embodiment of the present invention is to provide a method for operating a USB composite device as described above, where the method includes the following steps:
after the USB composite equipment is connected with a host, enumerating the USB composite equipment into composite equipment of storage equipment and video equipment;
if the USB composite equipment is used as storage equipment, the main controller is matched with the USB controller to realize the read-write operation of the TF/SD card;
if the USB composite equipment is used as video equipment, the main controller is matched with the USB controller to synchronously transmit the data processed by the video compression circuit to the host.
Another object of an embodiment of the present invention is to provide a method for operating a USB composite device, where the method includes the following steps:
after the USB composite equipment is connected with a host, the USB composite equipment is enumerated as composite equipment of storage equipment, video equipment and audio equipment;
if the USB composite equipment is used as storage equipment, the main controller is matched with the USB controller to realize the read-write operation of the TF/SD card;
if the USB composite equipment is used as video equipment, the main controller is matched with the USB controller to synchronously transmit the data processed by the video compression circuit to the host;
if the USB composite device is used as an audio device, the main controller is matched with the USB controller to synchronously transmit the data processed by the audio compression circuit to the host.
The USB compound device and the working method thereof provided by the embodiment of the invention at least integrate the storage function and the video function, can record the content photographed or recorded by the camera on the TF/SD card, can synchronize the content photographed or recorded by the camera to the host after being connected with the host, and further realize the read-write operation of the host on the content in the TF/SD card. Compared with the prior art, the direct operation of the contents in the TF/SD card can be realized without connecting the TF/SD card to a host, the method is convenient for users, economical and environment-friendly, and is particularly suitable for mini DV, a vehicle data recorder, aerial photography equipment and the like.
Drawings
Fig. 1 is a structural diagram of a USB composite device according to an embodiment of the present invention;
FIG. 2 is a diagram of a descriptor structure of a USB compound device according to an embodiment of the present invention;
fig. 3 is a structural diagram of a USB composite device according to a second embodiment of the present invention;
fig. 4 is a descriptor structure diagram of a USB composite device according to a second embodiment of the present invention;
fig. 5 is a flowchart of a working method of a USB composite device according to a third embodiment of the present invention;
fig. 6 is a flowchart of a working method of a USB composite device according to a fourth embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Aiming at the problems in the prior art, the invention provides a USB compound device. The USB composite device at least integrates a storage function and a video function, and will be described in detail with reference to the following embodiments:
example one
An embodiment of the present invention provides a USB composite device, as shown in fig. 1, including: a camera 1; a USB controller 5; a USB interface 6 connected with the USB controller 5; an SD card read-write module 7 of the external TF/SD card, wherein the SD card read-write module 7 reads and writes the content of the inserted TF/SD card; the CSI module 2 is connected with the camera 1, and the CSI module 2 collects data of an image sensor in the camera 1; the video compression circuit 3 is connected with the CSI module 2, and the video compression circuit 3 compresses the data collected by the CSI module 2, for example, the data can be compressed into an image in a JPEG format; the main controller 4 is connected with the video compression circuit 3, the SD card read-write module 7 and the USB controller 5, the main controller 4 controls the SD card read-write module 7 to write the data processed by the video compression circuit 3 into the TF/SD card, when the USB interface 6 is connected with a host (such as a personal computer and the like) and is used as a storage device, the main controller 4 is matched with the USB controller 5 to realize the read-write operation of the TF/SD card, when the USB interface 6 is connected with the host and is used as a video device, the main controller 4 is matched with the USB controller 5 to synchronously transmit the data processed by the video compression circuit 3 to the host.
In the first embodiment, after the USB composite device is connected to the host, an enumeration process needs to be performed first, so that the host recognizes that the inserted device is a composite device of a storage device and a video device, as shown in fig. 2, a descriptor structure of the USB composite device in the first embodiment is shown. For a USB composite device, multiple configurations of one device may be provided, or multiple interfaces may be configured, in an embodiment, one mode of configuring multiple interfaces is adopted, where a descriptor structure includes a device descriptor, a configuration descriptor is defined under the device descriptor, a mass device class interface descriptor (i.e., MassStorage interface descriptor), a USB Video class control interface descriptor (i.e., Video control interface descriptor), a Video stream interface descriptor 1 (i.e., Video streaming interface descriptor 1), a Video stream interface descriptor 2 (i.e., Video streaming interface descriptor 2) are defined under one configuration descriptor, a Bulk input Endpoint descriptor (i.e., Bulk-in Endpoint) and a Bulk output Endpoint descriptor (i.e., Bulk-out Endpoint) are defined under one mass device class interface descriptor, an Interrupt Endpoint descriptor (i.e., Interrupt Endpoint) is defined under the USB Video class control interface descriptor, a Video isochronous transfer Endpoint descriptor (i.e., an Isoch Video Endpoint) is defined under the Video stream interface descriptor 2.
Specifically, the enumeration process of the host to the USB composite device is as follows: the host acquires the first eight bytes of data of the device descriptor from the USB compound device; the host computer allocates a new address to the USB compound device; the host acquires a complete device descriptor from the USB compound device; the host acquires a complete configuration descriptor from the USB compound device; the host acquires a configuration set according to the total length of the configuration set in the configuration descriptor, wherein the configuration set comprises the configuration descriptor, each interface descriptor and each endpoint descriptor; the host sends a configuration packet to the USB composite equipment to configure the USB composite equipment and enable each interface of the USB composite equipment, wherein the interface refers to a high-capacity equipment interface, a USB video control interface and a video stream interface; the host mounts the driver according to the information of the interface. After the enumeration is successful, the USB composite equipment can execute corresponding operation according to a command issued by the host.
If the USB composite device is used as a storage device, the host issues a command packet header (CBW) to the USB composite device, where the CBW header indicates an address and a data amount of data to be read/written from/to the TF/SD card. After receiving the CBW command, the USB controller 5 extracts an SCSI command, and controls the SD card read-write module 7 to complete the read/write operation of the TF/SD card through the main controller 4 according to the SCSI command; after the read/write operation is completed, the USB controller 5 returns a Command Status Wrapper (CSW) to the host. The host then decides whether to continue sending the next CBW or data based on the CSW.
If the USB composite device is used as a video device, the main controller 4 starts an internal Direct Memory Access (DMA) controller, synchronizes data processed by the video compression circuit 3 to the USB FIFO of the USB controller 5, and the USB controller 5 transmits the data synchronized to the USB FIFO to the host computer, so that the host computer can use the video stream.
The USB compound device provided by the embodiment of the invention integrates the storage function and the video function, can record the content of photographing or recording by the camera 1 in the TF/SD card, and can synchronize the content of photographing or recording by the camera 1 to the host after being connected with the host, and further realize the read-write operation of the host on the content in the TF/SD card. Compared with the prior art, the direct operation of the contents in the TF/SD card can be realized without connecting the TF/SD card to a host, the method is convenient for users, economic and environment-friendly, and is particularly suitable for application in miniDV, automobile data recorders, aerial photography equipment and the like.
Example two
The second embodiment of the present invention provides a USB composite device, as shown in fig. 3. Different from the first embodiment, the second embodiment integrates the storage function and the video function, and further adds the audio function.
Specifically, in the second embodiment, the USB composite device further includes, on the basis of the first embodiment: an analog/digital conversion circuit 8 connected to the microphone, the analog/digital conversion circuit 8 converting an analog audio signal received by the microphone into a digital audio signal; an audio compression circuit 9 connected to the analog/digital conversion circuit 8, the audio compression circuit 9 compresses the digital audio signal converted by the analog/digital conversion circuit 8, for example, audio data in MP3 or ACC format can be compressed. At this time, the main controller 4 further controls the SD card read-write module 7 to write the data processed by the audio compression circuit 9 into the TF/SD card, and after the USB interface 6 is connected to the host, the main controller 4 cooperates with the USB controller 5 to synchronously transmit the data processed by the audio compression circuit 9 to the host when the host is used as an audio device.
Further, the USB composite device may further include: and the digital-to-analog conversion circuit 10 is connected with the main controller 4 and the loudspeaker, and the digital-to-analog conversion circuit 10 converts PCM data sent by the host computer through the USB interface 6 and the USB controller 5 into an analog signal and drives the loudspeaker to produce sound.
In the second embodiment, after the USB composite device is connected to the host, an enumeration process needs to be performed first, so that the host recognizes that the inserted devices are composite devices of a storage device, a video device and an audio device, as shown in fig. 4, a descriptor structure of the USB composite device in the second embodiment is shown. Similarly, the second embodiment is implemented by configuring multiple interfaces in a manner that one descriptor structure includes one device descriptor, where the device descriptor defines one configuration descriptor, and the configuration descriptor defines a high-capacity device class interface descriptor (i.e., MassStorage interface descriptor), a USB Video class control interface descriptor (i.e., Video control interface descriptor), a Video stream interface descriptor 1 (i.e., Video Streaming interface descriptor 1), a Video stream interface descriptor 2 (i.e., Video Streaming interface descriptor 2), an Audio control interface descriptor 0 (i.e., AudioControl interface descriptor 0), an Audio stream interface descriptor 1/0 (i.e., Audio Streaming interface descriptor 1/0), an Audio stream interface descriptor 1/1 (i.e., Audio Streaming interface descriptor 1/1), and an Audio stream interface descriptor 2/0 (i.e., Audio Streaming interface descriptor 2/0), The Audio stream interface descriptor 2/1 (i.e., Audio Streaming interface descriptor 2/1), the Bulk input Endpoint descriptor (i.e., Bulk-in Endpoint) and the Bulk output Endpoint descriptor (i.e., Bulk-out Endpoint) are defined under the mass device class interface descriptor, the Interrupt Endpoint descriptor (i.e., Interrupt Endpoint) is defined under the USB Video class control interface descriptor, and the Video isochronous transfer Endpoint descriptor (i.e., Isoch Video Endpoint) is defined under the Video stream interface descriptor 2. An audio-in audio Endpoint descriptor (i.e., Isoch-in audio Endpoint) is defined under the audio stream interface descriptor 1/1, and an audio-out audio Endpoint descriptor (i.e., Isoch-out audio Endpoint) is defined under the audio stream interface descriptor 2/1.
Specifically, the enumeration process of the host to the USB composite device is as follows: the host acquires the first eight bytes of data of the device descriptor from the USB compound device; the host computer allocates a new address to the USB compound device; the host acquires a complete device descriptor from the USB compound device; the host acquires a complete configuration descriptor from the USB compound device; the host acquires a configuration set according to the total length of the configuration set in the configuration descriptor, wherein the configuration set comprises the configuration descriptor, each interface descriptor and each endpoint descriptor; the host sends a configuration packet to the USB composite equipment to configure the USB composite equipment and enable each interface of the USB composite equipment, wherein the interface refers to a high-capacity equipment interface, a USB video control interface, a video stream interface, an audio control interface and an audio stream interface; the host mounts the driver according to the information of the interface. After the enumeration is successful, the USB composite equipment can execute corresponding operation according to a command issued by the host.
If the USB composite device is used as the storage device and the video device, the detailed description thereof is as described in the first embodiment, which is not repeated. If the USB composite device is used as an audio device and the audio device is a USB microphone, the main controller 4 starts an internal DMA controller, synchronizes the data processed by the audio compression circuit 9 to the USB FIFO of the USB controller 5, and the USB controller 5 transmits the data synchronized to the USB FIFO to the host computer, so that the host computer can use the audio stream. If the USB composite device is used as an audio device and the audio device is a USB headset, the host synchronously transmits PCM data to the USB FIFO through the USB interface 6 and the USB controller 5, the main controller 4 starts the internal DMA controller to synchronize the PCM data in the USB FIFO into the buffer memory of the digital-to-analog conversion circuit 10, and the digital-to-analog conversion circuit 10 drives the speaker to sound.
The USB composite device provided in the second embodiment of the present invention integrates the storage function, the video function, and the audio function, and can record the contents photographed or recorded by the camera 1 and the audio contents received by the microphone in the TF/SD card, and after connecting to the host, can synchronize the contents photographed or recorded by the camera 1 and the audio contents received by the microphone to the host, and further implement the read-write operation of the host on the contents in the TF/SD card. Compared with the prior art, the direct operation of the contents in the TF/SD card can be realized without connecting the TF/SD card to a host, the method is convenient for users, economical and environment-friendly, and is particularly suitable for mini DV, a vehicle data recorder, aerial photography equipment and the like.
EXAMPLE III
An embodiment of the present invention provides a working method of a USB composite device according to the first embodiment, as shown in fig. 5, including the following steps:
s11: after the USB composite device is connected with a host, the USB composite device is enumerated as a composite device of a storage device and a video device.
Further, step S11 may include the following steps:
s111: the host obtains the first eight bytes of data of the device descriptor from the USB composite device.
S112: the host assigns a new address to the USB composite device.
S113: the host obtains the complete device descriptor from the USB composite device.
S114: the host obtains the complete configuration descriptor from the USB composite device.
S115: and the host acquires the configuration set according to the total length of the configuration set in the configuration descriptor.
S116: and the host sends a configuration packet to the USB composite equipment to configure the USB composite equipment and enable each interface of the USB composite equipment.
S117: the host mounts the driver according to the information of the interface.
S12: if the USB composite device is used as a storage device, the main controller 4 is matched with the USB controller 5 to realize the read-write operation of the TF/SD card.
Further, step S12 may include the following steps:
s121: and the host issues the CBW to the USB compound equipment.
S122: after receiving the CBW command, the USB controller 5 extracts the SCSI command, and controls the SD card read/write module 7 to complete the read/write operation on the TF/SD card through the main controller 4 according to the SCSI command.
S123: after the read/write operation is completed, the USB controller 5 returns CSW to the host.
S13: if the USB composite device is used as a video device, the main controller 4 is matched with the USB controller 5 to synchronously transmit the data processed by the video compression circuit 3 to the host.
Further, step S13 may include the following steps:
s131: the main controller 4 starts an internal DMA controller and synchronizes the data processed by the video compression circuit 3 to the USB FIFO of the USB controller 5.
S132: the USB controller 5 sends the data isochronous transfer synchronized to the USB FIFO to the host.
In addition, in the third embodiment, before or after step S11, the method may further include the following steps:
s14: the CSI module 2 collects data of the image sensor in the camera 1.
S15: the video compression circuit 3 compresses the data collected by the CSI module 2, for example, into JPEG format images.
S16: the main controller 4 controls the SD card read-write module 7 to write the data processed by the video compression circuit 3 into the TF/SD card.
The working method of the USB composite device provided by the third embodiment of the invention integrates the storage function and the video function, can record the contents photographed or recorded by the camera 1 in the TF/SD card, and can synchronize the contents photographed or recorded by the camera 1 to the host after being connected with the host, and further realize the read-write operation of the host on the contents in the TF/SD card. Compared with the prior art, the direct operation of the contents in the TF/SD card can be realized without connecting the TF/SD card to a host, the method is convenient for users, economical and environment-friendly, and is particularly suitable for mini DV, a vehicle data recorder, aerial photography equipment and the like.
Example four
An embodiment of the present invention provides a working method of a USB composite device according to the first embodiment, as shown in fig. 6, including the following steps:
s21: after the USB composite device is connected with a host, the USB composite device is enumerated as a composite device of a storage device, a video device and an audio device. This step is similar to step S11 and will not be described in detail.
S22: if the USB composite device is used as a storage device, the main controller 4 is matched with the USB controller 5 to realize the read-write operation of the TF/SD card. This step is similar to step S12 and will not be described in detail.
S23: if the USB composite device is used as a video device, the main controller 4 is matched with the USB controller 5 to synchronously transmit the data processed by the video compression circuit 3 to the host. This step is similar to step S13 and will not be described in detail.
S24: if the USB composite device is an audio device, the main controller 4 cooperates with the USB controller 5 to synchronously transmit the data processed by the audio compression circuit 9 to the host, or the digital/analog conversion circuit 10 converts the PCM data sent by the host through the USB interface 6 and the USB controller 5 into an analog signal and drives the speaker to sound.
Further, step S24 may include the following steps:
s241: if the USB composite device is an audio device and the audio device is a USB microphone, the main controller 4 starts an internal DMA controller, synchronizes the data processed by the audio compression circuit 9 to the USB FIFO of the USB controller 5, and the USB controller 5 synchronously transmits the data synchronized to the USB FIFO to the host.
S242: if the USB composite device is used as an audio device and the audio device is a USB earphone, the host synchronously transmits PCM data to the USB FIFO through the USB interface 6 and the USB controller 5, the main controller 4 starts an internal DMA controller, the PCM data in the USBFIFO is synchronously stored in a cache of the digital-to-analog conversion circuit 10, and the digital-to-analog conversion circuit 10 drives a loudspeaker to sound.
In addition, in the fourth embodiment, before or after the step S21, the following steps may be further included:
s25: the CSI module 2 collects data of the image sensor in the camera 1.
S26: the video compression circuit 3 compresses the data collected by the CSI module 2, for example, into JPEG format images.
S27: the main controller 4 controls the SD card read-write module 7 to write the data processed by the video compression circuit 3 into the TF/SD card.
In addition, in the fourth embodiment, before or after the step S21, the following steps may be further included:
s28: the analog/digital conversion circuit 8 converts an analog audio signal received by the microphone into a digital audio signal.
S29: the audio compression circuit 9 compresses the digital audio signal converted by the analog/digital conversion circuit 8, and may compress audio data in the MP3 or ACC format, for example.
S30: the main controller 4 controls the SD card read-write module 7 to write the data processed by the audio compression circuit 9 into the TF/SD card.
The working method of the USB composite device provided by the fourth embodiment of the present invention integrates the storage function, the video function, and the audio function, and can record the contents photographed or recorded by the camera 1 and the audio contents received by the microphone in the TF/SD card, and after connecting to the host, can synchronize the contents photographed or recorded by the camera 1 and the audio contents received by the microphone to the host, and further implement the read-write operation of the contents in the TF/SD card by the host. Compared with the prior art, the direct operation of the contents in the TF/SD card can be realized without connecting the TF/SD card to a host, the method is convenient for users, economical and environment-friendly, and is particularly suitable for mini DV, a vehicle data recorder, aerial photography equipment and the like.
It will be understood by those skilled in the art that all or part of the steps in the method for implementing the above embodiments may be implemented by controlling the relevant hardware through a program, and the program may be stored in a computer readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc.
The above description is only for the purpose of illustrating the preferred embodiments of the present invention and is not to be construed as limiting the invention, and any modifications, equivalents and improvements made within the spirit and principle of the present invention are intended to be included within the scope of the present invention.