SX1276 library for modtronix inair9. Edited for use with NRF51DK board.

Dependents:   InAir9_PingPong

Fork of SX1276Lib_modtronix by modtronix H

Revision:
22:20db480143c9
Parent:
21:d3f64a075f0c
Child:
24:1346d1c71c40
diff -r d3f64a075f0c -r 20db480143c9 sx1276/sx1276-inAir.cpp
--- a/sx1276/sx1276-inAir.cpp	Thu Apr 02 12:27:47 2015 +1100
+++ b/sx1276/sx1276-inAir.cpp	Wed May 13 10:24:04 2015 +1000
@@ -9,7 +9,7 @@
 #include "myDebug.h"
 #include "sx1276-inAir.h"
 
-const RadioRegisters_t SX1276inAir9::RadioRegsInit[] = 
+const RadioRegisters_t SX1276inAir::RadioRegsInit[] = 
 {                                                 
     { MODEM_FSK , REG_LNA                , 0x23 },
     { MODEM_FSK , REG_RXCONFIG           , 0x1E },
@@ -28,7 +28,7 @@
     { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },  
 };
 
-SX1276inAir9::SX1276inAir9( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), 
+SX1276inAir::SX1276inAir( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), 
                             void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool ChannelActivityDetected ),
                             PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
                             PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
@@ -39,7 +39,8 @@
 {
     Reset( );
     
-    boardConnected = UNKNOWN;
+    boardConnected = BOARD_UNKNOWN;
+    DetectBoardType( );
     
     RxChainCalibration( );
     
@@ -56,22 +57,22 @@
     this->settings.State = IDLE ;
 }
 
-SX1276inAir9::SX1276inAir9( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), 
+SX1276inAir::SX1276inAir( void ( *txDone )( ), void ( *txTimeout ) ( ), void ( *rxDone ) ( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr ), 
                             void ( *rxTimeout ) ( ), void ( *rxError ) ( ), void ( *fhssChangeChannel ) ( uint8_t channelIndex ), void ( *cadDone ) ( bool ChannelActivityDetected ) ) 
                         #if( (defined (TARGET_NUCLEO_L152RE) || defined (TARGET_NUCLEO_F401RE)) && defined(SHIELD_SHD3I_INAIR9))
-                        //For SHD3I with inAir9 in imod3, on Nucleo board
+                        //For SHD3I with BOARD_INAIR4 in imod3, on Nucleo board
                         :   SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone,
                                     D11/*MOSI*/, D12/*MISO*/, D13/*SCLK*/, D7/*CS*/, A5/*RST*/, D2/*DIO0*/, D8, D4, A4, PC_3/*FAKE!!!*/, D3/*DIO5*/ ),
                         #elif( defined (TARGET_K64F) && defined(SHIELD_SHD3I_INAIR9) ) /* Use pin PTC0 as fake pin */
-                        //For SHD3I with inAir9 in imod3, on FRDM-K64F board
+                        //For SHD3I with BOARD_INAIR4 in imod3, on FRDM-K64F board
                         :   SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone,
                                     D11/*MOSI*/, D12/*MISO*/, D13/*SCLK*/, D7/*CS*/, A5/*RST*/, D2/*DIO0*/, D8, D4, A4, PTC0/*FAKE!!!*/, D3/*DIO5*/ ),
                         #elif( defined (TARGET_KL25Z) && defined(SHIELD_SHD3I_INAIR9) ) /* Use pin PTD7 as fake pin - only A & D pins have interrupts */
-                        //For SHD3I with inAir9 in imod3, on FRDM-KL25Z board
+                        //For SHD3I with BOARD_INAIR4 in imod3, on FRDM-KL25Z board
                         :   SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone,
                                     D11/*MOSI*/, D12/*MISO*/, D13/*SCLK*/, D7/*CS*/, A5/*RST*/, D2/*DIO0*/, D8, D4, A4, PTD7/*FAKE!!!*/, D3/*DIO5*/ ),
                         #elif ( defined ( TARGET_NZ32ST1L ) )
