Skip to content

Commit 37c5d1a

Browse files
committed
Merge branch 'feature/ble_mesh_example_light_driver_v5.1' into 'release/v5.1'
feat: replace lightdriver, and support more chips in ble mesh examples(backport v5.1) See merge request espressif/esp-idf!28920
2 parents 7452f30 + e994071 commit 37c5d1a

File tree

22 files changed

+630
-1892
lines changed

22 files changed

+630
-1892
lines changed

examples/bluetooth/esp_ble_mesh/aligenie_demo/main/Kconfig.projbuild

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ menu "AliGenie Example Configuration"
2323
menu "light driver config"
2424
config LIGHT_GPIO_RED
2525
int "Light red pin GPIO number"
26+
range -1 48 if IDF_TARGET_ESP32S3
2627
range -1 33
2728
default 25
2829
help
@@ -33,6 +34,7 @@ menu "AliGenie Example Configuration"
3334

3435
config LIGHT_GPIO_GREEN
3536
int "Light green pin GPIO number"
37+
range -1 48 if IDF_TARGET_ESP32S3
3638
range -1 33
3739
default 26
3840
help
@@ -43,6 +45,7 @@ menu "AliGenie Example Configuration"
4345

4446
config LIGHT_GPIO_BLUE
4547
int "Light blue pin GPIO number"
48+
range -1 48 if IDF_TARGET_ESP32S3
4649
range -1 33
4750
default 27
4851
help
@@ -53,6 +56,7 @@ menu "AliGenie Example Configuration"
5356

5457
config LIGHT_GPIO_COLD
5558
int "Light cold colors pin GPIO number"
59+
range -1 48 if IDF_TARGET_ESP32S3
5660
range -1 33
5761
default -1
5862
help
@@ -63,6 +67,7 @@ menu "AliGenie Example Configuration"
6367

6468
config LIGHT_GPIO_WARM
6569
int "Light warm color pin GPIO number"
70+
range -1 48 if IDF_TARGET_ESP32S3
6671
range -1 33
6772
default -1
6873
help

examples/bluetooth/esp_ble_mesh/aligenie_demo/main/aligenie_demo.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static const char *TAG = "genie_demo";
3737

3838
#define MESH_ELEM_COUNT 1
3939
#define MESH_ELEM_STATE_COUNT MESH_ELEM_COUNT
40+
#define LIGHT_STATUS_STORE_KEY "light_status"
4041

4142
nvs_handle_t NVS_HANDLE;
4243

@@ -416,12 +417,34 @@ void user_genie_event_handle(genie_event_t event, void *p_arg)
416417
switch (event) {
417418
case GENIE_EVT_RESET_BY_REPEAT_NOTIFY:
418419
ESP_LOGI(TAG, "GENIE_EVT_RESET_BY_REPEAT_NOTIFY");
419-
light_driver_breath_start(0, 255, 0); /**< green blink */
420+
lightbulb_set_switch(false);
421+
lightbulb_effect_config_t effect1 = {
422+
.red = 0,
423+
.green = 255,
424+
.blue = 0,
425+
.max_brightness = 100,
426+
.min_brightness = 0,
427+
.effect_cycle_ms = CONFIG_LIGHT_BLINK_PERIOD_MS,
428+
.effect_type = EFFECT_BLINK,
429+
.mode = WORK_COLOR,
430+
};
431+
lightbulb_basic_effect_start(&effect1); /**< green blink */
420432
break;
421433
case GENIE_EVT_SW_RESET:
422434
case GENIE_EVT_HW_RESET_START:
423435
ESP_LOGI(TAG, "GENIE_EVT_HW_RESET_START");
424-
light_driver_breath_start(0, 255, 0); /**< green blink */
436+
lightbulb_set_switch(false);
437+
lightbulb_effect_config_t effect2 = {
438+
.red = 0,
439+
.green = 255,
440+
.blue = 0,
441+
.max_brightness = 100,
442+
.min_brightness = 0,
443+
.effect_cycle_ms = CONFIG_LIGHT_BLINK_PERIOD_MS,
444+
.effect_type = EFFECT_BLINK,
445+
.mode = WORK_COLOR,
446+
};
447+
lightbulb_basic_effect_start(&effect2); /**< green blink */
425448
ble_mesh_nvs_erase(NVS_HANDLE, LIGHT_STATUS_STORE_KEY); // erase led status
426449
reset_light_para();
427450
break;
@@ -442,7 +465,7 @@ void user_genie_event_handle(genie_event_t event, void *p_arg)
442465
g_indication_flag |= INDICATION_FLAG_CTL;
443466
#endif
444467
ESP_LOGI(TAG, "light_driver_breath_stop %s", __FUNCTION__);
445-
light_driver_breath_stop();
468+
lightbulb_basic_effect_stop();
446469
// update led status
447470
genie_event(GENIE_EVT_SDK_ANALYZE_MSG, &g_elem_state[0]);
448471
break;
@@ -1290,7 +1313,18 @@ static esp_err_t ble_mesh_init(void)
12901313
ESP_LOGW(TAG, "node already provisioned");
12911314
} else {
12921315
ESP_LOGW(TAG, "node not provisioned");
1293-
light_driver_breath_start(0, 255, 0); /**< green blink */
1316+
lightbulb_set_switch(false);
1317+
lightbulb_effect_config_t effect3 = {
1318+
.red = 0,
1319+
.green = 255,
1320+
.blue = 0,
1321+
.max_brightness = 100,
1322+
.min_brightness = 0,
1323+
.effect_cycle_ms = CONFIG_LIGHT_BLINK_PERIOD_MS,
1324+
.effect_type = EFFECT_BLINK,
1325+
.mode = WORK_COLOR,
1326+
};
1327+
lightbulb_basic_effect_start(&effect3); /**< green blink */
12941328
}
12951329

