Skip to content

Commit 0fe82c9

Browse files
authored
Update ECCX08.cpp with counter functions
1 parent cbcf894 commit 0fe82c9

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

src/ECCX08.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,54 @@ int ECCX08Class::nonce(const byte data[])
548548
return challenge(data);
549549
}
550550

551+
long ECCX08Class::incrementCounter(int keyId)
552+
{
553+
uint32_t counter; // the counter can go up to 2,097,151
554+
555+
if (!wakeup()) {
556+
return -1;
557+
}
558+
559+
if (!sendCommand(0x24, 1, keyId)) {
560+
return -1;
561+
}
562+
563+
delay(20);
564+
565+
if (!receiveResponse(&counter, sizeof(counter))) {
566+
return -1;
567+
}
568+
569+
delay(1);
570+
idle();
571+
572+
return counter;
573+
}
574+
575+
long ECCX08Class::readCounter(int keyId)
576+
{
577+
uint32_t counter; // the counter can go up to 2,097,151
578+
579+
if (!wakeup()) {
580+
return -1;
581+
}
582+
583+
if (!sendCommand(0x24, 0, keyId)) {
584+
return -1;
585+
}
586+
587+
delay(20);
588+
589+
if (!receiveResponse(&counter, sizeof(counter))) {
590+
return -1;
591+
}
592+
593+
delay(1);
594+
idle();
595+
596+
return counter;
597+
}
598+
551599
int ECCX08Class::wakeup()
552600
{
553601
_wire->setClock(_wakeupFrequency);
@@ -892,4 +940,4 @@ uint16_t ECCX08Class::crc16(const byte data[], size_t length)
892940
ECCX08Class ECCX08(CRYPTO_WIRE, 0x60);
893941
#else
894942
ECCX08Class ECCX08(Wire, 0x60);
895-
#endif
943+
#endif

0 commit comments

Comments
 (0)