A universal LED driving method

CN119377137BActive Publication Date: 2026-08-21TIANJIN JINHANG COMP TECH RES INST
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411470918.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-21
Publication Date
2026-08-21
Estimated Expiration
2044-10-21

AI Technical Summary

Technical Problem

直接IO驱动的优点是电路简单、易于实现,缺点是直接IO驱动能力有限,适用于少量LED驱动

Benefits of technology

上述技术方案所提供的通用LED驱动方法,将LED IO驱动方式、PWM驱动方式、专用芯片驱动方式进行集成统一,提高了LED驱动程序的效率。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119377137B_ABST
    Figure CN119377137B_ABST
Patent Text Reader

Abstract

The application discloses a general LED driving method, steps are as follows: S1: defining module configuration information structure body driverCfg; S2: defining module driving structure body driverInfo; S3: defining S2 module driving structure body driverInfo pointer variable LedModule; S4: matching different driving, initializing function pointer in LedModule, LED function pointer for lighting and LED function pointer for extinguishing respectively pointing to pin driving type 'PIN', PWM duty cycle control type, chip driving type 'WS2812B', and realizing start running function, starting LED hardware circuit output enable through receiving message instruction; callback function is called pturnon and pturnoff through timing interrupt mode to carry out lighting and extinguishing operation; S5: in the main function, directly configuring driving type in the cfg. The application integrates and unifies LED IO driving mode, PWM driving mode and special chip driving mode, and improves the efficiency of the LED driving program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer control technology and relates to a general LED driving method. Background Technology

[0002] LEDs are semiconductor devices, and common hardware driving methods include constant current driving, constant voltage driving, and PWM driving. Main control chip driving methods include direct / indirect I / O driving, PWM driving, and direct LED chip driving. Direct I / O driving has the advantages of simple circuitry and ease of implementation, but its disadvantage is limited driving capability, making it suitable for driving a small number of LEDs. Indirect I / O driving methods, such as transistor driving and Darlington transistor driving, have the advantages of strong driving capability, but the disadvantage of complex circuitry. Additionally, dedicated LED chip driving methods offer simple circuit design and rich functionality, but are more expensive. Summary of the Invention

[0003] (a) Technical problems to be solved For different LED driving methods, the main control chip usually needs to use different control programs to drive it. This invention abstracts the common parts in different driving methods and maps the different parts through pointers, forming a program that can control the integrated and unified IO drive, PWM drive and dedicated chip driver.

[0004] (II) Technical Solution To solve the above-mentioned technical problems, the present invention provides a universal LED driving method, which includes the following steps: S1: Defines the module configuration information structure driverCfg; S2: Defines the module driver structure driverInfo; S3: Define the LedModule pointer variable, which is the driverInfo structure in S2; S4: For different driver matching, initialize function pointers in LedModule, set the LED light-up function pointer to the pin-driven "PIN", duty cycle control "PWM", and chip-driven "WS2812B" function pointers respectively, and implement the start function to start the LED hardware circuit output enable by receiving message instructions; the callback function calls pturnon and pturnoff through timer interrupt to perform the light-up and light-down operations. S5: In the main function, the driver type in cfg is configured directly.

[0005] In step S1, the module configuration information structure driverCfg includes: ① the driver module name drv_name, which is a character pointer; ② the version number, which is a character pointer.

[0006] In step S1, define the module configuration information structure variable cfg.

[0007] In step S2, the module driver structure driverInfo includes: ① initialization function pointer pinit, ② start running function pointer pstart, ③ callback function pointer phandler, ④ LED light-up function pointer pturnon, and ⑤ LED light-off function pointer pturnoff.

[0008] In step S3, the pointer variable LedModule is initialized to NULL.

[0009] In step S3, the module information is stored in the structure variable cfg from step S1. The strcmp function is used to match the driver module name drv_name and the driver type in the structure variable cfg. The driver types are: ① Pin-driven type "PIN", ② Duty cycle control type "PWM", ③ Programmable LED module "WS2812B".

[0010] In step S3, for a matching result of "PIN" (pin-driven), perform the following operations: S3_21 sets the initialization pointer pinit in S2 to the pin driver type initialization function pin_init, which calls the InitGPIO() initialization function to perform initialization operations on the I / O driving the LED. S3_22 sets the LED-lighting function pointer pturnon in S2 to the pin-driven LED-lighting function pin_turnon, which calls the setGPIO() function to light up the LED.

