Skip to content

Conversation

peterharperuk
Copy link
Contributor

Add a status led library to make adapting to a "normal" led and the cyw43 led a bit easier.
Bonus support for ws2812 leds.

@kilograham
Copy link
Contributor

I think the color setting should be orthogonal to the On/Off and the color method should not mention WS2812 in their name - they should probably (and all the methods really) have a bool which says whether they do anything (so you can still use the library with no LEDs at all)

I'm not quite sure about the color APIs right now - somewhat leaning towards uint32_t so you can read, and allow r,g,b or w,r,g,b methods - maybe make it a #define what WRGB LEDs do when you set r,g,b (either 0 for WRGB or auto set)

@peterharperuk
Copy link
Contributor Author

I think the color setting should be orthogonal

Ah right. I was thinking you'd use the ws2812 as the blinking led. But just having a function to set the ws2812 colour might be better - as most boards seem to have both a simple led and a ws2812 led.

@lurch
Copy link
Contributor

lurch commented Jun 4, 2025

as most boards seem to have both a simple led and a ws2812 led.

There are definitely several boards with only a WS2812 and no normal LED though.

EDIT: Hmmm, so given that this is a "status LED" library and not a "WS2812 library", and we're basically using the ws2812 as though it were a normal LED; perhaps it makes sense to only have the "on" colour configurable, and always have the "off colour" as blank? 🤔 Because otherwise it might not be clear that e.g. "red" is "on" and "turquoise" is "off"! 🌈

@peterharperuk
Copy link
Contributor Author

I'll get rid of the on off thing and just have a method that sets the RGB of a colour status led.

@lurch
Copy link
Contributor

lurch commented Jun 4, 2025

I'll get rid of the on off thing and just have a method that sets the RGB of a colour status led.

IMHO being able to simply turn on/off an RGB LED would mean that a board with an RGB LED (using this status_led library) could be used identically (after a recompile of course) to a board with a normal LED? (e.g. the canonical "status-LED-blink" example)
Perhaps we've just got a different mental-model of what it is that this status_led library is actually for?

@peterharperuk
Copy link
Contributor Author

But most boards are configured with both. Who's to say that you shouldn't be able to control both individually?

@lurch
Copy link
Contributor

lurch commented Jun 4, 2025

But most boards are configured with both. Who's to say that you shouldn't be able to control both individually?

I'm not saying that you shouldn't be able to control both LEDs individually, I guess I was just kinda expecting a status_led library to control only one of them, with the other LED then free for user-purposes. 💡

So, entirely IMVHO:

  • board has a regular LED (i.e. PICO_DEFAULT_LED_PIN or CYW43_WL_GPIO_LED_PIN) but no RGB LED : status_led on/off turns the regular LED on/off
  • board has an RGB LED (i.e. PICO_DEFAULT_WS2812_PIN) but no regular LED : status_led on/off turns the RGB led on/off, with optional control of the "on" colour (defaults to "white")
  • board has both a regular LED and an RGB LED (i.e. PICO_DEFAULT_LED_PIN and PICO_DEFAULT_WS2812_PIN) : status_led on/off turns the regular LED on/off, with the RGB LED then left free for any other purposes
  • board has both a regular LED and an RGB LED and the user sets the PICO_STATUS_LED_USE_WS2812_PIN define (or equivalent) : status_led on/off turns the RGB led on/off, with the regular LED then left free for any other purpose
  • board has lots of regular LEDs and lots of RGB LEDs : user is free to set whatever PICO_CONFIG defines they want, in order to customise which LED the status_led on/off functions will control

That way any example-code that's using the status_led on/off functions will "just work" on any type of board? 🤷

@peterharperuk
Copy link
Contributor Author

Let's keep it simple. If @kilograham disagrees we can change it

@peterharperuk peterharperuk force-pushed the status_led branch 3 times, most recently from fcada13 to 0e0dd15 Compare June 5, 2025 14:35
@kilograham
Copy link
Contributor

kilograham commented Jun 5, 2025

But most boards are configured with both. Who's to say that you shouldn't be able to control both individually?

I'm not saying that you shouldn't be able to control both LEDs individually, I guess I was just kinda expecting a status_led library to control only one of them, with the other LED then free for user-purposes. 💡

