Просмотр исходного кода

Merge branch 'ripplebiz:dev' into dev

cod3doomy 1 год назад
Родитель
Сommit
c872f72584

+ 9 - 0
src/helpers/ESP32Board.h

@@ -51,6 +51,15 @@ public:
   void onAfterTransmit() override {
     digitalWrite(P_LORA_TX_LED, LOW);   // turn TX LED off
   }
+#elif defined(P_LORA_TX_NEOPIXEL_LED)
+  #define NEOPIXEL_BRIGHTNESS    64  // white brightness (max 255)
+
+  void onBeforeTransmit() override {
+    neopixelWrite(P_LORA_TX_NEOPIXEL_LED, NEOPIXEL_BRIGHTNESS, NEOPIXEL_BRIGHTNESS, NEOPIXEL_BRIGHTNESS);   // turn TX neopixel on (White)
+  }
+  void onAfterTransmit() override {
+    neopixelWrite(P_LORA_TX_NEOPIXEL_LED, 0, 0, 0);   // turn TX neopixel off
+  }
 #endif
 
   uint16_t getBattMilliVolts() override {

+ 5 - 1
src/helpers/esp32/TBeamBoard.cpp

@@ -1,3 +1,5 @@
+#if defined(TBEAM_SUPREME_SX1262) || defined(TBEAM_SX1262) || defined(TBEAM_SX1276)
+
 #include <Arduino.h>
 #include "TBeamBoard.h"
 //#include <RadioLib.h>
@@ -343,4 +345,6 @@ bool TBeamBoard::power_init()
 
   
 // }
-#pragma endregion
+#pragma endregion
+
+#endif

+ 4 - 0
src/helpers/esp32/TBeamBoard.h

@@ -1,5 +1,7 @@
 #pragma once
 
+#if defined(TBEAM_SUPREME_SX1262) || defined(TBEAM_SX1262) || defined(TBEAM_SX1276)
+
 #include <Wire.h>
 #include <Arduino.h>
 #include "XPowersLib.h"
@@ -162,3 +164,5 @@ public:
     return "LilyGo T-Beam";
   }
 };
+
+#endif

+ 1 - 1
src/helpers/nrf52/RAK4631Board.cpp

@@ -84,7 +84,7 @@ bool RAK4631Board::startOTAUpdate(const char* id, char reply[]) {
   memset(mac_addr, 0, sizeof(mac_addr));
   Bluefruit.getAddr(mac_addr);
   sprintf(reply, "OK - mac: %02X:%02X:%02X:%02X:%02X:%02X", 
-      mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
+      mac_addr[5], mac_addr[4], mac_addr[3], mac_addr[2], mac_addr[1], mac_addr[0]);
 
   return true;
 }

+ 7 - 0
src/helpers/stm32/STM32Board.h

@@ -23,6 +23,13 @@ public:
   }
 
   void reboot() override {
+    NVIC_SystemReset(); 
+  }
+
+  void powerOff() override {
+    HAL_PWREx_DisableInternalWakeUpLine();
+    __disable_irq();
+    HAL_PWREx_EnterSHUTDOWNMode();
   }
 
 #if defined(P_LORA_TX_LED)

+ 2 - 2
variants/rak3x72/platformio.ini

@@ -7,6 +7,8 @@ build_flags = ${stm32_base.build_flags}
   -D WRAPPER_CLASS=CustomSTM32WLxWrapper
   -D SPI_INTERFACES_COUNT=0
   -D RX_BOOSTED_GAIN=true
+;  -D STM32WL_TCXO_VOLTAGE=1.6 ; defaults to 0 if undef
+;  -D LORA_TX_POWER=14 ; Defaults to 22 for HP, 14 is for LP version
   -I variants/rak3x72
 build_src_filter = ${stm32_base.build_src_filter}
   +<../variants/rak3x72>
@@ -14,7 +16,6 @@ build_src_filter = ${stm32_base.build_src_filter}
 [env:rak3x72-repeater]
 extends = rak3x72
 build_flags = ${rak3x72.build_flags}
-  -D LORA_TX_POWER=22
   -D ADVERT_NAME='"RAK3x72 Repeater"'
   -D ADMIN_PASSWORD='"password"'
 build_src_filter = ${rak3x72.build_src_filter}
@@ -24,7 +25,6 @@ build_src_filter = ${rak3x72.build_src_filter}
 extends = rak3x72
 build_flags = ${rak3x72.build_flags}
 ;  -D FORMAT_FS=true
-  -D LORA_TX_POWER=22
   -D MAX_CONTACTS=100
   -D MAX_GROUP_CHANNELS=8
 build_src_filter = ${rak3x72.build_src_filter}

+ 10 - 1
variants/rak3x72/target.cpp

@@ -24,12 +24,21 @@ SensorManager sensors;
   #define LORA_CR      5
 #endif
 
