Skip to content

Commit 698c5c9

Browse files
authored
Merge pull request #9 from RestucciaMichele/main
inline to the new rfal library
2 parents 9aa5132 + 301f859 commit 698c5c9

File tree

9 files changed

+676
-128
lines changed

9 files changed

+676
-128
lines changed

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino ST25R3911B
2-
version=1.0.4
2+
version=2.0.0
33
author=STMicroelectronics
44
maintainer=stm32duino
55
sentence=Allows controlling the ST ST25R3911B component

src/rfal_rfst25r3911.cpp

Lines changed: 550 additions & 87 deletions
Large diffs are not rendered by default.

src/rfal_rfst25r3911.h

Lines changed: 96 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@
3636
* INCLUDES
3737
******************************************************************************
3838
*/
39-
39+
#include "rfal_config.h"
4040
#include "SPI.h"
41+
#include "Wire.h"
4142
#include "rfal_rf.h"
4243
#include "st_errno.h"
4344
#include "nfc_utils.h"
@@ -46,12 +47,21 @@
4647
#include "st25r3911_interrupt.h"
4748
#include "rfal_rfst25r3911_analogConfig.h"
4849
#include "rfal_rfst25r3911_iso15693_2.h"
50+
#include <functional>
4951

5052
/*
51-
******************************************************************************
52-
* ENABLE SWITCHES
53-
******************************************************************************
54-
*/
53+
******************************************************************************
54+
* ENABLE SWITCH
55+
******************************************************************************
56+
*/
57+
58+
#ifndef RFAL_FEATURE_LISTEN_MODE
59+
#error " RFAL: Module configuration missing. Please enable/disable support for Listen Mode: RFAL_FEATURE_LISTEN_MODE "
60+
#endif
61+
62+
#ifndef RFAL_FEATURE_WAKEUP_MODE
63+
#error " RFAL: Module configuration missing. Please enable/disable support for Wake-Up Mode: RFAL_FEATURE_WAKEUP_MODE "
64+
#endif
5565

5666
/*
5767
******************************************************************************
@@ -70,22 +80,46 @@ typedef struct {
7080
} rfalTxRx;
7181

7282

83+
/*! Struct that holds certain WU mode information to be retrieved by rfalWakeUpModeGetInfo */
84+
typedef struct {
85+
bool irqWut; /*!< Wake-Up Timer IRQ received (cleared upon read) */
86+
87+
struct {
88+
uint8_t lastMeas; /*!< Value of the latest measurement */
89+
bool irqWu; /*!< Amplitude WU IRQ received (cleared upon read) */
90+
} indAmp; /*!< Inductive Amplitude */
91+
struct {
92+
uint8_t lastMeas; /*!< Value of the latest measurement */
93+
bool irqWu; /*!< Phase WU IRQ received (cleared upon read) */
94+
} indPha; /*!< Inductive Phase */
95+
struct {
96+
uint8_t lastMeas; /*!< Value of the latest measurement */
97+
bool irqWu; /*!< Capacitive WU IRQ received (cleared upon read) */
98+
} cap; /*!< Capacitance */
99+
} rfalWakeUpData;
100+
101+
73102
/*! Struct that holds all context for the Listen Mode */
74103
typedef struct {
75104
rfalLmState state; /*!< Current Listen Mode state */
105+
uint32_t mdMask; /*!< Listen Mode mask used */
106+
uint32_t mdReg; /*!< Listen Mode register value used */
107+
uint32_t mdIrqs; /*!< Listen Mode IRQs used */
76108
rfalBitRate brDetected; /*!< Last bit rate detected */
77109

78110
uint8_t *rxBuf; /*!< Location to store incoming data in Listen Mode */
79111
uint16_t rxBufLen; /*!< Length of rxBuf */
80112
uint16_t *rxLen; /*!< Pointer to write the data length placed into rxBuf */
81113
bool dataFlag; /*!< Listen Mode current Data Flag */
114+
bool iniFlag; /*!< Listen Mode initialized Flag (FeliCa slots) */
82115
} rfalLm;
83116

84117

85118
/*! Struct that holds all context for the Wake-Up Mode */
86119
typedef struct {
87120
rfalWumState state; /*!< Current Wake-Up Mode state */
88121
rfalWakeUpConfig cfg; /*!< Current Wake-Up Mode context */
122+
rfalWakeUpData info; /*!< Current Wake-Up Mode info */
89123
} rfalWum;
90124

