Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
LED Interface

LED Interface . More...

Data Structures

struct  led_info
 LED information structure. More...
 
struct  led_driver_api
 LED driver API. More...
 
struct  led_dt_spec
 Container for an LED information specified in devicetree. More...
 

Macros

#define LED_DT_SPEC_GET(node_id)
 Static initializer for a struct led_dt_spec.
 
#define LED_DT_SPEC_GET_OR(node_id, default_value)
 Like LED_DT_SPEC_GET(), with a fallback value if the node does not exist.
 

Typedefs

typedef 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.
 
typedef int(* led_api_get_info) (const struct device *dev, uint32_t led, const struct led_info **info)
 Optional API callback to get LED information.
 
typedef int(* led_api_set_brightness) (const struct device *dev, uint32_t led, uint8_t value)
 Callback API for setting brightness of an LED.
 
typedef 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.
 
typedef int(* led_api_on) (const struct device *dev, uint32_t led)
 Callback API for turning on an LED.
 
typedef int(* led_api_off) (const struct device *dev, uint32_t led)
 Callback API for turning off an LED.
 
typedef 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.
 

Functions

int led_blink (const struct device *dev, uint32_t led, uint32_t delay_on, uint32_t delay_off)
 Blink an LED.
 
int led_get_info (const struct device *dev, uint32_t led, const struct led_info **info)
 Get LED information.
 
int led_set_brightness (const struct device *dev, uint32_t led, uint8_t value)
 Set LED brightness.
 
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.
 
int led_set_channel (const struct device *dev, uint32_t channel, uint8_t value)
 Set a single LED channel.
 
int led_set_color (const struct device *dev, uint32_t led, uint8_t num_colors, const uint8_t *color)
 Set LED color.
 
int led_on (const struct device *dev, uint32_t led)
 Turn on an LED.
 
int led_off (const struct device *dev, uint32_t led)
 Turn off an LED.
 
static int led_set_brightness_dt (const struct led_dt_spec *spec, uint8_t value)
 Set LED brightness from a led_dt_spec.
 
static int led_on_dt (const struct led_dt_spec *spec)
 Turn on an LED from a struct led_dt_spec.
 
static int led_off_dt (const struct led_dt_spec *spec)
 Turn off an LED from a struct led_dt_spec.
 
static bool led_is_ready_dt (const struct led_dt_spec *spec)
 Validate that the LED device is ready.
 

Detailed Description

LED Interface .

Since
1.12
Version
1.0.0

Macro Definition Documentation

◆ LED_DT_SPEC_GET

#define LED_DT_SPEC_GET ( node_id)

#include <zephyr/drivers/led.h>

Value:
{ \
.dev = DEVICE_DT_GET(DT_PARENT(node_id)), \
.index = DT_NODE_CHILD_IDX(node_id), \
}
#define DEVICE_DT_GET(node_id)
Get a device reference from a devicetree node identifier.
Definition device.h:254
#define DT_NODE_CHILD_IDX(node_id)
Get a devicetree node's index into its parent's list of children.
Definition devicetree.h:641
#define DT_PARENT(node_id)
Get a node identifier for a parent node.
Definition devicetree.h:364

Static initializer for a struct led_dt_spec.

This returns a static initializer for a struct led_dt_spec given a devicetree node identifier.

Example devicetree fragment:

leds {
compatible = "gpio-leds";
led0: led_0 {
...
};
};

Example usage:

const struct led_dt_spec spec = LED_DT_SPEC_GET(DT_NODELABEL(led0));
// Initializes 'spec' to:
// {
// .dev = DEVICE_DT_GET(DT_PARENT(led0)),
// .index = 0,
// }
#define DT_NODELABEL(label)
Get a node identifier for a node label.
Definition devicetree.h:196
#define LED_DT_SPEC_GET(node_id)
Static initializer for a struct led_dt_spec.
Definition led.h:442
Container for an LED information specified in devicetree.
Definition led.h:345

The device (dev) must still be checked for readiness, e.g. using device_is_ready().

Parameters
node_idDevicetree node identifier.
Returns
Static initializer for a struct led_dt_spec for the property.

◆ LED_DT_SPEC_GET_OR

#define LED_DT_SPEC_GET_OR ( node_id,
default_value )

#include <zephyr/drivers/led.h>

Value:
(LED_DT_SPEC_GET(node_id)), \
(default_value))
#define DT_NODE_EXISTS(node_id)
Does a node identifier refer to a node?
Definition devicetree.h:3604
#define COND_CODE_1(_flag, _if_1_code, _else_code)
Insert code depending on whether _flag expands to 1 or not.
Definition util_macro.h:195

Like LED_DT_SPEC_GET(), with a fallback value if the node does not exist.

Parameters
node_idDevicetree node identifier.
Returns
Static initializer for a struct led_dt_spec for the property.
See also
LED_DT_SPEC_GET

Typedef Documentation

◆ led_api_blink

typedef int(* led_api_blink) (const struct device *dev, uint32_t led, uint32_t delay_on, uint32_t delay_off)

#include <zephyr/drivers/led.h>

Callback API for blinking an LED.

See also
led_blink() for argument descriptions.

◆ led_api_get_info

typedef int(* led_api_get_info) (const struct device *dev, uint32_t led, const struct led_info **info)

#include <zephyr/drivers/led.h>

Optional API callback to get LED information.

See also
led_get_info() for argument descriptions.

◆ led_api_off

typedef int(* led_api_off) (const struct device *dev, uint32_t led)

#include <zephyr/drivers/led.h>

Callback API for turning off an LED.

See also
led_off() for argument descriptions.

◆ led_api_on

typedef int(* led_api_on) (const struct device *dev, uint32_t led)

