Compare commits

...

18 Commits

Author SHA1 Message Date
Michael Gjelsø
4a5c4476a2
Merge 4e527ff487 into a30f431b6a 2025-04-19 16:38:35 -04:00
renovate[bot]
a30f431b6a
Update Kongduino-Adafruit_nRFCrypto digest to 5f838d2 (#6634)
Some checks are pending
CI / build-esp32-c3 (push) Blocked by required conditions
CI / build-esp32-c6 (push) Blocked by required conditions
CI / build-nrf52 (push) Blocked by required conditions
CI / build-rpi2040 (push) Blocked by required conditions
CI / build-stm32 (push) Blocked by required conditions
CI / build-debian-src (push) Waiting to run
CI / package-pio-deps-native-tft (push) Waiting to run
CI / test-native (push) Waiting to run
CI / docker-deb-amd64 (push) Waiting to run
CI / docker-deb-amd64-tft (push) Waiting to run
CI / docker-alp-amd64 (push) Waiting to run
CI / docker-alp-amd64-tft (push) Waiting to run
CI / docker-deb-arm64 (push) Waiting to run
CI / docker-deb-armv7 (push) Waiting to run
CI / after-checks (push) Blocked by required conditions
CI / gather-artifacts (esp32) (push) Blocked by required conditions
CI / gather-artifacts (esp32c3) (push) Blocked by required conditions
CI / gather-artifacts (esp32c6) (push) Blocked by required conditions
CI / gather-artifacts (esp32s3) (push) Blocked by required conditions
CI / gather-artifacts (nrf52840) (push) Blocked by required conditions
CI / gather-artifacts (rp2040) (push) Blocked by required conditions
CI / gather-artifacts (stm32) (push) Blocked by required conditions
CI / release-artifacts (push) Blocked by required conditions
CI / release-firmware (esp32) (push) Blocked by required conditions
CI / release-firmware (esp32c3) (push) Blocked by required conditions
CI / release-firmware (esp32c6) (push) Blocked by required conditions
CI / release-firmware (esp32s3) (push) Blocked by required conditions
CI / release-firmware (nrf52840) (push) Blocked by required conditions
CI / release-firmware (rp2040) (push) Blocked by required conditions
CI / release-firmware (stm32) (push) Blocked by required conditions
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-04-19 18:49:05 +02:00
Michael Gjelsø
4e527ff487
Merge branch 'master' into use_detected_ina_addr 2025-04-17 16:09:03 +02:00
Michael Gjelsø
d8ef6d5592
Merge branch 'master' into use_detected_ina_addr 2025-04-17 12:41:05 +02:00
Michael Gjelsø
0b325faf17
Merge branch 'master' into use_detected_ina_addr 2025-04-17 11:13:13 +02:00
Michael Gjelsø
c58bf5070b
Merge branch 'meshtastic:master' into use_detected_ina_addr 2025-03-31 18:00:56 +02:00
gjelsoe
07f955518a Use ScanI2C
Re-wrote some to use ScanI2C
2025-03-31 15:37:53 +02:00
Michael Gjelsø
bd19402411
Merge branch 'meshtastic:master' into use_detected_ina_addr 2025-03-06 16:56:17 +01:00
gjelsoe
bde3a88f41 Merge branch 'use_detected_ina_addr' of https://github.com/gjelsoe/firmware into use_detected_ina_addr 2025-03-02 14:59:06 +01:00
Michael Gjelsø
323e977961
Merge branch 'master' into use_detected_ina_addr 2025-03-01 14:06:16 +01:00
michael
57cf9ddd0a Trunk.... 2025-02-27 16:08:44 +01:00
gjelsoe
3df87d9fab Merge branch 'use_detected_ina_addr' of https://github.com/gjelsoe/firmware into use_detected_ina_addr 2025-02-27 15:24:55 +01:00
gjelsoe
81176de5a7 Update Power.cpp
Take two
2025-02-27 13:54:54 +08:00
gjelsoe
fc289198c9 Update Power.cpp
First stab at using I2C detected INA addr.
2025-02-27 13:54:54 +08:00
Michael Gjelsø
6e89ba98fd
Merge branch 'meshtastic:master' into use_detected_ina_addr 2025-02-17 16:28:21 +01:00
Michael Gjelsø
61912b0dd9
Merge branch 'meshtastic:master' into use_detected_ina_addr 2025-02-16 15:26:05 +01:00
gjelsoe
8b2a6c3b78 Update Power.cpp
Take two
2025-02-15 23:40:27 +01:00
gjelsoe
89e0857c73 Update Power.cpp
First stab at using I2C detected INA addr.
2025-02-15 19:18:25 +01:00
6 changed files with 135 additions and 41 deletions

View File

@ -7,7 +7,7 @@ lib_deps =
${nrf52_base.lib_deps}
${environmental_base.lib_deps}
# renovate: datasource=git-refs depName=Kongduino-Adafruit_nRFCrypto packageName=https://github.com/Kongduino/Adafruit_nRFCrypto gitBranch=master
https://github.com/Kongduino/Adafruit_nRFCrypto/archive/e31a8825ea3300b163a0a3c1ddd5de34e10e1371.zip
https://github.com/Kongduino/Adafruit_nRFCrypto/archive/5f838d2709461a2c981f642917aa50254a25c14c.zip
; Common NRF52 debugging settings follow. See the Meshtastic developer docs for how to connect SWD debugging probes to your board.

View File

@ -77,6 +77,8 @@ static const uint8_t ext_chrg_detect_value = EXT_CHRG_DETECT_VALUE;
#endif
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO)
#include "main.h";
uint8_t INA_ADDR_LOCAL;
INA219Sensor ina219Sensor;
INA226Sensor ina226Sensor;
INA260Sensor ina260Sensor;
@ -440,7 +442,8 @@ class AnalogBatteryLevel : public HasBatteryLevel
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);
// LOG_DEBUG("Using INA on I2C addr 0x%x for charging detection", config.power.device_battery_ina_address);
LOG_DEBUG("Using INA on I2C addr 0x%x for charging detection", INA_ADDR_LOCAL);
#if defined(INA_CHARGING_DETECTION_INVERT)
return getINACurrent() > 0;
#else
@ -483,8 +486,29 @@ class AnalogBatteryLevel : public HasBatteryLevel
#endif
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
/*
Read Voltage from INA using autodetect of addr first else use addr in config.power.device_battery_ina_address
*/
uint16_t getINAVoltage()
{
if (!config.power.device_battery_ina_address) {
if (ina_found.type != ScanI2C::DeviceType::NONE) {
switch (ina_found.type) {
case ScanI2C::DeviceType::INA219:
return ina219Sensor.getBusVoltageMv();
break;
case ScanI2C::DeviceType::INA226:
return ina226Sensor.getBusVoltageMv();
break;
case ScanI2C::DeviceType::INA260:
return ina260Sensor.getBusVoltageMv();
break;
case ScanI2C::DeviceType::INA3221:
return ina3221Sensor.getBusVoltageMv();
break;
}
}
} else if (config.power.device_battery_ina_address) {
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
return ina219Sensor.getBusVoltageMv();
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
@ -497,11 +521,29 @@ class AnalogBatteryLevel : public HasBatteryLevel
config.power.device_battery_ina_address) {
return ina3221Sensor.getBusVoltageMv();
}
}
return 0;
}
/*
Read Current from INA using autodetect of addr first else use addr in config.power.device_battery_ina_address
*/
int16_t getINACurrent()
{
if (!config.power.device_battery_ina_address) {
if (ina_found.type != ScanI2C::DeviceType::NONE) {
switch (ina_found.type) {
case ScanI2C::DeviceType::INA219:
return ina219Sensor.getCurrentMa();
case ScanI2C::DeviceType::INA226:
return ina226Sensor.getCurrentMa();
case ScanI2C::DeviceType::INA3221:
return ina3221Sensor.getCurrentMa();
}
}
} else if (config.power.device_battery_ina_address) {
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
return ina219Sensor.getCurrentMa();
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
@ -511,14 +553,43 @@ class AnalogBatteryLevel : public HasBatteryLevel
config.power.device_battery_ina_address) {
return ina3221Sensor.getCurrentMa();
}
}
return 0;
}
bool hasINA()
/*
Use autodetect of addr first else use addr in config.power.device_battery_ina_address
Store INA addr in local variable for later use.
*/
{
if (!config.power.device_battery_ina_address) {
return false;
if (ina_found.type != ScanI2C::DeviceType::NONE) {
INA_ADDR_LOCAL = ina_found.address.address;
switch (ina_found.type) {
case ScanI2C::DeviceType::INA219:
if (!ina219Sensor.isInitialized())
return ina219Sensor.runOnce() > 0;
return ina219Sensor.isRunning();
case ScanI2C::DeviceType::INA226:
if (!ina226Sensor.isInitialized())
return ina226Sensor.runOnce() > 0;
return ina226Sensor.isRunning();
case ScanI2C::DeviceType::INA260:
if (!ina260Sensor.isInitialized())
return ina260Sensor.runOnce() > 0;
return ina260Sensor.isRunning();
case ScanI2C::DeviceType::INA3221:
if (!ina3221Sensor.isInitialized())
return ina3221Sensor.runOnce() > 0;
return ina3221Sensor.isRunning();
}
}
} else if (config.power.device_battery_ina_address) {
INA_ADDR_LOCAL = config.power.device_battery_ina_address;
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
if (!ina219Sensor.isInitialized())
return ina219Sensor.runOnce() > 0;
@ -538,6 +609,8 @@ class AnalogBatteryLevel : public HasBatteryLevel
return ina3221Sensor.runOnce() > 0;
return ina3221Sensor.isRunning();
}
}
INA_ADDR_LOCAL = 0;
return false;
}
#endif

