[go: up one dir, main page]

CN109408418B - A USB mode switching device and method, and USB device - Google Patents

A USB mode switching device and method, and USB device Download PDF

Info

Publication number
CN109408418B
CN109408418B CN201710706084.4A CN201710706084A CN109408418B CN 109408418 B CN109408418 B CN 109408418B CN 201710706084 A CN201710706084 A CN 201710706084A CN 109408418 B CN109408418 B CN 109408418B
Authority
CN
China
Prior art keywords
usb
mode
module
usb controller
driver
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710706084.4A
Other languages
Chinese (zh)
Other versions
CN109408418A (en
Inventor
郭善宁
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sanechips Technology Co Ltd
Original Assignee
Sanechips Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Sanechips Technology Co Ltd filed Critical Sanechips Technology Co Ltd
Priority to CN201710706084.4A priority Critical patent/CN109408418B/en
Publication of CN109408418A publication Critical patent/CN109408418A/en
Application granted granted Critical
Publication of CN109408418B publication Critical patent/CN109408418B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/10Program control for peripheral devices
    • G06F13/102Program control for peripheral devices where the programme performs an interfacing function, e.g. device driver
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F13/00Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F13/38Information transfer, e.g. on bus
    • G06F13/382Information transfer, e.g. on bus using universal interface adapter
    • G06F13/385Information transfer, e.g. on bus using universal interface adapter for adaptation of a particular data processing system to different peripheral devices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2213/00Indexing scheme relating to interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
    • G06F2213/0042Universal serial bus [USB]

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Systems (AREA)

Abstract

一种USB模式切换装置,包括:上层应用模块、USB CORE模块、USB控制器驱动模块、USB控制器硬件模块,以及GADGET设备驱动模块,其中,上层应用模块,其与对端设备进行交互,对USB模式切换进行确认;USB CORE模块,其与对端设备进行枚举,设置模式标志;USB控制器驱动模块,其用于USB控制器驱动的卸载或加载,以实现主机模式或外接设备模式的配置;USB控制器硬件模块,其与对端设备实现硬件连接;GADGET设备驱动模块,其提供外接设备模式下的功能驱动。本发明还提供一种USB模式切换方法、USB设备,不采用OTG模块,能够降低硬件成本,降低软件的复杂度和兼容性风险,进而在USB模式切换上达到便捷、高效、稳定的效果。

Figure 201710706084

A USB mode switching device includes: an upper-layer application module, a USB CORE module, a USB controller driver module, a USB controller hardware module, and a GADGET device driver module, wherein the upper-layer application module interacts with a peer device to The USB mode switch is confirmed; the USB CORE module, which enumerates with the peer device and sets the mode flag; the USB controller driver module, which is used for unloading or loading the USB controller driver to realize the host mode or external device mode. Configuration; USB controller hardware module, which realizes hardware connection with the peer device; GADGET device driver module, which provides function drivers in the external device mode. The invention also provides a USB mode switching method and a USB device, which do not use an OTG module, can reduce hardware costs, reduce software complexity and compatibility risks, and achieve convenient, efficient and stable effects in USB mode switching.

Figure 201710706084

Description

USB mode switching device and method and USB equipment
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a USB mode switching apparatus and method, and a USB device.
Background
The USB OTG (Universal Serial Bus On-The-Go) specification enables embedded devices to communicate with each other without going through a PC (personal computer). The device supporting the OTG function is provided with an OTG module and has two roles: a Host (USB Host) mode, a peripheral Device (USB Device) mode, and supports a Host signaling protocol (HNP) and a Session Request Protocol (SRP). The OTG initial host Device and the Device perform mode switching judgment by monitoring an ID pin of a USB module or a GPIO (General Purpose Input/Output) Device.
The determination types all need to adopt an OTG module, and the adoption of the OTG module also needs to consider the difference of versions of the OTG specification and the compatibility problem of different versions on the software level.
Disclosure of Invention
In order to solve the defects in the prior art, the invention aims to provide a USB mode switching device and method, and a USB device, which can reduce the hardware cost of the USB device, reduce the complexity and compatibility risk of software, and further achieve the effects of convenience, high efficiency and stability in USB mode switching.
To achieve the above object, the present invention provides a USB mode switching device, comprising: an upper application module, a USB CORE module, a USB controller driving module, a USB controller hardware module and a GADGET device driving module,
the upper application module interacts with opposite terminal equipment and confirms the switching of the USB mode;
the USB CORE module enumerates with opposite terminal equipment and sets a mode mark;
the USB controller driving module is used for unloading or loading the USB controller driver so as to realize the configuration of a host mode or an external equipment mode;
the USB controller hardware module is in hardware connection with opposite-end equipment;
the GADGET device driving module provides function driving in an external device mode.
Further, the upper layer application module determines whether to switch to the external device mode through a handshake protocol with the device at the opposite end.
Further, the USB controller driving module powers down or powers up the USB controller hardware module.
Furthermore, the USB controller driver module reads the mode flag of the USB CORE module to determine whether to load the USB driver.
In order to achieve the above object, the method for switching USB modes provided by the present invention comprises the following steps:
the USB mode is a host mode, USB enumeration is carried out, and connected opposite-end equipment is identified;
judging that the mode needs to be switched to an external device mode through a handshake protocol between an upper application module and opposite-end equipment;
unloading the drive of the USB controller, powering down a hardware module of the USB controller, and setting a USB mode flag to be 1;
judging whether the USB mode mark is 1, if so, loading the USB controller drive into an external device mode, and electrifying a USB controller hardware module;
and loading the GADGET device driver, and switching from the host mode to the external device mode.
Further, if the USB mode flag is not 1, loading the USB controller driver to a host mode, and powering on the USB controller hardware module.
In order to achieve the above object, the method for switching USB modes provided by the present invention comprises the following steps:
the USB mode is an external equipment mode, and when the USB interface is judged to be disconnected with opposite-end equipment, the GADGET equipment drive is unloaded;
unloading the drive of the USB controller, powering down a hardware module of the USB controller, and setting a USB mode flag to be 0;
and judging whether the USB mode mark is 0, if so, loading the USB controller drive into a host mode, electrifying a USB controller hardware module, and switching from the external equipment mode to the host mode.
Further, if the USB mode flag is not 0, loading the USB controller driver into an external device mode, and powering on the USB controller hardware module; and loading the GADGET device driver, and switching from the host mode back to the external device mode.
According to the USB mode switching device and method, the upper application module judges whether to switch to the external equipment mode or not through a handshake protocol with opposite-end equipment. Therefore, the realization of the corresponding OTG specification and protocols of different versions is not needed on the software level, the software complexity and compatibility risk are reduced, and the effects of convenience, high efficiency and stability are achieved on the USB mode switching. The USB mode switching device and the method are applied to USB equipment, an OTG module is removed from hardware, and compared with the equipment adopting the OTG module, the hardware cost is reduced.
Drawings
The accompanying drawings are included to provide a further understanding of the invention and are incorporated in and constitute a part of this specification, illustrate embodiments of the invention and together with the description serve to explain the principles of the invention and not to limit the invention. In the drawings:
FIG. 1 is a schematic diagram of a USB mode switching device according to the present invention;
FIG. 2 is a flow chart of switching from a host mode to an external device mode according to the present invention;
fig. 3 is a flowchart of switching from the peripheral mode to the host mode according to the present invention.
Detailed Description
The preferred embodiments of the present invention will be described in conjunction with the accompanying drawings, and it will be understood that they are described herein for the purpose of illustration and explanation and not limitation.
Fig. 1 is a schematic structural diagram of a USB mode switching apparatus 101 according to the present invention, as shown in fig. 1, the USB mode switching apparatus 101 of the present invention includes an upper layer application module 102, a USB CORE module 103, a USB controller driver module 104, a USB controller hardware module 105, and a GADGET device driver module 106, wherein,
the upper application module 102 is configured to interact with an opposite device when another USB device is connected to the USB mode switching apparatus 101 through a USB cable, and determine whether to switch to the external device mode through a handshake protocol with the opposite device.
The USB CORE module 103 is configured to enumerate with an opposite device, that is, an external device, when the USB mode switching device 101 is in the host mode, and provide an attribute file for setting a mode flag.
The USB controller driver module 104 is configured to switch between a host mode and an external device mode of the USB mode switching apparatus 101. The USB controller driver module 104 configures the USB controller hardware module 105 into a host mode or an external device mode by unloading or loading the USB driver to perform corresponding functions. A USB controller driver module 104, which is also used to power down or power up the USB controller hardware module.
The USB controller hardware module 105 includes the USB itself and associated peripheral hardware circuitry.
And the GADGET device driver module 106 is configured to provide function driving in the peripheral device mode.
Fig. 2 is a flowchart illustrating a process of switching from the host mode to the external device mode according to the present invention, and the process of switching from the host mode to the external device mode according to the present invention will be described in detail with reference to fig. 2.
First, in step 201, the USB CORE module 103 enumerates the connected devices, and the upper application module 102 performs handshake interaction with the connected devices. In step 201, firstly, the USB mode is set as the host mode by default, when other USB devices are connected to the apparatus through a USB cable, the USB CORE module 103 performs normal USB enumeration, and identifies the connected devices as external devices; next, the upper layer application module 102 and the connected application module confirm whether the host mode needs to be switched to the external device mode through a handshake protocol. For example, when the upper layer application module 102 supports the iap2 protocol of apple Inc. and the connected device is an iPhone, the iPhone will request to switch the host mode to the external device mode through iap2 protocol interaction.
Step 202, judging whether to switch to the external device mode. If the mode does not need to be switched to the external equipment mode, ending the process; and if the mode needs to be switched to the external equipment mode, the next step is carried out.
Step 203, uninstall the USB driver, power down the USB controller hardware module 105, and set the mode flag to 1. In step 203, after confirming that the external device mode needs to be switched, the upper application module 102 controls the USB controller driver module 104 to uninstall the USB driver, and powers down the USB controller hardware module 105. In addition, the USB CORE module 103 provides an attribute file to set the mode flag to 1.
In step 204, it is determined whether the mode flag is 1. In step 204, the USB controller driver module 104 determines whether the mode flag is 1 by reading the attribute file value of the mode flag of the USB CORE module 103. If the mode flag is not 1, go to step 207; if the mode flag is 1, the next step is performed.
Step 205, load the USB controller hardware module 105 into the external device mode, and power up the USB controller hardware module 105. In step 205, the upper application module 102 controls the USB controller driver module 104 to reload the USB driver, loads the USB controller hardware module 105 into the external device mode, and powers on the USB controller hardware module 105.
Step 206, load the GADGET device driver. In step 206, after the USB controller hardware module 105 switches to the external device mode, the GADGET device driver module 106 loads the GADGET device driver.
Step 207 loads the USB controller hardware module 105 into host mode and powers up the USB controller hardware module 105. In step 207, the upper application module 102 controls the USB controller driver module 104 to reload the USB driver, reload the USB controller hardware module 105 into the host mode, and power up the USB controller hardware module 105.
The switching from the host mode to the peripheral mode is completed according to steps 201 to 206. At this time, the device at the opposite end is switched to the host mode, and the USB mode switching device 101 is enumerated as an external device. And then, data interaction is performed between the device at the opposite end and the USB mode switching device 101.
When the interaction is complete or the connection is no longer needed, the connection between the two is broken. After that, the USB mode switching device 101 switches from the external device mode to the host mode.
Fig. 3 is a flowchart of switching from the peripheral mode to the host mode according to the present invention, and the following describes in detail the flow of switching from the peripheral mode to the host mode according to the present invention with reference to fig. 3.
First, in step 301, the USB mode is an external device mode, and it is determined whether the connection is disconnected. If the connection is not disconnected, ending the process; if the connection has been broken, the next step is taken.
Step 302, uninstall the GADGET device driver. In step 302, the GADGET device driver module 106 unloads the GADGET device driver when a connection to disconnect is confirmed.
Step 303, uninstall the USB driver, power down the USB controller hardware module 105, and set the mode flag to 0. In step 303, the upper application module 102 controls the USB controller driver module 104 to uninstall the USB driver and power down the USB controller hardware module 105. In addition, the USB CORE module 103 provides an attribute file to set the mode flag to 0.
In step 304, it is determined whether the mode flag is 0. In step 304, the USB controller driver module 104 determines whether the mode flag is 0 by reading the attribute file value of the mode flag of the USB CORE module 103. If the mode flag is not 0, go to step 306 and step 307; if the mode flag is 0, the next step is performed.
Step 305 loads the USB controller hardware module 105 into host mode and powers up the USB controller hardware module 105. In step 305, the upper application module 102 controls the USB controller driver module 104 to reload the USB driver, loads the USB controller hardware module 105 into the host mode, and powers on the USB controller hardware module 105.
Step 306, reload the USB controller hardware module 105 into the external device mode, and power up the USB controller hardware module 105. In step 306, the upper application module 102 controls the USB controller driver module 104 to reload the USB driver, reload the USB controller hardware module 105 into the peripheral mode, and power up the USB controller hardware module 105.
Step 307, load the GADGET device driver. In step 307, after the USB controller hardware module 105 switches to the external device mode, that is, when the USB mode switching device 101 is in the external device mode, the GADGET device driver module 106 loads the GADGET device driver.
The switching to the host mode is completed according to steps 301 to 305. At this time, the USB mode switching device 101 switches to the host mode.
The USB mode switching device and the method are applied to USB equipment, an OTG module is removed from hardware, and compared with the equipment adopting the OTG module, the hardware cost is reduced.
By adopting the USB mode switching device and method in the USB equipment, the upper application module judges whether to switch to the external equipment mode or not through a handshake protocol with equipment at the opposite end. Therefore, the realization of the corresponding OTG specification and protocols of different versions is not needed on the software level, the software complexity and compatibility risk are reduced, and the effects of convenience, high efficiency and stability are achieved on the USB mode switching.
Those of ordinary skill in the art will understand that: although the present invention has been described in detail with reference to the foregoing embodiments, it will be apparent to those skilled in the art that changes may be made in the embodiments and/or equivalents thereof without departing from the spirit and scope of the invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (9)

1. A USB mode switching device, comprising: an upper application module, a USB CORE module, a USB controller driving module, a USB controller hardware module and a GADGET device driving module,
the upper application module interacts with opposite terminal equipment and confirms the switching of the USB mode;
the USB CORE module enumerates with opposite terminal equipment and provides an attribute file for setting a mode mark;
the USB controller driving module is used for reading the attribute file under the control of the upper application module and unloading or loading the USB controller driving according to the mode mark in the attribute file so as to realize the configuration of a host mode or an external equipment mode;
the USB controller hardware module is in hardware connection with opposite-end equipment;
the GADGET device driving module provides function driving in an external device mode.
2. The USB mode switching apparatus according to claim 1, wherein the upper layer application module determines whether to switch to an external device mode through a handshake protocol with a device at an opposite end.
3. The USB mode switching device according to claim 1, wherein the USB controller driver module powers down or powers up the USB controller hardware module.
4. The USB mode switching device according to claim 1, wherein the USB controller driver module reads a mode flag of the USB CORE module to determine whether to load a USB driver.
5. A method of USB mode switching, comprising the steps of:
the USB mode is a host mode, USB enumeration is carried out, and connected opposite-end equipment is identified;
judging that the mode needs to be switched to an external device mode through a handshake protocol between an upper application module and opposite-end equipment;
unloading the drive of the USB controller, powering down a hardware module of the USB controller, setting a USB mode mark as 1, and writing the USB mode mark into an attribute file;
calling the attribute file, judging whether a USB mode mark is 1, if so, loading a USB controller drive into an external device mode, and electrifying a USB controller hardware module;
and loading the GADGET device driver, and switching from the host mode to the external device mode.
6. The method according to claim 5, wherein if the USB mode flag is not 1, loading the USB controller driver into a host mode, and powering on the USB controller hardware module.
7. A method of USB mode switching, comprising the steps of:
the USB mode is an external equipment mode, and when the USB interface is judged to be disconnected with opposite-end equipment, the GADGET equipment drive is unloaded;
unloading the drive of the USB controller, powering down a hardware module of the USB controller, setting a USB mode mark to be 0, and writing the USB mode mark into an attribute file;
and calling the attribute file, judging whether the USB mode mark is 0, if so, loading the USB controller drive into a host mode, electrifying a USB controller hardware module, and switching from an external equipment mode to the host mode.
8. The method according to claim 7, wherein if the USB mode flag is not 0, loading the USB controller driver into an external device mode, and powering on the USB controller hardware module; and loading the GADGET device driver, and switching from the host mode back to the external device mode.
9. A USB device comprising the USB mode switching apparatus according to any one of claims 1 to 4.
CN201710706084.4A 2017-08-17 2017-08-17 A USB mode switching device and method, and USB device Active CN109408418B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710706084.4A CN109408418B (en) 2017-08-17 2017-08-17 A USB mode switching device and method, and USB device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710706084.4A CN109408418B (en) 2017-08-17 2017-08-17 A USB mode switching device and method, and USB device

Publications (2)

Publication Number Publication Date
CN109408418A CN109408418A (en) 2019-03-01
CN109408418B true CN109408418B (en) 2022-03-25

Family

ID=65454821

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710706084.4A Active CN109408418B (en) 2017-08-17 2017-08-17 A USB mode switching device and method, and USB device

Country Status (1)

Country Link
CN (1) CN109408418B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111823863B (en) * 2020-05-28 2021-11-16 惠州华阳通用电子有限公司 Vehicle-mounted play source switching method, system and equipment

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6389029B1 (en) * 1998-11-10 2002-05-14 Nortel Networks Limited Local area network incorporating universal serial bus protocol
CN101226516A (en) * 2007-01-15 2008-07-23 奇岩电子股份有限公司 Device and method capable of automatically switching to USB host or peripheral equipment
CN103309708A (en) * 2013-05-31 2013-09-18 南京熊猫电子股份有限公司 Method for automatically installing USB device driving program on mainframe
CN103473202A (en) * 2013-09-03 2013-12-25 福建星网锐捷网络有限公司 USB OTG device, electronic unit and OTG function implementation method
CN104281542A (en) * 2014-09-26 2015-01-14 中兴通讯股份有限公司 Method, device and system for adaptation of multifunctional USB (universal serial bus) terminal equipment
CN104850512A (en) * 2014-02-13 2015-08-19 珠海全志科技股份有限公司 Method and apparatus for implementing USB OTG function without ID pin
CN106027487A (en) * 2016-04-28 2016-10-12 广州广电运通金融电子股份有限公司 Hardware equipment access management method and system
CN106066842A (en) * 2016-05-30 2016-11-02 上海华为技术有限公司 A kind of method of switch mode, SOC(system on a chip) and base station

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4284499B2 (en) * 2003-03-07 2009-06-24 ソニー株式会社 Device management method and device management system
CN102082969B (en) * 2010-10-29 2013-03-27 广东星海数字家庭产业技术研究院有限公司 External Bluetooth equipment driving system for set-top box
WO2012083423A1 (en) * 2010-12-23 2012-06-28 Icron Technologies Corporation Method and apparatus for connecting usb devices to a computer
US9104384B2 (en) * 2013-05-13 2015-08-11 International Microsystems, Inc. Portable USB mass storage device

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6389029B1 (en) * 1998-11-10 2002-05-14 Nortel Networks Limited Local area network incorporating universal serial bus protocol
CN101226516A (en) * 2007-01-15 2008-07-23 奇岩电子股份有限公司 Device and method capable of automatically switching to USB host or peripheral equipment
CN103309708A (en) * 2013-05-31 2013-09-18 南京熊猫电子股份有限公司 Method for automatically installing USB device driving program on mainframe
CN103473202A (en) * 2013-09-03 2013-12-25 福建星网锐捷网络有限公司 USB OTG device, electronic unit and OTG function implementation method
CN104850512A (en) * 2014-02-13 2015-08-19 珠海全志科技股份有限公司 Method and apparatus for implementing USB OTG function without ID pin
CN104281542A (en) * 2014-09-26 2015-01-14 中兴通讯股份有限公司 Method, device and system for adaptation of multifunctional USB (universal serial bus) terminal equipment
CN106027487A (en) * 2016-04-28 2016-10-12 广州广电运通金融电子股份有限公司 Hardware equipment access management method and system
CN106066842A (en) * 2016-05-30 2016-11-02 上海华为技术有限公司 A kind of method of switch mode, SOC(system on a chip) and base station

Also Published As

Publication number Publication date
CN109408418A (en) 2019-03-01

Similar Documents

Publication Publication Date Title
CN103744821B (en) Method and device for realizing USB OTG (Universal Serial Bus On-The-Go) function of mobile terminal
CN101601001B (en) Multiple connections to a single serial interface
JP4601330B2 (en) Electronic device and control method thereof, information processing apparatus, and computer program
US8862790B2 (en) Method for identifying version type of windows operating system on a host by a USB device
US9606597B2 (en) Intermediate electronic device, method for operating the intermediate electronic device and electronic system
US9747237B2 (en) Methods and apparatus for reliable detection and enumeration of devices
EP2474913A1 (en) USB device switching working mode
CN101989205B (en) Software system upgrading method for universal serial bus (USB) equipment
US20170255585A1 (en) Method and system for switching role of usb otg device and otg device thereof
US20090037622A1 (en) Method and system for changing operation modes of an interface device
TW201606518A (en) Port disconnect charging function for USB hub
JP6024288B2 (en) Information processing system and external device
US20130019035A1 (en) Apparatus for peer-to-peer communication over a universal serial bus link
CN112041827B (en) Automatic USB host detection and port configuration method and device
WO2024114247A1 (en) Data transmission method and apparatus
CN104220958A (en) Computer device and method for converting working mode of universal serial bus connector of the computer device
JP2016201909A (en) Electrical apparatus and control method therefor
US11977618B2 (en) Electronic device and control method
US9235249B2 (en) Power control for serial bus peripheral device
WO2015196479A1 (en) Program data updating method and device
CN109408418B (en) A USB mode switching device and method, and USB device
JP6434630B2 (en) USB OTG device identification system and apparatus
CN1316388C (en) USB control circuit suitable for computer-to-computer transmission and its working method
JP2023040804A (en) Port controller and electronic apparatus
CN104850512B (en) No ID pin does the method and device of USB OTG function

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant