A method for implementing double usb interface of printer software and hardware cooperation switching mode
By using a dual USB interface design and USB PHY to detect plugging and unplugging events, the problem of the printer not being able to automatically switch modes was solved, enabling automatic switching between Master and Slave functions and meeting compatibility requirements.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INGENIC SEMICON CO LTD
- Filing Date
- 2021-03-24
- Publication Date
- 2026-07-03
AI Technical Summary
The existing printer is not compatible with both Master and Slave modes and cannot switch automatically, which means it cannot simultaneously support reading files from a USB flash drive and printing as a USB printer connected to a computer.
By combining hardware and software, a dual USB interface design is adopted. The USB high-speed switch and GPIO port are used to automatically switch modes. Combined with the USB PHY to detect plug-in and unplug events, the automatic switching of device modes is realized.
It enables the printer to function as a master for reading files from a USB flash drive when the USB flash drive is inserted, and as a slave for printing to a computer when the USB flash drive is unplugged, thus meeting compatibility requirements.
Smart Images

Figure CN115129268B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of printer technology, and in particular to a method for implementing dual USB interfaces in printer hardware and software switching modes. Background Technology
[0002] Thermal receipt printers are a common type of printing device, typically using a microcontroller to control the print head and achieve printing functionality. For example, Beijing Junzheng's X2000 chip is designed for the Internet of Things (IoT) field. For the thermal printer market, Beijing Junzheng has developed a printer driver based on its chip. Mini USB A and B connectors and their contacts (not drawn to scale). Mini USB connector contact functions:
[0003] 1 VBUS (4.4–5.25V)
[0004] 2 D-
[0005] 3D+
[0006] 4 ID
[0007] 5. Grounding
[0008] The ID pin is only used in OTG functionality. Mini USB interfaces come in mini-A, B, and AB types. If the system is only used as a slave, then the B interface is used. The system controller determines the type of device inserted by checking the ID pin's voltage level. If it's high, a B connector is inserted, and the system operates in slave mode. If ID is low, an A connector is inserted, and the system uses the HNP protocol to determine which device acts as the master and which as the slave. Except for pin 4, the mini USB interface functions the same as a standard USB. Pin 4 is called the ID pin; it connects to pin 5 on mini-A, and on mini-B, it can be left floating or connected to pin 5.
[0009] However, most printers in the current technology use standard USB interfaces for compatibility, thus lacking the ID pin (pin 4) found in chips like those from Ingenic Semiconductor. Therefore, they cannot distinguish whether the inserted device is a master or slave. But printer customers require support for both modes and the ability to switch between them. Specifically, it needs to support the master function of reading files from a USB flash drive, and also function as a slave device for printing from a computer.
[0010] Commonly used technical terms in the prior art include:
[0011] X2000: This refers to a dual-core (big.LITTLE) embedded chip for the Internet of Things, such as the one launched by Beijing Junzheng.
[0012] CPU: Here it refers to the main CPU of, for example, the Junzheng X2000 chip, or simply "big core".
[0013] USB Protocol: The USB (Universal Serial Bus) protocol is a serial interface standard primarily developed by Intel, with contributions from seven companies including Compaq, Microsoft, IBM, DEC, Northern Telecom, and NEC. The USB bus is a polling bus; the host control port initializes all data transmissions. Each bus action transmits a maximum of three data packets: token, data, and handshake.
[0014] USB device (Slave) mode: Configure the x2000 as a USB flash drive-like device and connect it to the computer.
[0015] USB host (Master) mode: Configure the x2000 as a PC host-like device that can recognize inserted USB flash drives.
[0016] OTG (On-The-Go): Primarily used for connecting different devices or mobile devices to exchange data. A mobile phone typically has only one external USB port. For user convenience, an OTG cable that supports USB flash drives can be plugged in, allowing the phone to directly access the flash drive's contents without going through a PC. The phone powers the peripheral. If the phone is connected to a PC, the PC's USB port is primarily in host mode. For ease of use, the phone is more conveniently positioned as the device. Therefore, the phone's USB port supports automatic switching between host and device modes. OTG essentially adds a host / device negotiation mechanism to the USB port.
[0017] ID pin: The system controller determines what kind of device is inserted by judging the voltage level of the ID pin.
[0018] GPIO (General-purpose input / output): The pins can be freely used by the user through programmable control. Depending on the practical considerations, the pins can be used as general-purpose input (GPI), general-purpose output (GPO), or general-purpose input and output (GPIO).
[0019] The USB PHY is responsible for the lowest-level signal conversion, similar to the PHY of a network port. Summary of the Invention
[0020] To address the aforementioned issues, the present invention aims to realize the special USB switching customization needs of printer customers through a combination of hardware and software design.
[0021] Specifically, the present invention provides a method for implementing dual USB interfaces in printer hardware and software switching modes, the method comprising the following steps:
[0022] S1. Hardware setup: Use two USB ports: one device port and one host port; automatically switch between the two modes through the plugging and unplugging hardware events of the device port, that is, the device can switch to device mode when the device is plugged in and switch to host mode when the device is unplugged.
[0023] S2. Corresponding software configuration: Based on the state of the device plug-in / plug-out event, force the device to be configured as deviceonly or hostonly mode, corresponding to the device interface and host interface respectively.
[0024] The automatic switching between the two modes described in S1 is achieved by using a high-speed USB switch to determine the high or low state of the S port and switch between different paths, i.e. (1) when S=0, the HSD1 path is open, and (2) when S=1, the HSD2 path is open; in this way, the USB device and USB host functions of usbotg are separated into two independent circuits.
[0025] In S2, the detection of the USB ID pin is integrated into the USB PHY detection in the USB driver.
[0026] In summary, the advantages of this invention are as follows: through the coordinated design of hardware and software, it realizes the technical implementation of dual USB ports to perform master and slave functions and switch between each other. It can realize the master function of supporting the insertion of USB flash drives to read files, and also realize the slave function of connecting to the computer as a USB printer to print. Attached Figure Description
[0027] The accompanying drawings, which are provided to further illustrate the invention and form part of this application, are not intended to limit the scope of the invention.
[0028] Figure 1 This is a flowchart illustrating the method of the present invention.
[0029] Figure 2 This is a circuit diagram of a USB high-speed switching switch using the SGM7227. Detailed Implementation
[0030] To better understand the technical content and advantages of the present invention, the present invention will now be described in further detail with reference to the accompanying drawings.
[0031] like Figure 1 As shown, this invention is a method for implementing dual USB interfaces in a printer with coordinated hardware and software switching modes. The method includes the following steps:
[0032] S1. Hardware setup: Use two USB ports: one device port and one host port; automatically switch between the two modes through the hardware event of plugging and unplugging the device port, that is, the device can switch to device mode when plugged in and switch to host mode when unplugged; this can make up for the defect that the two modes cannot be switched due to the lack of ID pin;
[0033] S2. Corresponding software configuration: Based on the state of the device plug-in / plug-out event, force the device to be configured as deviceonly or hostonly mode, corresponding to the device interface and host interface respectively.
[0034] The automatic switching between the two modes described in S1 is achieved by using a high-speed USB switch to determine the high or low state of the S port and switch between different paths, i.e. (1) when S=0, the HSD1 path is open, and (2) when S=1, the HSD2 path is open; in this way, the USB device and USB host functions of usbotg are separated into two independent circuits.
[0035] The USB high-speed switch uses the SGM7227 USB switch.
[0036] In S2, the detection of the USB ID pin is integrated into the USB PHY detection in the USB driver.
[0037] The method further includes:
[0038] If a USB cable is plugged in, the USB PHY layer detects the plugging event, ignores the high and low levels of the USB ID pin, and forces the currently plugged USB port to be configured as a USB device slave mode.
[0039] If the USB cable is unplugged, the USB PHY layer detects the unplugging event, ignores the high / low level signal of the USB ID pin, and forces the other USB port of the dual USB ports to be configured as a USB host device.
[0040] When the USB cable is unplugged, it functions as the Master for reading files from the USB flash drive; when the USB cable is plugged in, it functions as the Slave for connecting to the computer as a USB printer.
[0041] Specifically, in terms of hardware: such as Figure 2 The USB high-speed switch using SGM7227 is shown. Different paths are switched by judging the high or low of the S port, that is, (1) when S=0, the HSD1 path is open, and (2) when S=1, the HSD2 path is open.
[0042] This separates the USB device and USB host functions of USB OTG into two independent circuits.
[0043] On the software side: The device insertion / removal event status is used to replace the original ID pin detection, forcing the device to be configured in device-only or host-only mode.
[0044] Specifically, in terms of software: key technical points: the main idea behind the USB driver modifications is to integrate the detection of the USB ID pin into the USB PHY detection.
[0045] Before the modification, the code flow of the driver layer with ID pin was: insert USB cable --> USB PHY layer detects insertion event --> USB DWC driver layer determines the high or low level of USB ID pin signal --> switch master / slave mode.
[0046] Modified driver layer code flow:
[0047] 1. When a USB cable is inserted, the USB PHY layer detects the insertion event, ignores the high and low levels of the USB ID pin, and forcibly configures the currently inserted USB port as a USB device slave mode.
[0048] 2. When the USB cable is unplugged, the USB PHY layer detects the unplugging event, ignores the high / low level signals of the USB ID pin, and forces the other USB port of the dual USB ports to be configured as a USB host device.
[0049] Through the combined design of the above hardware and software, the technology of enabling dual USB ports to perform master and slave functions and switch between them has been realized.
[0050] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations can be made to the embodiments of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for implementing a double USB interface of a printer software and hardware cooperation switching mode, characterized in that, The method includes the following steps: S1. Hardware setup: Use two USB ports: one device port and one host port; automatically switch between the two modes through the plugging and unplugging hardware events of the device port, that is, the device can switch to device mode when the device is plugged in and switch to host mode when the device is unplugged. S2. Corresponding software configuration: Based on the state of device plugging and unplugging events, integrate the detection of the USB ID pin into the USB PHY detection in the USB driver, and force the device to be configured as device only and host only mode, corresponding to the device interface and host interface respectively. Specifically, the software configuration includes: If a USB cable is plugged in, the USB PHY layer detects the plugging event, ignores the high and low levels of the USB ID pin, and forces the currently plugged USB port to be configured as a USB device slave mode. If the USB cable is unplugged, the USB PHY layer detects the unplugging event, ignores the high / low level signal of the USB ID pin, and forces the other USB port of the dual USB ports to be configured as a USB host device.
2. The method according to claim 1, wherein the method is characterized in that, The automatic switching between the two modes described in S1 is achieved by using a high-speed USB switch to determine the high or low state of the S port and switching between different paths, i.e. (1) When S=0, the HSD1 path is open, and (2) when S=1, the HSD2 path is open; in this way, the USB device and USB host functions of usbotg are divided into two independent circuits.
3. The method for implementing dual USB interfaces for printer hardware and software coordinating switching modes according to claim 2, characterized in that, The USB high-speed switch uses the SGM7227 USB switch.
4. The method for implementing dual USB interfaces for printer hardware and software coordinating switching modes according to claim 1, characterized in that, When the USB cable is unplugged, it functions as the Master for reading files from the USB flash drive; when the USB cable is plugged in, it functions as a Slave for connecting to the computer as a USB printer.