r g / SX1276GenericLib-us915

Dependents:   DISCO-L072CZ-LRWAN1_LoRa_PingPong

Fork of SX1276GenericLib by Helmut Tschemernjak

Files at this revision

API Documentation at this revision

Comitter:
Helmut64
Date:
Sat May 06 12:10:11 2017 +0000
Parent:
35:c278a826a8e2
Child:
37:21fa0615e993
Commit message:
Remove debug folder, added TODO file

Changed in this revision

LoRa_TODO.txt Show annotated file Show diff for this revision Revisions of this file
debug/debug.h Show diff for this revision Revisions of this file
sx1276/sx1276-hal.cpp Show diff for this revision Revisions of this file
sx1276/sx1276-hal.h Show diff for this revision Revisions of this file
sx1276/sx1276-mbed-hal.cpp Show annotated file Show diff for this revision Revisions of this file
sx1276/sx1276-mbed-hal.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LoRa_TODO.txt	Sat May 06 12:10:11 2017 +0000
@@ -0,0 +1,26 @@
+
+Tasks we needs to be done. (move finished tasks to Done: with you name & date)
+- Check of the MURATA TCXO config is correct
+- What needs to e done in the MURATA PA_BOOST case
+- Verify the Murata ANT Switch code.
+- Make the timers more generic and move the OS code into the HAL layer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Done:
+- Started a Generic SX1276 drive to support multiple SX1276 based modules (My-2017 Helmut Tsch)
--- a/debug/debug.h	Sat May 06 13:58:14 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-#if 0
-/* Copyright (c) 2012 mbed.org, MIT License
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
- 
-#ifndef DEBUG_H
-#define DEBUG_H
-
-/** @file debug.h */
-
-#ifndef NDEBUG
-
-#include <stdarg.h>
-#include <stdio.h>
-
-/** Output a debug message
- * 
- * @param format printf-style format string, followed by variables
- */
-static inline void debug(const char *format, ...) {
-    va_list args;
-    va_start(args, format);
-    vfprintf(stderr, format, args);
-    va_end(args);
-}
-
-/** Conditionally output a debug message
- * 
- * @param condition output only if condition is true
- * @param format printf-style format string, followed by variables
- */
-static inline void debug_if(bool condition, const char *format, ...) {
-    if(condition) {
-        va_list args;
-        va_start(args, format);
-        vfprintf(stderr, format, args);
-        va_end(args);
-    }
-}
-
-#else
-
-static inline void debug(const char *format, ...) {}
-static inline void debug(bool condition, const char *format, ...) {}
-
-#endif
-
-#endif
-
-#endif
\ No newline at end of file
--- a/sx1276/sx1276-hal.cpp	Sat May 06 13:58:14 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,416 +0,0 @@
-/*
- / _____)             _              | |
-( (____  _____ ____ _| |_ _____  ____| |__
- \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
-    (C) 2014 Semtech
-
-Description: -
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
-*/
-
-/*
- * additional development to make it more generic across multiple os versions
- * (c) 2017 Helmut Tschemernjak
- * 30826 Garbsen (Hannover) Germany
- */
-
-#include "sx1276-hal.h"
-
-const RadioRegisters_t SX1276Generic::RadioRegsInit[] = RADIO_INIT_REGISTERS_VALUE;
-
-SX1276Generic::SX1276Generic( RadioEvents_t *events, BoardType_t board,
-                            PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
-                            PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
-                            PinName antSwitch, PinName antSwitchTX, PinName antSwitchTXBoost, PinName tcxo)
-                            : SX1276( events)
-{
-    this->RadioEvents = events;
-    boardConnected = board;
-    
-    _antSwitch = NULL;
-    _antSwitchTX = NULL;
-    _antSwitchTXBoost = NULL;
-    
-    _tcxo = NULL;
-    if (tcxo != NC)
-        _tcxo = new DigitalOut(tcxo);
-    
-    switch(boardConnected) {
-        case SX1276MB1MAS:
-        case SX1276MB1LAS:
-            _antSwitch = new DigitalInOut(antSwitch);
-            break;
-        case RFM95_SX1276:
-            break;
-        case MURATA_SX1276:
-            _antSwitch = new DigitalInOut(antSwitch);
-            _antSwitchTX = new DigitalInOut(antSwitchTX);
-            _antSwitchTXBoost = new DigitalInOut(antSwitchTXBoost);
-            break;
-        default:
-            break;
-    }
-    _spi = new SPI(mosi, miso, sclk );
-    _nss = new DigitalOut(nss);
-    
-    _reset = new DigitalInOut(reset);
-    
-    _dio0 = NULL;
-    _dio1 = NULL;
-    _dio2 = NULL;
-    _dio3 = NULL;
-    _dio4 = NULL;
-    _dio5 = NULL;
-	if (dio0 != NC)
-        _dio0 = new InterruptIn(dio0);
-    if (dio1 != NC)
-        _dio1 = new InterruptIn(dio1);
-    if (dio2 != NC)
-        _dio2 = new InterruptIn(dio2);
-    if (dio3 != NC)
-        _dio3 = new InterruptIn(dio3);
-    if (dio4 != NC)
-        _dio4 = new InterruptIn(dio4);
-    if (dio5 != NC)
-        _dio5 = new DigitalIn(dio5);
-   
-    Reset( );
-
-    IoInit( );
-
-    RxChainCalibration( );
- 
-    SetOpMode( RF_OPMODE_SLEEP );
-
-    IoIrqInit( dioIrq );
-
-    RadioRegistersInit( );
-
-    SetModem( MODEM_FSK );
-
-    this->settings.State = RF_IDLE ;
-}
-
-SX1276Generic::~SX1276Generic()
-{
-    if (_antSwitch)
-    	delete _antSwitch;
-    if (_antSwitchTX)
-    	delete _antSwitchTX;
-    if (_antSwitchTXBoost)
-    	delete _antSwitchTXBoost;
-    
-    if (_tcxo) {
-        *_tcxo = 0;
-        delete (_tcxo);
-    }
-    delete _reset;
-    delete _spi;
-    delete _nss;
-    
-    if (_dio0)
-        delete _dio0;
-    if (_dio1)
-    	delete _dio1;
-    if (_dio2)
-        delete _dio2;
-    if (_dio3)
-        delete _dio3;
-    if (_dio4)
-    	delete _dio4;
-    if (_dio5)
-    	delete _dio5;
-}
-
-//-------------------------------------------------------------------------
-//                      Board relative functions
-//-------------------------------------------------------------------------
-uint8_t SX1276Generic::DetectBoardType( void )
-{
-    return boardConnected;
-}
-
-void SX1276Generic::IoInit( void )
-{
-    if (_tcxo)
-        *_tcxo = 1;
-    AntSwInit( );
-    SpiInit( );
-}
-
-void SX1276Generic::RadioRegistersInit( )
-{
-    uint8_t i = 0;
-    for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
-    {
-        SetModem( RadioRegsInit[i].Modem );
-        Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
-    }    
-}
-
-void SX1276Generic::SpiInit( void )
-{
-    *_nss = 1;
-    _spi->format( 8,0 );
-    uint32_t frequencyToSet = 8000000;
-#ifdef TARGET_KL25Z	//busclock frequency is halved -> double the spi frequency to compensate
-    _spi->frequency( frequencyToSet * 2 );
-#else
-    _spi->frequency( frequencyToSet );
-#endif
-    wait_ms(100);
-}
-
-void SX1276Generic::IoIrqInit( DioIrqHandler *irqHandlers )
-{
-#if( defined ( TARGET_NUCLEO_L152RE ) || defined ( TARGET_LPC11U6X ) )
-    dio0.mode( PullDown );
-    dio1.mode( PullDown );
-    dio2.mode( PullDown );
-    dio3.mode( PullDown );
-    dio4.mode( PullDown );
-#endif
-    if (_dio0)
-    	_dio0->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[0] )));
-    if (_dio1)
-    	_dio1->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[1] )));
-    if (_dio2)
-    	_dio2->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[2] )));
-    if (_dio3)
-    	_dio3->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[3] )));
-    if (_dio4)
-        _dio4->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[4] )));
-}
-
-void SX1276Generic::IoDeInit( void )
-{
-    //nothing
-}
-
-void SX1276Generic::SetRfTxPower( int8_t power )
-{
-    uint8_t paConfig = 0;
-    uint8_t paDac = 0;
-    
-    paConfig = Read( REG_PACONFIG );
-    paDac = Read( REG_PADAC );
-    
-    paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | GetPaSelect( this->settings.Channel );
-    paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70;
-    
-    if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST )
-    {
-        if( power > 17 )
-        {
-            paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON;
-        }
-        else
-        {
-            paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF;
-        }
-        if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON )
-        {
-            if( power < 5 )
-            {
-                power = 5;
-            }
-            if( power > 20 )
-            {
-                power = 20;
-            }
-            paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
-        }
-        else
-        {
-            if( power < 2 )
-            {
-                power = 2;
-            }
-            if( power > 17 )
-            {
-                power = 17;
-            }
-            paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
-        }
-    }
-    else
-    {
-        if( power < -1 )
-        {
-            power = -1;
-        }
-        if( power > 14 )
-        {
-            power = 14;
-        }
-        paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
-    }
-    Write( REG_PACONFIG, paConfig );
-    Write( REG_PADAC, paDac );
-}
-
-
-uint8_t SX1276Generic::GetPaSelect( uint32_t channel )
-{
-    if( channel > RF_MID_BAND_THRESH )
-    {
-        if( boardConnected == SX1276MB1LAS || boardConnected == RFM95_SX1276)
-        {
-            return RF_PACONFIG_PASELECT_PABOOST;
-        }
-        else
-        {
-            return RF_PACONFIG_PASELECT_RFO;
-        }
-    }
-    else
-    {
-        return RF_PACONFIG_PASELECT_RFO;
-    }
-}
-
-void SX1276Generic::SetAntSwLowPower( bool status )
-{
-    if( isRadioActive != status )
-    {
-        isRadioActive = status;
-    
-        if( status == false )
-        {
-            AntSwInit( );
-        }
-        else
-        {
-            AntSwDeInit( );
-        }
-    }
-}
-
-void SX1276Generic::AntSwInit( void )
-{
-    if (_antSwitch)
-    	*_antSwitch = 0;
-    if (boardConnected == MURATA_SX1276) {
-    	*_antSwitchTX = 0;
-		*_antSwitchTXBoost = 0;
-    }
-}
-
-void SX1276Generic::AntSwDeInit( void )
-{
-    if (_antSwitch)
-    	*_antSwitch = 0;
-    if (boardConnected == MURATA_SX1276) {
-        *_antSwitchTX = 0;
-    	*_antSwitchTXBoost = 0;
-    }
-}
-
-
-void SX1276Generic::SetAntSw( uint8_t opMode )
-{
-    switch( opMode )
-    {
-        case RFLR_OPMODE_TRANSMITTER:
-            if (boardConnected == MURATA_SX1276) {
-	            *_antSwitch = 0;// Murata-RX
-	            *_antSwitchTX = 1; 	// alternate: antSwitchTXBoost = 1
-                *_antSwitchTXBoost = 0;
-            } else {
-                if (_antSwitch)
-	        		*_antSwitch = 1;
-			}
-            break;
-        case RFLR_OPMODE_RECEIVER:
-        case RFLR_OPMODE_RECEIVER_SINGLE:
-        case RFLR_OPMODE_CAD:
-            if (boardConnected == MURATA_SX1276) {
-                *_antSwitch = 1;  // Murata-RX
-            	*_antSwitchTX = 0;
-            	*_antSwitchTXBoost = 0;
-            } else {
-                if (_antSwitch)
-        			_antSwitch = 0;
-            }
-            break;
-        default:
-            if (boardConnected == MURATA_SX1276) {
-                *_antSwitch = 0;  //Murata-RX
-            	*_antSwitchTX = 0;
-            	*_antSwitchTXBoost = 0;
-            } else {
-                if (_antSwitch)
-        			*_antSwitch = 0;
-            }
-            break;
-    }
-}
-
-bool SX1276Generic::CheckRfFrequency( uint32_t frequency )
-{
-    // Implement check. Currently all frequencies are supported
-    return true;
-}
-
-void SX1276Generic::Reset( void )
-{
-	_reset->output();
-	*_reset = 0;
-	wait_ms( 1 );
-    *_reset = 1;
-    _reset->input();	// I don't know my input again, maybe to save power (Helmut T)
-	wait_ms( 6 );
-}
-
-void SX1276Generic::Write( uint8_t addr, uint8_t data )
-{
-    Write( addr, &data, 1 );
-}
-
-uint8_t SX1276Generic::Read( uint8_t addr )
-{
-    uint8_t data;
-    Read( addr, &data, 1 );
-    return data;
-}
-
-void SX1276Generic::Write( uint8_t addr, uint8_t *buffer, uint8_t size )
-{
-    uint8_t i;
-
-    *_nss = 0; // what about SPI hold/release timing on fast MCUs? Helmut
-    _spi->write( addr | 0x80 );
-    for( i = 0; i < size; i++ )
-    {
-        _spi->write( buffer[i] );
-    }
-    *_nss = 1;
-}
-
-void SX1276Generic::Read( uint8_t addr, uint8_t *buffer, uint8_t size )
-{
-    uint8_t i;
-
-    *_nss = 0; // what about SPI hold/release timing on fast MCUs? Helmut
-    _spi->write( addr & 0x7F );
-    for( i = 0; i < size; i++ )
-    {
-        buffer[i] = _spi->write( 0 );
-    }
-    *_nss = 1;
-}
-
-void SX1276Generic::WriteFifo( uint8_t *buffer, uint8_t size )
-{
-    Write( 0, buffer, size );
-}
-
-void SX1276Generic::ReadFifo( uint8_t *buffer, uint8_t size )
-{
-    Read( 0, buffer, size );
-}
--- a/sx1276/sx1276-hal.h	Sat May 06 13:58:14 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,247 +0,0 @@
-/*
- / _____)             _              | |
-( (____  _____ ____ _| |_ _____  ____| |__
- \____ \| ___ |    (_   _) ___ |/ ___)  _ \
- _____) ) ____| | | || |_| ____( (___| | | |
-(______/|_____)_|_|_| \__)_____)\____)_| |_|
-    (C) 2014 Semtech
-
-Description: -
-
-License: Revised BSD License, see LICENSE.TXT file include in the project
-
-Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
-*/
-
-/*
- * additional development to make it more generic across multiple os versions
- * (c) 2017 Helmut Tschemernjak
- * 30826 Garbsen (Hannover) Germany
- */
-
-#ifndef __SX1276_HAL_H__
-#define __SX1276_HAL_H__
-#include "sx1276.h"
-
-/*!
- * @brief Radio hardware registers initialization definition
- *
- * @remark Can be automatically generated by the SX1276 GUI (not yet implemented)
- */
-#define RADIO_INIT_REGISTERS_VALUE                \
-{                                                 \
-    { MODEM_FSK , REG_LNA                , 0x23 },\
-    { MODEM_FSK , REG_RXCONFIG           , 0x1E },\
-    { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },\
-    { MODEM_FSK , REG_AFCFEI             , 0x01 },\
-    { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },\
-    { MODEM_FSK , REG_OSC                , 0x07 },\
-    { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },\
-    { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },\
-    { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },\
-    { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },\
-    { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },\
-    { MODEM_FSK , REG_FIFOTHRESH         , 0x8F },\
-    { MODEM_FSK , REG_IMAGECAL           , 0x02 },\
-    { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },\
-    { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },\
-    { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
-}                                                 \
-
-/*! 
- * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board
- */
-class SX1276Generic : public SX1276
-{
-protected:
-    /*!
-     * Antenna switch GPIO pins objects
-     */
-    DigitalInOut *_antSwitch;
-    DigitalInOut *_antSwitchTX;
-    DigitalInOut *_antSwitchTXBoost;
-
-    /*!
-     * SX1276 Reset pin
-     */
-    DigitalInOut *_reset;
-    
-    /*!
-     * TCXO being used with the Murata Module
-     */
-    DigitalOut *_tcxo;
-
-    /*!
-     * SPI Interface
-     */
-    SPI *_spi; // mosi, miso, sclk
-    DigitalOut *_nss;
-    
-    /*!
-     * SX1276 DIO pins
-     */
-    InterruptIn *_dio0;
-    InterruptIn *_dio1;
-    InterruptIn *_dio2;
-    InterruptIn *_dio3;
-    InterruptIn *_dio4;
-    DigitalIn *_dio5;
-    
-private:
-    static const RadioRegisters_t RadioRegsInit[];
-
-public:
-    SX1276Generic( RadioEvents_t *events, BoardType_t board,
-            PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
-            PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
-            PinName antSwitch = NC, PinName antSwitchTX= NC, PinName antSwitchTXBoost = NC, PinName tcxo = NC);
-
-    
-    SX1276Generic( RadioEvents_t *events );
-
-    virtual ~SX1276Generic();
-
-protected:
-    /*!
-     * @brief Initializes the radio I/Os pins interface
-     */
-    virtual void IoInit( void );
-
-    /*!
-     *  @brief Initializes the radio registers
-     */
-    virtual void RadioRegistersInit( );
-    
-    /*!
-     * @brief Initializes the radio SPI
-     */
-    virtual void SpiInit( void );
-
-    /*!
-     * @brief Initializes DIO IRQ handlers
-     *
-     * @param [IN] irqHandlers Array containing the IRQ callback functions
-     */
-    virtual void IoIrqInit( DioIrqHandler *irqHandlers );
-
-    /*!
-     * @brief De-initializes the radio I/Os pins interface. 
-     *
-     * \remark Useful when going in MCU lowpower modes
-     */
-    virtual void IoDeInit( void );
-
-    /*!
-     * \brief Sets the radio output power.
-     *
-     * @param [IN] power Sets the RF output power
-     */
-    virtual void SetRfTxPower( int8_t power );
-
-    /*!
-     * @brief Gets the board PA selection configuration
-     *
-     * @param [IN] channel Channel frequency in Hz
-     * @retval PaSelect RegPaConfig PaSelect value
-     */
-    virtual uint8_t GetPaSelect( uint32_t channel );
-
-    /*!
-     * @brief Set the RF Switch I/Os pins in Low Power mode
-     *
-     * @param [IN] status enable or disable
-     */
-    virtual void SetAntSwLowPower( bool status );
-
-    /*!
-     * @brief Initializes the RF Switch I/Os pins interface
-     */
-    virtual void AntSwInit( void );
-
-    /*!
-     * @brief De-initializes the RF Switch I/Os pins interface 
-     *
-     * @remark Needed to decrease the power consumption in MCU lowpower modes
-     */
-    virtual void AntSwDeInit( void );
-
-    /*!
-     * @brief Controls the antena switch if necessary.
-     *
-     * @remark see errata note
-     *
-     * @param [IN] opMode Current radio operating mode
-     */
-    virtual void SetAntSw( uint8_t opMode );
-
-public:
-    /*!
-     * @brief Detect the board connected by reading the value of the antenna switch pin
-     */
-	virtual uint8_t DetectBoardType( void );
-
-    /*!
-     * @brief Checks if the given RF frequency is supported by the hardware
-     *
-     * @param [IN] frequency RF frequency to be checked
-     * @retval isSupported [true: supported, false: unsupported]
-     */
-    virtual bool CheckRfFrequency( uint32_t frequency );
-
-    /*!
-     * @brief Writes the radio register at the specified address
-     *
-     * @param [IN]: addr Register address
-     * @param [IN]: data New register value
-     */
-    virtual void Write ( uint8_t addr, uint8_t data ) ;
-
-    /*!
-     * @brief Reads the radio register at the specified address
-     *
-     * @param [IN]: addr Register address
-     * @retval data Register value
-     */
-    virtual uint8_t Read ( uint8_t addr ) ;
-
-    /*!
-     * @brief Writes multiple radio registers starting at address
-     *
-     * @param [IN] addr   First Radio register address
-     * @param [IN] buffer Buffer containing the new register's values
-     * @param [IN] size   Number of registers to be written
-     */
-    virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
-
-    /*!
-     * @brief Reads multiple radio registers starting at address
-     *
-     * @param [IN] addr First Radio register address
-     * @param [OUT] buffer Buffer where to copy the registers data
-     * @param [IN] size Number of registers to be read
-     */
-    virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
-
-    /*!
-     * @brief Writes the buffer contents to the SX1276 FIFO
-     *
-     * @param [IN] buffer Buffer containing data to be put on the FIFO.
-     * @param [IN] size Number of bytes to be written to the FIFO
-     */
-    virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ;
-
-    /*!
-     * @brief Reads the contents of the SX1276 FIFO
-     *
-     * @param [OUT] buffer Buffer where to copy the FIFO read data.
-     * @param [IN] size Number of bytes to be read from the FIFO
-     */
-    virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ;
-
-    /*!
-     * @brief Reset the SX1276
-     */
-    virtual void Reset( void );
-};
-
-#endif // __SX1276_HAL_H__
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sx1276/sx1276-mbed-hal.cpp	Sat May 06 12:10:11 2017 +0000
@@ -0,0 +1,416 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C) 2014 Semtech
+
+Description: -
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
+*/
+
+/*
+ * additional development to make it more generic across multiple os versions
+ * (c) 2017 Helmut Tschemernjak
+ * 30826 Garbsen (Hannover) Germany
+ */
+
+#include "sx1276-mbed-hal.h"
+
+const RadioRegisters_t SX1276Generic::RadioRegsInit[] = RADIO_INIT_REGISTERS_VALUE;
+
+SX1276Generic::SX1276Generic( RadioEvents_t *events, BoardType_t board,
+                            PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
+                            PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
+                            PinName antSwitch, PinName antSwitchTX, PinName antSwitchTXBoost, PinName tcxo)
+                            : SX1276( events)
+{
+    this->RadioEvents = events;
+    boardConnected = board;
+    
+    _antSwitch = NULL;
+    _antSwitchTX = NULL;
+    _antSwitchTXBoost = NULL;
+    
+    _tcxo = NULL;
+    if (tcxo != NC)
+        _tcxo = new DigitalOut(tcxo);
+    
+    switch(boardConnected) {
+        case SX1276MB1MAS:
+        case SX1276MB1LAS:
+            _antSwitch = new DigitalInOut(antSwitch);
+            break;
+        case RFM95_SX1276:
+            break;
+        case MURATA_SX1276:
+            _antSwitch = new DigitalInOut(antSwitch);
+            _antSwitchTX = new DigitalInOut(antSwitchTX);
+            _antSwitchTXBoost = new DigitalInOut(antSwitchTXBoost);
+            break;
+        default:
+            break;
+    }
+    _spi = new SPI(mosi, miso, sclk );
+    _nss = new DigitalOut(nss);
+    
+    _reset = new DigitalInOut(reset);
+    
+    _dio0 = NULL;
+    _dio1 = NULL;
+    _dio2 = NULL;
+    _dio3 = NULL;
+    _dio4 = NULL;
+    _dio5 = NULL;
+	if (dio0 != NC)
+        _dio0 = new InterruptIn(dio0);
+    if (dio1 != NC)
+        _dio1 = new InterruptIn(dio1);
+    if (dio2 != NC)
+        _dio2 = new InterruptIn(dio2);
+    if (dio3 != NC)
+        _dio3 = new InterruptIn(dio3);
+    if (dio4 != NC)
+        _dio4 = new InterruptIn(dio4);
+    if (dio5 != NC)
+        _dio5 = new DigitalIn(dio5);
+   
+    Reset( );
+
+    IoInit( );
+
+    RxChainCalibration( );
+ 
+    SetOpMode( RF_OPMODE_SLEEP );
+
+    IoIrqInit( dioIrq );
+
+    RadioRegistersInit( );
+
+    SetModem( MODEM_FSK );
+
+    this->settings.State = RF_IDLE ;
+}
+
+SX1276Generic::~SX1276Generic()
+{
+    if (_antSwitch)
+    	delete _antSwitch;
+    if (_antSwitchTX)
+    	delete _antSwitchTX;
+    if (_antSwitchTXBoost)
+    	delete _antSwitchTXBoost;
+    
+    if (_tcxo) {
+        *_tcxo = 0;
+        delete (_tcxo);
+    }
+    delete _reset;
+    delete _spi;
+    delete _nss;
+    
+    if (_dio0)
+        delete _dio0;
+    if (_dio1)
+    	delete _dio1;
+    if (_dio2)
+        delete _dio2;
+    if (_dio3)
+        delete _dio3;
+    if (_dio4)
+    	delete _dio4;
+    if (_dio5)
+    	delete _dio5;
+}
+
+//-------------------------------------------------------------------------
+//                      Board relative functions
+//-------------------------------------------------------------------------
+uint8_t SX1276Generic::DetectBoardType( void )
+{
+    return boardConnected;
+}
+
+void SX1276Generic::IoInit( void )
+{
+    if (_tcxo)
+        *_tcxo = 1;
+    AntSwInit( );
+    SpiInit( );
+}
+
+void SX1276Generic::RadioRegistersInit( )
+{
+    uint8_t i = 0;
+    for( i = 0; i < sizeof( RadioRegsInit ) / sizeof( RadioRegisters_t ); i++ )
+    {
+        SetModem( RadioRegsInit[i].Modem );
+        Write( RadioRegsInit[i].Addr, RadioRegsInit[i].Value );
+    }    
+}
+
+void SX1276Generic::SpiInit( void )
+{
+    *_nss = 1;
+    _spi->format( 8,0 );
+    uint32_t frequencyToSet = 8000000;
+#ifdef TARGET_KL25Z	//busclock frequency is halved -> double the spi frequency to compensate
+    _spi->frequency( frequencyToSet * 2 );
+#else
+    _spi->frequency( frequencyToSet );
+#endif
+    wait_ms(100);
+}
+
+void SX1276Generic::IoIrqInit( DioIrqHandler *irqHandlers )
+{
+#if( defined ( TARGET_NUCLEO_L152RE ) || defined ( TARGET_LPC11U6X ) )
+    dio0.mode( PullDown );
+    dio1.mode( PullDown );
+    dio2.mode( PullDown );
+    dio3.mode( PullDown );
+    dio4.mode( PullDown );
+#endif
+    if (_dio0)
+    	_dio0->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[0] )));
+    if (_dio1)
+    	_dio1->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[1] )));
+    if (_dio2)
+    	_dio2->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[2] )));
+    if (_dio3)
+    	_dio3->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[3] )));
+    if (_dio4)
+        _dio4->rise(callback(this, static_cast< TriggerMB1xAS > ( irqHandlers[4] )));
+}
+
+void SX1276Generic::IoDeInit( void )
+{
+    //nothing
+}
+
+void SX1276Generic::SetRfTxPower( int8_t power )
+{
+    uint8_t paConfig = 0;
+    uint8_t paDac = 0;
+    
+    paConfig = Read( REG_PACONFIG );
+    paDac = Read( REG_PADAC );
+    
+    paConfig = ( paConfig & RF_PACONFIG_PASELECT_MASK ) | GetPaSelect( this->settings.Channel );
+    paConfig = ( paConfig & RF_PACONFIG_MAX_POWER_MASK ) | 0x70;
+    
+    if( ( paConfig & RF_PACONFIG_PASELECT_PABOOST ) == RF_PACONFIG_PASELECT_PABOOST )
+    {
+        if( power > 17 )
+        {
+            paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_ON;
+        }
+        else
+        {
+            paDac = ( paDac & RF_PADAC_20DBM_MASK ) | RF_PADAC_20DBM_OFF;
+        }
+        if( ( paDac & RF_PADAC_20DBM_ON ) == RF_PADAC_20DBM_ON )
+        {
+            if( power < 5 )
+            {
+                power = 5;
+            }
+            if( power > 20 )
+            {
+                power = 20;
+            }
+            paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 5 ) & 0x0F );
+        }
+        else
+        {
+            if( power < 2 )
+            {
+                power = 2;
+            }
+            if( power > 17 )
+            {
+                power = 17;
+            }
+            paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power - 2 ) & 0x0F );
+        }
+    }
+    else
+    {
+        if( power < -1 )
+        {
+            power = -1;
+        }
+        if( power > 14 )
+        {
+            power = 14;
+        }
+        paConfig = ( paConfig & RF_PACONFIG_OUTPUTPOWER_MASK ) | ( uint8_t )( ( uint16_t )( power + 1 ) & 0x0F );
+    }
+    Write( REG_PACONFIG, paConfig );
+    Write( REG_PADAC, paDac );
+}
+
+
+uint8_t SX1276Generic::GetPaSelect( uint32_t channel )
+{
+    if( channel > RF_MID_BAND_THRESH )
+    {
+        if( boardConnected == SX1276MB1LAS || boardConnected == RFM95_SX1276)
+        {
+            return RF_PACONFIG_PASELECT_PABOOST;
+        }
+        else
+        {
+            return RF_PACONFIG_PASELECT_RFO;
+        }
+    }
+    else
+    {
+        return RF_PACONFIG_PASELECT_RFO;
+    }
+}
+
+void SX1276Generic::SetAntSwLowPower( bool status )
+{
+    if( isRadioActive != status )
+    {
+        isRadioActive = status;
+    
+        if( status == false )
+        {
+            AntSwInit( );
+        }
+        else
+        {
+            AntSwDeInit( );
+        }
+    }
+}
+
+void SX1276Generic::AntSwInit( void )
+{
+    if (_antSwitch)
+    	*_antSwitch = 0;
+    if (boardConnected == MURATA_SX1276) {
+    	*_antSwitchTX = 0;
+		*_antSwitchTXBoost = 0;
+    }
+}
+
+void SX1276Generic::AntSwDeInit( void )
+{
+    if (_antSwitch)
+    	*_antSwitch = 0;
+    if (boardConnected == MURATA_SX1276) {
+        *_antSwitchTX = 0;
+    	*_antSwitchTXBoost = 0;
+    }
+}
+
+
+void SX1276Generic::SetAntSw( uint8_t opMode )
+{
+    switch( opMode )
+    {
+        case RFLR_OPMODE_TRANSMITTER:
+            if (boardConnected == MURATA_SX1276) {
+	            *_antSwitch = 0;// Murata-RX
+	            *_antSwitchTX = 1; 	// alternate: antSwitchTXBoost = 1
+                *_antSwitchTXBoost = 0;
+            } else {
+                if (_antSwitch)
+	        		*_antSwitch = 1;
+			}
+            break;
+        case RFLR_OPMODE_RECEIVER:
+        case RFLR_OPMODE_RECEIVER_SINGLE:
+        case RFLR_OPMODE_CAD:
+            if (boardConnected == MURATA_SX1276) {
+                *_antSwitch = 1;  // Murata-RX
+            	*_antSwitchTX = 0;
+            	*_antSwitchTXBoost = 0;
+            } else {
+                if (_antSwitch)
+        			_antSwitch = 0;
+            }
+            break;
+        default:
+            if (boardConnected == MURATA_SX1276) {
+                *_antSwitch = 0;  //Murata-RX
+            	*_antSwitchTX = 0;
+            	*_antSwitchTXBoost = 0;
+            } else {
+                if (_antSwitch)
+        			*_antSwitch = 0;
+            }
+            break;
+    }
+}
+
+bool SX1276Generic::CheckRfFrequency( uint32_t frequency )
+{
+    // Implement check. Currently all frequencies are supported
+    return true;
+}
+
+void SX1276Generic::Reset( void )
+{
+	_reset->output();
+	*_reset = 0;
+	wait_ms( 1 );
+    *_reset = 1;
+    _reset->input();	// I don't know my input again, maybe to save power (Helmut T)
+	wait_ms( 6 );
+}
+
+void SX1276Generic::Write( uint8_t addr, uint8_t data )
+{
+    Write( addr, &data, 1 );
+}
+
+uint8_t SX1276Generic::Read( uint8_t addr )
+{
+    uint8_t data;
+    Read( addr, &data, 1 );
+    return data;
+}
+
+void SX1276Generic::Write( uint8_t addr, uint8_t *buffer, uint8_t size )
+{
+    uint8_t i;
+
+    *_nss = 0; // what about SPI hold/release timing on fast MCUs? Helmut
+    _spi->write( addr | 0x80 );
+    for( i = 0; i < size; i++ )
+    {
+        _spi->write( buffer[i] );
+    }
+    *_nss = 1;
+}
+
+void SX1276Generic::Read( uint8_t addr, uint8_t *buffer, uint8_t size )
+{
+    uint8_t i;
+
+    *_nss = 0; // what about SPI hold/release timing on fast MCUs? Helmut
+    _spi->write( addr & 0x7F );
+    for( i = 0; i < size; i++ )
+    {
+        buffer[i] = _spi->write( 0 );
+    }
+    *_nss = 1;
+}
+
+void SX1276Generic::WriteFifo( uint8_t *buffer, uint8_t size )
+{
+    Write( 0, buffer, size );
+}
+
+void SX1276Generic::ReadFifo( uint8_t *buffer, uint8_t size )
+{
+    Read( 0, buffer, size );
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sx1276/sx1276-mbed-hal.h	Sat May 06 12:10:11 2017 +0000
@@ -0,0 +1,247 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    (C) 2014 Semtech
+
+Description: -
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
+*/
+
+/*
+ * additional development to make it more generic across multiple os versions
+ * (c) 2017 Helmut Tschemernjak
+ * 30826 Garbsen (Hannover) Germany
+ */
+
+#ifndef __SX1276_HAL_H__
+#define __SX1276_HAL_H__
+#include "sx1276.h"
+
+/*!
+ * @brief Radio hardware registers initialization definition
+ *
+ * @remark Can be automatically generated by the SX1276 GUI (not yet implemented)
+ */
+#define RADIO_INIT_REGISTERS_VALUE                \
+{                                                 \
+    { MODEM_FSK , REG_LNA                , 0x23 },\
+    { MODEM_FSK , REG_RXCONFIG           , 0x1E },\
+    { MODEM_FSK , REG_RSSICONFIG         , 0xD2 },\
+    { MODEM_FSK , REG_AFCFEI             , 0x01 },\
+    { MODEM_FSK , REG_PREAMBLEDETECT     , 0xAA },\
+    { MODEM_FSK , REG_OSC                , 0x07 },\
+    { MODEM_FSK , REG_SYNCCONFIG         , 0x12 },\
+    { MODEM_FSK , REG_SYNCVALUE1         , 0xC1 },\
+    { MODEM_FSK , REG_SYNCVALUE2         , 0x94 },\
+    { MODEM_FSK , REG_SYNCVALUE3         , 0xC1 },\
+    { MODEM_FSK , REG_PACKETCONFIG1      , 0xD8 },\
+    { MODEM_FSK , REG_FIFOTHRESH         , 0x8F },\
+    { MODEM_FSK , REG_IMAGECAL           , 0x02 },\
+    { MODEM_FSK , REG_DIOMAPPING1        , 0x00 },\
+    { MODEM_FSK , REG_DIOMAPPING2        , 0x30 },\
+    { MODEM_LORA, REG_LR_PAYLOADMAXLENGTH, 0x40 },\
+}                                                 \
+
+/*! 
+ * Actual implementation of a SX1276 radio, includes some modifications to make it compatible with the MB1 LAS board
+ */
+class SX1276Generic : public SX1276
+{
+protected:
+    /*!
+     * Antenna switch GPIO pins objects
+     */
+    DigitalInOut *_antSwitch;
+    DigitalInOut *_antSwitchTX;
+    DigitalInOut *_antSwitchTXBoost;
+
+    /*!
+     * SX1276 Reset pin
+     */
+    DigitalInOut *_reset;
+    
+    /*!
+     * TCXO being used with the Murata Module
+     */
+    DigitalOut *_tcxo;
+
+    /*!
+     * SPI Interface
+     */
+    SPI *_spi; // mosi, miso, sclk
+    DigitalOut *_nss;
+    
+    /*!
+     * SX1276 DIO pins
+     */
+    InterruptIn *_dio0;
+    InterruptIn *_dio1;
+    InterruptIn *_dio2;
+    InterruptIn *_dio3;
+    InterruptIn *_dio4;
+    DigitalIn *_dio5;
+    
+private:
+    static const RadioRegisters_t RadioRegsInit[];
+
+public:
+    SX1276Generic( RadioEvents_t *events, BoardType_t board,
+            PinName mosi, PinName miso, PinName sclk, PinName nss, PinName reset,
+            PinName dio0, PinName dio1, PinName dio2, PinName dio3, PinName dio4, PinName dio5,
+            PinName antSwitch = NC, PinName antSwitchTX= NC, PinName antSwitchTXBoost = NC, PinName tcxo = NC);
+
+    
+    SX1276Generic( RadioEvents_t *events );
+
+    virtual ~SX1276Generic();
+
+protected:
+    /*!
+     * @brief Initializes the radio I/Os pins interface
+     */
+    virtual void IoInit( void );
+
+    /*!
+     *  @brief Initializes the radio registers
+     */
+    virtual void RadioRegistersInit( );
+    
+    /*!
+     * @brief Initializes the radio SPI
+     */
+    virtual void SpiInit( void );
+
+    /*!
+     * @brief Initializes DIO IRQ handlers
+     *
+     * @param [IN] irqHandlers Array containing the IRQ callback functions
+     */
+    virtual void IoIrqInit( DioIrqHandler *irqHandlers );
+
+    /*!
+     * @brief De-initializes the radio I/Os pins interface. 
+     *
+     * \remark Useful when going in MCU lowpower modes
+     */
+    virtual void IoDeInit( void );
+
+    /*!
+     * \brief Sets the radio output power.
+     *
+     * @param [IN] power Sets the RF output power
+     */
+    virtual void SetRfTxPower( int8_t power );
+
+    /*!
+     * @brief Gets the board PA selection configuration
+     *
+     * @param [IN] channel Channel frequency in Hz
+     * @retval PaSelect RegPaConfig PaSelect value
+     */
+    virtual uint8_t GetPaSelect( uint32_t channel );
+
+    /*!
+     * @brief Set the RF Switch I/Os pins in Low Power mode
+     *
+     * @param [IN] status enable or disable
+     */
+    virtual void SetAntSwLowPower( bool status );
+
+    /*!
+     * @brief Initializes the RF Switch I/Os pins interface
+     */
+    virtual void AntSwInit( void );
+
+    /*!
+     * @brief De-initializes the RF Switch I/Os pins interface 
+     *
+     * @remark Needed to decrease the power consumption in MCU lowpower modes
+     */
+    virtual void AntSwDeInit( void );
+
+    /*!
+     * @brief Controls the antena switch if necessary.
+     *
+     * @remark see errata note
+     *
+     * @param [IN] opMode Current radio operating mode
+     */
+    virtual void SetAntSw( uint8_t opMode );
+
+public:
+    /*!
+     * @brief Detect the board connected by reading the value of the antenna switch pin
+     */
+	virtual uint8_t DetectBoardType( void );
+
+    /*!
+     * @brief Checks if the given RF frequency is supported by the hardware
+     *
+     * @param [IN] frequency RF frequency to be checked
+     * @retval isSupported [true: supported, false: unsupported]
+     */
+    virtual bool CheckRfFrequency( uint32_t frequency );
+
+    /*!
+     * @brief Writes the radio register at the specified address
+     *
+     * @param [IN]: addr Register address
+     * @param [IN]: data New register value
+     */
+    virtual void Write ( uint8_t addr, uint8_t data ) ;
+
+    /*!
+     * @brief Reads the radio register at the specified address
+     *
+     * @param [IN]: addr Register address
+     * @retval data Register value
+     */
+    virtual uint8_t Read ( uint8_t addr ) ;
+
+    /*!
+     * @brief Writes multiple radio registers starting at address
+     *
+     * @param [IN] addr   First Radio register address
+     * @param [IN] buffer Buffer containing the new register's values
+     * @param [IN] size   Number of registers to be written
+     */
+    virtual void Write( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
+
+    /*!
+     * @brief Reads multiple radio registers starting at address
+     *
+     * @param [IN] addr First Radio register address
+     * @param [OUT] buffer Buffer where to copy the registers data
+     * @param [IN] size Number of registers to be read
+     */
+    virtual void Read ( uint8_t addr, uint8_t *buffer, uint8_t size ) ;
+
+    /*!
+     * @brief Writes the buffer contents to the SX1276 FIFO
+     *
+     * @param [IN] buffer Buffer containing data to be put on the FIFO.
+     * @param [IN] size Number of bytes to be written to the FIFO
+     */
+    virtual void WriteFifo( uint8_t *buffer, uint8_t size ) ;
+
+    /*!
+     * @brief Reads the contents of the SX1276 FIFO
+     *
+     * @param [OUT] buffer Buffer where to copy the FIFO read data.
+     * @param [IN] size Number of bytes to be read from the FIFO
+     */
+    virtual void ReadFifo( uint8_t *buffer, uint8_t size ) ;
+
+    /*!
+     * @brief Reset the SX1276
+     */
+    virtual void Reset( void );
+};
+
+#endif // __SX1276_HAL_H__