Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for generic 4pin RGB LEDs (both CC and CA) and NeoPixels, also RGB LED and vibration notification support for unPhone #3647

Merged
merged 33 commits into from
Apr 23, 2024

Conversation

garethhcoleman
Copy link
Contributor

@garethhcoleman garethhcoleman commented Apr 16, 2024

This PR introduces support for generic 4 wire RGB leds both Common Cathode and Common Anode types. Support is also provided for NeoPixels. Also RGB and vibration functions in Meshtastic to the unPhone.

Ambient lighting and external notifications are supported.

All the code is macro guarded (#ifdef etc) so should have no impact on firmware size for others etc.

To maximise code-reuse I removed #ifdef guards around the NCP5623 in DeviceType - hope that seems fitting let me know if not. Edit - now reversed! Edit - double reversed, as in reinstated!

Also, perhaps controversially, I put the RGBLED_CA (common anode) in as a DeviceType despite it flagrantly not being an I2C device at all! again just because it made the code a bit simpler elsewhere. Edit - also reversed!

Let me know if I've broken a good rule and I'll rework it accordinly.

By request I went through variants and tried to implement RGB led functions where these had been half completed.

@garethhcoleman
Copy link
Contributor Author

Oh forgot to say, if there is an easy way to make this code more usable by other folks outside of the unPhone let me know

@garethhcoleman garethhcoleman changed the title RGB LED support for unPhone RGB LED and Vibration notification support for unPhone Apr 18, 2024
@thebentern
Copy link
Contributor

I'd like to keep the I2C device types true to it's name. If we could just use macros to gate the behavior, that would ideal.

Even better would be to create a generic HAS_RGB macro that could be controlled for any target with an RGB led on pre-defined gpio in the variant. It looks like you have some of that behavior abstracted in the unphone library though, so we would need to pull some of that into Meshtastic to be shared with other consuming variants.

@garethhcoleman
Copy link
Contributor Author

The wrinkle with the unphone is that two of the RGB led pins are on the i2c io expander, so we can't just use digitalwrite...

I'll rework it to not use an i2c device type, and implement support for RGB LEDs separately from unphone support - I cant imagine many other boards are going to use our strategy!

#ifdefs all the way!! 😁

@thebentern
Copy link
Contributor

The wrinkle with the unphone is that two of the RGB led pins are on the i2c io expander, so we can't just use digitalwrite...

Oooooh! That makes more sense :-)

@garethhcoleman
Copy link
Contributor Author

OK so good news is that it was fairly trivial to add support for RGB led's in the code...
Bad news is I don't have my stash of electronics with me right now and so I can't actually test it.

So please mark this as draft until we can get a real world confirmation, I mean it looks kinda right to me and I tried to make sure I didn't miss anything but, there's no test like a real test...

Usage would be something like this in variant.h:

// RGB LED configuration
#define RGBLED_RED 13 // GPIO pin connected to the red pin of the RGB LED
#define RGBLED_GREEN 14 // GPIO pin connected to the green pin of the RGB LED
#define RGBLED_BLUE 15 // GPIO pin connected to the blue pin of the RGB LED
#define RGBLED_CA // comment out this line if you have a common cathode type, as defined use common anode logic

…'t find it after a few minutes of searching stack overflow
@garethhcoleman garethhcoleman changed the title RGB LED and Vibration notification support for unPhone Generic support for RGB LEDs (both CC and CA), also RGB LED and vibration notification support for unPhone Apr 18, 2024
@garethhcoleman
Copy link
Contributor Author

Hmm that's odd, it compiles in the heltec-wireless-paper environment for me... Is this comment enough to restart the CI checks?

@thebentern thebentern requested a review from caveman99 April 21, 2024 19:45
@garethhcoleman
Copy link
Contributor Author

garethhcoleman commented Apr 22, 2024

Ok I've finally been able to test and generic 4 pin LEDs seem to work as expected.
IMG_20240422_011828
Ready for review (@caveman99 thank you in advance) and potential merging now.

@garethhcoleman
Copy link
Contributor Author

garethhcoleman commented Apr 22, 2024

I've added support for NeoPixels and tested them very briefly!

Usuage would be like this:

#define HAS_NEOPIXEL                       // Enable the use of neopixels
#define NEOPIXEL_COUNT 1                   // How many neopixels are connected
#define NEOPIXEL_DATA A0                   // gpio pin used to send data to the neopixels
#define NEOPIXEL_TYPE (NEO_GRB+NEO_KHZ800) // type of neopixels in use
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)```

@garethhcoleman garethhcoleman changed the title Generic support for RGB LEDs (both CC and CA), also RGB LED and vibration notification support for unPhone Support for generic 4pin RGB LEDs (both CC and CA) and NeoPixels, also RGB LED and vibration notification support for unPhone Apr 22, 2024
@garethhcoleman
Copy link
Contributor Author

OK so I've gone over various boards that seemed to have RGB leds and incomplete support and tried to get them working with this new approach. I have none of these available to test with.

Boards that should now be supported and just work are:
betafpv_2400_tx_micro
Dongle_nRF52840-pca10059-v1
esp32-s3-pico
lora_relay_v1
lora_relay_v2
my_esp32s3_diy_eink
my_esp32s3_diy_oled

@caveman99 caveman99 merged commit 3302fbc into meshtastic:master Apr 23, 2024
70 checks passed
@garethhcoleman garethhcoleman deleted the RGBLED branch April 23, 2024 19:26
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