Skip to content

Commit

Permalink
Merge branch 'fix/update_kp18052_param' into 'master'
Browse files Browse the repository at this point in the history
Fix/update kp18052 param

Closes AEG-1542

See merge request ae_group/esp-iot-solution!989
  • Loading branch information
leeebo committed May 9, 2024
2 parents 158546f + cde860a commit 2d1b12d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 33 deletions.
7 changes: 7 additions & 0 deletions components/led/lightbulb_driver/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# ChangeLog

## v1.1.4 - 2024-05-07

### Bug Fixes:

* Reconfigure KP18052 parameters
* When the IIC dimming gray scale data size is 0, skip sending the data and only send the address.

## v1.1.3 - 2024-04-24

### Bug Fixes:
Expand Down
14 changes: 10 additions & 4 deletions components/led/lightbulb_driver/drivers/common/iic/iic.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,18 @@ static iic_config_t *s_obj = NULL;
static esp_err_t _write(uint8_t addr, uint8_t *data_wr, size_t size)
{
#if 0
printf("--------start----------\r\n");
ESP_LOG_BUFFER_HEX_LEVEL(" _write addr:", &addr, 1, ESP_LOG_INFO);
ESP_LOG_BUFFER_HEX_LEVEL(" _write data:", data_wr, size, ESP_LOG_INFO);
printf("--------------------\r\n");
printf("--------stop----------\r\n");
#endif
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, addr, ACK_CHECK_DIS);
i2c_master_write(cmd, data_wr, size, ACK_CHECK_DIS);
// AEG-1520
if (size > 0) {
i2c_master_write(cmd, data_wr, size, ACK_CHECK_DIS);
}
i2c_master_stop(cmd);
s_obj->last_err = i2c_master_cmd_begin(s_obj->i2c_master_num, cmd, pdMS_TO_TICKS(10));
i2c_cmd_link_delete(cmd);
Expand Down Expand Up @@ -134,7 +138,10 @@ esp_err_t iic_driver_write(uint8_t addr, uint8_t *data_wr, size_t size)
i2c_send_data_t data = { 0 };
data.addr = addr;
data.real_data_size = size;
memcpy(data.data, data_wr, size);
//AEG-1520
if (size > 0) {
memcpy(data.data, data_wr, size);
}
if (xQueueSend(s_obj->cmd_queue_handle, &data, 0) != pdTRUE) {
ESP_LOGE(TAG, "queue send data fail");
ESP_LOG_BUFFER_HEX_LEVEL(TAG, data_wr, size, ESP_LOG_DEBUG);
Expand Down Expand Up @@ -165,7 +172,6 @@ esp_err_t iic_driver_send_task_create(void)

esp_err_t iic_driver_task_destroy(void)
{
DRIVER_CHECK(s_obj->cmd_queue_handle || s_obj->send_task_handle, "handle is null", return ESP_ERR_INVALID_STATE);
clean_up();
return ESP_OK;
}
Expand Down
22 changes: 11 additions & 11 deletions components/led/lightbulb_driver/drivers/kp18058/kp18058.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ esp_err_t kp18058_set_standby_mode(bool enable_standby)
{
DRIVER_CHECK(s_kp18058, "not init", return ESP_ERR_INVALID_STATE);

uint8_t addr = BASE_ADDR | BIT_STANDBY | BIT_NEXT_BYTE4;
uint8_t value[13] = { 0 };

if (!enable_standby) {
addr |= BIT_ALL_CHANNEL;
uint8_t addr = 0x00;
uint8_t value[10] = { 0 };
if (enable_standby) {
addr = BASE_ADDR | BIT_STANDBY | BIT_NEXT_BYTE4;
} else {
addr = BASE_ADDR | BIT_ALL_CHANNEL | BIT_NEXT_BYTE4;
}
memcpy(&value[0], s_kp18058->fixed_bit, 3);

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

int voltages[15] = {
140, 145, 150, 155, 160, 165, 170,
int voltages[16] = {
140, 145, 150, 155, 160, 165, 170, 175,
260, 270, 280, 290, 300, 310, 320, 330
};

for (size_t i = 0; i < 15; ++i) {
for (size_t i = 0; i < 16; ++i) {
if (voltage_v == voltages[i]) {
return (kp18058_compensation_t)i;
}
Expand Down Expand Up @@ -336,9 +336,9 @@ kp18058_slope_t kp18058_slope_mapping(float slope)

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

int freqs[4] = {2000, 1000, 500, 250};
int freqs[4] = {4000, 2000, 1000, 500};

for (size_t i = 0; i < 4; ++i) {
if (freq_hz == freqs[i]) {
Expand Down
5 changes: 3 additions & 2 deletions components/led/lightbulb_driver/drivers/kp18058/kp18058.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef enum {
KP18058_COMPENSATION_VOLTAGE_160V,
KP18058_COMPENSATION_VOLTAGE_165V,
KP18058_COMPENSATION_VOLTAGE_170V,
KP18058_COMPENSATION_VOLTAGE_175V,
KP18058_COMPENSATION_VOLTAGE_260V,
KP18058_COMPENSATION_VOLTAGE_270V,
KP18058_COMPENSATION_VOLTAGE_280V,
Expand Down Expand Up @@ -48,10 +49,10 @@ typedef enum {
*/
typedef enum {
KP18058_CHOPPING_INVALID = -1,
KP18058_CHOPPING_2KHZ = 0,
KP18058_CHOPPING_4KHZ = 0,
KP18058_CHOPPING_2KHZ,
KP18058_CHOPPING_1KHZ,
KP18058_CHOPPING_500HZ,
KP18058_CHOPPING_250HZ,
} kp18058_chopping_freq_t;

/**
Expand Down
2 changes: 1 addition & 1 deletion components/led/lightbulb_driver/idf_component.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "1.1.3"
version: "1.1.4"
description: Provide multiple dimming driver solutions to easily build lightbulb applications
url: https://github.com/espressif/esp-iot-solution/tree/master/components/led/lightbulb_driver
dependencies:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ TEST_CASE("BP1658CJ", "[Underlying Driver]")
vTaskDelay(pdMS_TO_TICKS(100));
TEST_ASSERT_EQUAL(ESP_OK, bp1658cj_set_rgbcw_channel(255, 0, 0, 0, 0));
vTaskDelay(pdMS_TO_TICKS(100));
//bp1658cj_set_sleep_mode(true); AEG-1520
bp1658cj_set_sleep_mode(true);
vTaskDelay(pdMS_TO_TICKS(100));
TEST_ASSERT_EQUAL(ESP_OK, bp1658cj_set_rgbcw_channel(0, 255, 0, 0, 0));
vTaskDelay(pdMS_TO_TICKS(100));
//bp1658cj_set_sleep_mode(true); AEG-1520
bp1658cj_set_sleep_mode(true);
vTaskDelay(pdMS_TO_TICKS(100));
TEST_ASSERT_EQUAL(ESP_OK, bp1658cj_set_rgbcw_channel(0, 0, 255, 0, 0));
vTaskDelay(pdMS_TO_TICKS(100));
Expand Down Expand Up @@ -568,8 +568,8 @@ TEST_CASE("SM2x35EGH", "[Underlying Driver]")
driver_sm2x35egh_t conf = {
.rgb_current = SM2235EGH_CW_CURRENT_10MA,
.cw_current = SM2235EGH_CW_CURRENT_40MA,
.iic_clk = 5,
.iic_sda = 4,
.iic_clk = 4,
.iic_sda = 3,
.freq_khz = 300,
.enable_iic_queue = true
};
Expand Down Expand Up @@ -673,8 +673,8 @@ TEST_CASE("SM2x35EGH", "[Application Layer]")
.type = DRIVER_SM2x35EGH,
.driver_conf.sm2x35egh.rgb_current = SM2235EGH_RGB_CURRENT_20MA,
.driver_conf.sm2x35egh.cw_current = SM2235EGH_CW_CURRENT_40MA,
.driver_conf.sm2x35egh.iic_clk = 5,
.driver_conf.sm2x35egh.iic_sda = 4,
.driver_conf.sm2x35egh.iic_clk = 4,
.driver_conf.sm2x35egh.iic_sda = 3,
.driver_conf.sm2x35egh.freq_khz = 400,
.driver_conf.sm2x35egh.enable_iic_queue = true,
.capability.enable_fade = true,
Expand Down Expand Up @@ -750,10 +750,10 @@ TEST_CASE("WS2812", "[Application Layer]")
TEST_CASE("KP18058", "[Underlying Driver]")
{
driver_kp18058_t kp18058 = {
.rgb_current_multiple = 10,
.rgb_current_multiple = 3,
.cw_current_multiple = 10,
.iic_clk = 5,
.iic_sda = 4,
.iic_clk = 4,
.iic_sda = 3,
.iic_freq_khz = 300,
.enable_iic_queue = true,
};
Expand Down Expand Up @@ -844,8 +844,8 @@ TEST_CASE("KP18058", "[Underlying Driver]")
TEST_ASSERT_EQUAL(KP18058_SLOPE_7_5, kp18058_slope_mapping(7.5));
TEST_ASSERT_EQUAL(KP18058_SLOPE_15_0, kp18058_slope_mapping(15));
TEST_ASSERT_EQUAL(KP18058_CHOPPING_INVALID, kp18058_chopping_freq_mapping(0));
TEST_ASSERT_EQUAL(KP18058_CHOPPING_2KHZ, kp18058_chopping_freq_mapping(2000));
TEST_ASSERT_EQUAL(KP18058_CHOPPING_250HZ, kp18058_chopping_freq_mapping(250));
TEST_ASSERT_EQUAL(KP18058_CHOPPING_4KHZ, kp18058_chopping_freq_mapping(4000));
TEST_ASSERT_EQUAL(KP18058_CHOPPING_500HZ, kp18058_chopping_freq_mapping(500));

//7. Deinit
TEST_ASSERT_EQUAL(ESP_OK, kp18058_set_shutdown());
Expand All @@ -858,10 +858,10 @@ TEST_CASE("KP18058", "[Application Layer]")
{
lightbulb_config_t config = {
.type = DRIVER_KP18058,
.driver_conf.kp18058.rgb_current_multiple = 15,
.driver_conf.kp18058.cw_current_multiple = 20,
.driver_conf.kp18058.iic_clk = 5,
.driver_conf.kp18058.iic_sda = 4,
.driver_conf.kp18058.rgb_current_multiple = 3,
.driver_conf.kp18058.cw_current_multiple = 10,
.driver_conf.kp18058.iic_clk = 4,
.driver_conf.kp18058.iic_sda = 3,
.driver_conf.kp18058.iic_freq_khz = 300,
.driver_conf.kp18058.enable_iic_queue = true,
.capability.enable_fade = true,
Expand All @@ -887,6 +887,7 @@ TEST_CASE("KP18058", "[Application Layer]")
TEST_ASSERT_EQUAL(ESP_OK, lightbulb_init(&config));
vTaskDelay(pdMS_TO_TICKS(1000));
lightbulb_lighting_output_test(LIGHTING_BASIC_FIVE, 1000);
vTaskDelay(pdMS_TO_TICKS(2000));
TEST_ASSERT_EQUAL(ESP_OK, lightbulb_deinit());
}
#endif
Expand Down

0 comments on commit 2d1b12d

Please sign in to comment.