Dynamic USB equipment optimization method based on Linux

By initializing USB device information in Linux system, registering hot-swap event callbacks, and handling plug-and-remove events and dimming failures, plug-and-remove delay and dimming failure problems in USB device management are solved, automated management and fault recovery are achieved, and user experience and device stability are improved.

CN120066593AActive Publication Date: 2025-05-30JIANGSU AUTOMATION RESEARCH INSTITUTE
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411969838.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-05-30
Estimated Expiration
2044-12-30

AI Technical Summary

Technical Problem

In the Linux operating system environment, the management of USB devices faces problems such as plug-in and unplugging delays, dimming failures, and the existing methods lack automation and intelligence support, resulting in poor user experience.

Method used

A dynamic USB device optimization method based on Linux is adopted to realize automated management and fault recovery by initializing USB device information, registering USB hot-swap event callback function, detecting and handling plug-in and unplugging events and dimming failures.

Benefits of technology

Real-time status monitoring and automatic management of USB devices are realized, quickly recovering dimming failures, significantly improving the user experience, and ensuring the stable operation of USB devices in various usage scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120066593A_ABST
    Figure CN120066593A_ABST
Patent Text Reader

Abstract

The invention discloses a dynamic USB (Universal Serial Bus) equipment optimization method based on Linux, aiming at solving the problems of dimming fault and identification in the use process of USB equipment. According to the method, insertion and extraction events of the USB equipment are monitored in real time through a hot plug callback mechanism of libusb, and efficient management of the equipment is ensured. The method comprises the following steps: firstly, recording USB equipment information when a system is initialized, and registering a callback function of a hot plug event; when the equipment is inserted, a program tries to open the equipment and declarates an interface, and if a dimming fault is found, the equipment is automatically reset to recover a normal function; when the device is pulled out, resources are released to prevent memory leakage. The method is suitable for various USB devices, especially display devices, and the efficiency of device management and the user experience are remarkably improved. According to the invention, a user can manage the USB equipment more conveniently, and meanwhile, the stability and reliability of the display dimming function are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical fields of computer operating systems and embedded systems, and particularly relates to a method for optimizing dynamic USB devices based on Linux. Background Art

[0002] With the rapid development of computer technology, USB (Universal Serial Bus) devices are increasingly widely used, including storage devices, printers, external displays, etc. Due to their plug-and-play characteristics, these devices greatly improve the convenience of users. However, in actual use, users often encounter problems such as the device not being recognized properly or dimming failures after plugging and unplugging the device, which not only affects work efficiency but may also lead to system instability or even crashes.

[0003] In the Linux operating system environment, the management of USB devices faces greater challenges. Although the Linux system provides some basic USB support, when dealing with frequent device plugging and unplugging and status changes, existing management solutions often seem insufficient. When users plug and unplug USB devices, the system may not be able to recognize the device changes in time, resulting in operation delays or failures. In addition, for some USB displays, the dimming function may not work properly after connection, manifested as abnormal brightness and contrast, or even a black screen phenomenon. Such dimming failures not only trouble users but also have a negative impact on the visual experience.

[0004] Existing methods usually rely on cumbersome operations such as manual configuration and restart when dealing with the recognition and dimming failures of USB devices, lacking automated and intelligent support. Users often need to repeatedly plug and unplug the device and make settings, increasing the complexity of use. At the same time, existing solutions lack an efficient mechanism for detecting and recovering from dimming failures and cannot respond to user needs in real time.

[0005] Therefore, it is particularly important to develop an efficient and intelligent USB device management and dimming optimization method. Such a method should be able to monitor the status of USB devices in real time, automatically process plugging and unplugging events, and quickly restore the function when a dimming failure occurs, thereby significantly improving the user experience and ensuring the stable operation of USB devices in various usage scenarios. Summary of the Invention

[0006] The object of the present invention is to solve the problems raised in the background art and propose a method for optimizing dynamic USB devices based on Linux.

