Helmut Tschemernjak / SX1276GenericLib

Dependents:   DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_PingPong DISCO-L072CZ-LRWAN1_LoRa_USB_Rx ... more

Fork of SX1276Lib by Semtech

Files at this revision

API Documentation at this revision

Comitter:
Helmut Tschemernjak
Date:
Sun Nov 12 18:23:36 2017 +0100
Parent:
93:c328629726a6
Child:
95:36a7fc74e437
Commit message:
Added support to clear unused DIO handlers when the DIO pin is not connected.
Added support to use CADDone on DIO0 instead of DIO3 when DIO3 is not connected.

Changed in this revision

sx1276/sx1276-mbed-hal.cpp Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/sx1276/sx1276-mbed-hal.cpp	Tue Oct 24 20:05:16 2017 +0200
+++ b/sx1276/sx1276-mbed-hal.cpp	Sun Nov 12 18:23:36 2017 +0100
@@ -170,14 +170,28 @@
 {
     if (_dio0)
     	_dio0->rise(callback(this, static_cast< Trigger > ( irqHandlers[0] )));
+    else
+        irqHandlers[0] = NULL;
+    
     if (_dio1)
     	_dio1->rise(callback(this, static_cast< Trigger > ( irqHandlers[1] )));
+ 	else
+    	irqHandlers[1] = NULL;
+    
     if (_dio2)
     	_dio2->rise(callback(this, static_cast< Trigger > ( irqHandlers[2] )));
+    else
+        irqHandlers[2] = NULL;
+    
     if (_dio3)
     	_dio3->rise(callback(this, static_cast< Trigger > ( irqHandlers[3] )));
+    else
+        irqHandlers[3] = NULL;
+    
     if (_dio4)
         _dio4->rise(callback(this, static_cast< Trigger > ( irqHandlers[4] )));
+	else
+        irqHandlers[4] = NULL;
 }
 
 void SX1276Generic::IoDeInit( void )
--- a/sx1276/sx1276.cpp	Tue Oct 24 20:05:16 2017 +0200
+++ b/sx1276/sx1276.cpp	Sun Nov 12 18:23:36 2017 +0100
@@ -1039,8 +1039,13 @@
                   						//RFLR_IRQFLAGS_CADDETECTED
                                         );
 
-            // DIO3=CADDone
-			Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO3_MASK ) | RFLR_DIOMAPPING1_DIO3_00 );
+            if (this->dioIrq[3]) {
+                // DIO3=CADDone
+                Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO3_MASK ) | RFLR_DIOMAPPING1_DIO3_00 );
+            } else {
+                // DIO0=CADDone
+                Write( REG_DIOMAPPING1, ( Read( REG_DIOMAPPING1 ) & RFLR_DIOMAPPING1_DIO0_MASK ) | RFLR_DIOMAPPING1_DIO0_00 );
+            }
 
             this->settings.State = RF_CAD;
             SetOpMode( RFLR_OPMODE_CAD );
@@ -1495,6 +1500,33 @@
                 break;
             }
             break;
+        case RF_CAD:
+            // CadDone interrupt
+            switch( this->settings.Modem ) {
+            case MODEM_LORA:
+            {
+                if( ( Read( REG_LR_IRQFLAGS ) & RFLR_IRQFLAGS_CADDETECTED ) == RFLR_IRQFLAGS_CADDETECTED )
+                {
+                    // Clear Irq
+                    Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDETECTED | RFLR_IRQFLAGS_CADDONE );
+                    if (this->RadioEvents && this->RadioEvents->CadDone)
+                    {
+                        this->RadioEvents->CadDone(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData, true );
+                    }
+                } else {
+                    // Clear Irq
+                    Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_CADDONE );
+                    if (this->RadioEvents && this->RadioEvents->CadDone)
+                    {
+                        this->RadioEvents->CadDone(this, this->RadioEvents->userThisPtr, this->RadioEvents->userData, false );
+                    }
+                }
+            }
+            case MODEM_FSK:
+            default:
+        	this->settings.State = RF_IDLE;
+            	break;
+        }
         default:
             break;
     }