Compare commits

..

No commits in common. "6c7cd9100f07ef64a89a35fc46fa0c7dba649a41" and "afc7528ad75ff1e0aa8c4858efbd79164751cd92" have entirely different histories.

18 changed files with 67 additions and 227 deletions

View File

@ -0,0 +1,16 @@
---
Lora:
## Ebyte E22-900M30S, E22-900M22S with no external RF switching setup
## Will work with any module without RF switching, and with TCXO
Module: sx1262
gpiochip: 1 # subtract 32 from the gpio numbers
DIO2_AS_RF_SWITCH: true
DIO3_TCXO_VOLTAGE: true
CS: 16 #pin6 / GPIO48 1C0
IRQ: 23 #pin17 / GPIO55 1C7
Busy: 22 #pin16 / GPIO54 1C6
Reset: 25 #pin13 / GPIO57 1D1
RXen: 24 #pin12 / GPIO56 1D0
#TXen: bridge to DIO2 on E22 module
spidev: spidev0.0
spiSpeed: 2000000

View File

@ -0,0 +1,16 @@
---
Lora:
## Ebyte E22-900MM22S with no external RF switching setup
## Will work with any module without RF switching and no TCXO
Module: sx1262
gpiochip: 1 # subtract 32 from the gpio numbers
DIO2_AS_RF_SWITCH: true
DIO3_TCXO_VOLTAGE: true
CS: 16 #pin6 / GPIO48 1C0
IRQ: 23 #pin17 / GPIO55 1C7
Busy: 22 #pin16 / GPIO54 1C6
Reset: 25 #pin13 / GPIO57 1D1
RXen: 24 #pin12 / GPIO56 1D0
#TXen: bridge to DIO2 on E22 module
spidev: spidev0.0
spiSpeed: 2000000

View File

@ -0,0 +1,14 @@
---
Lora:
## Heltec HT-RA62, Seeed WIO SX1262
## Will work with any module with automatic RF switching, and with TCXO
Module: sx1262
gpiochip: 1 # subtract 32 from the gpio numbers
DIO2_AS_RF_SWITCH: true
DIO3_TCXO_VOLTAGE: true
CS: 16 #pin6 (GPIO pin 48 1C0)
IRQ: 23 #pin17 (GPIO pin 55 1C7)
Reset: 25 #pin13 (GPIO pin 57 1D1)
Busy: 22 #pin16 (GPIO pin 54 1C6)
spidev: spidev0.0 #pins are (CS=6, CLK=7, MOSI=8, MISO=9)
spiSpeed: 2000000

View File

@ -1,20 +0,0 @@
---
Lora:
## Ebyte E80-900M22S
## This is a bit experimental
##
##
Module: lr1121
gpiochip: 1 # subtract 32 from the gpio numbers
DIO3_TCXO_VOLTAGE: 1.8
CS: 16 #pin6 / GPIO48 1C0
IRQ: 23 #pin17 / GPIO55 1C7
Busy: 22 #pin16 / GPIO54 1C6
Reset: 25 #pin13 / GPIO57 1D1
spidev: spidev0.0 #pins are (CS=16, CLK=17, MOSI=18, MISO=19)
spiSpeed: 2000000
General:
MACAddressSource: eth0

View File

@ -1,21 +0,0 @@
---
Lora:
## Ebyte E22-900M30S, E22-900M22S with or without external RF switching setup
## HT-RA62 (Has internal switching, but whatever)
## Seeed WIO SX1262 (already has TXEN-DIO2 link, but needs RXEN)
## Will work with any module with or without RF switching, and with TCXO
Module: sx1262
gpiochip: 1 # subtract 32 from the gpio numbers
DIO2_AS_RF_SWITCH: true
DIO3_TCXO_VOLTAGE: true
CS: 16 #pin6 / GPIO48 1C0
IRQ: 23 #pin17 / GPIO55 1C7
Busy: 22 #pin16 / GPIO54 1C6
Reset: 25 #pin13 / GPIO57 1D1
RXen: 24 #pin12 / GPIO56 1D0 # Not strictly needed for auto-switching, but why complicate things?
# TXen: bridge to DIO2 on E22 module
spidev: spidev0.0 #pins are (CS=16, CLK=17, MOSI=18, MISO=19)
spiSpeed: 2000000
General:
MACAddressSource: eth0

View File

@ -1,21 +0,0 @@
---
Lora:
## Ebyte E22-900MM22S with no external RF switching setup
## Waveshare SX126X XXXM, AI Thinker RA-01SH
## Will work with any module with or without RF switching and no TCXO
Module: sx1262
gpiochip: 1 # subtract 32 from the gpio numbers
DIO2_AS_RF_SWITCH: true
DIO3_TCXO_VOLTAGE: false
CS: 16 #pin6 / GPIO48 1C0
IRQ: 23 #pin17 / GPIO55 1C7
Busy: 22 #pin16 / GPIO54 1C6
Reset: 25 #pin13 / GPIO57 1D1
RXen: 24 #pin12 / GPIO56 1D0 # Not strictly needed for auto-switching, but why complicate things?
# TXen: bridge to DIO2 on E22 module
spidev: spidev0.0 #pins are (CS=16, CLK=17, MOSI=18, MISO=19)
spiSpeed: 2000000
General:
MACAddressSource: eth0