View File

@ -41,6 +41,13 @@ ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const
return firstOfOrNONE(8, types);
}
ScanI2C::FoundDevice ScanI2C::firstINA() const
{
ScanI2C::DeviceType types[] = {INA219, INA226, INA260, INA3221};
return firstOfOrNONE(4, types);
}
ScanI2C::FoundDevice ScanI2C::firstRGBLED() const
{
ScanI2C::DeviceType types[] = {NCP5623, LP5562};

View File

@ -123,6 +123,8 @@ class ScanI2C
FoundDevice firstAccelerometer() const;
FoundDevice firstINA() const;
FoundDevice firstRGBLED() const;
virtual FoundDevice find(DeviceType) const;

View File

@ -176,6 +176,10 @@ ScanI2C::DeviceAddress rtc_found = ScanI2C::ADDRESS_NONE;
ScanI2C::DeviceAddress accelerometer_found = ScanI2C::ADDRESS_NONE;
// The I2C address of the RGB LED (if found)
ScanI2C::FoundDevice rgb_found = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ScanI2C::ADDRESS_NONE);
// The I2C address of the INA Module (if found)
ScanI2C::FoundDevice ina_found = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ScanI2C::ADDRESS_NONE);
ScanI2C::DeviceAddress ina_Address = ScanI2C::ADDRESS_NONE;
#ifdef T_WATCH_S3
Adafruit_DRV2605 drv;
@ -698,6 +702,12 @@ void setup()
LOG_DEBUG("acc_info = %i", acc_info.type);
#endif
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO)
auto ina_Info = i2cScanner->firstINA();
// ina_Address = ina_Info.type != ScanI2C::DeviceType::NONE ? ina_Info.address : ina_Address;
LOG_DEBUG("ina_info = %i", ina_Info.type);
#endif
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BME_680, meshtastic_TelemetrySensorType_BME680);
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BME_280, meshtastic_TelemetrySensorType_BME280);
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BMP_280, meshtastic_TelemetrySensorType_BMP280);

View File

@ -34,6 +34,8 @@ extern uint8_t kb_model;
extern ScanI2C::DeviceAddress rtc_found;
extern ScanI2C::DeviceAddress accelerometer_found;
extern ScanI2C::FoundDevice rgb_found;
//extern ScanI2C::DeviceAddress ina_Address;
extern ScanI2C::FoundDevice ina_found;
extern bool eink_found;
extern bool pmu_found;