Simple RGBW PWM LED Driver#

Simple RGBW PWM LED Driver provides functionality to control Red/Green/Blue/White LEDs that are driven by the PWM. Basic functionalities such as on, off, toggle, or retrieve state of RGBW LED can also be executed using this module.

Introduction#

The Simple RGBW PWM LED Driver is a module for the LED driver that provides functionality for controlling Red/Green/Blue/White LEDs that are driven by PWM.

RGBW PWM LED Configuration#

RGBW PWM LEDs use the sl_led_t struct, and their own structs sl_simple_rgbw_pwm_led_context_t and sl_led_rgbw_pwm_t. 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_rgbw_pwm_led_instances.c

#include "em_gpio.h"
#include "sl_simple_rgbw_pwm_led.h"

#include "sl_simple_rgbw_pwm_led_inst0_config.h"



sl_led_pwm_t red_inst0 = {
  .port = SIMPLE_RGBW_PWM_LED_INST0_PORT,
  .pin = SIMPLE_RGBW_PWM_LED_INST0_PIN,
  .polarity = SIMPLE_RGBW_PWM_LED_INST0_POLARITY,
  .channel = SIMPLE_RGBW_PWM_LED_INST0_CHANNEL,
#if defined(SL_SIMPLE_RGBW_PWM_LED_INST0_RED_LOC)
  .location = SIMPLE_RGBW_PWM_LED_INST0_LOC,
#endif
};

sl_led_pwm_t green_inst0 = {
  .port = SIMPLE_RGBW_PWM_LED_INST0_PORT,
  .pin = SIMPLE_RGBW_PWM_LED_INST0_PIN,
  .polarity = SIMPLE_RGBW_PWM_LED_INST0_POLARITY,
  .channel = SIMPLE_RGBW_PWM_LED_INST0_CHANNEL,
#if defined(SL_SIMPLE_RGBW_PWM_LED_INST0_RED_LOC)
  .location = SIMPLE_RGBW_PWM_LED_INST0_LOC,
#endif
};

sl_led_pwm_t blue_inst0 = {
  .port = SIMPLE_RGBW_PWM_LED_INST0_PORT,
  .pin = SIMPLE_RGBW_PWM_LED_INST0_PIN,
  .polarity = SIMPLE_RGBW_PWM_LED_INST0_POLARITY,
  .channel = SIMPLE_RGBW_PWM_LED_INST0_CHANNEL,
#if defined(SL_SIMPLE_RGBW_PWM_LED_INST0_RED_LOC)
  .location = SIMPLE_RGBW_PWM_LED_INST0_LOC,
#endif
};

sl_led_pwm_t white_inst0 = {
  .port = SIMPLE_RGBW_PWM_LED_INST0_PORT,
  .pin = SIMPLE_RGBW_PWM_LED_INST0_PIN,
  .polarity = SIMPLE_RGBW_PWM_LED_INST0_POLARITY,
  .channel = SIMPLE_RGBW_PWM_LED_INST0_CHANNEL,
#if defined(SL_SIMPLE_RGBW_PWM_LED_INST0_RED_LOC)
  .location = SIMPLE_RGBW_PWM_LED_INST0_LOC,
#endif
};

sl_simple_rgbw_pwm_led_context_t simple_rgbw_pwm_inst0_context = {
  .red = &red_inst0,
  .green = &green_inst0,
  .blue = &blue_inst0,
  .white = &white_inst0,

  .timer = SL_SIMPLE_RGBW_PWM_LED_INST0_PERIPHERAL,
  .frequency = SL_SIMPLE_RGBW_PWM_LED_INST0_FREQUENCY,
  .resolution = SL_SIMPLE_RGBW_PWM_LED_INST0_RESOLUTION,
};

const sl_led_rgbw_pwm_t sl_inst0 = {
  .led_common.context = &simple_rgbw_pwm_inst0_context,
  .led_common.init = sl_simple_rgbw_pwm_led_init,
  .led_common.turn_on = sl_simple_rgbw_pwm_led_turn_on,
  .led_common.turn_off = sl_simple_rgbw_pwm_led_turn_off,
  .led_common.toggle = sl_simple_rgbw_pwm_led_toggle,
  .led_common.get_state = sl_simple_rgbw_pwm_led_get_state,
  .set_rgbw_color = sl_simple_rgbw_pwm_led_set_color,
  .get_rgbw_color = sl_simple_rgbw_pwm_led_get_color,
};