View File

@ -0,0 +1,13 @@
---
Lora:
## Waveshare SX126X XXXM, AI Thinker RA-01SH
## Will work with any module with automatic RF switching, and with no TCXO
Module: sx1262
gpiochip: 1 # subtract 32 from the gpio numbers
DIO2_AS_RF_SWITCH: true
CS: 16 #pin6 (GPIO pin 48 1C0)
IRQ: 23 #pin17 (GPIO pin 55 1C7)
Reset: 25 #pin13 (GPIO pin 57 1D1)
Busy: 22 #pin16 (GPIO pin 54 1C6)
spidev: spidev0.0 #pins are (CS=6, CLK=7, MOSI=8, MISO=9)
spiSpeed: 2000000

View File

@ -161,4 +161,3 @@ lib_deps =
mprograms/QMC5883LCompass@1.2.3
dfrobot/DFRobot_RTU@1.0.3
https://github.com/meshtastic/DFRobot_LarkWeatherStation#4de3a9cadef0f6a5220a8a906cf9775b02b0040d
robtillaart/INA226@0.6.0

View File

@ -72,9 +72,8 @@ static const uint8_t ext_chrg_detect_value = EXT_CHRG_DETECT_VALUE;
#endif
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO)
INA219Sensor ina219Sensor;
INA226Sensor ina226Sensor;
INA260Sensor ina260Sensor;
INA219Sensor ina219Sensor;
INA3221Sensor ina3221Sensor;
#endif
@ -414,20 +413,7 @@ class AnalogBatteryLevel : public HasBatteryLevel
#ifdef EXT_CHRG_DETECT
return digitalRead(EXT_CHRG_DETECT) == ext_chrg_detect_value;
#else
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && \
!defined(DISABLE_INA_CHARGING_DETECTION)
if (hasINA()) {
// get current flow from INA sensor - negative value means power flowing into the battery
// default assuming BATTERY+ <--> INA_VIN+ <--> SHUNT RESISTOR <--> INA_VIN- <--> LOAD
LOG_DEBUG("Using INA on I2C addr 0x%x for charging detection", config.power.device_battery_ina_address);
#if defined(INA_CHARGING_DETECTION_INVERT)
return getINACurrent() > 0;
#else
return getINACurrent() < 0;
#endif
}
return isBatteryConnect() && isVbusIn();
#endif
#endif
}
@ -464,9 +450,6 @@ class AnalogBatteryLevel : public HasBatteryLevel
{
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
return ina219Sensor.getBusVoltageMv();
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
config.power.device_battery_ina_address) {
return ina226Sensor.getBusVoltageMv();
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first ==
config.power.device_battery_ina_address) {
return ina260Sensor.getBusVoltageMv();
@ -477,20 +460,6 @@ class AnalogBatteryLevel : public HasBatteryLevel
return 0;
}
int16_t getINACurrent()
{
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
return ina219Sensor.getCurrentMa();
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
config.power.device_battery_ina_address) {
return ina226Sensor.getCurrentMa();
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
config.power.device_battery_ina_address) {
return ina3221Sensor.getCurrentMa();
}
return 0;
}
bool hasINA()
{
if (!config.power.device_battery_ina_address) {
@ -500,10 +469,6 @@ class AnalogBatteryLevel : public HasBatteryLevel
if (!ina219Sensor.isInitialized())
return ina219Sensor.runOnce() > 0;
return ina219Sensor.isRunning();
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
config.power.device_battery_ina_address) {
if (!ina226Sensor.isInitialized())
return ina226Sensor.runOnce() > 0;
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first ==
config.power.device_battery_ina_address) {
if (!ina260Sensor.isInitialized())

View File

@ -56,8 +56,6 @@ int32_t PowerTelemetryModule::runOnce()
// therefore, we should only enable the sensor loop if measurement is also enabled
if (ina219Sensor.hasSensor() && !ina219Sensor.isInitialized())
result = ina219Sensor.runOnce();
if (ina226Sensor.hasSensor() && !ina226Sensor.isInitialized())
result = ina226Sensor.runOnce();
if (ina260Sensor.hasSensor() && !ina260Sensor.isInitialized())
result = ina260Sensor.runOnce();
if (ina3221Sensor.hasSensor() && !ina3221Sensor.isInitialized())
@ -172,8 +170,6 @@ bool PowerTelemetryModule::getPowerTelemetry(meshtastic_Telemetry *m)
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
if (ina219Sensor.hasSensor())
valid = ina219Sensor.getMetrics(m);
if (ina226Sensor.hasSensor())
valid = ina226Sensor.getMetrics(m);
if (ina260Sensor.hasSensor())
valid = ina260Sensor.getMetrics(m);
if (ina3221Sensor.hasSensor())

View File

@ -1,13 +0,0 @@
#include "configuration.h"
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
#pragma once
class CurrentSensor
{
public:
virtual int16_t getCurrentMa() = 0;
};
#endif

View File

@ -45,9 +45,4 @@ uint16_t INA219Sensor::getBusVoltageMv()
return lround(ina219.getBusVoltage_V() * 1000);
}
int16_t INA219Sensor::getCurrentMa()
{
return lround(ina219.getCurrent_mA());
}
#endif

View File

@ -3,12 +3,11 @@
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "CurrentSensor.h"
#include "TelemetrySensor.h"
#include "VoltageSensor.h"
#include <Adafruit_INA219.h>
class INA219Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
class INA219Sensor : public TelemetrySensor, VoltageSensor
{
private:
Adafruit_INA219 ina219;
@ -21,7 +20,6 @@ class INA219Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
virtual int32_t runOnce() override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
virtual uint16_t getBusVoltageMv() override;
virtual int16_t getCurrentMa() override;
};
#endif

View File

@ -1,58 +0,0 @@
#include "configuration.h"
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "INA226.h"
#include "INA226Sensor.h"
#include "TelemetrySensor.h"
INA226Sensor::INA226Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_INA226, "INA226") {}
int32_t INA226Sensor::runOnce()
{
LOG_INFO("Init sensor: %s", sensorName);
if (!hasSensor()) {
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}
begin(nodeTelemetrySensorsMap[sensorType].second, nodeTelemetrySensorsMap[sensorType].first);
if (!status) {
status = ina226.begin();
}
return initI2CSensor();
}
void INA226Sensor::setup() {}
void INA226Sensor::begin(TwoWire *wire, uint8_t addr)
{
_wire = wire;
_addr = addr;
ina226 = INA226(_addr, _wire);
_wire->begin();
}
bool INA226Sensor::getMetrics(meshtastic_Telemetry *measurement)
{
measurement->variant.environment_metrics.has_voltage = true;
measurement->variant.environment_metrics.has_current = true;
// mV conversion to V
measurement->variant.environment_metrics.voltage = ina226.getBusVoltage() / 1000;
measurement->variant.environment_metrics.current = ina226.getCurrent_mA();
return true;
}
uint16_t INA226Sensor::getBusVoltageMv()
{
return lround(ina226.getBusVoltage());
}
int16_t INA226Sensor::getCurrentMa()
{
return lround(ina226.getCurrent_mA());
}
#endif