91125

@@ -94,6 +128,7 @@ typedef struct {
94128
uint32_t GT; /*!< GT in 1/fc */
95129
uint32_t FDTListen; /*!< FDTListen in 1/fc */
96130
uint32_t FDTPoll; /*!< FDTPoll in 1/fc */
131+
uint8_t nTRFW; /*!< n*TRFW (last two bits) used during RF CA */
97132
} rfalTimings;
98133

99134

@@ -102,13 +137,16 @@ typedef struct {
102137
uint32_t GT; /*!< RFAL's GT timer */
103138
uint32_t FWT; /*!< FWT/RWT timer for Active P2P*/
104139
uint32_t RXE; /*!< Timer between RXS and RXE */
140+
uint32_t PPON2; /*!< Timer between TXE - PPON2 */
141+
uint32_t txRx; /*!< Transceive sanity timer */
105142
} rfalTimers;
106143

107144

108145
/*! Struct that holds the RFAL's callbacks */
109146
typedef struct {
110147
rfalPreTxRxCallback preTxRx; /*!< RFAL's Pre TxRx callback */
111148
rfalPostTxRxCallback postTxRx; /*!< RFAL's Post TxRx callback */
149+
rfalSyncTxRxCallback syncTxRx; /*!< RFAL's Sync TxRx callback */
112150
} rfalCallbacks;
113151

114152

@@ -128,10 +166,28 @@ typedef struct {
128166
rfalEHandling eHandling; /*!< RFAL's error handling config/mode */
129167
} rfalConfigs;
130168

169+
/*! Struct that holds NFC-A data - Used only inside rfalISO14443ATransceiveAnticollisionFrame() */
170+
typedef struct {
171+
uint8_t collByte; /*!< NFC-A Anticollision collision byte */
172+
uint8_t *buf; /*!< NFC-A Anticollision frame buffer */
173+
uint8_t *bytesToSend;/*!< NFC-A Anticollision NFCID|UID byte context */
174+
uint8_t *bitsToSend; /*!< NFC-A Anticollision NFCID|UID bit context */
175+
uint16_t *rxLength; /*!< NFC-A Anticollision received length */
176+
} rfalNfcaWorkingData;
177+
131178

132-
/*! Struct that holds NFC-F data - Used only inside rfalFelicaPoll() (static to avoid adding it into stack) */
179+
/*! Struct that holds NFC-F data - Used only inside rfalFelicaPoll() */
133180
typedef struct {
134-
rfalFeliCaPollRes pollResponses[RFAL_FELICA_POLL_MAX_SLOTS]; /* FeliCa Poll response container for 16 slots */
181+
uint16_t actLen; /* Received length */
182+
rfalFeliCaPollRes *pollResList; /* Location of NFC-F device list */
183+
uint8_t pollResListSize; /* Size of NFC-F device list */
184+
uint8_t devDetected; /* Number of devices detected */
185+
uint8_t colDetected; /* Number of collisions detected */
186+
uint8_t *devicesDetected; /* Location to place number of devices */
187+
uint8_t *collisionsDetected; /* Location to place number of collisions */
188+
rfalEHandling curHandling; /* RFAL's error handling */
189+
rfalFeliCaPollRes pollResponses[RFAL_FELICA_POLL_MAX_SLOTS]; /* FeliCa Poll response buffer (16 slots) */
190+
rfalFeliCaPollSlots slots;
135191
} rfalNfcfWorkingData;
136192

137193

@@ -171,11 +227,25 @@ typedef struct {
171227
rfalTimers tmr; /*!< RFAL's Software timers */
172228
rfalCallbacks callbacks; /*!< RFAL's callbacks */
173229

230+
#if RFAL_FEATURE_LISTEN_MODE
231+
rfalLm Lm; /*!< RFAL's listen mode management */
232+
#endif /* RFAL_FEATURE_LISTEN_MODE */
233+
234+
#if RFAL_FEATURE_WAKEUP_MODE
174235
rfalWum wum; /*!< RFAL's Wake-up mode management */
236+
#endif /* RFAL_FEATURE_WAKEUP_MODE */
237+
238+
#if RFAL_FEATURE_NFCA
239+
rfalNfcaWorkingData nfcaData; /*!< RFAL's working data when supporting NFC-A */
240+
#endif /* RFAL_FEATURE_NFCA */
175241

242+
#if RFAL_FEATURE_NFCF
176243
rfalNfcfWorkingData nfcfData; /*!< RFAL's working data when supporting NFC-F */
244+
#endif /* RFAL_FEATURE_NFCF */
177245

246+
#if RFAL_FEATURE_NFCV
178247
rfalNfcvWorkingData nfcvData; /*!< RFAL's working data when supporting NFC-V */
248+
#endif /* RFAL_FEATURE_NFCV */
179249

180250
} rfal;
181251

