RGB LED (rgb-led)
RGB LED

General Description

Macros

#define CY_RSLT_RGB_LED_CLK_FAIL   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_RGB_LED , 0))
 Error code for RGB LED operation: Peripheral clock assignment failure.
 
#define CY_RSLT_RGB_LED_PWM_FAIL   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_RGB_LED , 1))
 Error code for RGB LED operation: PWM resource allocation failure.
 
#define CY_RSLT_RGB_LED_LP_CB_REG_FAIL   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_RGB_LED , 2))
 Error code for RGB LED operation: Low power callback function registration failure.
 
#define CY_RSLT_RGB_LED_LP_CB_DEREG_FAIL   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_LIB_RGB_LED , 3))
 Error code for RGB LED operation: Low power callback function deregistration failure.
 
#define CY_RGB_LED_RED_POS   (16u)
 Bit position for Red LED.
 
#define CY_RGB_LED_GREEN_POS   (8u)
 Bit position for Green LED.
 
#define CY_RGB_LED_BLUE_POS   (0u)
 Bit position for Blue LED.
 
#define CY_RGB_LED_COLOR_RED   (0xFF << CY_RGB_LED_RED_POS)
 32-bit encoding for Red Color
More...
 
#define CY_RGB_LED_COLOR_GREEN   (0xFF << CY_RGB_LED_GREEN_POS)
 32-bit encoding for Green Color. More...
 
#define CY_RGB_LED_COLOR_BLUE   (0xFF << CY_RGB_LED_BLUE_POS)
 32-bit encoding for Blue Color. More...
 
#define CY_RGB_LED_COLOR_WHITE
 32-bit encoding for White Color. More...
 
#define CY_RGB_LED_COLOR_YELLOW   (CY_RGB_LED_COLOR_RED | CY_RGB_LED_COLOR_GREEN)
 32-bit encoding for Yellow Color. More...
 
#define CY_RGB_LED_COLOR_MAGENTA   (CY_RGB_LED_COLOR_RED | CY_RGB_LED_COLOR_BLUE)
 32-bit encoding for Magenta Color. More...
 
#define CY_RGB_LED_COLOR_PURPLE   (CY_RGB_LED_COLOR_MAGENTA)
 Deprecated. More...
 
#define CY_RGB_LED_COLOR_CYAN   (CY_RGB_LED_COLOR_GREEN | CY_RGB_LED_COLOR_BLUE)
 32-bit encoding for Cyan Color. More...
 
#define CY_RGB_LED_COLOR_OFF   (0x00000000)
 No Color. More...
 
#define CY_RGB_LED_MAX_BRIGHTNESS   (100u)
 Maximum LED Brightness.
 
#define CY_RGB_LED_ACTIVE_HIGH   (true)
 RGB LED active HIGH logic.
 
#define CY_RGB_LED_ACTIVE_LOW   (false)
 RGB LED active LOW logic.
 

Functions

cy_rslt_t cy_rgb_led_init (cyhal_gpio_t pin_red, cyhal_gpio_t pin_green, cyhal_gpio_t pin_blue, bool led_active_logic)
 Initializes RGB LED on the board. More...
 
void cy_rgb_led_deinit (void)
 De-initializes the RGB LED on the board.
 
void cy_rgb_led_on (uint32_t color, uint8_t brightness)
 Turns on RGB LED with specified color and brightness. More...
 
void cy_rgb_led_off (void)
 Turns off the RGB LED on the board.
 
void cy_rgb_led_toggle (void)
 Toggles the RGB LED on the board.
 
void cy_rgb_led_set_color (uint32_t color)
 Sets color of the RGB LED. More...
 
uint32_t cy_rgb_led_get_color (void)
 Returns the current color of the RGB LED. More...
 
static uint32_t cy_rgb_led_create_color (uint8_t red, uint8_t green, uint8_t blue)
 Create a custom color code for the RGB LED. More...
 
void cy_rgb_led_set_brightness (uint8_t brightness)
 Sets brightness of the RGB LED. More...
 
uint8_t cy_rgb_led_get_brightness (void)
 Returns the current brightness of the RGB LED. More...
 

Macro Definition Documentation

◆ CY_RGB_LED_COLOR_RED

#define CY_RGB_LED_COLOR_RED   (0xFF << CY_RGB_LED_RED_POS)

32-bit encoding for Red Color

Note: LED Color is encoded as 0x00RRGGBB where RR - byte field for Red color GG - byte field for Green color BB - byte field for Blue color

Each byte represents 256 (0x00 to 0xFF) different brightness level for each LED color (Red, Green, Blue). Colors can be generated varying these byte fields.

For example: 0x00FFFFFF (RR = 0xFF; GG = 0xFF BB = 0xFF) produces white color.
0x00FFFF00 (RR = 0xFF; GG = 0xFF BB = 0x00) produces yellow color.

