Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/detect/ScanI2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ ScanI2C::FoundDevice ScanI2C::firstRTC() const

ScanI2C::FoundDevice ScanI2C::firstKeyboard() const
{
ScanI2C::DeviceType types[] = {CARDKB, TDECKKB, BBQ10KB, RAK14004, MPR121KB, TCA8418KB};
return firstOfOrNONE(6, types);
ScanI2C::DeviceType types[] = {CARDKB, TDECKKB, BBQ10KB, RAK14004, MCP23017, MPR121KB, TCA8418KB};
return firstOfOrNONE(7, types);
}

ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const
Expand Down
1 change: 1 addition & 0 deletions src/detect/ScanI2C.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class ScanI2C
SCD4X,
MAX30102,
TPS65233,
MCP23017,
MPR121KB,
CGRADSENS,
INA226,
Expand Down
13 changes: 10 additions & 3 deletions src/detect/ScanI2CTwoWire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,16 +648,23 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
logFoundDevice("BMA423", (uint8_t)addr.address);
}
break;
case TCA9535_ADDR:
case TCA9535_ADDR: // this can also be MCP23017_ADDR (both 0x20
case RAK120352_ADDR:
case RAK120353_ADDR:
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x02), 1);
if (registerValue == addr.address) { // RAK12035 returns its I2C address at 0x02 (eg 0x20)
type = RAK12035;
logFoundDevice("RAK12035", (uint8_t)addr.address);
} else {
type = TCA9535;
logFoundDevice("TCA9535", (uint8_t)addr.address);
// TCA9535 only has registers 0x00-0x07; MCP23017 has IOCON at 0x0A
registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0A), 1);
if (registerValue != 0xFF) {
type = MCP23017;
logFoundDevice("MCP23017", (uint8_t)addr.address);
} else {
type = TCA9535;
logFoundDevice("TCA9535", (uint8_t)addr.address);
}
Comment on lines +651 to +667

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Verify register 0x0A read behavior for TCA9535.

The differentiation between MCP23017 and TCA9535 relies on reading register 0x0A. The code assumes registerValue will be 0xFF for a TCA9535. If the TCA9535 wraps the command byte (e.g., 0x0A % 8 = 0x02), register 0x02 (Output Port 0) must default to 0xFF for this logic to hold. If the device NACKs the address instead, getRegisterValue() might return 0x00 (since available() would be 0), causing it to be incorrectly identified as an MCP23017 (0x00 != 0xFF).

Also, fix the missing closing parenthesis in the comment on line 651, and the off-by-one indentation on line 659 to comply with trunk fmt as per coding guidelines.

💻 Proposed fixes (assuming register logic is verified to work)
-            case TCA9535_ADDR: // this can also be MCP23017_ADDR (both 0x20
+            case TCA9535_ADDR: // this can also be MCP23017_ADDR (both 0x20)
             case RAK120352_ADDR:
             case RAK120353_ADDR:
                 registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x02), 1);
                 if (registerValue == addr.address) { // RAK12035 returns its I2C address at 0x02 (eg 0x20)
                     type = RAK12035;
                     logFoundDevice("RAK12035", (uint8_t)addr.address);
                 } else {
-                     // TCA9535 only has registers 0x00-0x07; MCP23017 has IOCON at 0x0A
+                    // TCA9535 only has registers 0x00-0x07; MCP23017 has IOCON at 0x0A
                     registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x0A), 1);
                     if (registerValue != 0xFF) { 
                         type = MCP23017;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/detect/ScanI2CTwoWire.cpp` around lines 651 - 667, Verify the TCA9535
behavior when reading register 0x0A, including wrapped-command and NACK
outcomes, and update the MCP23017/TCA9535 detection in the surrounding switch
case so failed or wrapped reads cannot misclassify the device; preserve RAK12035
detection. Also complete the missing closing parenthesis in the TCA9535/MCP23017
comment and correct the indentation of the nested register-read line to match
trunk fmt.

Source: Coding guidelines

}

break;
Expand Down
Loading