Simple LED Driver#

Simple LED Driver can be used to execute basic LED functionalities such as on, off, toggle, or retrive the on/off status on Silicon Labs devices.

Subsequent sections provide more insight into this module.

The Simple LED Driver can be used to execute basic LED functionalities such as on, off, toggle, or retrieve the on/off state on Silicon Labs devices. Subsequent sections provide more insight into this module.


Introduction#

The Simple LED driver is a module of the LED driver that provides the functionality to control simple on/off LEDs.


Instance pointer vs context pointer#

  • Common LED API (sl_led_init, sl_led_turn_on, sl_led_turn_off, sl_led_toggle, sl_led_get_state): pass &sl_led_<instance> (e.g. &sl_led_led0). Recommended for most application code.

  • Simple LED API (sl_simple_led_*): expects a pointer to sl_simple_led_context_t (as void *), not&sl_led_led0. Obtain it from the exported instance:

    (void *)sl_led_led0.context 
    

    Replace led0 with your instance name if different. Do not use &simple_led0_context in application code — that symbol is not declared in sl_simple_led_instances.h (see configuration notes below).


Simple LED Configuration#

Simple LEDs use the sl_led_t struct and their sl_simple_led_context_t struct. These are automatically generated into the following files, as well as instance specific headers with macro definitions in them. The samples below are for a single instance called "led0".

// sl_simple_led_instances.c

 #include "sl_simple_led.h"
 #include "sl_gpio.h"
 #include "sl_simple_led_led0_config.h"

 sl_simple_led_context_t simple_led0_context = {
   .port = SL_SIMPLE_LED_LED0_PORT,
   .pin = SL_SIMPLE_LED_LED0_PIN,
   .polarity = SL_SIMPLE_LED_LED0_POLARITY,
 };

 const sl_led_t sl_led_led0 = {
   .context = &simple_led0_context,
   .init = sl_simple_led_init,
   .turn_on = sl_simple_led_turn_on,
   .turn_off = sl_simple_led_turn_off,
   .toggle = sl_simple_led_toggle,
   .get_state = sl_simple_led_get_state,
 };

 void sl_simple_led_init_instances(void)
 {
   sl_led_init(&sl_led_led0);
 }

Note

  • The sl_simple_led_instances.c file is shown with only one instance, but if more were in use they would all appear in this .c file.

// sl_simple_led_instances.h

#ifndef SL_SIMPLE_LED_INSTANCES_H
#define SL_SIMPLE_LED_INSTANCES_H

#include "sl_simple_led.h"

extern const sl_led_t sl_led_led0;

void sl_simple_led_init_instances(void);

#endif // SL_SIMPLE_LED_INSTANCES_H

Note

  • The .h file exports only the LED instance (sl_led_led0), not the underlying context struct. User code must not reference simple_led0_context by name.


Simple LED Usage#

The simple LED driver is for LEDs with basic on/off functionality. There are no additional functions beyond those in the common driver. Include sl_simple_led_instances.h in application code that uses the generated instances. When the Simple LED component is present, startup typically calls sl_simple_led_init_instances(); you may omit extra sl_led_init unless needed.

Recommended — common LED API (uses sl_led_t *, not context):

#include "sl_simple_led_instances.h"

sl_led_turn_on(&sl_led_led0);
sl_led_turn_off(&sl_led_led0);
sl_led_toggle(&sl_led_led0);

sl_led_state_t state_led = sl_led_get_state(&sl_led_led0);

**Alternative — sl_simple_led_* directly** (must pass context via .context; cast to void * matches the API prototype and avoids toolchain warnings):

#include "sl_simple_led_instances.h"

sl_simple_led_init((void *)sl_led_led0.context);
sl_simple_led_turn_on((void *)sl_led_led0.context);
sl_simple_led_turn_off((void *)sl_led_led0.context);
sl_simple_led_toggle((void *)sl_led_led0.context);

sl_led_state_t state_simple = sl_simple_led_get_state((void *)sl_led_led0.context);

Do not pass &sl_led_led0 to sl_simple_led_turn_on (or similar), and do not use &simple_led0_context from application code.

Modules#

sl_simple_led_context_t

Typedefs#

typedef uint8_t

LED GPIO polarities (active high/low)

Functions#

sl_status_t
sl_simple_led_init(void *led_handle)

Initialize the simple LED driver.

void
sl_simple_led_turn_on(void *led_handle)

Turn on a simple LED.

void
sl_simple_led_turn_off(void *led_handle)

Turn off a simple LED.

void
sl_simple_led_toggle(void *led_handle)

Toggle a simple LED.

sl_simple_led_get_state(void *led_handle)

Get the current state of the simple LED.

Macros#

#define
SL_SIMPLE_LED_POLARITY_ACTIVE_LOW 0U

LED Active polarity Low.

#define
SL_SIMPLE_LED_POLARITY_ACTIVE_HIGH 1U

LED Active polarity High.

Typedef Documentation#

sl_led_polarity_t#

typedef uint8_t sl_led_polarity_t

LED GPIO polarities (active high/low)


Function Documentation#

sl_simple_led_init#

sl_status_t sl_simple_led_init (void * led_handle)

Initialize the simple LED driver.

Parameters
TypeDirectionArgument NameDescription
void *[in]led_handle

Pointer to simple-led specific data:

Returns

  • Status Code:

    • SL_STATUS_OK


sl_simple_led_turn_on#

void sl_simple_led_turn_on (void * led_handle)

Turn on a simple LED.

Parameters
TypeDirectionArgument NameDescription
void *[in]led_handle

Pointer to simple-led specific data:


sl_simple_led_turn_off#

void sl_simple_led_turn_off (void * led_handle)

Turn off a simple LED.

Parameters
TypeDirectionArgument NameDescription
void *[in]led_handle

Pointer to simple-led specific data:


sl_simple_led_toggle#

void sl_simple_led_toggle (void * led_handle)

Toggle a simple LED.

Parameters
TypeDirectionArgument NameDescription
void *[in]led_handle

Pointer to simple-led specific data:


sl_simple_led_get_state#

sl_led_state_t sl_simple_led_get_state (void * led_handle)

Get the current state of the simple LED.

Parameters
TypeDirectionArgument NameDescription
void *[in]led_handle

Pointer to simple-led specific data:

Returns

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