Skip to content

Commit 4c0c107

Browse files
committed
WS2812 config for status led
Define PICO_STATUS_LED_ONLY_USING_WS2812 to make pico_status_led_set use the ws2812 color led. This will beforced off if PICO_DEFAULT_WS2812_PIN is not defined. It will default to true only if neither PICO_DEFAULT_LED_PIN or CYW43_WL_GPIO_LED_PIN are defined. PICO_STATUS_LED_WS2812_ON and PICO_STATUS_LED_WS2812_OFF can be used to configure the on and off color led picel values.
1 parent f83483a commit 4c0c107

File tree

1 file changed

+69
-37
lines changed

1 file changed

+69
-37
lines changed

src/rp2_common/pico_status_led/include/pico/status_led.h

Lines changed: 69 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,39 @@ struct async_context;
2828
extern "C" {
2929
#endif
3030

31-
// PICO_CONFIG: PICO_STATUS_LED_WS2812_WRGB, Inidicate if the colored status led supports WRGB, type=bool, default=false group=pico_status_led
31+
// PICO_CONFIG: PICO_STATUS_LED_WS2812_WRGB, Indicate if the colored status led supports WRGB, type=bool, default=false group=pico_status_led
3232
#ifndef PICO_STATUS_LED_WS2812_WRGB
3333
#define PICO_STATUS_LED_WS2812_WRGB 0
3434
#endif
3535

36+
// PICO_CONFIG: PICO_STATUS_LED_ONLY_USING_WS2812, Indicate if only the colored status led should be used. Only true by default if a WS2812 pin is defined and no led pin is defined, type=bool group=pico_status_led
37+
#ifdef PICO_DEFAULT_WS2812_PIN
38+
#ifndef PICO_STATUS_LED_ONLY_USING_WS2812
39+
#define PICO_STATUS_LED_ONLY_USING_WS2812 !(defined PICO_DEFAULT_LED_PIN || defined CYW43_WL_GPIO_LED_PIN)
40+
#endif
41+
#else
42+
#undef PICO_STATUS_LED_ONLY_USING_WS2812
43+
#define PICO_STATUS_LED_ONLY_USING_WS2812 0
44+
#endif
45+
46+
// PICO_CONFIG: PICO_STATUS_LED_WS2812_ON, pixel color value of WS2812 led when status led is on. Only used when PICO_STATUS_LED_ONLY_USING_WS2812 is true , type=int group=pico_status_led
47+
#ifndef PICO_STATUS_LED_WS2812_ON
48+
#if PICO_STATUS_LED_WS2812_WRGB
49+
#define PICO_STATUS_LED_WS2812_ON PICO_STATUS_LED_WRGB(0xaa, 0, 0, 0)
50+
#else
51+
#define PICO_STATUS_LED_WS2812_ON PICO_STATUS_LED_RGB(0xaa, 0xaa, 0xaa)
52+
#endif
53+
#endif
54+
55+
// PICO_CONFIG: PICO_STATUS_LED_WS2812_OFF, pixel color value of WS2812 led when status led is off. Only used when PICO_STATUS_LED_ONLY_USING_WS2812 is true , type=int group=pico_status_led
56+
#ifndef PICO_STATUS_LED_WS2812_OFF
57+
#if PICO_STATUS_LED_WS2812_WRGB
58+
#define PICO_STATUS_LED_WS2812_OFF PICO_STATUS_LED_WRGB(0, 0, 0, 0)
59+
#else
60+
#define PICO_STATUS_LED_WS2812_OFF PICO_STATUS_LED_RGB(0, 0, 0)
61+
#endif
62+
#endif
63+
3664
/*! \brief Initialise the status leds
3765
* \ingroup pico_status_led
3866
*
@@ -44,6 +72,40 @@ extern "C" {
4472
*/
4573
bool pico_status_led_init(struct async_context *context);
4674

75+
/*! \brief Set the colored status led value
76+
* \ingroup pico_status_led
77+
*
78+
* The colored status led defaults to off. Use this function to change its color.
79+
*
80+
* \note: If your hardware does not support a colored status led (\see PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false.
81+
*
82+
* \param value The color of the colored status led in 0xWWRRGGBB format.
83+
* \param True if the coloured status led could be set, otherwise false on failure
84+
*/
85+
bool pico_status_led_color_set(uint32_t value);
86+
87+
/*! \brief Get the colored status led value
88+
* \ingroup pico_status_led
89+
*
90+
* \note: If your hardware does not support a colored status led (\see PICO_DEFAULT_WS2812_PIN), this function always returns 0x0.
91+
*
92+
* \return The color of the colored status led in 0xWWRRGGBB format.
93+
*/
94+
uint32_t pico_status_led_color_get(void);
95+
96+
/*! \brief Generate an RGB colour value for /ref pico_status_led_color_set
97+
* \ingroup pico_status_led
98+
*/
99+
#define PICO_STATUS_LED_RGB(R, G, B) (((R) << 16) | ((G) << 8) | (B))
100+
101+
/*! \brief Generate an WRGB colour value for \ref pico_status_led_color_set
102+
*
103+
* \note: If your hardware does not support a white pixel, the white component is ignored
104+
*
105+
* \ingroup pico_status_led
106+
*/
107+
#define PICO_STATUS_LED_WRGB(W, R, G, B) (((W) << 24) | ((R) << 16) | ((G) << 8) | (B))
108+
47109
/*! \brief Set the status led on or off
48110
* \ingroup pico_status_led
49111
*
@@ -53,7 +115,9 @@ bool pico_status_led_init(struct async_context *context);
53115
* \param True if the status led could be set, otherwise false
54116
*/
55117
static inline bool pico_status_led_set(bool led_on) {
56-
#if defined PICO_DEFAULT_LED_PIN
118+
#if PICO_STATUS_LED_ONLY_USING_WS2812
119+
return pico_status_led_color_set(led_on ? PICO_STATUS_LED_WS2812_ON : PICO_STATUS_LED_WS2812_OFF);
120+
#elif defined PICO_DEFAULT_LED_PIN
57121
gpio_put(PICO_DEFAULT_LED_PIN, led_on);
58122
return true;
59123
#elif defined CYW43_WL_GPIO_LED_PIN
@@ -72,7 +136,9 @@ static inline bool pico_status_led_set(bool led_on) {
72136
* \return True if the led is on, or False if the led is off
73137
*/
74138
static inline bool pico_status_led_get(void) {
75-
#if defined PICO_DEFAULT_LED_PIN
139+
#if PICO_STATUS_LED_ONLY_USING_WS2812
140+
return pico_status_led_color_get() != PICO_STATUS_LED_WS2812_OFF;
141+
#elif defined PICO_DEFAULT_LED_PIN
76142
return gpio_get(PICO_DEFAULT_LED_PIN);
77143
#elif defined CYW43_WL_GPIO_LED_PIN
78144
bool value = false;
@@ -83,40 +149,6 @@ static inline bool pico_status_led_get(void) {
83149
#endif
84150
}
85151

86-
/*! \brief Set the colored status led value
87-
* \ingroup pico_status_led
88-
*
89-
* The colored status led defaults to off. Use this function to change its color.
90-
*
91-
* \note: If your hardware does not support a colored status led (\see PICO_DEFAULT_WS2812_PIN), this function does nothing and returns false.
92-
*
93-
* \param value The color of the colored status led in 0xWWRRGGBB format.
94-
* \param True if the coloured status led could be set, otherwise false on failure
95-
*/
96-
bool pico_status_led_color_set(uint32_t value);
97-
98-
/*! \brief Get the colored status led value
99-
* \ingroup pico_status_led
100-
*
101-
* \note: If your hardware does not support a colored status led (\see PICO_DEFAULT_WS2812_PIN), this function always returns 0x0.
102-
*
103-
* \return The color of the colored status led in 0xWWRRGGBB format.
104-
*/
105-
uint32_t pico_status_led_color_get(void);
106-
107-
/*! \brief Generate an RGB colour value for /ref pico_status_led_color_set
108-
* \ingroup pico_status_led
109-
*/
110-
#define PICO_STATUS_LED_RGB(R, G, B) (((R) << 16) | ((G) << 8) | (B))
111-
112-
/*! \brief Generate an WRGB colour value for \ref pico_status_led_color_set
113-
*
114-
* \note: If your hardware does not support a white pixel, the white component is ignored
115-
*
116-
* \ingroup pico_status_led
117-
*/
118-
#define PICO_STATUS_LED_WRGB(W, R, G, B) (((W) << 24) | ((R) << 16) | ((G) << 8) | (B))
119-
120152
/*! \brief Deinitialise the status leds
121153
* \ingroup pico_status_led
122154
*

0 commit comments

Comments
 (0)