From 09d48f659ebe535c71a17f37ca6e1125496fbd1d Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 6 May 2023 07:17:40 -0500 Subject: [PATCH] RAK14001 RGB LED support (#2464) * WIP * WIP * Moved it * More random strobey behavior * Guard to RAK4630 devices for now * Oops * Ship it --- src/configuration.h | 5 +++ src/detect/ScanI2C.h | 1 + src/detect/ScanI2CTwoWire.cpp | 1 + src/main.cpp | 4 ++ src/main.h | 1 + src/modules/ExternalNotificationModule.cpp | 42 ++++++++++++++++++- variants/rak4631/platformio.ini | 1 + variants/rak4631_epaper/platformio.ini | 1 + variants/rak4631_epaper_onrxtx/platformio.ini | 1 + 9 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/configuration.h b/src/configuration.h index 58e41877..e1420c8d 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -124,6 +124,11 @@ along with this program. If not, see . #define MPU6050_ADDR 0x68 #define LIS3DH_ADR 0x18 +// ----------------------------------------------------------------------------- +// LED +// ----------------------------------------------------------------------------- +#define NCP5623_ADDR 0x38 + // ----------------------------------------------------------------------------- // Security // ----------------------------------------------------------------------------- diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 01b300c1..a56ce86f 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -33,6 +33,7 @@ class ScanI2C PMSA0031, MPU6050, LIS3DH, + NCP5623, } DeviceType; // typedef uint8_t DeviceAddress; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index fb568b55..b7f16734 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -213,6 +213,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port) break; SCAN_SIMPLE_CASE(ST7567_ADDRESS, SCREEN_ST7567, "st7567 display found\n") + SCAN_SIMPLE_CASE(NCP5623_ADDR, NCP5623, "NCP5623 RGB LED found\n"); #ifdef HAS_PMU SCAN_SIMPLE_CASE(XPOWERS_AXP192_AXP2101_ADDRESS, PMU_AXP192_AXP2101, "axp192/axp2101 PMU found\n") diff --git a/src/main.cpp b/src/main.cpp index e42c190d..b1a21e94 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -100,6 +100,8 @@ uint8_t kb_model; ScanI2C::DeviceAddress rtc_found = ScanI2C::ADDRESS_NONE; // The I2C address of the Accelerometer (if found) ScanI2C::DeviceAddress accelerometer_found = ScanI2C::ADDRESS_NONE; +// The I2C address of the RGB LED (if found) +ScanI2C::FoundDevice rgb_found = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ScanI2C::ADDRESS_NONE); #if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) ATECCX08A atecc; @@ -344,6 +346,8 @@ void setup() * nodeTelemetrySensorsMap singleton. This wraps that logic in a temporary scope to declare the temporary field * "found". */ + // Only one supported RGB LED currently + rgb_found = i2cScanner->find(ScanI2C::DeviceType::NCP5623); #if !defined(ARCH_PORTDUINO) auto acc_info = i2cScanner->firstAccelerometer(); diff --git a/src/main.h b/src/main.h index 645ba2ee..5707e3bc 100644 --- a/src/main.h +++ b/src/main.h @@ -26,6 +26,7 @@ extern ScanI2C::DeviceAddress cardkb_found; extern uint8_t kb_model; extern ScanI2C::DeviceAddress rtc_found; extern ScanI2C::DeviceAddress accelerometer_found; +extern ScanI2C::FoundDevice rgb_found; extern bool eink_found; extern bool pmu_found; diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index 3c931f3e..7dbf78a0 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -8,6 +8,17 @@ #include "mesh/generated/meshtastic/rtttl.pb.h" #include +#include "main.h" + +#ifdef RAK4630 +#include +NCP5623 rgb; + +uint8_t red = 0; +uint8_t green = 0; +uint8_t blue = 0; +#endif + #ifndef PIN_BUZZER #define PIN_BUZZER false #endif @@ -73,6 +84,15 @@ int32_t ExternalNotificationModule::runOnce() millis()) { getExternal(2) ? setExternalOff(2) : setExternalOn(2); } +#ifdef RAK4630 + if (rgb_found.type == ScanI2C::NCP5623) { + green = (green + 50) % 255; + red = abs(red - green) % 255; + blue = abs(blue / red) % 255; + + rgb.setColor(red, green, blue); + } +#endif } // now let the PWM buzzer play @@ -84,6 +104,7 @@ int32_t ExternalNotificationModule::runOnce() rtttl::begin(config.device.buzzer_gpio, rtttlConfig.ringtone); } } + return 25; } } @@ -106,6 +127,11 @@ void ExternalNotificationModule::setExternalOn(uint8_t index) digitalWrite(output, (moduleConfig.external_notification.active ? true : false)); break; } +#ifdef RAK4630 + if (rgb_found.type == ScanI2C::NCP5623) { + rgb.setColor(red, green, blue); + } +#endif } void ExternalNotificationModule::setExternalOff(uint8_t index) @@ -126,6 +152,15 @@ void ExternalNotificationModule::setExternalOff(uint8_t index) digitalWrite(output, (moduleConfig.external_notification.active ? false : true)); break; } + +#ifdef RAK4630 + if (rgb_found.type == ScanI2C::NCP5623) { + red = 0; + green = 0; + blue = 0; + rgb.setColor(red, green, blue); + } +#endif } bool ExternalNotificationModule::getExternal(uint8_t index) @@ -200,6 +235,12 @@ ExternalNotificationModule::ExternalNotificationModule() LOG_INFO("Using Pin %i in PWM mode\n", config.device.buzzer_gpio); } } +#ifdef RAK4630 + if (rgb_found.type == ScanI2C::NCP5623) { + rgb.begin(); + rgb.setCurrent(10); + } +#endif } else { LOG_INFO("External Notification Module Disabled\n"); disable(); @@ -300,7 +341,6 @@ ProcessMessage ExternalNotificationModule::handleReceived(const meshtastic_MeshP nagCycleCutoff = millis() + moduleConfig.external_notification.output_ms; } } - setIntervalFromNow(0); // run once so we know if we should do something } diff --git a/variants/rak4631/platformio.ini b/variants/rak4631/platformio.ini index a0928605..0d1f17d9 100644 --- a/variants/rak4631/platformio.ini +++ b/variants/rak4631/platformio.ini @@ -9,6 +9,7 @@ lib_deps = ${networking_base.lib_deps} melopero/Melopero RV3028@^1.1.0 https://github.com/RAKWireless/RAK13800-W5100S.git#1.0.2 + rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink \ No newline at end of file diff --git a/variants/rak4631_epaper/platformio.ini b/variants/rak4631_epaper/platformio.ini index fd266c07..e9c3e872 100644 --- a/variants/rak4631_epaper/platformio.ini +++ b/variants/rak4631_epaper/platformio.ini @@ -8,6 +8,7 @@ lib_deps = ${nrf52840_base.lib_deps} zinggjm/GxEPD2@^1.4.9 melopero/Melopero RV3028@^1.1.0 + rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink \ No newline at end of file diff --git a/variants/rak4631_epaper_onrxtx/platformio.ini b/variants/rak4631_epaper_onrxtx/platformio.ini index 92038001..6e922b84 100644 --- a/variants/rak4631_epaper_onrxtx/platformio.ini +++ b/variants/rak4631_epaper_onrxtx/platformio.ini @@ -10,6 +10,7 @@ lib_deps = ${nrf52840_base.lib_deps} zinggjm/GxEPD2@^1.5.1 melopero/Melopero RV3028@^1.1.0 + rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2 debug_tool = jlink ; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) ;upload_protocol = jlink