mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-19 16:29:31 +00:00
Compare commits
3 Commits
afc7528ad7
...
6c7cd9100f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6c7cd9100f | ||
![]() |
80fc0f2bda | ||
![]() |
fa1a1fd869 |
@ -1,16 +0,0 @@
|
||||
---
|
||||
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
|
@ -1,16 +0,0 @@
|
||||
---
|
||||
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
|
@ -1,14 +0,0 @@
|
||||
---
|
||||
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
|
20
bin/config.d/femtofox/femtofox_LR1121_TCXO.yaml
Normal file
20
bin/config.d/femtofox/femtofox_LR1121_TCXO.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
---
|
||||
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
|
21
bin/config.d/femtofox/femtofox_SX1262_TCXO.yaml
Normal file
21
bin/config.d/femtofox/femtofox_SX1262_TCXO.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
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
|
21
bin/config.d/femtofox/femtofox_SX1262_XTAL.yaml
Normal file
21
bin/config.d/femtofox/femtofox_SX1262_XTAL.yaml
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
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
|
@ -1,13 +0,0 @@
|
||||
---
|
||||
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
|
@ -160,4 +160,5 @@ lib_deps =
|
||||
https://github.com/KodinLanewave/INA3221@1.0.1
|
||||
mprograms/QMC5883LCompass@1.2.3
|
||||
dfrobot/DFRobot_RTU@1.0.3
|
||||
https://github.com/meshtastic/DFRobot_LarkWeatherStation#4de3a9cadef0f6a5220a8a906cf9775b02b0040d
|
||||
https://github.com/meshtastic/DFRobot_LarkWeatherStation#4de3a9cadef0f6a5220a8a906cf9775b02b0040d
|
||||
robtillaart/INA226@0.6.0
|
||||
|
@ -72,8 +72,9 @@ static const uint8_t ext_chrg_detect_value = EXT_CHRG_DETECT_VALUE;
|
||||
#endif
|
||||
|
||||
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO)
|
||||
INA260Sensor ina260Sensor;
|
||||
INA219Sensor ina219Sensor;
|
||||
INA226Sensor ina226Sensor;
|
||||
INA260Sensor ina260Sensor;
|
||||
INA3221Sensor ina3221Sensor;
|
||||
#endif
|
||||
|
||||
@ -413,7 +414,20 @@ 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
|
||||
}
|
||||
|
||||
@ -450,6 +464,9 @@ 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();
|
||||
@ -460,6 +477,20 @@ 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) {
|
||||
@ -469,6 +500,10 @@ 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())
|
||||
@ -1154,4 +1189,4 @@ bool Power::lipoInit()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -56,6 +56,8 @@ 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())
|
||||
@ -170,6 +172,8 @@ 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())
|
||||
@ -253,4 +257,4 @@ bool PowerTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
13
src/modules/Telemetry/Sensor/CurrentSensor.h
Normal file
13
src/modules/Telemetry/Sensor/CurrentSensor.h
Normal file
@ -0,0 +1,13 @@
|
||||
#include "configuration.h"
|
||||
|
||||
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
||||
|
||||
#pragma once
|
||||
|
||||
class CurrentSensor
|
||||
{
|
||||
public:
|
||||
virtual int16_t getCurrentMa() = 0;
|
||||
};
|
||||
|
||||
#endif
|
@ -45,4 +45,9 @@ uint16_t INA219Sensor::getBusVoltageMv()
|
||||
return lround(ina219.getBusVoltage_V() * 1000);
|
||||
}
|
||||
|
||||
int16_t INA219Sensor::getCurrentMa()
|
||||
{
|
||||
return lround(ina219.getCurrent_mA());
|
||||
}
|
||||
|
||||
#endif
|
@ -3,11 +3,12 @@
|
||||
#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
|
||||
class INA219Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
|
||||
{
|
||||
private:
|
||||
Adafruit_INA219 ina219;
|
||||
@ -20,6 +21,7 @@ class INA219Sensor : public TelemetrySensor, VoltageSensor
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
|
||||
virtual uint16_t getBusVoltageMv() override;
|
||||
virtual int16_t getCurrentMa() override;
|
||||
};
|
||||
|
||||
#endif
|
58
src/modules/Telemetry/Sensor/INA226Sensor.cpp
Normal file
58
src/modules/Telemetry/Sensor/INA226Sensor.cpp
Normal file
@ -0,0 +1,58 @@
|
||||
#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
|
30
src/modules/Telemetry/Sensor/INA226Sensor.h
Normal file
30
src/modules/Telemetry/Sensor/INA226Sensor.h
Normal file
@ -0,0 +1,30 @@
|
||||
#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
|
@ -102,4 +102,9 @@ uint16_t INA3221Sensor::getBusVoltageMv()
|
||||
return lround(ina3221.getVoltage(BAT_CH) * 1000);
|
||||
}
|
||||
|
||||
int16_t INA3221Sensor::getCurrentMa()
|
||||
{
|
||||
return lround(ina3221.getCurrent(BAT_CH));
|
||||
}
|
||||
|
||||
#endif
|
@ -3,11 +3,12 @@
|
||||
#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
|
||||
class INA3221Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
|
||||
{
|
||||
private:
|
||||
INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
|
||||
@ -35,6 +36,7 @@ class INA3221Sensor : public TelemetrySensor, VoltageSensor
|
||||
int32_t runOnce() override;
|
||||
bool getMetrics(meshtastic_Telemetry *measurement) override;
|
||||
virtual uint16_t getBusVoltageMv() override;
|
||||
virtual int16_t getCurrentMa() override;
|
||||
};
|
||||
|
||||
struct _INA3221Measurement {
|
||||
|
@ -42,10 +42,12 @@ 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 INA260Sensor ina260Sensor;
|
||||
extern INA219Sensor ina219Sensor;
|
||||
extern INA226Sensor ina226Sensor;
|
||||
extern INA260Sensor ina260Sensor;
|
||||
extern INA3221Sensor ina3221Sensor;
|
||||
#endif
|
||||
|
||||
@ -99,4 +101,4 @@ class Power : private concurrency::OSThread
|
||||
#endif
|
||||
};
|
||||
|
||||
extern Power *power;
|
||||
extern Power *power;
|
||||
|
Loading…
Reference in New Issue
Block a user