rcc 1.0
RCC - RGB LED Color Cube Documentation
|
Implementation of LED control functions using SPI interface. More...
#include "led.h"
Functions | |
void | led_init (void) |
Initialize the LED control interface and hardware. | |
void | led_disable (void) |
Disable the LED hardware interface. | |
void | led_xof (unsigned char value) |
Transmit a specified value repeatedly over SPI to form a data frame. | |
void | led_data (LED_Data data) |
Send an LED data frame with specified color and intensity. | |
LED_Data | led_status_color (LED_Status status, unsigned char intensity) |
Generate a color configuration for an LED based on its status and intensity. | |
void | leds_off (void) |
Turn off all LEDs by sending zero-intensity frames. | |
void | led_color (LED_Position position, LED_Data color) |
Set the colors of specified LEDs based on position flags. | |
void | led_blink (LED_Position position, LED_Data color, LED_Delay delay, unsigned char repeat) |
Blink LEDs on specified positions with given color, delay and repeat count. |
Implementation of LED control functions using SPI interface.
This source file provides functions to initialize and control addressable LEDs, including setting colors, blinking patterns, and turning LEDs on or off. It utilizes the SPI communication peripheral to send LED data frames.
void led_blink | ( | LED_Position | position, |
LED_Data | color, | ||
LED_Delay | delay, | ||
unsigned char | repeat ) |
Blink LEDs on specified positions with given color, delay and repeat count.
position | Bitwise flags indicating LED positions and blinking modes to be used. |
color | The color and intensity to blink on the LEDs. |
delay | Enumeration specifying delay duration between blink states. |
repeat | The number of times to repeat the blink sequence. |
This function controls blinking patterns for LEDs by alternately activating the specified LED positions and their alternating blinking counterparts. It uses the function led_color to set the color, and led_delay to wait between blinking states. The blinking sequence runs for repeat cycles, then turns off all LEDs using leds_off().
void led_color | ( | LED_Position | position, |
LED_Data | color ) |
Set the colors of specified LEDs based on position flags.
position | Bitwise flags indicating which LEDs to color and their blinking modes. |
color | The LED_Data structure specifying color and intensity for the LEDs. |
This function initiates an LED data frame sequence by sending a start-of-frame (SOF) signal. It then iterates over all configured LEDs and determines, based on their position and the position flags, whether to set the LED color to the specified color or turn the LED off.
For odd numbers of LEDs, the middle LED is always turned off. The function supports left and right LED positions as well as alternating blinking flags. The LED data or off frames are sent accordingly. Finally, an end-of-frame (EOF) signal is sent to mark the completion of the LED update.
void led_data | ( | LED_Data | data | ) |
Send an LED data frame with specified color and intensity.
data | LED_Data structure containing intensity and RGB color values. |
This function constructs and transmits a single LED data frame over SPI, combining the LED enable flag with the masked intensity value, followed by the blue, green, and red color components. The intensity value is masked with 0x3F to limit it to valid bits.
The frame format is:
void led_disable | ( | void | ) |
Disable the LED hardware interface.
This function sends multiple sleep commands to all configured LEDs to put them into a low power state. It transmits four repeated LED sleep frames using SPI and then disables the SPI peripheral itself.
This operation is used to safely turn off the LEDs and reduce power consumption when LED functionality is not needed.
void led_init | ( | void | ) |
Initialize the LED control interface and hardware.
This function initializes the SPI peripheral to communicate with the LEDs using most significant bit (MSB) first, with clock polarity and phase set to rising edges. After SPI initialization, it sends a start-of-frame (SOF) signal followed by initializing all configured LEDs with the enable flag and zero color data (LEDs initially off). Finally, it sends an end-of-frame (EOF) signal to mark completion of the initialization sequence. This setup prepares the LEDs for subsequent color and blink control operations by configuring the communication and initial states.
LED_Data led_status_color | ( | LED_Status | status, |
unsigned char | intensity ) |
Generate a color configuration for an LED based on its status and intensity.
status | The LED status indicating the system state (e.g., ready, warning, error). |
intensity | The brightness intensity level for the LED (0-255). |
This function initializes an LED_Data
structure with the provided intensity and default black color (all zero). It then assigns color values based on the status:
This mapping follows common LED indicator color conventions to visually represent different states.
void led_xof | ( | unsigned char | value | ) |
Transmit a specified value repeatedly over SPI to form a data frame.
value | The byte value to be sent repeatedly. |
This function sends the given value repeatedly for LED_FRAME_SIZE times via SPI using the spi_transfer function. It is commonly used to send start or stop frames for LED data sequences to synchronize communication with the LED hardware.
void leds_off | ( | void | ) |
Turn off all LEDs by sending zero-intensity frames.
This function sends a start-of-frame signal followed by zero-intensity data frames to all configured LEDs, effectively turning them off. It concludes by sending an end-of-frame signal. This ensures all LEDs are turned off cleanly by resetting their color and intensity data.