Skip to content

Commit bcb4de3

Browse files
authored
Merge pull request #4 from cparata/main
Move the interrupt management inside the ST25R3916 library
2 parents 9d67ff2 + e74cbe1 commit bcb4de3

3 files changed

Lines changed: 39 additions & 10 deletions

File tree

library.properties

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

src/rfal_rfst25r3916.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ RfalRfST25R3916Class::RfalRfST25R3916Class(SPIClass *spi, int cs_pin, int int_pi
5050
dev_i2c = NULL;
5151
isr_pending = false;
5252
bus_busy = false;
53+
irq_handler = NULL;
5354
}
5455

5556
RfalRfST25R3916Class::RfalRfST25R3916Class(TwoWire *i2c, int int_pin) : dev_i2c(i2c), int_pin(int_pin)
@@ -64,6 +65,7 @@ RfalRfST25R3916Class::RfalRfST25R3916Class(TwoWire *i2c, int int_pin) : dev_i2c(
6465
dev_spi = NULL;
6566
isr_pending = false;
6667
bus_busy = false;
68+
irq_handler = NULL;
6769
}
6870

6971

@@ -74,6 +76,11 @@ ReturnCode RfalRfST25R3916Class::rfalInitialize(void)
7476
pinMode(cs_pin, OUTPUT);
7577
digitalWrite(cs_pin, HIGH);
7678

79+
pinMode(int_pin, INPUT);
80+
Callback<void()>::func = std::bind(&RfalRfST25R3916Class::st25r3916Isr, this);
81+
irq_handler = static_cast<ST25R3916IrqHandler>(Callback<void()>::callback);
82+
attachInterrupt(int_pin, irq_handler, RISING);
83+
7784
rfalAnalogConfigInitialize(); /* Initialize RFAL's Analog Configs */
7885

7986
EXIT_ON_ERR(err, st25r3916Initialize());
@@ -196,6 +203,10 @@ ReturnCode RfalRfST25R3916Class::rfalDeinitialize(void)
196203
rfalSetAnalogConfig((RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_DEINIT));
197204

198205
gRFAL.state = RFAL_STATE_IDLE;
206+
207+
detachInterrupt(int_pin);
208+
irq_handler = NULL;
209+
199210
return ERR_NONE;
200211
}
201212

src/rfal_rfst25r3916.h

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include "rfal_rfst25r3916_analogConfig.h"
4949
#include "rfal_rfst25r3916_iso15693_2.h"
5050
#include "st25r3916_aat.h"
51+
#include <functional>
5152

5253
/*
5354
******************************************************************************
@@ -210,6 +211,23 @@ typedef struct {
210211
bool ready; /*!< Indicate if Look Up Table is complete and ready for use */
211212
} rfalAnalogConfigMgmt;
212213

214+
template <typename T>
215+
struct Callback;
216+
217+
template <typename Ret, typename... Params>
218+
struct Callback<Ret(Params...)> {
219+
template <typename... Args>
220+
static Ret callback(Args... args) {
221+
return func(args...);
222+
}
223+
static std::function<Ret(Params...)> func;
224+
};
225+
226+
template <typename Ret, typename... Params>
227+
std::function<Ret(Params...)> Callback<Ret(Params...)>::func;
228+
229+
typedef void (*ST25R3916IrqHandler)(void);
230+
213231
/*
214232
******************************************************************************
215233
* GLOBAL DEFINES
@@ -1747,15 +1765,6 @@ class RfalRfST25R3916Class : public RfalRfClass {
17471765
*/
17481766
void st25r3916CheckForReceivedInterrupts(void);
17491767

1750-
/*!
1751-
*****************************************************************************
1752-
* \brief ISR Service routine
1753-
*
1754-
* This function modiefies the interrupt
1755-
*****************************************************************************
1756-
*/
1757-
void st25r3916Isr(void);
1758-
17591768
/*!
17601769
*****************************************************************************
17611770
* \brief Enable a given ST25R3916 Interrupt source
@@ -1951,6 +1960,14 @@ class RfalRfST25R3916Class : public RfalRfClass {
19511960
ReturnCode aatStepDacVals(const struct st25r3916AatTuneParams *tuningParams, uint8_t *a, uint8_t *b, int32_t dir);
19521961
void setISRPending(void);
19531962
bool isBusBusy(void);
1963+
/*!
1964+
*****************************************************************************
1965+
* \brief ISR Service routine
1966+
*
1967+
* This function modifies the interrupt
1968+
*****************************************************************************
1969+
*/
1970+
void st25r3916Isr(void);
19541971

19551972
TwoWire *dev_i2c;
19561973
SPIClass *dev_spi;
@@ -1967,6 +1984,7 @@ class RfalRfST25R3916Class : public RfalRfClass {
19671984
bool i2c_enabled;
19681985
volatile bool isr_pending;
19691986
volatile bool bus_busy;
1987+
ST25R3916IrqHandler irq_handler;
19701988
};
19711989

19721990
#ifdef __cplusplus

0 commit comments

Comments
 (0)