So, entirely IMVHO:

* board has a regular LED (i.e. `PICO_DEFAULT_LED_PIN` or `CYW43_WL_GPIO_LED_PIN`) but no RGB LED : `status_led` on/off turns the regular LED on/off

* board has an RGB LED (i.e. `PICO_DEFAULT_WS2812_PIN`) but no regular LED : `status_led` on/off turns the RGB led on/off, with optional control of the "on" colour (defaults to "white")

* board has both a regular LED and an RGB LED (i.e. `PICO_DEFAULT_LED_PIN` and  `PICO_DEFAULT_WS2812_PIN`) : `status_led` on/off turns the regular LED on/off, with the RGB LED then left free for any other purposes

* board has both a regular LED and an RGB LED **and** the user sets the `PICO_STATUS_LED_USE_WS2812_PIN` define (or equivalent) : `status_led` on/off turns the RGB led on/off, with the regular LED then left free for any other purpose

* board has lots of regular LEDs and lots of RGB LEDs : user is free to set whatever `PICO_CONFIG` defines they want, in order to customise which LED the `status_led` on/off functions will control

That way any example-code that's using the status_led on/off functions will "just work" on any type of board? 🤷

This is somewhat similar to what i was expecting.

  1. The ability to blink a LED on any old board. If it has a WS812 or similar, the ability to set the color too (the API can exist but return false)
  2. Possibly in the future, some helpers, like "blink error pattern" (possibly incorporating colors for colored LEDs)
  3. The ability to target these APIs at a particular LED pin or WS2812 pin, or WIFI LED is probably nice too

Sorry, i haven't given a lot of though yet to how i would like this to look

@peterharperuk peterharperuk marked this pull request as ready for review June 5, 2025 17:30
@kilograham
Copy link
Contributor

looking nice - one comment in code

@kilograham kilograham changed the title Status led add pico_status_led Jun 12, 2025
@kilograham kilograham added this to the 2.1.2 milestone Jun 12, 2025
@kilograham
Copy link
Contributor

kilograham commented Jul 15, 2025

looking great; a few comments in the code, but also

I still think
c
the status LED may or may not have a settable color
the status LED may or may not be on/off

i.e. turning on/off a WS2812 LED should set it to the "currently chosen" color for on and zeros for off

@peterharperuk peterharperuk force-pushed the status_led branch 2 times, most recently from 33b3c32 to 0899540 Compare July 18, 2025 13:35
@peterharperuk
Copy link
Contributor Author

Another attempt pushed. Note that I don't have a WS2812 atm, so will test more on Monday.

@peterharperuk
Copy link
Contributor Author

@kilograham Can you tell me if this is closer to what you want before I waste more time on it?

The cyw43-driver enables LwIP if CYW43_LWIP is not defined.
Allow LwIP to be disabled by default if CYW43_LWIP is not defined so we
can use the driver to access the led without needing to link to LwIP.

Add CYW43_LWIP_DEFAULT to enable this.
@peterharperuk peterharperuk force-pushed the status_led branch 2 times, most recently from cbd4e4d to 40417de Compare July 21, 2025 11:26
Functions for turning a binary led on and off and setting value of a
colour status led.

Set/get the colour used if the colored led is ON...

pico_status_led_color_set_on_value
pico_status_led_color_get_on_value

Set the coloured led ON or OFF

pico_status_led_color_set
pico_status_led_color_get

pico_status_led_set and pico_status_led_get call these functions if
PICO_DEFAULT_LED_PIN is not defined or PICO_STATUS_LED_COLOR_ONLY is
true.

PICO_DEFAULT_LED_PIN_INVERTED and PICO_DEFAULT_WS2812_POWER_PIN are
now used.

Fixes raspberrypi#188
@peterharperuk
Copy link
Contributor Author

@kilograham I've tested this again.

kilograham and others added 3 commits July 25, 2025 16:51
Fix some typos and some sentances that didn't scan.
Copy link
Contributor

@kilograham kilograham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice thanks

@kilograham kilograham merged commit 9227cad into raspberrypi:develop Jul 28, 2025
6 checks passed
@kilograham
Copy link
Contributor

fixes #188

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants