From 787ebde43e2c1a58d1491c04c1df87d4ea10960f Mon Sep 17 00:00:00 2001 From: jgromes Date: Wed, 21 Jun 2023 22:21:55 +0200 Subject: [PATCH] [SX126x] Implemented generic IRQ actions (#773) --- .../SX126x_Receive_Interrupt.ino | 2 +- .../SX126x_Transmit_Interrupt.ino | 2 +- src/modules/SX126x/SX126x.cpp | 16 ++++++++++++++ src/modules/SX126x/SX126x.h | 22 +++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino b/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino index 76cd07be..0786d4b6 100644 --- a/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino +++ b/examples/SX126x/SX126x_Receive_Interrupt/SX126x_Receive_Interrupt.ino @@ -54,7 +54,7 @@ void setup() { // set the function that will be called // when new packet is received - radio.setDio1Action(setFlag); + radio.setPacketReceivedAction(setFlag); // start listening for LoRa packets Serial.print(F("[SX1262] Starting to listen ... ")); diff --git a/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino b/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino index 850ddbb8..6bf9be2b 100644 --- a/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino +++ b/examples/SX126x/SX126x_Transmit_Interrupt/SX126x_Transmit_Interrupt.ino @@ -53,7 +53,7 @@ void setup() { // set the function that will be called // when packet transmission is finished - radio.setDio1Action(setFlag); + radio.setPacketSentAction(setFlag); // start transmitting the first packet Serial.print(F("[SX1262] Sending first packet ... ")); diff --git a/src/modules/SX126x/SX126x.cpp b/src/modules/SX126x/SX126x.cpp index 6dbb4af2..1cbb5df3 100644 --- a/src/modules/SX126x/SX126x.cpp +++ b/src/modules/SX126x/SX126x.cpp @@ -470,6 +470,22 @@ void SX126x::clearDio1Action() { this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq())); } +void SX126x::setPacketReceivedAction(void (*func)(void)) { + this->setDio1Action(func); +} + +void SX126x::clearPacketReceivedAction() { + this->clearDio1Action(); +} + +void SX126x::setPacketSentAction(void (*func)(void)) { + this->setDio1Action(func); +} + +void SX126x::clearPacketSentAction() { + this->clearDio1Action(); +} + int16_t SX126x::startTransmit(uint8_t* data, size_t len, uint8_t addr) { // suppress unused variable warning (void)addr; diff --git a/src/modules/SX126x/SX126x.h b/src/modules/SX126x/SX126x.h index 7921c608..ce363187 100644 --- a/src/modules/SX126x/SX126x.h +++ b/src/modules/SX126x/SX126x.h @@ -573,6 +573,28 @@ class SX126x: public PhysicalLayer { */ void clearDio1Action(); + /*! + \brief Sets interrupt service routine to call when a packet is received. + \param func ISR to call. + */ + void setPacketReceivedAction(void (*func)(void)); + + /*! + \brief Clears interrupt service routine to call when a packet is received. + */ + void clearPacketReceivedAction(); + + /*! + \brief Sets interrupt service routine to call when a packet is sent. + \param func ISR to call. + */ + void setPacketSentAction(void (*func)(void)); + + /*! + \brief Clears interrupt service routine to call when a packet is sent. + */ + void clearPacketSentAction(); + /*! \brief Interrupt-driven binary transmit method. Overloads for string-based transmissions are implemented in PhysicalLayer.