summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2022-05-18 11:27:16 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-19 16:53:30 +0000
commit41bd403360fdece795f98594bea851420bf8a5ff (patch)
tree39a2b91fc7e8c35ed3c61ef941abc2cc3f0151cd
parent7d6fd649d0d58c04a6f540d2ea0c3523f88b4b54 (diff)
downloadchrome-ec-41bd403360fdece795f98594bea851420bf8a5ff.tar.gz
RGBKBD: Consolidate grids' states into one
Currently, grids track states individually. This patch consolidates grids' states into a single state common to all grids. BUG=b:233099161 BRANCH=None TEST=Vell Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: If2615384c3eadc8539116198632bafc89567c7e2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3654487 Reviewed-by: Parth Malkan <parthmalkan@google.com>
-rw-r--r--common/rgb_keyboard.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/common/rgb_keyboard.c b/common/rgb_keyboard.c
index 4f62271370..80d2ea04aa 100644
--- a/common/rgb_keyboard.c
+++ b/common/rgb_keyboard.c
@@ -36,6 +36,8 @@ test_export_static enum rgbkbd_demo demo =
test_export_static
uint8_t rgbkbd_table[EC_RGBKBD_MAX_KEY_COUNT];
+static enum rgbkbd_state rgbkbd_state;
+
static int set_color_single(struct rgb_s color, int x, int y)
{
struct rgbkbd *ctx = &rgbkbds[0];
@@ -279,16 +281,12 @@ static int rgbkbd_init(void)
{
int rv = EC_SUCCESS;
int e, i;
- bool updated = false;
rgbkbd_init_lookup_table();
for (i = 0; i < rgbkbd_count; i++) {
struct rgbkbd *ctx = &rgbkbds[i];
- if (ctx->state >= RGBKBD_STATE_INITIALIZED)
- continue;
-
e = ctx->cfg->drv->init(ctx);
if (e) {
CPRINTS("Failed to init GRID%d (%d)", i, e);
@@ -296,20 +294,18 @@ static int rgbkbd_init(void)
continue;
}
- ctx->state = RGBKBD_STATE_INITIALIZED;
- updated = true;
-
e = ctx->cfg->drv->set_scale(ctx, 0, 0x80, get_grid_size(ctx));
if (e) {
CPRINTS("Failed to set scale of GRID%d (%d)", i, e);
rv = e;
}
+
+ CPRINTS("Initialized GRID%d", i);
}
- if (updated)
- CPRINTS("Initialized (%d)", rv);
+ if (rv == EC_SUCCESS)
+ rgbkbd_state = RGBKBD_STATE_INITIALIZED;
- /* Return EC_SUCCESS or the last error. */
return rv;
}
@@ -317,14 +313,18 @@ static int rgbkbd_enable(int enable)
{
int rv = EC_SUCCESS;
int e, i;
- bool updated = false;
+
+ if (enable) {
+ if (rgbkbd_state == RGBKBD_STATE_ENABLED)
+ return EC_SUCCESS;
+ } else {
+ if (rgbkbd_state == RGBKBD_STATE_DISABLED)
+ return EC_SUCCESS;
+ }
for (i = 0; i < rgbkbd_count; i++) {
struct rgbkbd *ctx = &rgbkbds[i];
- if (ctx->state >= RGBKBD_STATE_ENABLED && enable)
- continue;
-
e = ctx->cfg->drv->enable(ctx, enable);
if (e) {
CPRINTS("Failed to %s GRID%d (%d)",
@@ -333,13 +333,13 @@ static int rgbkbd_enable(int enable)
continue;
}
- ctx->state = enable ?
- RGBKBD_STATE_ENABLED : RGBKBD_STATE_DISABLED;
- updated = true;
+ CPRINTS("%s GRID%d", enable ? "Enabled" : "Disabled", i);
}
- if (updated)
- CPRINTS("%s (%d)", enable ? "Enabled" : "Disabled", rv);
+ if (rv == EC_SUCCESS) {
+ rgbkbd_state = enable ?
+ RGBKBD_STATE_ENABLED : RGBKBD_STATE_DISABLED;
+ }
/* Return EC_SUCCESS or the last error. */
return rv;
@@ -353,13 +353,14 @@ static int rgbkbd_kblight_set(int percent)
static int rgbkbd_get_enabled(void)
{
- return rgbkbds[0].state >= RGBKBD_STATE_ENABLED;
+ return rgbkbd_state >= RGBKBD_STATE_ENABLED;
}
static void rgbkbd_reset(void)
{
board_kblight_shutdown();
board_kblight_init();
+ rgbkbd_state = RGBKBD_STATE_RESET;
}
const struct kblight_drv kblight_rgbkbd = {