+#ifndef STM32WL_TCXO_VOLTAGE
+  // TCXO set to 0 for RAK3172
+  #define STM32WL_TCXO_VOLTAGE 0
+#endif
+
+#ifndef LORA_TX_POWER
+  #define LORA_TX_POWER 22
+#endif
+
 bool radio_init() {
 //  rtc_clock.begin(Wire);
 
   radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
 
-  int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, 0, 0); // TCXO set to 0 for RAK3172
+  int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, STM32WL_TCXO_VOLTAGE, 0); 
 
   if (status != RADIOLIB_ERR_NONE) {
     Serial.print("ERROR: radio init failed: ");

+ 6 - 2
variants/rak3x72/target.h

@@ -18,8 +18,12 @@ public:
     }
 
     uint16_t getBattMilliVolts() override {
-        uint32_t raw = analogRead(PIN_VBAT_READ);            
-        return (ADC_MULTIPLIER * raw) / 1024;
+        analogReadResolution(12);
+        uint32_t raw = 0;
+        for (int i=0; i<8;i++) {
+            raw += analogRead(PIN_VBAT_READ);
+        }            
+        return ((double)raw) * ADC_MULTIPLIER / 8 / 4096;
     }
 };
 

+ 2 - 2
variants/station_g2/platformio.ini

@@ -7,7 +7,7 @@ build_flags =
   -D STATION_G2
   -D RADIO_CLASS=CustomSX1262
   -D WRAPPER_CLASS=CustomSX1262Wrapper
-  -D LORA_TX_POWER=7
+  -D LORA_TX_POWER=19
 ;  -D P_LORA_TX_LED=35
   -D PIN_BOARD_SDA=5
   -D PIN_BOARD_SCL=6
@@ -16,9 +16,9 @@ build_flags =
   -D SX126X_DIO3_TCXO_VOLTAGE=1.8
   -D SX126X_CURRENT_LIMIT=140
 ;  -D SX126X_RX_BOOSTED_GAIN=1 - DO NOT ENABLE THIS!
+;  https://wiki.uniteng.com/en/meshtastic/station-g2#impact-of-lora-node-dense-areashigh-noise-environments-on-rf-performance
   -I src/helpers/ui
   -D DISPLAY_CLASS=SH1106Display
-;  https://wiki.uniteng.com/en/meshtastic/station-g2#impact-of-lora-node-dense-areashigh-noise-environments-on-rf-performance
 build_src_filter = ${esp32_base.build_src_filter}
   +<../variants/station_g2>
   +<helpers/ui/SH1106Display.cpp>

+ 3 - 26
variants/station_g2/target.cpp

