Skip to content

Commit 0781693

Browse files
Josh-TsaiJohnAZoidberg
authored andcommitted
fwk: led: add a function to change the LED duty
The LED driver does not support to runtime change the LED duty. This change adds a function to change the LED duty. BRANCH=fwk-tulip-29169 BUG=https://app.clickup.com/t/86eun47uq TEST=create a hook second to call this function, and the LED duty can be changed. Signed-off-by: Josh Tsai <Josh_Tsai@compal.com>
1 parent 3df87fd commit 0781693

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

zephyr/program/framework/include/led.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ void auto_als_led_reset(void);
235235
*/
236236
int led_get_current_tick_time(void);
237237

238+
/**
239+
* Allow the project changes the LED duty.
240+
*
241+
* @param color which LED color would like to change
242+
* @param led_id which LED ID would like to change
243+
* @param pins_count how many pwm pin to control the color
244+
* @param duty the array of the duty that you want to change
245+
*/
246+
void led_change_color(enum led_color color, enum ec_led_id led_id, int pins_count, uint8_t *duty);
247+
238248
#ifdef TEST_BUILD
239249
const struct led_pins_node_t *led_get_node(enum led_color color,
240250
enum ec_led_id led_id);

zephyr/program/framework/src/led_pwm.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,36 @@ void led_set_color(enum led_color color, enum ec_led_id led_id)
113113
}
114114
}
115115

116+
const struct led_pins_node_t *led_get_node(enum led_color color, enum ec_led_id led_id)
117+
{
118+
const struct led_pins_node_t *pin_node = NULL;
119+
120+
for (int i = 0; i < ARRAY_SIZE(pins_node); i++) {
121+
if (pins_node[i]->led_id == led_id &&
122+
pins_node[i]->led_color == color) {
123+
pin_node = pins_node[i];
124+
break;
125+
}
126+
}
127+
128+
return pin_node;
129+
}
130+
131+
void led_change_color(enum led_color color, enum ec_led_id led_id, int pins_count, uint8_t *duty)
132+
{
133+
const struct led_pins_node_t *pin_node = led_get_node(color, led_id);
134+
uint64_t pulse_ns;
135+
136+
if (pin_node->pins_count != pins_count)
137+
LOG_ERR("LED change color: Wrong pins count");
138+
139+
for (int j = 0; j < pins_count; j++) {
140+
pulse_ns = DIV_ROUND_NEAREST(BOARD_LED_PWM_PERIOD_NS * duty[j], 100);
141+
pin_node->pwm_pins[j].pulse_ns = pulse_ns;
142+
}
143+
144+
}
145+
116146
/*
117147
* Set value for exponential pulsing as a minimum of 10,
118148
* because 0 to the power of anything is still 0.

0 commit comments

Comments
 (0)