void sl_simple_rgbw_pwm_led_init_instances(void)
{

  sl_led_init((sl_led_t *)&sl_inst0);

}

Note

  • The sl_simple_rgbw_pwm_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_rgbw_pwm_led_instances.h

#ifndef SL_SIMPLE_RGBW_PWM_LED_INSTANCES_H
#define SL_SIMPLE_RGBW_PWM_LED_INSTANCES_H

#include "sl_simple_rgbw_pwm_led.h"

extern const sl_led_rgbw_pwm_t sl_inst0;

void sl_simple_rgbw_pwm_led_init_instances(void);

#endif // SL_SIMPLE_RGBW_PWM_LED_INIT_H

Note

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

RGBW PWM LED Usage#

The RGBW PWM Led driver provides functionality for controlling Red/Green/Blue/White LEDs that are driven by PWM. The LEDs can be turned on and off and toggled, and remember their color and brightness state when being turned back on. The color and brightness can be set using values of 0-65535 for red, green, blue, and white. Retrieving the state gives the on/off value, while retrieving the color gives the rgbw values. The following code shows how to control these LEDs. An LED should always be initialized before calling any other functions with it.

// initialize rgbw LED
sl_led_init(&rgbw_led_inst0);

// turn on LED, set color to purple, turn off, toggle (would maintain purple color)
sl_led_turn_on(&rgbw_led_inst0);
uint16_t white = 65535; // max brightness
uint16_t red = 65535; // max red
uint16_t green = 0; // no green
uint16_t blue = 65535; // max blue
sl_led_set_rgbw_color(&rgbw_led_inst0, red, green, blue, white);
sl_led_turn_off(&rgbw_led_inst0);
sl_led_toggle(&rgbw_led_inst0);

// get the state of the led
sl_led_state_t state = sl_led_get_state(&rgbw_led_instance0);

Modules#

sl_simple_rgbw_pwm_led_context_t

sl_led_rgbw_pwm_t

Typedefs#

typedef uint8_t

LED GPIO polarities (active high/low)

Functions#

sl_status_t

Initialize the RGBW PWM LED driver.

void

Turn on an RBGW LED.

void

Turn off an RGBW LED.

void

Toggle an RGBW LED.

Get status of an RGBW LED.

void
sl_simple_rgbw_pwm_led_set_color(void *rgbw, uint16_t red, uint16_t green, uint16_t blue, uint16_t white)

Set color mixing and dimming level of an RGBW LED.

void
sl_simple_rgbw_pwm_led_get_color(void *rgbw, uint16_t *red, uint16_t *green, uint16_t *blue, uint16_t *white)

Get current color mixing and dimming level of an RGBW LED.

void
sl_led_set_rgbw_color(const sl_led_rgbw_pwm_t *rgbw, uint16_t red, uint16_t green, uint16_t blue, uint16_t white)

LED set RGBW color.

void
sl_led_get_rgbw_color(const sl_led_rgbw_pwm_t *rgbw, uint16_t *red, uint16_t *green, uint16_t *blue, uint16_t *white)

LED get RGBW setting.

Macros#

#define

LED Active polarity High.

#define

LED Active polarity Low.

#define
#define
#define
#define

Number of Timer Capture Channels required (1 for each RGBW color)

Typedef Documentation#

sl_simple_rgbw_pwm_led_polarity_t#

typedef uint8_t sl_simple_rgbw_pwm_led_polarity_t

LED GPIO polarities (active high/low)


Definition at line 75 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

Function Documentation#

sl_simple_rgbw_pwm_led_init#

sl_status_t sl_simple_rgbw_pwm_led_init (void * rgbw)

Initialize the RGBW PWM LED driver.

Parameters
[in]rgbw

Pointer to rgbw-pwm-led specific data:

Returns

  • Status Code:

    • SL_STATUS_OK Success

    • SL_STATUS_FAIL Init error


Definition at line 118 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

sl_simple_rgbw_pwm_led_turn_on#

void sl_simple_rgbw_pwm_led_turn_on (void * rgbw)

Turn on an RBGW LED.

Parameters
[in]rgbw

Pointer to rgbw_pwm-led specific data:

Turns on at previously set color levels If no previous levels set, turns on at max level for all four RGBW LEDs


Definition at line 128 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

sl_simple_rgbw_pwm_led_turn_off#

void sl_simple_rgbw_pwm_led_turn_off (void * rgbw)

