LED Driver#

Generic LED Driver.


Introduction#

The LED driver is a platfom level software module that manages the control of various types of LEDs. There are currently two types of LEDs supported by the LED driver:

The common LED functions are called through the generic LED driver, while other functions specific to a certain type of LED are called directly through their own driver.


Configuration#

All LED instances are configured using an sl_led_t struct along with a type-specific context struct, and sometimes additional structs. For sl_led_XXX functions, the sl_led_t *led_handle is used, while for sl_simple_led_XXX functions, the sl_simple_led_context_t *context is used.

These structs are automatically generated when an LED is set up using Simplicity Studio's wizard. Specific configuration setups for the various LED types are described in the following sections.


Usage#

Once the LED structs are defined, the common LED functions can be called being passed an instance of sl_led_t, which will be redirected to calling the type specific version of that function. The common functions include the following:

These functions allow for initializing the LED, turning it on and off, toggling it, and retrieving its current state (on/off). Other functions specific to certain types of LEDs are called through their respective APIs. The usages of the different types of LEDs are described in detail in the following sections:

Ensure that the appropriate context type is used in the function calls:

  • Use sl_led_t *led_handle for sl_led_XXX functions.

  • Use sl_simple_led_context_t *context for sl_simple_led_XXX functions.

These distinctions are handled by the Simplicity Studio auto-generated code.

Modules#

sl_led_t

Simple LED Driver

Simple RGB PWM LED Driver

Typedefs#

typedef uint8_t

LED state.

Functions#

sl_status_t
sl_led_init(const sl_led_t *led_handle)

Initialize the LED driver.

void
sl_led_turn_on(const sl_led_t *led_handle)

Turn on the LED.

void
sl_led_turn_off(const sl_led_t *led_handle)

Turn off the LED.

void
sl_led_toggle(const sl_led_t *led_handle)

Toggle the LED.

sl_led_get_state(const sl_led_t *led_handle)

Get the current state of the LED.

Macros#

#define
SL_LED_CURRENT_STATE_OFF 0U

LED state off.

#define
SL_LED_CURRENT_STATE_ON 1U

LED state on.

Typedef Documentation#

sl_led_state_t#

typedef uint8_t sl_led_state_t

LED state.


Function Documentation#

sl_led_init#

sl_status_t sl_led_init (const sl_led_t * led_handle)

Initialize the LED driver.

Parameters
TypeDirectionArgument NameDescription
const sl_led_t *[in]led_handle

Pointer to instance of sl_led_t to initialize

Call this function before any other LED function. Initializes the selected LED GPIO, mode, and polarity.

Returns

  • Status Code:

    • SL_STATUS_OK


sl_led_turn_on#

void sl_led_turn_on (const sl_led_t * led_handle)

Turn on the LED.

Parameters
TypeDirectionArgument NameDescription
const sl_led_t *[in]led_handle

Pointer to instance of sl_led_t to turn on


sl_led_turn_off#

void sl_led_turn_off (const sl_led_t * led_handle)

Turn off the LED.

Parameters
TypeDirectionArgument NameDescription
const sl_led_t *[in]led_handle

Pointer to instance of sl_led_t to turn off


sl_led_toggle#

void sl_led_toggle (const sl_led_t * led_handle)

Toggle the LED.

Parameters
TypeDirectionArgument NameDescription
const sl_led_t *[in]led_handle

Pointer to instance of sl_led_t to toggle

Turn it on if it is off, and off if it is on.


sl_led_get_state#

sl_led_state_t sl_led_get_state (const sl_led_t * led_handle)

Get the current state of the LED.

Parameters
TypeDirectionArgument NameDescription
const sl_led_t *[in]led_handle

Pointer to instance of sl_led_t to check

Returns

  • sl_led_state_t Current state of LED. 1 for on, 0 for off