[0007] To achieve the object of the present invention, the present invention discloses a method for optimizing dynamic USB devices based on Linux, which is used to solve the dimming failure caused by the plugging and unplugging of USB display devices, and specifically includes the following steps:

[0008] Step 1: When the system starts, initialize the relevant information of the USB display device, including device identifiers (such as vendor ID and device ID), interface numbers, and the required driver information; the system obtains the detailed data of the connected device by calling the corresponding USB interface functions and records this information completely in a global structure for management when the device is inserted or removed.

[0009] Step 2: Register the callback function for USB hot plug and unplug events, and monitor the insertion and removal events of the USB display device through the libusb library to respond to device status changes in real time and handle them.

[0010] Step 3: When a USB display device insertion event is detected, if the interface information of the USB display device matches the registered driver, attempt to open the device and detach the kernel driver; after successfully claiming the interface, confirm the device connection, and if a dimming failure is found, call the reset function to restore normal dimming.

[0011] Step 4: When the USB display device is removed, release the interface and close the device to ensure that resources are released and potential memory leaks or resource conflicts are avoided.

[0012] Further, the USB display device is a device that supports the USB HID protocol.

[0013] Further, the steps for initializing the USB display device include: allocating device identifiers, interface numbers, and driver information for each device and recording them in the global structure.

[0014] Further, the steps for registering the USB hot plug and unplug events include: registering the callback by calling the relevant functions in the libusb library to respond to the insertion and removal of the device.

[0015] Further, the device reset function includes calling the libusb_reset_device() function to perform recovery in case of a dimming failure.

[0016] Further, Step 3 specifically includes the following steps:

[0017] Step 3.1: When a USB display device insertion event is detected, obtain the interface information of the device and check whether it matches the registered driver.

[0018] Step 3.2: If the interface information of the device matches, attempt to open the device and detach the kernel driver, and then claim the device interface to prepare for subsequent operations.

[0019] Step 3.3: During the device initialization process, if a dimming failure is detected, call the device reset function to reset the device and re-declare the interface to restore the normal dimming function.

[0020] Compared with the prior art, the significant progress of the present invention lies in: 1) The method of the present invention is particularly applicable to various USB devices, especially display devices that support the USB HID protocol. By dynamically managing USB devices and optimizing the dimming function, the stability and reliability of the display dimming function are ensured; 2) In addition, the function of automatically detecting and repairing dimming failures enables users to enjoy a more stable and smooth operation experience when using the device.

[0021] To more clearly illustrate the functional characteristics and structural parameters of the present invention, the following further explains in conjunction with the accompanying drawings and specific embodiments. Description of the Drawings

[0022] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The schematic embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0023] Figure 1 is a flowchart of a dynamic USB device optimization method based on Linux;

[0024] Figure 2 is a flowchart of USB device plug and unplug event processing. Detailed Embodiments

[0025] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments; based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0026] As Figure 1 shown, a dynamic USB device optimization method based on Linux is used to solve the dimming failure caused by the plugging and unplugging of USB display devices, and specifically includes the following steps:

[0027] Step 1: At system startup, initialize the relevant information of the USB display device, including device identifiers (such as vendor ID and device ID), interface numbers, and required driver information; the system obtains the detailed data of the connected devices by calling the corresponding USB interface functions and records this information completely in a global structure for management when the device is inserted or removed;

[0028] Step 2: Register the callback function for USB hot plug and unplug events, and monitor the insertion and removal events of the USB display device through the libusb library to respond to device status changes in real time and handle them;

[0029] Step 3: When detecting the insertion event of the USB display device, if the interface information of the USB display device matches the registered driver, attempt to open the device and detach the kernel driver; after successfully claiming the interface, confirm the device connection. If a dimming failure is found, call the reset function to restore normal dimming;

[0030] Step 4: When the USB display device is unplugged, release the interface and close the device to ensure that resources are released and potential memory leaks or resource conflicts are avoided.