-                        //For NZ32ST1L board with inAir9 in imod2
+                        //For NZ32ST1L board with BOARD_INAIR4 in imod2
                         :   SX1276( txDone, txTimeout, rxDone, rxTimeout, rxError, fhssChangeChannel, cadDone,
                                     PB_5/*MOSI*/, PB_4/*MISO*/, PB_3/*SCLK*/, PC_8/*CS*/, PA_9/*RST*/, PB_0/*DIO0*/, PB_1, PC_6, PA_10, PC_3/*FAKE!!!*/, PC_13/*DIO5*/ ),
                         #else
@@ -83,8 +84,7 @@
 {
     Reset( );
     
-    boardConnected = UNKNOWN;
-    
+    boardConnected = BOARD_UNKNOWN;
     DetectBoardType( );
     
     RxChainCalibration( );
@@ -104,35 +104,20 @@
 //-------------------------------------------------------------------------
 //                      Board relative functions
 //-------------------------------------------------------------------------
-uint8_t SX1276inAir9::DetectBoardType( void )
+uint8_t SX1276inAir::DetectBoardType( void )
 {
-//    if( boardConnected == UNKNOWN )
-//    {
-//        antSwitch.input( );
-//        wait_ms( 1 );
-//        if( antSwitch == 1 )
-//        {
-//            boardConnected = SX1276MB1LAS;
-//        }
-//        else
-//        {
-//            boardConnected = SX1276MB1MAS;
-//        }
-//        antSwitch.output( );
-//        wait_ms( 1 );
-//    }
-    boardConnected = SX1276MB1MAS;  //Use SX1276MB1MAS, it is a 14dBm output board
-    
-    return ( boardConnected );
+	//Detect board type NOT possible with inAir4, inAir9 and inAir9B boards. User has to call
+	//the SetBoardType() function to set the board type!
+	return ( boardConnected );
 }
 
-void SX1276inAir9::IoInit( void )
+void SX1276inAir::IoInit( void )
 {
     AntSwInit( );
     SpiInit( );
 }
 
-void SX1276inAir9::RadioRegistersInit( ){
+void SX1276inAir::RadioRegistersInit( ){
     uint8_t i = 0;
     for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
     {
@@ -141,12 +126,12 @@
     }    
 }
 
-void SX1276inAir9::SpiInit( void )
+void SX1276inAir::SpiInit( void )
 {
     nss = 1;    
     spi.format( 8,0 );   
     //uint32_t frequencyToSet = 8000000;
-    // TEST TEST TEST
+    // TEST TEST
     uint32_t frequencyToSet = 1000000;   //DJH - Reduced speed to 1MHz
     #if( defined ( TARGET_NUCLEO_L152RE ) || defined (TARGET_NUCLEO_F401RE) || defined ( TARGET_LPC11U6X ) || defined (TARGET_K64F) || defined ( TARGET_NZ32ST1L ) )
         spi.frequency( frequencyToSet );
@@ -158,7 +143,7 @@
     wait(0.1); 
 }
 
-void SX1276inAir9::IoIrqInit( DioIrqHandler *irqHandlers )
+void SX1276inAir::IoIrqInit( DioIrqHandler *irqHandlers )
 {
     //TARGET_KL25Z board does not have pulldown resistors, seems like TARGET_K64F does have them
     #if( defined ( TARGET_NUCLEO_L152RE )  || defined (TARGET_NUCLEO_F401RE) ||  defined ( TARGET_LPC11U6X ) || defined (TARGET_K64F) || defined ( TARGET_NZ32ST1L ))
@@ -171,7 +156,7 @@
     dio0.rise( this, static_cast< TriggerInAir > ( irqHandlers[0] ) );
     dio1.rise( this, static_cast< TriggerInAir > ( irqHandlers[1] ) );
     dio2.rise( this, static_cast< TriggerInAir > ( irqHandlers[2] ) );
-    //For SHD3I with inAir9 in imod3, on FRDM-KL25Z board. It uses A4 on FRDM-KL25Z board, which does not have interrupt
+    //For SHD3I with BOARD_INAIR4 in imod3, on FRDM-KL25Z board. It uses A4 on FRDM-KL25Z board, which does not have interrupt
     #if( defined ( TARGET_KL25Z ) && defined(SHIELD_SHD3I_INAIR9) )
     //Nothing to be done
     #else
@@ -180,31 +165,22 @@
     dio4.rise( this, static_cast< TriggerInAir > ( irqHandlers[4] ) );
 }
 
-void SX1276inAir9::IoDeInit( void )
+void SX1276inAir::IoDeInit( void )
 {
     //nothing
 }
 
-uint8_t SX1276inAir9::GetPaSelect( uint32_t channel )
+uint8_t SX1276inAir::GetPaSelect( uint32_t channel )
 {
-    if( channel > RF_MID_BAND_THRESH )
-    {
-        if( boardConnected == SX1276MB1LAS )
-        {
-            return RF_PACONFIG_PASELECT_PABOOST;
-        }
-        else
-        {
-            return RF_PACONFIG_PASELECT_RFO;
-        }
-    }
-    else
-    {
-        return RF_PACONFIG_PASELECT_RFO;
-    }
+	if(boardConnected == BOARD_INAIR9B) {
+		return RF_PACONFIG_PASELECT_PABOOST;
+	}
+	else {
+		return RF_PACONFIG_PASELECT_RFO;
+	}
 }
 
-void SX1276inAir9::SetAntSwLowPower( bool status )
+void SX1276inAir::SetAntSwLowPower( bool status )
 {
     if( isRadioActive != status )
     {
@@ -221,17 +197,17 @@
     }
 }
 
-void SX1276inAir9::AntSwInit( void )
+void SX1276inAir::AntSwInit( void )
 {
     //antSwitch = 0;
 }
 
-void SX1276inAir9::AntSwDeInit( void )
+void SX1276inAir::AntSwDeInit( void )
 {
     //antSwitch = 0;
 }
 
-void SX1276inAir9::SetAntSw( uint8_t rxTx )
+void SX1276inAir::SetAntSw( uint8_t rxTx )
 {
     if( this->rxTx == rxTx )
     {
@@ -251,14 +227,14 @@
 //    }
 }
 
-bool SX1276inAir9::CheckRfFrequency( uint32_t frequency )
+bool SX1276inAir::CheckRfFrequency( uint32_t frequency )
 {
     //TODO: Implement check, currently all frequencies are supported
     return true;
 }
 
 
-void SX1276inAir9::Reset( void )
+void SX1276inAir::Reset( void )
 {
     reset.output();
     reset = 0;
@@ -267,19 +243,19 @@
     wait_ms( 6 );
 }
     
-void SX1276inAir9::Write( uint8_t addr, uint8_t data )
+void SX1276inAir::Write( uint8_t addr, uint8_t data )
 {
     Write( addr, &data, 1 );
 }
 
-uint8_t SX1276inAir9::Read( uint8_t addr )
+uint8_t SX1276inAir::Read( uint8_t addr )
 {
     uint8_t data;
     Read( addr, &data, 1 );
     return data;
 }
 
-void SX1276inAir9::Write( uint8_t addr, uint8_t *buffer, uint8_t size )
+void SX1276inAir::Write( uint8_t addr, uint8_t *buffer, uint8_t size )
 {
     uint8_t i;
 
@@ -292,7 +268,7 @@
     nss = 1;
 }
 
-void SX1276inAir9::Read( uint8_t addr, uint8_t *buffer, uint8_t size )
+void SX1276inAir::Read( uint8_t addr, uint8_t *buffer, uint8_t size )
 {
     uint8_t i;
 
@@ -305,12 +281,12 @@
     nss = 1;
 }
 
-void SX1276inAir9::WriteFifo( uint8_t *buffer, uint8_t size )
+void SX1276inAir::WriteFifo( uint8_t *buffer, uint8_t size )
 {
     Write( 0, buffer, size );
 }
 
-void SX1276inAir9::ReadFifo( uint8_t *buffer, uint8_t size )
+void SX1276inAir::ReadFifo( uint8_t *buffer, uint8_t size )
 {
     Read( 0, buffer, size );
 }