Fix T1000-E QMA6100P I2C probing (#10713)
* Fix T1000-E QMA6100P I2C probing * Refactored to make generic * address copilot comments * fix(i2c): address copilot comments on QMA6100P scanning and hardware init - ScanI2CTwoWire: gate bounded QMA6100P probing to addresses 0x12/0x13 only (Copilot comment: avoid blocking other I2C device detection on nRF52) Falls back to normal Wire probing for all other addresses, allowing BMM150 and other devices at overlapping addresses to be properly detected. - Nrf52Twim: suppress cppcheck redundantAssignment on ENABLE register write (intentional disable→configure→enable pattern for hardware safety; explicit disable ensures known state before configuration even if already disabled) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> * Nrf52Twim: gate on HAS_QMA6100P; suppress cppcheck redundantAssignment The TWIM helper is only used by the QMA6100P probing path (T1000-E, the sole board defining HAS_QMA6100P). It was gated only on ARCH_NRF52, so it compiled as dead code on every other nRF52 board and was analyzed by the rak4631 cppcheck job -- which failed on a redundantAssignment false positive. Gate the header and source on HAS_QMA6100P so the file is only built/analyzed where it is actually used. Also keep an inline suppression on the ENABLE re-assignment (a required volatile disable->reconfigure->enable sequence) for the case where the T1000-E build is run through cppcheck locally. Fixes the rak4631 cppcheck CI failure for PR #10713. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: nomdetom <nomdetom@protonmail.com> Co-authored-by: Tom <116762865+NomDeTom@users.noreply.github.com> Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
GitHub
Ben Meadors
nomdetom
Tom
Claude Haiku 4.5
parent
2fdb722e00
commit
0eaad08735
@@ -11,6 +11,25 @@
|
||||
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32)
|
||||
#include "meshUtils.h" // vformat
|
||||
|
||||
#endif
|
||||
#if defined(HAS_QMA6100P) && (defined(ARCH_NRF52) || defined(NRF52_SERIES) || defined(NRF52))
|
||||
#include "platform/nrf52/Nrf52Twim.h"
|
||||
#include <QMA6100P.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
bool probeQMA6100P(uint8_t address)
|
||||
{
|
||||
uint8_t chipID = 0;
|
||||
|
||||
Nrf52Twim::restoreBus();
|
||||
const bool readOk = Nrf52Twim::readRegister(address, SFE_QMA6100P_CHIP_ID, chipID);
|
||||
const bool found = readOk && chipID == QMA6100P_CHIP_ID;
|
||||
Nrf52Twim::restoreBus();
|
||||
|
||||
return found;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
bool in_array(uint8_t *array, int size, uint8_t lookfor)
|
||||
@@ -277,11 +296,36 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
||||
// 0x7C-0x7F Reserved for future purposes
|
||||
|
||||
for (addr.address = 8; addr.address < 120; addr.address++) {
|
||||
#if defined(HAS_QMA6100P) && (defined(ARCH_NRF52) || defined(NRF52_SERIES) || defined(NRF52))
|
||||
bool nrf52QmaFound = false;
|
||||
#endif
|
||||
if (asize != 0) {
|
||||
if (!in_array(address, asize, (uint8_t)addr.address))
|
||||
continue;
|
||||
LOG_DEBUG("Scan address 0x%x", (uint8_t)addr.address);
|
||||
}
|
||||
// For QMA6100P candidates on nRF52, use bounded I2C probing; otherwise use normal Wire
|
||||
#if defined(HAS_QMA6100P) && (defined(ARCH_NRF52) || defined(NRF52_SERIES) || defined(NRF52))
|
||||
if (addr.address == QMA6100P_ADDRESS_LOW || addr.address == QMA6100P_ADDRESS_HIGH) {
|
||||
nrf52QmaFound = probeQMA6100P(addr.address);
|
||||
err = nrf52QmaFound ? 0 : 2;
|
||||
} else {
|
||||
i2cBus->beginTransmission(addr.address);
|
||||
#ifdef ARCH_PORTDUINO
|
||||
err = 2;
|
||||
if ((addr.address >= 0x30 && addr.address <= 0x37) || (addr.address >= 0x50 && addr.address <= 0x5F)) {
|
||||
if (i2cBus->read() != -1)
|
||||
err = 0;
|
||||
} else {
|
||||
err = i2cBus->writeQuick((uint8_t)0);
|
||||
}
|
||||
if (err != 0)
|
||||
err = 2;
|
||||
#else
|
||||
err = i2cBus->endTransmission();
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
i2cBus->beginTransmission(addr.address);
|
||||
#ifdef ARCH_PORTDUINO
|
||||
err = 2;
|
||||
@@ -295,6 +339,7 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
||||
err = 2;
|
||||
#else
|
||||
err = i2cBus->endTransmission();
|
||||
#endif
|
||||
#endif
|
||||
type = NONE;
|
||||
if (err == 0) {
|
||||
@@ -750,7 +795,17 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
||||
}
|
||||
break;
|
||||
}
|
||||
SCAN_SIMPLE_CASE(BMM150_ADDR, BMM150, "BMM150", (uint8_t)addr.address);
|
||||
case BMM150_ADDR:
|
||||
#if defined(HAS_QMA6100P) && (defined(ARCH_NRF52) || defined(NRF52_SERIES) || defined(NRF52))
|
||||
if (nrf52QmaFound) {
|
||||
logFoundDevice("QMA6100P", (uint8_t)addr.address);
|
||||
type = QMA6100P;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
logFoundDevice("BMM150", (uint8_t)addr.address);
|
||||
type = BMM150;
|
||||
break;
|
||||
#ifdef HAS_TPS65233
|
||||
SCAN_SIMPLE_CASE(TPS65233_ADDR, TPS65233, "TPS65233", (uint8_t)addr.address);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user