◆ CY_RGB_LED_COLOR_GREEN

#define CY_RGB_LED_COLOR_GREEN   (0xFF << CY_RGB_LED_GREEN_POS)

32-bit encoding for Green Color.

Refer to CY_RGB_LED_COLOR_RED for color encoding scheme

◆ CY_RGB_LED_COLOR_BLUE

#define CY_RGB_LED_COLOR_BLUE   (0xFF << CY_RGB_LED_BLUE_POS)

32-bit encoding for Blue Color.

Refer to CY_RGB_LED_COLOR_RED for color encoding scheme

◆ CY_RGB_LED_COLOR_WHITE

#define CY_RGB_LED_COLOR_WHITE
Value:
CY_RGB_LED_COLOR_BLUE)
#define CY_RGB_LED_COLOR_RED
32-bit encoding for Red Color
Definition: cy_rgb_led.h:81
#define CY_RGB_LED_COLOR_GREEN
32-bit encoding for Green Color.
Definition: cy_rgb_led.h:83

32-bit encoding for White Color.

Refer to CY_RGB_LED_COLOR_RED for color encoding scheme

◆ CY_RGB_LED_COLOR_YELLOW

#define CY_RGB_LED_COLOR_YELLOW   (CY_RGB_LED_COLOR_RED | CY_RGB_LED_COLOR_GREEN)

32-bit encoding for Yellow Color.

Refer to CY_RGB_LED_COLOR_RED for color encoding scheme

◆ CY_RGB_LED_COLOR_MAGENTA

#define CY_RGB_LED_COLOR_MAGENTA   (CY_RGB_LED_COLOR_RED | CY_RGB_LED_COLOR_BLUE)

32-bit encoding for Magenta Color.

Refer to CY_RGB_LED_COLOR_RED for color encoding scheme

◆ CY_RGB_LED_COLOR_PURPLE

#define CY_RGB_LED_COLOR_PURPLE   (CY_RGB_LED_COLOR_MAGENTA)

Deprecated.

Use CY_RGB_LED_COLOR_MAGENTA instead

◆ CY_RGB_LED_COLOR_CYAN

#define CY_RGB_LED_COLOR_CYAN   (CY_RGB_LED_COLOR_GREEN | CY_RGB_LED_COLOR_BLUE)

32-bit encoding for Cyan Color.

Refer to CY_RGB_LED_COLOR_RED for color encoding scheme

◆ CY_RGB_LED_COLOR_OFF

#define CY_RGB_LED_COLOR_OFF   (0x00000000)

No Color.

Refer to CY_RGB_LED_COLOR_RED for color encoding scheme

Function Documentation

◆ cy_rgb_led_init()

cy_rslt_t cy_rgb_led_init ( cyhal_gpio_t  pin_red,
cyhal_gpio_t  pin_green,
cyhal_gpio_t  pin_blue,
bool  led_active_logic 
)

Initializes RGB LED on the board.

Parameters
pin_redGPIO for Red component.
pin_greenGPIO for Green component.
pin_blueGPIO for Blue component.
led_active_logicActive logic (low or high) for the RGB LED, all three LEDs must be connected in same active logic.
Returns
CY_RSLT_SUCCESS if the initialization was successful, an error code otherwise.

◆ cy_rgb_led_on()

void cy_rgb_led_on ( uint32_t  color,
uint8_t  brightness 
)

Turns on RGB LED with specified color and brightness.

Parameters
colorLED color
brightnessBrightness of the LED (Valid range: 0 to CY_RGB_LED_MAX_BRIGHTNESS).

◆ cy_rgb_led_set_color()

void cy_rgb_led_set_color ( uint32_t  color)

Sets color of the RGB LED.

Parameters
colorLED color

◆ cy_rgb_led_get_color()

uint32_t cy_rgb_led_get_color ( void  )

Returns the current color of the RGB LED.

Returns
4-byte encoded color.

◆ cy_rgb_led_create_color()

static uint32_t cy_rgb_led_create_color ( uint8_t  red,
uint8_t  green,
uint8_t  blue 
)
inlinestatic

Create a custom color code for the RGB LED.

Parameters
red1-byte value for Red component.
green1-byte value for Green component.
blue1-byte value for Blue component.
Returns
32-bit encoded color code.

◆ cy_rgb_led_set_brightness()

void cy_rgb_led_set_brightness ( uint8_t  brightness)

Sets brightness of the RGB LED.

Parameters
brightnessLED brightness (Valid range: 0 to CY_RGB_LED_MAX_BRIGHTNESS)

◆ cy_rgb_led_get_brightness()

uint8_t cy_rgb_led_get_brightness ( void  )

Returns the current brightness of the RGB LED.

Returns
uint8_t LED brightness.