From f1dd623ce95bf5d116488c363ddf71b15a6f02d5 Mon Sep 17 00:00:00 2001 From: Andy Shinn Date: Sun, 15 Jun 2025 07:39:49 -0500 Subject: [PATCH] allow overriding INA3221 channels (#7035) Co-authored-by: Jonathan Bennett --- src/modules/Telemetry/Sensor/INA3221Sensor.h | 12 ++++++++++-- variants/rak4631/variant.h | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/modules/Telemetry/Sensor/INA3221Sensor.h b/src/modules/Telemetry/Sensor/INA3221Sensor.h index 69edf8c50..0581f92f6 100644 --- a/src/modules/Telemetry/Sensor/INA3221Sensor.h +++ b/src/modules/Telemetry/Sensor/INA3221Sensor.h @@ -8,16 +8,24 @@ #include "VoltageSensor.h" #include +#ifndef INA3221_ENV_CH +#define INA3221_ENV_CH INA3221_CH1 +#endif + +#ifndef INA3221_BAT_CH +#define INA3221_BAT_CH INA3221_CH1 +#endif + class INA3221Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor { private: INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA); // channel to report voltage/current for environment metrics - ina3221_ch_t ENV_CH = INA3221_CH1; + static const ina3221_ch_t ENV_CH = INA3221_ENV_CH; // channel to report battery voltage for device_battery_ina_address - ina3221_ch_t BAT_CH = INA3221_CH1; + static const ina3221_ch_t BAT_CH = INA3221_BAT_CH; // get a single measurement for a channel struct _INA3221Measurement getMeasurement(ina3221_ch_t ch); diff --git a/variants/rak4631/variant.h b/variants/rak4631/variant.h index 0da1c04ea..82c914892 100644 --- a/variants/rak4631/variant.h +++ b/variants/rak4631/variant.h @@ -219,6 +219,10 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG // Testing USB detection #define NRF_APM +// If using a power chip like the INA3221 you can override the default battery voltage channel below +// and comment out NRF_APM to use the INA3221 instead of the USB detection for charging +// #define INA3221_BAT_CH INA3221_CH2 +// #define INA3221_ENV_CH INA3221_CH1 // enables 3.3V periphery like GPS or IO Module // Do not toggle this for GPS power savings