Fix INA226 detection for non-TI compatible chip (Silergy) (#10247)
* Fix INA226 detection for non-TI compatible chip (Silergy) * Removed extra I2C transaction + 20ms delay on every scan of address 0x40 (including real SHT2x sensors). Changes suggested by Copilot Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Apply formatting (trunk fmt) --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
co-authored by
Copilot Autofix powered by AI
parent
924411de59
commit
ba9cadc14d
@@ -415,30 +415,45 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
|||||||
#if !defined(M5STACK_UNITC6L)
|
#if !defined(M5STACK_UNITC6L)
|
||||||
case INA_ADDR: // Same as SHT2X
|
case INA_ADDR: // Same as SHT2X
|
||||||
case INA_ADDR_ALTERNATE:
|
case INA_ADDR_ALTERNATE:
|
||||||
case INA_ADDR_WAVESHARE_UPS:
|
case INA_ADDR_WAVESHARE_UPS: {
|
||||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFE), 2);
|
uint16_t mfg = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFE), 2);
|
||||||
LOG_DEBUG("Register MFG_UID: 0x%x", registerValue);
|
|
||||||
if (registerValue == 0x5449) {
|
|
||||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFF), 2);
|
|
||||||
LOG_DEBUG("Register DIE_UID: 0x%x", registerValue);
|
|
||||||
|
|
||||||
if (registerValue == 0x2260) {
|
LOG_DEBUG("Register MFG_UID: 0x%x", mfg);
|
||||||
|
|
||||||
|
// Only read DIE_UID for vendors we recognize as INA-compatible to avoid
|
||||||
|
// an extra I2C transaction + delay on other devices sharing this address.
|
||||||
|
if (mfg == 0x5449 || mfg == 0x190F) {
|
||||||
|
uint16_t die = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFF), 2);
|
||||||
|
LOG_DEBUG("Register DIE_UID: 0x%x", die);
|
||||||
|
|
||||||
|
// TI INA226 or fully compatible clones (e.g. TPA626)
|
||||||
|
if (mfg == 0x5449 && die == 0x2260) {
|
||||||
logFoundDevice("INA226", (uint8_t)addr.address);
|
logFoundDevice("INA226", (uint8_t)addr.address);
|
||||||
type = INA226;
|
type = INA226;
|
||||||
} else {
|
}
|
||||||
|
// Silergy SQ52201 (INA226-compatible with different IDs)
|
||||||
|
else if (mfg == 0x190F && die == 0x0000) {
|
||||||
|
logFoundDevice("INA226 (SQ52201)", (uint8_t)addr.address);
|
||||||
|
type = INA226;
|
||||||
|
}
|
||||||
|
// TI INA260
|
||||||
|
else if (mfg == 0x5449) {
|
||||||
logFoundDevice("INA260", (uint8_t)addr.address);
|
logFoundDevice("INA260", (uint8_t)addr.address);
|
||||||
type = INA260;
|
type = INA260;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
||||||
} else if (detectSHT21SerialNumber(i2cBus, (uint8_t)addr.address)) {
|
if (type == NONE && detectSHT21SerialNumber(i2cBus, (uint8_t)addr.address)) {
|
||||||
logFoundDevice("SHTXX (SHT2X)", (uint8_t)addr.address);
|
logFoundDevice("SHTXX (SHT2X)", (uint8_t)addr.address);
|
||||||
type = SHTXX;
|
type = SHTXX;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
} else { // Assume INA219 if none of the above ones are found
|
else { // Assume INA219 if none of the above ones are found
|
||||||
logFoundDevice("INA219", (uint8_t)addr.address);
|
logFoundDevice("INA219", (uint8_t)addr.address);
|
||||||
type = INA219;
|
type = INA219;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case INA3221_ADDR:
|
case INA3221_ADDR:
|
||||||
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFE), 2);
|
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0xFE), 2);
|
||||||
LOG_DEBUG("Register MFG_UID FE: 0x%x", registerValue);
|
LOG_DEBUG("Register MFG_UID FE: 0x%x", registerValue);
|
||||||
|
|||||||
Reference in New Issue
Block a user