diff options
author | Vic Yang <victoryang@chromium.org> | 2013-08-20 22:20:38 +0800 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-08-30 15:39:52 +0000 |
commit | cfd007c833a676ca2e5b82503f5871ec2531f322 (patch) | |
tree | c2c25711771224fc99fddb55ed3613906d5590b4 | |
parent | 7cb7d7dd99bf8c919010122667a69c6107a77228 (diff) | |
download | chrome-ec-cfd007c833a676ca2e5b82503f5871ec2531f322.tar.gz |
Kirby LED driver
This is just a simple driver that provides a function to set LED color
and also a console command for testing.
BUG=chrome-os-partner:22056
TEST=Change LED color and brightness with the console command.
BRANCH=None
Change-Id: I66ece63310a0547127698d1b242a5a1c130abff6
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/167450
-rw-r--r-- | board/kirby/board.c | 15 | ||||
-rw-r--r-- | board/kirby/board.h | 12 | ||||
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/led_kirby.c | 70 |
4 files changed, 97 insertions, 1 deletions
diff --git a/board/kirby/board.c b/board/kirby/board.c index 560250c56f..4a702b2781 100644 --- a/board/kirby/board.c +++ b/board/kirby/board.c @@ -12,6 +12,8 @@ #include "i2c.h" #include "keyboard_raw.h" #include "lid_switch.h" +#include "pwm.h" +#include "pwm_data.h" #include "registers.h" #include "spi.h" #include "task.h" @@ -95,7 +97,7 @@ BUILD_ASSERT(ARRAY_SIZE(gpio_list) == GPIO_COUNT); /* Pins with alternate functions */ const struct gpio_alt_func gpio_alt_funcs[] = { - {GPIO_C, 0x00e0, GPIO_ALT_TIM3_4, MODULE_LED_KIRBY}, + {GPIO_C, 0x01c0, GPIO_ALT_TIM3_4, MODULE_LED_KIRBY}, {GPIO_A, 0x00f0, GPIO_ALT_SPI, MODULE_SPI}, {GPIO_A, 0x0600, GPIO_ALT_USART, MODULE_UART}, {GPIO_B, 0x00c0, GPIO_ALT_I2C, MODULE_I2C}, @@ -112,6 +114,17 @@ const struct battery_temperature_ranges bat_temp_ranges = { .discharging_max_c = 100, }; +/* PWM channels */ +const struct pwm_t pwm_channels[] = { + [PWM_CH_CHG_Y] = {STM32_TIM(3), STM32_TIM_CH(1), PWM_CONFIG_ACTIVE_LOW, + GPIO_CHG_LED_Y}, + [PWM_CH_CHG_G] = {STM32_TIM(3), STM32_TIM_CH(2), PWM_CONFIG_ACTIVE_LOW, + GPIO_CHG_LED_G}, + [PWM_CH_CHG_R] = {STM32_TIM(3), STM32_TIM_CH(3), PWM_CONFIG_ACTIVE_LOW, + GPIO_CHG_LED_R}, +}; +BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT); + /* I2C ports */ const struct i2c_port_t i2c_ports[] = { {"host", I2C_PORT_HOST, 100}, diff --git a/board/kirby/board.h b/board/kirby/board.h index e44ecbdb47..f7fd9573ff 100644 --- a/board/kirby/board.h +++ b/board/kirby/board.h @@ -18,6 +18,7 @@ #define CONFIG_I2C #define CONFIG_KEYBOARD_PROTOCOL_MKBP #define CONFIG_SPI +#define CONFIG_PWM #ifndef __ASSEMBLER__ @@ -57,6 +58,17 @@ enum module_id { #define TIM_CLOCK_LSB 9 #define TIM_WATCHDOG 4 +/* PWM signal */ +enum pwm_channel { + /* Y, G, R charging LEDs */ + PWM_CH_CHG_Y = 0, + PWM_CH_CHG_G, + PWM_CH_CHG_R, + + /* Number of PWM channels */ + PWM_CH_COUNT +}; + /* GPIO signal list */ enum gpio_signal { /* Inputs with interrupt handlers are first for efficiency */ diff --git a/common/build.mk b/common/build.mk index 429f27b744..9d28ea307b 100644 --- a/common/build.mk +++ b/common/build.mk @@ -13,6 +13,7 @@ common-y+=gpio_common.o version.o printf.o queue.o common-$(BOARD_bolt)+=battery_link.o common-$(BOARD_daisy)+=extpower_snow.o common-$(BOARD_falco)+=battery_falco.o led_falco.o +common-$(BOARD_kirby)+=led_kirby.o common-$(BOARD_link)+=battery_link.o common-$(BOARD_peppy)+=battery_peppy.o led_common.o led_peppy.o common-$(BOARD_slippy)+=battery_slippy.o led_slippy.o diff --git a/common/led_kirby.c b/common/led_kirby.c new file mode 100644 index 0000000000..1395bc4820 --- /dev/null +++ b/common/led_kirby.c @@ -0,0 +1,70 @@ +/* Copyright (c) 2013 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. + * + * Kirby LED driver. + */ + +#include "common.h" +#include "console.h" +#include "gpio.h" +#include "pwm.h" +#include "util.h" + +void led_set_color(uint8_t red, uint8_t green, uint8_t yellow) +{ + if (!yellow) + pwm_enable(PWM_CH_CHG_Y, 0); + if (!green) + pwm_enable(PWM_CH_CHG_G, 0); + if (!red) + pwm_enable(PWM_CH_CHG_R, 0); + + /* Only allow one color of LED */ + if (yellow) { + pwm_enable(PWM_CH_CHG_Y, 1); + pwm_set_duty(PWM_CH_CHG_Y, yellow); + } else if (green) { + pwm_enable(PWM_CH_CHG_G, 1); + pwm_set_duty(PWM_CH_CHG_G, green); + } else if (red) { + pwm_enable(PWM_CH_CHG_R, 1); + pwm_set_duty(PWM_CH_CHG_R, red); + } else { + gpio_config_module(MODULE_LED_KIRBY, 0); + gpio_set_level(GPIO_CHG_LED_Y, 0); + gpio_set_level(GPIO_CHG_LED_G, 0); + gpio_set_level(GPIO_CHG_LED_R, 0); + } +} + +/*****************************************************************************/ +/* Console commands */ + +static int command_led(int argc, char **argv) +{ + char *e; + uint8_t brightness; + + if (argc != 3) + return EC_ERROR_PARAM_COUNT; + + brightness = strtoi(argv[2], &e, 0); + if ((e && *e) || brightness < 0 || brightness > 100) + return EC_ERROR_PARAM2; + + if (!strcasecmp(argv[1], "r")) + led_set_color(brightness, 0, 0); + else if (!strcasecmp(argv[1], "g")) + led_set_color(0, brightness, 0); + else if (!strcasecmp(argv[1], "y")) + led_set_color(0, 0, brightness); + else + return EC_ERROR_PARAM1; + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(led, command_led, + "<r | g | y> <brightness>", + "Set the color and brightness of the LED", + NULL); |