@web-font-path: "roboto-debian.css";
Loading...
Searching...
No Matches
status_led.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
16
17#ifndef _PICO_STATUS_LED_H
18#define _PICO_STATUS_LED_H
19
20#include "hardware/gpio.h"
21
22#if defined(CYW43_WL_GPIO_LED_PIN)
23#include "cyw43.h"
24#endif
25
26struct async_context;
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32// 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
33#ifndef PICO_STATUS_LED_AVAILABLE
34#if defined(PICO_DEFAULT_LED_PIN) || defined(CYW43_WL_GPIO_LED_PIN)
35#define PICO_STATUS_LED_AVAILABLE 1
36#else
37#define PICO_STATUS_LED_AVAILABLE 0
38#endif
39#endif
40
41// 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
42#ifndef PICO_COLORED_STATUS_LED_AVAILABLE
43#ifdef PICO_DEFAULT_WS2812_PIN
44#define PICO_COLORED_STATUS_LED_AVAILABLE 1
45#else
46#define PICO_COLORED_STATUS_LED_AVAILABLE 0
47#endif
48#endif
49
50// 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
51#ifndef PICO_STATUS_LED_VIA_COLORED_STATUS_LED
52#define PICO_STATUS_LED_VIA_COLORED_STATUS_LED (PICO_COLORED_STATUS_LED_AVAILABLE && !PICO_STATUS_LED_AVAILABLE)
53#endif
54
55// PICO_CONFIG: PICO_COLORED_STATUS_LED_USES_WRGB, Indicate if the colored status LED supports WRGB, type=bool, default=0, group=pico_status_led
56#ifndef PICO_COLORED_STATUS_LED_USES_WRGB
57#define PICO_COLORED_STATUS_LED_USES_WRGB 0
58#endif
59
63#ifndef PICO_COLORED_STATUS_LED_COLOR_FROM_RGB
64#define PICO_COLORED_STATUS_LED_COLOR_FROM_RGB(r, g, b) (((r) << 16) | ((g) << 8) | (b))
65#endif
66
72#ifndef PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB
73#define PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB(w, r, g, b) (((w) << 24) | ((r) << 16) | ((g) << 8) | (b))
74#endif
75
76// 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
77#ifndef PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR
78#if PICO_COLORED_STATUS_LED_USES_WRGB
79#define PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR PICO_COLORED_STATUS_LED_COLOR_FROM_WRGB(0xaa, 0, 0, 0)
80#else
81#define PICO_DEFAULT_COLORED_STATUS_LED_ON_COLOR PICO_COLORED_STATUS_LED_COLOR_FROM_RGB(0xaa, 0xaa, 0xaa)
82#endif
83#endif
84
101bool status_led_init(void);
102
114bool status_led_init_with_context(struct async_context *context);
115
122static inline bool colored_status_led_supported(void) {
123 return PICO_COLORED_STATUS_LED_AVAILABLE;
124}
125
131static inline bool status_led_via_colored_status_led(void) {
132 return PICO_STATUS_LED_VIA_COLORED_STATUS_LED;
133}
134
143static inline bool status_led_supported(void) {
146 }
147 return PICO_STATUS_LED_AVAILABLE;
148}
149
158bool colored_status_led_set_state(bool led_on);
159
168
177bool colored_status_led_set_on_with_color(uint32_t color);
178
187
196static inline bool status_led_set_state(bool led_on) {
198 return colored_status_led_set_state(led_on);
199 } else if (status_led_supported()) {
200#if defined(PICO_DEFAULT_LED_PIN)
201 #if PICO_DEFAULT_LED_PIN_INVERTED
202 gpio_put(PICO_DEFAULT_LED_PIN, !led_on);
203 #else
204 gpio_put(PICO_DEFAULT_LED_PIN, led_on);
205 #endif
206 return true;
207#elif defined(CYW43_WL_GPIO_LED_PIN)
208 cyw43_gpio_set(&cyw43_state, CYW43_WL_GPIO_LED_PIN, led_on);
209 return true;
210#endif
211 }
212 return false;
213}
214
222static inline bool status_led_get_state() {
225 } else if (status_led_supported()) {
226#if defined(PICO_DEFAULT_LED_PIN)
227 #if PICO_DEFAULT_LED_PIN_INVERTED
228 return !gpio_get(PICO_DEFAULT_LED_PIN);
229 #else
230 return gpio_get(PICO_DEFAULT_LED_PIN);
231 #endif
232#elif defined CYW43_WL_GPIO_LED_PIN
233 bool value = false;
234 cyw43_gpio_get(&cyw43_state, CYW43_WL_GPIO_LED_PIN, &value);
235 return value;
236#endif
237 }
238 return false;
239}
240
246void status_led_deinit();
247
248#ifdef __cplusplus
249}
250#endif
251
252#endif
static void gpio_put(uint gpio, bool value)
Drive a single GPIO high/low.
Definition gpio.h:1155
static bool gpio_get(uint gpio)
Get state of a single specified GPIO.
Definition gpio.h:869
static bool status_led_set_state(bool led_on)
Set the status LED on or off.
Definition status_led.h:196
bool status_led_init_with_context(struct async_context *context)
Initialise the status LED(s).
Definition status_led.c:150
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
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
static bool status_led_get_state()
Get the state of the status LED.
Definition status_led.h:222
void status_led_deinit()
De-initialize the status LED(s).
Definition status_led.c:155
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
bool colored_status_led_get_state(void)
Get the state of the colored status LED.
Definition status_led.c:94
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
bool colored_status_led_set_state(bool led_on)
Set the colored status LED on or off.
Definition status_led.c:78
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
bool status_led_init(void)
Initialize the status LED(s).
Definition status_led.c:146
Base structure type of all async_contexts. For details about its use, see pico_async_context.
Definition async_context.h:179