12#ifndef ZEPHYR_INCLUDE_DRIVERS_LED_H_
13#define ZEPHYR_INCLUDE_DRIVERS_LED_H_
36#define LED_BRIGTHNESS_MAX 100u
146static inline int z_impl_led_blink(
const struct device *dev,
uint32_t led,
152 if (api->blink ==
NULL) {
155 return api->blink(dev, led, delay_on, delay_off);
171static inline int z_impl_led_get_info(
const struct device *dev,
uint32_t led,
177 if (api->get_info ==
NULL) {
181 return api->get_info(dev, led, info);
203static inline int z_impl_led_set_brightness(
const struct device *dev,
210 if (api->set_brightness ==
NULL &&
211 api->on ==
NULL && api->off ==
NULL) {
219 if (api->set_brightness ==
NULL) {
221 return api->on(dev, led);
223 return api->off(dev, led);
227 return api->set_brightness(dev, led, value);
251z_impl_led_write_channels(
const struct device *dev,
uint32_t start_channel,
257 if (api->write_channels ==
NULL) {
260 return api->write_channels(dev, start_channel, num_channels, buf);
278static inline int z_impl_led_set_channel(
const struct device *dev,
281 return z_impl_led_write_channels(dev, channel, 1, &value);
303static inline int z_impl_led_set_color(
const struct device *dev,
uint32_t led,
309 if (api->set_color ==
NULL) {
312 return api->set_color(dev, led, num_colors, color);
329static inline int z_impl_led_on(
const struct device *dev,
uint32_t led)
334 if (api->set_brightness ==
NULL && api->on ==
NULL) {
338 if (api->on ==
NULL) {
342 return api->on(dev, led);
359static inline int z_impl_led_off(
const struct device *dev,
uint32_t led)
364 if (api->set_brightness ==
NULL && api->off ==
NULL) {
368 if (api->off ==
NULL) {
369 return api->set_brightness(dev, led, 0);
372 return api->off(dev, led);
484#define LED_DT_SPEC_GET(node_id) \
486 .dev = DEVICE_DT_GET(DT_PARENT(node_id)), \
487 .index = DT_NODE_CHILD_IDX(node_id), \
499#define LED_DT_SPEC_GET_OR(node_id, default_value) \
500 COND_CODE_1(DT_NODE_EXISTS(node_id), \
501 (LED_DT_SPEC_GET(node_id)), \
512#include <zephyr/syscalls/led.h>
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
int led_off(const struct device *dev, uint32_t led)
Turn off an LED.
int led_write_channels(const struct device *dev, uint32_t start_channel, uint32_t num_channels, const uint8_t *buf)
Write/update a strip of LED channels.
#define LED_BRIGTHNESS_MAX
Maximum brightness level, range is 0 to 100.
Definition led.h:36
int(* led_api_get_info)(const struct device *dev, uint32_t led, const struct led_info **info)
Optional API callback to get LED information.
Definition led.h:69
int led_blink(const struct device *dev, uint32_t led, uint32_t delay_on, uint32_t delay_off)
Blink an LED.
int(* led_api_off)(const struct device *dev, uint32_t led)
Callback API for turning off an LED.
Definition led.h:103
int(* led_api_write_channels)(const struct device *dev, uint32_t start_channel, uint32_t num_channels, const uint8_t *buf)
Callback API for writing a strip of LED channels.
Definition led.h:111
int led_set_channel(const struct device *dev, uint32_t channel, uint8_t value)
Set a single LED channel.
static int led_off_dt(const struct led_dt_spec *spec)
Turn off an LED from a struct led_dt_spec.
Definition led.h:430
int led_set_color(const struct device *dev, uint32_t led, uint8_t num_colors, const uint8_t *color)
Set LED color.
int(* led_api_set_color)(const struct device *dev, uint32_t led, uint8_t num_colors, const uint8_t *color)
Optional API callback to set the colors of a LED.
Definition led.h:86
int led_get_info(const struct device *dev, uint32_t led, const struct led_info **info)
Get LED information.
static bool led_is_ready_dt(const struct led_dt_spec *spec)
Validate that the LED device is ready.
Definition led.h:443
static int led_on_dt(const struct led_dt_spec *spec)
Turn on an LED from a struct led_dt_spec.
Definition led.h:417
int led_set_brightness(const struct device *dev, uint32_t led, uint8_t value)
Set LED brightness.
int(* led_api_on)(const struct device *dev, uint32_t led)
Callback API for turning on an LED.
Definition led.h:95
int(* led_api_blink)(const struct device *dev, uint32_t led, uint32_t delay_on, uint32_t delay_off)
Callback API for blinking an LED.
Definition led.h:60
int led_on(const struct device *dev, uint32_t led)
Turn on an LED.
int(* led_api_set_brightness)(const struct device *dev, uint32_t led, uint8_t value)
Callback API for setting brightness of an LED.
Definition led.h:78
static int led_set_brightness_dt(const struct led_dt_spec *spec, uint8_t value)
Set LED brightness from a led_dt_spec.
Definition led.h:403
#define EINVAL
Invalid argument.
Definition errno.h:60
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
Runtime device structure (in ROM) per driver instance.
Definition device.h:504
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:510
LED driver API.
Definition led.h:119
led_api_off off
Definition led.h:122
led_api_set_color set_color
Definition led.h:127
led_api_get_info get_info
Definition led.h:125
led_api_set_brightness set_brightness
Definition led.h:126
led_api_on on
Definition led.h:121
led_api_write_channels write_channels
Definition led.h:128
led_api_blink blink
Definition led.h:124
Container for an LED information specified in devicetree.
Definition led.h:387
uint32_t index
Index of the LED on the controller.
Definition led.h:391
const struct device * dev
LED device instance.
Definition led.h:389
LED information structure.
Definition led.h:43
const char * label
LED label.
Definition led.h:45
uint32_t index
Index of the LED on the controller.
Definition led.h:47
const uint8_t * color_mapping
Mapping of the LED colors.
Definition led.h:51
uint8_t num_colors
Number of colors per LED.
Definition led.h:49