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.

Introduction#

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

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 "inst0".

// sl_simple_led_instances.c

#include "sl_simple_led.h"
#include "em_gpio.h"
#include "sl_simple_led_inst0_config.h"

sl_simple_led_context_t simple_inst0_context = {
  .port = SL_SIMPLE_LED_INST0_PORT,
  .pin = SL_SIMPLE_LED_INST0_PIN,
  .polarity = SL_SIMPLE_LED_INST0_POLARITY,
};

const sl_led_t sl_led_inst0 = {
  .context = &simple_inst0_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_inst0);
}

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_inst0;

void sl_simple_led_init_instances(void);

#endif // SL_SIMPLE_LED_INIT_H

Note

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

Simple LED Usage#

The simple LED driver is for LEDs with basic on off functionality, and there are no additional functions beyond those in the common driver. The LEDs can be turned on and off, toggled, and their on/off state can be retrieved. The following code shows how to control these LEDs. An LED should always be initialized before calling any other functions with it.

// initialize simple LED
sl_simple_led_init(&simple_led_inst0);

// turn on simple LED, turn off simple LED, and toggle the simple LED
sl_simple_led_turn_on(&simple_led_inst0);
sl_simple_led_turn_off(&simple_led_inst0);
sl_simple_led_toggle(&simple_led_inst0);

// get the state of the simple LED
sl_led_state_t state = sl_simple_led_get_state(&simple_led_instance0);

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

LED Active polarity Low.

#define

LED Active polarity High.

Typedef Documentation#

sl_led_polarity_t#

typedef uint8_t sl_led_polarity_t

LED GPIO polarities (active high/low)


Definition at line 72 of file platform/driver/leddrv/inc/sl_simple_led.h

Function Documentation#

sl_simple_led_init#

sl_status_t sl_simple_led_init (void * led_handle)

Initialize the simple LED driver.

Parameters
[in]led_handle

Pointer to simple-led specific data:

Returns

  • Status Code:

    • SL_STATUS_OK


Definition at line 99 of file platform/driver/leddrv/inc/sl_simple_led.h

sl_simple_led_turn_on#

void sl_simple_led_turn_on (void * led_handle)

Turn on a simple LED.

Parameters
[in]led_handle

Pointer to simple-led specific data:


Definition at line 108 of file platform/driver/leddrv/inc/sl_simple_led.h

sl_simple_led_turn_off#

void sl_simple_led_turn_off (void * led_handle)

Turn off a simple LED.

Parameters
[in]led_handle

Pointer to simple-led specific data:


Definition at line 117 of file platform/driver/leddrv/inc/sl_simple_led.h

sl_simple_led_toggle#

void sl_simple_led_toggle (void * led_handle)

Toggle a simple LED.

Parameters
[in]led_handle

Pointer to simple-led specific data:


Definition at line 126 of file platform/driver/leddrv/inc/sl_simple_led.h

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
[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


Definition at line 136 of file platform/driver/leddrv/inc/sl_simple_led.h

Macro Definition Documentation#

SL_SIMPLE_LED_POLARITY_ACTIVE_LOW#

#define SL_SIMPLE_LED_POLARITY_ACTIVE_LOW
Value:
0U

LED Active polarity Low.


Definition at line 65 of file platform/driver/leddrv/inc/sl_simple_led.h

SL_SIMPLE_LED_POLARITY_ACTIVE_HIGH#

#define SL_SIMPLE_LED_POLARITY_ACTIVE_HIGH
Value:
1U

LED Active polarity High.


Definition at line 66 of file platform/driver/leddrv/inc/sl_simple_led.h