Simple RGBW PWM LED Driver
Description
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".
- 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.
- 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.
Data Structures |
|
struct | sl_simple_rgbw_pwm_led_context_t |
A Simple RGBW LED context.
|
|
struct | sl_led_rgbw_pwm_t |
A Simple RGBW LED PWM instance.
|
|
Functions |
|
sl_status_t | sl_simple_rgbw_pwm_led_init (void *rgbw) |
Initialize the RGBW PWM LED driver.
|
|
void | sl_simple_rgbw_pwm_led_turn_on (void *rgbw) |
Turn on an RBGW LED.
|
|
void | sl_simple_rgbw_pwm_led_turn_off (void *rgbw) |
Turn off an RGBW LED.
|
|
void | sl_simple_rgbw_pwm_led_toggle (void *rgbw) |
Toggle an RGBW LED.
|
|
sl_led_state_t | sl_simple_rgbw_pwm_led_get_state (void *rgbw) |
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 | SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_HIGH 0U |
LED Active polarity High.
|
|
#define | SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_LOW 1U |
LED Active polarity Low.
|
|
#define | SL_SIMPLE_RGBW_PWM_LED_COLOR_R 0U |
LED Red.
|
|
#define | SL_SIMPLE_RGBW_PWM_LED_COLOR_G 1U |
LED Green.
|
|
#define | SL_SIMPLE_RGBW_PWM_LED_COLOR_B 2U |
LED Blue.
|
|
#define | SL_SIMPLE_RGBW_PWM_LED_COLOR_W 3U |
LED White.
|
|
#define | SL_SIMPLE_RGBW_PWM_LED_NUM_CC_REQUIRED 4U |
Number of Timer Capture Channels required (1 for each RGBW color)
|
|
Typedefs |
|
typedef uint8_t | sl_simple_rgbw_pwm_led_polarity_t |
LED GPIO polarities (active high/low)
|
|
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] led_handle
Pointer to rgbw-pwm-led specific data:
- Returns
-
Status Code:
- SL_STATUS_OK Success
- SL_STATUS_FAIL Init error
◆ sl_simple_rgbw_pwm_led_turn_on()
void sl_simple_rgbw_pwm_led_turn_on | ( | void * |
rgbw
|
) |
Turn on an RBGW LED.
Turns on at previously set color levels If no previous levels set, turns on at max level for all four RGBW LEDs
- Parameters
-
[in] led_handle
Pointer to rgbw_pwm-led specific data:
◆ sl_simple_rgbw_pwm_led_turn_off()
void sl_simple_rgbw_pwm_led_turn_off | ( | void * |
rgbw
|
) |
Turn off an RGBW LED.
- Parameters
-
[in] led_handle
Pointer to rgbw-pwm-led specific data:
◆ sl_simple_rgbw_pwm_led_toggle()
void sl_simple_rgbw_pwm_led_toggle | ( | void * |
rgbw
|
) |
Toggle an RGBW LED.
The toggle "ON" behavior is as defined for sl_simple_rgbw_pwm_led_turn_on()
- Parameters
-
[in] led_handle
Pointer to rgbw-pwm-led specific data:
◆ 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] led_handle
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
◆ 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] led_handle
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])
◆ 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.
- Note
- Will return the last stored levels regardless of the current ON/OFF state. Call sl_simple_rgbw_pwm_led_get_state() to determine if the RGBW LED is actually ON or OFF.
- Parameters
-
[in] led_handle
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])
◆ 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
-
rgbw
LED Instance handle red
LED red intensity green
LED green intensity blue
LED blue intensity white
LED white intensity
◆ 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
-
rgbw
LED Instance handle red
LED red intensity green
LED green intensity blue
LED blue intensity white
LED white intensity
Macro Definition Documentation
◆ SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_HIGH
#define SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_HIGH 0U |
LED Active polarity High.
◆ SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_LOW
#define SL_SIMPLE_RGBW_PWM_LED_POLARITY_ACTIVE_LOW 1U |
LED Active polarity Low.
◆ SL_SIMPLE_RGBW_PWM_LED_COLOR_R
#define SL_SIMPLE_RGBW_PWM_LED_COLOR_R 0U |
LED Red.
◆ SL_SIMPLE_RGBW_PWM_LED_COLOR_G
#define SL_SIMPLE_RGBW_PWM_LED_COLOR_G 1U |
LED Green.
◆ SL_SIMPLE_RGBW_PWM_LED_COLOR_B
#define SL_SIMPLE_RGBW_PWM_LED_COLOR_B 2U |
LED Blue.
◆ SL_SIMPLE_RGBW_PWM_LED_COLOR_W
#define SL_SIMPLE_RGBW_PWM_LED_COLOR_W 3U |
LED White.
◆ SL_SIMPLE_RGBW_PWM_LED_NUM_CC_REQUIRED
#define SL_SIMPLE_RGBW_PWM_LED_NUM_CC_REQUIRED 4U |
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)