[0031] Furthermore, the USB display device is a device that supports the USB HID protocol.

[0032] Furthermore, the steps for initializing the USB display device include: allocating device identifiers, interface numbers, and driver information for each device and recording them in a global structure.

[0033] Furthermore, the steps for registering USB hot plug and unplug events include: registering the callback by calling relevant functions in the libusb library to respond to the insertion and removal of the device.

[0034] Furthermore, the device reset function includes calling the libusb_reset_device() function to perform recovery in case of a dimming failure.

[0035] Furthermore, Step 3 specifically includes the following steps:

[0036] Step 3.1: When detecting the insertion event of the USB display device, obtain the interface information of the device and check whether it matches the registered driver;

[0037] Step 3.2: If the interface information of the device matches, attempt to open the device and detach the kernel driver, and then claim the device interface to prepare for subsequent operations;

[0038] Step 3.3: During the device initialization process, if a dimming failure is found, call the device reset function to reset the device and re-claim the interface to restore the normal dimming function.

[0039] Embodiment

[0040] In one embodiment, a method for dynamic USB device management and dimming optimization based on Linux is as follows:

[0041] Step 1. At system startup, it is first necessary to initialize the relevant information of the USB display device, including device identifiers (such as vendor number and device number), interface number, and required driver information. Specifically as follows:

[0042] Step 1.1. Obtain the USB device list. The system uses the libusb_get_device_list() function to obtain the list of currently connected USB devices. This function returns a pointer to the device list, which contains information about all connected devices. Developers need to traverse this list to find the target USB display device.

[0043] Step 1.2. Extract device information. For each device, the system calls the libusb_get_device_descriptor() function to obtain its device descriptor information. This descriptor contains the Vendor ID and Product ID, which are crucial for subsequent device management. In addition, it is necessary to obtain the interface information of the device, including interface number, endpoint information, and driver requirements, etc.

[0044] The obtained device information will be recorded in a global structure. This structure is designed as an array, and each element represents a USB device. The fields in the structure include:

[0045] vendor_id: Vendor ID

[0046] product_id: Product ID

[0047] interface_number: Interface number

[0048] driver_info: Driver information

[0049] In this way, the system can efficiently manage multiple USB devices to quickly find and update the corresponding information when devices are plugged in or unplugged.

[0050] Step 2. After initialization, the system will register a callback function for USB hot plug events so that it can monitor the insertion and removal events of USB devices in real time.

[0051] Step 2-1. Define the callback function. The main task of the callback function usbHotPlugCallback is to handle the state changes of USB devices. The parameters of this function include the libusb context, device pointer, event type, and user data. According to the event type (device insertion or removal), the callback function will perform different operations.

[0052] Step 2-2: Register the hotplug callback function. By calling the libusb_hotplug_register_callback() function, bind the callback function to the device event. The parameters of this function include the context, event types (such as device arrival and departure), vendor ID, product ID, etc. After successful registration, the system will automatically call this callback function when detecting the insertion or removal of a device.

[0053] Step 3: Handle the USB device insertion event. When a USB monitor device is inserted, the system performs the following operations to ensure the correct opening of the device and the successful claim of the interface;

[0054] Step 3-1: The hotplug callback function will first detect the insertion event of the USB device. Then, call the libusb_get_active_config_descriptor() function to obtain the interface information of the inserted device. By comparing it with the information recorded in the global structure, confirm whether the interface information of the device matches that of the registered driver. If not, look for the next USB device.

[0055] Step 3-2: Open the device and detach the kernel driver. If the interface information of the device matches, the system will call the libusb_open() function to attempt to open the device. If the device is occupied by the kernel driver, detach the kernel driver through the libusb_detach_kernel_driver() function to ensure that the user space can fully control the device.

