Update Radiomaster target

This commit is contained in:
Thomas Göttgens 2024-11-12 16:53:36 +01:00
parent dd2a4a3121
commit 1898aec281
15 changed files with 118 additions and 29 deletions

View File

@ -59,6 +59,7 @@ build_flags = -Wno-missing-field-initializers
-DUSE_THREAD_NAMES
-DTINYGPS_OPTION_NO_CUSTOM_FIELDS
-DPB_ENABLE_MALLOC=1
-DRADIOLIB_LOW_LEVEL=1
-DRADIOLIB_EXCLUDE_CC1101=1
-DRADIOLIB_EXCLUDE_NRF24=1
-DRADIOLIB_EXCLUDE_RF69=1

View File

@ -170,6 +170,8 @@ bool pauseBluetoothLogging = false;
bool pmu_found;
uint8_t pa_fan_percentage = 50;
#if !MESHTASTIC_EXCLUDE_I2C
// Array map of sensor types with i2c address and wire as we'll find in the i2c scan
std::pair<uint8_t, TwoWire *> nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1] = {};
@ -1086,16 +1088,36 @@ void setup()
mqttInit();
#endif
#ifdef RF95_FAN_EN
// Ability to disable FAN if PIN has been set with RF95_FAN_EN.
#ifdef RADIO_FAN_EN
// Ability to disable FAN if PIN has been set with RADIO_FAN_EN.
// Make sure LoRa has been started before disabling FAN.
if (config.lora.pa_fan_disabled)
digitalWrite(RF95_FAN_EN, LOW ^ 0);
#ifdef RADIO_FAN_PWM
#if defined(ARCH_ESP32)
// Set up PWM at Channel 1 at 25KHz, using 8-bit resolution
// Turn ON/OFF fan to the specified value if enabled by config.
// code by https://github.com/gjelsoe/
if (ledcSetup(1, 25000, 8)) {
ledcAttachPin(RADIO_FAN_EN, 1);
LOG_INFO("PWM init C1 P%d\n", RADIO_FAN_EN);
// Set PWM duty cycle based on fan disabled state
ledcWrite(1, config.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55));
} else {
LOG_WARN("PWM init fail P%d\n", RADIO_FAN_EN);
}
#elif defined(ARCH_NRF52)
pinMode(RF95_FAN_PWM, OUTPUT);
analogWrite(RF95_FAN_PWM, config.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55));
#endif
#else
// Set up as ON/OFF switch of fan
pinMode(RF95_FAN_EN, OUTPUT);
digitalWrite(RADIO_FAN_EN, LOW ^ 0);
#endif
#endif
#ifndef ARCH_PORTDUINO
// Initialize Wifi
// Initialize Wifi
#if HAS_WIFI
initWifi();
#endif

View File

@ -75,6 +75,8 @@ extern uint32_t shutdownAtMsec;
extern uint32_t serialSinceMsec;
extern uint8_t pa_fan_percentage;
// If a thread does something that might need for it to be rescheduled ASAP it can set this flag
// This will suppress the current delay and instead try to run ASAP.
extern bool runASAP;

View File

@ -3,6 +3,7 @@
#include "Throttle.h"
#include "configuration.h"
#include "error.h"
#include "main.h"
#include "mesh/NodeDB.h"
#ifdef LR11X0_DIO_AS_RF_SWITCH
#include "rfswitch.h"
@ -48,6 +49,8 @@ template <typename T> bool LR11x0Interface<T>::init()
digitalWrite(LR11X0_POWER_EN, HIGH);
#endif
enableFan();
// FIXME: correct logic to default to not using TCXO if no voltage is specified for LR11x0_DIO3_TCXO_VOLTAGE
#if !defined(LR11X0_DIO3_TCXO_VOLTAGE)
float tcxoVoltage =
@ -275,6 +278,19 @@ template <typename T> bool LR11x0Interface<T>::isActivelyReceiving()
RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED);
}
template <typename T> void LR11x0Interface<T>::regulateFan()
{
float *pa_temp = 0;
lora.getTemp(pa_temp);
if (*pa_temp > 40) {
pa_fan_percentage = max(pa_fan_percentage + 1, 100);
enableFan();
} else {
pa_fan_percentage = max(pa_fan_percentage - 1, 100);
enableFan();
}
}
template <typename T> bool LR11x0Interface<T>::sleep()
{
// \todo Display actual typename of the adapter, not just `LR11x0`

View File

@ -65,5 +65,7 @@ template <class T> class LR11x0Interface : public RadioLibInterface
virtual void addReceiveMetadata(meshtastic_MeshPacket *mp) override;
virtual void setStandby() override;
void regulateFan();
};
#endif

View File

@ -154,10 +154,7 @@ bool RF95Interface::init()
digitalWrite(RF95_TXEN, 0);
#endif
#ifdef RF95_FAN_EN
pinMode(RF95_FAN_EN, OUTPUT);
digitalWrite(RF95_FAN_EN, 1);
#endif
enableFan();
#ifdef RF95_RXEN
pinMode(RF95_RXEN, OUTPUT);
@ -330,10 +327,7 @@ bool RF95Interface::sleep()
// put chipset into sleep mode
setStandby(); // First cancel any active receiving/sending
lora->sleep();
#ifdef RF95_FAN_EN
digitalWrite(RF95_FAN_EN, 0);
#endif
disableFan();
return true;
}

View File

