drivers: led: Add public API for LED drivers
Add support for LED APIs for controlling the LED devices. This API can be used by the LED devices present on the chip and connected externally via buses like I2C, SPI etc... Following APIs are currently supported: 1. led_blink 2. led_set_brightness 3. led_on 4. led_off Driver support using these APIs will be added in subsequent patches. Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
This commit is contained in:
parent
c7d808f965
commit
94bba071d6
6 changed files with 213 additions and 0 deletions
|
@ -14,6 +14,7 @@ add_subdirectory_if_kconfig(i2c)
|
||||||
add_subdirectory_if_kconfig(i2s)
|
add_subdirectory_if_kconfig(i2s)
|
||||||
add_subdirectory_if_kconfig(ieee802154)
|
add_subdirectory_if_kconfig(ieee802154)
|
||||||
add_subdirectory_if_kconfig(ipm)
|
add_subdirectory_if_kconfig(ipm)
|
||||||
|
add_subdirectory_if_kconfig(led)
|
||||||
add_subdirectory_if_kconfig(led_strip)
|
add_subdirectory_if_kconfig(led_strip)
|
||||||
add_subdirectory_if_kconfig(pci)
|
add_subdirectory_if_kconfig(pci)
|
||||||
add_subdirectory_if_kconfig(pinmux)
|
add_subdirectory_if_kconfig(pinmux)
|
||||||
|
|
|
@ -75,4 +75,6 @@ source "drivers/led_strip/Kconfig"
|
||||||
|
|
||||||
source "drivers/wifi/Kconfig"
|
source "drivers/wifi/Kconfig"
|
||||||
|
|
||||||
|
source "drivers/led/Kconfig"
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
1
drivers/led/CMakeLists.txt
Normal file
1
drivers/led/CMakeLists.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
# Nothing here (yet)
|
38
drivers/led/Kconfig
Normal file
38
drivers/led/Kconfig
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2018 Linaro Limited
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
# Top-level configuration file for LED drivers.
|
||||||
|
|
||||||
|
menuconfig LED
|
||||||
|
bool "LED drivers"
|
||||||
|
default n
|
||||||
|
help
|
||||||
|
Include LED drivers in the system configuration.
|
||||||
|
|
||||||
|
if LED
|
||||||
|
|
||||||
|
config SYS_LOG_LED_LEVEL
|
||||||
|
int "LED system log level"
|
||||||
|
depends on SYS_LOG
|
||||||
|
default 0
|
||||||
|
range 0 4
|
||||||
|
help
|
||||||
|
Sets the log level for LED drivers. You must have
|
||||||
|
system logging enabled.
|
||||||
|
Levels are:
|
||||||
|
0 OFF, do not write
|
||||||
|
1 ERROR, only write SYS_LOG_ERR
|
||||||
|
2 WARNING, write SYS_LOG_WRN in addition to previous level
|
||||||
|
3 INFO, write SYS_LOG_INF in addition to previous levels
|
||||||
|
4 DEBUG, write SYS_LOG_DBG in addition to previous levels
|
||||||
|
|
||||||
|
config LED_INIT_PRIORITY
|
||||||
|
int "LED initialization priority"
|
||||||
|
default 90
|
||||||
|
help
|
||||||
|
System initialization priority for LED drivers.
|
||||||
|
|
||||||
|
endif # LED
|
38
drivers/led/led_context.h
Normal file
38
drivers/led/led_context.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Linaro Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Private LED driver APIs
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __LED_CONTEXT_H__
|
||||||
|
#define __LED_CONTEXT_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Internal driver specific representation of an LED device
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct led_data {
|
||||||
|
/* Minimum acceptable LED blinking time period (in ms) */
|
||||||
|
u32_t min_period;
|
||||||
|
/* Maximum acceptable LED blinking time period (in ms) */
|
||||||
|
u32_t max_period;
|
||||||
|
/* Minimum acceptable LED brightness value */
|
||||||
|
u16_t min_brightness;
|
||||||
|
/* Maximum acceptable LED brightness value */
|
||||||
|
u16_t max_brightness;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* __LED_CONTEXT_H__ */
|
133
include/led.h
Normal file
133
include/led.h
Normal file
|
@ -0,0 +1,133 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Linaro Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ZEPHYR_LED_H
|
||||||
|
#define _ZEPHYR_LED_H
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file
|
||||||
|
* @brief Public LED driver APIs
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <zephyr/types.h>
|
||||||
|
#include <device.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef led_api_blink()
|
||||||
|
* @brief Callback API for blinking an LED
|
||||||
|
*
|
||||||
|
* @see led_blink() for argument descriptions.
|
||||||
|
*/
|
||||||
|
typedef int (*led_api_blink)(struct device *dev, u32_t led,
|
||||||
|
u32_t delay_on, u32_t delay_off);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef led_api_set_brightness()
|
||||||
|
* @brief Callback API for setting brightness of an LED
|
||||||
|
*
|
||||||
|
* @see led_set_brightness() for argument descriptions.
|
||||||
|
*/
|
||||||
|
typedef int (*led_api_set_brightness)(struct device *dev, u32_t led,
|
||||||
|
u8_t value);
|
||||||
|
/**
|
||||||
|
* @typedef led_api_on()
|
||||||
|
* @brief Callback API for turning on an LED
|
||||||
|
*
|
||||||
|
* @see led_on() for argument descriptions.
|
||||||
|
*/
|
||||||
|
typedef int (*led_api_on)(struct device *dev, u32_t led);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef led_api_off()
|
||||||
|
* @brief Callback API for turning off an LED
|
||||||
|
*
|
||||||
|
* @see led_off() for argument descriptions.
|
||||||
|
*/
|
||||||
|
typedef int (*led_api_off)(struct device *dev, u32_t led);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief LED driver API
|
||||||
|
*
|
||||||
|
* This is the mandatory API any LED driver needs to expose.
|
||||||
|
*/
|
||||||
|
struct led_driver_api {
|
||||||
|
led_api_blink blink;
|
||||||
|
led_api_set_brightness set_brightness;
|
||||||
|
led_api_on on;
|
||||||
|
led_api_off off;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Blink an LED
|
||||||
|
*
|
||||||
|
* This routine starts blinking an LED forever with the given time period
|
||||||
|
*
|
||||||
|
* @param dev LED device
|
||||||
|
* @param led LED channel/pin
|
||||||
|
* @param delay_on Time period (in milliseconds) an LED should be ON
|
||||||
|
* @param delay_off Time period (in milliseconds) an LED should be OFF
|
||||||
|
* @return 0 on success, negative on error
|
||||||
|
*/
|
||||||
|
static inline int led_blink(struct device *dev, u32_t led,
|
||||||
|
u32_t delay_on, u32_t delay_off)
|
||||||
|
{
|
||||||
|
const struct led_driver_api *api = dev->driver_api;
|
||||||
|
|
||||||
|
return api->blink(dev, led, delay_on, delay_off);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set LED brightness
|
||||||
|
*
|
||||||
|
* This routine sets the brightness of a LED to the given value.
|
||||||
|
* Calling this function after led_blink() won't affect blinking.
|
||||||
|
*
|
||||||
|
* @param dev LED device
|
||||||
|
* @param led LED channel/pin
|
||||||
|
* @param value Brightness value to set in percent
|
||||||
|
* @return 0 on success, negative on error
|
||||||
|
*/
|
||||||
|
static inline int led_set_brightness(struct device *dev, u32_t led,
|
||||||
|
u8_t value)
|
||||||
|
{
|
||||||
|
const struct led_driver_api *api = dev->driver_api;
|
||||||
|
|
||||||
|
return api->set_brightness(dev, led, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Turn on an LED
|
||||||
|
*
|
||||||
|
* This routine turns on an LED
|
||||||
|
*
|
||||||
|
* @param dev LED device
|
||||||
|
* @param led LED channel/pin
|
||||||
|
* @return 0 on success, negative on error
|
||||||
|
*/
|
||||||
|
static inline int led_on(struct device *dev, u32_t led)
|
||||||
|
{
|
||||||
|
const struct led_driver_api *api = dev->driver_api;
|
||||||
|
|
||||||
|
return api->on(dev, led);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Turn off an LED
|
||||||
|
*
|
||||||
|
* This routine turns off an LED
|
||||||
|
*
|
||||||
|
* @param dev LED device
|
||||||
|
* @param led LED channel/pin
|
||||||
|
* @return 0 on success, negative on error
|
||||||
|
*/
|
||||||
|
static inline int led_off(struct device *dev, u32_t led)
|
||||||
|
{
|
||||||
|
const struct led_driver_api *api = dev->driver_api;
|
||||||
|
|
||||||
|
return api->off(dev, led);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _ZEPHYR_LED_H */
|
Loading…
Add table
Add a link
Reference in a new issue