[0056] Step 3-3: Claim the interface and handle faults. After the device is successfully opened, the system will call the libusb_claim_interface() function to claim the interface. If a dimming fault is found during the claim process (such as abnormal display brightness), call the libusb_reset_device() function to reset the device. After resetting, the system attempts to claim the interface again to ensure the restoration of the normal dimming function. If the reset operation is successful, the device can work properly, and the system will print relevant information to confirm the successful connection of the device.

[0057] Step 4: Handle the USB device removal event. When a USB monitor device is removed, the system will perform the following steps to ensure the correct release of resources and avoid memory leaks or resource conflicts:

[0058] Step 4-1: Detect the device removal event. In the callback function, the system will judge whether the event type is device removal. If the handle pointer is empty, it means the device has not been opened, and the system will print the corresponding message and return.

[0059] Step 4-2: Release the interface and close the device. If the device is already open, the system will call the libusb_release_interface() function to release the previously declared interface. Then, use the libusb_close() function to close the device, ensuring that all related resources are released. In this way, the system effectively avoids possible memory leaks or resource conflicts.

[0060] Step 4-3: The system will update the information of the corresponding device in the global structure and mark the device as unconnected. This update is crucial for subsequent device management to ensure accurate information can be obtained when the device is inserted next time.

[0061] It should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device.

[0062] Although the embodiments of the present invention have been shown and described, those of ordinary skill in the art can understand that various changes, modifications, substitutions and variations can be made to these embodiments without departing from the principles and spirit of the present invention. The scope of the present invention is defined by the appended claims and their equivalents.

Claims

1. A Linux-based dynamic USB device optimization method, characterized in that: The specific steps include: Step 1: Initialize the relevant information of the USB display device when the system starts, including the device identifier, interface number and required driver information; The system obtains detailed data of the connected device by calling the corresponding USB interface function, and records this information in a global structure so that it can be managed when the device is plugged in or unplugged; Step 2: Register the callback function of USB hot plug event, and monitor the insertion and removal events of USB display device through libusb library, so as to respond to the device status change and process it in real time; Step 3: When a USB display device insertion event is detected, if the interface information of the USB display device matches the registered driver, try to open the device and detach the kernel driver; After successfully declaring the interface, confirm the device connection. If a dimming failure is found, call the reset function to restore normal dimming; Step 4. When the USB display device is unplugged, release the interface and turn off the device to ensure that resources are released and avoid potential memory leaks or resource conflicts.

2. A Linux-based dynamic USB device optimization method according to claim 1, characterized in that: The USB display device is a device that supports the USB HID protocol.

3. A Linux-based dynamic USB device optimization method according to claim 1, characterized in that: The steps of initializing the USB display device include: allocating a device identifier, an interface number and driver information to each device, and recording them in a global structure.

4. A Linux-based dynamic USB device optimization method according to claim 1, characterized in that: The steps to register USB hot plug events include: registering callbacks by calling relevant functions in the libusb library to respond to device insertion and removal.

5. A Linux-based dynamic USB device optimization method according to claim 1, characterized in that: The device reset function includes calling libusb_reset_device() function to recover in case of dimming failure.

6. A Linux-based dynamic USB device optimization method according to claim 1, characterized in that: Step 3 specifically includes the following steps: Step 3.1, when a USB display device insertion event is detected, the interface information of the device is obtained and checked whether it matches the registered driver; Step 3.2: If the device interface information matches, try to open the device, detach the kernel driver, and then declare the device interface to prepare for subsequent operations. Step 3.3: During the device initialization process, if a dimming failure is found, call the device reset function to reset the device and re-declare the interface to restore the normal dimming function.

Citation Information

Patent Citations

  • Method and system for redirecting cloud terminal USB

    CN104991871A

  • USB equipment management and control system based on Linux user space

    CN110598428A

  • Hardware equipment driving system based on microkernel and driving method thereof

    CN113268275A

  • Data protection method and device, storage medium and electronic equipment

    CN114611130A

  • Safely sharing USB devices

    US20110302330A1