At present, the three-color LED pins in the default project of the SDK do not support PWM functionality.
Currently, the PWM project of the SDK is not open to users for modifying RGB values with external devices. If there is a development need, please contact the developers!
If PWM support is required, please refer to the pin diagram of the chip, and connect the RGB LED to the GPIO pins that the PWM1 register uses (for example, on the 7236, these are pins 32, 34, and 36).
Hardware configuration for a three-color LED light supporting PWM (Pulse Width Modulation)
We still take the double lamp 7236 module as an example to introduce the hardware configuration.
In this demo project, the BK7236 module is used as shown in the following figure:
In this module, the GPIO pin connected to the LED1 is controlled by the PWM1 register on the left, thus, LED1 supports PWM functionality.
Software configuration for a three-color LED light supporting PWM (Pulse Width Modulation)
The software running logic for a three-color LED light that supports PWM is identical to that of a regular three-color light.
If you have not read the software design logic for the three-color LED light, please see :Introduction to the Software Mechanism and Interface of the RGB LED Lighting System for details.
Below is an introduction to the PWM-specific part, which provides a simple explanation based on the 7236 module shown in the above image.
PWM (Pulse Width Modulation) is a commonly used analog signal processing technology, which simulates analog signals of different intensities by controlling the width of pulse signals. In LED (light-emitting diode) applications, PWM is mainly used to adjust the brightness of LEDs.
Below are the main applications of PWM on LEDs:
Brightness Adjustment: By changing the duty cycle (the proportion of the pulse high level time to the overall cycle time) of PWM, the brightness of the LED can be controlled. The higher the duty cycle, the brighter the LED; the lower the duty cycle, the dimmer the LED.
Simulated Brightness: Although LEDs are digital devices, PWM can achieve effects similar to analog brightness adjustment. By changing the frequency and duty cycle of PWM, different brightness continuous changes can be produced.
Flicker Elimination: At low brightness, LEDs may flicker, which can be uncomfortable for people. By using PWM at an appropriate frequency (usually above a few thousand hertz), this flickering can be effectively eliminated.
Color Control: In RGB LED (red, green, blue light-emitting diode) applications, PWM can control the brightness of each color separately, thus achieving the adjustment of mixed light colors.
Image Display: In some special LED applications, such as LED displays, PWM can be used to control the brightness of each pixel, realizing the display of dynamic images.
In summary, PWM has a very wide range of applications in LEDs and is an important technology for adjusting LED brightness and color in modern electronic devices.
The PWM project is not applicable to the same engineering as the previous LED project. If you are using the PWM project, please use the following compilation command:
This API is used to configure the period and duty time. The unit is cycle of PWM channel clock, since the PWM channel clock is default to 26M, the unit is 1/26M (1/26 000 000) seconds.
The beken chip supports up to 3 duties, the exact duty numbers depends on the target type.
The software design for the PWM engineering is the same as that for the common LED three-color lights. The PWM engineering also requires the registration of external APIs. The interface for the external API is as follows:
The specific implementations of these functions can be carried out by the customer themselves, or functions that have already been written in the demo can be used.
These functions are just the specific implementation of the settings for the PWM LED. What we need to do next is to unify these APIs to the corresponding vendor APIs.
Just like in the LED tri-color lamp project, all the vendor information is stored under the global structure g_vendor_info , and for the PWM project, what we need to focus on is the struct bk_mesh_256_color_light_msg led_256_control .
The definition of the structure struct bk_mesh_256_color_light_msg is as follows:
Additionally, in order to characterize the compiled version that supports PWM projects, the following operations need to be performed in the initialization function:
Among them, BK_MESH_DEMO_SUPPORT_PWM_LED occupies BIT2 in the Bitmap, which is currently used for the internal message mechanism. If users need to set it in the external APP, please refer to the TODO Developer Documentation!
Note
To use PWM engineering, you need to enable CONFIG_BK_WIFI_MESH_DEMO_PWM_LED, and it is important to note that only LED1 supports PWM,
while LED2 only supports single-color configuration. In the case of using the double-LED bk7236 hardware module,
there is no need to enable CONFIG_BK_WIFI_MESH_DEMO_LED. This macro is prepared for the single-LED hardware group.
Similar to the LED tri-color light engineering, the external API used in the PWM LED engineering mentioned above is also from the unified external API provided by the vendor.
The overall process of determining which engineering to execute is by comparing the internal bit values stored in g_vendor_info.vendor_bitmap with the external bit values carried by the Vendor API (of course, there are also corresponding macros for protection).
The following figure is an internal execution flowchart of the Vendor API for the PWM engineering.
The set vendor function is currently supported internally in the SDK, but the mobile APP provided by Beken does not support configuration, therefore, the default SDK does not support PWM LED configuration!
If necessary, you can implement the APP-side settings yourself or contact the developer!
The format of the Vendor field in the external message area used in the demo project
The PWM LED project uses the Vendor field format in the external message area that is the same as the tri-color LED project, but with the following distinctions:
-ThePWMLEDprojectusesBIT2inthebitmapasamarker.
The PWM LED project uses the Bitmap2 Content field.
Below is an introduction to the Vendor field format related to the PWM LED project.
Bitmap0 is currently being used by the PWM LED project. For communication between user external devices and nodes, if it involves PWM LED interaction, this bit needs to be set to 1.
When this bit is set to 1, it indicates that this command supports PWM LED control.
When this bit is set to 0, it indicates that this command does not support PWM LED control.
Note
This field is effective when configured as true under the condition of CONFIG_BK_WIFI_MESH_DEMO_PWM_LED !