View File

@ -1,30 +0,0 @@
#include "configuration.h"
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "CurrentSensor.h"
#include "TelemetrySensor.h"
#include "VoltageSensor.h"
#include <INA226.h>
class INA226Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
{
private:
uint8_t _addr = INA_ADDR;
TwoWire *_wire = &Wire;
INA226 ina226 = INA226(_addr, _wire);
protected:
virtual void setup() override;
void begin(TwoWire *wire = &Wire, uint8_t addr = INA_ADDR);
public:
INA226Sensor();
virtual int32_t runOnce() override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
virtual uint16_t getBusVoltageMv() override;
virtual int16_t getCurrentMa() override;
};
#endif

View File

@ -102,9 +102,4 @@ uint16_t INA3221Sensor::getBusVoltageMv()
return lround(ina3221.getVoltage(BAT_CH) * 1000);
}
int16_t INA3221Sensor::getCurrentMa()
{
return lround(ina3221.getCurrent(BAT_CH));
}
#endif

View File

@ -3,12 +3,11 @@
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "CurrentSensor.h"
#include "TelemetrySensor.h"
#include "VoltageSensor.h"
#include <INA3221.h>
class INA3221Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
class INA3221Sensor : public TelemetrySensor, VoltageSensor
{
private:
INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
@ -36,7 +35,6 @@ class INA3221Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
int32_t runOnce() override;
bool getMetrics(meshtastic_Telemetry *measurement) override;
virtual uint16_t getBusVoltageMv() override;
virtual int16_t getCurrentMa() override;
};
struct _INA3221Measurement {

View File

@ -42,12 +42,10 @@ extern RTC_NOINIT_ATTR uint64_t RTC_reg_b;
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO)
#include "modules/Telemetry/Sensor/INA219Sensor.h"
#include "modules/Telemetry/Sensor/INA226Sensor.h"
#include "modules/Telemetry/Sensor/INA260Sensor.h"
#include "modules/Telemetry/Sensor/INA3221Sensor.h"
extern INA219Sensor ina219Sensor;
extern INA226Sensor ina226Sensor;
extern INA260Sensor ina260Sensor;
extern INA219Sensor ina219Sensor;
extern INA3221Sensor ina3221Sensor;
#endif