From d913d7b010fb841d637991ddd1adf2ec633fb017 Mon Sep 17 00:00:00 2001 From: Nickie Deuxyeux Date: Wed, 18 Mar 2026 02:54:44 +0300 Subject: [PATCH] PMU edits --- Boards.h | 31 +++++++++++++++++++------------ Config.h | 11 ++++++++++- Display.h | 4 ++-- Makefile | 6 +++--- Power.h | 23 +++++++++++++++++++++-- RNode_Firmware.ino | 4 ++-- Utilities.h | 8 ++++---- 7 files changed, 61 insertions(+), 26 deletions(-) diff --git a/Boards.h b/Boards.h index a24779c..72fb015 100644 --- a/Boards.h +++ b/Boards.h @@ -252,6 +252,7 @@ const int pin_led_tx = 4; #elif BOARD_MODEL == BOARD_MESHADVENTURER_S3 + #define IS_ESP32S3 true #define HAS_DISPLAY true #define HAS_NP true #define HAS_BLUETOOTH false @@ -266,8 +267,8 @@ #define DIO2_AS_RF_SWITCH false #define HAS_RF_SWITCH_RX_TX true #define HAS_LORA_LNA true - #define LORA_LNA_GAIN 17 - #define LORA_LNA_GVT 12 + #define LORA_LNA_GAIN 30 + #define LORA_LNA_GVT 14 const int pin_cs = 39; const int pin_sclk = 38; @@ -281,10 +282,18 @@ const int pin_tcxo_enable = -1; const int pin_btn_usr1 = 4; - const int pin_led_rx = 11; - const int pin_led_tx = 12; const int pin_np = 48; + #if HAS_NP == false + #if defined(EXTERNAL_LEDS) + const int pin_led_rx = 48; + const int pin_led_tx = 48; + #else + const int pin_led_rx = 48; + const int pin_led_tx = 48; + #endif + #endif + #elif BOARD_MODEL == BOARD_MESHADVENTURER #define HAS_DISPLAY true #define HAS_BLUETOOTH true @@ -298,8 +307,8 @@ #define DIO2_AS_RF_SWITCH false #define HAS_RF_SWITCH_RX_TX true #define HAS_LORA_LNA true - #define LORA_LNA_GAIN 17 - #define LORA_LNA_GVT 12 + #define LORA_LNA_GAIN 30 + #define LORA_LNA_GVT 14 const int pin_cs = 18; const int pin_sclk = 5; @@ -1043,7 +1052,7 @@ #define HAS_BLUETOOTH false #define HAS_BLE true #define HAS_CONSOLE false - #define HAS_PMU false + #define HAS_PMU true #define HAS_NP false #define HAS_SD false #define HAS_TCXO true @@ -1070,8 +1079,6 @@ #define I2C_SDA 8 //P1.04 #define I2C_SCL 7 //P0.11 - #define LED_ON LOW - #define LED_OFF HIGH #define PIN_LED_RED 22 //P0.15 const int pin_led_rx = PIN_LED_RED; const int pin_led_tx = PIN_LED_RED; @@ -1086,10 +1093,10 @@ const int pin_mosi = 14; //P1.15 const int pin_miso = 15; //P0.02 const int pin_busy = 16; //P0.29 - const int pin_dio = 11; //P0.10 + const int pin_dio = 11; //P0.10 + const int pin_rxen = 2; //P0.17 + const int pin_txen = -1; const int pin_tcxo_enable = -1; - const int pin_rxen = 2; //P0.17 - const int pin_txen = -1; #else #error An unsupported nRF board was selected. Cannot compile RNode firmware. diff --git a/Config.h b/Config.h index dec0063..d1374a4 100644 --- a/Config.h +++ b/Config.h @@ -110,7 +110,16 @@ #define CSMA_CW_PER_BAND_WINDOWS 15 #define CSMA_BAND_1_MAX_AIRTIME 7 #define CSMA_BAND_N_MIN_AIRTIME 85 - #define CSMA_INFR_THRESHOLD_DB 11 + + // Increase threshold for specific boards + #if BOARD_MODEL == BOARD_MESHADVENTURER_S3 || BOARD_MODEL == BOARD_MESHADVENTURER + #define CSMA_INFR_THRESHOLD_DB 14 + #elif BOARD_MODEL == BOARD_PROMICRO + #define CSMA_INFR_THRESHOLD_DB 13 + #else + #define CSMA_INFR_THRESHOLD_DB 11 + #endif + #define CSMA_RFENV_RECAL_MS 2500 #define CSMA_RFENV_RECAL_LIMIT_DB -83 bool interference_detected = false; diff --git a/Display.h b/Display.h index 1dc2871..c5cbad9 100644 --- a/Display.h +++ b/Display.h @@ -53,7 +53,7 @@ #elif BOARD_MODEL == BOARD_HELTEC32_V2 || BOARD_MODEL == BOARD_LORA32_V1_0 #define DISP_RST 16 #define DISP_ADDR 0x3C - #define SCL_OLED 15 + #define OBSCL_OLED 15 #define SDA_OLED 4 #elif BOARD_MODEL == BOARD_HELTEC32_V3 #define DISP_RST 21 @@ -73,7 +73,7 @@ #elif BOARD_MODEL == BOARD_MESHADVENTURER_S3 #define DISP_RST -1 #define DISP_ADDR 0x3C - #define SCL_OLED 0 + #define SCL_OLED 44 #define SDA_OLED 42 #elif BOARD_MODEL == BOARD_MESHADVENTURER #define DISP_RST -1 diff --git a/Makefile b/Makefile index 98d841a..22a4c56 100644 --- a/Makefile +++ b/Makefile @@ -143,7 +143,7 @@ firmware-genericesp32: check_bt_buffers arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x35\"" firmware-meshadventurer_s3: check_bt_buffers - arduino-cli compile --log --fqbn esp32:esp32:esp32s3 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF2\"" + arduino-cli compile --log --fqbn "esp32:esp32:esp32s3:CDCOnBoot=cdc" -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF2\"" firmware-meshadventurer: check_bt_buffers arduino-cli compile --log --fqbn esp32:esp32:esp32 -e --build-property "build.partitions=no_ota" --build-property "upload.maximum_size=2097152" --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0xF4\"" @@ -181,8 +181,8 @@ upload-genericesp32: upload-meshadventurer_s3: arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32s3 - @sleep 1 - rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin) +# @sleep 1 +# rnodeconf /dev/ttyACM0 --firmware-hash $$(./partition_hashes ./build/esp32.esp32.esp32s3/RNode_Firmware.ino.bin) @sleep 3 python ./Release/esptool/esptool.py --chip esp32 --port /dev/ttyACM0 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin diff --git a/Power.h b/Power.h index 7ce6d8a..245ac85 100644 --- a/Power.h +++ b/Power.h @@ -164,6 +164,22 @@ float pmu_temperature = PMU_TEMP_MIN-1; bool bat_voltage_dropping = false; float bat_delay_v = 0; float bat_state_change_v = 0; +#elif BOARD_MODEL == BOARD_PROMICRO + #define BAT_V_MIN 3.15 + #define BAT_V_MAX 4.165 + #define BAT_V_CHG 4.48 + #define BAT_V_FLOAT 4.33 + #define BAT_SAMPLES 7 + const uint8_t pin_vbat = 17; + float bat_p_samples[BAT_SAMPLES]; + float bat_v_samples[BAT_SAMPLES]; + uint8_t bat_samples_count = 0; + int bat_discharging_samples = 0; + int bat_charging_samples = 0; + int bat_charged_samples = 0; + bool bat_voltage_dropping = false; + float bat_delay_v = 0; + float bat_state_change_v = 0; #elif BOARD_MODEL == BOARD_TECHO #define BAT_V_MIN 3.15 #define BAT_V_MAX 4.16 @@ -202,7 +218,7 @@ void measure_temperature() { } void measure_battery() { - #if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 || BOARD_MODEL == BOARD_HELTEC32_V3 || BOARD_MODEL == BOARD_HELTEC32_V4 || BOARD_MODEL == BOARD_TDECK || BOARD_MODEL == BOARD_T3S3 || BOARD_MODEL == BOARD_HELTEC_T114 || BOARD_MODEL == BOARD_TECHO + #if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 || BOARD_MODEL == BOARD_HELTEC32_V3 || BOARD_MODEL == BOARD_HELTEC32_V4 || BOARD_MODEL == BOARD_TDECK || BOARD_MODEL == BOARD_T3S3 || BOARD_MODEL == BOARD_HELTEC_T114 || BOARD_MODEL == BOARD_PROMICRO || BOARD_MODEL == BOARD_TECHO battery_installed = true; #if BOARD_MODEL == BOARD_HELTEC32_V3 || BOARD_MODEL == BOARD_HELTEC32_V4 battery_indeterminate = false; @@ -218,6 +234,8 @@ void measure_battery() { float battery_measurement = (float)(analogRead(pin_vbat)) / 4095.0*6.7828; #elif BOARD_MODEL == BOARD_HELTEC_T114 float battery_measurement = (float)(analogRead(pin_vbat)) * 0.017165; + #elif BOARD_MODEL == BOARD_PROMICRO + float battery_measurement = (float)(analogRead(pin_vbat)) * 0.017165; #elif BOARD_MODEL == BOARD_TECHO float battery_measurement = (float)(analogRead(pin_vbat)) * 0.007067; #else @@ -225,6 +243,7 @@ void measure_battery() { #endif bat_v_samples[bat_samples_count%BAT_SAMPLES] = battery_measurement; + bat_p_samples[bat_samples_count%BAT_SAMPLES] = ((battery_voltage-BAT_V_MIN) / (BAT_V_MAX-BAT_V_MIN))*100.0; bat_samples_count++; @@ -411,7 +430,7 @@ bool init_pmu() { pmu_temp_sensor_ready = true; #endif - #if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 || BOARD_MODEL == BOARD_TDECK || BOARD_MODEL == BOARD_T3S3 || BOARD_MODEL == BOARD_TECHO + #if BOARD_MODEL == BOARD_RNODE_NG_21 || BOARD_MODEL == BOARD_LORA32_V2_1 || BOARD_MODEL == BOARD_TDECK || BOARD_MODEL == BOARD_T3S3 || BOARD_MODEL == BOARD_TECHO || BOARD_MODEL == BOARD_PROMICRO pinMode(pin_vbat, INPUT); return true; #elif BOARD_MODEL == BOARD_HELTEC32_V3 diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index f2e071f..02b3590 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -135,14 +135,14 @@ void setup() { boot_seq(); #endif - #if BOARD_MODEL != BOARD_RAK4631 && BOARD_MODEL != BOARD_HELTEC_T114 && BOARD_MODEL != BOARD_PROMICRO && BOARD_MODEL != BOARD_TECHO && BOARD_MODEL != BOARD_T3S3 && BOARD_MODEL != BOARD_TBEAM_S_V1 && BOARD_MODEL != BOARD_HELTEC32_V4 + #if BOARD_MODEL != BOARD_RAK4631 && BOARD_MODEL != BOARD_HELTEC_T114 && BOARD_MODEL != BOARD_MESHADVENTURER_S3 && BOARD_MODEL != BOARD_PROMICRO && BOARD_MODEL != BOARD_TECHO && BOARD_MODEL != BOARD_T3S3 && BOARD_MODEL != BOARD_TBEAM_S_V1 && BOARD_MODEL != BOARD_HELTEC32_V4 // Some boards need to wait until the hardware UART is set up before booting // the full firmware. In the case of the RAK4631 and Heltec T114, the line below will wait // until a serial connection is actually established with a master. Thus, it // is disabled on this platform. while (!Serial); #endif - + serial_interrupt_init(); // Configure input and output pins diff --git a/Utilities.h b/Utilities.h index 44163e5..85fe004 100644 --- a/Utilities.h +++ b/Utilities.h @@ -385,10 +385,10 @@ uint8_t boot_vector = 0x00; void led_id_on() { } void led_id_off() { } #elif BOARD_MODEL == BOARD_PROMICRO - void led_rx_on() { digitalWrite(pin_led_rx, LED_ON); } - void led_rx_off() { digitalWrite(pin_led_rx, LED_OFF); } - void led_tx_on() { digitalWrite(pin_led_tx, LED_ON); } - void led_tx_off() { digitalWrite(pin_led_tx, LED_OFF); } + void led_rx_on() { digitalWrite(pin_led_rx, HIGH); } + void led_rx_off() { digitalWrite(pin_led_rx, LOW); } + void led_tx_on() { digitalWrite(pin_led_tx, HIGH); } + void led_tx_off() { digitalWrite(pin_led_tx, LOW); } void led_id_on() { } void led_id_off() { } #elif BOARD_MODEL == BOARD_HELTEC_T114