summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/lp5562.c10
-rw-r--r--include/lp5562.h11
2 files changed, 14 insertions, 7 deletions
diff --git a/common/lp5562.c b/common/lp5562.c
index 50f0f940a2..a4c0e85fd6 100644
--- a/common/lp5562.c
+++ b/common/lp5562.c
@@ -21,13 +21,13 @@ inline int lp5562_write(uint8_t reg, uint8_t val)
return i2c_write8(I2C_PORT_HOST, LP5562_I2C_ADDR, reg, val);
}
-int lp5562_set_color(uint8_t red, uint8_t green, uint8_t blue)
+int lp5562_set_color(uint32_t rgb)
{
int ret = 0;
- ret |= lp5562_write(LP5562_REG_B_PWM, blue);
- ret |= lp5562_write(LP5562_REG_G_PWM, green);
- ret |= lp5562_write(LP5562_REG_R_PWM, red);
+ ret |= lp5562_write(LP5562_REG_B_PWM, rgb & 0xff);
+ ret |= lp5562_write(LP5562_REG_G_PWM, (rgb >> 8) & 0xff);
+ ret |= lp5562_write(LP5562_REG_R_PWM, (rgb >> 16) & 0xff);
return ret;
}
@@ -69,7 +69,7 @@ static int command_lp5562(int argc, char **argv)
if (e && *e)
return EC_ERROR_PARAM3;
- return lp5562_set_color(red, green, blue);
+ return lp5562_set_color((red << 16) | (green << 8) | blue);
} else if (argc == 2) {
if (!strcasecmp(argv[1], "on"))
return lp5562_poweron();
diff --git a/include/lp5562.h b/include/lp5562.h
index 5e848ec9ac..8bb8d71188 100644
--- a/include/lp5562.h
+++ b/include/lp5562.h
@@ -26,13 +26,20 @@
#define LP5562_REG_W_CURRENT 0x0f
#define LP5562_REG_LED_MAP 0x70
+#define LP5562_COLOR_RED 0x800000
+#define LP5562_COLOR_GREEN 0x008000
+#define LP5562_COLOR_BLUE 0x000080
+
/* Power on and initialize LP5562. */
int lp5562_poweron(void);
/* Power off LP5562. */
int lp5562_poweroff(void);
-/* Set LED color. */
-int lp5562_set_color(uint8_t red, uint8_t green, uint8_t blue);
+/*
+ * Set LED color.
+ * The parameter 'rgb' is in the format 0x00RRGGBB.
+ */
+int lp5562_set_color(uint32_t rgb);
#endif /* LP5562_H */