add support for mfrc proxyies
This commit is contained in:
57
mfrc522.h
57
mfrc522.h
@ -3,10 +3,19 @@
|
||||
#include "softspim.h"
|
||||
#include "defines.h"
|
||||
#include "serial.h"
|
||||
#include "uid.h"
|
||||
|
||||
class Mfrc522
|
||||
{
|
||||
public:
|
||||
|
||||
static constexpr uint32_t POLL_OUT_US = 15000;
|
||||
static constexpr uint8_t PRESCALLER = 169;
|
||||
static constexpr uint16_t POLL_TIMER = (POLL_OUT_US*1.0E-6)/((2*PRESCALLER+1)/13.56E6);
|
||||
|
||||
static constexpr uint32_t TIMEOUT_US = 1000000;
|
||||
static constexpr uint16_t TIMEOUT_TIMER = (TIMEOUT_US*1.0E-6)/((2*169.0+1)/13.56E6);
|
||||
|
||||
// Error codes.
|
||||
static constexpr uint8_t OK = 0; // Everything A-OK.
|
||||
static constexpr uint8_t NOTAGERR = 1; // No tag error
|
||||
@ -133,32 +142,10 @@ public:
|
||||
// The PICC_CMD_MF_READ and PICC_CMD_MF_WRITE can also be used for MIFARE Ultralight.
|
||||
static constexpr uint8_t PICC_CMD_UL_WRITE = 0xA2; // Writes one 4 byte page to the PICC
|
||||
|
||||
class Uid
|
||||
{
|
||||
public:
|
||||
uint8_t size; // Number of bytes in the UID. 4, 7 or 10.
|
||||
uint8_t uidByte[10];
|
||||
uint8_t sak; // The SAK (Select acknowledge) byte returned from the PICC after successful selection.
|
||||
bool operator==(Uid& in)
|
||||
{
|
||||
if(size != in.size)
|
||||
return false;
|
||||
for(uint8_t i = 0; i < size; ++i)
|
||||
{
|
||||
if(uidByte[i] != in.uidByte[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool operator!=(Uid& in)
|
||||
{
|
||||
return !operator==(in);
|
||||
}
|
||||
};
|
||||
|
||||
// Modes
|
||||
static constexpr uint8_t MODE_IDLE = 0;
|
||||
static constexpr uint8_t MODE_TRANSCEIVE = 1;
|
||||
static constexpr uint8_t MODE_TIMEOUT = 2;
|
||||
|
||||
private:
|
||||
ShiftReg<NFC_PORTS>* _csReg;
|
||||
@ -207,6 +194,8 @@ public:
|
||||
uint8_t selectTag(Uid *uid);
|
||||
|
||||
uint8_t getUid(Uid *uid);
|
||||
|
||||
void reset();
|
||||
|
||||
void irq();
|
||||
|
||||
@ -218,17 +207,21 @@ public:
|
||||
|
||||
bool cardPresent();
|
||||
|
||||
bool testFifo();
|
||||
bool testFifo(Serial* serial);
|
||||
|
||||
bool checkIrq(uint8_t *irq)
|
||||
bool startTimeout(void (transceiveCb)(uint8_t, Mfrc522*, uint8_t*, uint8_t, void*), void* userData)
|
||||
{
|
||||
write(ComIrqReg, 0b01111111);
|
||||
if(read(Status1Reg) & (1 << 4))
|
||||
{
|
||||
*irq = read(ComIrqReg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
_transceiveCb = transceiveCb;
|
||||
_transceiveUserData = userData;
|
||||
if(mode != MODE_IDLE)
|
||||
return false;
|
||||
mode = MODE_TIMEOUT;
|
||||
write(TReloadRegH, TIMEOUT_TIMER >> 8);
|
||||
write(TReloadRegL, TIMEOUT_TIMER & 0x0F);
|
||||
write(ComIrqReg, 0b01111111); // clear irqs
|
||||
write(ComIEnReg, (1 << 0));
|
||||
updateBit(ControlReg, 6, true);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool probe(SpiMaster* spi, ShiftReg<NFC_PORTS>* csReg, uint8_t csPin);
|
||||
|
Reference in New Issue
Block a user