summaryrefslogtreecommitdiff
path: root/zephyr/shim/src/led_driver/led.c
diff options
context:
space:
mode:
authorParth Malkan <parthmalkan@google.com>2022-04-19 10:13:44 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-04-21 17:56:46 +0000
commita0ed2ff3ba131cea397cfff712c02b231a690bd8 (patch)
tree636cd589b8e854fef601570a939dbb665a2eec31 /zephyr/shim/src/led_driver/led.c
parentb452703848299bf4654a16aba8235c905adef743 (diff)
downloadchrome-ec-a0ed2ff3ba131cea397cfff712c02b231a690bd8.tar.gz
zephyr: LED: Fix led_tick logic
This patch fixes the led_tick logic to call it every HOOK_TICK_INTERVAL_MS instead of every sec. BRANCH=none BUG=b:229744810 TEST=zmake build -a, test on Lazor Signed-off-by: Parth Malkan <parthmalkan@google.com> Cq-Depend: chromium:3594245, chromium:3594246 Change-Id: Ie451a8381f7858a047a365b88f6177c25cbe7734 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3594244 Reviewed-by: Wai-Hong Tam <waihong@google.com>
Diffstat (limited to 'zephyr/shim/src/led_driver/led.c')
-rw-r--r--zephyr/shim/src/led_driver/led.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/zephyr/shim/src/led_driver/led.c b/zephyr/shim/src/led_driver/led.c
index 1a72eecad7..61cffa1958 100644
--- a/zephyr/shim/src/led_driver/led.c
+++ b/zephyr/shim/src/led_driver/led.c
@@ -24,8 +24,6 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(gpio_led, LOG_LEVEL_ERR);
-#define LED_ONE_SEC (1000 / HOOK_TICK_INTERVAL_MS)
-
#define LED_COLOR_NODE DT_PATH(led_colors)
struct led_color_node_t {
@@ -69,11 +67,12 @@ struct node_prop_t {
* led_colors[1].acc_period = period value of color-0 + color-1 nodes
* led_colors[2].acc_period = period value of color-0 + color-1 + color-2 nodes
* and so on. If period prop or color node doesn't exist, period val is 0
+ * It is stored in terms of number of ticks by dividing it with
+ * HOOT_TICK_INTERVAL_MS
*/
-#define PERIOD_VAL(id) COND_CODE_1(DT_NODE_HAS_PROP(id, period), \
- (DT_PROP(id, period)), \
- (0))
+#define PERIOD_VAL(id) COND_CODE_1(DT_NODE_HAS_PROP(id, period_ms), \
+ (DT_PROP(id, period_ms) / HOOK_TICK_INTERVAL_MS), (0))
#define LED_PERIOD(color_num, state_id) \
PERIOD_VAL(DT_CHILD(state_id, color_##color_num))
@@ -211,17 +210,20 @@ static int find_node(void)
#define GET_PERIOD(n_idx, c_idx) node_array[n_idx].led_colors[c_idx].acc_period
#define GET_COLOR(n_idx, c_idx) node_array[n_idx].led_colors[c_idx].led_color
-static int find_color(int node_idx, int ticks)
+static int find_color(int node_idx, uint32_t ticks)
{
int color_idx = 0;
/* If period value at index 0 is not 0, it's a blinking LED */
if (GET_PERIOD(node_idx, 0) != 0) {
/* Period is accumulated at the last index */
- ticks = (ticks * LED_ONE_SEC) %
- GET_PERIOD(node_idx, MAX_COLOR - 1);
+ ticks = ticks % GET_PERIOD(node_idx, MAX_COLOR - 1);
for (color_idx = 0; color_idx < MAX_COLOR; color_idx++) {
+ /*
+ * Period value that we use here is in terms of number
+ * of ticks stored during initialization of the struct
+ */
if (ticks < GET_PERIOD(node_idx, color_idx))
break;
}
@@ -234,7 +236,7 @@ static void board_led_set_color(void)
{
int color = LED_OFF;
int node = 0;
- static int ticks;
+ static uint32_t ticks;
ticks++;
@@ -261,7 +263,7 @@ static void led_tick(void)
if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
board_led_set_color();
}
-DECLARE_HOOK(HOOK_SECOND, led_tick, HOOK_PRIO_DEFAULT);
+DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);
void led_control(enum ec_led_id led_id, enum ec_led_state state)
{