Currently, the general three-color LED light project of the SDK is the default project, and its used external project macro BK_MESH_DEMO_SUPPORT_PWM_LED is set to default as ‘y’.
The general three-color LED light project of the SDK does not support PWM!
Please refer to :Introduction to the Software Mechanism and Interface Introduction of PWM LED Control Mechanism for PWM project configuration and implementation.
Hardware configuration of the RGB LED Lighting System
The SDK uses an internal test module to test a common three-color he RGB LED Lighting System project.
As shown in the figure below, it uses the BK7236 module:
Three-color he RGB LED Lighting System project bk7236 module
The following chart shows the GPIO pin configuration for the default ordinary Three-color RGB LED Lighting System engineering of the SDK:
Color pin | GPIO pin
BK_MESH_PWM_RED_PIN
18
BK_MESH_PWM_GREEN_PIN
24
BK_MESH_PWM_BLUE_PIN
19
Configurations of GPIO pins for hree-color he RGB LED Lighting System project.
Note
Please ensure that the configuration is set below BK_MESH_DEMO_SUPPORT_PWM_LED !
Software Configuration for Three-color RGB LED Lighting System
The software configuration for Three-color RGB LED Lighting System follows the Vendor’s software configuration as well, i.e.,
it occupies the bit0 position of the Vendor Bitmap and the Bitmap0 Content field.
Of course, the default field design of the SDK merely provides a method of implementation, allowing users to design the content of the Bitmap0 Content themselves.
Below, I will introduce the default design form of the SDK.
Three-color RGB LED Lighting System implementation
demo path:
components/demos/bk_mesh_led_demo.c
Note
The Three-color RGB LED Lighting System is supported by default, and the compilation command is as follows (the part in parentheses is optional):
make bk7236 -j8 (PROJECT=bk_mesh/3_led)
Internal API used for Three-color RGB LED Lighting System
In the demo project, we only use the introductions of these APIs as follows:
Register an alarm to AON_RTC id timer !!! NOTES: the callback function is in ISR, so can’t block too much time. F.E:can’t call sleep/suspend; !!! !!! NOTES: freertos forbid call free/malloc in ISR which include suspend and resume. !!! @id: register to which aon_rtc id
Parameters
alarm_info_p – includes below info: name_p: the name of the registered alarm period_time: what’s the alarm time, milliseconds * AON_RTC_MS_TICK_CNT period_cnt: 0xFFFFFFF means always period until user unregister it, or means period how many times callback: if the alarm comes, will call this callback param_p: the param will be used for callback
The specific implementation of these functions can be done by the client themselves, or functions already written in the demo can be used.
These functions are merely the specific implementation settings within Three-color RGB LED Lighting System. What we need to do next is to unify these APIs to the corresponding vendor APIs.
All vendor information is stored under the global structure named g_vendor_info , while in the cThree-color RGB LED Lighting System, what we need to focus on is the struct bk_mesh_light_msg led_control .
Among them, BK_MESH_DEMO_SUPPORT_LED occupies BIT0 in the Bitmap!
Note
Three-color RGB LED Lighting System requires enabling CONFIG_BK_WIFI_MESH_DEMO_LED!
Registration of the external API used in the Three-color RGB LED Lighting System
The overall process of the external API is determined by comparing the internal bit values stored in g_vendor_info.vendor_bitmap with the external bit values carried by the Vendor API,
to decide which project to execute (of course, there are also corresponding macros for protection).
The following illustration shows the internal execution flow chart of the Vendor API for a common three-color LED lamp:
Bitmap0 is currently used in Three-color RGB LED Lighting System, for communication between users’ external devices and nodes. If PWM LED interaction is involved, this bit needs to be set to 1.
When this bit is 1, it indicates that this command supports LED control.
When this bit is 0, it indicates that this command does not support LED control.
Note
This field takes effect when it is CONFIG_BK_WIFI_MESH_DEMO_LED configured as true!
Throughout the bitmap, the enable bits representing the three primary colors (Red, Green, Blue) from low to high are arranged.
Currently, in order to expand, each primary color group occupies two bits, with its structure shown as follows:
The structure diagram of the enable bit for the primary color group
From the above figure, it can be seen that at present, each primary color’s enable only occupies the low bit positions of the enable group, with the high bit positions reserved.