Skip to content

Commit 6c9b156

Browse files
committed
Improve runCommandTest
1 parent 2046a04 commit 6c9b156

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/SparkFun_Qwiic_KX13X.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ bool QwDevKX13X::softwareReset()
134134
cntl2.all = 0;
135135
cntl2.bits.srst = 1; // This is a long winded, but definitive way of setting the software reset bit
136136

137-
retVal = writeRegisterByte(SFE_KX13X_CNTL2, cntl2.all); // Do the reset
137+
writeRegisterByte(SFE_KX13X_CNTL2, cntl2.all); // Do the reset
138138

139139
uint8_t loopCount = 0;
140140
while (loopCount < 10) // Reset takes about 2ms. Timeout after 10ms
@@ -1351,23 +1351,34 @@ bool QwDevKX13X::runCommandTest()
13511351
cntl2.bits.cotc = 1; // This is a long winded, but definitive way of setting the COTC bit
13521352
tempVal = cntl2.all;
13531353

1354-
// Going to assume that communication is working at this point.
1355-
writeRegisterByte(SFE_KX13X_CNTL2, tempVal);
1354+
retVal = writeRegisterByte(SFE_KX13X_CNTL2, tempVal); // Start the test
13561355

1357-
readRegisterRegion(SFE_KX13X_COTR, &tempVal, 1);
1356+
if (retVal != 0)
1357+
return false;
1358+
1359+
retVal = readRegisterRegion(SFE_KX13X_COTR, &tempVal, 1); // Check COTR is 0xAA
1360+
1361+
if (retVal != 0)
1362+
return false;
13581363

13591364
if (tempVal != 0xAA)
13601365
return false;
13611366

1362-
readRegisterRegion(SFE_KX13X_CNTL2, &tempVal, 1);
1367+
retVal = readRegisterRegion(SFE_KX13X_CNTL2, &tempVal, 1);
1368+
1369+
if (retVal != 0)
1370+
return false;
13631371

13641372
cntl2.all = tempVal;
1365-
if (cntl2.bits.cotc != 0)
1373+
if (cntl2.bits.cotc != 0) // Check the COTC bit has been cleared
13661374
return false;
13671375

1368-
readRegisterRegion(SFE_KX13X_COTR, &tempVal, 1);
1376+
retVal = readRegisterRegion(SFE_KX13X_COTR, &tempVal, 1);
1377+
1378+
if (retVal != 0)
1379+
return false;
13691380

1370-
if (tempVal != 0x55)
1381+
if (tempVal != 0x55) // Check COTR is 0x55
13711382
return false;
13721383

13731384
return true;

0 commit comments

Comments
 (0)