@@ -27,36 +27,13 @@ SensorManager sensors;
 bool radio_init() {
   fallback_clock.begin();
   rtc_clock.begin(Wire);
-  
-#ifdef SX126X_DIO3_TCXO_VOLTAGE
-  float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
-#else
-  float tcxo = 1.6f;
-#endif
 
 #if defined(P_LORA_SCLK)
   spi.begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
+  return radio.std_init(&spi);
+#else
+  return radio.std_init();
 #endif
-  int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 8, tcxo);
-  if (status != RADIOLIB_ERR_NONE) {
-    Serial.print("ERROR: radio init failed: ");
-    Serial.println(status);
-    return false;  // fail
-  }
-  
-  radio.setCRC(1);
-  
-#ifdef SX126X_CURRENT_LIMIT
-  radio.setCurrentLimit(SX126X_CURRENT_LIMIT);
-#endif
-#ifdef SX126X_DIO2_AS_RF_SWITCH
-  radio.setDio2AsRfSwitch(SX126X_DIO2_AS_RF_SWITCH);
-#endif
-#ifdef SX126X_RX_BOOSTED_GAIN
-  radio.setRxBoostedGainMode(SX126X_RX_BOOSTED_GAIN);
-#endif
-
-  return true;  // success
 }
 
 uint32_t radio_get_rng_seed() {

+ 65 - 0
variants/tenstar_c3/platformio.ini

@@ -0,0 +1,65 @@
+[Tenstar_esp32_C3]
+extends = esp32_base
+board = esp32-c3-devkitm-1
+build_flags =
+  ${esp32_base.build_flags}
+  -I variants/tenstar_c3
+  -D ESP32_CPU_FREQ=80
+  -D LORA_TX_BOOST_PIN=4
+  -D P_LORA_TX_NEOPIXEL_LED=10
+  -D PIN_VBAT_READ=1
+  -D P_LORA_MISO=9
+  -D P_LORA_SCLK=8
+  -D P_LORA_MOSI=7
+  -D P_LORA_DIO_1=2
+  -D P_LORA_NSS=6
+  -D P_LORA_RESET=RADIOLIB_NC
+  -D P_LORA_BUSY=3
+;  -D PIN_BOARD_SDA=18
+;  -D PIN_BOARD_SCL=19
+  -D SX126X_DIO2_AS_RF_SWITCH=true
+  -D SX126X_DIO3_TCXO_VOLTAGE=1.8
+  -D SX126X_CURRENT_LIMIT=140
+build_src_filter = ${esp32_base.build_src_filter}
+  +<../variants/tenstar_c3>
+
+[env:Tenstar_C3_Repeater_sx1262]
+extends = Tenstar_esp32_C3
+build_src_filter = ${Tenstar_esp32_C3.build_src_filter}
+  +<../examples/simple_repeater/main.cpp>
+build_flags =
+  ${Tenstar_esp32_C3.build_flags}
+  -D RADIO_CLASS=CustomSX1262
+  -D WRAPPER_CLASS=CustomSX1262Wrapper
+  -D SX126X_RX_BOOSTED_GAIN=1
+  -D LORA_TX_POWER=22
+  -D ADVERT_NAME='"Tenstar C3 Repeater"'
+  -D ADVERT_LAT=0.0
+  -D ADVERT_LON=0.0
+  -D ADMIN_PASSWORD='"password"'
+  -D MAX_NEIGHBOURS=8
+;  -D MESH_PACKET_LOGGING=1
+;  -D MESH_DEBUG=1
+lib_deps =
+  ${Tenstar_esp32_C3.lib_deps}
+  ${esp32_ota.lib_deps}
+
+[env:Tenstar_C3_Repeater_sx1268]
+extends = Tenstar_esp32_C3
+build_src_filter = ${Tenstar_esp32_C3.build_src_filter}
+  +<../examples/simple_repeater/main.cpp>
+build_flags =
+  ${Tenstar_esp32_C3.build_flags}
+  -D RADIO_CLASS=CustomSX1268
+  -D WRAPPER_CLASS=CustomSX1268Wrapper
+  -D LORA_TX_POWER=22
+  -D ADVERT_NAME='"Tenstar C3 Repeater"'
+  -D ADVERT_LAT=0.0
+  -D ADVERT_LON=0.0
+  -D ADMIN_PASSWORD='"password"'
+  -D MAX_NEIGHBOURS=8
+ ; -D MESH_PACKET_LOGGING=1
+ ; -D MESH_DEBUG=1
+lib_deps =
+  ${Tenstar_esp32_C3.lib_deps}
+  ${esp32_ota.lib_deps}

+ 48 - 0
variants/tenstar_c3/target.cpp

@@ -0,0 +1,48 @@
+#include <Arduino.h>
+#include "target.h"
+
+XiaoC3Board board;
+
+#if defined(P_LORA_SCLK)
+  static SPIClass spi;
+  RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi);
+#else
+  RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY);
+#endif
+
+WRAPPER_CLASS radio_driver(radio, board);
+
+ESP32RTCClock fallback_clock;
+AutoDiscoverRTCClock rtc_clock(fallback_clock);
+SensorManager sensors;
+
+bool radio_init() {
+  fallback_clock.begin();
+  rtc_clock.begin(Wire);
+
+#if defined(P_LORA_SCLK)
+  return radio.std_init(&spi);
+#else
+  return radio.std_init();
+#endif
+}
+
+uint32_t radio_get_rng_seed() {
+  return radio.random(0x7FFFFFFF);
+}
+
+void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
+  radio.setFrequency(freq);
+  radio.setSpreadingFactor(sf);
+  radio.setBandwidth(bw);
+  radio.setCodingRate(cr);
+}
+
+void radio_set_tx_power(uint8_t dbm) {
+  radio.setOutputPower(dbm);
+}
+
+mesh::LocalIdentity radio_new_identity() {
+  RadioNoiseListener rng(radio);
+  return mesh::LocalIdentity(&rng);  // create new random identity
+}

+ 21 - 0
variants/tenstar_c3/target.h

@@ -0,0 +1,21 @@
+#pragma once
+
+#define RADIOLIB_STATIC_ONLY 1
+#include <RadioLib.h>
+#include <helpers/RadioLibWrappers.h>
+#include <helpers/XiaoC3Board.h>
+#include <helpers/CustomSX1262Wrapper.h>
+#include <helpers/CustomSX1268Wrapper.h>
+#include <helpers/AutoDiscoverRTCClock.h>
+#include <helpers/SensorManager.h>
+
+extern XiaoC3Board board;
+extern WRAPPER_CLASS radio_driver;
+extern AutoDiscoverRTCClock rtc_clock;
+extern SensorManager sensors;
+
+bool radio_init();
+uint32_t radio_get_rng_seed();
+void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
+void radio_set_tx_power(uint8_t dbm);
+mesh::LocalIdentity radio_new_identity();