fix(ScanI2C): fetch the SE050 probe response with requestFrom() (#11133)
This commit is contained in:
@@ -905,15 +905,27 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
|
||||
break;
|
||||
|
||||
case 0x48: {
|
||||
i2cBus->beginTransmission(addr.address);
|
||||
uint8_t getInfo[] = {0x5A, 0xC0, 0x00, 0xFF, 0xFC};
|
||||
uint8_t expectedInfo[] = {0xa5, 0xE0, 0x00, 0x3F, 0x19};
|
||||
uint8_t info[5];
|
||||
// T=1oI2C soft reset; an SE050 answers A5 E0 00 3F 19. requestFrom() is
|
||||
// required: readBytes() only drains the RX buffer requestFrom() fills.
|
||||
const uint8_t getInfo[] = {0x5A, 0xC0, 0x00, 0xFF, 0xFC};
|
||||
const uint8_t expectedInfo[] = {0xA5, 0xE0, 0x00, 0x3F, 0x19};
|
||||
uint8_t info[sizeof(expectedInfo)] = {0};
|
||||
size_t len = 0;
|
||||
i2cBus->write(getInfo, 5);
|
||||
i2cBus->endTransmission();
|
||||
len = i2cBus->readBytes(info, 5);
|
||||
if (len == 5 && memcmp(expectedInfo, info, len) == 0) {
|
||||
bool isSE050 = false;
|
||||
|
||||
i2cBus->beginTransmission(addr.address);
|
||||
i2cBus->write(getInfo, sizeof(getInfo));
|
||||
if (i2cBus->endTransmission() == 0) {
|
||||
delay(2); // guard time before the answer can be read back
|
||||
len = i2cBus->requestFrom((uint8_t)addr.address, (uint8_t)sizeof(info));
|
||||
if (len == sizeof(info)) {
|
||||
for (size_t i = 0; i < sizeof(info); i++)
|
||||
info[i] = i2cBus->read();
|
||||
isSE050 = (memcmp(expectedInfo, info, sizeof(info)) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (isSE050) {
|
||||
LOG_INFO("NXP SE050 crypto chip found");
|
||||
type = NXP_SE050;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user