12961330
return err;

examples/bluetooth/esp_ble_mesh/aligenie_demo/main/board.c

Lines changed: 98 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
#include "esp_log.h"
1414

1515
#include "iot_button.h"
16-
#include "light_driver.h"
16+
#include "lightbulb.h"
1717

1818
#include "genie_event.h"
1919

20+
#if CONFIG_IDF_TARGET_ESP32C3
21+
#define BUTTON_ON_OFF 9 /* on/off button */
22+
#else
2023
#define BUTTON_ON_OFF 0 /* on/off button */
24+
#endif
2125
#define BUTTON_ACTIVE_LEVEL 0
2226

2327
static const char *TAG = "board";
@@ -38,22 +42,37 @@ static void board_led_init(void)
3842
* If the module has SPI flash, GPIOs 6-11 are connected to the module’s integrated SPI flash and PSRAM.
3943
* If the module has PSRAM, GPIOs 16 and 17 are connected to the module’s integrated PSRAM.
4044
*/
41-
light_driver_config_t driver_config = {
42-
.gpio_red = CONFIG_LIGHT_GPIO_RED,
43-
.gpio_green = CONFIG_LIGHT_GPIO_GREEN,
44-
.gpio_blue = CONFIG_LIGHT_GPIO_BLUE,
45-
.gpio_cold = CONFIG_LIGHT_GPIO_COLD,
46-
.gpio_warm = CONFIG_LIGHT_GPIO_WARM,
47-
.fade_period_ms = CONFIG_LIGHT_FADE_PERIOD_MS,
48-
.blink_period_ms = CONFIG_LIGHT_BLINK_PERIOD_MS,
45+
lightbulb_config_t config = {
46+
.type = DRIVER_ESP_PWM,
47+
.driver_conf.pwm.freq_hz = 4000,
48+
.capability.enable_fades = true,
49+
.capability.fades_ms = CONFIG_LIGHT_FADE_PERIOD_MS,
50+
.capability.enable_lowpower = false,
51+
.capability.enable_mix_cct = false,
52+
.capability.enable_status_storage = false,
53+
.capability.mode_mask = COLOR_MODE,
54+
.capability.storage_cb = NULL,
55+
.capability.sync_change_brightness_value = true,
56+
.io_conf.pwm_io.red = CONFIG_LIGHT_GPIO_RED,
57+
.io_conf.pwm_io.green = CONFIG_LIGHT_GPIO_GREEN,
58+
.io_conf.pwm_io.blue = CONFIG_LIGHT_GPIO_BLUE,
59+
.io_conf.pwm_io.cold_cct = CONFIG_LIGHT_GPIO_COLD,
60+
.io_conf.pwm_io.warm_brightness = CONFIG_LIGHT_GPIO_WARM,
61+
.external_limit = NULL,
62+
.gamma_conf = NULL,
63+
.init_status.mode = WORK_COLOR,
64+
.init_status.on = true,
65+
.init_status.hue = 0,
66+
.init_status.saturation = 100,
67+
.init_status.value = 100,
4968
};
5069

5170
/**
5271
* @brief Light driver initialization
5372
*/
54-
ESP_ERROR_CHECK(light_driver_init(&driver_config));
55-
light_driver_set_mode(MODE_HSL);
56-
// light_driver_set_switch(true);
73+
ESP_ERROR_CHECK(lightbulb_init(&config));
74+
vTaskDelay(pdMS_TO_TICKS(1000) * 1);
75+
lightbulb_set_switch(true);
5776

5877
button_handle_t dev_on_off_btn = iot_button_create(BUTTON_ON_OFF, BUTTON_ACTIVE_LEVEL);
5978
iot_button_set_evt_cb(dev_on_off_btn, BUTTON_CB_TAP, button_tap_cb, &dev_on_btn_num);
@@ -64,6 +83,62 @@ void board_init(void)
6483
board_led_init();
6584
}
6685

