This is the documentation for the latest (master) development branch of Zephyr. If you are looking for the documentation of previous releases, use the drop-down menu on the left and select the desired version.

LED

Overview

The LED API provides access to Light Emitting Diodes, both in individual and stip form.

Configuration Options

Related configuration options:

API Reference

LED

group led_interface

LED Interface.

Typedefs

Callback API for blinking an LED.

See

led_blink() for argument descriptions.

typedef led_api_set_brightness

Callback API for setting brightness of an LED.

See

led_set_brightness() for argument descriptions.

typedef led_api_on

Callback API for turning on an LED.

See

led_on() for argument descriptions.

typedef led_api_off

Callback API for turning off an LED.

See

led_off() for argument descriptions.

Functions

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

Blink an LED.

This routine starts blinking an LED forever with the given time period

Return

0 on success, negative on error

Parameters
  • dev: LED device

  • led: LED channel/pin

  • delay_on: Time period (in milliseconds) an LED should be ON

  • delay_off: Time period (in milliseconds) an LED should be OFF

int led_set_brightness(struct device *dev, u32_t led, u8_t value)

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.

Return

0 on success, negative on error

Parameters
  • dev: LED device

  • led: LED channel/pin

  • value: Brightness value to set in percent

int led_on(struct device *dev, u32_t led)

Turn on an LED.

This routine turns on an LED

Return

0 on success, negative on error

Parameters
  • dev: LED device

  • led: LED channel/pin

int led_off(struct device *dev, u32_t led)

Turn off an LED.

This routine turns off an LED

Return

0 on success, negative on error

Parameters
  • dev: LED device

  • led: LED channel/pin

struct led_driver_api
#include <led.h>

LED driver API.

This is the mandatory API any LED driver needs to expose.

LED Strip

group led_strip_interface

LED Strip Interface.

Typedefs

typedef led_api_update_rgb

Callback API for updating an RGB LED strip.

See

led_strip_update_rgb() for argument descriptions.

typedef led_api_update_channels

Callback API for updating channels without an RGB interpretation.

See

led_strip_update_channels() for argument descriptions.

Functions

static int led_strip_update_rgb(struct device *dev, struct led_rgb *pixels, size_t num_pixels)

Update an LED strip made of RGB pixels.

Important: This routine may overwrite pixels.

This routine immediately updates the strip display according to the given pixels array.

Return

0 on success, negative on error

Warning

May overwrite pixels

Parameters
  • dev: LED strip device

  • pixels: Array of pixel data

  • num_pixels: Length of pixels array

static int led_strip_update_channels(struct device *dev, u8_t *channels, size_t num_channels)

Update an LED strip on a per-channel basis.

Important: This routine may overwrite channels.

This routine immediately updates the strip display according to the given channels array. Each channel byte corresponds to an individually addressable color channel or LED. Channels are updated linearly in strip order.

Return

0 on success, negative on error

Warning

May overwrite channels

Parameters
  • dev: LED strip device

  • channels: Array of per-channel data

  • num_channels: Length of channels array

struct led_rgb
#include <led_strip.h>

Color value for a single RGB LED.

Individual strip drivers may ignore lower-order bits if their resolution in any channel is less than a full byte.

struct led_strip_driver_api
#include <led_strip.h>

LED strip driver API.

This is the mandatory API any LED strip driver needs to expose.