@web-font-path: "roboto-debian.css";
v2.2.0 (RP2040)
Loading...
Searching...
No Matches
status_led.h
Go to the documentation of this file.
/*
* Copyright (c) 2025 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _PICO_STATUS_LED_H
#define _PICO_STATUS_LED_H
#include "hardware/gpio.h"
#if defined(CYW43_WL_GPIO_LED_PIN)
#include "cyw43.h"
#endif
struct async_context;
#ifdef __cplusplus
extern "C" {
#endif
// PICO_CONFIG: PICO_STATUS_LED_AVAILABLE, Indicate whether a single-color status LED is available, type=bool, default=1 if PICO_DEFAULT_LED_PIN or CYW43_WL_GPIO_LED_PIN is defined; may be set by the user to 0 to not use either even if they are available, group=pico_status_led
#ifndef PICO_STATUS_LED_AVAILABLE
#if defined(PICO_DEFAULT_LED_PIN) || defined(CYW43_WL_GPIO_LED_PIN)
#define PICO_STATUS_LED_AVAILABLE 1
#else
#define PICO_STATUS_LED_AVAILABLE 0
#endif
#endif
// PICO_CONFIG: PICO_COLORED_STATUS_LED_AVAILABLE, Indicate whether a colored status LED is available, type=bool, default=1 if PICO_DEFAULT_WS2812_PIN is defined; may be set by the user to 0 to not use the colored status LED even if available, group=pico_status_led
#ifndef PICO_COLORED_STATUS_LED_AVAILABLE
#ifdef PICO_DEFAULT_WS2812_PIN
#define PICO_COLORED_STATUS_LED_AVAILABLE 1
#else
#define PICO_COLORED_STATUS_LED_AVAILABLE 0
#endif
#endif
// PICO_CONFIG: PICO_STATUS_LED_VIA_COLORED_STATUS_LED, Indicate if the colored status LED should be used for both status_led and colored_status_led APIs, type=bool, default=1 if PICO_COLORED_STATUS_LED_AVAILABLE is 1 and PICO_STATUS_LED_AVAILABLE is 0, group=pico_status_led
#ifndef PICO_STATUS_LED_VIA_COLORED_STATUS_LED
#define PICO_STATUS_LED_VIA_COLORED_STATUS_LED (PICO_COLORED_STATUS_LED_AVAILABLE && !PICO_STATUS_LED_AVAILABLE)
#endif
// PICO_CONFIG: PICO_COLORED_STATUS_LED_USES_WRGB, Indicate if the colored status LED supports WRGB, type=bool, default=0, group=pico_status_led
#ifndef PICO_COLORED_STATUS_LED_USES_WRGB
#define PICO_COLORED_STATUS_LED_USES_WRGB 0
#endif
#ifndef PICO_COLORED_STATUS_LED_COLOR_FROM_RGB
#define PICO_COLORED_STATUS_LED_COLOR_FROM_RGB(r, g, b) (((r) << 16) | ((g) << 8) | (b))
#endif
#ifndef PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB
#define PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB(w, r, g, b) (((w) << 24) | ((r) << 16) | ((g) << 8) | (b))
#endif
// PICO_CONFIG: PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR, the default pixel color value of the colored status LED when it is on, type=int, group=pico_status_led
#ifndef PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR
#if PICO_COLORED_STATUS_LED_USES_WRGB
#define PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB(0xaa, 0, 0, 0)
#else
#define PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR PICO_COLORED_STATUS_LED_COLOR_FROM_RGB(0xaa, 0xaa, 0xaa)
#endif
#endif
bool status_led_init(void);
bool status_led_init_with_context(struct async_context *context);
static inline bool colored_status_led_supported(void) {
return PICO_COLORED_STATUS_LED_AVAILABLE;
}
static inline bool status_led_via_colored_status_led(void) {
return PICO_STATUS_LED_VIA_COLORED_STATUS_LED;
}
static inline bool status_led_supported(void) {
if (status_led_via_colored_status_led()) {
return colored_status_led_supported();
}
return PICO_STATUS_LED_AVAILABLE;
}
bool colored_status_led_set_state(bool led_on);
bool colored_status_led_get_state(void);
bool colored_status_led_set_on_with_color(uint32_t color);
uint32_t colored_status_led_get_on_color(void);
static inline bool status_led_set_state(bool led_on) {
if (status_led_via_colored_status_led()) {
return colored_status_led_set_state(led_on);
} else if (status_led_supported()) {
#if defined(PICO_DEFAULT_LED_PIN)
#if PICO_DEFAULT_LED_PIN_INVERTED
gpio_put(PICO_DEFAULT_LED_PIN, !led_on);
#else
gpio_put(PICO_DEFAULT_LED_PIN, led_on);
#endif
return true;
#elif defined(CYW43_WL_GPIO_LED_PIN)
cyw43_gpio_set(&cyw43_state, CYW43_WL_GPIO_LED_PIN, led_on);
return true;
#endif
}
return false;
}
static inline bool status_led_get_state() {
if (status_led_via_colored_status_led()) {
return colored_status_led_get_state();
} else if (status_led_supported()) {
#if defined(PICO_DEFAULT_LED_PIN)
#if PICO_DEFAULT_LED_PIN_INVERTED
return !gpio_get(PICO_DEFAULT_LED_PIN);
#else
return gpio_get(PICO_DEFAULT_LED_PIN);
#endif
#elif defined CYW43_WL_GPIO_LED_PIN
bool value = false;
cyw43_gpio_get(&cyw43_state, CYW43_WL_GPIO_LED_PIN, &value);
return value;
#endif
}
return false;
}
void status_led_deinit();
#ifdef __cplusplus
}
#endif
#endif
gpio.h
gpio_put
static void gpio_put(uint gpio, bool value)
Drive a single GPIO high/low.
Definition gpio.h:1155
gpio_get
static bool gpio_get(uint gpio)
Get state of a single specified GPIO.
Definition gpio.h:869
status_led_set_state
static bool status_led_set_state(bool led_on)
Set the status LED on or off.
Definition status_led.h:196
status_led_init_with_context
bool status_led_init_with_context(struct async_context *context)
Initialise the status LED(s).
Definition status_led.c:150
status_led_supported
static bool status_led_supported(void)
Determine if the single-color status_led_ APIs are supported (i.e. if there is a regular LED,...
Definition status_led.h:143
colored_status_led_set_on_with_color
bool colored_status_led_set_on_with_color(uint32_t color)
Ensure the colored status LED is on, with the specified color.
Definition status_led.c:69
status_led_get_state
static bool status_led_get_state()
Get the state of the status LED.
Definition status_led.h:222
status_led_deinit
void status_led_deinit()
De-initialize the status LED(s).
Definition status_led.c:155
status_led_via_colored_status_led
static bool status_led_via_colored_status_led(void)
Determine if the colored status LED is being used for the single-color status_led_ APIs.
Definition status_led.h:131
colored_status_led_get_state
bool colored_status_led_get_state(void)
Get the state of the colored status LED.
Definition status_led.c:94
colored_status_led_get_on_color
uint32_t colored_status_led_get_on_color(void)
Get the color used for the status LED value when it is on.
Definition status_led.c:74
colored_status_led_set_state
bool colored_status_led_set_state(bool led_on)
Set the colored status LED on or off.
Definition status_led.c:78
colored_status_led_supported
static bool colored_status_led_supported(void)
Determine if the colored_status_led_ APIs are supported (i.e. if there is a colored status LED,...
Definition status_led.h:122
status_led_init
bool status_led_init(void)
Initialize the status LED(s).
Definition status_led.c:146
async_context
Base structure type of all async_contexts. For details about its use, see pico_async_context.
Definition async_context.h:179