Skip to content

Commit 2282563

Browse files
committed
Add begin function that takes I2C addr, and conditional compile for ESP32
1 parent 4355f29 commit 2282563

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ sentence=Arduino Library for the Atmel/Microchip ECC508 and ECC608 crypto chips
66
paragraph=
77
category=Communication
88
url=https://github.com/arduino-libraries/ArduinoECCX08
9-
architectures=samd,megaavr,mbed
9+
architectures=samd,megaavr,mbed,esp32
1010
includes=ArduinoECCX08.h

src/ECCX08.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ ECCX08Class::~ECCX08Class()
3838
{
3939
}
4040

41+
int ECCX08Class::begin(uint8_t i2cAddress)
42+
{
43+
_address = i2cAddress;
44+
return begin();
45+
}
46+
4147
int ECCX08Class::begin()
4248
{
4349
_wire->begin();
@@ -721,7 +727,11 @@ int ECCX08Class::receiveResponse(void* response, size_t length)
721727
size_t responseSize = length + 3; // 1 for length header, 2 for CRC
722728
byte responseBuffer[responseSize];
723729

730+
#if (ESP32)
731+
while (_wire->requestFrom((uint8_t)_address, (uint8_t)responseSize, (bool)true) != responseSize && retries--);
732+
#else
724733
while (_wire->requestFrom((uint8_t)_address, (size_t)responseSize, (bool)true) != responseSize && retries--);
734+
#endif
725735

726736
responseBuffer[0] = _wire->read();
727737

src/ECCX08.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ECCX08Class
3434
virtual ~ECCX08Class();
3535

3636
int begin();
37+
int begin(uint8_t i2cAddress);
3738
void end();
3839

3940
int serialNumber(byte sn[]);

0 commit comments

Comments
 (0)