86+
static esp_err_t board_led_hsl2rgb(uint16_t hue, uint8_t saturation, uint8_t lightness,
87+
uint8_t *red, uint8_t *green, uint8_t *blue)
88+
{
89+
uint16_t hi = (hue / 60) % 6;
90+
uint16_t C = (100 - abs(2 * lightness - 100)) * saturation / 100;
91+
uint16_t M = 100 * (lightness - 0.5 * C) / 100;
92+
uint16_t X = C * (100 - abs((hue * 100 / 60 ) % 200 - 100)) / 100;
93+
94+
switch (hi) {
95+
case 0: /* hue 0~60 */
96+
*red = C + M;
97+
*green = X + M;
98+
*blue = M;
99+
break;
100+
101+
case 1: /* hue 60~120 */
102+
*red = X + M;
103+
*green = C + M;
104+
*blue = M;
105+
break;
106+
107+
case 2: /* hue 120~180 */
108+
*red = M;
109+
*green = C + M;
110+
*blue = X + M;
111+
break;
112+
113+
case 3: /* hue 180~240 */
114+
*red = M;
115+
*green = X + M;
116+
*blue = C + M;
117+
break;
118+
119+
case 4: /* hue 240~300 */
120+
*red = X + M;
121+
*green = M;
122+
*blue = C + M;
123+
break;
124+
125+
case 5: /* hue 300~360 */
126+
*red = C + M;
127+
*green = M;
128+
*blue = X + M;
129+
break;
130+
131+
default:
132+
return ESP_FAIL;
133+
}
134+
135+
*red = *red * 255 / 100;
136+
*green = *green * 255 / 100;
137+
*blue = *blue * 255 / 100;
138+
139+
return ESP_OK;
140+
}
141+
67142
/**
68143
* hsl
69144
*/
@@ -86,8 +161,14 @@ void board_led_hsl(uint8_t elem_index, uint16_t hue, uint16_t saturation, uint16
86161
uint8_t actual_saturation = (float)last_saturation / (UINT16_MAX / 100.0);
87162
uint8_t actual_lightness = (float)last_lightness / (UINT16_MAX / 100.0);
88163

164+
uint8_t r, g, b;
165+
uint16_t h;
166+
uint8_t s, v;
167+
89168
ESP_LOGD(TAG, "hsl: %d, %d, %d operation", actual_hue, actual_saturation, actual_lightness);
90-
light_driver_set_hsl(actual_hue, actual_saturation, actual_lightness);
169+
board_led_hsl2rgb(actual_hue, actual_saturation, actual_lightness, &r, &g, &b);
170+
lightbulb_rgb2hsv(r, g, b, &h, &s, &v);
171+
lightbulb_set_hsv(h, s, v);
91172
}
92173
}
93174

@@ -105,7 +186,7 @@ void board_led_temperature(uint8_t elem_index, uint16_t temperature)
105186

106187
uint16_t actual_temperature = (float)last_temperature / (UINT16_MAX / 100.0);
107188
ESP_LOGD(TAG, "temperature %d %%%d operation", last_temperature, actual_temperature);
108-
light_driver_set_color_temperature(actual_temperature);
189+
lightbulb_set_cct(actual_temperature);
109190
}
110191
}
111192

@@ -123,7 +204,7 @@ void board_led_lightness(uint8_t elem_index, uint16_t actual)
123204

124205
uint16_t actual_lightness = (float)last_acual / (UINT16_MAX / 100.0);
125206
ESP_LOGD(TAG, "lightness %d %%%d operation", last_acual, actual_lightness);
126-
light_driver_set_lightness(actual_lightness);
207+
lightbulb_set_brightness(actual_lightness);
127208
}
128209
}
129210

