summaryrefslogtreecommitdiff
path: root/include/led_pwm.h
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2018-01-22 11:50:57 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-05 23:05:39 -0800
commitd940d2a991b33b5b1ad9d6a2698ebfcdaa0f59db (patch)
tree017ac8b77a97807db600d9bbf76c2b2e324cde74 /include/led_pwm.h
parent5ef9b94d70418dd596fd81fda834e52787a24296 (diff)
downloadchrome-ec-d940d2a991b33b5b1ad9d6a2698ebfcdaa0f59db.tar.gz
common: Add support for PWM LEDs.
This commit adds support for a common framework for PWM controlled LEDs. If there are multiple LEDs, they will all follow the same pattern. The pattern is such that it follows the Chrome OS LED behaviour specification, essentially a similar version of led_policy_std.c but for PWM controlled LEDs. To use this framework, a board must do the following: - First, define the number of logical PWM LEDs which will be controlled by this common policy, CONFIG_LED_PWM_COUNT. - Then declare those logical LEDs and define the PWM channels that comprise those LEDs. (struct pwm_led pwm_leds[]). - Next, define what each color should look like (struct pwm_led led_color_map[]). By default, the colors follow the recommended colors in the LED behaviour spec, which assume an LED with a red and green channel. If a board differs or wishes to change the colors in general, they can redefine the colors (CONFIG_LED_PWM_*_COLOR) as they see fit. The colors must be one in enum ec_led_colors. These colors are the ones that can represent the charging state, SoC state, etc. BUG=b:69138917,chromium:752553 BRANCH=None TEST=make -j buildall TEST=Enable led_pwm for meowth, and verify that LEDs behave as expected. Change-Id: I945b86a7f8ed30df58d7da835d83577192548bea Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/888220 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org>
Diffstat (limited to 'include/led_pwm.h')
-rw-r--r--include/led_pwm.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/led_pwm.h b/include/led_pwm.h
new file mode 100644
index 0000000000..8814023d42
--- /dev/null
+++ b/include/led_pwm.h
@@ -0,0 +1,48 @@
+/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __CROS_EC_LED_PWM_H
+#define __CROS_EC_LED_PWM_H
+
+#include "ec_commands.h"
+
+#define PWM_LED_NO_CHANNEL -1
+
+struct pwm_led {
+ int ch0;
+ int ch1;
+ int ch2;
+};
+
+enum pwm_led_id {
+ PWM_LED0 = 0,
+#if CONFIG_LED_PWM_COUNT >= 2
+ PWM_LED1,
+#endif /* CONFIG_LED_PWM_COUNT > 2 */
+};
+
+/*
+ * A mapping of color to LED duty cycles per channel.
+ *
+ * This should be defined by the boards to declare what each color looks like.
+ * There should be an entry for every enum ec_led_colors value. For colors that
+ * are impossible for a given board, they should define a duty cycle of 0 for
+ * all applicable channels. (e.g. A bi-color LED which has a red and green
+ * channel should define all 0s for EC_LED_COLOR_BLUE and EC_LED_COLOR_WHITE.)
+ */
+extern struct pwm_led led_color_map[EC_LED_COLOR_COUNT];
+
+/*
+ * A map of the PWM channels to logical PWM LEDs.
+ *
+ * A logical PWM LED would be considered as "per diffuser". There may be 1-3
+ * channels per diffuser and they should form a single entry in pwm_leds. If a
+ * channel is not used, simply define that channel as PWM_LED_NO_CHANNEL.
+ */
+extern struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT];
+
+void set_pwm_led_color(enum pwm_led_id id, int color);
+
+#endif /* defined(__CROS_EC_LED_PWM_H) */