SX1261 and sx1262 common library
Dependents: SX126xDevKit SX1262PingPong SX126X_TXonly SX126X_PingPong_Demo ... more
Fork of SX126xLib by
Diff: sx126x-hal.cpp
- Revision:
- 2:4ff11ea92fbe
- Parent:
- 1:35d34672a089
- Child:
- 3:7e3595a9ebe0
--- a/sx126x-hal.cpp Tue Sep 06 07:04:37 2016 +0000 +++ b/sx126x-hal.cpp Fri Sep 23 09:38:34 2016 +0000 @@ -36,12 +36,12 @@ */ #define WaitUartReadable( ) while( RadioUart->readable( ) == false ){ } -SX1261Hal::SX1261Hal( PinName mosi, PinName miso, PinName sclk, PinName nss, PinName busy, PinName dio1, PinName dio2, PinName dio3, PinName rst, +SX126xHal::SX126xHal( PinName mosi, PinName miso, PinName sclk, PinName nss, PinName busy, PinName dio1, PinName dio2, PinName dio3, PinName rst, void ( *txDone )( ), void ( *rxDone )( ), void ( *rxPblSyncWordHeader )( IrqPblSyncHeaderCode_t val ), void ( *rxTxTimeout )( ), void ( *rxError )( IrqErrorCode_t errorCode ), void ( *rangingDone )( IrqRangingCode_t val ), void ( *cadDone )( bool channelActivityDetected ), void ( *onDioIrq )( ) ) - : SX1261( txDone, rxDone, rxPblSyncWordHeader, rxTxTimeout, rxError, rangingDone, cadDone, onDioIrq ), + : SX126x( txDone, rxDone, rxPblSyncWordHeader, rxTxTimeout, rxError, rangingDone, cadDone, onDioIrq ), RadioNss( nss ), RadioReset( rst ), BUSY( busy ), @@ -56,12 +56,12 @@ RadioReset = 1; } -SX1261Hal::SX1261Hal( PinName tx, PinName rx, PinName busy, PinName dio1, PinName dio2, PinName dio3, PinName rst, +SX126xHal::SX126xHal( PinName tx, PinName rx, PinName busy, PinName dio1, PinName dio2, PinName dio3, PinName rst, void ( *txDone )( ), void ( *rxDone )( ), void ( *rxPblSyncWordHeader )( IrqPblSyncHeaderCode_t val ), void ( *rxTxTimeout )( ), void ( *rxError )( IrqErrorCode_t errorCode ), void ( *rangingDone )( IrqRangingCode_t val ), void ( *cadDone )( bool channelActivityDetected ), void ( *onDioIrq )( ) ) - : SX1261( txDone, rxDone, rxPblSyncWordHeader, rxTxTimeout, rxError, rangingDone, cadDone, onDioIrq ), + : SX126x( txDone, rxDone, rxPblSyncWordHeader, rxTxTimeout, rxError, rangingDone, cadDone, onDioIrq ), RadioNss( NC ), RadioReset( rst ), BUSY( busy ), @@ -74,21 +74,21 @@ RadioReset = 1; } -void SX1261Hal::SpiInit( void ) +void SX126xHal::SpiInit( void ) { RadioNss = 1; RadioSpi->format( 8, 0 ); - RadioSpi->frequency( SX1261_SPI_FREQ_DEFAULT ); + RadioSpi->frequency( SX126x_SPI_FREQ_DEFAULT ); wait( 0.1 ); } -void SX1261Hal::UartInit( void ) +void SX126xHal::UartInit( void ) { RadioUart->format( 9, SerialBase::Even, 1 ); // 8 data bits + 1 even parity bit + 1 stop bit RadioUart->baud( 115200 ); - // By default the SX1261 UART is setup to handle bytes MSB first. + // By default the SX126x UART is setup to handle bytes MSB first. // In order to setup the radio to use the UART standard way we first send // the equivalent of a WriteRegister with reversed bit order in order to // change the endianness. @@ -111,7 +111,7 @@ wait_us( 10 ); } -void SX1261Hal::IoIrqInit( DioIrqHandler irqHandler ) +void SX126xHal::IoIrqInit( DioIrqHandler irqHandler ) { assert_param( RadioSpi != 0 || RadioUart != 0 ); if( RadioSpi != NULL ) @@ -133,7 +133,7 @@ DIO3.rise( this, static_cast <Trigger>( irqHandler ) ); } -void SX1261Hal::Reset( void ) +void SX126xHal::Reset( void ) { __disable_irq( ); wait( 0.05 ); @@ -144,7 +144,7 @@ __enable_irq( ); } -void SX1261Hal::ClearInstructionRam( void ) +void SX126xHal::ClearInstructionRam( void ) { // Clearing the instruction RAM is writing 0x00s on every bytes of the // instruction RAM @@ -177,7 +177,7 @@ WaitBusy( ); } -void SX1261Hal::Wakeup( void ) +void SX126xHal::Wakeup( void ) { __disable_irq( ); @@ -214,7 +214,7 @@ __enable_irq( ); } -void SX1261Hal::WriteCommand( RadioCommands_t command, uint8_t *buffer, uint16_t size ) +void SX126xHal::WriteCommand( RadioCommands_t command, uint8_t *buffer, uint16_t size ) { WaitBusy( ); @@ -247,7 +247,7 @@ } } -void SX1261Hal::ReadCommand( RadioCommands_t command, uint8_t *buffer, uint16_t size ) +void SX126xHal::ReadCommand( RadioCommands_t command, uint8_t *buffer, uint16_t size ) { WaitBusy( ); @@ -290,7 +290,7 @@ WaitBusy( ); } -void SX1261Hal::WriteRegister( uint16_t address, uint8_t *buffer, uint16_t size ) +void SX126xHal::WriteRegister( uint16_t address, uint8_t *buffer, uint16_t size ) { WaitBusy( ); @@ -321,7 +321,7 @@ WaitBusy( ); } -void SX1261Hal::WriteRegisterNoBusy( uint16_t address, uint8_t *buffer, uint16_t size ) +void SX126xHal::WriteRegisterNoBusy( uint16_t address, uint8_t *buffer, uint16_t size ) { if( RadioSpi != NULL ) { @@ -348,17 +348,17 @@ } } -void SX1261Hal::WriteRegister( uint16_t address, uint8_t value ) +void SX126xHal::WriteRegister( uint16_t address, uint8_t value ) { WriteRegister( address, &value, 1 ); } -void SX1261Hal::WriteRegisterNoBusy( uint16_t address, uint8_t value ) +void SX126xHal::WriteRegisterNoBusy( uint16_t address, uint8_t value ) { WriteRegisterNoBusy( address, &value, 1 ); } -void SX1261Hal::ReadRegister( uint16_t address, uint8_t *buffer, uint16_t size ) +void SX126xHal::ReadRegister( uint16_t address, uint8_t *buffer, uint16_t size ) { WaitBusy( ); @@ -391,7 +391,7 @@ WaitBusy( ); } -void SX1261Hal::ReadRegisterNoBusy( uint16_t address, uint8_t *buffer, uint16_t size ) +void SX126xHal::ReadRegisterNoBusy( uint16_t address, uint8_t *buffer, uint16_t size ) { if( RadioSpi != NULL ) @@ -422,7 +422,7 @@ } -uint8_t SX1261Hal::ReadRegister( uint16_t address ) +uint8_t SX126xHal::ReadRegister( uint16_t address ) { uint8_t data; @@ -430,7 +430,7 @@ return data; } -uint8_t SX1261Hal::ReadRegisterNoBusy( uint16_t address ) +uint8_t SX126xHal::ReadRegisterNoBusy( uint16_t address ) { uint8_t data; @@ -438,7 +438,7 @@ return data; } -void SX1261Hal::WriteBuffer( uint8_t offset, uint8_t *buffer, uint8_t size ) +void SX126xHal::WriteBuffer( uint8_t offset, uint8_t *buffer, uint8_t size ) { WaitBusy( ); @@ -467,7 +467,7 @@ WaitBusy( ); } -void SX1261Hal::ReadBuffer( uint8_t offset, uint8_t *buffer, uint8_t size ) +void SX126xHal::ReadBuffer( uint8_t offset, uint8_t *buffer, uint8_t size ) { WaitBusy( ); @@ -498,7 +498,7 @@ WaitBusy( ); } -uint8_t SX1261Hal::GetDioStatus( void ) +uint8_t SX126xHal::GetDioStatus( void ) { return ( DIO3 << 3 ) | ( DIO2 << 2 ) | ( DIO1 << 1 ) | ( BUSY << 0 ); }