Skip to content

Commit 807cc64

Browse files
Merge branch 'feature/lightbulb_add_color_mode_calibration' into 'master'
feat(lightbulb): Add color Calibration Scheme See merge request ae_group/esp-iot-solution!966
2 parents b5e7e7e + cacff27 commit 807cc64

File tree

11 files changed

+416
-126
lines changed

11 files changed

+416
-126
lines changed

components/led/lightbulb_driver/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
# ChangeLog
2+
## v1.3.0 - 2024-06-05
3+
4+
### Enhancements:
5+
6+
* Add precise color control capability.
27

38
## v1.2.0 - 2024-05-22
49

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static kp18058_handle_t *s_kp18058 = NULL;
9898

9999
static IRAM_ATTR uint8_t parity_check(uint8_t input)
100100
{
101-
#if 0
101+
#if 1
102102
uint8_t result = input;
103103
result ^= result >> 8;
104104
result ^= result >> 4;

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.2.0"
1+
version: "1.3.0"
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/include/lightbulb.h

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,19 @@ typedef struct {
146146
Used to define the perceived warmth or coolness of the light emitted. */
147147
} lightbulb_cct_mapping_data_t;
148148

149+
/**
150+
* @brief Color mode mapping data
151+
*
152+
* @note Used for calibrating color accuracy in color mode.
153+
*
154+
*/
155+
typedef struct {
156+
float rgbcw_100[5]; /**< The RGBCW components required when saturation is 100 at a specific hue. */
157+
float rgbcw_50[5]; /**< The RGBCW components required when saturation is 50 at a specific hue. */
158+
float rgbcw_0[5]; /**< The RGBCW components required when saturation is 10 at a specific hue. */
159+
uint16_t hue;
160+
} lightbulb_color_mapping_data_t;
161+
149162
/**
150163
* @brief Gamma correction and color balance configuration
151164
*
@@ -263,6 +276,7 @@ typedef struct {
263276
bool enable_status_storage : 1; /**< Enable this option to store the lightbulb state in NVS. */
264277
bool enable_hardware_cct : 1; /**< Enable this option if your driver uses hardware CCT. Some PWM type drivers may need to set this option. */
265278
bool enable_precise_cct_control : 1; /**< Enable this option if you need precise CCT control. Must set 'enable_hardware_cct' to false in order to enable it.*/
279+
bool enable_precise_color_control : 1; /**< Enable this option if you need precise Color control. */
266280
bool sync_change_brightness_value : 1; /**< Enable this option if you need to use a parameter to mark the brightness of the white and color output. */
267281
bool disable_auto_on : 1; /**< Enable this option if you don't need automatic on when the color/white value is set. */
268282
} lightbulb_capability_t;
@@ -326,6 +340,13 @@ typedef struct {
326340
} precise;
327341
} cct_mix_mode;
328342

343+
union {
344+
struct {
345+
lightbulb_color_mapping_data_t *table;
346+
int table_size;
347+
} precise;
348+
} color_mix_mode;
349+
329350
lightbulb_gamma_config_t *gamma_conf; /**< Pointer to the gamma configuration data. */
330351
lightbulb_power_limit_t *external_limit; /**< Pointer to the external power limit configuration. */
331352