Turn off an RGBW LED.

Parameters
[in]rgbw

Pointer to rgbw-pwm-led specific data:


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

sl_simple_rgbw_pwm_led_toggle#

void sl_simple_rgbw_pwm_led_toggle (void * rgbw)

Toggle an RGBW LED.

Parameters
[in]rgbw

Pointer to rgbw-pwm-led specific data:

The toggle "ON" behavior is as defined for sl_simple_rgbw_pwm_led_turn_on()


Definition at line 145 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

sl_simple_rgbw_pwm_led_get_state#

sl_led_state_t sl_simple_rgbw_pwm_led_get_state (void * rgbw)

Get status of an RGBW LED.

Parameters
[in]rgbw

Pointer to rgbw-pwm-led specific data:

Returns

  • sl_led_state_t Current state of RGBW LED. 0 for Red, Green, Blue and White LEDs are all OFF 1 for Red, Green, Blue or White LED is ON


Definition at line 156 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

sl_simple_rgbw_pwm_led_set_color#

void sl_simple_rgbw_pwm_led_set_color (void * rgbw, uint16_t red, uint16_t green, uint16_t blue, uint16_t white)

Set color mixing and dimming level of an RGBW LED.

Parameters
[in]rgbw

Pointer to rgbw-pwm-led specific data:

[in]red

Red color level (PWM duty-cycle [0-65535])

[in]green

Green color level (PWM duty-cycle [0-65535])

[in]blue

Blue color level (PWM duty-cycle [0-65535])

[in]white

White color level (PWM duty-cycle [0-65535])


Definition at line 169 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

sl_simple_rgbw_pwm_led_get_color#

void sl_simple_rgbw_pwm_led_get_color (void * rgbw, uint16_t * red, uint16_t * green, uint16_t * blue, uint16_t * white)

Get current color mixing and dimming level of an RGBW LED.

Parameters
[in]rgbw

Pointer to rgbw-pwm-led specific data:

[out]red

Red color level (PWM duty-cycle [0-65535])

[out]green

Green color level (PWM duty-cycle [0-65535])

[out]blue

Blue color level (PWM duty-cycle [0-65535])

[out]white

White color level (PWM duty-cycle [0-65535])

Note


Definition at line 190 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

sl_led_set_rgbw_color#

void sl_led_set_rgbw_color (const sl_led_rgbw_pwm_t * rgbw, uint16_t red, uint16_t green, uint16_t blue, uint16_t white)

LED set RGBW color.

Parameters
N/Argbw
N/Ared
N/Agreen
N/Ablue
N/Awhite

Definition at line 200 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

sl_led_get_rgbw_color#

void sl_led_get_rgbw_color (const sl_led_rgbw_pwm_t * rgbw, uint16_t * red, uint16_t * green, uint16_t * blue, uint16_t * white)

LED get RGBW setting.

Parameters
N/Argbw
N/Ared
N/Agreen
N/Ablue
N/Awhite

Definition at line 207 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

Macro Definition Documentation#

SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_HIGH#

#define SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_HIGH
Value:
0U

LED Active polarity High.


Definition at line 61 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_LOW#

#define SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_LOW
Value:
1U

LED Active polarity Low.


Definition at line 62 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

SL_SIMPLE_RGBW_PWM_LED_COLOR_R#

#define SL_SIMPLE_RGBW_PWM_LED_COLOR_R
Value:
0U

LED Red.


Definition at line 64 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

SL_SIMPLE_RGBW_PWM_LED_COLOR_G#

#define SL_SIMPLE_RGBW_PWM_LED_COLOR_G
Value:
1U

LED Green.


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

SL_SIMPLE_RGBW_PWM_LED_COLOR_B#

#define SL_SIMPLE_RGBW_PWM_LED_COLOR_B
Value:
2U

LED Blue.


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

SL_SIMPLE_RGBW_PWM_LED_COLOR_W#

#define SL_SIMPLE_RGBW_PWM_LED_COLOR_W
Value:
3U

LED White.


Definition at line 67 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h

SL_SIMPLE_RGBW_PWM_LED_NUM_CC_REQUIRED#

#define SL_SIMPLE_RGBW_PWM_LED_NUM_CC_REQUIRED
Value:
4U

Number of Timer Capture Channels required (1 for each RGBW color)


Definition at line 69 of file platform/driver/leddrv/inc/sl_simple_rgbw_pwm_led.h