[0011] S3_23 sets the LED-off function pointer pturnoff in S2 to the pin-driven LED-off function pin_turnoff, which calls the reset GPIO() function to turn off the LED.

[0012] In step S3, for a matching result of duty cycle control type "PWM", perform the following operations: S3_31 sets the initialization pointer pinit in S2 to the duty cycle control type initialization function pwm_init, which calls the InitPWM() initialization function to initialize the PWM peripheral. S3_32 sets the LED-lighting function pointer pturnon in S2 to the duty cycle-controlled LED-lighting function pwm_turnon. This function calls the duty cycle setting function setpwm() with a parameter of 1 to light up the LED. S3_33 sets the LED-off function pointer pturnoff in S2 to the duty cycle-controlled LED-on function pwm_turnoff. This function calls the duty cycle setting function setpwm() with a parameter of 0 to turn off the LED.

[0013] In step S3, for the matching result "WS2812B" (chip driver type), perform the following operations: In S2, the initialization pointer pinit is set to the pin-driven initialization function init. This function calls the InitGPIO() initialization function to drive the WS2812B chip to control the LED.

[0014] In step S5, the driver type configuration operation includes: ① directly calling pinit in the LedModule pointer variable to perform initialization operation; ② waiting to receive instructions and calling pstart in the LedModule pointer variable to enable the LED hardware circuit output; ③ periodically calling the phandler function to perform the LED running light operation or directly calling pturnon to turn on the LED and pturnoff to turn off the LED.

[0015] (III) Beneficial Effects The general LED driving method provided by the above technical solution integrates and unifies LED IO driving mode, PWM driving mode and dedicated chip driving mode, thereby improving the efficiency of LED driver program. Attached Figure Description

[0016] Figure 1 This is a flowchart of the general LED driving method of the present invention. Detailed Implementation

[0017] To make the objectives, contents, and advantages of the present invention clearer, the specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples.

[0018] Reference Figure 1 As shown, the general LED driving method in this embodiment includes the following steps: S1: Define the module configuration information structure driverCfg The module configuration information structure driverCfg includes: ① the driver module name drv_name, which is a character pointer; e.g., "LED"; ② the version number, which is a character pointer. Define the module configuration information structure variable cfg.

[0019] S2: Define the module driver structure driverInfo The module driver structure driverInfo includes: ① initialization function pointer pinit, ② start function pointer pstart, ③ callback function pointer phandler, ④ LED-on function pointer pturnon, and ⑤ LED-off function pointer pturnoff.

[0020] S3: Define the LedModule pointer variable, which is the driverInfo structure in S2. The pointer variable LedModule is initialized to NULL.

[0021] The S3_1 module information is stored in the structure variable cfg in step S1. The strcmp function is used to match the driver module name drv_name and the driver type in the structure variable cfg. The driver types are: ① pin driver type "PIN", ② duty cycle control type "PWM", ③ programmable LED module "WS2812B".

[0022] For S3_2, if the matching result is a pin-driven "PIN", perform the following operations: S3_21 sets the initialization pointer pinit in S2 to the pin driver initialization function pin_init, which calls the InitGPIO() initialization function to initialize the I / O driving the LED.

[0023] S3_22 sets the LED-lighting function pointer pturnon in S2 to the pin-driven LED-lighting function pin_turnon, which calls the setGPIO() function to light up the LED.

[0024] S3_23 sets the LED-off function pointer pturnoff in S2 to the pin-driven LED-off function pin_turnoff, which calls the reset GPIO() function to turn off the LED.

[0025] For S3_3, if the matching result is a duty cycle control type "PWM", perform the following operations: S3_31 sets the initialization pointer pinit in S2 to the duty cycle control type initialization function pwm_init, which calls the InitPWM() initialization function to perform initialization operations on the PWM peripheral.

[0026] S3_32 sets the LED-lighting function pointer pturnon in S2 to the duty cycle-controlled LED-lighting function pwm_turnon. This function calls the duty cycle setting function setpwm() with a parameter of 1 to light up the LED.

[0027] S3_33 sets the LED-off function pointer pturnoff in S2 to the duty cycle-controlled LED-on function pwm_turnoff. This function calls the duty cycle setting function setpwm() with a parameter of 0 to turn off the LED.