@@ -357,12 +378,11 @@ typedef struct {
357378
typedef struct {
358379
lightbulb_effect_t effect_type; /**< Type of the effect to be configured. */
359380
lightbulb_works_mode_t mode; /**< Working mode of the lightbulb during the effect. */
360-
uint8_t red; /**< Red component value for the effect (0-255). */
361-
uint8_t green; /**< Green component value for the effect (0-255). */
362-
uint8_t blue; /**< Blue component value for the effect (0-255). */
381+
uint16_t hue; /**< Hue component value for the effect (0-360). */
382+
uint8_t saturation; /**< Saturation component value for the effect (0-100). */
363383
uint16_t cct; /**< Color temperature value for the effect. */
364-
uint8_t min_brightness; /**< Minimum brightness level for the effect (0-100). */
365-
uint8_t max_brightness; /**< Maximum brightness level for the effect (0-100). */
384+
uint8_t min_value_brightness; /**< Minimum brightness level for the effect (0-100). */
385+
uint8_t max_value_brightness; /**< Maximum brightness level for the effect (0-100). */
366386
uint16_t effect_cycle_ms; /**< Cycle time for the effect in milliseconds (ms). */
367387

368388
/*

components/led/lightbulb_driver/src/hal_driver.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void gpio_reverse(int gpio_num)
5050
#define CHANGE_RATE_MS (12) // Interval in milliseconds between each update during the lightbulb's fading transition.
5151
#define FADE_CB_CHECK_MS (CHANGE_RATE_MS * 4) // Maximum wait time in milliseconds when fade_cb is blocked.
5252
#define HARDWARE_RETAIN_RATE_MS (CHANGE_RATE_MS - 2) // Safety margin in milliseconds for hardware fade interface in PWM scheme.
53-
#define MAX_TABLE_SIZE (256) // Maximum size for linear and gamma correction tables.
53+
//#define s_hal_obj->interface->driver_grayscale_level (256) // Maximum size for linear and gamma correction tables.
5454
#define DEFAULT_CURVE_COE (1.0) // Default coefficient for gamma correction curve.
5555
#define HAL_OUT_MAX_CHANNEL (5) // Maximum number of output channels in the Hardware Abstraction Layer (HAL).
5656
#define ERROR_COUNT_THRESHOLD (6) // Threshold for errors in the lower interface.
@@ -493,22 +493,22 @@ esp_err_t hal_output_init(hal_config_t *config, lightbulb_gamma_config_t *gamma,
493493
err = s_hal_obj->interface->init(config->driver_data, driver_default_hook_func);
494494
LIGHTBULB_CHECK(err == ESP_OK, "driver init fail", goto EXIT);
495495

496-
s_hal_obj->table_group[0] = calloc(MAX_TABLE_SIZE, sizeof(uint16_t));
496+
s_hal_obj->table_group[0] = calloc(s_hal_obj->interface->driver_grayscale_level, sizeof(uint16_t));
497497
LIGHTBULB_CHECK(s_hal_obj->table_group[0], "curve table buffer alloc fail", goto EXIT);
498498

499499
float curve_coe = gamma ? gamma->curve_coefficient : DEFAULT_CURVE_COE;
500500
float linear_coe = 1.0;
501501

502-
gamma_table_create(s_hal_obj->table_group[0], MAX_TABLE_SIZE, curve_coe, s_hal_obj->interface->driver_grayscale_level);
503-
s_hal_obj->table_group[0][MAX_TABLE_SIZE - 1] = s_hal_obj->interface->hardware_allow_max_input_value;
502+
gamma_table_create(s_hal_obj->table_group[0], s_hal_obj->interface->driver_grayscale_level, curve_coe, s_hal_obj->interface->driver_grayscale_level);
503+
s_hal_obj->table_group[0][s_hal_obj->interface->driver_grayscale_level - 1] = s_hal_obj->interface->hardware_allow_max_input_value;
504504

505505
if (linear_coe == curve_coe) {
506506
s_hal_obj->linear_use_curve_table = true;
507507
} else {
508-
s_hal_obj->table_group[1] = calloc(MAX_TABLE_SIZE, sizeof(uint16_t));
508+
s_hal_obj->table_group[1] = calloc(s_hal_obj->interface->driver_grayscale_level, sizeof(uint16_t));
509509
LIGHTBULB_CHECK(s_hal_obj->table_group[1], "linear table buffer alloc fail", goto EXIT);
510-
gamma_table_create(s_hal_obj->table_group[1], MAX_TABLE_SIZE, linear_coe, s_hal_obj->interface->driver_grayscale_level);
511-
s_hal_obj->table_group[1][MAX_TABLE_SIZE - 1] = s_hal_obj->interface->hardware_allow_max_input_value;
510+
gamma_table_create(s_hal_obj->table_group[1], s_hal_obj->interface->driver_grayscale_level, linear_coe, s_hal_obj->interface->driver_grayscale_level);
511+
s_hal_obj->table_group[1][s_hal_obj->interface->driver_grayscale_level - 1] = s_hal_obj->interface->hardware_allow_max_input_value;
512512
}
513513

514514
for (int i = 0; i < 5; i++) {
@@ -1047,7 +1047,7 @@ esp_err_t hal_get_driver_feature(hal_feature_query_list_t type, void *out_data)
10471047
return ESP_OK;
10481048
}
10491049

1050-
esp_err_t hal_get_curve_table_value(uint8_t input, uint16_t *output)
1050+
esp_err_t hal_get_curve_table_value(uint16_t input, uint16_t *output)
10511051
{
10521052
LIGHTBULB_CHECK(s_hal_obj, "init() must be called first", return ESP_ERR_INVALID_STATE);
10531053
LIGHTBULB_CHECK(output, "out_data is null", return ESP_ERR_INVALID_STATE);
@@ -1057,7 +1057,7 @@ esp_err_t hal_get_curve_table_value(uint8_t input, uint16_t *output)
10571057
return ESP_OK;
10581058
}
10591059

1060-
esp_err_t hal_get_linear_table_value(uint8_t input, uint16_t *output)
1060+
esp_err_t hal_get_linear_table_value(uint16_t input, uint16_t *output)
10611061
{
10621062
LIGHTBULB_CHECK(s_hal_obj, "init() must be called first", return ESP_ERR_INVALID_STATE);
10631063
LIGHTBULB_CHECK(output, "out_data is null", return ESP_ERR_INVALID_STATE);

0 commit comments

Comments
 (0)