@ -497,4 +497,37 @@ bool RadioLibInterface::startSend(meshtastic_MeshPacket *txp)
return res == RADIOLIB_ERR_NONE;
}
}
void RadioLibInterface::enableFan()
{
#ifdef RADIO_FAN_EN
#ifdef RADIO_FAN_PWM
#if defined(ARCH_ESP32)
ledcWrite(1, config.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55));
#elif defined(ARCH_NRF52)
analogWrite(RADIO_FAN_EN, config.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55));
#endif
#else
pinMode(RADIO_FAN_EN, OUTPUT);
digitalWrite(RADIO_FAN_EN, 1);
#endif
#endif
}
void RadioLibInterface::disableFan()
{
#ifdef RADIO_FAN_EN
#ifdef RADIO_FAN_PWM
#if defined(ARCH_ESP32)
ledcWrite(1, 0);
#elif defined(ARCH_NRF52)
analogWrite(RADIO_FAN_EN, 0);
#endif
#else
pinMode(RADIO_FAN_EN, OUTPUT);
digitalWrite(RADIO_FAN_EN, 0);
#endif
#endif
}

View File

@ -142,6 +142,9 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified
/** Attempt to cancel a previously sent packet. Returns true if a packet was found we could cancel */
virtual bool cancelSending(NodeNum from, PacketId id) override;
void enableFan();
void disableFan();
private:
/** if we have something waiting to send, start a short (random) timer so we can come check for collision before actually
* doing the transmit */

View File

@ -49,6 +49,8 @@ template <typename T> bool SX126xInterface<T>::init()
pinMode(SX126X_POWER_EN, OUTPUT);
#endif
enableFan();
#if ARCH_PORTDUINO
float tcxoVoltage = 0;
if (settingsMap[dio3_tcxo_voltage])

View File

@ -32,10 +32,7 @@ template <typename T> bool SX128xInterface<T>::init()
digitalWrite(SX128X_POWER_EN, HIGH);
#endif
#ifdef RF95_FAN_EN
pinMode(RF95_FAN_EN, OUTPUT);
digitalWrite(RF95_FAN_EN, 1);
#endif
enableFan();
#if ARCH_PORTDUINO
if (settingsMap[rxen] != RADIOLIB_NC) {

View File

@ -545,13 +545,21 @@ void AdminModule::handleSetConfig(const meshtastic_Config &c)
requiresReboot = false;
}
#ifdef RF95_FAN_EN
#ifdef RADIO_FAN_EN
#ifdef RADIO_FAN_PWM
#if defined(ARCH_ESP32)
ledcWrite(1, c.payload_variant.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55));
#elif defined(ARCH_NFR52)
analogWrite(RADIO_FAN_EN, c.payload_variant.lora.pa_fan_disabled ? 0 : (pa_fan_percentage * 2.55));
#endif
#else
// Turn PA off if disabled by config
if (c.payload_variant.lora.pa_fan_disabled) {
digitalWrite(RF95_FAN_EN, LOW ^ 0);
digitalWrite(RADIO_FAN_EN, LOW ^ 0);
} else {
digitalWrite(RF95_FAN_EN, HIGH ^ 0);
digitalWrite(RADIO_FAN_EN, HIGH ^ 0);
}
#endif
#endif
config.lora = c.payload_variant.lora;
// If we're setting region for the first time, init the region

View File

@ -12,7 +12,7 @@
#define LORA_MISO 19
#define LORA_MOSI 23
#define LORA_CS 5
#define RF95_FAN_EN 17
#define RADIO_FAN_EN 17
// #define LED_PIN 16 // This is a LED_WS2812 not a standard LED
#define HAS_NEOPIXEL // Enable the use of neopixels

View File

@ -46,7 +46,8 @@
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
#define RADIO_FAN_EN 2
#define RADIO_FAN_PWM
/*
LED PIN setup and it has a NeoPixel LED.

View File

@ -32,7 +32,7 @@
This unit has a FAN built-in.
FAN is active at 250mW on it's ExpressLRS Firmware.
*/
#define RF95_FAN_EN 2
#define RADIO_FAN_EN 2
/*
LED PIN setup.

View File

@ -28,6 +28,13 @@
#define LR1121_SPI_MOSI_PIN LORA_MOSI
#define LR1121_SPI_MISO_PIN LORA_MISO
// not yet implemented
#define JANUS_RADIO
#define LR1121_IRQ2_PIN 34
#define LR1121_NRESET2_PIN 21
#define LR1121_BUSY2_PIN 39
#define LR1121_SPI_NSS2_PIN 13
// #define LR11X0_DIO3_TCXO_VOLTAGE 1.6
#define LR11X0_DIO_AS_RF_SWITCH
@ -42,10 +49,11 @@
#undef EXT_NOTIFY_OUT
#define BAT_MEASURE_ADC_UNIT
#define BATTERY_PIN 26
#define ADC_CHANNEL ADC2_GPIO26_CHANNEL
#define BATTERY_SENSE_SAMPLES 30
// #define BAT_MEASURE_ADC_UNIT
// #define BATTERY_PIN 26
// #define ADC_CHANNEL ADC2_GPIO26_CHANNEL
// #define BATTERY_SENSE_SAMPLES 30
// ratio of voltage divider = 2.0 (R42=100k, R43=100k)
#define ADC_MULTIPLIER 2
#define RADIO_FAN_EN 2
// this board does need PWM on the FAN PIN
#define RADIO_FAN_PWM