@@ -362,6 +432,7 @@ typedef void (*ST25R3911BIrqHandler)(void);
362432
#define rfalAdjACBR( b ) (((uint16_t)(b) >= (uint16_t)RFAL_BR_52p97) ? (uint16_t)(b) : ((uint16_t)(b)+1U)) /*!< Adjusts ST25R391x Bit rate to Analog Configuration */
363433
#define rfalConvBR2ACBR( b ) (((rfalAdjACBR((b)))<<RFAL_ANALOG_CONFIG_BITRATE_SHIFT) & RFAL_ANALOG_CONFIG_BITRATE_MASK) /*!< Converts ST25R391x Bit rate to Analog Configuration bit rate id */
364434

435+
#define rfalRunBlocking( e, fn ) do{ (e)=(fn); rfalWorker(); }while( (e) == ERR_BUSY )
365436

366437

367438
class RfalRfST25R3911BClass : public RfalRfClass {
@@ -380,14 +451,15 @@ class RfalRfST25R3911BClass : public RfalRfClass {
380451
void rfalSetUpperLayerCallback(rfalUpperLayerCallback pFunc);
381452
void rfalSetPreTxRxCallback(rfalPreTxRxCallback pFunc);
382453
void rfalSetPostTxRxCallback(rfalPostTxRxCallback pFunc);
454+
void rfalSetLmEonCallback(rfalLmEonCallback pFunc);
383455
ReturnCode rfalDeinitialize(void);
384456
ReturnCode rfalSetMode(rfalMode mode, rfalBitRate txBR, rfalBitRate rxBR);
385457
rfalMode rfalGetMode(void);
386458
ReturnCode rfalSetBitRate(rfalBitRate txBR, rfalBitRate rxBR);
387459
ReturnCode rfalGetBitRate(rfalBitRate *txBR, rfalBitRate *rxBR);
388460
void rfalSetErrorHandling(rfalEHandling eHandling);
389461
rfalEHandling rfalGetErrorHandling(void);
390-
void rfalSetObsvMode(uint8_t txMode, uint8_t rxMode);
462+
void rfalSetObsvMode(uint32_t txMode, uint32_t rxMode);
391463
void rfalGetObsvMode(uint8_t *txMode, uint8_t *rxMode);
392464
void rfalDisableObsvMode(void);
393465
void rfalSetFDTPoll(uint32_t FDTPoll);
@@ -406,12 +478,23 @@ class RfalRfST25R3911BClass : public RfalRfClass {
406478
bool rfalIsTransceiveInRx(void);
407479
ReturnCode rfalGetTransceiveRSSI(uint16_t *rssi);
408480
void rfalWorker(void);
481+
void rfalSetSyncTxRxCallback(rfalSyncTxRxCallback pFunc);
482+
bool rfalIsTransceiveSubcDetected(void);
483+
ReturnCode rfalISO14443AStartTransceiveAnticollisionFrame(uint8_t *buf, uint8_t *bytesToSend, uint8_t *bitsToSend, uint16_t *rxLength, uint32_t fwt);
484+
ReturnCode rfalISO14443AGetTransceiveAnticollisionFrameStatus(void);
485+
486+
#if RFAL_FEATURE_LISTEN_MODE
487+
ReturnCode rfalRunListenModeWorker(void);
488+
#endif /* RFAL_FEATURE_LISTEN_MODE */
489+
409490
ReturnCode rfalISO14443ATransceiveShortFrame(rfal14443AShortFrameCmd txCmd, uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *rxRcvdLen, uint32_t fwt);
410491
ReturnCode rfalISO14443ATransceiveAnticollisionFrame(uint8_t *buf, uint8_t *bytesToSend, uint8_t *bitsToSend, uint16_t *rxLength, uint32_t fwt);
411492
ReturnCode rfalFeliCaPoll(rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *pollResList, uint8_t pollResListSize, uint8_t *devicesDetected, uint8_t *collisionsDetected);
493+
ReturnCode rfalStartFeliCaPoll(rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *pollResList, uint8_t pollResListSize, uint8_t *devicesDetected, uint8_t *collisionsDetected);
494+
ReturnCode rfalGetFeliCaPollStatus(void);
412495
ReturnCode rfalISO15693TransceiveAnticollisionFrame(uint8_t *txBuf, uint8_t txBufLen, uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen);
413496
ReturnCode rfalISO15693TransceiveEOFAnticollision(uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen);
414-
ReturnCode rfalISO15693TransceiveEOF(uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen);
497+
ReturnCode rfalISO15693TransceiveEOF(uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *actLen);
415498
ReturnCode rfalTransceiveBlockingTx(uint8_t *txBuf, uint16_t txBufLen, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *actLen, uint32_t flags, uint32_t fwt);
416499
ReturnCode rfalTransceiveBlockingRx(void);
417500
ReturnCode rfalTransceiveBlockingTxRx(uint8_t *txBuf, uint16_t txBufLen, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *actLen, uint32_t flags, uint32_t fwt);
@@ -421,7 +504,9 @@ class RfalRfST25R3911BClass : public RfalRfClass {
421504
ReturnCode rfalListenStop(void);
422505
rfalLmState rfalListenGetState(bool *dataFlag, rfalBitRate *lastBR);
423506
ReturnCode rfalListenSetState(rfalLmState newSt);
507+
bool rfalWakeUpModeIsEnabled(void);
424508
ReturnCode rfalWakeUpModeStart(const rfalWakeUpConfig *config);
509+
ReturnCode rfalWakeUpModeGetInfo(bool force, rfalWakeUpInfo *info);
425510
bool rfalWakeUpModeHasWoke(void);
426511
ReturnCode rfalWakeUpModeStop(void);
427512

@@ -1802,7 +1887,9 @@ class RfalRfST25R3911BClass : public RfalRfClass {
18021887
void rfalCleanupTransceive(void);
18031888
void rfalErrorHandling(void);
18041889
ReturnCode rfalRunTransceiveWorker(void);
1890+
#if RFAL_FEATURE_WAKEUP_MODE
18051891
void rfalRunWakeUpModeWorker(void);
1892+
#endif /* RFAL_FEATURE_WAKEUP_MODE */
18061893

18071894
void rfalFIFOStatusUpdate(void);
18081895
void rfalFIFOStatusClear(void);
@@ -1836,7 +1923,6 @@ class RfalRfST25R3911BClass : public RfalRfClass {
18361923
volatile t_st25r3911Interrupt st25r3911interrupt; /*!< Instance of ST25R3911 interrupt */
18371924
uint32_t timerStopwatchTick;
18381925
volatile bool isr_pending;
1839-
volatile bool bus_busy;
18401926
ST25R3911BIrqHandler irq_handler;
18411927
};
18421928

src/rfal_rfst25r3911_iso15693_2.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
******************************************************************************
4343
*/
4444

45+
#if RFAL_FEATURE_NFCV
4546
/*
4647
******************************************************************************
4748
* LOCAL MACROS
@@ -462,3 +463,5 @@ ReturnCode iso15693PhyVCDCode1Of256(const uint8_t data, uint8_t *outbuffer, uint
462463

463464
return err;
464465
}
466+
467+
#endif /* RFAL_FEATURE_NFCV */

src/st25r3911.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ ReturnCode RfalRfST25R3911BClass::st25r3911CalibrateCapacitiveSensor(uint8_t *re
229229
uint8_t res;
230230

231231
/* Clear Manual calibration values to enable automatic calibration mode */
232-
st25r3911ClrRegisterBits(ST25R3911_REG_CAP_SENSOR_CONTROL, ST25R3911_REG_CAP_SENSOR_CONTROL_mask_cs_mcal);
232+
st25r3911ClrRegisterBits(ST25R3911_REG_CAP_SENSOR_CONTROL, ST25R3916_REG_CAP_SENSOR_CONTROL_mask_cs_mcal);
233233

234234
/* Execute automatic calibration */
235235
ret = st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_CALIBRATE_C_SENSOR, ST25R3911_REG_CAP_SENSOR_RESULT, ST25R3911_TOUT_CALIBRATE_CAP_SENSOR, &res);

src/st25r3911.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
******************************************************************************
5757
*/
5858
#include "st_errno.h"
59+
#include "st25r3911_com.h"
5960

6061
/*
6162
******************************************************************************

0 commit comments

Comments
 (0)