Universal LED driving method
Through the method of abstract and pointer mapping, the control programs of different LED drivers are unified, and the complex and difficult problems of drivers in existing technologies have been solved, and efficient LED driver integration is achieved.
Patent Information
- Application Number
- CN202411470918.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-21
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2044-10-21
AI Technical Summary
In the prior art, the main control chip needs to adopt different control programs according to different LED driving methods, which makes the drivers complex and difficult to unify.
By abstracting the same parts of different drivers, and using the pointer method to map different parts, a program can form a program that can uniformly control the integration method of IO driver, PWM driver and special chip driver.
The unity and efficiency of the LED driver is achieved, the efficiency of the driver is improved, and the configuration and management of the driver method is simplified.
Smart Images

Figure CN119377137A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of computer control and relates to a universal LED driving method. Background Art
[0002] LED is a semiconductor device. Common hardware driving methods include constant current driving, constant voltage driving, PWM driving and other methods. The main control chip driving methods include direct / indirect IO driving, PWM driving, and direct driving of LED chips. The advantages of direct IO driving are simple circuits and easy implementation. The disadvantages are that the direct IO driving capability is limited and it is suitable for driving a small number of LEDs. Indirect IO driving methods such as triode driving and Darlington driving have the advantages of strong driving capability and the disadvantages of complex circuits. In addition, the dedicated LED chip driving method has a simple circuit design and rich functions, but the cost is relatively high. Summary of the invention
[0003] 1. Technical issues to be resolved
[0004] For different LED driving methods, the main control chip usually needs to be driven by different control programs. The present invention abstracts the same parts in different driving methods and maps the different parts through pointers, forming a program that can control the integration of IO drive, PWM drive, and proprietary chip driver.
[0005] (II) Technical solution
[0006] In order to solve the above technical problems, the present invention provides a universal LED driving method, which comprises the following steps:
[0007] S1: define the module configuration information structure driverCfg;
[0008] S2: define the module driver structure driverInfo;
[0009] S3: define the module driver structure driverInfo pointer variable LedModule in S2;
[0010] S4: For different driver matching, initialize the function pointer in LedModule, light up the LED function pointer, and turn off the LED function pointer to point to the pin drive type "PIN", duty cycle control type "PWM", and chip drive type "WS2812B" respectively, and implement the start function, and start the LED hardware circuit output enable by receiving the message instruction; the callback function calls pturnon and pturnoff through the timer interrupt method to perform lighting and extinguishing operations;
[0011] S5: In the main function, directly configure the driver type in cfg.
[0012] In step S1, the module configuration information structure driverCfg includes: ① the driver module name drv_name, the type is character pointer type; ② the version number version, the type is character pointer.
[0013] In step S1, a module configuration information structure variable cfg is defined.
[0014] In step S2, the module driver structure driverInfo includes: ① initialization function pointer pinit, ② start running function pointer pstart, ③ callback function pointer phandler, ④ light up LED function pointer pturnon, ⑤ turn off LED function pointer pturnoff.
[0015] In step S3, the initial value of the pointer variable LedModule is set to NULL.
[0016] In step S3, the module information is stored in the structure variable cfg in step S1, and 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", and ③ programmable LED module "WS2812B".
[0017] In step S3, for the matching result of the pin drive type "PIN", the following operations are performed:
[0018] S3_21 points the initialization pointer pinit in S2 to the pin driver initialization function pin_init, in which the InitGPIO() initialization function is called to initialize the IO driving the LED;
[0019] S3_22 points the LED lighting function pointer pturnon in S2 to the pin-driven LED lighting function pin_turnon. This function calls the switch setting function setGPIO() to light up the LED.
[0020] S3_23 points the LED turning-off function pointer pturnoff in S2 to the pin-driven LED turning-off function pin_turnoff. This function calls the reset switch function resetGPIO() to turn off the LED.
[0021] In step S3, if the matching result is the duty cycle control type "PWM", the following operations are performed:
[0022] S3_31 points the initialization pointer pinit in S2 to the duty cycle control initialization function pwm_init, and this function calls the InitPWM() initialization function to initialize the PWM peripherals;
[0023] S3_32 points the LED lighting function pointer pturnon in S2 to the duty cycle controlled LED lighting function pwm_turnon. In this function, the duty cycle setting function setpwm() is called with a parameter of 1 to light up the LED.
[0024] S3_33 points the LED turning off function pointer pturnoff in S2 to the duty cycle controlled LED lighting function pwm_turnoff. In this function, the duty cycle setting function setpwm() is called with a parameter of 0 to turn off the LED.
[0025] In step S3, if the matching result is the chip driver type "WS2812B", the following operations are performed:
[0026] Set the initialization pointer pinit in S2 to point to the pin-driven initialization function init. In this function, the InitGPIO() initialization function is called to control the LED through the IO driver WS2812B chip.
[0027] In step S5, the operations of the drive type configuration include: ① directly calling pinit in the LedModule pointer variable to perform initialization operation; ② waiting for receiving instructions, calling pstart in the LedModule pointer variable to start the LED hardware circuit output enable; ③ periodically calling the phandler function to perform the water light operation or directly calling pturnon to light up the LED and pturnoff to turn off the LED for operation.
[0028] (III) Beneficial effects
[0029] The universal LED driving method provided by the above technical solution integrates and unifies the LED IO driving mode, PWM driving mode, and dedicated chip driving mode, thereby improving the efficiency of the LED driving program. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 This is a flow chart of the universal LED driving method of the present invention. DETAILED DESCRIPTION
[0031] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.
[0032] Reference Figure 1 As shown, the general LED driving method of this embodiment includes the following steps:
[0033] S1: Define the module configuration information structure driverCfg
[0034] The module configuration information structure driverCfg includes: ① the driver module name drv_name, the type is character pointer type; such as "LED"; ② the version number version, the type is character pointer. Define the module configuration information structure variable cfg.
[0035] S2: Define the module driver structure driverInfo
[0036] The module driver structure driverInfo includes: ① initialization function pointer pinit, ② start running function pointer pstart, ③ callback function pointer phandler, ④ light up LED function pointer pturnon, ⑤ turn off LED function pointer pturnoff.
[0037] S3: Define the module driver structure driverInfo pointer variable LedModule in S2
[0038] The initial value of the pointer variable LedModule is set to NULL.
[0039] 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".
[0040] S3_2 For the pin driving type "PIN" as the matching result, perform the following operations:
[0041] S3_21 points the initialization pointer pinit in S2 to the pin driver initialization function pin_init, in which the InitGPIO() initialization function is called to initialize the IO driving the LED.
[0042] S3_22 points the LED lighting function pointer pturnon in S2 to the pin-driven LED lighting function pin_turnon. This function calls the switch setting function setGPIO() to light up the LED.
[0043] S3_23 points the LED turning-off function pointer pturnoff in S2 to the pin-driven LED turning-off function pin_turnoff. This function calls the reset switch function resetGPIO() to turn off the LED.
[0044] S3_3 performs the following operations for the duty cycle control type "PWM" when the matching result is obtained:
[0045] S3_31 points the initialization pointer pinit in S2 to the duty cycle control initialization function pwm_init, and this function calls the InitPWM() initialization function to initialize the PWM peripheral.
[0046] S3_32 points 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.
[0047] S3_33 points the LED turning off function pointer pturnoff in S2 to the duty cycle controlled LED lighting function pwm_turnoff. In this function, the duty cycle setting function setpwm() is called with a parameter of 0 to turn off the LED.
[0048] S3_4 For the matching result of chip driver type "WS2812B", perform the following operations:
[0049] Set the initialization pointer pinit in S2 to point to the pin-driven initialization function init. In this function, the InitGPIO() initialization function is called to control the LED through the IO driver WS2812B chip.
[0050] S4: For different driver matching, the initialization function pointer in LedModule, the LED lighting function pointer, and the LED extinguishing function pointer point to the pin driving type "PIN", the duty cycle control type "PWM", and the chip driving type "WS2812B" respectively, and realize the start running function, and start the LED hardware circuit output enable by receiving the message instruction; the callback function calls pturnon and pturnoff through the timer interrupt mode to light up and extinguish the operation. Such as 1S running light.
[0051] S5: In the main function, directly configure the driver type in cfg without modifying other parts.
[0052] The operations of driver type configuration include: ① directly call pinit in the LedModule pointer variable to perform initialization operation. ② wait for receiving instructions, call pstart in the LedModule pointer variable to start the LED hardware circuit output enable. ③ periodically call the phandler function to operate the water light or directly call pturnon to light up the LED and pturnoff to turn off the LED for operation.
[0053] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.
Claims
1. A general LED driving method, characterized in that: The following steps are involved: S1: define the module configuration information structure driverCfg; S2: define the module driver structure driverInfo; S3: define the module driver structure driverInfo pointer variable LedModule in S2; S4: For different driver matching, initialize the function pointer in LedModule, light up the LED function pointer, and turn off the LED function pointer to the pin drive type "PIN", duty cycle control type "PWM", and chip drive type "WS2812B" respectively, and implement the start function, start the LED hardware circuit output enable by receiving the message instruction; the callback function calls pturnon and pturnoff through the timer interrupt mode to light up and turn off the LED; S5: In the main function, directly configure the driver type in cfg.
2. The universal LED driving method according to claim 1, characterized in that: In step S1, the module configuration information structure driverCfg includes: ① the driver module name drv_name, the type is character pointer type; ② the version number version, the type is character pointer.
3. The universal LED driving method according to claim 2, characterized in that: In step S1, a module configuration information structure variable cfg is defined.
4. The universal LED driving method according to claim 3, characterized in that: In step S2, the module driver structure driverInfo includes: ① initialization function pointer pinit, ② start running function pointer pstart, ③ callback function pointer phandler, ④ light up LED function pointer pturnon, ⑤ turn off LED function pointer pturnoff.
5. The universal LED driving method according to claim 4, characterized in that: In step S3, the initial value of the pointer variable LedModule is set to NULL.
6. The universal LED driving method according to claim 5, characterized in that: In step S3, the module information is stored in the structure variable cfg in step S1, and 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", and ③ programmable LED module "WS2812B".
7. The universal LED driving method according to claim 6, characterized in that: In step S3, for the matching result of the pin drive type "PIN", the following operations are performed: S3_21 points the initialization pointer pinit in S2 to the pin driver initialization function pin_init, in which the InitGPIO() initialization function is called to initialize the IO driving the LED; S3_22 points the LED lighting function pointer pturnon in S2 to the pin-driven LED lighting function pin_turnon. This function calls the switch setting function setGPIO() to light up the LED. S3_23 points the LED turning-off function pointer pturnoff in S2 to the pin-driven LED turning-off function pin_turnoff. This function calls the reset switch function resetGPIO() to turn off the LED.
8. The universal LED driving method according to claim 7, characterized in that: In step S3, if the matching result is the duty cycle control type "PWM", the following operations are performed: S3_31 points the initialization pointer pinit in S2 to the duty cycle control initialization function pwm_init, and this function calls the InitPWM() initialization function to initialize the PWM peripherals; S3_32 points the LED lighting function pointer pturnon in S2 to the duty cycle controlled LED lighting function pwm_turnon. In this function, the duty cycle setting function setpwm() is called with a parameter of 1 to light up the LED. S3_33 points the LED turning off function pointer pturnoff in S2 to the duty cycle controlled LED lighting function pwm_turnoff. In this function, the duty cycle setting function setpwm() is called with a parameter of 0 to turn off the LED.
9. The universal LED driving method according to claim 8, characterized in that: In step S3, if the matching result is the chip driver type "WS2812B", the following operations are performed: Set the initialization pointer pinit in S2 to point to the pin-driven initialization function init. In this function, the InitGPIO() initialization function is called to control the LED through the IO driver WS2812B chip.
10. The universal LED driving method according to claim 9, characterized in that: In step S5, the operations of the drive type configuration include: ① directly calling pinit in the LedModule pointer variable to perform initialization operation; ② waiting for receiving instructions, calling pstart in the LedModule pointer variable to start the LED hardware circuit output enable; ③ periodically calling the phandler function to perform the water light operation or directly calling pturnon to light up the LED and pturnoff to turn off the LED for operation.
Citation Information
Patent Citations
Light emitting diode and manufacturing method therefor
CN106165125A
M-led, m-led array, display and method therefor
CN114097099A
LED intelligent monitoring illumination system
CN214316351U
Decoder compatible with various colorful LED driving ICs
CN221598177U
Display device, display module, and electronic apparatus
JP2017207697A