Simple LED Driver

Description

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,
};
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_led_init (&simple_led_inst0);
// turn on LED, turn off LED, and toggle
sl_led_turn_on (&simple_led_inst0);
sl_led_turn_off (&simple_led_inst0);
sl_led_toggle (&simple_led_inst0);
// get the state of the led
sl_led_state_t state = sl_led_get_state (&simple_led_instance0);

Data Structures

struct sl_simple_led_context_t
A Simple LED instance.

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_led_state_t 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.

Typedefs

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
[in] led_handle Pointer to simple-led specific data:
Returns
Status Code:
  • SL_STATUS_OK

defined(_SILICON_LABS_32B_SERIES_2)

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:

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:

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:

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

Macro Definition Documentation

SL_SIMPLE_LED_POLARITY_ACTIVE_LOW

#define SL_SIMPLE_LED_POLARITY_ACTIVE_LOW   0U

LED Active polarity Low.

SL_SIMPLE_LED_POLARITY_ACTIVE_HIGH

#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)