Skip to content

Commit cde860a

Browse files
fix(lightbulb): Reconfigure KP18052 parameters
1 parent ce4c75d commit cde860a

File tree

6 files changed

+48
-33
lines changed

6 files changed

+48
-33
lines changed

components/led/lightbulb_driver/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# ChangeLog
22

3+
## v1.1.4 - 2024-05-07
4+
5+
### Bug Fixes:
6+
7+
* Reconfigure KP18052 parameters
8+
* When the IIC dimming gray scale data size is 0, skip sending the data and only send the address.
9+
310
## v1.1.3 - 2024-04-24
411

512
### Bug Fixes:

components/led/lightbulb_driver/drivers/common/iic/iic.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ static iic_config_t *s_obj = NULL;
5656
static esp_err_t _write(uint8_t addr, uint8_t *data_wr, size_t size)
5757
{
5858
#if 0
59+
printf("--------start----------\r\n");
5960
ESP_LOG_BUFFER_HEX_LEVEL(" _write addr:", &addr, 1, ESP_LOG_INFO);
6061
ESP_LOG_BUFFER_HEX_LEVEL(" _write data:", data_wr, size, ESP_LOG_INFO);
61-
printf("--------------------\r\n");
62+
printf("--------stop----------\r\n");
6263
#endif
6364
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
6465
i2c_master_start(cmd);
6566
i2c_master_write_byte(cmd, addr, ACK_CHECK_DIS);
66-
i2c_master_write(cmd, data_wr, size, ACK_CHECK_DIS);
67+
// AEG-1520
68+
if (size > 0) {
69+
i2c_master_write(cmd, data_wr, size, ACK_CHECK_DIS);
70+
}
6771
i2c_master_stop(cmd);
6872
s_obj->last_err = i2c_master_cmd_begin(s_obj->i2c_master_num, cmd, pdMS_TO_TICKS(10));
6973
i2c_cmd_link_delete(cmd);
@@ -134,7 +138,10 @@ esp_err_t iic_driver_write(uint8_t addr, uint8_t *data_wr, size_t size)
134138
i2c_send_data_t data = { 0 };
135139
data.addr = addr;
136140
data.real_data_size = size;
137-
memcpy(data.data, data_wr, size);
141+
//AEG-1520
142+
if (size > 0) {
143+
memcpy(data.data, data_wr, size);
144+
}
138145
if (xQueueSend(s_obj->cmd_queue_handle, &data, 0) != pdTRUE) {
139146
ESP_LOGE(TAG, "queue send data fail");
140147
ESP_LOG_BUFFER_HEX_LEVEL(TAG, data_wr, size, ESP_LOG_DEBUG);
@@ -165,7 +172,6 @@ esp_err_t iic_driver_send_task_create(void)
165172

166173
esp_err_t iic_driver_task_destroy(void)
167174
{
168-
DRIVER_CHECK(s_obj->cmd_queue_handle || s_obj->send_task_handle, "handle is null", return ESP_ERR_INVALID_STATE);
169175
clean_up();
170176
return ESP_OK;
171177
}

components/led/lightbulb_driver/drivers/kp18058/kp18058.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ esp_err_t kp18058_set_standby_mode(bool enable_standby)
161161
{
162162
DRIVER_CHECK(s_kp18058, "not init", return ESP_ERR_INVALID_STATE);
163163

164-
uint8_t addr = BASE_ADDR | BIT_STANDBY | BIT_NEXT_BYTE4;
165-
uint8_t value[13] = { 0 };
166-
167-
if (!enable_standby) {
168-
addr |= BIT_ALL_CHANNEL;
164+
uint8_t addr = 0x00;
165+
uint8_t value[10] = { 0 };
166+
if (enable_standby) {
167+
addr = BASE_ADDR | BIT_STANDBY | BIT_NEXT_BYTE4;
168+
} else {
169+
addr = BASE_ADDR | BIT_ALL_CHANNEL | BIT_NEXT_BYTE4;
169170
}
170-
memcpy(&value[0], s_kp18058->fixed_bit, 3);
171171

172172
return _write(addr, value, sizeof(value));
173173
}
@@ -303,12 +303,12 @@ kp18058_compensation_t kp18058_compensation_mapping(int voltage_v)
303303
{
304304
DRIVER_CHECK((voltage_v >= 140) && (voltage_v <= 330), "The compensation value is incorrect and cannot be mapped.", return KP18058_COMPENSATION_VOLTAGE_INVALID);
305305

306-
int voltages[15] = {
307-
140, 145, 150, 155, 160, 165, 170,
306+
int voltages[16] = {
307+
140, 145, 150, 155, 160, 165, 170, 175,
308308
260, 270, 280, 290, 300, 310, 320, 330
309309
};
310310

311-
for (size_t i = 0; i < 15; ++i) {
311+
for (size_t i = 0; i < 16; ++i) {
312312
if (voltage_v == voltages[i]) {
313313
return (kp18058_compensation_t)i;
314314
}
@@ -336,9 +336,9 @@ kp18058_slope_t kp18058_slope_mapping(float slope)
336336

337337
kp18058_chopping_freq_t kp18058_chopping_freq_mapping(int freq_hz)
338338
{
339-
DRIVER_CHECK((freq_hz >= 250) && (freq_hz <= 2000), "The slope value is incorrect and cannot be mapped.", return KP18058_CHOPPING_INVALID);
339+
DRIVER_CHECK((freq_hz >= 500) && (freq_hz <= 4000), "The slope value is incorrect and cannot be mapped.", return KP18058_CHOPPING_INVALID);
340340

341-
int freqs[4] = {2000, 1000, 500, 250};
341+
int freqs[4] = {4000, 2000, 1000, 500};
342342

343343
for (size_t i = 0; i < 4; ++i) {
344344
if (freq_hz == freqs[i]) {

components/led/lightbulb_driver/drivers/kp18058/kp18058.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ typedef enum {
2020
KP18058_COMPENSATION_VOLTAGE_160V,
2121
KP18058_COMPENSATION_VOLTAGE_165V,
2222
KP18058_COMPENSATION_VOLTAGE_170V,
23+
KP18058_COMPENSATION_VOLTAGE_175V,
2324
KP18058_COMPENSATION_VOLTAGE_260V,
2425
KP18058_COMPENSATION_VOLTAGE_270V,
2526
KP18058_COMPENSATION_VOLTAGE_280V,
@@ -48,10 +49,10 @@ typedef enum {
4849
*/
4950
typedef enum {
5051
KP18058_CHOPPING_INVALID = -1,
51-
KP18058_CHOPPING_2KHZ = 0,
52+
KP18058_CHOPPING_4KHZ = 0,
53+
KP18058_CHOPPING_2KHZ,
5254
KP18058_CHOPPING_1KHZ,
5355
KP18058_CHOPPING_500HZ,
54-
KP18058_CHOPPING_250HZ,
5556
} kp18058_chopping_freq_t;
5657

5758
/**

components/led/lightbulb_driver/idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "1.1.3"
1+
version: "1.1.4"
22
description: Provide multiple dimming driver solutions to easily build lightbulb applications
33
url: https://github.com/espressif/esp-iot-solution/tree/master/components/led/lightbulb_driver
44
dependencies:

components/led/lightbulb_driver/test_apps/main/lightbulb_driver_test.c

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,11 @@ TEST_CASE("BP1658CJ", "[Underlying Driver]")
490490
vTaskDelay(pdMS_TO_TICKS(100));
491491
TEST_ASSERT_EQUAL(ESP_OK, bp1658cj_set_rgbcw_channel(255, 0, 0, 0, 0));
492492
vTaskDelay(pdMS_TO_TICKS(100));
493-
//bp1658cj_set_sleep_mode(true); AEG-1520
493+
bp1658cj_set_sleep_mode(true);
494494
vTaskDelay(pdMS_TO_TICKS(100));
495495
TEST_ASSERT_EQUAL(ESP_OK, bp1658cj_set_rgbcw_channel(0, 255, 0, 0, 0));
496496
vTaskDelay(pdMS_TO_TICKS(100));
497-
//bp1658cj_set_sleep_mode(true); AEG-1520
497+
bp1658cj_set_sleep_mode(true);
498498
vTaskDelay(pdMS_TO_TICKS(100));
499499
TEST_ASSERT_EQUAL(ESP_OK, bp1658cj_set_rgbcw_channel(0, 0, 255, 0, 0));
500500
vTaskDelay(pdMS_TO_TICKS(100));
@@ -568,8 +568,8 @@ TEST_CASE("SM2x35EGH", "[Underlying Driver]")
568568
driver_sm2x35egh_t conf = {
569569
.rgb_current = SM2235EGH_CW_CURRENT_10MA,
570570
.cw_current = SM2235EGH_CW_CURRENT_40MA,
571-
.iic_clk = 5,
572-
.iic_sda = 4,
571+
.iic_clk = 4,
572+
.iic_sda = 3,
573573
.freq_khz = 300,
574574
.enable_iic_queue = true
575575
};
@@ -673,8 +673,8 @@ TEST_CASE("SM2x35EGH", "[Application Layer]")
673673
.type = DRIVER_SM2x35EGH,
674674
.driver_conf.sm2x35egh.rgb_current = SM2235EGH_RGB_CURRENT_20MA,
675675
.driver_conf.sm2x35egh.cw_current = SM2235EGH_CW_CURRENT_40MA,
676-
.driver_conf.sm2x35egh.iic_clk = 5,
677-
.driver_conf.sm2x35egh.iic_sda = 4,
676+
.driver_conf.sm2x35egh.iic_clk = 4,
677+
.driver_conf.sm2x35egh.iic_sda = 3,
678678
.driver_conf.sm2x35egh.freq_khz = 400,
679679
.driver_conf.sm2x35egh.enable_iic_queue = true,
680680
.capability.enable_fade = true,
@@ -750,10 +750,10 @@ TEST_CASE("WS2812", "[Application Layer]")
750750
TEST_CASE("KP18058", "[Underlying Driver]")
751751
{
752752
driver_kp18058_t kp18058 = {
753-
.rgb_current_multiple = 10,
753+
.rgb_current_multiple = 3,
754754
.cw_current_multiple = 10,
755-
.iic_clk = 5,
756-
.iic_sda = 4,
755+
.iic_clk = 4,
756+
.iic_sda = 3,
757757
.iic_freq_khz = 300,
758758
.enable_iic_queue = true,
759759
};
@@ -844,8 +844,8 @@ TEST_CASE("KP18058", "[Underlying Driver]")
844844
TEST_ASSERT_EQUAL(KP18058_SLOPE_7_5, kp18058_slope_mapping(7.5));
845845
TEST_ASSERT_EQUAL(KP18058_SLOPE_15_0, kp18058_slope_mapping(15));
846846
TEST_ASSERT_EQUAL(KP18058_CHOPPING_INVALID, kp18058_chopping_freq_mapping(0));
847-
TEST_ASSERT_EQUAL(KP18058_CHOPPING_2KHZ, kp18058_chopping_freq_mapping(2000));
848-
TEST_ASSERT_EQUAL(KP18058_CHOPPING_250HZ, kp18058_chopping_freq_mapping(250));
847+
TEST_ASSERT_EQUAL(KP18058_CHOPPING_4KHZ, kp18058_chopping_freq_mapping(4000));
848+
TEST_ASSERT_EQUAL(KP18058_CHOPPING_500HZ, kp18058_chopping_freq_mapping(500));
849849

850850
//7. Deinit
851851
TEST_ASSERT_EQUAL(ESP_OK, kp18058_set_shutdown());
@@ -858,10 +858,10 @@ TEST_CASE("KP18058", "[Application Layer]")
858858
{
859859
lightbulb_config_t config = {
860860
.type = DRIVER_KP18058,
861-
.driver_conf.kp18058.rgb_current_multiple = 15,
862-
.driver_conf.kp18058.cw_current_multiple = 20,
863-
.driver_conf.kp18058.iic_clk = 5,
864-
.driver_conf.kp18058.iic_sda = 4,
861+
.driver_conf.kp18058.rgb_current_multiple = 3,
862+
.driver_conf.kp18058.cw_current_multiple = 10,
863+
.driver_conf.kp18058.iic_clk = 4,
864+
.driver_conf.kp18058.iic_sda = 3,
865865
.driver_conf.kp18058.iic_freq_khz = 300,
866866
.driver_conf.kp18058.enable_iic_queue = true,
867867
.capability.enable_fade = true,
@@ -887,6 +887,7 @@ TEST_CASE("KP18058", "[Application Layer]")
887887
TEST_ASSERT_EQUAL(ESP_OK, lightbulb_init(&config));
888888
vTaskDelay(pdMS_TO_TICKS(1000));
889889
lightbulb_lighting_output_test(LIGHTING_BASIC_FIVE, 1000);
890+
vTaskDelay(pdMS_TO_TICKS(2000));
890891
TEST_ASSERT_EQUAL(ESP_OK, lightbulb_deinit());
891892
}
892893
#endif

0 commit comments

Comments
 (0)