[0028] For S3_4, if the matching result is "WS2812B" (chip driver type), perform the following operations: In S2, the initialization pointer pinit is set to the pin-driven initialization function init. This function calls the InitGPIO() initialization function to drive the WS2812B chip to control the LED.

[0029] S4: For different driver matching, the initialization function pointer, LED-on function pointer, and LED-off function pointer in LedModule are respectively set to pin-driven "PIN", duty cycle-controlled "PWM", and chip-driven "WS2812B", and the start-up function is implemented. The LED hardware circuit output enable is started by receiving message instructions; the callback function calls pturnon and pturnoff through timer interrupts to perform the light-on and light-off operations. For example, a 1-second running light.

[0030] S5: In the main function, the driver type in cfg can be configured directly without modifying other parts.

[0031] The driver type configuration operations include: ① Directly calling `pinit` in the `LedModule` pointer variable for initialization. ② Waiting for instructions and calling `pstart` in the `LedModule` pointer variable to enable the LED hardware circuit output. ③ Periodically calling the `phandler` function to perform LED sequential operation, or directly calling `pturnon` to turn the LED on and `pturnoff` to turn the LED off.

[0032] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A general LED driving method, characterized in that, Includes the following steps: S1: Defines the module configuration information structure driverCfg; The module configuration information structure driverCfg includes: ① the driver module name drv_name, which is a character pointer; ② the version number, which is a character pointer. Define the module configuration information structure variable cfg; S2: Defines the module driver structure driverInfo; The module driver structure driverInfo includes: ① initialization function pointer pinit, ② start execution function pointer pstart, ③ callback function pointer phandler, ④ LED light-up function pointer pturnon, and ⑤ LED light-off function pointer pturnoff; S3: Define the LedModule pointer variable, which is the driverInfo structure in S2; The pointer variable LedModule is initialized to NULL. The module information is stored in the structure variable cfg in step S1. The strcmp function is used to match the driver module name drv_name and the driver type in the structure variable cfg. The driver types are: ① pin driver type "PIN", ② duty cycle control type "PWM", ③ programmable LED module "WS2812B". For a matching result of "PIN" (pin-driven), perform the following operations: S3_21 sets the initialization pointer pinit in S2 to the pin driver type initialization function pin_init, which calls the InitGPIO() initialization function to perform initialization operations on the I / O driving the LED. S3_22 sets the LED-lighting function pointer pturnon in S2 to point to the pin-driven LED-lighting function pin_turnon, which calls the setGPIO() function to light up the LED. S3_23 sets the LED-off function pointer pturnoff in S2 to the pin-driven LED-off function pin_turnoff, which calls the reset switch function resetGPIO() to turn off the LED. For a matching result of duty cycle control type "PWM", perform the following operations: S3_31 sets the initialization pointer pinit in S2 to the duty cycle control type initialization function pwm_init, which calls the InitPWM() initialization function to initialize the PWM peripheral. S3_32 sets the LED-lighting function pointer pturnon in S2 to the duty cycle-controlled LED-lighting function pwm_turnon. This function calls the duty cycle setting function setpwm() with a parameter of 1 to light up the LED. S3_33 sets the LED-off function pointer pturnoff in S2 to the duty cycle-controlled LED-on function pwm_turnoff. This function calls the duty cycle setting function setpwm() with a parameter of 0 to turn off the LED. For a matching result of "WS2812B" (chip driver type), perform the following operations: In S2, the initialization pointer pinit is set to point to the pin-driven initialization function init. This function calls the InitGPIO() initialization function to drive the WS2812B chip to control the LED through IO. S4: For different driver matching, initialize function pointers in LedModule, set the LED light-up function pointer to point to pin-driven "PIN", duty cycle control "PWM", and chip-driven "WS2812B" respectively, and implement the start function to start the LED hardware circuit output enable by receiving message instructions; the callback function calls pturnon and pturnoff through timer interrupt to perform the light-up and light-down operations; S5: In the main function, directly configure the driver type in cfg; The driver type configuration operations include: ① directly calling pinit in the LedModule pointer variable for initialization; ② waiting to receive instructions and calling pstart in the LedModule pointer variable to enable the LED hardware circuit output; ③ periodically calling the phandler function to perform LED running light operation or directly calling pturnon to turn on the LED and pturnoff to turn off the LED.

Citation Information

Patent Citations

  • Light emitting diode and manufacturing method therefor

    CN106165125A

  • LED intelligent monitoring illumination system

    CN214316351U