#include <memory>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <spdlog/spdlog.h>
#include "rc522.h"
Go to the source code of this file.
|
void | InitRc522 (SPI *p_spi) |
|
char | PcdRequest (uint8_t req_code, uint8_t *pTagType) |
|
char | PcdAnticoll (uint8_t cascade, uint8_t *pSnr) |
|
char | PcdSelect (uint8_t cascade, uint8_t *pSnr, uint8_t *SAK) |
|
char | PcdAuthState (uint8_t auth_mode, uint8_t addr, uint8_t *pKey, uint8_t *pSnr) |
|
char | PcdRead (uint8_t addr, uint8_t *p) |
|
char | PcdWrite (uint8_t addr, uint8_t *p) |
|
char | PcdHalt (void) |
|
char | PcdValue (uint8_t act, uint8_t addr, double value) |
|
void | Pcd_stopcrypto1 () |
|
int | PcdCheckAuth () |
|
void | CalulateCRC (uint8_t *pIn, uint8_t len, uint8_t *pOut) |
|
char | PcdReset (void) |
|
uint8_t | ReadRawRC (uint8_t Address) |
|
uint8_t | WriteRawRC (uint8_t Address, uint8_t value) |
|
void | SetBitMask (uint8_t reg, uint8_t mask) |
|
void | ClearBitMask (uint8_t reg, uint8_t mask) |
|
char | PcdComMF522 (uint8_t Command, uint8_t *pIn, uint8_t InLenByte, uint8_t *pOut, uint8_t *pOutLenBit, int CheckTimeout) |
|
void | PcdAntennaOn (void) |
|
void | PcdAntennaOff (void) |
|
◆ CalulateCRC()
void CalulateCRC |
( |
uint8_t * |
pIn, |
|
|
uint8_t |
len, |
|
|
uint8_t * |
pOut |
|
) |
| |
Definition at line 461 of file rc522.cpp.
489 while ((i!=0) && !(n&0x04));
void ClearBitMask(uint8_t reg, uint8_t mask)
uint8_t WriteRawRC(uint8_t Address, uint8_t value)
void SetBitMask(uint8_t reg, uint8_t mask)
uint8_t ReadRawRC(uint8_t Address)
◆ ClearBitMask()
void ClearBitMask |
( |
uint8_t |
reg, |
|
|
uint8_t |
mask |
|
) |
| |
◆ InitRc522()
void InitRc522 |
( |
SPI * |
p_spi | ) |
|
Definition at line 39 of file rc522.cpp.
41 if (p_spi)
spi = p_spi;
42 else spdlog::critical(
"rc522.cpp - RC522 didn't recieve SPI");
◆ Pcd_stopcrypto1()
◆ PcdAntennaOff()
void PcdAntennaOff |
( |
void |
| ) |
|
◆ PcdAntennaOn()
void PcdAntennaOn |
( |
void |
| ) |
|
◆ PcdAnticoll()
char PcdAnticoll |
( |
uint8_t |
cascade, |
|
|
uint8_t * |
pSnr |
|
) |
| |
Definition at line 89 of file rc522.cpp.
92 uint8_t i,snr_check=0;
110 ucComMF522Buf[0] = cascade;
124 ucComMF522Buf[1] = 0x20+collbits;
137 if (collbits==0) collbits=32;
142 ucComMF522Buf[i-1]|=(1<<((collbits-1)%8));
143 ucComMF522Buf[5]=ucComMF522Buf[3];
144 ucComMF522Buf[4]=ucComMF522Buf[2];
145 ucComMF522Buf[3]=ucComMF522Buf[1];
146 ucComMF522Buf[2]=ucComMF522Buf[0];
156 for (i=0; i < 4; i++)
158 *(pSnr+i) = ucComMF522Buf[i];
159 snr_check ^= ucComMF522Buf[i];
162 if (snr_check != ucComMF522Buf[i]) status =
TAG_ERR;
char PcdComMF522(uint8_t Command, uint8_t *pIn, uint8_t InLenByte, uint8_t *pOut, uint8_t *pOutLenBit, int CheckTimeout)
◆ PcdAuthState()
char PcdAuthState |
( |
uint8_t |
auth_mode, |
|
|
uint8_t |
addr, |
|
|
uint8_t * |
pKey, |
|
|
uint8_t * |
pSnr |
|
) |
| |
Definition at line 259 of file rc522.cpp.
263 uint8_t ucComMF522Buf[
MAXRLEN];
265 memset(ucComMF522Buf,0,
sizeof(ucComMF522Buf));
267 ucComMF522Buf[0] = auth_mode;
268 ucComMF522Buf[1] = addr;
270 memcpy(&ucComMF522Buf[2], pKey, 6);
271 memcpy(&ucComMF522Buf[8], pSnr, 4);
◆ PcdCheckAuth()
◆ PcdComMF522()
char PcdComMF522 |
( |
uint8_t |
Command, |
|
|
uint8_t * |
pIn, |
|
|
uint8_t |
InLenByte, |
|
|
uint8_t * |
pOut, |
|
|
uint8_t * |
pOutLenBit, |
|
|
int |
CheckTimeout |
|
) |
| |
Definition at line 626 of file rc522.cpp.
635 uint8_t irqEn = 0x00;
636 uint8_t waitFor = 0x00;
653 printf(
"FATAL - RC522 unrecognized command in PcdComMF522(...)");
704 while (i!=0 && (! (n&0x01)) && (!(n&waitFor)));
715 if (!(PcdErr & 0x11))
720 if (n & irqEn & 0x01)
736 if (lastBits) *pOutLenBit = (n-1)*8 + lastBits;
737 else *pOutLenBit = n*8;
744 for (i=0; i < n; i++) {
768 printf(
"Parity or buffer overflow\n");
775 printf(
"ERROR - RC522 PcdComRF522 Collision!");
◆ PcdHalt()
Definition at line 363 of file rc522.cpp.
367 uint8_t ucComMF522Buf[
MAXRLEN];
370 ucComMF522Buf[1] = 0;
void CalulateCRC(uint8_t *pIn, uint8_t len, uint8_t *pOut)
◆ PcdRead()
char PcdRead |
( |
uint8_t |
addr, |
|
|
uint8_t * |
p |
|
) |
| |
Definition at line 286 of file rc522.cpp.
290 uint8_t i,ucComMF522Buf[
MAXRLEN];
293 memset(ucComMF522Buf,0,
sizeof(ucComMF522Buf));
296 ucComMF522Buf[1] = addr;
303 if ((status ==
TAG_OK) && (unLen == 0x90))
311 if ((CRC_buff[0]!=ucComMF522Buf[16])||(CRC_buff[1]!=ucComMF522Buf[17]))
317 for (i=0; i<16; i++) *(p+i) = ucComMF522Buf[i];
◆ PcdRequest()
char PcdRequest |
( |
uint8_t |
req_code, |
|
|
uint8_t * |
pTagType |
|
) |
| |
Definition at line 47 of file rc522.cpp.
62 ucComMF522Buf[0] = req_code;
68 if ((status ==
TAG_OK) && (unLen == 0x10))
70 *pTagType = ucComMF522Buf[0];
71 *(pTagType+1) = ucComMF522Buf[1];
◆ PcdReset()
◆ PcdSelect()
char PcdSelect |
( |
uint8_t |
cascade, |
|
|
uint8_t * |
pSnr, |
|
|
uint8_t * |
SAK |
|
) |
| |
Definition at line 187 of file rc522.cpp.
192 uint8_t ucComMF522Buf[
MAXRLEN];
195 ucComMF522Buf[0] = cascade;
196 ucComMF522Buf[1] = 0x70;
197 ucComMF522Buf[6] = 0;
201 ucComMF522Buf[i+2] = *(pSnr+i);
202 ucComMF522Buf[6] ^= *(pSnr+i);
214 if ((status ==
TAG_OK) && (unLen == 0x18))
222 if ((CRC_buff[0]!=ucComMF522Buf[1])||(CRC_buff[1]!=ucComMF522Buf[2]))
227 *SAK = ucComMF522Buf[0];
◆ PcdValue()
char PcdValue |
( |
uint8_t |
act, |
|
|
uint8_t |
addr, |
|
|
double |
value |
|
) |
| |
Definition at line 385 of file rc522.cpp.
389 uint8_t ucComMF522Buf[
MAXRLEN];
392 ucComMF522Buf[0] = act;
393 ucComMF522Buf[1] = addr;
403 printf(
"ERROR - PcdValue(...) cannot send command!!!");
408 ucComMF522Buf[0] = ((
long long) value & (
long long) 0xff);
409 ucComMF522Buf[1] = ((
long long) value & (
long long) 0xff00) >> 8;
410 ucComMF522Buf[2] = ((
long long) value & (
long long) 0xff0000) >> 16;
411 ucComMF522Buf[3] = ((
long long) value & (
long long) 0xff000000) >> 24;
427 if (status !=
TAG_OK) printf(
"ERROR - PcdValue(...) cannot send value!!!");
◆ PcdWrite()
char PcdWrite |
( |
uint8_t |
addr, |
|
|
uint8_t * |
p |
|
) |
| |
Definition at line 326 of file rc522.cpp.
330 uint8_t i,ucComMF522Buf[
MAXRLEN];
333 ucComMF522Buf[1] = addr;
339 if ((status !=
TAG_OK) || (unLen != 4) || ((ucComMF522Buf[0] & 0x0F) != 0x0A))
344 for (i=0; i<16; i++) ucComMF522Buf[i] = *(p+i);
352 if ((status !=
TAG_OK) || (unLen != 4) || ((ucComMF522Buf[0] & 0x0F) != 0x0A))
◆ ReadRawRC()
uint8_t ReadRawRC |
( |
uint8_t |
Address | ) |
|
Definition at line 573 of file rc522.cpp.
575 uint8_t in_buff[2] = {0};
576 uint8_t out_buff[2] = {0};
578 in_buff[0] = ((Address<<1)&0x7E)|0x80;
580 spi->xfer(in_buff, 2, out_buff, 2);
584 return (uint8_t) out_buff[1];
◆ SetBitMask()
void SetBitMask |
( |
uint8_t |
reg, |
|
|
uint8_t |
mask |
|
) |
| |
◆ WriteRawRC()
uint8_t WriteRawRC |
( |
uint8_t |
Address, |
|
|
uint8_t |
value |
|
) |
| |
Definition at line 593 of file rc522.cpp.
597 buff[0] = ((Address<<1)&0x7E);
◆ extra_delay
◆ spi