Skip to content

Commit 4921508

Browse files
Miaojianyuespressif-bot
authored andcommitted
fix: modify curve table at hal layer for sm16825e
1 parent 3f46af3 commit 4921508

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

components/led/lightbulb_driver/src/hal_driver.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,24 @@ esp_err_t hal_get_curve_table_value(uint16_t input, uint16_t *output)
10851085
LIGHTBULB_CHECK(s_hal_obj, "init() must be called first", return ESP_ERR_INVALID_STATE);
10861086
LIGHTBULB_CHECK(output, "out_data is null", return ESP_ERR_INVALID_STATE);
10871087

1088-
*output = s_hal_obj->table_group[input];
1088+
uint32_t max_input = s_hal_obj->interface->hardware_allow_max_input_value;
1089+
uint32_t table_size = s_hal_obj->table_size;
1090+
1091+
if (table_size == 0) {
1092+
return ESP_ERR_INVALID_STATE;
1093+
}
1094+
1095+
uint32_t in = input;
1096+
if (in > max_input) {
1097+
in = max_input;
1098+
}
1099+
1100+
// Scale input to table index range
1101+
uint32_t idx = (table_size > 1) ? (in * (table_size - 1)) / MAX(1u, max_input) : 0u;
1102+
if (idx >= table_size) {
1103+
idx = table_size - 1;
1104+
}
1105+
*output = s_hal_obj->table_group[idx];
10891106

10901107
return ESP_OK;
10911108
}

0 commit comments

Comments
 (0)