@@ -139,10 +220,10 @@ void board_led_switch(uint8_t elem_index, uint8_t onoff)
139220
last_onoff = onoff;
140221
if (last_onoff) {
141222
ESP_LOGD(TAG, "onoff %d operation", last_onoff);
142-
light_driver_set_switch(true);
223+
lightbulb_set_switch(true);
143224
} else {
144225
ESP_LOGD(TAG, "onoff %d operation", last_onoff);
145-
light_driver_set_switch(false);
226+
lightbulb_set_switch(false);
146227
}
147228
}
148229
}

examples/bluetooth/esp_ble_mesh/aligenie_demo/main/include/board.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern "C" {
1414
#endif /**< __cplusplus */
1515

1616
#include "driver/gpio.h"
17-
#include "light_driver.h"
17+
#include "lightbulb.h"
1818

1919
#define LED_ON 1
2020
#define LED_OFF 0

examples/bluetooth/esp_ble_mesh/aligenie_demo/sdkconfig.defaults

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ CONFIG_BLE_MESH_MODEL_KEY_COUNT=5
3535
CONFIG_BLE_MESH_MODEL_GROUP_COUNT=5
3636
CONFIG_BLE_MESH_MSG_CACHE_SIZE=20
3737
CONFIG_BLE_MESH_ADV_BUF_COUNT=256
38+
39+
#
40+
# light driver config
41+
#
42+
CONFIG_PWM_ENABLE_HW_FADE=n
43+
# end of light driver config

examples/bluetooth/esp_ble_mesh/aligenie_demo/sdkconfig.defaults.esp32c3

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
#
2-
# Partition Table
3-
#
4-
CONFIG_PARTITION_TABLE_CUSTOM=y
5-
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
6-
7-
#
8-
# Serial flasher config
9-
#
10-
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
11-
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
12-
131
# Override some defaults so BT stack is enabled
142
# by default in this example
153
CONFIG_BT_ENABLED=y
@@ -18,20 +6,8 @@ CONFIG_BT_CTRL_BLE_MESH_SCAN_DUPL_EN=y
186
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
197
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
208
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
21-
22-
# Override some defaults of ESP BLE Mesh
23-
CONFIG_BLE_MESH=y
24-
CONFIG_BLE_MESH_NODE=y
25-
CONFIG_BLE_MESH_PB_GATT=y
26-
CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=10
27-
CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=10
28-
CONFIG_BLE_MESH_SETTINGS=y
29-
CONFIG_BLE_MESH_SUBNET_COUNT=5
30-
CONFIG_BLE_MESH_APP_KEY_COUNT=5
31-
CONFIG_BLE_MESH_MODEL_KEY_COUNT=5
32-
CONFIG_BLE_MESH_MODEL_GROUP_COUNT=5
33-
CONFIG_BLE_MESH_MSG_CACHE_SIZE=20
34-
CONFIG_BLE_MESH_ADV_BUF_COUNT=256
9+
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
10+
CONFIG_BT_LE_50_FEATURE_SUPPORT=n
3511

3612
#
3713
# light driver config
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Override some defaults so BT stack is enabled
2+
# by default in this example
3+
CONFIG_BT_ENABLED=y
4+
CONFIG_BT_LE_SCAN_DUPL_TYPE_DATA_DEVICE=y
5+
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
6+
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
7+
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
8+
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
9+
CONFIG_BT_LE_50_FEATURE_SUPPORT=n
10+
11+
#
12+
# light driver config
13+
#
14+
CONFIG_LIGHT_GPIO_RED=4
15+
CONFIG_LIGHT_GPIO_GREEN=5
16+
CONFIG_LIGHT_GPIO_BLUE=6
17+
CONFIG_LIGHT_GPIO_COLD=7
18+
CONFIG_LIGHT_GPIO_WARM=10
19+
# end of light driver config
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Override some defaults so BT stack is enabled
2+
# by default in this example
3+
CONFIG_BT_ENABLED=y
4+
CONFIG_BT_LE_SCAN_DUPL_TYPE_DATA_DEVICE=y
5+
CONFIG_BT_GATTS_SEND_SERVICE_CHANGE_MANUAL=y
6+
CONFIG_BT_BTU_TASK_STACK_SIZE=4512
7+
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
8+
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
9+
CONFIG_BT_LE_50_FEATURE_SUPPORT=n
10+
11+
#
12+
# light driver config
13+
#
14+
CONFIG_LIGHT_GPIO_RED=4
15+
CONFIG_LIGHT_GPIO_GREEN=5
16+
CONFIG_LIGHT_GPIO_BLUE=11
17+
CONFIG_LIGHT_GPIO_COLD=12
18+
CONFIG_LIGHT_GPIO_WARM=10
19+
# end of light driver config

0 commit comments

Comments
 (0)