#include <zephyr/drivers/led.h>

Callback API for turning on an LED.

See also
led_on() for argument descriptions.

◆ led_api_set_brightness

typedef int(* led_api_set_brightness) (const struct device *dev, uint32_t led, uint8_t value)

#include <zephyr/drivers/led.h>

Callback API for setting brightness of an LED.

See also
led_set_brightness() for argument descriptions.

◆ led_api_set_color

typedef int(* led_api_set_color) (const struct device *dev, uint32_t led, uint8_t num_colors, const uint8_t *color)

#include <zephyr/drivers/led.h>

Optional API callback to set the colors of a LED.

See also
led_set_color() for argument descriptions.

◆ led_api_write_channels

typedef int(* led_api_write_channels) (const struct device *dev, uint32_t start_channel, uint32_t num_channels, const uint8_t *buf)

#include <zephyr/drivers/led.h>

Callback API for writing a strip of LED channels.

See also
led_api_write_channels() for arguments descriptions.

Function Documentation

◆ led_blink()

int led_blink ( const struct device * dev,
uint32_t led,
uint32_t delay_on,
uint32_t delay_off )

#include <zephyr/drivers/led.h>

Blink an LED.

This optional routine starts blinking a LED forever with the given time period.

Parameters
devLED device
ledLED number
delay_onTime period (in milliseconds) an LED should be ON
delay_offTime period (in milliseconds) an LED should be OFF
Returns
0 on success, negative on error

◆ led_get_info()

int led_get_info ( const struct device * dev,
uint32_t led,
const struct led_info ** info )

#include <zephyr/drivers/led.h>

Get LED information.

This optional routine provides information about a LED.

Parameters
devLED device
ledLED number
infoPointer to a pointer filled with LED information
Returns
0 on success, negative on error

◆ led_is_ready_dt()

static bool led_is_ready_dt ( const struct led_dt_spec * spec)
inlinestatic

#include <zephyr/drivers/led.h>

Validate that the LED device is ready.

Parameters
specLED specification from devicetree.
Return values
trueIf the LED device is ready for use.
falseIf the LED device is not ready for use.

◆ led_off()

int led_off ( const struct device * dev,
uint32_t led )

#include <zephyr/drivers/led.h>

Turn off an LED.

This routine turns off an LED

Parameters
devLED device
ledLED number
Returns
0 on success, negative on error

◆ led_off_dt()

static int led_off_dt ( const struct led_dt_spec * spec)
inlinestatic

#include <zephyr/drivers/led.h>

Turn off an LED from a struct led_dt_spec.

Parameters
specLED device specification from devicetree.
Returns
0 on success, negative on error.
See also
led_off()

◆ led_on()

int led_on ( const struct device * dev,
uint32_t led )

#include <zephyr/drivers/led.h>

Turn on an LED.

This routine turns on an LED

Parameters
devLED device
ledLED number
Returns
0 on success, negative on error

◆ led_on_dt()

static int led_on_dt ( const struct led_dt_spec * spec)
inlinestatic

#include <zephyr/drivers/led.h>

Turn on an LED from a struct led_dt_spec.

Parameters
specLED device specification from devicetree.
Returns
0 on success, negative on error.
See also
led_on()

◆ led_set_brightness()

int led_set_brightness ( const struct device * dev,
uint32_t led,
uint8_t value )

#include <zephyr/drivers/led.h>

Set LED brightness.

This optional routine sets the brightness of a LED to the given value. Calling this function after led_blink() won't affect blinking.

LEDs which can only be turned on or off may provide this function. These should simply turn the LED on if value is nonzero, and off if value is zero.

Parameters
devLED device
ledLED number
valueBrightness value to set in percent
Returns
0 on success, negative on error

◆ led_set_brightness_dt()

static int led_set_brightness_dt ( const struct led_dt_spec * spec,
uint8_t value )
inlinestatic

#include <zephyr/drivers/led.h>

Set LED brightness from a led_dt_spec.

Parameters
specLED device specification from devicetree.
valueBrightness value to set in percent.
Returns
0 on success, negative on error.
See also
led_set_brightness()

◆ led_set_channel()

int led_set_channel ( const struct device * dev,
uint32_t channel,
uint8_t value )

#include <zephyr/drivers/led.h>

Set a single LED channel.

This optional routine sets a single LED channel to the given value.

Calling this function after led_blink() won't affect blinking.

Parameters
devLED device
channelAbsolute channel number (i.e. not relative to a LED)
valueValue to configure the channel with
Returns
0 on success, negative on error

◆ led_set_color()

int led_set_color ( const struct device * dev,
uint32_t led,
uint8_t num_colors,
const uint8_t * color )

#include <zephyr/drivers/led.h>

Set LED color.

This routine configures all the color channels of a LED with the given color array.

Calling this function after led_blink() won't affect blinking.

Parameters
devLED device
ledLED number
num_colorsNumber of colors in the array.
colorArray of colors. It must be ordered following the color mapping of the LED controller. See the color_mapping member in struct led_info.
Returns
0 on success, negative on error

◆ led_write_channels()

int led_write_channels ( const struct device * dev,
uint32_t start_channel,
uint32_t num_channels,
const uint8_t * buf )

#include <zephyr/drivers/led.h>

Write/update a strip of LED channels.

This optional routine writes a strip of LED channels to the given array of levels. Therefore it can be used to configure several LEDs at the same time.

Calling this function after led_blink() won't affect blinking.

Parameters
devLED device
start_channelAbsolute number (i.e. not relative to a LED) of the first channel to update.
num_channelsThe number of channels to write/update.
bufarray of values to configure the channels with. num_channels entries must be provided.
Returns
0 on success, negative on error