LED

provide a simple interface to control the RGB LED on the board.

Configuration

LED_CHANNEL_*

defines the bitmasks for each color channel

#define LED_CHANNEL_RED (0b100)
#define LED_CHANNEL_GREEN (0b010)
#define LED_CHANNEL_BLUE (0b001)

Public Types

led_color_t,

provides a list of colors that the LED can be set to encodes the color as a 3-bit value, with each bit representing a different color channel

typedef enum led_color_t
{
    LED_COLOR_RED = 0b011,
    LED_COLOR_GREEN = 0b101,
    LED_COLOR_BLUE = 0b110,
    LED_COLOR_YELLOW = 0b001,
    LED_COLOR_PURPLE = 0b010,
    LED_COLOR_TEAL = 0b100,
    LED_COLOR_WHITE = 0b000,
    LED_COLOR_BLACK = 0b111,
} led_color_t;

Public Functions

led_init

initializes the LED module, set up GPIO pins for the LED, and makes it GREEN by default

void led_init(void)
{
    gpio_pad_select_gpio(GREEN_LED);
    gpio_pad_select_gpio(BLUE_LED);
    gpio_pad_select_gpio(RED_LED);

    gpio_set_direction(GREEN_LED, GPIO_MODE_OUTPUT);
    gpio_set_direction(BLUE_LED, GPIO_MODE_OUTPUT);
    gpio_set_direction(RED_LED, GPIO_MODE_OUTPUT);

    led_set_color(LED_COLOR_GREEN);
}

led_set_color

sets the color of the LED to the specified color

void led_set_color(led_color_t color)
{
    bool r_channel = color & LED_CHANNEL_RED;
    bool g_channel = color & LED_CHANNEL_GREEN;
    bool b_channel = color & LED_CHANNEL_BLUE;

    gpio_set_level(RED_LED, r_channel);
    gpio_set_level(GREEN_LED, g_channel);
    gpio_set_level(BLUE_LED, b_channel);
}