diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 4c570c856..aeb0a1b43 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,6 +1,6 @@ version: 0.1 cli: - version: 1.22.11 + version: 1.22.12 plugins: sources: - id: trunk @@ -12,7 +12,7 @@ lint: - trufflehog@3.88.20 - yamllint@1.37.0 - bandit@1.8.3 - - checkov@3.2.394 + - checkov@3.2.396 - terrascan@1.19.9 - trivy@0.61.0 - taplo@0.9.3 @@ -22,7 +22,7 @@ lint: - oxipng@9.1.4 - svgo@3.3.2 - actionlint@1.7.7 - - flake8@7.1.2 + - flake8@7.2.0 - hadolint@2.12.1-beta - shfmt@3.6.0 - shellcheck@0.10.0 diff --git a/bin/config-dist.yaml b/bin/config-dist.yaml index 722f80fae..9238d0e56 100644 --- a/bin/config-dist.yaml +++ b/bin/config-dist.yaml @@ -197,5 +197,6 @@ General: MaxNodes: 200 MaxMessageQueue: 100 ConfigDirectory: /etc/meshtasticd/config.d/ + AvailableDirectory: /etc/meshtasticd/available.d/ # MACAddress: AA:BB:CC:DD:EE:FF -# MACAddressSource: eth0 \ No newline at end of file +# MACAddressSource: eth0 diff --git a/bin/config.d/lora-MeshAdv-900M30S.yaml b/bin/config.d/lora-MeshAdv-900M30S.yaml index 113901d5e..5c148bf68 100644 --- a/bin/config.d/lora-MeshAdv-900M30S.yaml +++ b/bin/config.d/lora-MeshAdv-900M30S.yaml @@ -1,3 +1,5 @@ +# MeshAdv-Pi E22-900M30S +# https://github.com/chrismyers2000/MeshAdv-Pi-Hat Lora: Module: sx1262 CS: 21 @@ -9,4 +11,4 @@ Lora: DIO3_TCXO_VOLTAGE: true # Only for E22-900M33S: # Limit the output power to 8 dBm - # SX126X_MAX_POWER: 8 \ No newline at end of file + # SX126X_MAX_POWER: 8 diff --git a/bin/config.d/lora-MeshAdv-Mini-900M22S.yaml b/bin/config.d/lora-MeshAdv-Mini-900M22S.yaml new file mode 100644 index 000000000..554116b57 --- /dev/null +++ b/bin/config.d/lora-MeshAdv-Mini-900M22S.yaml @@ -0,0 +1,11 @@ +# MeshAdv Mini E22-900M22S +# https://github.com/chrismyers2000/MeshAdv-Mini +Lora: + Module: sx1262 # Ebyte E22-900M22S + CS: 8 + IRQ: 16 + Busy: 20 + Reset: 24 + TXen: 13 + DIO2_AS_RF_SWITCH: true + DIO3_TCXO_VOLTAGE: true diff --git a/boards/heltec_vision_master_e213.json b/boards/heltec_vision_master_e213.json index bf5fe15ad..152515cf3 100644 --- a/boards/heltec_vision_master_e213.json +++ b/boards/heltec_vision_master_e213.json @@ -2,7 +2,8 @@ "build": { "arduino": { "ldscript": "esp32s3_out.ld", - "partitions": "default_8MB.csv" + "partitions": "default_8MB.csv", + "memory_type": "qio_opi" }, "core": "esp32", "extra_flags": [ @@ -15,6 +16,7 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "qio", + "psram_type": "opi", "hwids": [ ["0x303A", "0x1001"], ["0x303A", "0x0002"] diff --git a/boards/heltec_vision_master_e290.json b/boards/heltec_vision_master_e290.json index 70f7d5f02..b7cbac878 100644 --- a/boards/heltec_vision_master_e290.json +++ b/boards/heltec_vision_master_e290.json @@ -2,7 +2,8 @@ "build": { "arduino": { "ldscript": "esp32s3_out.ld", - "partitions": "default_8MB.csv" + "partitions": "default_8MB.csv", + "memory_type": "qio_opi" }, "core": "esp32", "extra_flags": [ @@ -15,6 +16,7 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "qio", + "psram_type": "opi", "hwids": [ ["0x303A", "0x1001"], ["0x303A", "0x0002"] diff --git a/boards/heltec_vision_master_t190.json b/boards/heltec_vision_master_t190.json index 341e70218..440f76ad0 100644 --- a/boards/heltec_vision_master_t190.json +++ b/boards/heltec_vision_master_t190.json @@ -2,7 +2,8 @@ "build": { "arduino": { "ldscript": "esp32s3_out.ld", - "partitions": "default_8MB.csv" + "partitions": "default_8MB.csv", + "memory_type": "qio_opi" }, "core": "esp32", "extra_flags": [ @@ -15,6 +16,7 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "qio", + "psram_type": "opi", "hwids": [ ["0x303A", "0x1001"], ["0x303A", "0x0002"] diff --git a/boards/seeed-sensecap-indicator.json b/boards/seeed-sensecap-indicator.json index 0a02fc882..03bff35b5 100644 --- a/boards/seeed-sensecap-indicator.json +++ b/boards/seeed-sensecap-indicator.json @@ -18,6 +18,7 @@ "f_boot": "120000000L", "boot": "qio", "flash_mode": "qio", + "psram_type": "opi", "hwids": [["0x1A86", "0x7523"]], "mcu": "esp32s3", "variant": "esp32s3" diff --git a/boards/seeed-xiao-s3.json b/boards/seeed-xiao-s3.json index 0b7b432a0..6981085dd 100644 --- a/boards/seeed-xiao-s3.json +++ b/boards/seeed-xiao-s3.json @@ -15,6 +15,7 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "qio", + "psram_type": "opi", "hwids": [["0x2886", "0x0059"]], "mcu": "esp32s3", "variant": "seeed-xiao-s3" diff --git a/boards/t-watch-s3.json b/boards/t-watch-s3.json index 5d4afd322..51bb7cf4b 100644 --- a/boards/t-watch-s3.json +++ b/boards/t-watch-s3.json @@ -16,6 +16,7 @@ "f_cpu": "240000000L", "f_flash": "80000000L", "flash_mode": "qio", + "psram_type": "opi", "hwids": [ ["0x303A", "0x1001"], ["0x303A", "0x0002"] diff --git a/platformio.ini b/platformio.ini index 010aea90f..377635873 100644 --- a/platformio.ini +++ b/platformio.ini @@ -56,7 +56,7 @@ build_flags = -Wno-missing-field-initializers monitor_speed = 115200 monitor_filters = direct lib_deps = - https://github.com/meshtastic/esp8266-oled-ssd1306/archive/e16cee124fe26490cb14880c679321ad8ac89c95.zip + https://github.com/meshtastic/esp8266-oled-ssd1306/archive/0119501e9983bd894830b02f545c377ee08d66fe.zip mathertel/OneButton@2.6.1 https://github.com/meshtastic/arduino-fsm/archive/7db3702bf0cfe97b783d6c72595e3f38e0b19159.zip https://github.com/meshtastic/TinyGPSPlus/archive/71a82db35f3b973440044c476d4bcdc673b104f4.zip diff --git a/protobufs b/protobufs index 484d002a5..13a3e5dce 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 484d002a52bc20fa9f91ebf1b216d585c5f93a1b +Subproject commit 13a3e5dcee25a2d2d4f1fbaba4c091c66d698ca5 diff --git a/src/AmbientLightingThread.h b/src/AmbientLightingThread.h index c487f9d53..bff8846d6 100644 --- a/src/AmbientLightingThread.h +++ b/src/AmbientLightingThread.h @@ -6,6 +6,11 @@ NCP5623 rgb; #endif +#ifdef HAS_LP5562 +#include +LP5562 rgbw; +#endif + #ifdef HAS_NEOPIXEL #include Adafruit_NeoPixel pixels(NEOPIXEL_COUNT, NEOPIXEL_DATA, NEOPIXEL_TYPE); @@ -26,7 +31,7 @@ class AmbientLightingThread : public concurrency::OSThread notifyDeepSleepObserver.observe(¬ifyDeepSleep); // Let us know when shutdown() is issued. // Enables Ambient Lighting by default if conditions are meet. -#if defined(HAS_NCP5623) || defined(RGBLED_RED) || defined(HAS_NEOPIXEL) || defined(UNPHONE) +#ifdef HAS_RGB_LED #ifdef ENABLE_AMBIENTLIGHTING moduleConfig.ambient_lighting.led_state = true; #endif @@ -39,7 +44,7 @@ class AmbientLightingThread : public concurrency::OSThread // moduleConfig.ambient_lighting.green = (myNodeInfo.my_node_num & 0x00FF00) >> 8; // moduleConfig.ambient_lighting.blue = myNodeInfo.my_node_num & 0x0000FF; -#ifdef HAS_NCP5623 +#if defined(HAS_NCP5623) || defined(HAS_LP5562) _type = type; if (_type == ScanI2C::DeviceType::NONE) { LOG_DEBUG("AmbientLighting Disable due to no RGB leds found on I2C bus"); @@ -47,17 +52,21 @@ class AmbientLightingThread : public concurrency::OSThread return; } #endif -#if defined(HAS_NCP5623) || defined(RGBLED_RED) || defined(HAS_NEOPIXEL) || defined(UNPHONE) +#ifdef HAS_RGB_LED if (!moduleConfig.ambient_lighting.led_state) { LOG_DEBUG("AmbientLighting Disable due to moduleConfig.ambient_lighting.led_state OFF"); disable(); return; } LOG_DEBUG("AmbientLighting init"); -#ifdef HAS_NCP5623 +#if defined(HAS_NCP5623) || defined(HAS_LP5562) if (_type == ScanI2C::NCP5623) { rgb.begin(); #endif +#ifdef HAS_LP5562 + } else if (_type == ScanI2C::LP5562) { + rgbw.begin(); +#endif #ifdef RGBLED_RED pinMode(RGBLED_RED, OUTPUT); pinMode(RGBLED_GREEN, OUTPUT); @@ -70,7 +79,7 @@ class AmbientLightingThread : public concurrency::OSThread #endif setLighting(); #endif -#ifdef HAS_NCP5623 +#if defined(HAS_NCP5623) || defined(HAS_LP5562) } #endif } @@ -78,13 +87,13 @@ class AmbientLightingThread : public concurrency::OSThread protected: int32_t runOnce() override { -#if defined(HAS_NCP5623) || defined(RGBLED_RED) || defined(HAS_NEOPIXEL) || defined(UNPHONE) -#ifdef HAS_NCP5623 - if (_type == ScanI2C::NCP5623 && moduleConfig.ambient_lighting.led_state) { +#ifdef HAS_RGB_LED +#if defined(HAS_NCP5623) || defined(HAS_LP5562) + if ((_type == ScanI2C::NCP5623 || _type == ScanI2C::LP5562) && moduleConfig.ambient_lighting.led_state) { #endif setLighting(); return 30000; // 30 seconds to reset from any animations that may have been running from Ext. Notification -#ifdef HAS_NCP5623 +#if defined(HAS_NCP5623) || defined(HAS_LP5562) } #endif #endif @@ -108,6 +117,14 @@ class AmbientLightingThread : public concurrency::OSThread rgb.setBlue(0); LOG_INFO("OFF: NCP5623 Ambient lighting"); #endif +#ifdef HAS_LP5562 + rgbw.setCurrent(0); + rgbw.setRed(0); + rgbw.setGreen(0); + rgbw.setBlue(0); + rgbw.setWhite(0); + LOG_INFO("OFF: LP5562 Ambient lighting"); +#endif #ifdef HAS_NEOPIXEL pixels.clear(); pixels.show(); @@ -141,6 +158,14 @@ class AmbientLightingThread : public concurrency::OSThread LOG_DEBUG("Init NCP5623 Ambient light w/ current=%d, red=%d, green=%d, blue=%d", moduleConfig.ambient_lighting.current, moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green, moduleConfig.ambient_lighting.blue); #endif +#ifdef HAS_LP5562 + rgbw.setCurrent(moduleConfig.ambient_lighting.current); + rgbw.setRed(moduleConfig.ambient_lighting.red); + rgbw.setGreen(moduleConfig.ambient_lighting.green); + rgbw.setBlue(moduleConfig.ambient_lighting.blue); + LOG_DEBUG("Init LP5562 Ambient light w/ current=%d, red=%d, green=%d, blue=%d", moduleConfig.ambient_lighting.current, + moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green, moduleConfig.ambient_lighting.blue); +#endif #ifdef HAS_NEOPIXEL pixels.fill(pixels.Color(moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green, moduleConfig.ambient_lighting.blue), diff --git a/src/DisplayFormatters.cpp b/src/DisplayFormatters.cpp index 0718ffcbd..44bc0897b 100644 --- a/src/DisplayFormatters.cpp +++ b/src/DisplayFormatters.cpp @@ -27,9 +27,6 @@ const char *DisplayFormatters::getModemPresetDisplayName(meshtastic_Config_LoRaC case meshtastic_Config_LoRaConfig_ModemPreset_LONG_MODERATE: return useShortName ? "LongM" : "LongMod"; break; - case meshtastic_Config_LoRaConfig_ModemPreset_VERY_LONG_SLOW: - return useShortName ? "VeryL" : "VLongSlow"; - break; default: return useShortName ? "Custom" : "Invalid"; break; diff --git a/src/configuration.h b/src/configuration.h index fd4a5b196..d319ddb0a 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -152,6 +152,7 @@ along with this program. If not, see . #define MLX90614_ADDR_DEF 0x5A #define CGRADSENS_ADDR 0x66 #define LTR390UV_ADDR 0x53 +#define XPOWERS_AXP192_AXP2101_ADDRESS 0x34 // same adress as TCA8418 // ----------------------------------------------------------------------------- // ACCELEROMETER @@ -170,6 +171,7 @@ along with this program. If not, see . // LED // ----------------------------------------------------------------------------- #define NCP5623_ADDR 0x38 +#define LP5562_ADDR 0x30 // ----------------------------------------------------------------------------- // Security @@ -295,6 +297,11 @@ along with this program. If not, see . #error HW_VENDOR must be defined #endif +// Support multiple RGB LED configuration +#if defined(HAS_NCP5623) || defined(HAS_LP5562) || defined(RGBLED_RED) || defined(HAS_NEOPIXEL) || defined(UNPHONE) +#define HAS_RGB_LED +#endif + // ----------------------------------------------------------------------------- // Global switches to turn off features for a minimized build // ----------------------------------------------------------------------------- diff --git a/src/detect/ScanI2C.cpp b/src/detect/ScanI2C.cpp index 4caa0f730..5bd5c0d12 100644 --- a/src/detect/ScanI2C.cpp +++ b/src/detect/ScanI2C.cpp @@ -31,8 +31,8 @@ ScanI2C::FoundDevice ScanI2C::firstRTC() const ScanI2C::FoundDevice ScanI2C::firstKeyboard() const { - ScanI2C::DeviceType types[] = {CARDKB, TDECKKB, BBQ10KB, RAK14004, MPR121KB}; - return firstOfOrNONE(5, types); + ScanI2C::DeviceType types[] = {CARDKB, TDECKKB, BBQ10KB, RAK14004, MPR121KB, TCA8418KB}; + return firstOfOrNONE(6, types); } ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const @@ -41,6 +41,12 @@ ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const return firstOfOrNONE(8, types); } +ScanI2C::FoundDevice ScanI2C::firstRGBLED() const +{ + ScanI2C::DeviceType types[] = {NCP5623, LP5562}; + return firstOfOrNONE(2, types); +} + ScanI2C::FoundDevice ScanI2C::find(ScanI2C::DeviceType) const { return DEVICE_NONE; diff --git a/src/detect/ScanI2C.h b/src/detect/ScanI2C.h index 5b6bbe629..c363db1b5 100644 --- a/src/detect/ScanI2C.h +++ b/src/detect/ScanI2C.h @@ -18,7 +18,7 @@ class ScanI2C TDECKKB, BBQ10KB, RAK14004, - PMU_AXP192_AXP2101, + PMU_AXP192_AXP2101, // has the same adress as the TCA8418KB BME_680, BME_280, BMP_280, @@ -49,6 +49,7 @@ class ScanI2C VEML7700, RCWL9620, NCP5623, + LP5562, TSL2591, OPT3001, MLX90632, @@ -69,6 +70,7 @@ class ScanI2C DFROBOT_RAIN, DPS310, LTR390UV, + TCA8418KB, } DeviceType; // typedef uint8_t DeviceAddress; @@ -121,6 +123,8 @@ class ScanI2C FoundDevice firstAccelerometer() const; + FoundDevice firstRGBLED() const; + virtual FoundDevice find(DeviceType) const; virtual bool exists(DeviceType) const; diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 8b779277d..9781cbf56 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -10,11 +10,6 @@ #include "meshUtils.h" // vformat #endif -// AXP192 and AXP2101 have the same device address, we just need to identify it in Power.cpp -#ifndef XPOWERS_AXP192_AXP2101_ADDRESS -#define XPOWERS_AXP192_AXP2101_ADDRESS 0x34 -#endif - bool in_array(uint8_t *array, int size, uint8_t lookfor) { int i; @@ -218,9 +213,20 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) #ifdef HAS_NCP5623 SCAN_SIMPLE_CASE(NCP5623_ADDR, NCP5623, "NCP5623", (uint8_t)addr.address); #endif -#ifdef HAS_PMU - SCAN_SIMPLE_CASE(XPOWERS_AXP192_AXP2101_ADDRESS, PMU_AXP192_AXP2101, "AXP192/AXP2101", (uint8_t)addr.address) +#ifdef HAS_LP5562 + SCAN_SIMPLE_CASE(LP5562_ADDR, LP5562, "LP5562", (uint8_t)addr.address); #endif + case XPOWERS_AXP192_AXP2101_ADDRESS: + // Do we have the axp2101/192 or the TCA8418 + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x90), 1); + if (registerValue == 0x0) { + logFoundDevice("TCA8418", (uint8_t)addr.address); + type = TCA8418KB; + } else { + logFoundDevice("AXP192/AXP2101", (uint8_t)addr.address); + type = PMU_AXP192_AXP2101; + } + break; case BME_ADDR: case BME_ADDR_ALTERNATE: registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xD0), 1); // GET_ID diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 41a2ff980..a2e7ebbc7 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -1206,7 +1206,8 @@ GnssModel_t GPS::probe(int serialSpeed) delay(20); std::vector mtk = {{"L76B", "Quectel-L76B", GNSS_MODEL_MTK_L76B}, {"PA1616S", "1616S", GNSS_MODEL_MTK_PA1616S}, - {"LS20031", "MC-1513", GNSS_MODEL_MTK_L76B}}; + {"LS20031", "MC-1513", GNSS_MODEL_MTK_L76B}, + {"L96", "Quectel-L96", GNSS_MODEL_MTK_L76B}}; PROBE_FAMILY("MTK Family", "$PMTK605*31", mtk, 500); uint8_t cfg_rate[] = {0xB5, 0x62, 0x06, 0x08, 0x00, 0x00, 0x00, 0x00}; diff --git a/src/graphics/EInkDisplay2.cpp b/src/graphics/EInkDisplay2.cpp index 96c6b44c1..d2d373d24 100644 --- a/src/graphics/EInkDisplay2.cpp +++ b/src/graphics/EInkDisplay2.cpp @@ -129,9 +129,10 @@ bool EInkDisplay::connect() // backlight power, HIGH is backlight on, LOW is off pinMode(PIN_EINK_EN, OUTPUT); #ifdef ELECROW_ThinkNode_M1 - digitalWrite(PIN_EINK_EN, LOW); -#else + // ThinkNode M1 has a hardware dimmable backlight. Start enabled digitalWrite(PIN_EINK_EN, HIGH); +#else + digitalWrite(PIN_EINK_EN, LOW); #endif #endif diff --git a/src/graphics/NomadStarLED.h b/src/graphics/NomadStarLED.h new file mode 100644 index 000000000..0633a577e --- /dev/null +++ b/src/graphics/NomadStarLED.h @@ -0,0 +1,5 @@ +#ifdef HAS_LP5562 +#include +extern LP5562 rgbw; + +#endif \ No newline at end of file diff --git a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h index 4f8205647..f162aa385 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h +++ b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h @@ -18,8 +18,7 @@ namespace NicheGraphics::InkHUD enum MenuAction { NO_ACTION, - SEND_NODEINFO, - SEND_POSITION, + SEND_PING, SHUTDOWN, NEXT_TILE, TOGGLE_BACKLIGHT, diff --git a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp index f59579230..5ca9692c8 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp @@ -4,6 +4,7 @@ #include "RTC.h" +#include "MeshService.h" #include "airtime.h" #include "main.h" #include "power.h" @@ -144,6 +145,14 @@ void InkHUD::MenuApplet::execute(MenuItem item) inkhud->nextTile(); break; + case SEND_PING: + service->refreshLocalMeshNode(); + service->trySendPosition(NODENUM_BROADCAST, true); + + // Force the next refresh to use FULL, to protect the display, as some users will probably spam this button + inkhud->forceUpdate(Drivers::EInk::UpdateTypes::FULL); + break; + case ROTATE: inkhud->rotate(); break; @@ -242,7 +251,7 @@ void InkHUD::MenuApplet::showPage(MenuPage page) if (settings->optionalMenuItems.nextTile && settings->userTiles.count > 1) items.push_back(MenuItem("Next Tile", MenuAction::NEXT_TILE, MenuPage::ROOT)); // Only if multiple applets shown - // items.push_back(MenuItem("Send", MenuPage::SEND)); // TODO + items.push_back(MenuItem("Send", MenuPage::SEND)); items.push_back(MenuItem("Options", MenuPage::OPTIONS)); // items.push_back(MenuItem("Display Off", MenuPage::EXIT)); // TODO items.push_back(MenuItem("Save & Shut Down", MenuAction::SHUTDOWN)); @@ -250,9 +259,8 @@ void InkHUD::MenuApplet::showPage(MenuPage page) break; case SEND: - items.push_back(MenuItem("Send Message", MenuPage::EXIT)); - items.push_back(MenuItem("Send NodeInfo", MenuAction::SEND_NODEINFO)); - items.push_back(MenuItem("Send Position", MenuAction::SEND_POSITION)); + items.push_back(MenuItem("Ping", MenuAction::SEND_PING, MenuPage::EXIT)); + // Todo: canned messages items.push_back(MenuItem("Exit", MenuPage::EXIT)); break; @@ -389,11 +397,14 @@ void InkHUD::MenuApplet::onRender() // Center-line for the text int16_t center = itemT + (itemH / 2); + // Box, if currently selected if (cursorShown && i == cursor) drawRect(itemL, itemT, itemW, itemH, BLACK); + + // Item's text printAt(itemL + X(padding), center, item.label, LEFT, MIDDLE); - // Testing only: circle instead of check box + // Checkbox, if relevant if (item.checkState) { const uint16_t cbWH = fontSmall.lineHeight(); // Checkbox: width / height const int16_t cbL = itemR - X(padding) - cbWH; // Checkbox: left diff --git a/src/graphics/niche/Inputs/TwoButton.cpp b/src/graphics/niche/Inputs/TwoButton.cpp index 10d89ef41..b270d56cf 100644 --- a/src/graphics/niche/Inputs/TwoButton.cpp +++ b/src/graphics/niche/Inputs/TwoButton.cpp @@ -2,6 +2,7 @@ #include "./TwoButton.h" +#include "NodeDB.h" // For the helper function TwoButton::getUserButtonPin #include "PowerFSM.h" #include "sleep.h" @@ -57,14 +58,47 @@ void TwoButton::stop() detachInterrupt(buttons[1].pin); } +// Attempt to resolve a GPIO pin for the user button, honoring userPrefs.jsonc and device settings +// This helper method isn't used by the TweButton class itself, it could be moved elsewhere. +// Intention is to pass this value to TwoButton::setWiring in the setupNicheGraphics method. +uint8_t TwoButton::getUserButtonPin() +{ + uint8_t pin = 0xFF; // Unset + + // Use default pin for variant, if no better source +#ifdef BUTTON_PIN + pin = BUTTON_PIN; +#endif + + // From userPrefs.jsonc, if set +#ifdef USERPREFS_BUTTON_PIN + pin = USERPREFS_BUTTON_PIN; +#endif + + // From user's override in device settings, if set + if (config.device.button_gpio) + pin = config.device.button_gpio; + + return pin; +} + // Configures the wiring and logic of either button // Called when outlining your NicheGraphics implementation, in variant/nicheGraphics.cpp void TwoButton::setWiring(uint8_t whichButton, uint8_t pin, bool internalPullup) { + // Prevent the same GPIO being assigned to multiple buttons + // Allows an edge case when the user remaps hardware buttons using device settings, due to a broken user button + for (uint8_t i = 0; i < whichButton; i++) { + if (buttons[i].pin == pin) { + LOG_WARN("Attempted reuse of GPIO %d. Ignoring assignment whichButton=%d", pin, whichButton); + return; + } + } + assert(whichButton < 2); buttons[whichButton].pin = pin; - buttons[whichButton].activeLogic = LOW; - buttons[whichButton].mode = internalPullup ? INPUT_PULLUP : INPUT; // fix me + buttons[whichButton].activeLogic = LOW; // Unimplemented + buttons[whichButton].mode = internalPullup ? INPUT_PULLUP : INPUT; pinMode(buttons[whichButton].pin, buttons[whichButton].mode); } diff --git a/src/graphics/niche/Inputs/TwoButton.h b/src/graphics/niche/Inputs/TwoButton.h index 1e1576256..f1e18dd89 100644 --- a/src/graphics/niche/Inputs/TwoButton.h +++ b/src/graphics/niche/Inputs/TwoButton.h @@ -30,6 +30,8 @@ class TwoButton : protected concurrency::OSThread public: typedef std::function Callback; + static uint8_t getUserButtonPin(); // Resolve the GPIO, considering the various possible source of definition + static TwoButton *getInstance(); // Create or get the singleton instance void start(); // Start handling button input void stop(); // Stop handling button input (disconnect ISRs for sleep) @@ -62,7 +64,7 @@ class TwoButton : protected concurrency::OSThread public: // Per-button config uint8_t pin = 0xFF; // 0xFF: unset - bool activeLogic = LOW; // Active LOW by default. Todo: remove, unused + bool activeLogic = LOW; // Active LOW by default. Currently unimplemented. uint8_t mode = INPUT; // Whether to use internal pull up / pull down resistors uint32_t debounceLength = 50; // Minimum length for shortpress, in ms uint32_t longpressLength = 500; // How long after button down to fire longpress, in ms diff --git a/src/input/TCA8418Keyboard.cpp b/src/input/TCA8418Keyboard.cpp new file mode 100644 index 000000000..21cd7b2d5 --- /dev/null +++ b/src/input/TCA8418Keyboard.cpp @@ -0,0 +1,561 @@ +// Based on the MPR121 Keyboard and Adafruit TCA8418 library + +#include "TCA8418Keyboard.h" +#include "configuration.h" + +#include + +// REGISTERS +// #define _TCA8418_REG_RESERVED 0x00 +#define _TCA8418_REG_CFG 0x01 // Configuration register +#define _TCA8418_REG_INT_STAT 0x02 // Interrupt status +#define _TCA8418_REG_KEY_LCK_EC 0x03 // Key lock and event counter +#define _TCA8418_REG_KEY_EVENT_A 0x04 // Key event register A +#define _TCA8418_REG_KEY_EVENT_B 0x05 // Key event register B +#define _TCA8418_REG_KEY_EVENT_C 0x06 // Key event register C +#define _TCA8418_REG_KEY_EVENT_D 0x07 // Key event register D +#define _TCA8418_REG_KEY_EVENT_E 0x08 // Key event register E +#define _TCA8418_REG_KEY_EVENT_F 0x09 // Key event register F +#define _TCA8418_REG_KEY_EVENT_G 0x0A // Key event register G +#define _TCA8418_REG_KEY_EVENT_H 0x0B // Key event register H +#define _TCA8418_REG_KEY_EVENT_I 0x0C // Key event register I +#define _TCA8418_REG_KEY_EVENT_J 0x0D // Key event register J +#define _TCA8418_REG_KP_LCK_TIMER 0x0E // Keypad lock1 to lock2 timer +#define _TCA8418_REG_UNLOCK_1 0x0F // Unlock register 1 +#define _TCA8418_REG_UNLOCK_2 0x10 // Unlock register 2 +#define _TCA8418_REG_GPIO_INT_STAT_1 0x11 // GPIO interrupt status 1 +#define _TCA8418_REG_GPIO_INT_STAT_2 0x12 // GPIO interrupt status 2 +#define _TCA8418_REG_GPIO_INT_STAT_3 0x13 // GPIO interrupt status 3 +#define _TCA8418_REG_GPIO_DAT_STAT_1 0x14 // GPIO data status 1 +#define _TCA8418_REG_GPIO_DAT_STAT_2 0x15 // GPIO data status 2 +#define _TCA8418_REG_GPIO_DAT_STAT_3 0x16 // GPIO data status 3 +#define _TCA8418_REG_GPIO_DAT_OUT_1 0x17 // GPIO data out 1 +#define _TCA8418_REG_GPIO_DAT_OUT_2 0x18 // GPIO data out 2 +#define _TCA8418_REG_GPIO_DAT_OUT_3 0x19 // GPIO data out 3 +#define _TCA8418_REG_GPIO_INT_EN_1 0x1A // GPIO interrupt enable 1 +#define _TCA8418_REG_GPIO_INT_EN_2 0x1B // GPIO interrupt enable 2 +#define _TCA8418_REG_GPIO_INT_EN_3 0x1C // GPIO interrupt enable 3 +#define _TCA8418_REG_KP_GPIO_1 0x1D // Keypad/GPIO select 1 +#define _TCA8418_REG_KP_GPIO_2 0x1E // Keypad/GPIO select 2 +#define _TCA8418_REG_KP_GPIO_3 0x1F // Keypad/GPIO select 3 +#define _TCA8418_REG_GPI_EM_1 0x20 // GPI event mode 1 +#define _TCA8418_REG_GPI_EM_2 0x21 // GPI event mode 2 +#define _TCA8418_REG_GPI_EM_3 0x22 // GPI event mode 3 +#define _TCA8418_REG_GPIO_DIR_1 0x23 // GPIO data direction 1 +#define _TCA8418_REG_GPIO_DIR_2 0x24 // GPIO data direction 2 +#define _TCA8418_REG_GPIO_DIR_3 0x25 // GPIO data direction 3 +#define _TCA8418_REG_GPIO_INT_LVL_1 0x26 // GPIO edge/level detect 1 +#define _TCA8418_REG_GPIO_INT_LVL_2 0x27 // GPIO edge/level detect 2 +#define _TCA8418_REG_GPIO_INT_LVL_3 0x28 // GPIO edge/level detect 3 +#define _TCA8418_REG_DEBOUNCE_DIS_1 0x29 // Debounce disable 1 +#define _TCA8418_REG_DEBOUNCE_DIS_2 0x2A // Debounce disable 2 +#define _TCA8418_REG_DEBOUNCE_DIS_3 0x2B // Debounce disable 3 +#define _TCA8418_REG_GPIO_PULL_1 0x2C // GPIO pull-up disable 1 +#define _TCA8418_REG_GPIO_PULL_2 0x2D // GPIO pull-up disable 2 +#define _TCA8418_REG_GPIO_PULL_3 0x2E // GPIO pull-up disable 3 +// #define _TCA8418_REG_RESERVED 0x2F + +// FIELDS CONFIG REGISTER 1 +#define _TCA8418_REG_CFG_AI 0x80 // Auto-increment for read/write +#define _TCA8418_REG_CFG_GPI_E_CGF 0x40 // Event mode config +#define _TCA8418_REG_CFG_OVR_FLOW_M 0x20 // Overflow mode enable +#define _TCA8418_REG_CFG_INT_CFG 0x10 // Interrupt config +#define _TCA8418_REG_CFG_OVR_FLOW_IEN 0x08 // Overflow interrupt enable +#define _TCA8418_REG_CFG_K_LCK_IEN 0x04 // Keypad lock interrupt enable +#define _TCA8418_REG_CFG_GPI_IEN 0x02 // GPI interrupt enable +#define _TCA8418_REG_CFG_KE_IEN 0x01 // Key events interrupt enable + +// FIELDS INT_STAT REGISTER 2 +#define _TCA8418_REG_STAT_CAD_INT 0x10 // Ctrl-alt-del seq status +#define _TCA8418_REG_STAT_OVR_FLOW_INT 0x08 // Overflow interrupt status +#define _TCA8418_REG_STAT_K_LCK_INT 0x04 // Key lock interrupt status +#define _TCA8418_REG_STAT_GPI_INT 0x02 // GPI interrupt status +#define _TCA8418_REG_STAT_K_INT 0x01 // Key events interrupt status + +// FIELDS KEY_LCK_EC REGISTER 3 +#define _TCA8418_REG_LCK_EC_K_LCK_EN 0x40 // Key lock enable +#define _TCA8418_REG_LCK_EC_LCK_2 0x20 // Keypad lock status 2 +#define _TCA8418_REG_LCK_EC_LCK_1 0x10 // Keypad lock status 1 +#define _TCA8418_REG_LCK_EC_KLEC_3 0x08 // Key event count bit 3 +#define _TCA8418_REG_LCK_EC_KLEC_2 0x04 // Key event count bit 2 +#define _TCA8418_REG_LCK_EC_KLEC_1 0x02 // Key event count bit 1 +#define _TCA8418_REG_LCK_EC_KLEC_0 0x01 // Key event count bit 0 + +// Pin IDs for matrix rows/columns +enum { + _TCA8418_ROW0, // Pin ID for row 0 + _TCA8418_ROW1, // Pin ID for row 1 + _TCA8418_ROW2, // Pin ID for row 2 + _TCA8418_ROW3, // Pin ID for row 3 + _TCA8418_ROW4, // Pin ID for row 4 + _TCA8418_ROW5, // Pin ID for row 5 + _TCA8418_ROW6, // Pin ID for row 6 + _TCA8418_ROW7, // Pin ID for row 7 + _TCA8418_COL0, // Pin ID for column 0 + _TCA8418_COL1, // Pin ID for column 1 + _TCA8418_COL2, // Pin ID for column 2 + _TCA8418_COL3, // Pin ID for column 3 + _TCA8418_COL4, // Pin ID for column 4 + _TCA8418_COL5, // Pin ID for column 5 + _TCA8418_COL6, // Pin ID for column 6 + _TCA8418_COL7, // Pin ID for column 7 + _TCA8418_COL8, // Pin ID for column 8 + _TCA8418_COL9 // Pin ID for column 9 +}; + +#define _TCA8418_COLS 3 +#define _TCA8418_ROWS 4 +#define _TCA8418_NUM_KEYS 12 + +uint8_t TCA8418TapMod[_TCA8418_NUM_KEYS] = {13, 7, 7, 7, 7, 7, + 9, 7, 9, 2, 2, 2}; // Num chars per key, Modulus for rotating through characters + +unsigned char TCA8418TapMap[_TCA8418_NUM_KEYS][13] = { + {'1', '.', ',', '?', '!', ':', ';', '-', '_', '\\', '/', '(', ')'}, // 1 + {'2', 'a', 'b', 'c', 'A', 'B', 'C'}, // 2 + {'3', 'd', 'e', 'f', 'D', 'E', 'F'}, // 3 + {'4', 'g', 'h', 'i', 'G', 'H', 'I'}, // 4 + {'5', 'j', 'k', 'l', 'J', 'K', 'L'}, // 5 + {'6', 'm', 'n', 'o', 'M', 'N', 'O'}, // 6 + {'7', 'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S'}, // 7 + {'8', 't', 'u', 'v', 'T', 'U', 'V'}, // 8 + {'9', 'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z'}, // 9 + {'*', '+'}, // * + {'0', ' '}, // 0 + {'#', '@'}, // # +}; + +unsigned char TCA8418LongPressMap[_TCA8418_NUM_KEYS] = { + _TCA8418_ESC, // 1 + _TCA8418_UP, // 2 + _TCA8418_NONE, // 3 + _TCA8418_LEFT, // 4 + _TCA8418_NONE, // 5 + _TCA8418_RIGHT, // 6 + _TCA8418_NONE, // 7 + _TCA8418_DOWN, // 8 + _TCA8418_NONE, // 9 + _TCA8418_BSP, // * + _TCA8418_NONE, // 0 + _TCA8418_NONE, // # +}; + +#define _TCA8418_LONG_PRESS_THRESHOLD 2000 +#define _TCA8418_MULTI_TAP_THRESHOLD 750 + +TCA8418Keyboard::TCA8418Keyboard() : m_wire(nullptr), m_addr(0), readCallback(nullptr), writeCallback(nullptr) +{ + state = Init; + last_key = -1; + next_key = -1; + should_backspace = false; + last_tap = 0L; + char_idx = 0; + tap_interval = 0; + backlight_on = true; + queue = ""; +} + +void TCA8418Keyboard::begin(uint8_t addr, TwoWire *wire) +{ + m_addr = addr; + m_wire = wire; + + m_wire->begin(); + + reset(); +} + +void TCA8418Keyboard::begin(i2c_com_fptr_t r, i2c_com_fptr_t w, uint8_t addr) +{ + m_addr = addr; + m_wire = nullptr; + writeCallback = w; + readCallback = r; + reset(); +} + +void TCA8418Keyboard::reset() +{ + LOG_DEBUG("TCA8418 Reset"); + // GPIO + // set default all GIO pins to INPUT + writeRegister(_TCA8418_REG_GPIO_DIR_1, 0x00); + writeRegister(_TCA8418_REG_GPIO_DIR_2, 0x00); + // Set COL9 as GPIO output + writeRegister(_TCA8418_REG_GPIO_DIR_3, 0x02); + // Switch off keyboard backlight (COL9 = LOW) + writeRegister(_TCA8418_REG_GPIO_DAT_OUT_3, 0x00); + + // add all pins to key events + writeRegister(_TCA8418_REG_GPI_EM_1, 0xFF); + writeRegister(_TCA8418_REG_GPI_EM_2, 0xFF); + writeRegister(_TCA8418_REG_GPI_EM_3, 0xFF); + + // set all pins to FALLING interrupts + writeRegister(_TCA8418_REG_GPIO_INT_LVL_1, 0x00); + writeRegister(_TCA8418_REG_GPIO_INT_LVL_2, 0x00); + writeRegister(_TCA8418_REG_GPIO_INT_LVL_3, 0x00); + + // add all pins to interrupts + writeRegister(_TCA8418_REG_GPIO_INT_EN_1, 0xFF); + writeRegister(_TCA8418_REG_GPIO_INT_EN_2, 0xFF); + writeRegister(_TCA8418_REG_GPIO_INT_EN_3, 0xFF); + + // Set keyboard matrix size + matrix(_TCA8418_ROWS, _TCA8418_COLS); + enableDebounce(); + flush(); + state = Idle; +} + +bool TCA8418Keyboard::matrix(uint8_t rows, uint8_t columns) +{ + if ((rows > 8) || (columns > 10)) + return false; + + // Skip zero size matrix + if ((rows != 0) && (columns != 0)) { + // Setup the keypad matrix. + uint8_t mask = 0x00; + for (int r = 0; r < rows; r++) { + mask <<= 1; + mask |= 1; + } + writeRegister(_TCA8418_REG_KP_GPIO_1, mask); + + mask = 0x00; + for (int c = 0; c < columns && c < 8; c++) { + mask <<= 1; + mask |= 1; + } + writeRegister(_TCA8418_REG_KP_GPIO_2, mask); + + if (columns > 8) { + if (columns == 9) + mask = 0x01; + else + mask = 0x03; + writeRegister(_TCA8418_REG_KP_GPIO_3, mask); + } + } + + return true; +} + +uint8_t TCA8418Keyboard::keyCount() const +{ + uint8_t eventCount = readRegister(_TCA8418_REG_KEY_LCK_EC); + eventCount &= 0x0F; // lower 4 bits only + return eventCount; +} + +bool TCA8418Keyboard::hasEvent() +{ + return queue.length() > 0; +} + +void TCA8418Keyboard::queueEvent(char next) +{ + if (next == _TCA8418_NONE) { + return; + } + queue.concat(next); +} + +char TCA8418Keyboard::dequeueEvent() +{ + if (queue.length() < 1) { + return _TCA8418_NONE; + } + char next = queue.charAt(0); + queue.remove(0, 1); + return next; +} + +void TCA8418Keyboard::trigger() +{ + if (keyCount() == 0) { + return; + } + if (state != Init) { + // Read the key register + uint8_t k = readRegister(_TCA8418_REG_KEY_EVENT_A); + uint8_t key = k & 0x7F; + if (k & 0x80) { + if (state == Idle) + pressed(key); + return; + } else { + if (state == Held) { + released(); + } + state = Idle; + return; + } + } else { + reset(); + } +} + +void TCA8418Keyboard::pressed(uint8_t key) +{ + if (state == Init || state == Busy) { + return; + } + uint8_t next_key = 0; + int row = (key - 1) / 10; + int col = (key - 1) % 10; + + if (row >= _TCA8418_ROWS || col >= _TCA8418_COLS) { + return; // Invalid key + } + + // Compute key index based on dynamic row/column + next_key = row * _TCA8418_COLS + col; + + // LOG_DEBUG("TCA8418: Key %u -> Next Key %u", key, next_key); + + state = Held; + uint32_t now = millis(); + tap_interval = now - last_tap; + if (tap_interval < 0) { + // Long running, millis has overflowed. + last_tap = 0; + state = Busy; + return; + } + + // Check if the key is the same as the last one or if the time interval has passed + if (next_key != last_key || tap_interval > _TCA8418_MULTI_TAP_THRESHOLD) { + char_idx = 0; // Reset char index if new key or long press + should_backspace = false; // dont backspace on new key + } else { + char_idx += 1; // Cycle through characters if same key pressed + should_backspace = true; // allow backspace on same key + } + + // Store the current key as the last key + last_key = next_key; + last_tap = now; +} + +void TCA8418Keyboard::released() +{ + if (state != Held) { + return; + } + + if (last_key < 0 || last_key > _TCA8418_NUM_KEYS) { // reset to idle if last_key out of bounds + last_key = -1; + state = Idle; + return; + } + uint32_t now = millis(); + int32_t held_interval = now - last_tap; + last_tap = now; + if (tap_interval < _TCA8418_MULTI_TAP_THRESHOLD && should_backspace) { + queueEvent(_TCA8418_BSP); + } + if (held_interval > _TCA8418_LONG_PRESS_THRESHOLD) { + queueEvent(TCA8418LongPressMap[last_key]); + // LOG_DEBUG("Long Press Key: %i Map: %i", last_key, TCA8418LongPressMap[last_key]); + } else { + queueEvent(TCA8418TapMap[last_key][(char_idx % TCA8418TapMod[last_key])]); + // LOG_DEBUG("Key Press: %i Index:%i if %i Map: %c", last_key, char_idx, TCA8418TapMod[last_key], + // TCA8418TapMap[last_key][(char_idx % TCA8418TapMod[last_key])]); + } +} + +uint8_t TCA8418Keyboard::flush() +{ + // Flush key events + uint8_t count = 0; + while (readRegister(_TCA8418_REG_KEY_EVENT_A) != 0) + count++; + // Flush gpio events + readRegister(_TCA8418_REG_GPIO_INT_STAT_1); + readRegister(_TCA8418_REG_GPIO_INT_STAT_2); + readRegister(_TCA8418_REG_GPIO_INT_STAT_3); + // Clear INT_STAT register + writeRegister(_TCA8418_REG_INT_STAT, 3); + return count; +} + +uint8_t TCA8418Keyboard::digitalRead(uint8_t pinnum) const +{ + if (pinnum > _TCA8418_COL9) + return 0xFF; + + uint8_t reg = _TCA8418_REG_GPIO_DAT_STAT_1 + pinnum / 8; + uint8_t mask = (1 << (pinnum % 8)); + + // Level 0 = low other = high + uint8_t value = readRegister(reg); + if (value & mask) + return HIGH; + return LOW; +} + +bool TCA8418Keyboard::digitalWrite(uint8_t pinnum, uint8_t level) +{ + if (pinnum > _TCA8418_COL9) + return false; + + uint8_t reg = _TCA8418_REG_GPIO_DAT_OUT_1 + pinnum / 8; + uint8_t mask = (1 << (pinnum % 8)); + + // Level 0 = low other = high + uint8_t value = readRegister(reg); + if (level == LOW) + value &= ~mask; + else + value |= mask; + writeRegister(reg, value); + return true; +} + +bool TCA8418Keyboard::pinMode(uint8_t pinnum, uint8_t mode) +{ + if (pinnum > _TCA8418_COL9) + return false; + + uint8_t idx = pinnum / 8; + uint8_t reg = _TCA8418_REG_GPIO_DIR_1 + idx; + uint8_t mask = (1 << (pinnum % 8)); + + // Mode 0 = input 1 = output + uint8_t value = readRegister(reg); + if (mode == OUTPUT) + value |= mask; + else + value &= ~mask; + writeRegister(reg, value); + + // Pullup 0 = enabled 1 = disabled + reg = _TCA8418_REG_GPIO_PULL_1 + idx; + value = readRegister(reg); + if (mode == INPUT_PULLUP) + value &= ~mask; + else + value |= mask; + writeRegister(reg, value); + + return true; +} + +bool TCA8418Keyboard::pinIRQMode(uint8_t pinnum, uint8_t mode) +{ + if (pinnum > _TCA8418_COL9) + return false; + if ((mode != RISING) && (mode != FALLING)) + return false; + + // Mode 0 = falling 1 = rising + uint8_t idx = pinnum / 8; + uint8_t reg = _TCA8418_REG_GPIO_INT_LVL_1 + idx; + uint8_t mask = (1 << (pinnum % 8)); + + uint8_t value = readRegister(reg); + if (mode == RISING) + value |= mask; + else + value &= ~mask; + writeRegister(reg, value); + + // Enable interrupt + reg = _TCA8418_REG_GPIO_INT_EN_1 + idx; + value = readRegister(reg); + value |= mask; + writeRegister(reg, value); + + return true; +} + +void TCA8418Keyboard::enableInterrupts() +{ + uint8_t value = readRegister(_TCA8418_REG_CFG); + value |= (_TCA8418_REG_CFG_GPI_IEN | _TCA8418_REG_CFG_KE_IEN); + writeRegister(_TCA8418_REG_CFG, value); +}; + +void TCA8418Keyboard::disableInterrupts() +{ + uint8_t value = readRegister(_TCA8418_REG_CFG); + value &= ~(_TCA8418_REG_CFG_GPI_IEN | _TCA8418_REG_CFG_KE_IEN); + writeRegister(_TCA8418_REG_CFG, value); +}; + +void TCA8418Keyboard::enableMatrixOverflow() +{ + uint8_t value = readRegister(_TCA8418_REG_CFG); + value |= _TCA8418_REG_CFG_OVR_FLOW_M; + writeRegister(_TCA8418_REG_CFG, value); +}; + +void TCA8418Keyboard::disableMatrixOverflow() +{ + uint8_t value = readRegister(_TCA8418_REG_CFG); + value &= ~_TCA8418_REG_CFG_OVR_FLOW_M; + writeRegister(_TCA8418_REG_CFG, value); +}; + +void TCA8418Keyboard::enableDebounce() +{ + writeRegister(_TCA8418_REG_DEBOUNCE_DIS_1, 0x00); + writeRegister(_TCA8418_REG_DEBOUNCE_DIS_2, 0x00); + writeRegister(_TCA8418_REG_DEBOUNCE_DIS_3, 0x00); +} + +void TCA8418Keyboard::disableDebounce() +{ + writeRegister(_TCA8418_REG_DEBOUNCE_DIS_1, 0xFF); + writeRegister(_TCA8418_REG_DEBOUNCE_DIS_2, 0xFF); + writeRegister(_TCA8418_REG_DEBOUNCE_DIS_3, 0xFF); +} + +void TCA8418Keyboard::setBacklight(bool on) +{ + if (on) { + digitalWrite(_TCA8418_COL9, HIGH); + } else { + digitalWrite(_TCA8418_COL9, LOW); + } +} + +uint8_t TCA8418Keyboard::readRegister(uint8_t reg) const +{ + if (m_wire) { + m_wire->beginTransmission(m_addr); + m_wire->write(reg); + m_wire->endTransmission(); + + m_wire->requestFrom(m_addr, (uint8_t)1); + if (m_wire->available() < 1) + return 0; + + return m_wire->read(); + } + if (readCallback) { + uint8_t data; + readCallback(m_addr, reg, &data, 1); + return data; + } + return 0; +} + +void TCA8418Keyboard::writeRegister(uint8_t reg, uint8_t value) +{ + uint8_t data[2]; + data[0] = reg; + data[1] = value; + + if (m_wire) { + m_wire->beginTransmission(m_addr); + m_wire->write(data, sizeof(uint8_t) * 2); + m_wire->endTransmission(); + } + if (writeCallback) { + writeCallback(m_addr, data[0], &(data[1]), 1); + } +} \ No newline at end of file diff --git a/src/input/TCA8418Keyboard.h b/src/input/TCA8418Keyboard.h new file mode 100644 index 000000000..c7f3c1f28 --- /dev/null +++ b/src/input/TCA8418Keyboard.h @@ -0,0 +1,83 @@ +// Based on the MPR121 Keyboard and Adafruit TCA8418 library +#include "configuration.h" +#include + +#define _TCA8418_NONE 0x00 +#define _TCA8418_REBOOT 0x90 +#define _TCA8418_LEFT 0xb4 +#define _TCA8418_UP 0xb5 +#define _TCA8418_DOWN 0xb6 +#define _TCA8418_RIGHT 0xb7 +#define _TCA8418_ESC 0x1b +#define _TCA8418_BSP 0x08 +#define _TCA8418_SELECT 0x0d + +class TCA8418Keyboard +{ + public: + typedef uint8_t (*i2c_com_fptr_t)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint8_t len); + + enum KeyState { Init = 0, Idle, Held, Busy }; + + KeyState state; + int8_t last_key; + int8_t next_key; + bool should_backspace; + uint32_t last_tap; + uint8_t char_idx; + int32_t tap_interval; + bool backlight_on; + + String queue; + + TCA8418Keyboard(); + + void begin(uint8_t addr = XPOWERS_AXP192_AXP2101_ADDRESS, TwoWire *wire = &Wire); + void begin(i2c_com_fptr_t r, i2c_com_fptr_t w, uint8_t addr = XPOWERS_AXP192_AXP2101_ADDRESS); + + void reset(void); + // Configure the size of the keypad. + // All other rows and columns are set as inputs. + bool matrix(uint8_t rows, uint8_t columns); + + // Flush all events in the FIFO buffer + GPIO events. + uint8_t flush(void); + + // Key events available in the internal FIFO buffer. + uint8_t keyCount(void) const; + + void trigger(void); + void pressed(uint8_t key); + void released(void); + bool hasEvent(void); + char dequeueEvent(void); + void queueEvent(char); + + uint8_t digitalRead(uint8_t pinnum) const; + bool digitalWrite(uint8_t pinnum, uint8_t level); + bool pinMode(uint8_t pinnum, uint8_t mode); + bool pinIRQMode(uint8_t pinnum, uint8_t mode); // MODE FALLING or RISING + + // enable / disable interrupts for matrix and GPI pins + void enableInterrupts(); + void disableInterrupts(); + + // ignore key events when FIFO buffer is full or not. + void enableMatrixOverflow(); + void disableMatrixOverflow(); + + // debounce keys. + void enableDebounce(); + void disableDebounce(); + + void setBacklight(bool on); + + uint8_t readRegister(uint8_t reg) const; + void writeRegister(uint8_t reg, uint8_t value); + + private: + TwoWire *m_wire; + uint8_t m_addr; + i2c_com_fptr_t readCallback; + i2c_com_fptr_t writeCallback; +}; diff --git a/src/input/cardKbI2cImpl.cpp b/src/input/cardKbI2cImpl.cpp index eb9b07d6e..21ecf381a 100644 --- a/src/input/cardKbI2cImpl.cpp +++ b/src/input/cardKbI2cImpl.cpp @@ -12,8 +12,8 @@ void CardKbI2cImpl::init() #if !MESHTASTIC_EXCLUDE_I2C && !defined(ARCH_PORTDUINO) && !defined(I2C_NO_RESCAN) if (cardkb_found.address == 0x00) { LOG_DEBUG("Rescan for I2C keyboard"); - uint8_t i2caddr_scan[] = {CARDKB_ADDR, TDECK_KB_ADDR, BBQ10_KB_ADDR, MPR121_KB_ADDR}; - uint8_t i2caddr_asize = 4; + uint8_t i2caddr_scan[] = {CARDKB_ADDR, TDECK_KB_ADDR, BBQ10_KB_ADDR, MPR121_KB_ADDR, XPOWERS_AXP192_AXP2101_ADDRESS}; + uint8_t i2caddr_asize = 5; auto i2cScanner = std::unique_ptr(new ScanI2CTwoWire()); #if WIRE_INTERFACES_COUNT == 2 @@ -43,6 +43,10 @@ void CardKbI2cImpl::init() // assign an arbitrary value to distinguish from other models kb_model = 0x37; break; + case ScanI2C::DeviceType::TCA8418KB: + // assign an arbitrary value to distinguish from other models + kb_model = 0x84; + break; default: // use this as default since it's also just zero LOG_WARN("kb_info.type is unknown(0x%02x), setting kb_model=0x00", kb_info.type); diff --git a/src/input/kbI2cBase.cpp b/src/input/kbI2cBase.cpp index 9b1a27745..70e9e4365 100644 --- a/src/input/kbI2cBase.cpp +++ b/src/input/kbI2cBase.cpp @@ -43,6 +43,9 @@ int32_t KbI2cBase::runOnce() if (cardkb_found.address == MPR121_KB_ADDR) { MPRkeyboard.begin(MPR121_KB_ADDR, &Wire1); } + if (cardkb_found.address == XPOWERS_AXP192_AXP2101_ADDRESS) { + TCAKeyboard.begin(XPOWERS_AXP192_AXP2101_ADDRESS, &Wire1); + } break; #endif case ScanI2C::WIRE: @@ -55,6 +58,9 @@ int32_t KbI2cBase::runOnce() if (cardkb_found.address == MPR121_KB_ADDR) { MPRkeyboard.begin(MPR121_KB_ADDR, &Wire); } + if (cardkb_found.address == XPOWERS_AXP192_AXP2101_ADDRESS) { + TCAKeyboard.begin(XPOWERS_AXP192_AXP2101_ADDRESS, &Wire); + } break; case ScanI2C::NO_I2C: default: @@ -226,6 +232,68 @@ int32_t KbI2cBase::runOnce() } break; } + case 0x84: { // Adafruit TCA8418 + TCAKeyboard.trigger(); + InputEvent e; + while (TCAKeyboard.hasEvent()) { + char nextEvent = TCAKeyboard.dequeueEvent(); + e.inputEvent = ANYKEY; + e.kbchar = 0x00; + e.source = this->_originName; + switch (nextEvent) { + case _TCA8418_NONE: + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; + e.kbchar = 0x00; + break; + case _TCA8418_REBOOT: + e.inputEvent = ANYKEY; + e.kbchar = INPUT_BROKER_MSG_REBOOT; + break; + case _TCA8418_LEFT: + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_LEFT; + e.kbchar = 0x00; + break; + case _TCA8418_UP: + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_UP; + e.kbchar = 0x00; + break; + case _TCA8418_DOWN: + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_DOWN; + e.kbchar = 0x00; + break; + case _TCA8418_RIGHT: + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT; + e.kbchar = 0x00; + break; + case _TCA8418_BSP: + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_BACK; + e.kbchar = 0x08; + break; + case _TCA8418_SELECT: + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT; + e.kbchar = 0x0d; + break; + case _TCA8418_ESC: + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_CANCEL; + e.kbchar = 0x1b; + break; + default: + if (nextEvent > 127) { + e.inputEvent = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE; + e.kbchar = 0x00; + break; + } + e.inputEvent = ANYKEY; + e.kbchar = nextEvent; + break; + } + if (e.inputEvent != meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_NONE) { + LOG_DEBUG("TCA8418 Notifying: %i Char: %c", e.inputEvent, e.kbchar); + this->notifyObservers(&e); + } + } + break; + } case 0x02: { // RAK14004 uint8_t rDataBuf[8] = {0}; diff --git a/src/input/kbI2cBase.h b/src/input/kbI2cBase.h index dc2414fc0..8193433fe 100644 --- a/src/input/kbI2cBase.h +++ b/src/input/kbI2cBase.h @@ -3,6 +3,7 @@ #include "BBQ10Keyboard.h" #include "InputBroker.h" #include "MPR121Keyboard.h" +#include "TCA8418Keyboard.h" #include "Wire.h" #include "concurrency/OSThread.h" @@ -21,5 +22,6 @@ class KbI2cBase : public Observable, public concurrency::OST BBQ10Keyboard Q10keyboard; MPR121Keyboard MPRkeyboard; + TCA8418Keyboard TCAKeyboard; bool is_sym = false; }; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 59cd6d8e9..fd65830ef 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -587,6 +587,10 @@ void setup() // assign an arbitrary value to distinguish from other models kb_model = 0x37; break; + case ScanI2C::DeviceType::TCA8418KB: + // assign an arbitrary value to distinguish from other models + kb_model = 0x84; + break; default: // use this as default since it's also just zero LOG_WARN("kb_info.type is unknown(0x%02x), setting kb_model=0x00", kb_info.type); @@ -602,9 +606,9 @@ void setup() * "found". */ -// Only one supported RGB LED currently -#ifdef HAS_NCP5623 - rgb_found = i2cScanner->find(ScanI2C::DeviceType::NCP5623); +// Two supported RGB LED currently +#ifdef HAS_RGB_LED + rgb_found = i2cScanner->firstRGBLED(); #endif #ifdef HAS_TPS65233 @@ -1270,10 +1274,23 @@ extern meshtastic_DeviceMetadata getDeviceMetadata() #ifndef ARCH_ESP32 deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_PAXCOUNTER_CONFIG; #endif -#if !defined(HAS_NCP5623) && !defined(RGBLED_RED) && !defined(HAS_NEOPIXEL) && !defined(UNPHONE) && !RAK_4631 +#if !defined(HAS_RGB_LED) && !RAK_4631 deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_AMBIENTLIGHTING_CONFIG; #endif +// No bluetooth on these targets (yet): +// Pico W / 2W may get it at some point +// Portduino and ESP32-C6 are excluded because we don't have a working bluetooth stacks integrated yet. +#if defined(ARCH_RP2040) || defined(ARCH_PORTDUINO) || defined(ARCH_STM32WL) || defined(CONFIG_IDF_TARGET_ESP32C6) + deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_BLUETOOTH_CONFIG; +#endif + +#if defined(ARCH_NRF52) && !HAS_ETHERNET // nrf52 doesn't have network unless it's a RAK ethernet gateway currently + deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_NETWORK_CONFIG; // No network on nRF52 +#elif defined(ARCH_RP2040) && !HAS_WIFI && !HAS_ETHERNET + deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_NETWORK_CONFIG; // No network on RP2040 +#endif + #if !(MESHTASTIC_EXCLUDE_PKI) deviceMetadata.hasPKC = true; #endif diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 3f79d18e6..9bb63652a 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -689,7 +689,7 @@ void NodeDB::initConfigIntervals() config.display.screen_on_secs = default_screen_on_secs; -#if defined(T_WATCH_S3) || defined(T_DECK) || defined(MESH_TAB) || defined(RAK14014) +#if defined(T_WATCH_S3) || defined(T_DECK) || defined(UNPHONE) || defined(MESH_TAB) || defined(RAK14014) config.power.is_power_saving = true; config.display.screen_on_secs = 30; config.power.wait_bluetooth_secs = 30; diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 2e50c0168..86903153b 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -488,11 +488,6 @@ void RadioInterface::applyModemConfig() cr = 8; sf = 12; break; - case meshtastic_Config_LoRaConfig_ModemPreset_VERY_LONG_SLOW: - bw = (myRegion->wideLora) ? 203.125 : 62.5; - cr = 8; - sf = 12; - break; } } else { sf = loraConfig.spread_factor; diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index defaaad28..191f9e121 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -237,6 +237,8 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_T_ETH_ELITE = 91, /* Heltec HRI-3621 industrial probe */ meshtastic_HardwareModel_HELTEC_SENSOR_HUB = 92, + /* Reserved Fried Chicken ID for future use */ + meshtastic_HardwareModel_RESERVED_FRIED_CHICKEN = 93, /* ------------------------------------------------------------------------------------------------------------------------------------------ Reserved ID For developing private Ports. These will show up in live traffic sparsely, so we can use a high number. Keep it within 8 bits. ------------------------------------------------------------------------------------------------------------------------------------------ */ diff --git a/src/mesh/wifi/WiFiAPClient.cpp b/src/mesh/wifi/WiFiAPClient.cpp index e050c2057..4d0b74f7c 100644 --- a/src/mesh/wifi/WiFiAPClient.cpp +++ b/src/mesh/wifi/WiFiAPClient.cpp @@ -163,7 +163,7 @@ static int32_t reconnectWiFi() delay(5000); if (!WiFi.isConnected()) { -#ifdef ARCH_ESP32 +#ifdef CONFIG_IDF_TARGET_ESP32C3 WiFi.mode(WIFI_MODE_NULL); WiFi.useStaticBuffers(true); WiFi.mode(WIFI_STA); diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 2a5ec00ab..c16c0e4b3 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -483,7 +483,7 @@ int32_t CannedMessageModule::runOnce() #if defined(USE_VIRTUAL_KEYBOARD) sendText(this->dest, indexChannels[this->channel], this->messages[this->currentMessageIndex], true); #else - sendText(NODENUM_BROADCAST, channels.getPrimaryIndex(), this->messages[this->currentMessageIndex], true); + sendText(this->dest, indexChannels[this->channel], this->messages[this->currentMessageIndex], true); #endif } this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE; @@ -1114,20 +1114,19 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st display->drawStringf(0 + x, 0 + y, buffer, "To: %s", cannedMessageModule->getNodeName(this->dest)); int lines = (display->getHeight() / FONT_HEIGHT_SMALL) - 1; if (lines == 3) { - // static (old) behavior for small displays - display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL, cannedMessageModule->getPrevMessage()); display->fillRect(0 + x, 0 + y + FONT_HEIGHT_SMALL * 2, x + display->getWidth(), y + FONT_HEIGHT_SMALL); display->setColor(BLACK); display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL * 2, cannedMessageModule->getCurrentMessage()); display->setColor(WHITE); - display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL * 3, cannedMessageModule->getNextMessage()); + if (this->messagesCount > 1) { + display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL, cannedMessageModule->getPrevMessage()); + display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL * 3, cannedMessageModule->getNextMessage()); + } } else { - // use entire display height for larger displays int topMsg = (messagesCount > lines && currentMessageIndex >= lines - 1) ? currentMessageIndex - lines + 2 : 0; for (int i = 0; i < std::min(messagesCount, lines); i++) { if (i == currentMessageIndex - topMsg) { #ifdef USE_EINK - // Avoid drawing solid black with fillRect: harder to clear for E-Ink display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL * (i + 1), ">"); display->drawString(12 + x, 0 + y + FONT_HEIGHT_SMALL * (i + 1), cannedMessageModule->getCurrentMessage()); @@ -1138,7 +1137,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL * (i + 1), cannedMessageModule->getCurrentMessage()); display->setColor(WHITE); #endif - } else { + } else if (messagesCount > 1) { // Only draw others if there are multiple messages display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL * (i + 1), cannedMessageModule->getMessageByIndex(topMsg + i)); } diff --git a/src/modules/ExternalNotificationModule.cpp b/src/modules/ExternalNotificationModule.cpp index bbb3f90e0..dc17460f6 100644 --- a/src/modules/ExternalNotificationModule.cpp +++ b/src/modules/ExternalNotificationModule.cpp @@ -28,6 +28,10 @@ #include #endif +#ifdef HAS_LP5562 +#include +#endif + #ifdef HAS_NEOPIXEL #include #endif @@ -37,10 +41,11 @@ extern unPhone unphone; #endif -#if defined(HAS_NCP5623) || defined(RGBLED_RED) || defined(HAS_NEOPIXEL) || defined(UNPHONE) +#if defined(HAS_RGB_LED) uint8_t red = 0; uint8_t green = 0; uint8_t blue = 0; +uint8_t white = 0; uint8_t colorState = 1; uint8_t brightnessIndex = 0; uint8_t brightnessValues[] = {0, 10, 20, 30, 50, 90, 160, 170}; // blue gets multiplied by 1.5 @@ -128,15 +133,21 @@ int32_t ExternalNotificationModule::runOnce() millis()); setExternalState(2, !getExternal(2)); } -#if defined(HAS_NCP5623) || defined(RGBLED_RED) || defined(HAS_NEOPIXEL) || defined(UNPHONE) +#if defined(HAS_RGB_LED) red = (colorState & 4) ? brightnessValues[brightnessIndex] : 0; // Red enabled on colorState = 4,5,6,7 green = (colorState & 2) ? brightnessValues[brightnessIndex] : 0; // Green enabled on colorState = 2,3,6,7 blue = (colorState & 1) ? (brightnessValues[brightnessIndex] * 1.5) : 0; // Blue enabled on colorState = 1,3,5,7 + white = (colorState & 12) ? brightnessValues[brightnessIndex] : 0; #ifdef HAS_NCP5623 if (rgb_found.type == ScanI2C::NCP5623) { rgb.setColor(red, green, blue); } #endif +#ifdef HAS_LP5562 + if (rgb_found.type == ScanI2C::LP5562) { + rgbw.setColor(red, green, blue, white); + } +#endif #ifdef RGBLED_CA analogWrite(RGBLED_RED, 255 - red); // CA type needs reverse logic analogWrite(RGBLED_GREEN, 255 - green); @@ -233,11 +244,12 @@ void ExternalNotificationModule::setExternalState(uint8_t index, bool on) break; } -#if defined(HAS_NCP5623) || defined(RGBLED_RED) || defined(HAS_NEOPIXEL) || defined(UNPHONE) +#if defined(HAS_RGB_LED) if (!on) { red = 0; green = 0; blue = 0; + white = 0; } #endif @@ -246,6 +258,11 @@ void ExternalNotificationModule::setExternalState(uint8_t index, bool on) rgb.setColor(red, green, blue); } #endif +#ifdef HAS_LP5562 + if (rgb_found.type == ScanI2C::LP5562) { + rgbw.setColor(red, green, blue, white); + } +#endif #ifdef RGBLED_CA analogWrite(RGBLED_RED, 255 - red); // CA type needs reverse logic analogWrite(RGBLED_GREEN, 255 - green); @@ -365,6 +382,12 @@ ExternalNotificationModule::ExternalNotificationModule() rgb.setCurrent(10); } #endif +#ifdef HAS_LP5562 + if (rgb_found.type == ScanI2C::LP5562) { + rgbw.begin(); + rgbw.setCurrent(20); + } +#endif #ifdef RGBLED_RED pinMode(RGBLED_RED, OUTPUT); // set up the RGB led pins pinMode(RGBLED_GREEN, OUTPUT); diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index a4050e702..6d0972dc3 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -247,7 +247,7 @@ void portduinoSetup() std::cerr << "autoconf: Unable to find config for " << autoconf_product << std::endl; exit(EXIT_FAILURE); } - if (loadConfig(("/etc/meshtasticd/available.d/" + product_config).c_str())) { + if (loadConfig((settingsStrings[available_directory] + product_config).c_str())) { std::cout << "autoconf: Using " << product_config << " as config file for " << autoconf_product << std::endl; } else { std::cerr << "autoconf: Unable to use " << product_config << " as config file for " << autoconf_product @@ -602,6 +602,8 @@ bool loadConfig(const char *configPath) settingsMap[maxnodes] = (yamlConfig["General"]["MaxNodes"]).as(200); settingsMap[maxtophone] = (yamlConfig["General"]["MaxMessageQueue"]).as(100); settingsStrings[config_directory] = (yamlConfig["General"]["ConfigDirectory"]).as(""); + settingsStrings[available_directory] = + (yamlConfig["General"]["AvailableDirectory"]).as("/etc/meshtasticd/available.d/"); if ((yamlConfig["General"]["MACAddress"]).as("") != "" && (yamlConfig["General"]["MACAddressSource"]).as("") != "") { std::cout << "Cannot set both MACAddress and MACAddressSource!" << std::endl; diff --git a/src/platform/portduino/PortduinoGlue.h b/src/platform/portduino/PortduinoGlue.h index a7aea1c3e..f7239cb73 100644 --- a/src/platform/portduino/PortduinoGlue.h +++ b/src/platform/portduino/PortduinoGlue.h @@ -11,6 +11,7 @@ inline const std::unordered_map configProducts = {{"MESHTOAD", "lora-usb-meshtoad-e22.yaml"}, {"MESHSTICK", "lora-meshstick-1262.yaml"}, {"MESHADV-PI", "lora-MeshAdv-900M30S.yaml"}, + {"MESHADV-MINI", "lora-MeshAdv-Mini-900M22S.yaml"}, {"POWERPI", "lora-MeshAdv-900M30S.yaml"}}; enum configNames { @@ -98,6 +99,7 @@ enum configNames { maxnodes, ascii_logs, config_directory, + available_directory, mac_address }; enum { no_screen, x11, st7789, st7735, st7735s, st7796, ili9341, ili9342, ili9486, ili9488, hx8357d }; diff --git a/test/test_crypto/test_main.cpp b/test/test_crypto/test_main.cpp index ac507116c..36dc37b9d 100644 --- a/test/test_crypto/test_main.cpp +++ b/test/test_crypto/test_main.cpp @@ -110,7 +110,7 @@ void test_DH25519(void) TEST_ASSERT_EQUAL_MEMORY(expected_shared, crypto->shared_key, 32); } -void test_PKC_Decrypt(void) +void test_PKC(void) { uint8_t private_key[32]; meshtastic_UserLite_public_key_t public_key; @@ -120,7 +120,8 @@ void test_PKC_Decrypt(void) uint8_t decrypted[128] __attribute__((__aligned__)); uint8_t expected_nonce[16]; - uint32_t fromNode; + uint32_t fromNode = 0x0929; + uint64_t packetNum = 0x13b2d662; HexToBytes(public_key.bytes, "db18fc50eea47f00251cb784819a3cf5fc361882597f589f0d7ff820e8064457"); public_key.size = 32; HexToBytes(private_key, "a00330633e63522f8a4d81ec6d9d1e6617f6c8ffd3a4c698229537d44e522277"); @@ -128,14 +129,26 @@ void test_PKC_Decrypt(void) HexToBytes(expected_decrypted, "08011204746573744800"); HexToBytes(radioBytes, "8c646d7a2909000062d6b2136b00000040df24abfcc30a17a3d9046726099e796a1c036a792b"); HexToBytes(expected_nonce, "62d6b213036a792b2909000000"); - fromNode = 0x0929; crypto->setDHPrivateKey(private_key); - // TEST_ASSERT(crypto->setDHPublicKey(public_key)); - // crypto->hash(crypto->shared_key, 32); - crypto->decryptCurve25519(fromNode, public_key, 0x13b2d662, 22, radioBytes + 16, decrypted); + + TEST_ASSERT(crypto->decryptCurve25519(fromNode, public_key, packetNum, 22, radioBytes + 16, decrypted)); TEST_ASSERT_EQUAL_MEMORY(expected_shared, crypto->shared_key, 8); TEST_ASSERT_EQUAL_MEMORY(expected_nonce, crypto->nonce, 13); + TEST_ASSERT_EQUAL_MEMORY(expected_decrypted, decrypted, 10); + uint32_t toNode = 0; // Only impacts logging + uint8_t encrypted[128] __attribute__((__aligned__)); + TEST_ASSERT(crypto->encryptCurve25519(toNode, fromNode, public_key, packetNum, 10, decrypted, encrypted)); + TEST_ASSERT_EQUAL_MEMORY(expected_shared, crypto->shared_key, 8); + // The extraNonce is random, so skip checking the nonce and encrypted output here + + // Copy the nonce to check it after encryption + memcpy(expected_nonce, crypto->nonce, 16); + + // Decrypt the re-encrypted bytes and check they are the same as what we expect + TEST_ASSERT(crypto->decryptCurve25519(fromNode, public_key, packetNum, 22, encrypted, decrypted)); + TEST_ASSERT_EQUAL_MEMORY(expected_shared, crypto->shared_key, 8); + TEST_ASSERT_EQUAL_MEMORY(expected_nonce, crypto->nonce, 13); TEST_ASSERT_EQUAL_MEMORY(expected_decrypted, decrypted, 10); } @@ -178,7 +191,7 @@ void setup() RUN_TEST(test_ECB_AES256); RUN_TEST(test_DH25519); RUN_TEST(test_AES_CTR); - RUN_TEST(test_PKC_Decrypt); + RUN_TEST(test_PKC); exit(UNITY_END()); // stop unit testing } diff --git a/variants/ELECROW-ThinkNode-M1/nicheGraphics.h b/variants/ELECROW-ThinkNode-M1/nicheGraphics.h new file mode 100644 index 000000000..f68ac9edd --- /dev/null +++ b/variants/ELECROW-ThinkNode-M1/nicheGraphics.h @@ -0,0 +1,119 @@ +#pragma once + +#include "configuration.h" + +#ifdef MESHTASTIC_INCLUDE_NICHE_GRAPHICS + +// InkHUD-specific components +// --------------------------- +#include "graphics/niche/InkHUD/InkHUD.h" + +// Applets +#include "graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.h" +#include "graphics/niche/InkHUD/Applets/User/DM/DMApplet.h" +#include "graphics/niche/InkHUD/Applets/User/Heard/HeardApplet.h" +#include "graphics/niche/InkHUD/Applets/User/Positions/PositionsApplet.h" +#include "graphics/niche/InkHUD/Applets/User/RecentsList/RecentsListApplet.h" +#include "graphics/niche/InkHUD/Applets/User/ThreadedMessage/ThreadedMessageApplet.h" + +// Shared NicheGraphics components +// -------------------------------- +#include "graphics/niche/Drivers/Backlight/LatchingBacklight.h" +#include "graphics/niche/Drivers/EInk/GDEY0154D67.h" +#include "graphics/niche/Inputs/TwoButton.h" + +#include "graphics/niche/Fonts/FreeSans6pt7b.h" +#include "graphics/niche/Fonts/FreeSans6pt8bCyrillic.h" +#include + +void setupNicheGraphics() +{ + using namespace NicheGraphics; + + // SPI + // ----------------------------- + + // For NRF52 platforms, SPI pins are defined in variant.h, not passed to begin() + SPI1.begin(); + + // Driver + // ----------------------------- + + // Use E-Ink driver + Drivers::EInk *driver = new Drivers::GDEY0154D67; // Todo: confirm display model + driver->begin(&SPI1, PIN_EINK_DC, PIN_EINK_CS, PIN_EINK_BUSY, PIN_EINK_RES); + + // InkHUD + // ---------------------------- + + InkHUD::InkHUD *inkhud = InkHUD::InkHUD::getInstance(); + + // Set the driver + inkhud->setDriver(driver); + + // Set how many FAST updates per FULL update + // Set how unhealthy additional FAST updates beyond this number are + // Todo: observe the display's performance in-person and adjust accordingly. + // Currently set to the values given by Elecrow for EInkDynamicDisplay. + inkhud->setDisplayResilience(10, 1.5); + + // Prepare fonts + InkHUD::Applet::fontLarge = InkHUD::AppletFont(FreeSans9pt7b); + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt7b); + /* + // Font localization demo: Cyrillic + InkHUD::Applet::fontSmall = InkHUD::AppletFont(FreeSans6pt8bCyrillic); + InkHUD::Applet::fontSmall.addSubstitutionsWin1251(); + */ + + // Customize default settings + inkhud->persistence->settings.userTiles.maxCount = 2; // Two applets side-by-side + inkhud->persistence->settings.rotation = 0; // To be confirmed? + inkhud->persistence->settings.optionalFeatures.batteryIcon = true; // Device definitely has a battery + + // Setup backlight + // Note: button mapping for this configured further down + Drivers::LatchingBacklight *backlight = Drivers::LatchingBacklight::getInstance(); + backlight->setPin(PIN_EINK_EN); + + // Pick applets + // Note: order of applets determines priority of "auto-show" feature + inkhud->addApplet("All Messages", new InkHUD::AllMessageApplet, true, true); // Activated, autoshown + inkhud->addApplet("DMs", new InkHUD::DMApplet); // Inactive + inkhud->addApplet("Channel 0", new InkHUD::ThreadedMessageApplet(0)); // Inactive + inkhud->addApplet("Channel 1", new InkHUD::ThreadedMessageApplet(1)); // Inactive + inkhud->addApplet("Positions", new InkHUD::PositionsApplet, true); // Activated + inkhud->addApplet("Recents List", new InkHUD::RecentsListApplet); // Inactive + inkhud->addApplet("Heard", new InkHUD::HeardApplet, true, false, 0); // Activated, no autoshow, default on tile 0 + + // Start running InkHUD + inkhud->begin(); + + // Buttons + // -------------------------- + + Inputs::TwoButton *buttons = Inputs::TwoButton::getInstance(); // Shared NicheGraphics component + + // As labeled on Elecrow diagram: https://www.elecrow.com/download/product/CIL12901M/ThinkNode-M1_User_Manual.pdf + constexpr uint8_t PAGE_TURN_BUTTON = 0; + constexpr uint8_t FUNCTION_BUTTON = 1; + + // Setup the main user button + buttons->setWiring(PAGE_TURN_BUTTON, PIN_BUTTON2); + buttons->setTiming(PAGE_TURN_BUTTON, 50, 500); // Todo: confirm 50ms is adequate debounce + buttons->setHandlerShortPress(PAGE_TURN_BUTTON, []() { InkHUD::InkHUD::getInstance()->shortpress(); }); + buttons->setHandlerLongPress(PAGE_TURN_BUTTON, []() { InkHUD::InkHUD::getInstance()->longpress(); }); + + // Setup the aux button + // Initial testing only: mapped to the backlight + // Todo: additional features + buttons->setWiring(FUNCTION_BUTTON, PIN_BUTTON1); + buttons->setTiming(FUNCTION_BUTTON, 50, 500); // 500ms before latch + buttons->setHandlerDown(FUNCTION_BUTTON, [backlight]() { backlight->peek(); }); + buttons->setHandlerLongPress(FUNCTION_BUTTON, [backlight]() { backlight->latch(); }); + buttons->setHandlerShortPress(FUNCTION_BUTTON, [backlight]() { backlight->off(); }); + + buttons->start(); +} + +#endif \ No newline at end of file diff --git a/variants/ELECROW-ThinkNode-M1/platformio.ini b/variants/ELECROW-ThinkNode-M1/platformio.ini index f37f6d310..86fbde398 100644 --- a/variants/ELECROW-ThinkNode-M1/platformio.ini +++ b/variants/ELECROW-ThinkNode-M1/platformio.ini @@ -10,6 +10,7 @@ build_flags = ${nrf52840_base.build_flags} -Ivariants/ELECROW-ThinkNode-M1 -DELECROW_ThinkNode_M1 -DGPS_POWER_TOGGLE -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard" + -DUSE_EINK -DEINK_DISPLAY_MODEL=GxEPD2_154_D67 -DEINK_WIDTH=200 -DEINK_HEIGHT=200 @@ -26,4 +27,23 @@ lib_deps = https://github.com/meshtastic/GxEPD2/archive/33db3fa8ee6fc47d160bdb44f8f127c9a9203a10.zip lewisxhe/PCF8563_Library@^1.0.1 khoih-prog/nRF52_PWM@^1.0.1 -;upload_protocol = fs \ No newline at end of file +;upload_protocol = fs + +[env:thinknode_m1-inkhud] +extends = nrf52840_base, inkhud +board = ThinkNode-M1 +board_check = true +debug_tool = jlink +build_flags = + ${nrf52840_base.build_flags} + ${inkhud.build_flags} + -I variants/ELECROW-ThinkNode-M1 + -D ELECROW_ThinkNode_M1 + -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard" +build_src_filter = + ${nrf52_base.build_src_filter} + ${inkhud.build_src_filter} +lib_deps = + ${inkhud.lib_deps} ; InkHUD libs first, so we get GFXRoot instead of AdafruitGFX + ${nrf52840_base.lib_deps} + lewisxhe/PCF8563_Library@^1.0.1 \ No newline at end of file diff --git a/variants/ELECROW-ThinkNode-M1/variant.h b/variants/ELECROW-ThinkNode-M1/variant.h index 3bfa360f6..fc2fddbdf 100644 --- a/variants/ELECROW-ThinkNode-M1/variant.h +++ b/variants/ELECROW-ThinkNode-M1/variant.h @@ -140,8 +140,6 @@ External serial flash WP25R1635FZUIL0 // Controls power for all peripherals (eink + GPS + LoRa + Sensor) #define PIN_POWER_EN (0 + 12) -#define USE_EINK - #define PIN_SPI1_MISO (32 + 7) #define PIN_SPI1_MOSI PIN_EINK_MOSI #define PIN_SPI1_SCK PIN_EINK_SCLK diff --git a/variants/heltec_vision_master_e213/nicheGraphics.h b/variants/heltec_vision_master_e213/nicheGraphics.h index 75e4423be..d6983bafe 100644 --- a/variants/heltec_vision_master_e213/nicheGraphics.h +++ b/variants/heltec_vision_master_e213/nicheGraphics.h @@ -95,7 +95,7 @@ void setupNicheGraphics() constexpr uint8_t AUX_BUTTON = 1; // Setup the main user button - buttons->setWiring(MAIN_BUTTON, BUTTON_PIN); + buttons->setWiring(MAIN_BUTTON, Inputs::TwoButton::getUserButtonPin()); buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->shortpress(); }); buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->longpress(); }); diff --git a/variants/heltec_vision_master_e290/nicheGraphics.h b/variants/heltec_vision_master_e290/nicheGraphics.h index 2674436b8..c2f26c7ff 100644 --- a/variants/heltec_vision_master_e290/nicheGraphics.h +++ b/variants/heltec_vision_master_e290/nicheGraphics.h @@ -19,7 +19,7 @@ Different NicheGraphics UIs and different hardware variants will each have their // InkHUD-specific components // --------------------------- -#include "graphics/niche/InkHUD/WindowManager.h" +#include "graphics/niche/InkHUD/InkHUD.h" // Applets #include "graphics/niche/InkHUD/Applets/User/AllMessage/AllMessageApplet.h" @@ -113,7 +113,7 @@ void setupNicheGraphics() Inputs::TwoButton *buttons = Inputs::TwoButton::getInstance(); // A shared NicheGraphics component // Setup the main user button (0) - buttons->setWiring(0, BUTTON_PIN); + buttons->setWiring(0, Inputs::TwoButton::getUserButtonPin()); buttons->setHandlerShortPress(0, []() { InkHUD::InkHUD::getInstance()->shortpress(); }); buttons->setHandlerLongPress(0, []() { InkHUD::InkHUD::getInstance()->longpress(); }); diff --git a/variants/heltec_wireless_paper/nicheGraphics.h b/variants/heltec_wireless_paper/nicheGraphics.h index ece4225d0..5e938fa64 100644 --- a/variants/heltec_wireless_paper/nicheGraphics.h +++ b/variants/heltec_wireless_paper/nicheGraphics.h @@ -93,7 +93,7 @@ void setupNicheGraphics() constexpr uint8_t MAIN_BUTTON = 0; // Setup the main user button - buttons->setWiring(MAIN_BUTTON, BUTTON_PIN); + buttons->setWiring(MAIN_BUTTON, Inputs::TwoButton::getUserButtonPin()); buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->shortpress(); }); buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->longpress(); }); diff --git a/variants/t-echo/nicheGraphics.h b/variants/t-echo/nicheGraphics.h index e8a9232f1..f5dde6b19 100644 --- a/variants/t-echo/nicheGraphics.h +++ b/variants/t-echo/nicheGraphics.h @@ -104,7 +104,7 @@ void setupNicheGraphics() constexpr uint8_t TOUCH_BUTTON = 1; // Setup the main user button - buttons->setWiring(MAIN_BUTTON, BUTTON_PIN, LOW); + buttons->setWiring(MAIN_BUTTON, Inputs::TwoButton::getUserButtonPin()); buttons->setTiming(MAIN_BUTTON, 75, 500); buttons->setHandlerShortPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->shortpress(); }); buttons->setHandlerLongPress(MAIN_BUTTON, []() { InkHUD::InkHUD::getInstance()->longpress(); }); diff --git a/variants/tbeam/platformio.ini b/variants/tbeam/platformio.ini index 85e66c2dd..9049836a3 100644 --- a/variants/tbeam/platformio.ini +++ b/variants/tbeam/platformio.ini @@ -8,4 +8,6 @@ lib_deps = build_flags = ${esp32_base.build_flags} -D TBEAM_V10 -I variants/tbeam -DGPS_POWER_TOGGLE ; comment this line to disable double press function on the user button to turn off gps entirely. + -DBOARD_HAS_PSRAM + -mfix-esp32-psram-cache-issue upload_speed = 921600 \ No newline at end of file diff --git a/variants/unphone/platformio.ini b/variants/unphone/platformio.ini index 18efbb157..399d65b03 100644 --- a/variants/unphone/platformio.ini +++ b/variants/unphone/platformio.ini @@ -35,19 +35,19 @@ lib_deps = ${esp32s3_base.lib_deps} extends = env:unphone build_flags = ${env:unphone.build_flags} + -D CONFIG_DISABLE_HAL_LOCKS=1 -D MESHTASTIC_EXCLUDE_CANNEDMESSAGES=1 -D MESHTASTIC_EXCLUDE_INPUTBROKER=1 - -D MESHTASTIC_EXCLUDE_BLUETOOTH=1 -D MESHTASTIC_EXCLUDE_WEBSERVER=1 -D MESHTASTIC_EXCLUDE_SERIAL=1 -D MESHTASTIC_EXCLUDE_SOCKETAPI=1 -D INPUTDRIVER_BUTTON_TYPE=21 - -D MAX_THREADS=40 -D HAS_SCREEN=0 -D HAS_TFT=1 -D HAS_SDCARD -D DISPLAY_SET_RESOLUTION - -D RAM_SIZE=3072 + -D RAM_SIZE=6144 + -D LV_CACHE_DEF_SIZE=2097152 -D LV_LVGL_H_INCLUDE_SIMPLE -D LV_CONF_INCLUDE_SIMPLE -D LV_COMP_CONF_INCLUDE_SIMPLE @@ -63,6 +63,7 @@ build_flags = -D GFX_DRIVER_INC=\"graphics/LGFX/LGFX_UNPHONE.h\" -D VIEW_320x240 -D USE_PACKET_API + -D MAP_FULL_REDRAW lib_deps = ${env:unphone.lib_deps}