diff options
author | Vic Yang <victoryang@chromium.org> | 2013-02-06 00:44:03 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-02-05 09:45:44 -0800 |
commit | c06e987c1b9f7436530cd928bcc7a08f9830d703 (patch) | |
tree | ace6733ed416d7bc0df97dd80ca89e12321f74e2 | |
parent | 6e29f8091d9da763cd39b7ea61eefb5c35b94606 (diff) | |
download | chrome-ec-c06e987c1b9f7436530cd928bcc7a08f9830d703.tar.gz |
Tweak lp5562 driver interface
This makes it possible to define color constants so as to reduce code
size when called.
BUG=chrome-os-partner:17561
TEST=Build success.
BRANCH=none
Change-Id: I800b8d4b84749907b071febfea58d27fef7cc2b7
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/42617
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | common/lp5562.c | 10 | ||||
-rw-r--r-- | include/lp5562.h | 11 |
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 */ |