From d017fc7a5d392eb35b197c104a33ab2c533bc6ea Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 21 Aug 2024 16:53:12 -0700 Subject: [PATCH 01/40] for #4154 use internal pull-ups to power ADC_Ctrl * Currently only on heltec tracker, but could use ADC_USE_PULLUP on other boards that could benefit * Thanks @todd-herbert and @StevenCellist for the instructions ;-) * Remove nasty Heltec_wireless #ifdefs that got somehow added to Power.cpp, instead use proper variant defs * Cleanup adc enable/disable code a bit for less copy-paste cruft --- src/Power.cpp | 60 ++++++++++----------- variants/heltec_wireless_paper/variant.h | 3 +- variants/heltec_wireless_paper_v1/variant.h | 3 +- variants/heltec_wireless_tracker/variant.h | 6 +-- 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index d63c43137e..61a6c987d4 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -136,6 +136,30 @@ using namespace meshtastic; */ static HasBatteryLevel *batteryLevel; // Default to NULL for no battery level sensor +static void adcEnable() +{ +#ifdef ADC_CTRL // enable adc voltage divider when we need to read +#ifdef ADC_USE_PULLUP + pinMode(ADC_CTRL, INPUT_PULLUP); +#else + pinMode(ADC_CTRL, OUTPUT); + digitalWrite(ADC_CTRL, ADC_CTRL_ENABLED); +#endif + delay(10); +#endif +} + +static void adcDisable() +{ +#ifdef ADC_CTRL // disable adc voltage divider when we need to read +#ifdef ADC_USE_PULLUP + pinMode(ADC_CTRL, INPUT_PULLDOWN); +#else + digitalWrite(ADC_CTRL, !ADC_CTRL_ENABLED); +#endif +#endif +} + /** * A simple battery level sensor that assumes the battery voltage is attached via a voltage-divider to an analog input */ @@ -226,25 +250,19 @@ class AnalogBatteryLevel : public HasBatteryLevel uint32_t raw = 0; float scaled = 0; + adcEnable(); #ifdef ARCH_ESP32 // ADC block for espressif platforms raw = espAdcRead(); scaled = esp_adc_cal_raw_to_voltage(raw, adc_characs); scaled *= operativeAdcMultiplier; -#else // block for all other platforms -#ifdef ADC_CTRL // enable adc voltage divider when we need to read - pinMode(ADC_CTRL, OUTPUT); - digitalWrite(ADC_CTRL, ADC_CTRL_ENABLED); - delay(10); -#endif +#else // block for all other platforms for (uint32_t i = 0; i < BATTERY_SENSE_SAMPLES; i++) { raw += analogRead(BATTERY_PIN); } raw = raw / BATTERY_SENSE_SAMPLES; scaled = operativeAdcMultiplier * ((1000 * AREF_VOLTAGE) / pow(2, BATTERY_SENSE_RESOLUTION_BITS)) * raw; -#ifdef ADC_CTRL // disable adc voltage divider when we need to read - digitalWrite(ADC_CTRL, !ADC_CTRL_ENABLED); -#endif #endif + adcDisable(); if (!initial_read_done) { // Flush the smoothing filter with an ADC reading, if the reading is plausibly correct @@ -275,11 +293,6 @@ class AnalogBatteryLevel : public HasBatteryLevel uint8_t raw_c = 0; // raw reading counter #ifndef BAT_MEASURE_ADC_UNIT // ADC1 -#ifdef ADC_CTRL // enable adc voltage divider when we need to read - pinMode(ADC_CTRL, OUTPUT); - digitalWrite(ADC_CTRL, ADC_CTRL_ENABLED); - delay(10); -#endif for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) { int val_ = adc1_get_raw(adc_channel); if (val_ >= 0) { // save only valid readings @@ -288,18 +301,7 @@ class AnalogBatteryLevel : public HasBatteryLevel } // delayMicroseconds(100); } -#ifdef ADC_CTRL // disable adc voltage divider when we need to read - digitalWrite(ADC_CTRL, !ADC_CTRL_ENABLED); -#endif -#else // ADC2 -#ifdef ADC_CTRL -#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) - pinMode(ADC_CTRL, OUTPUT); - digitalWrite(ADC_CTRL, LOW); // ACTIVE LOW - delay(10); -#endif -#endif // End ADC_CTRL - +#else // ADC2 #ifdef CONFIG_IDF_TARGET_ESP32S3 // ESP32S3 // ADC2 wifi bug workaround not required, breaks compile // On ESP32S3, ADC2 can take turns with Wifi (?) @@ -334,12 +336,6 @@ class AnalogBatteryLevel : public HasBatteryLevel } #endif // BAT_MEASURE_ADC_UNIT -#ifdef ADC_CTRL -#if defined(HELTEC_WIRELESS_PAPER) || defined(HELTEC_WIRELESS_PAPER_V1_0) - digitalWrite(ADC_CTRL, HIGH); -#endif -#endif // End ADC_CTRL - #endif // End BAT_MEASURE_ADC_UNIT return (raw / (raw_c < 1 ? 1 : raw_c)); } diff --git a/variants/heltec_wireless_paper/variant.h b/variants/heltec_wireless_paper/variant.h index a7bd460f79..36ab804453 100644 --- a/variants/heltec_wireless_paper/variant.h +++ b/variants/heltec_wireless_paper/variant.h @@ -29,6 +29,7 @@ #define BAT_MEASURE_ADC_UNIT 2 // Use ADC2 #define ADC_ATTENUATION ADC_ATTEN_DB_12 // Voltage divider output is quite high #define HAS_32768HZ +#define ADC_CTRL_ENABLED LOW // LoRa #define USE_SX1262 @@ -49,4 +50,4 @@ #define SX126X_RESET LORA_RESET #define SX126X_DIO2_AS_RF_SWITCH -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 \ No newline at end of file diff --git a/variants/heltec_wireless_paper_v1/variant.h b/variants/heltec_wireless_paper_v1/variant.h index a7bd460f79..36ab804453 100644 --- a/variants/heltec_wireless_paper_v1/variant.h +++ b/variants/heltec_wireless_paper_v1/variant.h @@ -29,6 +29,7 @@ #define BAT_MEASURE_ADC_UNIT 2 // Use ADC2 #define ADC_ATTENUATION ADC_ATTEN_DB_12 // Voltage divider output is quite high #define HAS_32768HZ +#define ADC_CTRL_ENABLED LOW // LoRa #define USE_SX1262 @@ -49,4 +50,4 @@ #define SX126X_RESET LORA_RESET #define SX126X_DIO2_AS_RF_SWITCH -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 \ No newline at end of file diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index 685c9f0795..a2ca095d86 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -38,8 +38,8 @@ #define ADC_CHANNEL ADC1_GPIO1_CHANNEL #define ADC_ATTENUATION ADC_ATTEN_DB_2_5 // lower dB for high resistance voltage divider #define ADC_MULTIPLIER 4.9 * 1.045 -#define ADC_CTRL 2 // active HIGH, powers the voltage divider. Only on 1.1 -#define ADC_CTRL_ENABLED HIGH +#define ADC_CTRL 2 // active HIGH, powers the voltage divider. Only on 1.1 +#define ADC_USE_PULLUP // Use internal pullup/pulldown instead of actively driving the output #undef GPS_RX_PIN #undef GPS_TX_PIN @@ -72,4 +72,4 @@ #define SX126X_RESET LORA_RESET #define SX126X_DIO2_AS_RF_SWITCH -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 \ No newline at end of file From 7fb9b094d522fefb41c8e13ee8de8cf526b8b227 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 08:59:46 -0700 Subject: [PATCH 02/40] Remove redundant ST7735_BL variant defs. No need for _V05 and _V03 definitions - I think there was a slight misunderstanding on how variant files are supposed to _decrease_ #ifdef code in the cpp files. --- src/graphics/TFTDisplay.cpp | 32 ++++++------------- src/main.cpp | 6 +--- src/sleep.cpp | 1 - variants/heltec_wireless_tracker/variant.h | 2 +- .../heltec_wireless_tracker_V1_0/variant.h | 4 +-- variants/tracksenger/internal/variant.h | 2 +- variants/tracksenger/lcd/variant.h | 4 +-- variants/tracksenger/oled/variant.h | 2 +- 8 files changed, 18 insertions(+), 35 deletions(-) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 8ea90c5232..73ad4d1302 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -95,14 +95,8 @@ class LGFX : public lgfx::LGFX_Device { auto cfg = _light_instance.config(); // Gets a structure for backlight settings. -#ifdef ST7735_BL_V03 - cfg.pin_bl = ST7735_BL_V03; -#elif defined(ST7735_BL_V05) - cfg.pin_bl = ST7735_BL_V05; -#else cfg.pin_bl = ST7735_BL; // Pin number to which the backlight is connected -#endif - cfg.invert = true; // true to invert the brightness of the backlight + cfg.invert = true; // true to invert the brightness of the backlight // cfg.freq = 44100; // PWM frequency of backlight // cfg.pwm_channel = 1; // PWM channel number to use @@ -581,11 +575,9 @@ void TFTDisplay::sendCommand(uint8_t com) display(true); if (settingsMap[displayBacklight] > 0) digitalWrite(settingsMap[displayBacklight], TFT_BACKLIGHT_ON); -#elif defined(ST7735_BL_V03) - digitalWrite(ST7735_BL_V03, TFT_BACKLIGHT_ON); -#elif defined(ST7735_BL_V05) - pinMode(ST7735_BL_V05, OUTPUT); - digitalWrite(ST7735_BL_V05, TFT_BACKLIGHT_ON); +#elif defined(ST7735_BL) + pinMode(ST7735_BL, OUTPUT); + digitalWrite(ST7735_BL, TFT_BACKLIGHT_ON); #elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) tft->wakeup(); tft->powerSaveOff(); @@ -614,11 +606,9 @@ void TFTDisplay::sendCommand(uint8_t com) tft->clear(); if (settingsMap[displayBacklight] > 0) digitalWrite(settingsMap[displayBacklight], !TFT_BACKLIGHT_ON); -#elif defined(ST7735_BL_V03) - digitalWrite(ST7735_BL_V03, !TFT_BACKLIGHT_ON); -#elif defined(ST7735_BL_V05) - pinMode(ST7735_BL_V05, OUTPUT); - digitalWrite(ST7735_BL_V05, !TFT_BACKLIGHT_ON); +#elif defined(ST7735_BL) + pinMode(ST7735_BL, OUTPUT); + digitalWrite(ST7735_BL, !TFT_BACKLIGHT_ON); #elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) tft->sleep(); tft->powerSaveOn(); @@ -720,11 +710,9 @@ bool TFTDisplay::connect() LOG_INFO("Power to TFT Backlight\n"); #endif -#ifdef ST7735_BL_V03 - digitalWrite(ST7735_BL_V03, TFT_BACKLIGHT_ON); -#elif defined(ST7735_BL_V05) - pinMode(ST7735_BL_V05, OUTPUT); - digitalWrite(ST7735_BL_V05, TFT_BACKLIGHT_ON); +#ifdef ST7735_BL + pinMode(ST7735_BL, OUTPUT); + digitalWrite(ST7735_BL, TFT_BACKLIGHT_ON); #endif #ifdef UNPHONE unphone.backlight(true); // using unPhone library diff --git a/src/main.cpp b/src/main.cpp index d38b4e669e..968ee60534 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -280,15 +280,11 @@ void setup() #if defined(VEXT_ENABLE_V03) pinMode(VEXT_ENABLE_V03, OUTPUT); - pinMode(ST7735_BL_V03, OUTPUT); digitalWrite(VEXT_ENABLE_V03, 0); // turn on the display power and antenna boost - digitalWrite(ST7735_BL_V03, 1); // display backligth on LOG_DEBUG("HELTEC Detect Tracker V1.0\n"); #elif defined(VEXT_ENABLE_V05) pinMode(VEXT_ENABLE_V05, OUTPUT); - pinMode(ST7735_BL_V05, OUTPUT); digitalWrite(VEXT_ENABLE_V05, 1); // turn on the lora antenna boost - digitalWrite(ST7735_BL_V05, 1); // turn on display backligth LOG_DEBUG("HELTEC Detect Tracker V1.1\n"); #elif defined(VEXT_ENABLE) && defined(VEXT_ON_VALUE) pinMode(VEXT_ENABLE, OUTPUT); @@ -1149,4 +1145,4 @@ void loop() } // if (didWake) LOG_DEBUG("wake!\n"); } -#endif +#endif \ No newline at end of file diff --git a/src/sleep.cpp b/src/sleep.cpp index bf50d8ffa7..693d02a292 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -250,7 +250,6 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) digitalWrite(VEXT_ENABLE_V03, 1); // turn off the display power #elif defined(VEXT_ENABLE_V05) digitalWrite(VEXT_ENABLE_V05, 0); // turn off the lora amplifier power - digitalWrite(ST7735_BL_V05, 0); // turn off the display power #elif defined(VEXT_ENABLE) && defined(VEXT_ON_VALUE) digitalWrite(VEXT_ENABLE, !VEXT_ON_VALUE); // turn on the display power #elif defined(VEXT_ENABLE) diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index a2ca095d86..f10612601d 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -15,7 +15,7 @@ #define ST7735_RESET 39 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL_V05 21 /* V1.1 PCB marking */ +#define ST7735_BL 21 /* V1.1 PCB marking */ #define ST7735_SPI_HOST SPI3_HOST #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 diff --git a/variants/heltec_wireless_tracker_V1_0/variant.h b/variants/heltec_wireless_tracker_V1_0/variant.h index 23987adf02..e972191638 100644 --- a/variants/heltec_wireless_tracker_V1_0/variant.h +++ b/variants/heltec_wireless_tracker_V1_0/variant.h @@ -15,7 +15,7 @@ #define ST7735_RESET 39 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL_V03 45 +#define ST7735_BL 45 #define ST7735_SPI_HOST SPI3_HOST #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 @@ -69,4 +69,4 @@ #define SX126X_RESET LORA_RESET #define SX126X_DIO2_AS_RF_SWITCH -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 \ No newline at end of file diff --git a/variants/tracksenger/internal/variant.h b/variants/tracksenger/internal/variant.h index 929c387930..75d81752b6 100644 --- a/variants/tracksenger/internal/variant.h +++ b/variants/tracksenger/internal/variant.h @@ -17,7 +17,7 @@ #define ST7735_RESET 39 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL_V05 21 /* V1.1 PCB marking */ +#define ST7735_BL 21 /* V1.1 PCB marking */ #define ST7735_SPI_HOST SPI3_HOST #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 diff --git a/variants/tracksenger/lcd/variant.h b/variants/tracksenger/lcd/variant.h index 3f952361bb..7e814de680 100644 --- a/variants/tracksenger/lcd/variant.h +++ b/variants/tracksenger/lcd/variant.h @@ -16,7 +16,7 @@ #define ST7789_CS 38 #define ST7789_RS 40 #define ST7789_BL 21 -// P#define ST7735_BL_V05 21 /* V1.1 PCB marking */ +// P#define ST7735_BL 21 /* V1.1 PCB marking */ #define ST7789_RESET -1 #define ST7789_MISO -1 @@ -41,7 +41,7 @@ // #define ST7735_RESET 39 // #define ST7735_MISO -1 // #define ST7735_BUSY -1 -#define ST7735_BL_V05 21 /* V1.1 PCB marking */ +#define ST7735_BL 21 /* V1.1 PCB marking */ // #define ST7735_SPI_HOST SPI3_HOST // #define SPI_FREQUENCY 40000000 // #define SPI_READ_FREQUENCY 16000000 diff --git a/variants/tracksenger/oled/variant.h b/variants/tracksenger/oled/variant.h index 99f12bd233..10bd7358be 100644 --- a/variants/tracksenger/oled/variant.h +++ b/variants/tracksenger/oled/variant.h @@ -19,7 +19,7 @@ // #define ST7735_RESET 39 // #define ST7735_MISO -1 // #define ST7735_BUSY -1 -#define ST7735_BL_V05 21 /* V1.1 PCB marking */ +#define ST7735_BL 21 /* V1.1 PCB marking */ // #define ST7735_SPI_HOST SPI3_HOST // #define SPI_FREQUENCY 40000000 // #define SPI_READ_FREQUENCY 16000000 From 3ae8aadaf0214d86c20842b3e67eed4bb0056ed1 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 09:15:59 -0700 Subject: [PATCH 03/40] Merge the three redundant backlight enables into the single TFT_BL flag --- src/graphics/TFTDisplay.cpp | 30 +++++++------------ variants/chatter2/variant.h | 2 +- variants/heltec_wireless_tracker/variant.h | 2 +- .../heltec_wireless_tracker_V1_0/variant.h | 2 +- variants/lora_relay_v1/variant.h | 4 +-- variants/lora_relay_v2/variant.h | 4 +-- variants/tracksenger/internal/variant.h | 4 +-- variants/tracksenger/lcd/variant.h | 6 ++-- variants/tracksenger/oled/variant.h | 2 +- 9 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 73ad4d1302..d20733e906 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -21,10 +21,6 @@ extern SX1509 gpioExtender; #if defined(ST7735S) #include // Graphics and font library for ST7735 driver chip -#if defined(ST7735_BACKLIGHT_EN) && !defined(TFT_BL) -#define TFT_BL ST7735_BACKLIGHT_EN -#endif - #ifndef TFT_INVERT #define TFT_INVERT true #endif @@ -91,18 +87,20 @@ class LGFX : public lgfx::LGFX_Device _panel_instance.config(cfg); } +#ifdef TFT_BL // Set the backlight control { auto cfg = _light_instance.config(); // Gets a structure for backlight settings. - cfg.pin_bl = ST7735_BL; // Pin number to which the backlight is connected - cfg.invert = true; // true to invert the brightness of the backlight + cfg.pin_bl = TFT_BL; // Pin number to which the backlight is connected + cfg.invert = true; // true to invert the brightness of the backlight // cfg.freq = 44100; // PWM frequency of backlight // cfg.pwm_channel = 1; // PWM channel number to use _light_instance.config(cfg); _panel_instance.setLight(&_light_instance); // Set the backlight on the panel. } +#endif setPanel(&_panel_instance); } @@ -575,14 +573,12 @@ void TFTDisplay::sendCommand(uint8_t com) display(true); if (settingsMap[displayBacklight] > 0) digitalWrite(settingsMap[displayBacklight], TFT_BACKLIGHT_ON); -#elif defined(ST7735_BL) - pinMode(ST7735_BL, OUTPUT); - digitalWrite(ST7735_BL, TFT_BACKLIGHT_ON); +#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) + pinMode(TFT_BL, OUTPUT); + digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); #elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) tft->wakeup(); tft->powerSaveOff(); -#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) - digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); #endif #ifdef VTFT_CTRL_V03 @@ -606,14 +602,12 @@ void TFTDisplay::sendCommand(uint8_t com) tft->clear(); if (settingsMap[displayBacklight] > 0) digitalWrite(settingsMap[displayBacklight], !TFT_BACKLIGHT_ON); -#elif defined(ST7735_BL) - pinMode(ST7735_BL, OUTPUT); - digitalWrite(ST7735_BL, !TFT_BACKLIGHT_ON); +#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) + pinMode(TFT_BL, OUTPUT); + digitalWrite(TFT_BL, !TFT_BACKLIGHT_ON); #elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) tft->sleep(); tft->powerSaveOn(); -#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) - digitalWrite(TFT_BL, !TFT_BACKLIGHT_ON); #endif #ifdef VTFT_CTRL_V03 @@ -710,10 +704,6 @@ bool TFTDisplay::connect() LOG_INFO("Power to TFT Backlight\n"); #endif -#ifdef ST7735_BL - pinMode(ST7735_BL, OUTPUT); - digitalWrite(ST7735_BL, TFT_BACKLIGHT_ON); -#endif #ifdef UNPHONE unphone.backlight(true); // using unPhone library LOG_INFO("Power to TFT Backlight\n"); diff --git a/variants/chatter2/variant.h b/variants/chatter2/variant.h index 70438e52ac..b7f9469708 100644 --- a/variants/chatter2/variant.h +++ b/variants/chatter2/variant.h @@ -54,7 +54,7 @@ #define ST7735_RESET 15 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL 32 +#define TFT_BL 32 #define ST7735_SPI_HOST HSPI_HOST // SPI2_HOST for S3, auto may work too #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index f10612601d..519c76d8f9 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -15,7 +15,7 @@ #define ST7735_RESET 39 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL 21 /* V1.1 PCB marking */ +#define TFT_BL 21 /* V1.1 PCB marking */ #define ST7735_SPI_HOST SPI3_HOST #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 diff --git a/variants/heltec_wireless_tracker_V1_0/variant.h b/variants/heltec_wireless_tracker_V1_0/variant.h index e972191638..b638dec535 100644 --- a/variants/heltec_wireless_tracker_V1_0/variant.h +++ b/variants/heltec_wireless_tracker_V1_0/variant.h @@ -15,7 +15,7 @@ #define ST7735_RESET 39 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL 45 +#define TFT_BL 45 #define ST7735_SPI_HOST SPI3_HOST #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 diff --git a/variants/lora_relay_v1/variant.h b/variants/lora_relay_v1/variant.h index 54bc87b68a..6efd711c6c 100644 --- a/variants/lora_relay_v1/variant.h +++ b/variants/lora_relay_v1/variant.h @@ -144,7 +144,7 @@ static const uint8_t SCK = PIN_SPI_SCK; #define ST7735_RESET (11) // Output #define ST7735_CS (12) -#define ST7735_BACKLIGHT_EN (13) +#define TFT_BL (13) #define ST7735_RS (9) // #define LORA_DISABLE_SENDING // The board can brownout during lora TX if you don't have a battery connected. Disable sending @@ -158,4 +158,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif +#endif \ No newline at end of file diff --git a/variants/lora_relay_v2/variant.h b/variants/lora_relay_v2/variant.h index 6ef7ad7d6b..f18f810345 100644 --- a/variants/lora_relay_v2/variant.h +++ b/variants/lora_relay_v2/variant.h @@ -166,7 +166,7 @@ static const uint8_t SCK = PIN_SPI_SCK; // ST7565 SPI #define ST7735_RESET (11) // Output #define ST7735_CS (12) -#define ST7735_BACKLIGHT_EN (13) +#define TFT_BL (13) #define ST7735_RS (9) #define ST7735_SDA (39) // actually spi MOSI #define ST7735_SCK (37) // actually spi clk @@ -185,4 +185,4 @@ static const uint8_t SCK = PIN_SPI_SCK; * Arduino objects - C++ only *----------------------------------------------------------------------------*/ -#endif +#endif \ No newline at end of file diff --git a/variants/tracksenger/internal/variant.h b/variants/tracksenger/internal/variant.h index 75d81752b6..bd4a51a2da 100644 --- a/variants/tracksenger/internal/variant.h +++ b/variants/tracksenger/internal/variant.h @@ -17,7 +17,7 @@ #define ST7735_RESET 39 #define ST7735_MISO -1 #define ST7735_BUSY -1 -#define ST7735_BL 21 /* V1.1 PCB marking */ +#define TFT_BL 21 /* V1.1 PCB marking */ #define ST7735_SPI_HOST SPI3_HOST #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 @@ -88,4 +88,4 @@ { \ 26, 37, 17, 16, 15, 7 \ } -// #end keyboard +// #end keyboard \ No newline at end of file diff --git a/variants/tracksenger/lcd/variant.h b/variants/tracksenger/lcd/variant.h index 7e814de680..17b012ae74 100644 --- a/variants/tracksenger/lcd/variant.h +++ b/variants/tracksenger/lcd/variant.h @@ -16,7 +16,7 @@ #define ST7789_CS 38 #define ST7789_RS 40 #define ST7789_BL 21 -// P#define ST7735_BL 21 /* V1.1 PCB marking */ +// P#define TFT_BL 21 /* V1.1 PCB marking */ #define ST7789_RESET -1 #define ST7789_MISO -1 @@ -41,7 +41,7 @@ // #define ST7735_RESET 39 // #define ST7735_MISO -1 // #define ST7735_BUSY -1 -#define ST7735_BL 21 /* V1.1 PCB marking */ +#define TFT_BL 21 /* V1.1 PCB marking */ // #define ST7735_SPI_HOST SPI3_HOST // #define SPI_FREQUENCY 40000000 // #define SPI_READ_FREQUENCY 16000000 @@ -112,4 +112,4 @@ { \ 26, 37, 17, 16, 15, 7 \ } -// #end keyboard +// #end keyboard \ No newline at end of file diff --git a/variants/tracksenger/oled/variant.h b/variants/tracksenger/oled/variant.h index 10bd7358be..e6e28e459c 100644 --- a/variants/tracksenger/oled/variant.h +++ b/variants/tracksenger/oled/variant.h @@ -19,7 +19,7 @@ // #define ST7735_RESET 39 // #define ST7735_MISO -1 // #define ST7735_BUSY -1 -#define ST7735_BL 21 /* V1.1 PCB marking */ +#define TFT_BL 21 /* V1.1 PCB marking */ // #define ST7735_SPI_HOST SPI3_HOST // #define SPI_FREQUENCY 40000000 // #define SPI_READ_FREQUENCY 16000000 From 5ccb6df142a3136be813f0c0e98f2c0a72b779ca Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 09:28:41 -0700 Subject: [PATCH 04/40] Remove all sorts of redundant VEXT_ENABLE ifdefs --- src/graphics/TFTDisplay.cpp | 7 ------- src/main.cpp | 18 +----------------- src/sleep.cpp | 8 +------- variants/heltec_wireless_tracker/variant.h | 3 ++- .../heltec_wireless_tracker_V1_0/variant.h | 5 +++-- variants/tracksenger/internal/variant.h | 3 ++- variants/tracksenger/lcd/variant.h | 3 ++- variants/tracksenger/oled/variant.h | 5 +++-- 8 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index d20733e906..0e203a9d69 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -581,10 +581,6 @@ void TFTDisplay::sendCommand(uint8_t com) tft->powerSaveOff(); #endif -#ifdef VTFT_CTRL_V03 - digitalWrite(VTFT_CTRL_V03, LOW); -#endif - #ifdef VTFT_CTRL digitalWrite(VTFT_CTRL, LOW); #endif @@ -610,9 +606,6 @@ void TFTDisplay::sendCommand(uint8_t com) tft->powerSaveOn(); #endif -#ifdef VTFT_CTRL_V03 - digitalWrite(VTFT_CTRL_V03, HIGH); -#endif #ifdef VTFT_CTRL digitalWrite(VTFT_CTRL, HIGH); #endif diff --git a/src/main.cpp b/src/main.cpp index 968ee60534..7520667dd6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -278,25 +278,9 @@ void setup() digitalWrite(LORA_TCXO_GPIO, HIGH); #endif -#if defined(VEXT_ENABLE_V03) - pinMode(VEXT_ENABLE_V03, OUTPUT); - digitalWrite(VEXT_ENABLE_V03, 0); // turn on the display power and antenna boost - LOG_DEBUG("HELTEC Detect Tracker V1.0\n"); -#elif defined(VEXT_ENABLE_V05) - pinMode(VEXT_ENABLE_V05, OUTPUT); - digitalWrite(VEXT_ENABLE_V05, 1); // turn on the lora antenna boost - LOG_DEBUG("HELTEC Detect Tracker V1.1\n"); -#elif defined(VEXT_ENABLE) && defined(VEXT_ON_VALUE) +#if defined(VEXT_ENABLE) pinMode(VEXT_ENABLE, OUTPUT); digitalWrite(VEXT_ENABLE, VEXT_ON_VALUE); // turn on the display power -#elif defined(VEXT_ENABLE) - pinMode(VEXT_ENABLE, OUTPUT); - digitalWrite(VEXT_ENABLE, 0); // turn on the display power -#endif - -#if defined(VTFT_CTRL_V03) - pinMode(VTFT_CTRL_V03, OUTPUT); - digitalWrite(VTFT_CTRL_V03, LOW); #endif #if defined(VTFT_CTRL) diff --git a/src/sleep.cpp b/src/sleep.cpp index 693d02a292..27e81ce548 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -246,14 +246,8 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false) digitalWrite(RESET_OLED, 1); // put the display in reset before killing its power #endif -#if defined(VEXT_ENABLE_V03) - digitalWrite(VEXT_ENABLE_V03, 1); // turn off the display power -#elif defined(VEXT_ENABLE_V05) - digitalWrite(VEXT_ENABLE_V05, 0); // turn off the lora amplifier power -#elif defined(VEXT_ENABLE) && defined(VEXT_ON_VALUE) +#if defined(VEXT_ENABLE) digitalWrite(VEXT_ENABLE, !VEXT_ON_VALUE); // turn on the display power -#elif defined(VEXT_ENABLE) - digitalWrite(VEXT_ENABLE, 1); // turn off the display power #endif #ifdef ARCH_ESP32 diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index 519c76d8f9..46e922eb59 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -31,7 +31,8 @@ // GPS UC6580: GPS V_DET(8), VDD_IO(7), DCDC_IN(21), pulls up RESETN(17), D_SEL(33) and BOOT_MODE(34) through 10kR // GPS LNA SW7125DE: VCC(4), pulls up SHDN(5) through 10kR // LED: VDD, LEDA (through diode) -#define VEXT_ENABLE_V05 3 // active HIGH - powers the GPS, GPS LNA and OLED VDD/anode +#define VEXT_ENABLE 3 // active HIGH - powers the GPS, GPS LNA and OLED VDD/anode +#define VEXT_ON_VALUE HIGH #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage diff --git a/variants/heltec_wireless_tracker_V1_0/variant.h b/variants/heltec_wireless_tracker_V1_0/variant.h index b638dec535..36c3dd2617 100644 --- a/variants/heltec_wireless_tracker_V1_0/variant.h +++ b/variants/heltec_wireless_tracker_V1_0/variant.h @@ -24,11 +24,12 @@ #define TFT_WIDTH DISPLAY_HEIGHT #define TFT_OFFSET_X 26 #define TFT_OFFSET_Y -1 -#define VTFT_CTRL_V03 46 // Heltec Tracker needs this pulled low for TFT +#define VTFT_CTRL 46 // Heltec Tracker needs this pulled low for TFT #define SCREEN_TRANSITION_FRAMERATE 3 // fps #define DISPLAY_FORCE_SMALL_FONTS -#define VEXT_ENABLE_V03 Vext // active low, powers the oled display and the lora antenna boost +#define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost +#define VEXT_ON_VALUE LOW #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage diff --git a/variants/tracksenger/internal/variant.h b/variants/tracksenger/internal/variant.h index bd4a51a2da..57ead848d3 100644 --- a/variants/tracksenger/internal/variant.h +++ b/variants/tracksenger/internal/variant.h @@ -29,7 +29,8 @@ #define SCREEN_TRANSITION_FRAMERATE 3 // fps #define DISPLAY_FORCE_SMALL_FONTS -#define VEXT_ENABLE_V05 3 // active HIGH, powers the lora antenna boost +#define VEXT_ENABLE 3 // active HIGH, powers the lora antenna boost +#define VEXT_ON_VALUE HIGH #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage diff --git a/variants/tracksenger/lcd/variant.h b/variants/tracksenger/lcd/variant.h index 17b012ae74..c89bf141c6 100644 --- a/variants/tracksenger/lcd/variant.h +++ b/variants/tracksenger/lcd/variant.h @@ -53,7 +53,8 @@ #define SCREEN_TRANSITION_FRAMERATE 3 // fps // #define DISPLAY_FORCE_SMALL_FONTS -#define VEXT_ENABLE_V05 3 // active HIGH, powers the lora antenna boost +#define VEXT_ENABLE 3 // active HIGH, powers the lora antenna boost +#define VEXT_ON_VALUE HIGH #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage diff --git a/variants/tracksenger/oled/variant.h b/variants/tracksenger/oled/variant.h index e6e28e459c..70f0f3209f 100644 --- a/variants/tracksenger/oled/variant.h +++ b/variants/tracksenger/oled/variant.h @@ -31,7 +31,8 @@ #define SCREEN_TRANSITION_FRAMERATE 3 // fps // #define DISPLAY_FORCE_SMALL_FONTS -#define VEXT_ENABLE_V05 3 // active HIGH, powers the lora antenna boost +#define VEXT_ENABLE 3 // active HIGH, powers the lora antenna boost +#define VEXT_ON_VALUE HIGH #define BUTTON_PIN 0 #define BATTERY_PIN 1 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage @@ -90,4 +91,4 @@ { \ 26, 37, 17, 16, 15, 7 \ } -// #end keyboard +// #end keyboard \ No newline at end of file From 2dda640d27c6c1373515f8a6fef895fdee2c669f Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 09:33:43 -0700 Subject: [PATCH 05/40] Remove unneeded VGNSS_CTRL_V03 --- variants/heltec_wireless_tracker_V1_0/variant.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/variants/heltec_wireless_tracker_V1_0/variant.h b/variants/heltec_wireless_tracker_V1_0/variant.h index 36c3dd2617..876ff11465 100644 --- a/variants/heltec_wireless_tracker_V1_0/variant.h +++ b/variants/heltec_wireless_tracker_V1_0/variant.h @@ -44,8 +44,7 @@ #define PIN_GPS_RESET 35 #define PIN_GPS_PPS 36 -#define VGNSS_CTRL_V03 37 // Heltec Tracker needs this pulled low for GPS -#define PIN_GPS_EN VGNSS_CTRL_V03 +#define PIN_GPS_EN 37 // Heltec Tracker needs this pulled low for GPS #define GPS_EN_ACTIVE LOW #define GPS_RESET_MODE LOW From 5570b6bbc6542642735f774b95af56451ca87dda Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 10:15:23 -0700 Subject: [PATCH 06/40] change GPS to use virtual GPIOs (for #4154) --- src/GpioLogic.cpp | 6 ++++++ src/GpioLogic.h | 2 +- src/gps/GPS.cpp | 27 +++++++++++++++++---------- src/gps/GPS.h | 11 +++++++++-- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/GpioLogic.cpp b/src/GpioLogic.cpp index d164615a7b..c23c40a7fe 100644 --- a/src/GpioLogic.cpp +++ b/src/GpioLogic.cpp @@ -10,6 +10,12 @@ void GpioVirtPin::set(bool value) } } +void GpioHwPin::set(bool value) +{ + pinMode(num, OUTPUT); + digitalWrite(num, value); +} + GpioTransformer::GpioTransformer(GpioPin *outPin) : outPin(outPin) {} void GpioTransformer::set(bool value) diff --git a/src/GpioLogic.h b/src/GpioLogic.h index 27e85d55b4..c5a3cefa99 100644 --- a/src/GpioLogic.h +++ b/src/GpioLogic.h @@ -29,7 +29,7 @@ class GpioHwPin : public GpioPin public: explicit GpioHwPin(uint32_t num) : num(num) {} - void set(bool value) { digitalWrite(num, value); } + void set(bool value); }; class GpioTransformer; diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 7d7de8700e..f7db1367a9 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -2,6 +2,7 @@ #if !MESHTASTIC_EXCLUDE_GPS #include "Default.h" #include "GPS.h" +#include "GpioLogic.h" #include "NodeDB.h" #include "PowerMon.h" #include "RTC.h" @@ -875,16 +876,8 @@ void GPS::writePinEN(bool on) if (HW_VENDOR == meshtastic_HardwareModel_RAK4631 && (rotaryEncoderInterruptImpl1 || upDownInterruptImpl1)) return; - // Abort: if pin unset - if (!en_gpio) - return; - - // Determine new value for the pin - bool val = GPS_EN_ACTIVE ? on : !on; - // Write and log - pinMode(en_gpio, OUTPUT); - digitalWrite(en_gpio, val); + enablePin->set(on); #ifdef GPS_EXTRAVERBOSE LOG_DEBUG("Pin EN %s\n", val == HIGH ? "HIGH" : "LOW"); #endif @@ -1421,7 +1414,21 @@ GPS *GPS::createGps() GPS *new_gps = new GPS; new_gps->rx_gpio = _rx_gpio; new_gps->tx_gpio = _tx_gpio; - new_gps->en_gpio = _en_gpio; + + if (_en_gpio) { + GpioPin *p = new GpioHwPin(_en_gpio); + + if (!GPS_EN_ACTIVE) { // Need to invert the pin before hardware + auto virtPin = new GpioVirtPin(); + new GpioNotTransformer( + virtPin, p); // We just leave this created object on the heap so it can stay watching virtPin and driving en_gpio + p = virtPin; + } + new_gps->enablePin = p; + } else { + // Just use a simulated pin + new_gps->enablePin = new GpioVirtPin(); + } #ifdef PIN_GPS_PPS // pulse per second diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 96171cba52..494bddae81 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -3,6 +3,7 @@ #if !MESHTASTIC_EXCLUDE_GPS #include "GPSStatus.h" +#include "GpioLogic.h" #include "Observer.h" #include "TinyGPS++.h" #include "concurrency/OSThread.h" @@ -73,7 +74,6 @@ class GPS : private concurrency::OSThread uint32_t lastWakeStartMsec = 0, lastSleepStartMsec = 0, lastFixStartMsec = 0; uint32_t rx_gpio = 0; uint32_t tx_gpio = 0; - uint32_t en_gpio = 0; int speedSelect = 0; int probeTries = 2; @@ -152,6 +152,13 @@ class GPS : private concurrency::OSThread meshtastic_Position p = meshtastic_Position_init_default; + /** This is normally bound to config.position.gps_en_gpio but some rare boards (like heltec tracker) need more advanced + * implementations. Those boards will set this public variable to a custom implementation. + * + * Normally set by GPS::createGPS() + */ + GpioPin *enablePin; + GPS() : concurrency::OSThread("GPS") {} virtual ~GPS(); @@ -303,4 +310,4 @@ class GPS : private concurrency::OSThread }; extern GPS *gps; -#endif // Exclude GPS +#endif // Exclude GPS \ No newline at end of file From db6e591c078deb5829922d7f6d2254b00cd6be6d Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 10:38:19 -0700 Subject: [PATCH 07/40] For #4154 - change TFT driver to use virtual GPIO for backlight enable --- src/graphics/TFTDisplay.cpp | 30 ++++++++++++++++++------------ src/graphics/TFTDisplay.h | 7 +++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 0e203a9d69..21b9c2bd11 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -516,6 +516,21 @@ extern unPhone unphone; TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY geometry, HW_I2C i2cBus) { LOG_DEBUG("TFTDisplay!\n"); + +#ifdef TFT_BL + GpioPin *p = new GpioHwPin(TFT_BL); + + if (!TFT_BACKLIGHT_ON) { // Need to invert the pin before hardware + auto virtPin = new GpioVirtPin(); + new GpioNotTransformer( + virtPin, p); // We just leave this created object on the heap so it can stay watching virtPin and driving en_gpio + p = virtPin; + } +#else + GpioPin *p = new GpioVirtPin(); // Just simulate a pin +#endif + backlightEnable = p; + #if ARCH_PORTDUINO if (settingsMap[displayRotate]) { setGeometry(GEOMETRY_RAWMODE, settingsMap[configNames::displayHeight], settingsMap[configNames::displayWidth]); @@ -569,13 +584,11 @@ void TFTDisplay::sendCommand(uint8_t com) // handle display on/off directly switch (com) { case DISPLAYON: { + backlightEnable->set(true); #if ARCH_PORTDUINO display(true); if (settingsMap[displayBacklight] > 0) digitalWrite(settingsMap[displayBacklight], TFT_BACKLIGHT_ON); -#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) - pinMode(TFT_BL, OUTPUT); - digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); #elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) tft->wakeup(); tft->powerSaveOff(); @@ -594,13 +607,11 @@ void TFTDisplay::sendCommand(uint8_t com) break; } case DISPLAYOFF: { + backlightEnable->set(false); #if ARCH_PORTDUINO tft->clear(); if (settingsMap[displayBacklight] > 0) digitalWrite(settingsMap[displayBacklight], !TFT_BACKLIGHT_ON); -#elif defined(TFT_BL) && defined(TFT_BACKLIGHT_ON) - pinMode(TFT_BL, OUTPUT); - digitalWrite(TFT_BL, !TFT_BACKLIGHT_ON); #elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) tft->sleep(); tft->powerSaveOn(); @@ -689,13 +700,8 @@ bool TFTDisplay::connect() tft = new LGFX; #endif -#ifdef TFT_BL - pinMode(TFT_BL, OUTPUT); - digitalWrite(TFT_BL, TFT_BACKLIGHT_ON); - // pinMode(PIN_3V3_EN, OUTPUT); - // digitalWrite(PIN_3V3_EN, HIGH); + backlightEnable->set(true); LOG_INFO("Power to TFT Backlight\n"); -#endif #ifdef UNPHONE unphone.backlight(true); // using unPhone library diff --git a/src/graphics/TFTDisplay.h b/src/graphics/TFTDisplay.h index 42aa3abff5..595984fbc2 100644 --- a/src/graphics/TFTDisplay.h +++ b/src/graphics/TFTDisplay.h @@ -1,5 +1,6 @@ #pragma once +#include #include /** @@ -39,6 +40,12 @@ class TFTDisplay : public OLEDDisplay */ void setDetected(uint8_t detected); + /** + * This is normally managed entirely by TFTDisplay, but some rare applications (heltec tracker) might need to replace the + * default GPIO behavior with something a bit more complex. + */ + GpioPin *backlightEnable; + protected: // the header size of the buffer used, e.g. for the SPI command header virtual int getBufferOffset(void) override { return 0; } From 2a7cf9d3873ee4a8d485c8688d96cd084b08b31a Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 10:40:12 -0700 Subject: [PATCH 08/40] Remove redundant defintions of ST7789_BACKLIGHT_EN --- src/graphics/TFTDisplay.cpp | 4 ---- variants/heltec_mesh_node_t114/variant.h | 2 +- variants/picomputer-s3/variant.h | 2 +- variants/t-deck/variant.h | 2 +- variants/t-watch-s3/variant.h | 4 +--- variants/tracksenger/lcd/variant.h | 2 +- variants/wiphone/variant.h | 2 +- 7 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 21b9c2bd11..7a0a8c3eba 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -123,10 +123,6 @@ static void rak14014_tpIntHandle(void) #elif defined(ST7789_CS) #include // Graphics and font library for ST7735 driver chip -#if defined(ST7789_BACKLIGHT_EN) && !defined(TFT_BL) -#define TFT_BL ST7789_BACKLIGHT_EN -#endif - class LGFX : public lgfx::LGFX_Device { lgfx::Panel_ST7789 _panel_instance; diff --git a/variants/heltec_mesh_node_t114/variant.h b/variants/heltec_mesh_node_t114/variant.h index f7a2681489..e8c3059902 100644 --- a/variants/heltec_mesh_node_t114/variant.h +++ b/variants/heltec_mesh_node_t114/variant.h @@ -49,7 +49,7 @@ extern "C" { // #define ST7789_BL (32+6) #define TFT_BACKLIGHT_ON LOW #define ST7789_SPI_HOST SPI1_HOST -// #define ST7789_BACKLIGHT_EN (32+6) +// #define TFT_BL (32+6) #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define TFT_HEIGHT 135 diff --git a/variants/picomputer-s3/variant.h b/variants/picomputer-s3/variant.h index fc746c599d..ff8faa6f4e 100644 --- a/variants/picomputer-s3/variant.h +++ b/variants/picomputer-s3/variant.h @@ -37,7 +37,7 @@ #define ST7789_MISO -1 #define ST7789_BUSY -1 #define ST7789_SPI_HOST SPI3_HOST -#define ST7789_BACKLIGHT_EN 5 +#define TFT_BL 5 #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define TFT_HEIGHT 320 diff --git a/variants/t-deck/variant.h b/variants/t-deck/variant.h index 7efa00c825..9860d608f8 100644 --- a/variants/t-deck/variant.h +++ b/variants/t-deck/variant.h @@ -8,7 +8,7 @@ #define ST7789_BUSY -1 #define ST7789_BL 42 #define ST7789_SPI_HOST SPI2_HOST -#define ST7789_BACKLIGHT_EN 42 +#define TFT_BL 42 #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define TFT_HEIGHT 320 diff --git a/variants/t-watch-s3/variant.h b/variants/t-watch-s3/variant.h index ad7e6b56b5..9f939d8594 100644 --- a/variants/t-watch-s3/variant.h +++ b/variants/t-watch-s3/variant.h @@ -8,7 +8,7 @@ #define ST7789_BUSY -1 #define ST7789_BL 45 #define ST7789_SPI_HOST SPI3_HOST -#define ST7789_BACKLIGHT_EN 45 +#define TFT_BL 45 #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define TFT_HEIGHT 240 @@ -30,8 +30,6 @@ #define I2C_SDA1 39 // Used for capacitive touch #define I2C_SCL1 40 // Used for capacitive touch -#define TFT_BL ST7789_BACKLIGHT_EN - #define HAS_I2S #define DAC_I2S_BCK 48 #define DAC_I2S_WS 15 diff --git a/variants/tracksenger/lcd/variant.h b/variants/tracksenger/lcd/variant.h index c89bf141c6..ecf4e854e9 100644 --- a/variants/tracksenger/lcd/variant.h +++ b/variants/tracksenger/lcd/variant.h @@ -22,7 +22,7 @@ #define ST7789_MISO -1 #define ST7789_BUSY -1 #define ST7789_SPI_HOST SPI3_HOST -#define ST7789_BACKLIGHT_EN 21 +#define TFT_BL 21 #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define TFT_HEIGHT 320 diff --git a/variants/wiphone/variant.h b/variants/wiphone/variant.h index b2b3ade788..052dc5ea8f 100644 --- a/variants/wiphone/variant.h +++ b/variants/wiphone/variant.h @@ -40,7 +40,7 @@ #define ST7789_MISO 19 #define ST7789_BUSY -1 #define ST7789_SPI_HOST SPI3_HOST -#define ST7789_BACKLIGHT_EN -1 // EXTENDER_PIN(9) +#define TFT_BL -1 // EXTENDER_PIN(9) #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define TFT_HEIGHT 240 From f77c5f6a5bb42ea5d28cb2db54417d2694acc7c9 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 10:50:44 -0700 Subject: [PATCH 09/40] Don't create backlight instances when the variant hasn't specified a pin --- src/graphics/TFTDisplay.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 7a0a8c3eba..f6bd6513ac 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -192,6 +192,7 @@ class LGFX : public lgfx::LGFX_Device _panel_instance.config(cfg); } +#ifdef ST7789_BL // Set the backlight control. (delete if not necessary) { auto cfg = _light_instance.config(); // Gets a structure for backlight settings. @@ -203,6 +204,7 @@ class LGFX : public lgfx::LGFX_Device _light_instance.config(cfg); _panel_instance.setLight(&_light_instance); // Set the backlight on the panel. } +#endif #if HAS_TOUCHSCREEN // Configure settings for touch screen control. @@ -312,6 +314,7 @@ class LGFX : public lgfx::LGFX_Device _panel_instance.config(cfg); } +#ifdef TFT_BL // Set the backlight control { auto cfg = _light_instance.config(); // Gets a structure for backlight settings. @@ -324,6 +327,7 @@ class LGFX : public lgfx::LGFX_Device _light_instance.config(cfg); _panel_instance.setLight(&_light_instance); // Set the backlight on the panel. } +#endif setPanel(&_panel_instance); } From 5c5cbb23cfaae33693f2f7b505b827a493a60811 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 10:51:15 -0700 Subject: [PATCH 10/40] wiphone isn't setting a valid backlight enable pin Therefore don't just randomly be writing to a GPIO numbered -1 Instead just don't try to control the backlight NOTE: I don't have a 'wiphone' to test with, but I saw this via inspection while cleaning up some other stuff. --- variants/wiphone/variant.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/variants/wiphone/variant.h b/variants/wiphone/variant.h index 052dc5ea8f..cfa5667bb1 100644 --- a/variants/wiphone/variant.h +++ b/variants/wiphone/variant.h @@ -34,13 +34,17 @@ #define ST7789_SCK 18 #define ST7789_CS 5 #define ST7789_RS 26 -#define ST7789_BL -1 // EXTENDER_PIN(9) +// I don't have a 'wiphone' but this I think should not be defined this way (don't set TFT_BL if we don't have a hw way to control +// it) +// #define ST7789_BL -1 // EXTENDER_PIN(9) #define ST7789_RESET -1 #define ST7789_MISO 19 #define ST7789_BUSY -1 #define ST7789_SPI_HOST SPI3_HOST -#define TFT_BL -1 // EXTENDER_PIN(9) +// I don't have a 'wiphone' but this I think should not be defined this way (don't set TFT_BL if we don't have a hw way to control +// it) +// #define TFT_BL -1 // EXTENDER_PIN(9) #define SPI_FREQUENCY 40000000 #define SPI_READ_FREQUENCY 16000000 #define TFT_HEIGHT 240 From e6163a59cd0521a19bf2d1db63e9f6792964d359 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Thu, 22 Aug 2024 11:07:06 -0700 Subject: [PATCH 11/40] Make specifying VEXT_ON_VALUE manatory if using VEXT_ENABLE --- variants/heltec_wireless_paper/variant.h | 1 + variants/heltec_wireless_paper_v1/variant.h | 1 + variants/heltec_wsl_v3/variant.h | 3 ++- variants/tlora_v1/variant.h | 5 +++-- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/variants/heltec_wireless_paper/variant.h b/variants/heltec_wireless_paper/variant.h index 36ab804453..520dcec9b3 100644 --- a/variants/heltec_wireless_paper/variant.h +++ b/variants/heltec_wireless_paper/variant.h @@ -22,6 +22,7 @@ // Power #define VEXT_ENABLE 45 // Active low, powers the E-Ink display +#define VEXT_ON_VALUE LOW #define ADC_CTRL 19 #define BATTERY_PIN 20 #define ADC_CHANNEL ADC2_GPIO20_CHANNEL diff --git a/variants/heltec_wireless_paper_v1/variant.h b/variants/heltec_wireless_paper_v1/variant.h index 36ab804453..520dcec9b3 100644 --- a/variants/heltec_wireless_paper_v1/variant.h +++ b/variants/heltec_wireless_paper_v1/variant.h @@ -22,6 +22,7 @@ // Power #define VEXT_ENABLE 45 // Active low, powers the E-Ink display +#define VEXT_ON_VALUE LOW #define ADC_CTRL 19 #define BATTERY_PIN 20 #define ADC_CHANNEL ADC2_GPIO20_CHANNEL diff --git a/variants/heltec_wsl_v3/variant.h b/variants/heltec_wsl_v3/variant.h index 75cea538d0..c103b91728 100644 --- a/variants/heltec_wsl_v3/variant.h +++ b/variants/heltec_wsl_v3/variant.h @@ -4,6 +4,7 @@ #define LED_PIN LED #define VEXT_ENABLE Vext // active low, powers the oled display and the lora antenna boost +#define VEXT_ON_VALUE LOW #define BUTTON_PIN 0 #define ADC_CTRL 37 @@ -32,4 +33,4 @@ #define SX126X_RESET LORA_RESET #define SX126X_DIO2_AS_RF_SWITCH -#define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#define SX126X_DIO3_TCXO_VOLTAGE 1.8 \ No newline at end of file diff --git a/variants/tlora_v1/variant.h b/variants/tlora_v1/variant.h index 08fefa809b..83e2c193e4 100644 --- a/variants/tlora_v1/variant.h +++ b/variants/tlora_v1/variant.h @@ -4,8 +4,9 @@ #define RESET_OLED 16 // If defined, this pin will be used to reset the display controller #define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost -#define LED_PIN 2 // If defined we will blink this LED -#define BUTTON_PIN 0 // If defined, this will be used for user button presses +#define VEXT_ON_VALUE LOW +#define LED_PIN 2 // If defined we will blink this LED +#define BUTTON_PIN 0 // If defined, this will be used for user button presses #define BUTTON_NEED_PULLUP #define EXT_NOTIFY_OUT 13 // Default pin to use for Ext Notify Module. From 06175737ccb25ea69688023ffd02c05d4fdd8291 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Thu, 22 Aug 2024 20:57:03 -0500 Subject: [PATCH 12/40] Save nodedb after favoriting (or removing) (#4537) --- src/modules/AdminModule.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index d64aea5d87..ef60a4bf2c 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -238,6 +238,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(r->set_favorite_node); if (node != NULL) { node->is_favorite = true; + saveChanges(SEGMENT_DEVICESTATE, false); } break; } @@ -246,6 +247,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(r->remove_favorite_node); if (node != NULL) { node->is_favorite = false; + saveChanges(SEGMENT_DEVICESTATE, false); } break; } From 710fdbd4e530d244efc86841e2432afa6058da0e Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Fri, 23 Aug 2024 06:25:40 -0500 Subject: [PATCH 13/40] Adds has_x bools to position packet. (#4540) --- src/modules/PositionModule.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/modules/PositionModule.cpp b/src/modules/PositionModule.cpp index f534baf677..2a0c95a9b4 100644 --- a/src/modules/PositionModule.cpp +++ b/src/modules/PositionModule.cpp @@ -187,16 +187,23 @@ meshtastic_MeshPacket *PositionModule::allocReply() p.longitude_i = localPosition.longitude_i; } p.precision_bits = precision; + p.has_latitude_i = true; + p.has_longitude_i = true; p.time = getValidTime(RTCQualityNTP) > 0 ? getValidTime(RTCQualityNTP) : localPosition.time; if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE) { - if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE_MSL) + if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE_MSL) { p.altitude = localPosition.altitude; - else + p.has_altitude = true; + } else { p.altitude_hae = localPosition.altitude_hae; + p.has_altitude_hae = true; + } - if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_GEOIDAL_SEPARATION) + if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_GEOIDAL_SEPARATION) { p.altitude_geoidal_separation = localPosition.altitude_geoidal_separation; + p.has_altitude_geoidal_separation = true; + } } if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_DOP) { @@ -216,11 +223,15 @@ meshtastic_MeshPacket *PositionModule::allocReply() if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_SEQ_NO) p.seq_number = localPosition.seq_number; - if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_HEADING) + if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_HEADING) { p.ground_track = localPosition.ground_track; + p.has_ground_track = true; + } - if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_SPEED) + if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_SPEED) { p.ground_speed = localPosition.ground_speed; + p.has_ground_speed = true; + } // Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other // nodes shouldn't trust it anyways) Note: we allow a device with a local GPS or NTP to include the time, so that devices @@ -471,4 +482,4 @@ void PositionModule::handleNewPosition() } } -#endif +#endif \ No newline at end of file From 9b2ef971c219e2c40336584d6592cf6f874a0311 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Fri, 23 Aug 2024 06:26:19 -0500 Subject: [PATCH 14/40] Fix copyPasta in NodeDB (#4538) --- src/mesh/NodeDB.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 1caaaf39be..34d3e4ce90 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -556,13 +556,8 @@ void NodeDB::cleanupMeshDB() for (int i = 0; i < numMeshNodes; i++) { if (meshNodes->at(i).has_user) { if (meshNodes->at(i).user.public_key.size > 0) { - for (int j = 0; j < numMeshNodes; j++) { - if (meshNodes->at(i).user.public_key.bytes[j] != 0) { - break; - } - if (j == 31) { - meshNodes->at(i).user.public_key.size = 0; - } + if (memfll(meshNodes->at(i).user.public_key.bytes, 0, meshNodes->at(i).user.public_key.size)) { + meshNodes->at(i).user.public_key.size = 0; } } meshNodes->at(newPos++) = meshNodes->at(i); From de41a054b0a399123c141d08e043fe8567a502c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Gjels=C3=B8?= <36234524+gjelsoe@users.noreply.github.com> Date: Fri, 23 Aug 2024 13:28:23 +0200 Subject: [PATCH 15/40] Initial support for RadioMaster Bandit. (#4523) * Initial support for RadioMaster Bandit. * Different lighting can be made for Button 1 & 2 on the Bandit. Changes to AmbientLighting will turn off af shutdown(). * Trunk * Trunk again. --- platformio.ini | 1 + src/AmbientLightingThread.h | 59 ++++++++- src/mesh/RF95Interface.cpp | 26 +++- src/platform/esp32/architecture.h | 2 + .../radiomaster_900_bandit/platformio.ini | 14 ++ variants/radiomaster_900_bandit/variant.h | 121 ++++++++++++++++++ 6 files changed, 217 insertions(+), 6 deletions(-) create mode 100644 variants/radiomaster_900_bandit/platformio.ini create mode 100644 variants/radiomaster_900_bandit/variant.h diff --git a/platformio.ini b/platformio.ini index 5ad7d60a24..4de1ec39fc 100644 --- a/platformio.ini +++ b/platformio.ini @@ -34,6 +34,7 @@ default_envs = tbeam ;default_envs = wio-e5 ;default_envs = radiomaster_900_bandit_nano ;default_envs = radiomaster_900_bandit_micro +;default_envs = radiomaster_900_bandit ;default_envs = heltec_capsule_sensor_v3 ;default_envs = heltec_vision_master_t190 ;default_envs = heltec_vision_master_e213 diff --git a/src/AmbientLightingThread.h b/src/AmbientLightingThread.h index 6b3360b1f9..fdd4b53fac 100644 --- a/src/AmbientLightingThread.h +++ b/src/AmbientLightingThread.h @@ -1,3 +1,4 @@ +#include "Observer.h" #include "configuration.h" #ifdef HAS_NCP5623 @@ -22,10 +23,18 @@ class AmbientLightingThread : public concurrency::OSThread public: explicit AmbientLightingThread(ScanI2C::DeviceType type) : OSThread("AmbientLightingThread") { + 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 ENABLE_AMBIENTLIGHTING + moduleConfig.ambient_lighting.led_state = true; +#endif +#endif // Uncomment to test module // moduleConfig.ambient_lighting.led_state = true; // moduleConfig.ambient_lighting.current = 10; - // // Default to a color based on our node number + // Default to a color based on our node number // moduleConfig.ambient_lighting.red = (myNodeInfo.my_node_num & 0xFF0000) >> 16; // moduleConfig.ambient_lighting.green = (myNodeInfo.my_node_num & 0x00FF00) >> 8; // moduleConfig.ambient_lighting.blue = myNodeInfo.my_node_num & 0x0000FF; @@ -82,9 +91,46 @@ class AmbientLightingThread : public concurrency::OSThread return disable(); } + // When shutdown() is issued, setLightingOff will be called. + CallbackObserver notifyDeepSleepObserver = + CallbackObserver(this, &AmbientLightingThread::setLightingOff); + private: ScanI2C::DeviceType _type = ScanI2C::DeviceType::NONE; + // Turn RGB lighting off, is used in junction to shutdown() + int setLightingOff(void *unused) + { +#ifdef HAS_NCP5623 + rgb.setCurrent(0); + rgb.setRed(0); + rgb.setGreen(0); + rgb.setBlue(0); + LOG_INFO("Turn Off NCP5623 Ambient lighting.\n"); +#endif +#ifdef HAS_NEOPIXEL + pixels.clear(); + pixels.show(); + LOG_INFO("Turn Off NeoPixel Ambient lighting.\n"); +#endif +#ifdef RGBLED_CA + analogWrite(RGBLED_RED, 255 - 0); + analogWrite(RGBLED_GREEN, 255 - 0); + analogWrite(RGBLED_BLUE, 255 - 0); + LOG_INFO("Turn Off Ambient lighting RGB Common Anode.\n"); +#elif defined(RGBLED_RED) + analogWrite(RGBLED_RED, 0); + analogWrite(RGBLED_GREEN, 0); + analogWrite(RGBLED_BLUE, 0); + LOG_INFO("Turn Off Ambient lighting RGB Common Cathode.\n"); +#endif +#ifdef UNPHONE + unphone.rgb(0, 0, 0); + LOG_INFO("Turn Off unPhone Ambient lighting.\n"); +#endif + return 0; + } + void setLighting() { #ifdef HAS_NCP5623 @@ -100,6 +146,17 @@ class AmbientLightingThread : public concurrency::OSThread pixels.fill(pixels.Color(moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green, moduleConfig.ambient_lighting.blue), 0, NEOPIXEL_COUNT); + +// RadioMaster Bandit has addressable LED at the two buttons +// this allow us to set different lighting for them in variant.h file. +#ifdef RADIOMASTER_900_BANDIT +#if defined(BUTTON1_COLOR) && defined(BUTTON1_COLOR_INDEX) + pixels.fill(BUTTON1_COLOR, BUTTON1_COLOR_INDEX, 1); +#endif +#if defined(BUTTON2_COLOR) && defined(BUTTON2_COLOR_INDEX) + pixels.fill(BUTTON2_COLOR, BUTTON1_COLOR_INDEX, 1); +#endif +#endif pixels.show(); LOG_DEBUG("Initializing NeoPixel Ambient lighting w/ brightness(current)=%d, red=%d, green=%d, blue=%d\n", moduleConfig.ambient_lighting.current, moduleConfig.ambient_lighting.red, moduleConfig.ambient_lighting.green, diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index b6083e7f9e..25df3258ff 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -16,7 +16,7 @@ // In theory up to 27 dBm is possible, but the modules installed in most radios can cope with a max of 20. So BIG WARNING // if you set power to something higher than 17 or 20 you might fry your board. -#ifdef RADIOMASTER_900_BANDIT_NANO +#if defined(RADIOMASTER_900_BANDIT_NANO) || defined(RADIOMASTER_900_BANDIT) // Structure to hold DAC and DB values typedef struct { uint8_t dac; @@ -40,12 +40,23 @@ DACDB getDACandDB(uint8_t dbm) static const struct { uint8_t dbm; DACDB values; - } dbmToDACDB[] = { + } +#ifdef RADIOMASTER_900_BANDIT_NANO + dbmToDACDB[] = { {20, {168, 2}}, // 100mW {24, {148, 6}}, // 250mW {27, {128, 9}}, // 500mW {30, {90, 12}} // 1000mW }; +#endif +#ifdef RADIOMASTER_900_BANDIT + dbmToDACDB[] = { + {20, {165, 2}}, // 100mW + {24, {155, 6}}, // 250mW + {27, {142, 9}}, // 500mW + {30, {110, 10}} // 1000mW + }; +#endif const int numValues = sizeof(dbmToDACDB) / sizeof(dbmToDACDB[0]); // Find the interval dbm falls within and interpolate @@ -56,7 +67,12 @@ DACDB getDACandDB(uint8_t dbm) } // Return a default value if no match is found and default to 100mW +#ifdef RADIOMASTER_900_BANDIT_NANO DACDB defaultValue = {168, 2}; +#endif +#ifdef RADIOMASTER_900_BANDIT + DACDB defaultValue = {165, 2}; +#endif return defaultValue; } #endif @@ -95,7 +111,7 @@ bool RF95Interface::init() { RadioLibInterface::init(); -#ifdef RADIOMASTER_900_BANDIT_NANO +#if defined(RADIOMASTER_900_BANDIT_NANO) || defined(RADIOMASTER_900_BANDIT) // DAC and DB values based on dBm using interpolation DACDB dacDbValues = getDACandDB(power); int8_t powerDAC = dacDbValues.dac; @@ -117,7 +133,7 @@ bool RF95Interface::init() // enable PA #ifdef RF95_PA_EN #if defined(RF95_PA_DAC_EN) -#ifdef RADIOMASTER_900_BANDIT_NANO +#if defined(RADIOMASTER_900_BANDIT_NANO) || defined(RADIOMASTER_900_BANDIT) // Use calculated DAC value dacWrite(RF95_PA_EN, powerDAC); #else @@ -163,7 +179,7 @@ bool RF95Interface::init() LOG_INFO("Frequency set to %f\n", getFreq()); LOG_INFO("Bandwidth set to %f\n", bw); LOG_INFO("Power output set to %d\n", power); -#ifdef RADIOMASTER_900_BANDIT_NANO +#if defined(RADIOMASTER_900_BANDIT_NANO) || defined(RADIOMASTER_900_BANDIT) LOG_INFO("DAC output set to %d\n", powerDAC); #endif diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index b6def5b01f..3761235a0e 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -152,6 +152,8 @@ #define HW_VENDOR meshtastic_HardwareModel_WIPHONE #elif defined(RADIOMASTER_900_BANDIT_NANO) #define HW_VENDOR meshtastic_HardwareModel_RADIOMASTER_900_BANDIT_NANO +#elif defined(RADIOMASTER_900_BANDIT) +#define HW_VENDOR meshtastic_HardwareModel_RADIOMASTER_900_BANDIT #elif defined(HELTEC_CAPSULE_SENSOR_V3) #define HW_VENDOR meshtastic_HardwareModel_HELTEC_CAPSULE_SENSOR_V3 #elif defined(HELTEC_VISION_MASTER_T190) diff --git a/variants/radiomaster_900_bandit/platformio.ini b/variants/radiomaster_900_bandit/platformio.ini new file mode 100644 index 0000000000..4ff8a6ea28 --- /dev/null +++ b/variants/radiomaster_900_bandit/platformio.ini @@ -0,0 +1,14 @@ +[env:radiomaster_900_bandit] +extends = esp32_base +board = esp32doit-devkit-v1 +build_flags = + ${esp32_base.build_flags} + -DRADIOMASTER_900_BANDIT + -DVTABLES_IN_FLASH=1 + -DCONFIG_DISABLE_HAL_LOCKS=1 + -O2 + -Ivariants/radiomaster_900_bandit +board_build.f_cpu = 240000000L +upload_protocol = esptool +lib_deps = + ${esp32_base.lib_deps} \ No newline at end of file diff --git a/variants/radiomaster_900_bandit/variant.h b/variants/radiomaster_900_bandit/variant.h new file mode 100644 index 0000000000..0499970f5e --- /dev/null +++ b/variants/radiomaster_900_bandit/variant.h @@ -0,0 +1,121 @@ +/* + Initial settings and work by https://github.com/gjelsoe + Unit provided by Radio Master RC + https://radiomasterrc.com/products/bandit-expresslrs-rf-module with 1.29" OLED display CH1115 driver +*/ + +/* + On this model then screen is NOT upside down, don't flip it for the user. +*/ +#undef DISPLAY_FLIP_SCREEN + +/* + I2C SDA and SCL. + 0x18 - STK8XXX Accelerometer, Not supported yet. + 0x3C - SH1115 Display Driver +*/ +#define I2C_SDA 14 +#define I2C_SCL 12 + +/* + No GPS - but free pins are available. +*/ +#define HAS_GPS 0 +#undef GPS_RX_PIN +#undef GPS_TX_PIN + +/* + Pin connections from ESP32-D0WDQ6 to SX1276. +*/ +#define LORA_DIO0 22 +#define LORA_DIO1 21 +#define LORA_SCK 18 +#define LORA_MISO 19 +#define LORA_MOSI 23 +#define LORA_CS 4 +#define LORA_RESET 5 +#define LORA_TXEN 33 + +/* + This unit has a FAN built-in. + FAN is active at 250mW on it's ExpressLRS Firmware. + This FAN has TACHO signal on Pin 27 for use with PWM. +*/ +#define RF95_FAN_EN 2 + +/* + LED PIN setup and it has a NeoPixel LED. + It's possible to setup colors for Button 1 and 2, + look at BUTTON1_COLOR, BUTTON1_COLOR_INDEX, BUTTON2_COLOR and BUTTON2_COLOR_INDEX + this is done here for now. +*/ +#define HAS_NEOPIXEL // Enable the use of neopixels +#define NEOPIXEL_COUNT 6 // How many neopixels are connected +#define NEOPIXEL_DATA 15 // GPIO pin used to send data to the neopixels +#define NEOPIXEL_TYPE (NEO_GRB + NEO_KHZ800) // Type of neopixels in use +#define ENABLE_AMBIENTLIGHTING // Turn on Ambient Lighting +// #define BUTTON1_COLOR 0xFF0000 // Background light for Button 1 in HEX RGB Color (RadioMaster Bandit only). +// #define BUTTON1_COLOR_INDEX 0 // NeoPixel Index ID for Button 1 +// #define BUTTON2_COLOR 0x0000FF // Background light for Button 2 in HEX RGB Color (RadioMaster Bandit only). +// #define BUTTON2_COLOR_INDEX 1 // NeoPixel Index ID for Button 2 + +/* + It has 1 x five-way and 2 x normal buttons. + + Button GPIO RGB Index + --------------------------- + Five-way 39 - + Button 1 34 0 + Button 2 35 1 + + Five way button when using ADC. + 2.632V, 2.177V, 1.598V, 1.055V, 0V + + ADC Values: + { UP, DOWN, LEFT, RIGHT, ENTER, IDLE } + 3227, 0 ,1961, 2668, 1290, 4095 + + Five way button when using ADC. + https://github.com/ExpressLRS/targets/blob/f3215b5ec891108db1a13523e4163950cfcadaac/TX/Radiomaster%20Bandit.json#L41 + +*/ +#define INPUTBROKER_EXPRESSLRSFIVEWAY_TYPE +#define PIN_JOYSTICK 39 +#define JOYSTICK_ADC_VALS /*UP*/ 3227, /*DOWN*/ 0, /*LEFT*/ 1961, /*RIGHT*/ 2668, /*OK*/ 1290, /*IDLE*/ 4095 + +/* + Normal Button Pin setup. +*/ +#define BUTTON_PIN 34 +#define BUTTON_NEED_PULLUP + +/* + No External notification. +*/ +#undef EXT_NOTIFY_OUT + +/* + Remapping PIN Names. + Note, that this unit uses RFO +*/ +#define USE_RF95 +#define USE_RF95_RFO +#define RF95_CS LORA_CS +#define RF95_DIO1 LORA_DIO1 +#define RF95_TXEN LORA_TXEN +#define RF95_RESET LORA_RESET +#define RF95_MAX_POWER 10 + +/* + This module has Skyworks SKY66122 controlled by dacWrite + power ranging from 100mW to 1000mW. + + Mapping of PA_LEVEL to Power output: GPIO26/dacWrite + 168 -> 100mW + 155 -> 250mW + 142 -> 500mW + 110 -> 1000mW +*/ +#define RF95_PA_EN 26 +#define RF95_PA_DAC_EN +#define RF95_PA_LEVEL 110 \ No newline at end of file From fe9a80a4e0a9b88fd04229c2b4e18e1cf8033080 Mon Sep 17 00:00:00 2001 From: Ian McEwen Date: Fri, 23 Aug 2024 05:03:29 -0700 Subject: [PATCH 16/40] Use the '+' wildcard for MQTT rather than '#', to subscribe only to topics one nesting level deep (#4528) --- src/mqtt/MQTT.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mqtt/MQTT.cpp b/src/mqtt/MQTT.cpp index 22f68bac8d..2f7e82e3da 100644 --- a/src/mqtt/MQTT.cpp +++ b/src/mqtt/MQTT.cpp @@ -376,12 +376,12 @@ void MQTT::sendSubscriptions() const auto &ch = channels.getByIndex(i); if (ch.settings.downlink_enabled) { hasDownlink = true; - std::string topic = cryptTopic + channels.getGlobalId(i) + "/#"; + std::string topic = cryptTopic + channels.getGlobalId(i) + "/+"; LOG_INFO("Subscribing to %s\n", topic.c_str()); pubSub.subscribe(topic.c_str(), 1); // FIXME, is QOS 1 right? #ifndef ARCH_NRF52 // JSON is not supported on nRF52, see issue #2804 if (moduleConfig.mqtt.json_enabled == true) { - std::string topicDecoded = jsonTopic + channels.getGlobalId(i) + "/#"; + std::string topicDecoded = jsonTopic + channels.getGlobalId(i) + "/+"; LOG_INFO("Subscribing to %s\n", topicDecoded.c_str()); pubSub.subscribe(topicDecoded.c_str(), 1); // FIXME, is QOS 1 right? } @@ -390,7 +390,7 @@ void MQTT::sendSubscriptions() } #if !MESHTASTIC_EXCLUDE_PKI if (hasDownlink) { - std::string topic = cryptTopic + "PKI/#"; + std::string topic = cryptTopic + "PKI/+"; LOG_INFO("Subscribing to %s\n", topic.c_str()); pubSub.subscribe(topic.c_str(), 1); } @@ -674,4 +674,4 @@ bool MQTT::isValidJsonEnvelope(JSONObject &json) (json["from"]->AsNumber() == nodeDB->getNodeNum()) && // only accept message if the "from" is us (json.find("type") != json.end()) && json["type"]->IsString() && // should specify a type (json.find("payload") != json.end()); // should have a payload -} \ No newline at end of file +} From 9de0b7cfac56a0e8ceea13e48112d8ddd88a8555 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 23 Aug 2024 07:04:34 -0500 Subject: [PATCH 17/40] Found more places to set explicit has_optional on position (#4542) --- src/mesh/TypeConversions.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/mesh/TypeConversions.cpp b/src/mesh/TypeConversions.cpp index d8ee6afc74..bcff0b8178 100644 --- a/src/mesh/TypeConversions.cpp +++ b/src/mesh/TypeConversions.cpp @@ -16,8 +16,14 @@ meshtastic_NodeInfo TypeConversions::ConvertToNodeInfo(const meshtastic_NodeInfo if (lite->has_position) { info.has_position = true; + if (lite->position.latitude_i > 0) + info.position.has_latitude_i = true; info.position.latitude_i = lite->position.latitude_i; + if (lite->position.longitude_i > 0) + info.position.has_longitude_i = true; info.position.longitude_i = lite->position.longitude_i; + if (lite->position.altitude > 0) + info.position.has_altitude = true; info.position.altitude = lite->position.altitude; info.position.location_source = lite->position.location_source; info.position.time = lite->position.time; @@ -48,8 +54,14 @@ meshtastic_PositionLite TypeConversions::ConvertToPositionLite(meshtastic_Positi meshtastic_Position TypeConversions::ConvertToPosition(meshtastic_PositionLite lite) { meshtastic_Position position = meshtastic_Position_init_default; + if (lite.latitude_i > 0) + position.has_latitude_i = true; position.latitude_i = lite.latitude_i; + if (lite.longitude_i > 0) + position.has_longitude_i = true; position.longitude_i = lite.longitude_i; + if (lite.altitude > 0) + position.has_altitude = true; position.altitude = lite.altitude; position.location_source = lite.location_source; position.time = lite.time; From b285aa5bd608e57e5cbd8398402805eca8c27dd0 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Fri, 23 Aug 2024 07:07:28 -0500 Subject: [PATCH 18/40] Dum dum zero comparision --- src/mesh/TypeConversions.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mesh/TypeConversions.cpp b/src/mesh/TypeConversions.cpp index bcff0b8178..513728ca52 100644 --- a/src/mesh/TypeConversions.cpp +++ b/src/mesh/TypeConversions.cpp @@ -16,13 +16,13 @@ meshtastic_NodeInfo TypeConversions::ConvertToNodeInfo(const meshtastic_NodeInfo if (lite->has_position) { info.has_position = true; - if (lite->position.latitude_i > 0) + if (lite->position.latitude_i != 0) info.position.has_latitude_i = true; info.position.latitude_i = lite->position.latitude_i; - if (lite->position.longitude_i > 0) + if (lite->position.longitude_i != 0) info.position.has_longitude_i = true; info.position.longitude_i = lite->position.longitude_i; - if (lite->position.altitude > 0) + if (lite->position.altitude != 0) info.position.has_altitude = true; info.position.altitude = lite->position.altitude; info.position.location_source = lite->position.location_source; @@ -54,13 +54,13 @@ meshtastic_PositionLite TypeConversions::ConvertToPositionLite(meshtastic_Positi meshtastic_Position TypeConversions::ConvertToPosition(meshtastic_PositionLite lite) { meshtastic_Position position = meshtastic_Position_init_default; - if (lite.latitude_i > 0) + if (lite.latitude_i != 0) position.has_latitude_i = true; position.latitude_i = lite.latitude_i; - if (lite.longitude_i > 0) + if (lite.longitude_i != 0) position.has_longitude_i = true; position.longitude_i = lite.longitude_i; - if (lite.altitude > 0) + if (lite.altitude != 0) position.has_altitude = true; position.altitude = lite.altitude; position.location_source = lite.location_source; From 5ce5b7b08bfadb9312e2e9f95d10b54d6dff7b4c Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Fri, 23 Aug 2024 08:03:16 -0700 Subject: [PATCH 19/40] Older variant.h files (IMO sloppily) don't define VEXT_ON_VALUE But in an attempt to avoid updating lots of files, make it default to LOW --- src/configuration.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/configuration.h b/src/configuration.h index 2e0efffd49..047dbd7275 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -177,6 +177,11 @@ along with this program. If not, see . /* Step #1: offer chance for variant-specific defines */ #include "variant.h" +#if defined(VEXT_ENABLE) && !defined(VEXT_ON_VALUE) +// Older variant.h files might not be defining this value, so stay with the old default +#define VEXT_ON_VALUE LOW +#endif + #ifndef GPS_BAUDRATE #define GPS_BAUDRATE 9600 #endif From cdafa87cefac890ae2398885cc9052b6aaa0e4d7 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 28 Aug 2024 09:51:00 -0700 Subject: [PATCH 20/40] add lateInitVariant() as a concept. see below for docs (from src/extra_variants/README.md) This directory tree is designed to solve two problems. - The ESP32 arduino/platformio project doesn't support the nice "if initVariant() is found, call that after init" behavior of the nrf52 builds (they use initVariant() internally). - Over the years a lot of 'board specific' init code has been added to init() in main.cpp. It would be great to have a general/clean mechanism to allow developers to specify board specific/unique code in a clean fashion without mucking in main. So we are borrowing the initVariant() ideas here (by using weak gcc references). You can now define lateInitVariant() if your board needs it. If you'd like a board specific variant to be run, add the variant.cpp file to an appropriately named subdirectory and check for \_VARIANT_boardname in the cpp file (so that your code is only built for your board). You'll need to define \_VARIANT_boardname in your corresponding variant.h file. See existing boards for examples. This approach has no added runtime cost. --- src/main.cpp | 7 ++++ src/platform/extra_variants/README.md | 15 ++++++++ .../heltec_wireless_tracker/variant.cpp | 34 +++++++++++++++++++ variants/heltec_wireless_tracker/variant.h | 4 ++- 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/platform/extra_variants/README.md create mode 100644 src/platform/extra_variants/heltec_wireless_tracker/variant.cpp diff --git a/src/main.cpp b/src/main.cpp index 7520667dd6..8f64960bba 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -224,6 +224,11 @@ __attribute__((weak, noinline)) bool loopCanSleep() return true; } +// Weak empty variant initialization function. +// May be redefined by variant files. +void lateInitVariant() __attribute__((weak)); +void lateInitVariant() {} + /** * Print info as a structured log message (for automated log processing) */ @@ -1003,6 +1008,8 @@ void setup() } } + lateInitVariant(); // Do board specific init (see extra_variants/README.md for documentation) + #if !MESHTASTIC_EXCLUDE_MQTT mqttInit(); #endif diff --git a/src/platform/extra_variants/README.md b/src/platform/extra_variants/README.md new file mode 100644 index 0000000000..e558502f09 --- /dev/null +++ b/src/platform/extra_variants/README.md @@ -0,0 +1,15 @@ +# About extra_variants + +This directory tree is designed to solve two problems. + +- The ESP32 arduino/platformio project doesn't support the nice "if initVariant() is found, call that after init" behavior of the nrf52 builds (they use initVariant() internally). +- Over the years a lot of 'board specific' init code has been added to init() in main.cpp. It would be great to have a general/clean mechanism to allow developers to specify board specific/unique code in a clean fashion without mucking in main. + +So we are borrowing the initVariant() ideas here (by using weak gcc references). You can now define lateInitVariant() if your board needs it. + +If you'd like a board specific variant to be run, add the variant.cpp file to an appropriately named +subdirectory and check for \_VARIANT_boardname in the cpp file (so that your code is only built for your board). +You'll need to define \_VARIANT_boardname in your corresponding variant.h file. +See existing boards for examples. + +This approach has no added runtime cost. diff --git a/src/platform/extra_variants/heltec_wireless_tracker/variant.cpp b/src/platform/extra_variants/heltec_wireless_tracker/variant.cpp new file mode 100644 index 0000000000..84264ef587 --- /dev/null +++ b/src/platform/extra_variants/heltec_wireless_tracker/variant.cpp @@ -0,0 +1,34 @@ +#include "configuration.h" + +#ifdef _VARIANT_HELTEC_WIRELESS_TRACKER + +#include "GPS.h" +#include "GpioLogic.h" +#include "graphics/TFTDisplay.h" + +// Heltec tracker specific init +void lateInitVariant() +{ + // LOG_DEBUG("Heltec tracker initVariant\n"); +#ifdef VEXT_ENABLE + GpioPin *hwEnable = new GpioHwPin(VEXT_ENABLE); + GpioVirtPin *virtGpsEnable = gps ? gps->enablePin : new GpioVirtPin(); + + // On this board we are actually using the backlightEnable signal to already be controlling a physical enable to the + // display controller. But we'd _ALSO_ like to have that signal drive a virtual GPIO. So nest it as needed. + GpioVirtPin *virtScreenEnable = new GpioVirtPin(); + if (TFTDisplay::backlightEnable) { + GpioPin *physScreenEnable = TFTDisplay::backlightEnable; + GpioPin *splitter = new GpioSplitter(virtScreenEnable, physScreenEnable); + TFTDisplay::backlightEnable = splitter; + + // Assume screen is initially powered + splitter->set(true); + } + + // If either the GPS or the screen is on, turn on the external power regulator + new GpioBinaryTransformer(virtGpsEnable, virtScreenEnable, hwEnable, GpioBinaryTransformer::Or); +#endif +} + +#endif \ No newline at end of file diff --git a/variants/heltec_wireless_tracker/variant.h b/variants/heltec_wireless_tracker/variant.h index 46e922eb59..79fa0e8010 100644 --- a/variants/heltec_wireless_tracker/variant.h +++ b/variants/heltec_wireless_tracker/variant.h @@ -1,5 +1,6 @@ #define LED_PIN 18 +#define _VARIANT_HELTEC_WIRELESS_TRACKER #define HELTEC_TRACKER_V1_X // I2C @@ -31,7 +32,8 @@ // GPS UC6580: GPS V_DET(8), VDD_IO(7), DCDC_IN(21), pulls up RESETN(17), D_SEL(33) and BOOT_MODE(34) through 10kR // GPS LNA SW7125DE: VCC(4), pulls up SHDN(5) through 10kR // LED: VDD, LEDA (through diode) -#define VEXT_ENABLE 3 // active HIGH - powers the GPS, GPS LNA and OLED VDD/anode + +#define VEXT_ENABLE 3 // active HIGH - powers the GPS, GPS LNA and OLED #define VEXT_ON_VALUE HIGH #define BUTTON_PIN 0 From 8a9cc727a8d73b9b9e0b1754d483954151abcb40 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 28 Aug 2024 09:59:42 -0700 Subject: [PATCH 21/40] for #4154 use a binary gpio transformer to manage vext on heltec-tracker (saves power) --- src/GpioLogic.cpp | 16 +++++++++++++++- src/GpioLogic.h | 28 ++++++++++++++++++++++------ src/gps/GPS.cpp | 11 +++++------ src/gps/GPS.h | 2 +- src/graphics/TFTDisplay.cpp | 4 ++++ src/graphics/TFTDisplay.h | 4 +++- 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/GpioLogic.cpp b/src/GpioLogic.cpp index c23c40a7fe..cbe26fc600 100644 --- a/src/GpioLogic.cpp +++ b/src/GpioLogic.cpp @@ -12,6 +12,7 @@ void GpioVirtPin::set(bool value) void GpioHwPin::set(bool value) { + // if (num == 3) LOG_DEBUG("Setting pin %d to %d\n", num, value); pinMode(num, OUTPUT); digitalWrite(num, value); } @@ -23,7 +24,7 @@ void GpioTransformer::set(bool value) outPin->set(value); } -GpioNotTransformer::GpioNotTransformer(GpioVirtPin *inPin, GpioPin *outPin) : GpioTransformer(outPin), inPin(inPin) +GpioUnaryTransformer::GpioUnaryTransformer(GpioVirtPin *inPin, GpioPin *outPin) : GpioTransformer(outPin), inPin(inPin) { assert(!inPin->dependentPin); // We only allow one dependent pin inPin->dependentPin = this; @@ -33,6 +34,18 @@ GpioNotTransformer::GpioNotTransformer(GpioVirtPin *inPin, GpioPin *outPin) : Gp // update(); } +/** + * Update the output pin based on the current state of the input pin. + */ +void GpioUnaryTransformer::update() +{ + auto p = inPin->get(); + if (p == GpioVirtPin::PinState::Unset) + return; // Not yet fully initialized + + set(p); +} + /** * Update the output pin based on the current state of the input pin. */ @@ -75,6 +88,7 @@ void GpioBinaryTransformer::update() newValue = (GpioVirtPin::PinState)(p1 && p2); break; case Or: + // LOG_DEBUG("Doing GPIO OR\n"); newValue = (GpioVirtPin::PinState)(p1 || p2); break; case Xor: diff --git a/src/GpioLogic.h b/src/GpioLogic.h index c5a3cefa99..947d49625a 100644 --- a/src/GpioLogic.h +++ b/src/GpioLogic.h @@ -42,7 +42,7 @@ class GpioBinaryTransformer; class GpioVirtPin : public GpioPin { friend class GpioBinaryTransformer; - friend class GpioNotTransformer; + friend class GpioUnaryTransformer; public: enum PinState { On = true, Off = false, Unset = 2 }; @@ -79,12 +79,12 @@ class GpioTransformer }; /** - * A transformer that performs a unary NOT operation from an input. + * A transformer that just drives a hw pin based on a virtual pin. */ -class GpioNotTransformer : public GpioTransformer +class GpioUnaryTransformer : public GpioTransformer { public: - GpioNotTransformer(GpioVirtPin *inPin, GpioPin *outPin); + GpioUnaryTransformer(GpioVirtPin *inPin, GpioPin *outPin); protected: friend class GpioVirtPin; @@ -92,12 +92,28 @@ class GpioNotTransformer : public GpioTransformer /** * Update the output pin based on the current state of the input pin. */ - void update(); + virtual void update(); - private: GpioVirtPin *inPin; }; +/** + * A transformer that performs a unary NOT operation from an input. + */ +class GpioNotTransformer : public GpioUnaryTransformer +{ + public: + GpioNotTransformer(GpioVirtPin *inPin, GpioPin *outPin) : GpioUnaryTransformer(inPin, outPin) {} + + protected: + friend class GpioVirtPin; + + /** + * Update the output pin based on the current state of the input pin. + */ + void update(); +}; + /** * A transformer that combines multiple virtual pins to drive an output pin */ diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index f7db1367a9..12ef34c52e 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -1415,19 +1415,18 @@ GPS *GPS::createGps() new_gps->rx_gpio = _rx_gpio; new_gps->tx_gpio = _tx_gpio; + GpioVirtPin *virtPin = new GpioVirtPin(); + new_gps->enablePin = virtPin; // Always at least populate a virtual pin if (_en_gpio) { GpioPin *p = new GpioHwPin(_en_gpio); if (!GPS_EN_ACTIVE) { // Need to invert the pin before hardware - auto virtPin = new GpioVirtPin(); new GpioNotTransformer( virtPin, p); // We just leave this created object on the heap so it can stay watching virtPin and driving en_gpio - p = virtPin; + } else { + new GpioUnaryTransformer( + virtPin, p); // We just leave this created object on the heap so it can stay watching virtPin and driving en_gpio } - new_gps->enablePin = p; - } else { - // Just use a simulated pin - new_gps->enablePin = new GpioVirtPin(); } #ifdef PIN_GPS_PPS diff --git a/src/gps/GPS.h b/src/gps/GPS.h index 494bddae81..befa4eef00 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -157,7 +157,7 @@ class GPS : private concurrency::OSThread * * Normally set by GPS::createGPS() */ - GpioPin *enablePin; + GpioVirtPin *enablePin; GPS() : concurrency::OSThread("GPS") {} diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index f6bd6513ac..1dc4569db2 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -25,6 +25,8 @@ extern SX1509 gpioExtender; #define TFT_INVERT true #endif +GpioPin *TFTDisplay::backlightEnable; + class LGFX : public lgfx::LGFX_Device { lgfx::Panel_ST7735S _panel_instance; @@ -584,6 +586,7 @@ void TFTDisplay::sendCommand(uint8_t com) // handle display on/off directly switch (com) { case DISPLAYON: { + // LOG_DEBUG("Display on\n"); backlightEnable->set(true); #if ARCH_PORTDUINO display(true); @@ -607,6 +610,7 @@ void TFTDisplay::sendCommand(uint8_t com) break; } case DISPLAYOFF: { + // LOG_DEBUG("Display off\n"); backlightEnable->set(false); #if ARCH_PORTDUINO tft->clear(); diff --git a/src/graphics/TFTDisplay.h b/src/graphics/TFTDisplay.h index 595984fbc2..38cd53ebb5 100644 --- a/src/graphics/TFTDisplay.h +++ b/src/graphics/TFTDisplay.h @@ -43,8 +43,10 @@ class TFTDisplay : public OLEDDisplay /** * This is normally managed entirely by TFTDisplay, but some rare applications (heltec tracker) might need to replace the * default GPIO behavior with something a bit more complex. + * + * We (cruftily) make it static so that variant.cpp can access it without needing a ptr to the TFTDisplay instance. */ - GpioPin *backlightEnable; + static GpioPin *backlightEnable; protected: // the header size of the buffer used, e.g. for the SPI command header From 9631a1be3875169a7e9b802e4d06e1c881ef6783 Mon Sep 17 00:00:00 2001 From: geeksville Date: Fri, 23 Aug 2024 18:18:36 -0700 Subject: [PATCH 22/40] remove deprecated serial/bt logging options and unify in the new (#4516) security option. Per discussion in https://github.com/meshtastic/firmware/issues/4375 no need to preserve the old options when changing to this new simpler single boolean because they were newish, rarely used and only for 'advanced' developers. --- protobufs | 2 +- src/RedirectablePrint.cpp | 2 +- src/mesh/NodeDB.cpp | 1 - src/mesh/generated/meshtastic/config.pb.h | 37 ++++++------------- src/mesh/generated/meshtastic/deviceonly.pb.h | 2 +- src/mesh/generated/meshtastic/localonly.pb.h | 2 +- 6 files changed, 15 insertions(+), 31 deletions(-) diff --git a/protobufs b/protobufs index 56a4355070..183ba970a7 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 56a4355070f3371213d48f3a8cac1ddaf0d553fe +Subproject commit 183ba970a7a71de7a81541b74c413543523417d2 diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 96cf851e4c..6eb6f8319a 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -213,7 +213,7 @@ void RedirectablePrint::log_to_syslog(const char *logLevel, const char *format, void RedirectablePrint::log_to_ble(const char *logLevel, const char *format, va_list arg) { #if !MESHTASTIC_EXCLUDE_BLUETOOTH - if (config.security.bluetooth_logging_enabled && !pauseBluetoothLogging) { + if (config.security.debug_log_api_enabled && !pauseBluetoothLogging) { bool isBleConnected = false; #ifdef ARCH_ESP32 isBleConnected = nimbleBluetooth && nimbleBluetooth->isActive() && nimbleBluetooth->isConnected(); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 34d3e4ce90..0504cc273e 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -127,7 +127,6 @@ NodeDB::NodeDB() if (!config.has_security) { config.has_security = true; config.security.serial_enabled = config.device.serial_enabled; - config.security.bluetooth_logging_enabled = config.bluetooth.device_logging_enabled; config.security.is_managed = config.device.is_managed; } #if !(MESHTASTIC_EXCLUDE_PKI) diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index 2f4c00fb0d..d79654856e 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -284,10 +284,6 @@ typedef struct _meshtastic_Config_DeviceConfig { /* Disabling this will disable the SerialConsole by not initilizing the StreamAPI Moved to SecurityConfig */ bool serial_enabled; - /* By default we turn off logging as soon as an API client connects (to keep shared serial link quiet). - Set this to true to leave the debug log outputting even when API is active. - Moved to SecurityConfig */ - bool debug_log_enabled; /* For boards without a hard wired button, this is the pin number that will be used Boards that have more than one button can swap the function with this one. defaults to BUTTON_PIN if defined. */ uint32_t button_gpio; @@ -523,9 +519,6 @@ typedef struct _meshtastic_Config_BluetoothConfig { meshtastic_Config_BluetoothConfig_PairingMode mode; /* Specified PIN for PairingMode.FixedPin */ uint32_t fixed_pin; - /* Enables device (serial style logs) over Bluetooth - Moved to SecurityConfig */ - bool device_logging_enabled; } meshtastic_Config_BluetoothConfig; typedef PB_BYTES_ARRAY_T(32) meshtastic_Config_SecurityConfig_public_key_t; @@ -546,10 +539,8 @@ typedef struct _meshtastic_Config_SecurityConfig { /* Serial Console over the Stream API." */ bool serial_enabled; /* By default we turn off logging as soon as an API client connects (to keep shared serial link quiet). - Output live debug logging over serial. */ + Output live debug logging over serial or bluetooth is set to true. */ bool debug_log_api_enabled; - /* Enables device (serial style logs) over Bluetooth */ - bool bluetooth_logging_enabled; /* Allow incoming device control over the insecure legacy admin channel. */ bool admin_channel_enabled; } meshtastic_Config_SecurityConfig; @@ -658,32 +649,31 @@ extern "C" { /* Initializer values for message structs */ #define meshtastic_Config_init_default {0, {meshtastic_Config_DeviceConfig_init_default}} -#define meshtastic_Config_DeviceConfig_init_default {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0, 0, "", 0} +#define meshtastic_Config_DeviceConfig_init_default {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0, 0, "", 0} #define meshtastic_Config_PositionConfig_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _meshtastic_Config_PositionConfig_GpsMode_MIN} #define meshtastic_Config_PowerConfig_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Config_NetworkConfig_init_default {0, "", "", "", 0, _meshtastic_Config_NetworkConfig_AddressMode_MIN, false, meshtastic_Config_NetworkConfig_IpV4Config_init_default, ""} #define meshtastic_Config_NetworkConfig_IpV4Config_init_default {0, 0, 0, 0} #define meshtastic_Config_DisplayConfig_init_default {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0, _meshtastic_Config_DisplayConfig_CompassOrientation_MIN} #define meshtastic_Config_LoRaConfig_init_default {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0} -#define meshtastic_Config_BluetoothConfig_init_default {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0, 0} -#define meshtastic_Config_SecurityConfig_init_default {{0, {0}}, {0, {0}}, {0, {0}}, 0, 0, 0, 0, 0} +#define meshtastic_Config_BluetoothConfig_init_default {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0} +#define meshtastic_Config_SecurityConfig_init_default {{0, {0}}, {0, {0}}, {0, {0}}, 0, 0, 0, 0} #define meshtastic_Config_SessionkeyConfig_init_default {0} #define meshtastic_Config_init_zero {0, {meshtastic_Config_DeviceConfig_init_zero}} -#define meshtastic_Config_DeviceConfig_init_zero {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0, 0, "", 0} +#define meshtastic_Config_DeviceConfig_init_zero {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0, 0, "", 0} #define meshtastic_Config_PositionConfig_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _meshtastic_Config_PositionConfig_GpsMode_MIN} #define meshtastic_Config_PowerConfig_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0} #define meshtastic_Config_NetworkConfig_init_zero {0, "", "", "", 0, _meshtastic_Config_NetworkConfig_AddressMode_MIN, false, meshtastic_Config_NetworkConfig_IpV4Config_init_zero, ""} #define meshtastic_Config_NetworkConfig_IpV4Config_init_zero {0, 0, 0, 0} #define meshtastic_Config_DisplayConfig_init_zero {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0, _meshtastic_Config_DisplayConfig_CompassOrientation_MIN} #define meshtastic_Config_LoRaConfig_init_zero {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0} -#define meshtastic_Config_BluetoothConfig_init_zero {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0, 0} -#define meshtastic_Config_SecurityConfig_init_zero {{0, {0}}, {0, {0}}, {0, {0}}, 0, 0, 0, 0, 0} +#define meshtastic_Config_BluetoothConfig_init_zero {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0} +#define meshtastic_Config_SecurityConfig_init_zero {{0, {0}}, {0, {0}}, {0, {0}}, 0, 0, 0, 0} #define meshtastic_Config_SessionkeyConfig_init_zero {0} /* Field tags (for use in manual encoding/decoding) */ #define meshtastic_Config_DeviceConfig_role_tag 1 #define meshtastic_Config_DeviceConfig_serial_enabled_tag 2 -#define meshtastic_Config_DeviceConfig_debug_log_enabled_tag 3 #define meshtastic_Config_DeviceConfig_button_gpio_tag 4 #define meshtastic_Config_DeviceConfig_buzzer_gpio_tag 5 #define meshtastic_Config_DeviceConfig_rebroadcast_mode_tag 6 @@ -758,14 +748,12 @@ extern "C" { #define meshtastic_Config_BluetoothConfig_enabled_tag 1 #define meshtastic_Config_BluetoothConfig_mode_tag 2 #define meshtastic_Config_BluetoothConfig_fixed_pin_tag 3 -#define meshtastic_Config_BluetoothConfig_device_logging_enabled_tag 4 #define meshtastic_Config_SecurityConfig_public_key_tag 1 #define meshtastic_Config_SecurityConfig_private_key_tag 2 #define meshtastic_Config_SecurityConfig_admin_key_tag 3 #define meshtastic_Config_SecurityConfig_is_managed_tag 4 #define meshtastic_Config_SecurityConfig_serial_enabled_tag 5 #define meshtastic_Config_SecurityConfig_debug_log_api_enabled_tag 6 -#define meshtastic_Config_SecurityConfig_bluetooth_logging_enabled_tag 7 #define meshtastic_Config_SecurityConfig_admin_channel_enabled_tag 8 #define meshtastic_Config_device_tag 1 #define meshtastic_Config_position_tag 2 @@ -803,7 +791,6 @@ X(a, STATIC, ONEOF, MESSAGE, (payload_variant,sessionkey,payload_variant.s #define meshtastic_Config_DeviceConfig_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, UENUM, role, 1) \ X(a, STATIC, SINGULAR, BOOL, serial_enabled, 2) \ -X(a, STATIC, SINGULAR, BOOL, debug_log_enabled, 3) \ X(a, STATIC, SINGULAR, UINT32, button_gpio, 4) \ X(a, STATIC, SINGULAR, UINT32, buzzer_gpio, 5) \ X(a, STATIC, SINGULAR, UENUM, rebroadcast_mode, 6) \ @@ -906,8 +893,7 @@ X(a, STATIC, SINGULAR, BOOL, ignore_mqtt, 104) #define meshtastic_Config_BluetoothConfig_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, BOOL, enabled, 1) \ X(a, STATIC, SINGULAR, UENUM, mode, 2) \ -X(a, STATIC, SINGULAR, UINT32, fixed_pin, 3) \ -X(a, STATIC, SINGULAR, BOOL, device_logging_enabled, 4) +X(a, STATIC, SINGULAR, UINT32, fixed_pin, 3) #define meshtastic_Config_BluetoothConfig_CALLBACK NULL #define meshtastic_Config_BluetoothConfig_DEFAULT NULL @@ -918,7 +904,6 @@ X(a, STATIC, SINGULAR, BYTES, admin_key, 3) \ X(a, STATIC, SINGULAR, BOOL, is_managed, 4) \ X(a, STATIC, SINGULAR, BOOL, serial_enabled, 5) \ X(a, STATIC, SINGULAR, BOOL, debug_log_api_enabled, 6) \ -X(a, STATIC, SINGULAR, BOOL, bluetooth_logging_enabled, 7) \ X(a, STATIC, SINGULAR, BOOL, admin_channel_enabled, 8) #define meshtastic_Config_SecurityConfig_CALLBACK NULL #define meshtastic_Config_SecurityConfig_DEFAULT NULL @@ -955,15 +940,15 @@ extern const pb_msgdesc_t meshtastic_Config_SessionkeyConfig_msg; /* Maximum encoded size of messages (where known) */ #define MESHTASTIC_MESHTASTIC_CONFIG_PB_H_MAX_SIZE meshtastic_Config_size -#define meshtastic_Config_BluetoothConfig_size 12 -#define meshtastic_Config_DeviceConfig_size 100 +#define meshtastic_Config_BluetoothConfig_size 10 +#define meshtastic_Config_DeviceConfig_size 98 #define meshtastic_Config_DisplayConfig_size 30 #define meshtastic_Config_LoRaConfig_size 82 #define meshtastic_Config_NetworkConfig_IpV4Config_size 20 #define meshtastic_Config_NetworkConfig_size 196 #define meshtastic_Config_PositionConfig_size 62 #define meshtastic_Config_PowerConfig_size 52 -#define meshtastic_Config_SecurityConfig_size 112 +#define meshtastic_Config_SecurityConfig_size 110 #define meshtastic_Config_SessionkeyConfig_size 0 #define meshtastic_Config_size 199 diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index 343e5f48af..976e0e1358 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -358,7 +358,7 @@ extern const pb_msgdesc_t meshtastic_OEMStore_msg; #define MESHTASTIC_MESHTASTIC_DEVICEONLY_PB_H_MAX_SIZE meshtastic_OEMStore_size #define meshtastic_ChannelFile_size 718 #define meshtastic_NodeInfoLite_size 183 -#define meshtastic_OEMStore_size 3502 +#define meshtastic_OEMStore_size 3496 #define meshtastic_PositionLite_size 28 #define meshtastic_UserLite_size 96 diff --git a/src/mesh/generated/meshtastic/localonly.pb.h b/src/mesh/generated/meshtastic/localonly.pb.h index c612b24abd..38529fc146 100644 --- a/src/mesh/generated/meshtastic/localonly.pb.h +++ b/src/mesh/generated/meshtastic/localonly.pb.h @@ -187,7 +187,7 @@ extern const pb_msgdesc_t meshtastic_LocalModuleConfig_msg; /* Maximum encoded size of messages (where known) */ #define MESHTASTIC_MESHTASTIC_LOCALONLY_PB_H_MAX_SIZE meshtastic_LocalModuleConfig_size -#define meshtastic_LocalConfig_size 669 +#define meshtastic_LocalConfig_size 663 #define meshtastic_LocalModuleConfig_size 687 #ifdef __cplusplus From eddb72705f4b540970dbc141539b1e97edf0f816 Mon Sep 17 00:00:00 2001 From: Nestpebble <116762865+Nestpebble@users.noreply.github.com> Date: Sat, 24 Aug 2024 02:24:23 +0100 Subject: [PATCH 23/40] add a .yml to setup a Gitpod instance quickly (#4551) * Create .gitpod.yml * Update .gitpod.yml --- .gitpod.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000000..0af235a3ac --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,2 @@ +tasks: + - init: pip install platformio && pip install --upgrade pip From 17b2a83b44fdf5e4788ec16d8de1aee389a3cf08 Mon Sep 17 00:00:00 2001 From: John Hollowell Date: Fri, 23 Aug 2024 21:25:16 -0400 Subject: [PATCH 24/40] Add devcontainer (#4491) devcontainers can be used by IDEs/editors like VS Code to create a standardized development environment in a container --- .devcontainer/Dockerfile | 24 ++++++++++++++++++++++++ .devcontainer/devcontainer.json | 28 ++++++++++++++++++++++++++++ .devcontainer/setup.sh | 3 +++ 3 files changed, 55 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json create mode 100755 .devcontainer/setup.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..82f4d91bf6 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,24 @@ +FROM mcr.microsoft.com/devcontainers/cpp:1-debian-12 + +# [Optional] Uncomment this section to install additional packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends \ + ca-certificates \ + g++ \ + git \ + libbluetooth-dev \ + libgpiod-dev \ + liborcania-dev \ + libssl-dev \ + libulfius-dev \ + libyaml-cpp-dev \ + pkg-config \ + python3 \ + python3-pip \ + python3-venv \ + python3-wheel \ + wget \ + zip \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + +RUN pip3 install --no-cache-dir -U platformio==6.1.15 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..e45fd5d936 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,28 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/cpp +{ + "name": "Meshtastic Firmware Dev", + "build": { + "dockerfile": "Dockerfile" + }, + "features": { + "ghcr.io/devcontainers/features/python:1": { + "installTools": true, + "version": "latest" + } + }, + "customizations": { + "vscode": { + "extensions": [ + "ms-vscode.cpptools", + "platformio.platformio-ide", + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + "forwardPorts": [ 4403 ], + + // Run commands to prepare the container for use + "postCreateCommand": ".devcontainer/setup.sh", +} diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh new file mode 100755 index 0000000000..866a4a417a --- /dev/null +++ b/.devcontainer/setup.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +git submodule update --init \ No newline at end of file From 059d5582d15c5922e437ffd0a6a772fc50fbfdf8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 23 Aug 2024 20:44:14 -0500 Subject: [PATCH 25/40] [create-pull-request] automated change (#4544) Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com> --- protobufs | 2 +- src/mesh/generated/meshtastic/mesh.pb.h | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/protobufs b/protobufs index 183ba970a7..52cfa2c1c2 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 183ba970a7a71de7a81541b74c413543523417d2 +Subproject commit 52cfa2c1c2cd5a1a714e1338d551d967f674fca8 diff --git a/src/mesh/generated/meshtastic/mesh.pb.h b/src/mesh/generated/meshtastic/mesh.pb.h index f32f865db7..d612d74be4 100644 --- a/src/mesh/generated/meshtastic/mesh.pb.h +++ b/src/mesh/generated/meshtastic/mesh.pb.h @@ -189,6 +189,13 @@ typedef enum _meshtastic_HardwareModel { meshtastic_HardwareModel_RADIOMASTER_900_BANDIT = 74, /* Minewsemi ME25LS01 (ME25LE01_V1.0). NRF52840 w/ LR1110 radio, buttons and leds and pins. */ meshtastic_HardwareModel_ME25LS01_4Y10TD = 75, + /* RP2040_FEATHER_RFM95 + Adafruit Feather RP2040 with RFM95 LoRa Radio RFM95 with SX1272, SSD1306 OLED + https://www.adafruit.com/product/5714 + https://www.adafruit.com/product/326 + https://www.adafruit.com/product/938 + ^^^ short A0 to switch to I2C address 0x3C */ + meshtastic_HardwareModel_RP2040_FEATHER_RFM95 = 76, /* ------------------------------------------------------------------------------------------------------------------------------------------ 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. ------------------------------------------------------------------------------------------------------------------------------------------ */ From c11a66030f5c35d32d26c0e750d52b851c071984 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sat, 24 Aug 2024 12:19:31 -0500 Subject: [PATCH 26/40] Userlite mem comparison (#4552) --- src/mesh/NodeDB.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 0504cc273e..3af6c6a454 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1027,9 +1027,10 @@ bool NodeDB::updateUser(uint32_t nodeId, meshtastic_User &p, uint8_t channelInde #endif // Both of info->user and p start as filled with zero so I think this is okay - bool changed = memcmp(&info->user, &p, sizeof(info->user)) || (info->channel != channelIndex); + auto lite = TypeConversions::ConvertToUserLite(p); + bool changed = memcmp(&info->user, &lite, sizeof(info->user)) || (info->channel != channelIndex); - info->user = TypeConversions::ConvertToUserLite(p); + info->user = lite; if (info->user.public_key.size == 32) { printBytes("Saved Pubkey: ", info->user.public_key.bytes, 32); } From 927a35ef51c5e644432def8581757231c7a526f1 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Mon, 26 Aug 2024 07:48:07 -0500 Subject: [PATCH 27/40] Protos --- protobufs | 2 +- src/mesh/generated/meshtastic/config.pb.h | 11 ++++++----- src/mesh/generated/meshtastic/deviceonly.pb.h | 2 +- src/mesh/generated/meshtastic/localonly.pb.h | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/protobufs b/protobufs index 52cfa2c1c2..431291e673 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 52cfa2c1c2cd5a1a714e1338d551d967f674fca8 +Subproject commit 431291e673c1c7592ee64cb972d7845589f60138 diff --git a/src/mesh/generated/meshtastic/config.pb.h b/src/mesh/generated/meshtastic/config.pb.h index d79654856e..eb03ddc586 100644 --- a/src/mesh/generated/meshtastic/config.pb.h +++ b/src/mesh/generated/meshtastic/config.pb.h @@ -532,7 +532,8 @@ typedef struct _meshtastic_Config_SecurityConfig { Used to create a shared key with a remote device. */ meshtastic_Config_SecurityConfig_private_key_t private_key; /* The public key authorized to send admin messages to this node. */ - meshtastic_Config_SecurityConfig_admin_key_t admin_key; + pb_size_t admin_key_count; + meshtastic_Config_SecurityConfig_admin_key_t admin_key[1]; /* If true, device is considered to be "managed" by a mesh administrator via admin messages Device is managed by a mesh administrator. */ bool is_managed; @@ -657,7 +658,7 @@ extern "C" { #define meshtastic_Config_DisplayConfig_init_default {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0, _meshtastic_Config_DisplayConfig_CompassOrientation_MIN} #define meshtastic_Config_LoRaConfig_init_default {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0} #define meshtastic_Config_BluetoothConfig_init_default {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0} -#define meshtastic_Config_SecurityConfig_init_default {{0, {0}}, {0, {0}}, {0, {0}}, 0, 0, 0, 0} +#define meshtastic_Config_SecurityConfig_init_default {{0, {0}}, {0, {0}}, 0, {{0, {0}}}, 0, 0, 0, 0} #define meshtastic_Config_SessionkeyConfig_init_default {0} #define meshtastic_Config_init_zero {0, {meshtastic_Config_DeviceConfig_init_zero}} #define meshtastic_Config_DeviceConfig_init_zero {_meshtastic_Config_DeviceConfig_Role_MIN, 0, 0, 0, _meshtastic_Config_DeviceConfig_RebroadcastMode_MIN, 0, 0, 0, 0, "", 0} @@ -668,7 +669,7 @@ extern "C" { #define meshtastic_Config_DisplayConfig_init_zero {0, _meshtastic_Config_DisplayConfig_GpsCoordinateFormat_MIN, 0, 0, 0, _meshtastic_Config_DisplayConfig_DisplayUnits_MIN, _meshtastic_Config_DisplayConfig_OledType_MIN, _meshtastic_Config_DisplayConfig_DisplayMode_MIN, 0, 0, _meshtastic_Config_DisplayConfig_CompassOrientation_MIN} #define meshtastic_Config_LoRaConfig_init_zero {0, _meshtastic_Config_LoRaConfig_ModemPreset_MIN, 0, 0, 0, 0, _meshtastic_Config_LoRaConfig_RegionCode_MIN, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0} #define meshtastic_Config_BluetoothConfig_init_zero {0, _meshtastic_Config_BluetoothConfig_PairingMode_MIN, 0} -#define meshtastic_Config_SecurityConfig_init_zero {{0, {0}}, {0, {0}}, {0, {0}}, 0, 0, 0, 0} +#define meshtastic_Config_SecurityConfig_init_zero {{0, {0}}, {0, {0}}, 0, {{0, {0}}}, 0, 0, 0, 0} #define meshtastic_Config_SessionkeyConfig_init_zero {0} /* Field tags (for use in manual encoding/decoding) */ @@ -900,7 +901,7 @@ X(a, STATIC, SINGULAR, UINT32, fixed_pin, 3) #define meshtastic_Config_SecurityConfig_FIELDLIST(X, a) \ X(a, STATIC, SINGULAR, BYTES, public_key, 1) \ X(a, STATIC, SINGULAR, BYTES, private_key, 2) \ -X(a, STATIC, SINGULAR, BYTES, admin_key, 3) \ +X(a, STATIC, REPEATED, BYTES, admin_key, 3) \ X(a, STATIC, SINGULAR, BOOL, is_managed, 4) \ X(a, STATIC, SINGULAR, BOOL, serial_enabled, 5) \ X(a, STATIC, SINGULAR, BOOL, debug_log_api_enabled, 6) \ @@ -948,7 +949,7 @@ extern const pb_msgdesc_t meshtastic_Config_SessionkeyConfig_msg; #define meshtastic_Config_NetworkConfig_size 196 #define meshtastic_Config_PositionConfig_size 62 #define meshtastic_Config_PowerConfig_size 52 -#define meshtastic_Config_SecurityConfig_size 110 +#define meshtastic_Config_SecurityConfig_size 111 #define meshtastic_Config_SessionkeyConfig_size 0 #define meshtastic_Config_size 199 diff --git a/src/mesh/generated/meshtastic/deviceonly.pb.h b/src/mesh/generated/meshtastic/deviceonly.pb.h index 976e0e1358..6924022105 100644 --- a/src/mesh/generated/meshtastic/deviceonly.pb.h +++ b/src/mesh/generated/meshtastic/deviceonly.pb.h @@ -358,7 +358,7 @@ extern const pb_msgdesc_t meshtastic_OEMStore_msg; #define MESHTASTIC_MESHTASTIC_DEVICEONLY_PB_H_MAX_SIZE meshtastic_OEMStore_size #define meshtastic_ChannelFile_size 718 #define meshtastic_NodeInfoLite_size 183 -#define meshtastic_OEMStore_size 3496 +#define meshtastic_OEMStore_size 3497 #define meshtastic_PositionLite_size 28 #define meshtastic_UserLite_size 96 diff --git a/src/mesh/generated/meshtastic/localonly.pb.h b/src/mesh/generated/meshtastic/localonly.pb.h index 38529fc146..91a23dc4f4 100644 --- a/src/mesh/generated/meshtastic/localonly.pb.h +++ b/src/mesh/generated/meshtastic/localonly.pb.h @@ -187,7 +187,7 @@ extern const pb_msgdesc_t meshtastic_LocalModuleConfig_msg; /* Maximum encoded size of messages (where known) */ #define MESHTASTIC_MESHTASTIC_LOCALONLY_PB_H_MAX_SIZE meshtastic_LocalModuleConfig_size -#define meshtastic_LocalConfig_size 663 +#define meshtastic_LocalConfig_size 664 #define meshtastic_LocalModuleConfig_size 687 #ifdef __cplusplus From 1fe80e0f304986d4fe1a9a8e8faf642b6735e0c9 Mon Sep 17 00:00:00 2001 From: John Milton Date: Mon, 26 Aug 2024 11:28:08 -0400 Subject: [PATCH 28/40] Add support for Adafruit Feather RP2040 with RFM95. (#4451) * Add support for Adafruit Feather RP2040 with RFM95. * Update mesh.pb.h dropping this change from the file generated by the protobuf * Update mesh.pb.h remove these reverting changes * Update mesh.pb.h oops, missed a comma --- src/platform/rp2040/architecture.h | 2 + variants/feather_rp2040_rfm95/platformio.ini | 16 +++++ variants/feather_rp2040_rfm95/variant.h | 61 ++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 variants/feather_rp2040_rfm95/platformio.ini create mode 100644 variants/feather_rp2040_rfm95/variant.h diff --git a/src/platform/rp2040/architecture.h b/src/platform/rp2040/architecture.h index d7d7214c0d..3f75735d34 100644 --- a/src/platform/rp2040/architecture.h +++ b/src/platform/rp2040/architecture.h @@ -29,4 +29,6 @@ #define HW_VENDOR meshtastic_HardwareModel_SENSELORA_RP2040 #elif defined(RP2040_LORA) #define HW_VENDOR meshtastic_HardwareModel_RP2040_LORA +#elif defined(RP2040_FEATHER_RFM95) +#define HW_VENDOR meshtastic_HardwareModel_RP2040_FEATHER_RFM95 #endif \ No newline at end of file diff --git a/variants/feather_rp2040_rfm95/platformio.ini b/variants/feather_rp2040_rfm95/platformio.ini new file mode 100644 index 0000000000..a28ad76557 --- /dev/null +++ b/variants/feather_rp2040_rfm95/platformio.ini @@ -0,0 +1,16 @@ +[env:feather_rp2040_rfm95] +extends = rp2040_base +board = adafruit_feather +upload_protocol = picotool + +# add our variants files to the include and src paths +build_flags = ${rp2040_base.build_flags} + -DRP2040_FEATHER_RFM95 + -Ivariants/feather_rp2040_rfm95 + -DDEBUG_RP2040_PORT=Serial + -DHW_SPI1_DEVICE + -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m0plus" +lib_deps = + ${rp2040_base.lib_deps} +debug_build_flags = ${rp2040_base.build_flags} +debug_tool = cmsis-dap ; for e.g. Picotool \ No newline at end of file diff --git a/variants/feather_rp2040_rfm95/variant.h b/variants/feather_rp2040_rfm95/variant.h new file mode 100644 index 0000000000..e9e178202a --- /dev/null +++ b/variants/feather_rp2040_rfm95/variant.h @@ -0,0 +1,61 @@ +// #define RADIOLIB_CUSTOM_ARDUINO 1 +// #define RADIOLIB_TONE_UNSUPPORTED 1 +// #define RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED 1 + +#define ARDUINO_ARCH_AVR + +// #define USE_SSD1306 + +// #define USE_SH1106 1 + +// default I2C pins: +// SDA = 4 +// SCL = 5 + +// Recommended pins for SerialModule: +// txd = 8 +// rxd = 9 + +#define EXT_NOTIFY_OUT 22 +#define BUTTON_PIN 7 +// #define BUTTON_NEED_PULLUP + +#define LED_PIN PIN_LED + +// #define BATTERY_PIN 26 +// ratio of voltage divider = 3.0 (R17=200k, R18=100k) +// #define ADC_MULTIPLIER 3.1 // 3.0 + a bit for being optimistic + +#define USE_RF95 // RFM95/SX127x + +#undef LORA_SCK +#undef LORA_MISO +#undef LORA_MOSI +#undef LORA_CS + +// https://www.adafruit.com/product/5714 +// https://learn.adafruit.com/feather-rp2040-rfm95 +// https://learn.adafruit.com/assets/120283 +// https://learn.adafruit.com/assets/120813 +#define LORA_SCK 14 // 10 12P +#define LORA_MISO 8 // 12 10P +#define LORA_MOSI 15 // 11 11P +#define LORA_CS 16 // 3 13P + +#define LORA_RESET 17 // 15 14P + +#define LORA_DIO0 21 // ?? 6P +#define LORA_DIO1 22 // 20 7P +#define LORA_DIO2 23 // 2 8P +#define LORA_DIO3 19 // ?? 3P +#define LORA_DIO4 20 // ?? 4P +#define LORA_DIO5 18 // ?? 15P + +#ifdef USE_SX1262 +#define SX126X_CS LORA_CS +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +#define SX126X_DIO2_AS_RF_SWITCH +// #define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#endif \ No newline at end of file From 574124aee55dfc79d5e40053ec12887d83e48c02 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 26 Aug 2024 12:29:44 -0500 Subject: [PATCH 29/40] Deal with admin_key being repeated (#4558) --- src/mesh/NodeDB.cpp | 6 +++--- src/modules/AdminModule.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 3af6c6a454..fa736e08ac 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -292,10 +292,10 @@ void NodeDB::installDefaultConfig() config.lora.ignore_mqtt = false; #endif #ifdef ADMIN_KEY_USERPREFS - memcpy(config.security.admin_key.bytes, admin_key_userprefs, 32); - config.security.admin_key.size = 32; + memcpy(config.security.admin_key[0].bytes, admin_key_userprefs, 32); + config.security.admin_key[0].size = 32; #else - config.security.admin_key.size = 0; + config.security.admin_key[0].size = 0; #endif config.security.public_key.size = 0; config.security.private_key.size = 0; diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index ef60a4bf2c..b63eca3964 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -75,7 +75,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta // and only allowing responses from that remote. if (!((mp.from == 0 && !config.security.is_managed) || messageIsResponse(r) || (strcasecmp(ch->settings.name, Channels::adminChannel) == 0 && config.security.admin_channel_enabled) || - (mp.pki_encrypted && memcmp(mp.public_key.bytes, config.security.admin_key.bytes, 32) == 0))) { + (mp.pki_encrypted && memcmp(mp.public_key.bytes, config.security.admin_key[0].bytes, 32) == 0))) { LOG_INFO("Ignoring admin payload %i\n", r->which_payload_variant); return handled; } From 3c4d964334788e7c335268c746ed0c9eb6947d32 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Mon, 26 Aug 2024 15:48:47 -0500 Subject: [PATCH 30/40] Mask out random bits when doing queue ordering (#4561) * Mask out random bits when doing queue ordering * Parenthesis --- src/mesh/MeshPacketQueue.cpp | 7 ++++--- src/mesh/MeshTypes.h | 5 +++-- src/mesh/Router.cpp | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/mesh/MeshPacketQueue.cpp b/src/mesh/MeshPacketQueue.cpp index 24756fd2a4..f1c6c4ff34 100644 --- a/src/mesh/MeshPacketQueue.cpp +++ b/src/mesh/MeshPacketQueue.cpp @@ -20,8 +20,9 @@ bool CompareMeshPacketFunc(const meshtastic_MeshPacket *p1, const meshtastic_Mes // If priorities differ, use that // for equal priorities, order by id (older packets have higher priority - this will briefly be wrong when IDs roll over but // no big deal) - return (p1p != p2p) ? (p1p < p2p) // prefer bigger priorities - : (p1->id >= p2->id); // prefer smaller packet ids + return (p1p != p2p) + ? (p1p < p2p) // prefer bigger priorities + : ((p1->id & ID_COUNTER_MASK) >= (p2->id & ID_COUNTER_MASK)); // Mask to counter portion, prefer smaller packet ids } MeshPacketQueue::MeshPacketQueue(size_t _maxLen) : maxLen(_maxLen) {} @@ -127,4 +128,4 @@ bool MeshPacketQueue::replaceLowerPriorityPacket(meshtastic_MeshPacket *p) std::make_heap(queue.begin(), queue.end(), &CompareMeshPacketFunc); return true; -} +} \ No newline at end of file diff --git a/src/mesh/MeshTypes.h b/src/mesh/MeshTypes.h index c0919bf5d3..1c9099c39e 100644 --- a/src/mesh/MeshTypes.h +++ b/src/mesh/MeshTypes.h @@ -14,8 +14,9 @@ typedef uint32_t PacketId; // A packet sequence number 1 // Reserved to only deliver packets over high speed (non-lora) transports, such as MQTT or BLE mesh (not yet implemented) #define ERRNO_OK 0 #define ERRNO_NO_INTERFACES 33 -#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER -#define ERRNO_DISABLED 34 // the interface is disabled +#define ERRNO_UNKNOWN 32 // pick something that doesn't conflict with RH_ROUTER_ERROR_UNABLE_TO_DELIVER +#define ERRNO_DISABLED 34 // the interface is disabled +#define ID_COUNTER_MASK (UINT32_MAX >> 22) // mask to select the counter portion of the ID /* * Source of a received message diff --git a/src/mesh/Router.cpp b/src/mesh/Router.cpp index bdd8c4e6c9..61b1bbfb61 100644 --- a/src/mesh/Router.cpp +++ b/src/mesh/Router.cpp @@ -109,7 +109,7 @@ PacketId generatePacketId() rollingPacketId++; - rollingPacketId &= UINT32_MAX >> 22; // Mask out the top 22 bits + rollingPacketId &= ID_COUNTER_MASK; // Mask out the top 22 bits PacketId id = rollingPacketId | random(UINT32_MAX & 0x7fffffff) << 10; // top 22 bits LOG_DEBUG("Partially randomized packet id %u\n", id); return id; From e3ce3a3a4f478ebaf266a1335e6e40f4cbb93f42 Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Tue, 27 Aug 2024 14:49:58 -0500 Subject: [PATCH 31/40] Don't compare nodeDB macaddr to owner.macaddr, because in rare cases that may be unset. (#4562) Co-authored-by: Ben Meadors --- src/mesh/NodeDB.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index fa736e08ac..8409eaff6f 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -620,7 +620,7 @@ void NodeDB::pickNewNodeNum() meshtastic_NodeInfoLite *found; while ((nodeNum == NODENUM_BROADCAST || nodeNum < NUM_RESERVED) || - ((found = getMeshNode(nodeNum)) && memcmp(found->user.macaddr, owner.macaddr, sizeof(owner.macaddr)) != 0)) { + ((found = getMeshNode(nodeNum)) && memcmp(found->user.macaddr, ourMacAddr, sizeof(ourMacAddr)) != 0)) { NodeNum candidate = random(NUM_RESERVED, LONG_MAX); // try a new random choice LOG_WARN("NOTE! Our desired nodenum 0x%x is invalid or in use, so trying for 0x%x\n", nodeNum, candidate); nodeNum = candidate; From cc93df27a5835ebe90649d1351c451d0fdffd789 Mon Sep 17 00:00:00 2001 From: Power Li Date: Wed, 28 Aug 2024 05:26:02 +0800 Subject: [PATCH 32/40] set current time to system time in portduino build (#4556) * set current time to system time in portduino build * fix includes order --------- Co-authored-by: Jonathan Bennett --- src/platform/portduino/PortduinoGlue.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index 3532d2e79f..cce893c0b4 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -1,5 +1,6 @@ #include "CryptoEngine.h" #include "PortduinoGPIO.h" +#include "RTC.h" #include "SPIChip.h" #include "mesh/RF95Interface.h" #include "sleep.h" @@ -370,6 +371,12 @@ void portduinoSetup() exit(EXIT_FAILURE); } } + + struct timeval tv; + tv.tv_sec = time(NULL); + tv.tv_usec = 0; + perhapsSetRTC(RTCQualityNTP, &tv); + return; } From 72c82c1c08b83986fe9afdf5b55fa10d9933e308 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Tue, 27 Aug 2024 18:24:14 -0500 Subject: [PATCH 33/40] Add RAK4631 hex to firmware release --- bin/build-nrf52.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/build-nrf52.sh b/bin/build-nrf52.sh index 060d06cfda..9d0b3dfddc 100755 --- a/bin/build-nrf52.sh +++ b/bin/build-nrf52.sh @@ -46,3 +46,8 @@ else cp bin/device-update.* $OUTDIR cp bin/*.uf2 $OUTDIR fi + +if (echo $1 | grep -q "rak4631"); then + echo "Copying hex file" + cp .pio/build/$1/firmware.hex $OUTDIR/$basename.hex +fi \ No newline at end of file From 94c3bb4a560b0e3e3aa9e4b1c81fa0b6fc0db8af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 28 Aug 2024 12:43:19 +0200 Subject: [PATCH 34/40] fix #4390 (#4571) --- src/serialization/MeshPacketSerializer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/serialization/MeshPacketSerializer.cpp b/src/serialization/MeshPacketSerializer.cpp index a42bb867ae..e00dde024c 100644 --- a/src/serialization/MeshPacketSerializer.cpp +++ b/src/serialization/MeshPacketSerializer.cpp @@ -76,6 +76,13 @@ std::string MeshPacketSerializer::JsonSerialize(const meshtastic_MeshPacket *mp, msgPayload["wind_direction"] = new JSONValue((uint)decoded->variant.environment_metrics.wind_direction); msgPayload["wind_gust"] = new JSONValue(decoded->variant.environment_metrics.wind_gust); msgPayload["wind_lull"] = new JSONValue(decoded->variant.environment_metrics.wind_lull); + } else if (decoded->which_variant == meshtastic_Telemetry_air_quality_metrics_tag) { + msgPayload["pm10"] = new JSONValue((unsigned int)decoded->variant.air_quality_metrics.pm10_standard); + msgPayload["pm25"] = new JSONValue((unsigned int)decoded->variant.air_quality_metrics.pm25_standard); + msgPayload["pm100"] = new JSONValue((unsigned int)decoded->variant.air_quality_metrics.pm100_standard); + msgPayload["pm10_e"] = new JSONValue((unsigned int)decoded->variant.air_quality_metrics.pm10_environmental); + msgPayload["pm25_e"] = new JSONValue((unsigned int)decoded->variant.air_quality_metrics.pm25_environmental); + msgPayload["pm100_e"] = new JSONValue((unsigned int)decoded->variant.air_quality_metrics.pm100_environmental); } else if (decoded->which_variant == meshtastic_Telemetry_power_metrics_tag) { msgPayload["voltage_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_voltage); msgPayload["current_ch1"] = new JSONValue(decoded->variant.power_metrics.ch1_current); From 545d32fcec222a86c487950c21ecbcbf37634d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Cort=C3=AAs?= Date: Mon, 26 Aug 2024 17:15:42 +0100 Subject: [PATCH 35/40] Fix devcontainer Dockerfile build --- .devcontainer/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 82f4d91bf6..c21564491f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -12,6 +12,7 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ libssl-dev \ libulfius-dev \ libyaml-cpp-dev \ + pipx \ pkg-config \ python3 \ python3-pip \ @@ -21,4 +22,4 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ zip \ && apt-get clean && rm -rf /var/lib/apt/lists/* -RUN pip3 install --no-cache-dir -U platformio==6.1.15 \ No newline at end of file +RUN pipx install platformio==6.1.15 \ No newline at end of file From 3ad0af5ce8afa3009009acaf4961c5677377da46 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 Aug 2024 06:43:30 -0500 Subject: [PATCH 36/40] Fix super tiny T1114 tft font size and fork repo to fix compiler warnings (#4573) --- src/graphics/Screen.cpp | 13 ++++++++----- src/graphics/ScreenFonts.h | 3 ++- src/graphics/images.h | 4 ++-- variants/heltec_mesh_node_t114/platformio.ini | 2 +- variants/heltec_vision_master_t190/platformio.ini | 2 +- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 3a4db6ee00..2690d0b70c 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -1093,7 +1093,8 @@ static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, const NodeStat { char usersString[20]; snprintf(usersString, sizeof(usersString), "%d/%d", nodeStatus->getNumOnline(), nodeStatus->getNumTotal()); -#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(HX8357_CS)) && \ +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(USE_ST7789) || \ + defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x, y + 3, 8, 8, imgUser); #else @@ -2414,7 +2415,8 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 #ifdef ARCH_ESP32 if (millis() - storeForwardModule->lastHeartbeat > (storeForwardModule->heartbeatInterval * 1200)) { // no heartbeat, overlap a bit -#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(HX8357_CS)) && \ +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(USE_ST7789) || \ + defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgQuestionL1); @@ -2425,7 +2427,8 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 imgQuestion); #endif } else { -#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(HX8357_CS)) && \ +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(USE_ST7789) || \ + defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 16, 8, imgSFL1); @@ -2439,8 +2442,8 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16 #endif } else { // TODO: Raspberry Pi supports more than just the one screen size -#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(HX8357_CS) || \ - ARCH_PORTDUINO) && \ +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(USE_ST7789) || \ + defined(HX8357_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgInfoL1); diff --git a/src/graphics/ScreenFonts.h b/src/graphics/ScreenFonts.h index 8a48d053e9..41e739fa16 100644 --- a/src/graphics/ScreenFonts.h +++ b/src/graphics/ScreenFonts.h @@ -8,7 +8,8 @@ #include "graphics/fonts/OLEDDisplayFontsUA.h" #endif -#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(HX8357_CS)) && \ +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(USE_ST7789) || \ + defined(HX8357_CS)) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) // The screen is bigger so use bigger fonts #define FONT_SMALL ArialMT_Plain_16 // Height: 19 diff --git a/src/graphics/images.h b/src/graphics/images.h index d4c738610a..ab3767a897 100644 --- a/src/graphics/images.h +++ b/src/graphics/images.h @@ -20,8 +20,8 @@ const uint8_t bluetoothConnectedIcon[36] PROGMEM = {0xfe, 0x01, 0xff, 0x03, 0x03 0xfe, 0x31, 0x00, 0x30, 0x30, 0x30, 0x30, 0x30, 0xf0, 0x3f, 0xe0, 0x1f}; #endif -#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(HX8357_CS) || \ - ARCH_PORTDUINO) && \ +#if (defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS) || defined(ST7789_CS) || defined(USE_ST7789) || \ + defined(HX8357_CS) || ARCH_PORTDUINO) && \ !defined(DISPLAY_FORCE_SMALL_FONTS) const uint8_t imgQuestionL1[] PROGMEM = {0xff, 0x01, 0x01, 0x32, 0x7b, 0x49, 0x49, 0x6f, 0x26, 0x01, 0x01, 0xff}; const uint8_t imgQuestionL2[] PROGMEM = {0x0f, 0x08, 0x08, 0x08, 0x06, 0x0f, 0x0f, 0x06, 0x08, 0x08, 0x08, 0x0f}; diff --git a/variants/heltec_mesh_node_t114/platformio.ini b/variants/heltec_mesh_node_t114/platformio.ini index 99bdf77a72..c2a458f789 100644 --- a/variants/heltec_mesh_node_t114/platformio.ini +++ b/variants/heltec_mesh_node_t114/platformio.ini @@ -12,4 +12,4 @@ build_src_filter = ${nrf52_base.build_src_filter} +<../variants/heltec_mesh_node lib_deps = ${nrf52840_base.lib_deps} lewisxhe/PCF8563_Library@^1.0.1 - https://github.com/Bei-Ji-Quan/st7789#b8e7e076714b670764139289d3829b0beff67edb \ No newline at end of file + https://github.com/meshtastic/st7789#7181320e7ed05c7fb5fd2d32f14723bce6088b7b \ No newline at end of file diff --git a/variants/heltec_vision_master_t190/platformio.ini b/variants/heltec_vision_master_t190/platformio.ini index 38a3169e84..fd00014394 100644 --- a/variants/heltec_vision_master_t190/platformio.ini +++ b/variants/heltec_vision_master_t190/platformio.ini @@ -9,5 +9,5 @@ build_flags = lib_deps = ${esp32s3_base.lib_deps} lewisxhe/PCF8563_Library@^1.0.1 - https://github.com/Bei-Ji-Quan/st7789#b8e7e076714b670764139289d3829b0beff67edb + https://github.com/meshtastic/st7789#7181320e7ed05c7fb5fd2d32f14723bce6088b7b upload_speed = 921600 \ No newline at end of file From ad931799c9d434d6861869cf4e3fa83740346913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 28 Aug 2024 13:51:44 +0200 Subject: [PATCH 37/40] trunk upgrade (#4574) --- .trunk/trunk.yaml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml index 2d9f608997..b20a1ec952 100644 --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -1,36 +1,36 @@ version: 0.1 cli: - version: 1.22.2 + version: 1.22.3 plugins: sources: - id: trunk - ref: v1.5.0 + ref: v1.6.2 uri: https://github.com/trunk-io/plugins lint: enabled: - - trufflehog@3.76.3 + - trufflehog@3.81.9 - yamllint@1.35.1 - - bandit@1.7.8 - - checkov@3.2.95 + - bandit@1.7.9 + - checkov@3.2.238 - terrascan@1.19.1 - - trivy@0.51.1 + - trivy@0.54.1 #- trufflehog@3.63.2-rc0 - - taplo@0.8.1 - - ruff@0.4.4 + - taplo@0.9.3 + - ruff@0.6.2 - isort@5.13.2 - - markdownlint@0.40.0 - - oxipng@9.1.1 + - markdownlint@0.41.0 + - oxipng@9.1.2 - svgo@3.3.2 - - actionlint@1.7.0 - - flake8@7.0.0 + - actionlint@1.7.1 + - flake8@7.1.1 - hadolint@2.12.0 - shfmt@3.6.0 - shellcheck@0.10.0 - - black@24.4.2 + - black@24.8.0 - git-diff-check - - gitleaks@8.18.2 + - gitleaks@8.18.4 - clang-format@16.0.3 - - prettier@3.2.5 + - prettier@3.3.3 ignore: - linters: [ALL] paths: From f5633bf0c5cff3bfc2c83d1ae293cf23664d8ff1 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 Aug 2024 07:24:41 -0500 Subject: [PATCH 38/40] Fix T1000-E default to turn on buzzer for Ext. Notification (#4575) --- src/mesh/NodeDB.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 8409eaff6f..004f27a0d3 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -395,6 +395,12 @@ void NodeDB::installDefaultModuleConfig() moduleConfig.has_store_forward = true; moduleConfig.has_telemetry = true; moduleConfig.has_external_notification = true; +#if defined(PIN_BUZZER) + moduleConfig.external_notification.enabled = true; + moduleConfig.external_notification.output_buzzer = PIN_BUZZER; + moduleConfig.external_notification.alert_message_buzzer = true; + moduleConfig.external_notification.nag_timeout = 60; +#endif #if defined(RAK4630) || defined(RAK11310) // Default to RAK led pin 2 (blue) moduleConfig.external_notification.enabled = true; From a1bf0d8519263a2663db0374211d370cacee0127 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 28 Aug 2024 07:54:50 -0500 Subject: [PATCH 39/40] Add button secondary and enable scan-select on T190 (#4577) --- variants/heltec_vision_master_t190/variant.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/variants/heltec_vision_master_t190/variant.h b/variants/heltec_vision_master_t190/variant.h index 726f6d8648..1da3f99711 100644 --- a/variants/heltec_vision_master_t190/variant.h +++ b/variants/heltec_vision_master_t190/variant.h @@ -1,4 +1,6 @@ #define BUTTON_PIN 0 +#define BUTTON_PIN_SECONDARY 21 // Second built-in button +#define BUTTON_SECONDARY_CANNEDMESSAGES // By default, use the secondary button as canned message input // I2C #define I2C_SDA SDA From dc9f6e1360a8f2e7d8b84886482a9e4322877c75 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Wed, 28 Aug 2024 10:44:46 -0700 Subject: [PATCH 40/40] fix CI warnings (and change CI comment to be correct) --- .github/workflows/build_native.yml | 2 +- src/gps/GPS.h | 2 +- src/graphics/TFTDisplay.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build_native.yml b/.github/workflows/build_native.yml index 3e8b4c001c..51bef0c132 100644 --- a/.github/workflows/build_native.yml +++ b/.github/workflows/build_native.yml @@ -10,7 +10,7 @@ jobs: build-native: runs-on: ubuntu-latest steps: - - name: Install libbluetooth + - name: Install libs needed for native build shell: bash run: | sudo apt-get update --fix-missing diff --git a/src/gps/GPS.h b/src/gps/GPS.h index befa4eef00..c0e9fb8b67 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -157,7 +157,7 @@ class GPS : private concurrency::OSThread * * Normally set by GPS::createGPS() */ - GpioVirtPin *enablePin; + GpioVirtPin *enablePin = NULL; GPS() : concurrency::OSThread("GPS") {} diff --git a/src/graphics/TFTDisplay.cpp b/src/graphics/TFTDisplay.cpp index 1dc4569db2..2849dd9a90 100644 --- a/src/graphics/TFTDisplay.cpp +++ b/src/graphics/TFTDisplay.cpp @@ -25,8 +25,6 @@ extern SX1509 gpioExtender; #define TFT_INVERT true #endif -GpioPin *TFTDisplay::backlightEnable; - class LGFX : public lgfx::LGFX_Device { lgfx::Panel_ST7735S _panel_instance; @@ -515,6 +513,8 @@ static LGFX *tft = nullptr; extern unPhone unphone; #endif +GpioPin *TFTDisplay::backlightEnable = NULL; + TFTDisplay::TFTDisplay(uint8_t address, int sda, int scl, OLEDDISPLAY_GEOMETRY geometry, HW_I2C i2cBus) { LOG_DEBUG("TFTDisplay!\n");