From 8567c77641f255277c24e3f6377daf3de173bfeb Mon Sep 17 00:00:00 2001
From: jgromes <jan.gromes@gmail.com>
Date: Wed, 21 Jun 2023 22:07:24 +0200
Subject: [PATCH] [CC1101] Implemented generic actions

---
 .../CC1101_Receive_Interrupt.ino              |  2 +-
 .../CC1101_Transmit_Interrupt.ino             |  5 +----
 src/modules/CC1101/CC1101.cpp                 | 16 ++++++++++++++
 src/modules/CC1101/CC1101.h                   | 22 +++++++++++++++++++
 4 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino
index f61253fc..4dbd17f1 100644
--- a/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino
+++ b/examples/CC1101/CC1101_Receive_Interrupt/CC1101_Receive_Interrupt.ino
@@ -49,7 +49,7 @@ void setup() {
 
   // set the function that will be called
   // when new packet is received
-  radio.setGdo0Action(setFlag, RISING);
+  radio.setPacketReceivedAction(setFlag);
 
   // start listening for packets
   Serial.print(F("[CC1101] Starting to listen ... "));
diff --git a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino
index 699e88c4..ee88090a 100644
--- a/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino
+++ b/examples/CC1101/CC1101_Transmit_Interrupt/CC1101_Transmit_Interrupt.ino
@@ -48,10 +48,7 @@ void setup() {
 
   // set the function that will be called
   // when packet transmission is finished
-  // NOTE: Unlike other modules (such as SX127x),
-  //       different GDOx pins are used for
-  //       transmit and receive interrupts!
-  radio.setGdo2Action(setFlag, FALLING);
+  radio.setPacketSentAction(setFlag);
 
   // start transmitting the first packet
   Serial.print(F("[CC1101] Sending first packet ... "));
diff --git a/src/modules/CC1101/CC1101.cpp b/src/modules/CC1101/CC1101.cpp
index 24721017..8a90f480 100644
--- a/src/modules/CC1101/CC1101.cpp
+++ b/src/modules/CC1101/CC1101.cpp
@@ -239,6 +239,22 @@ void CC1101::clearGdo0Action() {
   this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()));
 }
 
+void CC1101::setPacketReceivedAction(void (*func)(void)) {
+  this->setGdo0Action(func, RISING);
+}
+
+void CC1101::clearPacketReceivedAction() {
+  this->clearGdo0Action();
+}
+
+void CC1101::setPacketSentAction(void (*func)(void)) {
+  this->setGdo2Action(func, FALLING);
+}
+
+void CC1101::clearPacketSentAction() {
+  this->clearGdo2Action();
+}
+
 void CC1101::setGdo2Action(void (*func)(void), uint32_t dir) {
   if(this->mod->getGpio() == RADIOLIB_NC) {
     return;
diff --git a/src/modules/CC1101/CC1101.h b/src/modules/CC1101/CC1101.h
index 8dbf4326..4ca73c60 100644
--- a/src/modules/CC1101/CC1101.h
+++ b/src/modules/CC1101/CC1101.h
@@ -659,6 +659,28 @@ class CC1101: public PhysicalLayer {
     */
     void clearGdo2Action();
 
+    /*!
+      \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.