mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-28 02:35:28 +00:00
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
This commit is contained in:
committed by
chrome-internal-fetch
parent
7cb7d7dd99
commit
cfd007c833
@@ -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},
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
70
common/led_kirby.c
Normal file
70
common/led_kirby.c
Normal file
@@ -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);
|
||||
Reference in New Issue
Block a user