Skip to content

Commit 21b978b

Browse files
authored
Merge pull request #819 from sparkfun/Better_Auth_CoPro_Detection
Better Authentication Coprocessor detection - for Torch X2
2 parents 65fc6b4 + f5dddba commit 21b978b

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

Firmware/RTK_Everywhere/Begin.ino

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ void identifyBoard()
9595
bool husb238Present = i2cIsDevicePresent(i2c_0, 0x08);
9696

9797
// 0x10 - MFI343S00177 Authentication Coprocessor
98-
bool mfiPresent = i2cIsDevicePresent(i2c_0, 0x10);
98+
// The authentication coprocessor can be asleep. It needs special treatment
99+
bool mfiPresent = i2cIsDeviceRegisterPresent(i2c_0, 0x10, 0x00, 0x07);
99100

100101
i2c_0->end();
101102

@@ -1803,12 +1804,19 @@ bool i2cBusInitialization(TwoWire *i2cBus, int sda, int scl, int clockKHz)
18031804
// SDA/GND shorted: 14ms, response 5
18041805
timer = millis();
18051806

1806-
// If there is nothing else on the bus, the authentication coprocessor can be asleep
1807-
// Ping it twice to be sure
1808-
if (addr == 0x10)
1809-
i2cIsDevicePresent(i2cBus, addr); // Throw away result. Just wake it up.
1807+
// The authentication coprocessor can be asleep. It needs special treatment
1808+
if ((addr == 0x10) && (i2cIsDeviceRegisterPresent(i2cBus, addr, 0x00, 0x07)))
1809+
{
1810+
if (deviceFound == false)
1811+
{
1812+
systemPrintln("I2C Devices:");
1813+
deviceFound = true;
1814+
}
18101815

1811-
if (i2cIsDevicePresent(i2cBus, addr))
1816+
systemPrintf(" 0x%02X - MFI343S00177 Authentication Coprocessor\r\n", addr);
1817+
i2cAuthCoPro = i2cBus; // Record the bus
1818+
}
1819+
else if (i2cIsDevicePresent(i2cBus, addr))
18121820
{
18131821
if (deviceFound == false)
18141822
{
@@ -1819,7 +1827,7 @@ bool i2cBusInitialization(TwoWire *i2cBus, int sda, int scl, int clockKHz)
18191827
switch (addr)
18201828
{
18211829
default: {
1822-
systemPrintf(" 0x%02X\r\n", addr);
1830+
systemPrintf(" 0x%02X - Unknown\r\n", addr);
18231831
break;
18241832
}
18251833

@@ -1833,12 +1841,6 @@ bool i2cBusInitialization(TwoWire *i2cBus, int sda, int scl, int clockKHz)
18331841
break;
18341842
}
18351843

1836-
case 0x10: {
1837-
systemPrintf(" 0x%02X - MFI343S00177 Authentication Coprocessor\r\n", addr);
1838-
i2cAuthCoPro = i2cBus; // Record the bus
1839-
break;
1840-
}
1841-
18421844
case 0x18: {
18431845
systemPrintf(" 0x%02X - PCA9557 GPIO Expander with Reset\r\n", addr);
18441846
break;

Firmware/RTK_Everywhere/System.ino

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,31 @@ bool i2cIsDevicePresent(TwoWire *i2cBus, uint8_t deviceAddress)
278278
return false;
279279
}
280280

281+
// Read an I2C device register and check for an expected value
282+
bool i2cIsDeviceRegisterPresent(TwoWire *i2cBus, uint8_t deviceAddress, uint8_t registerAddress, uint8_t expectedValue)
283+
{
284+
int maxRetries = 3;
285+
286+
while (maxRetries > 0)
287+
{
288+
maxRetries--;
289+
delay(1);
290+
291+
i2cBus->beginTransmission(deviceAddress);
292+
i2cBus->write(registerAddress);
293+
if (i2cBus->endTransmission() != 0)
294+
continue;
295+
296+
i2cBus->requestFrom(deviceAddress, (uint8_t)1);
297+
if (i2cBus->available())
298+
{
299+
return (i2cBus->read() == expectedValue);
300+
}
301+
}
302+
303+
return false;
304+
}
305+
281306
// Create a test file in file structure to make sure we can
282307
bool createTestFile()
283308
{

0 commit comments

Comments
 (0)