From d6aee1c59247aedd3b96120f8b1d82f8fc2853bf Mon Sep 17 00:00:00 2001 From: Willem Oldemans Date: Sat, 2 Oct 2021 11:44:52 +0200 Subject: [PATCH] fix: updated constructor --- PN532_SPI.cpp | 13 +++++-------- PN532_SPI.h | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/PN532_SPI.cpp b/PN532_SPI.cpp index e76a2fe..1b3468c 100644 --- a/PN532_SPI.cpp +++ b/PN532_SPI.cpp @@ -21,14 +21,11 @@ void PN532_SPI::begin() _spi->begin(); _spi->setDataMode(SPI_MODE0); // PN532 only supports mode0 _spi->setBitOrder(LSBFIRST); -#if defined __SAM3X8E__ +#ifndef __SAM3X8E__ + _spi->setClockDivider(SPI_CLOCK_DIV8); // set clock 2MHz(max: 5MHz) +#else /** DUE spi library does not support SPI_CLOCK_DIV8 macro */ _spi->setClockDivider(42); // set clock 2MHz(max: 5MHz) -#elif defined __SAMD21G18A__ - /** M0 spi library does not support SPI_CLOCK_DIV8 macro */ - _spi->setClockDivider(24); // set clock 2MHz(max: 5MHz) -#else - _spi->setClockDivider(SPI_CLOCK_DIV8); // set clock 2MHz(max: 5MHz) #endif } @@ -69,7 +66,7 @@ int16_t PN532_SPI::readResponse(uint8_t buf[], uint8_t len, uint16_t timeout) while (!isReady()) { delay(1); time++; - if (time > timeout) { + if (timeout > 0 && time > timeout) { return PN532_TIMEOUT; } } @@ -142,7 +139,7 @@ int16_t PN532_SPI::readResponse(uint8_t buf[], uint8_t len, uint16_t timeout) return result; } -bool PN532_SPI::isReady() +boolean PN532_SPI::isReady() { digitalWrite(_ss, LOW); diff --git a/PN532_SPI.h b/PN532_SPI.h index 1c8c499..53ff697 100644 --- a/PN532_SPI.h +++ b/PN532_SPI.h @@ -20,7 +20,7 @@ private: uint8_t _ss; uint8_t command; - bool isReady(); + boolean isReady(); void writeFrame(const uint8_t *header, uint8_t hlen, const uint8_t *body = 0, uint8_t blen = 0); int8_t readAckFrame();