Update RadioLib
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
#include "ArduinoHal.h"
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
|
||||
ArduinoHal::ArduinoHal(): RadioLibHal(INPUT, OUTPUT, LOW, HIGH, RISING, FALLING), spi(&RADIOLIB_DEFAULT_SPI), initInterface(true) {}
|
||||
|
||||
ArduinoHal::ArduinoHal(SPIClass& spi, SPISettings spiSettings): RadioLibHal(INPUT, OUTPUT, LOW, HIGH, RISING, FALLING), spi(&spi), spiSettings(spiSettings) {}
|
||||
|
||||
void ArduinoHal::init() {
|
||||
if(initInterface) {
|
||||
spiBegin();
|
||||
}
|
||||
}
|
||||
|
||||
void ArduinoHal::term() {
|
||||
if(initInterface) {
|
||||
spiEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void inline ArduinoHal::pinMode(uint32_t pin, uint32_t mode) {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::pinMode(pin, RADIOLIB_ARDUINOHAL_PIN_MODE_CAST mode);
|
||||
}
|
||||
|
||||
void inline ArduinoHal::digitalWrite(uint32_t pin, uint32_t value) {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::digitalWrite(pin, RADIOLIB_ARDUINOHAL_PIN_STATUS_CAST value);
|
||||
}
|
||||
|
||||
uint32_t inline ArduinoHal::digitalRead(uint32_t pin) {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return 0;
|
||||
}
|
||||
return(::digitalRead(pin));
|
||||
}
|
||||
|
||||
void inline ArduinoHal::attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) {
|
||||
if(interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::attachInterrupt(interruptNum, interruptCb, RADIOLIB_ARDUINOHAL_INTERRUPT_MODE_CAST mode);
|
||||
}
|
||||
|
||||
void inline ArduinoHal::detachInterrupt(uint32_t interruptNum) {
|
||||
if(interruptNum == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::detachInterrupt(interruptNum);
|
||||
}
|
||||
|
||||
void inline ArduinoHal::delay(RadioLibTime_t ms) {
|
||||
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
|
||||
::delay(ms);
|
||||
#else
|
||||
::delay(ms * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS));
|
||||
#endif
|
||||
}
|
||||
|
||||
void inline ArduinoHal::delayMicroseconds(RadioLibTime_t us) {
|
||||
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
|
||||
::delayMicroseconds(us);
|
||||
#else
|
||||
::delayMicroseconds(us * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS));
|
||||
#endif
|
||||
}
|
||||
|
||||
RadioLibTime_t inline ArduinoHal::millis() {
|
||||
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
|
||||
return(::millis());
|
||||
#else
|
||||
return(::millis() * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS));
|
||||
#endif
|
||||
}
|
||||
|
||||
RadioLibTime_t inline ArduinoHal::micros() {
|
||||
#if !defined(RADIOLIB_CLOCK_DRIFT_MS)
|
||||
return(::micros());
|
||||
#else
|
||||
return(::micros() * 1000 / (1000 + RADIOLIB_CLOCK_DRIFT_MS));
|
||||
#endif
|
||||
}
|
||||
|
||||
long inline ArduinoHal::pulseIn(uint32_t pin, uint32_t state, RadioLibTime_t timeout) {
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return 0;
|
||||
}
|
||||
return(::pulseIn(pin, state, timeout));
|
||||
}
|
||||
|
||||
void inline ArduinoHal::spiBegin() {
|
||||
spi->begin();
|
||||
}
|
||||
|
||||
void inline ArduinoHal::spiBeginTransaction() {
|
||||
spi->beginTransaction(spiSettings);
|
||||
}
|
||||
|
||||
void ArduinoHal::spiTransfer(uint8_t* out, size_t len, uint8_t* in) {
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
in[i] = spi->transfer(out[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void inline ArduinoHal::spiEndTransaction() {
|
||||
spi->endTransaction();
|
||||
}
|
||||
|
||||
void inline ArduinoHal::spiEnd() {
|
||||
spi->end();
|
||||
}
|
||||
|
||||
void inline ArduinoHal::tone(uint32_t pin, unsigned int frequency, RadioLibTime_t duration) {
|
||||
#if !defined(RADIOLIB_TONE_UNSUPPORTED)
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::tone(pin, frequency, duration);
|
||||
#elif defined(RADIOLIB_ESP32)
|
||||
// ESP32 tone() emulation
|
||||
(void)duration;
|
||||
if(prev == -1) {
|
||||
#if !defined(ESP_IDF_VERSION) || (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0))
|
||||
ledcAttachPin(pin, RADIOLIB_TONE_ESP32_CHANNEL);
|
||||
#else
|
||||
ledcAttach(pin, frequency, 14); // 14-bit resolution should be enough
|
||||
#endif
|
||||
}
|
||||
if(prev != frequency) {
|
||||
#if !defined(ESP_IDF_VERSION) || (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0))
|
||||
ledcWriteTone(RADIOLIB_TONE_ESP32_CHANNEL, frequency);
|
||||
#else
|
||||
ledcWriteTone(pin, frequency);
|
||||
#endif
|
||||
}
|
||||
prev = frequency;
|
||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
// better tone for mbed OS boards
|
||||
(void)duration;
|
||||
if(!pwmPin) {
|
||||
pwmPin = new mbed::PwmOut(digitalPinToPinName(pin));
|
||||
}
|
||||
pwmPin->period(1.0 / frequency);
|
||||
pwmPin->write(0.5);
|
||||
#else
|
||||
(void)pin;
|
||||
(void)frequency;
|
||||
(void)duration;
|
||||
#endif
|
||||
}
|
||||
|
||||
void inline ArduinoHal::noTone(uint32_t pin) {
|
||||
#if !defined(RADIOLIB_TONE_UNSUPPORTED) and defined(ARDUINO_ARCH_STM32)
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::noTone(pin, false);
|
||||
#elif !defined(RADIOLIB_TONE_UNSUPPORTED)
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
::noTone(pin);
|
||||
#elif defined(RADIOLIB_ESP32)
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
// ESP32 tone() emulation
|
||||
#if !defined(ESP_IDF_VERSION) || (ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5,0,0))
|
||||
ledcDetachPin(pin);
|
||||
ledcWrite(RADIOLIB_TONE_ESP32_CHANNEL, 0);
|
||||
#else
|
||||
ledcDetach(pin);
|
||||
ledcWrite(pin, 0);
|
||||
#endif
|
||||
prev = -1;
|
||||
#elif defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
if(pin == RADIOLIB_NC) {
|
||||
return;
|
||||
}
|
||||
// better tone for mbed OS boards
|
||||
(void)pin;
|
||||
pwmPin->suspend();
|
||||
#else
|
||||
(void)pin;
|
||||
#endif
|
||||
}
|
||||
|
||||
void inline ArduinoHal::yield() {
|
||||
#if !defined(RADIOLIB_YIELD_UNSUPPORTED)
|
||||
::yield();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t inline ArduinoHal::pinToInterrupt(uint32_t pin) {
|
||||
return(digitalPinToInterrupt(pin));
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
// make sure this is always compiled
|
||||
#include "TypeDef.h"
|
||||
|
||||
#if !defined(_RADIOLIB_ARDUINOHAL_H)
|
||||
#define _RADIOLIB_ARDUINOHAL_H
|
||||
|
||||
// this file only makes sense for Arduino builds
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
|
||||
#if defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
#include "mbed.h"
|
||||
#endif
|
||||
|
||||
#include "Hal.h"
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
/*!
|
||||
\class ArduinoHal
|
||||
\brief Arduino default hardware abstraction library implementation.
|
||||
This class can be extended to support other Arduino platform or change behaviour of the default implementation.
|
||||
*/
|
||||
class ArduinoHal : public RadioLibHal {
|
||||
public:
|
||||
/*!
|
||||
\brief Arduino Hal constructor. Will use the default SPI interface and automatically initialize it.
|
||||
*/
|
||||
ArduinoHal();
|
||||
|
||||
/*!
|
||||
\brief Arduino Hal constructor. Will not attempt SPI interface initialization.
|
||||
\param spi SPI interface to be used, can also use software SPI implementations.
|
||||
\param spiSettings SPI interface settings.
|
||||
*/
|
||||
explicit ArduinoHal(SPIClass& spi, SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS);
|
||||
|
||||
// implementations of pure virtual RadioLibHal methods
|
||||
void pinMode(uint32_t pin, uint32_t mode) override;
|
||||
void digitalWrite(uint32_t pin, uint32_t value) override;
|
||||
uint32_t digitalRead(uint32_t pin) override;
|
||||
void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) override;
|
||||
void detachInterrupt(uint32_t interruptNum) override;
|
||||
void delay(RadioLibTime_t ms) override;
|
||||
void delayMicroseconds(RadioLibTime_t us) override;
|
||||
RadioLibTime_t millis() override;
|
||||
RadioLibTime_t micros() override;
|
||||
long pulseIn(uint32_t pin, uint32_t state, RadioLibTime_t timeout) override;
|
||||
void spiBegin() override;
|
||||
void spiBeginTransaction() override;
|
||||
void spiTransfer(uint8_t* out, size_t len, uint8_t* in) override;
|
||||
void spiEndTransaction() override;
|
||||
void spiEnd() override;
|
||||
|
||||
// implementations of virtual RadioLibHal methods
|
||||
void init() override;
|
||||
void term() override;
|
||||
void tone(uint32_t pin, unsigned int frequency, RadioLibTime_t duration = 0) override;
|
||||
void noTone(uint32_t pin) override;
|
||||
void yield() override;
|
||||
uint32_t pinToInterrupt(uint32_t pin) override;
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
SPIClass* spi = NULL;
|
||||
SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS;
|
||||
bool initInterface = false;
|
||||
|
||||
#if defined(RADIOLIB_MBED_TONE_OVERRIDE)
|
||||
mbed::PwmOut *pwmPin = NULL;
|
||||
#endif
|
||||
|
||||
#if defined(RADIOLIB_ESP32)
|
||||
int32_t prev = -1;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+494
-953
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
#if !defined(_RADIOLIB_USER_BUILD_OPTIONS_H)
|
||||
#define _RADIOLIB_USER_BUILD_OPTIONS_H
|
||||
|
||||
// this file can be used to define any user build options
|
||||
// most commonly, RADIOLIB_EXCLUDE_* macros
|
||||
// or enabling debug output
|
||||
|
||||
//#define RADIOLIB_DEBUG_BASIC (1) // basic debugging (e.g. reporting GPIO timeouts or module not being found)
|
||||
//#define RADIOLIB_DEBUG_PROTOCOL (1) // protocol information (e.g. LoRaWAN internal information)
|
||||
//#define RADIOLIB_DEBUG_SPI (1) // verbose transcription of all SPI communication - produces large debug logs!
|
||||
//#define RADIOLIB_VERBOSE_ASSERT (1) // verbose assertions - will print out file and line number on failure
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "Hal.h"
|
||||
|
||||
RadioLibHal::RadioLibHal(const uint32_t input, const uint32_t output, const uint32_t low, const uint32_t high, const uint32_t rising, const uint32_t falling)
|
||||
: GpioModeInput(input),
|
||||
GpioModeOutput(output),
|
||||
GpioLevelLow(low),
|
||||
GpioLevelHigh(high),
|
||||
GpioInterruptRising(rising),
|
||||
GpioInterruptFalling(falling) {}
|
||||
|
||||
void RadioLibHal::init() {
|
||||
|
||||
}
|
||||
|
||||
void RadioLibHal::term() {
|
||||
|
||||
}
|
||||
|
||||
void RadioLibHal::tone(uint32_t pin, unsigned int frequency, RadioLibTime_t duration) {
|
||||
(void)pin;
|
||||
(void)frequency;
|
||||
(void)duration;
|
||||
}
|
||||
|
||||
void RadioLibHal::noTone(uint32_t pin) {
|
||||
(void)pin;
|
||||
}
|
||||
|
||||
void RadioLibHal::yield() {
|
||||
|
||||
}
|
||||
|
||||
uint32_t RadioLibHal::pinToInterrupt(uint32_t pin) {
|
||||
return(pin);
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
#if !defined(_RADIOLIB_HAL_H)
|
||||
#define _RADIOLIB_HAL_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "BuildOpt.h"
|
||||
|
||||
/*!
|
||||
\class RadioLibHal
|
||||
\brief Hardware abstraction library base interface.
|
||||
*/
|
||||
class RadioLibHal {
|
||||
public:
|
||||
|
||||
// values for pin modes, levels and change directions
|
||||
// these tell RadioLib how are different logic states represented on a given platform
|
||||
|
||||
/*!
|
||||
\brief Value to be used as the "input" GPIO direction.
|
||||
*/
|
||||
const uint32_t GpioModeInput;
|
||||
|
||||
/*!
|
||||
\brief Value to be used as the "output" GPIO direction.
|
||||
*/
|
||||
const uint32_t GpioModeOutput;
|
||||
|
||||
/*!
|
||||
\brief Value to be used as the "low" GPIO level.
|
||||
*/
|
||||
const uint32_t GpioLevelLow;
|
||||
|
||||
/*!
|
||||
\brief Value to be used as the "high" GPIO level.
|
||||
*/
|
||||
const uint32_t GpioLevelHigh;
|
||||
|
||||
/*!
|
||||
\brief Value to be used as the "rising" GPIO level change direction.
|
||||
*/
|
||||
const uint32_t GpioInterruptRising;
|
||||
|
||||
/*!
|
||||
\brief Value to be used as the "falling" GPIO level change direction.
|
||||
*/
|
||||
const uint32_t GpioInterruptFalling;
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param input Value to be used as the "input" GPIO direction.
|
||||
\param output Value to be used as the "output" GPIO direction.
|
||||
\param low Value to be used as the "low" GPIO level.
|
||||
\param high Value to be used as the "high" GPIO level.
|
||||
\param rising Value to be used as the "rising" GPIO level change direction.
|
||||
\param falling Value to be used as the "falling" GPIO level change direction.
|
||||
*/
|
||||
RadioLibHal(const uint32_t input, const uint32_t output, const uint32_t low, const uint32_t high, const uint32_t rising, const uint32_t falling);
|
||||
|
||||
// pure virtual methods - these must be implemented by the hardware abstraction for RadioLib to function
|
||||
|
||||
/*!
|
||||
\brief GPIO pin mode (input/output/...) configuration method.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\param pin Pin to be changed (platform-specific).
|
||||
\param mode Mode to be set (platform-specific).
|
||||
*/
|
||||
virtual void pinMode(uint32_t pin, uint32_t mode) = 0;
|
||||
|
||||
/*!
|
||||
\brief Digital write method.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\param pin Pin to be changed (platform-specific).
|
||||
\param value Value to set (platform-specific).
|
||||
*/
|
||||
virtual void digitalWrite(uint32_t pin, uint32_t value) = 0;
|
||||
|
||||
/*!
|
||||
\brief Digital read method.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\param pin Pin to be changed (platform-specific).
|
||||
\returns Value read on the pin (platform-specific).
|
||||
*/
|
||||
virtual uint32_t digitalRead(uint32_t pin) = 0;
|
||||
|
||||
/*!
|
||||
\brief Method to attach function to an external interrupt.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\param interruptNum Interrupt number to attach to (platform-specific).
|
||||
\param interruptCb Interrupt service routine to execute.
|
||||
\param mode Rising/falling mode (platform-specific).
|
||||
*/
|
||||
virtual void attachInterrupt(uint32_t interruptNum, void (*interruptCb)(void), uint32_t mode) = 0;
|
||||
|
||||
/*!
|
||||
\brief Method to detach function from an external interrupt.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\param interruptNum Interrupt number to detach from (platform-specific).
|
||||
*/
|
||||
virtual void detachInterrupt(uint32_t interruptNum) = 0;
|
||||
|
||||
/*!
|
||||
\brief Blocking wait function.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\param ms Number of milliseconds to wait.
|
||||
*/
|
||||
virtual void delay(RadioLibTime_t ms) = 0;
|
||||
|
||||
/*!
|
||||
\brief Blocking microsecond wait function.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\param us Number of microseconds to wait.
|
||||
*/
|
||||
virtual void delayMicroseconds(RadioLibTime_t us) = 0;
|
||||
|
||||
/*!
|
||||
\brief Get number of milliseconds since start.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\returns Number of milliseconds since start.
|
||||
*/
|
||||
virtual RadioLibTime_t millis() = 0;
|
||||
|
||||
/*!
|
||||
\brief Get number of microseconds since start.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\returns Number of microseconds since start.
|
||||
*/
|
||||
virtual RadioLibTime_t micros() = 0;
|
||||
|
||||
/*!
|
||||
\brief Measure the length of incoming digital pulse in microseconds.
|
||||
Must be implemented by the platform-specific hardware abstraction!
|
||||
\param pin Pin to measure on (platform-specific).
|
||||
\param state Pin level to monitor (platform-specific).
|
||||
\param timeout Timeout in microseconds.
|
||||
\returns Pulse length in microseconds, or 0 if the pulse did not start before timeout.
|
||||
*/
|
||||
virtual long pulseIn(uint32_t pin, uint32_t state, RadioLibTime_t timeout) = 0;
|
||||
|
||||
/*!
|
||||
\brief SPI initialization method.
|
||||
*/
|
||||
virtual void spiBegin() = 0;
|
||||
|
||||
/*!
|
||||
\brief Method to start SPI transaction.
|
||||
*/
|
||||
virtual void spiBeginTransaction() = 0;
|
||||
|
||||
/*!
|
||||
\brief Method to transfer buffer over SPI.
|
||||
\param out Buffer to send.
|
||||
\param len Number of data to send or receive.
|
||||
\param in Buffer to save received data into.
|
||||
*/
|
||||
virtual void spiTransfer(uint8_t* out, size_t len, uint8_t* in) = 0;
|
||||
|
||||
/*!
|
||||
\brief Method to end SPI transaction.
|
||||
*/
|
||||
virtual void spiEndTransaction() = 0;
|
||||
|
||||
/*!
|
||||
\brief SPI termination method.
|
||||
*/
|
||||
virtual void spiEnd() = 0;
|
||||
|
||||
// virtual methods - these may or may not exists on a given platform
|
||||
// they exist in this implementation, but do nothing
|
||||
|
||||
/*!
|
||||
\brief Module initialization method.
|
||||
This will be called by all radio modules at the beginning of startup.
|
||||
Can be used to e.g., initialize SPI interface.
|
||||
*/
|
||||
virtual void init();
|
||||
|
||||
/*!
|
||||
\brief Module termination method.
|
||||
This will be called by all radio modules when the destructor is called.
|
||||
Can be used to e.g., stop SPI interface.
|
||||
*/
|
||||
virtual void term();
|
||||
|
||||
/*!
|
||||
\brief Method to produce a square-wave with 50% duty cycle ("tone") of a given frequency at some pin.
|
||||
\param pin Pin to be used as the output.
|
||||
\param frequency Frequency of the square wave.
|
||||
\param duration Duration of the tone in ms. When set to 0, the tone will be infinite.
|
||||
*/
|
||||
virtual void tone(uint32_t pin, unsigned int frequency, RadioLibTime_t duration = 0);
|
||||
|
||||
/*!
|
||||
\brief Method to stop producing a tone.
|
||||
\param pin Pin which is currently producing the tone.
|
||||
*/
|
||||
virtual void noTone(uint32_t pin);
|
||||
|
||||
/*!
|
||||
\brief Yield method, called from long loops in multi-threaded environment (to prevent blocking other threads).
|
||||
*/
|
||||
virtual void yield();
|
||||
|
||||
/*!
|
||||
\brief Function to convert from pin number to interrupt number.
|
||||
\param pin Pin to convert from.
|
||||
\returns The interrupt number of a given pin.
|
||||
*/
|
||||
virtual uint32_t pinToInterrupt(uint32_t pin);
|
||||
};
|
||||
|
||||
#endif
|
||||
+497
-436
File diff suppressed because it is too large
Load Diff
+376
-273
@@ -2,94 +2,236 @@
|
||||
#define _RADIOLIB_MODULE_H
|
||||
|
||||
#include "TypeDef.h"
|
||||
#include "Hal.h"
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
#include <SPI.h>
|
||||
#endif
|
||||
|
||||
#if defined(STM32WLxx)
|
||||
#include <SubGhz.h>
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\def END_OF_MODE_TABLE Value to use as the last element in a mode table to indicate the
|
||||
end of the table. See \ref setRfSwitchTable for details.
|
||||
*/
|
||||
#define END_OF_MODE_TABLE { Module::MODE_END_OF_TABLE, {} }
|
||||
|
||||
/*!
|
||||
\defgroup module_spi_command_pos Position of commands in Module::spiConfig command array.
|
||||
\{
|
||||
*/
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_COMMAND_READ Position of the read command. */
|
||||
#define RADIOLIB_MODULE_SPI_COMMAND_READ (0)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_COMMAND_WRITE Position of the write command. */
|
||||
#define RADIOLIB_MODULE_SPI_COMMAND_WRITE (1)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_COMMAND_NOP Position of the no-operation command. */
|
||||
#define RADIOLIB_MODULE_SPI_COMMAND_NOP (2)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_COMMAND_STATUS Position of the status command. */
|
||||
#define RADIOLIB_MODULE_SPI_COMMAND_STATUS (3)
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\defgroup module_spi_width_pos Position of bit field widths in Module::spiConfig width array.
|
||||
\{
|
||||
*/
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_WIDTH_ADDR Position of the address width. */
|
||||
#define RADIOLIB_MODULE_SPI_WIDTH_ADDR (0)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_WIDTH_CMD Position of the command width. */
|
||||
#define RADIOLIB_MODULE_SPI_WIDTH_CMD (1)
|
||||
|
||||
/*! \def RADIOLIB_MODULE_SPI_WIDTH_STATUS Position of the status width. */
|
||||
#define RADIOLIB_MODULE_SPI_WIDTH_STATUS (2)
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\class Module
|
||||
|
||||
\brief Implements all common low-level methods to control the wireless module.
|
||||
Every module class contains one private instance of this class.
|
||||
*/
|
||||
class Module {
|
||||
public:
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief The maximum number of pins supported by the RF switch code.
|
||||
Note: It is not recommended to use this constant in your sketch
|
||||
when defining a rfswitch pins array, to prevent issues when this
|
||||
value is ever increased and such an array gets extra zero
|
||||
elements (that will be interpreted as pin 0).
|
||||
*/
|
||||
static const size_t RFSWITCH_MAX_PINS = 5;
|
||||
|
||||
/*!
|
||||
\brief Arduino Module constructor. Will use the default SPI interface and automatically initialize it
|
||||
\struct RfSwitchMode_t
|
||||
\brief Description of RF switch pin states for a single mode.
|
||||
See \ref setRfSwitchTable for details.
|
||||
*/
|
||||
struct RfSwitchMode_t {
|
||||
/*! \brief RF switching mode, one of \ref OpMode_t or a custom radio-defined value. */
|
||||
uint8_t mode;
|
||||
|
||||
/*! \brief Output pin values */
|
||||
uint32_t values[RFSWITCH_MAX_PINS];
|
||||
};
|
||||
|
||||
/*!
|
||||
\enum OpMode_t
|
||||
\brief Constants to use in a mode table set be setRfSwitchTable. These
|
||||
constants work for most radios, but some radios define their own
|
||||
constants to be used instead.
|
||||
|
||||
See \ref setRfSwitchTable for details.
|
||||
*/
|
||||
enum OpMode_t {
|
||||
/*!
|
||||
\brief End of table marker, use \ref END_OF_MODE_TABLE constant instead.
|
||||
Value is zero to ensure zero-initialized mode ends the table.
|
||||
*/
|
||||
MODE_END_OF_TABLE = 0,
|
||||
|
||||
/*! \brief Idle mode */
|
||||
MODE_IDLE,
|
||||
|
||||
/*! \brief Receive mode */
|
||||
MODE_RX,
|
||||
|
||||
/*! \brief Transmission mode */
|
||||
MODE_TX,
|
||||
};
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief Arduino Module constructor. Will use the default SPI interface and automatically initialize it.
|
||||
\param cs Arduino pin to be used as chip select.
|
||||
|
||||
\param irq Arduino pin to be used as interrupt/GPIO.
|
||||
|
||||
\param rst Arduino pin to be used as hardware reset for the module.
|
||||
|
||||
\param gpio Arduino pin to be used as additional interrupt/GPIO.
|
||||
*/
|
||||
Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio = RADIOLIB_NC);
|
||||
Module(uint32_t cs, uint32_t irq, uint32_t rst, uint32_t gpio = RADIOLIB_NC);
|
||||
|
||||
/*!
|
||||
\brief Arduino Module constructor. Will not attempt SPI interface initialization.
|
||||
|
||||
\param cs Arduino pin to be used as chip select.
|
||||
|
||||
\param irq Arduino pin to be used as interrupt/GPIO.
|
||||
|
||||
\param rst Arduino pin to be used as hardware reset for the module.
|
||||
|
||||
\param gpio Arduino pin to be used as additional interrupt/GPIO.
|
||||
|
||||
\param spi SPI interface to be used, can also use software SPI implementations.
|
||||
|
||||
\param spiSettings SPI interface settings.
|
||||
*/
|
||||
Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio, SPIClass& spi, SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS);
|
||||
|
||||
#else
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param cs Pin to be used as chip select.
|
||||
|
||||
\param irq Pin to be used as interrupt/GPIO.
|
||||
|
||||
\param rst Pin to be used as hardware reset for the module.
|
||||
|
||||
\param gpio Pin to be used as additional interrupt/GPIO.
|
||||
*/
|
||||
Module(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE gpio = RADIOLIB_NC);
|
||||
|
||||
Module(uint32_t cs, uint32_t irq, uint32_t rst, uint32_t gpio, SPIClass& spi, SPISettings spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Copy constructor.
|
||||
\brief Module constructor.
|
||||
\param hal A Hardware abstraction layer instance. An ArduinoHal instance for example.
|
||||
\param cs Pin to be used as chip select.
|
||||
\param irq Pin to be used as interrupt/GPIO.
|
||||
\param rst Pin to be used as hardware reset for the module.
|
||||
\param gpio Pin to be used as additional interrupt/GPIO.
|
||||
*/
|
||||
Module(RadioLibHal *hal, uint32_t cs, uint32_t irq, uint32_t rst, uint32_t gpio = RADIOLIB_NC);
|
||||
|
||||
/*!
|
||||
\brief Copy constructor.
|
||||
\param mod Module instance to copy.
|
||||
*/
|
||||
Module(const Module& mod);
|
||||
|
||||
/*!
|
||||
\brief Overload for assignment operator.
|
||||
|
||||
\param frame rvalue Module.
|
||||
\param mod rvalue Module.
|
||||
*/
|
||||
Module& operator=(const Module& mod);
|
||||
|
||||
// public member variables
|
||||
/*! \brief Hardware abstraction layer to be used. */
|
||||
RadioLibHal* hal = NULL;
|
||||
|
||||
/*! \brief Callback for parsing SPI status. */
|
||||
typedef int16_t (*SPIparseStatusCb_t)(uint8_t in);
|
||||
|
||||
/*! \brief Callback for validation SPI status. */
|
||||
typedef int16_t (*SPIcheckStatusCb_t)(Module* mod);
|
||||
|
||||
enum BitWidth_t {
|
||||
BITS_0 = 0,
|
||||
BITS_8 = 8,
|
||||
BITS_16 = 16,
|
||||
BITS_32 = 32,
|
||||
};
|
||||
|
||||
/*!
|
||||
\brief Basic SPI read command. Defaults to 0x00.
|
||||
\struct SPIConfig_t
|
||||
\brief SPI configuration structure.
|
||||
*/
|
||||
uint8_t SPIreadCommand = 0b00000000;
|
||||
struct SPIConfig_t {
|
||||
/*! \brief Whether the SPI module is stream-type (SX126x/8x) or registrer access type (SX127x, CC1101 etc). */
|
||||
bool stream;
|
||||
|
||||
/*! \brief Last recorded SPI error - only updated for modules that return status during SPI transfers. */
|
||||
int16_t err;
|
||||
|
||||
/*! \brief SPI commands */
|
||||
uint16_t cmds[4];
|
||||
|
||||
/*! \brief Bit widths of SPI addresses, commands and status bytes */
|
||||
BitWidth_t widths[3];
|
||||
|
||||
/*! \brief Byte position of status command in SPI stream */
|
||||
uint8_t statusPos;
|
||||
|
||||
/*! \brief Callback for parsing SPI status. */
|
||||
SPIparseStatusCb_t parseStatusCb;
|
||||
|
||||
/*! \brief Callback for validation SPI status. */
|
||||
SPIcheckStatusCb_t checkStatusCb;
|
||||
|
||||
/*! \brief Timeout in ms when waiting for GPIO signals. */
|
||||
RadioLibTime_t timeout;
|
||||
};
|
||||
|
||||
/*! \brief SPI configuration structure. The default configuration corresponds to register-access modules, such as SX127x. */
|
||||
SPIConfig_t spiConfig = {
|
||||
.stream = false,
|
||||
.err = RADIOLIB_ERR_UNKNOWN,
|
||||
.cmds = { 0x00, 0x80, 0x00, 0x00 },
|
||||
.widths = { Module::BITS_8, Module::BITS_0, Module::BITS_8 },
|
||||
.statusPos = 0,
|
||||
.parseStatusCb = nullptr,
|
||||
.checkStatusCb = nullptr,
|
||||
.timeout = 1000,
|
||||
};
|
||||
|
||||
#if RADIOLIB_INTERRUPT_TIMING
|
||||
|
||||
/*!
|
||||
\brief Basic SPI write command. Defaults to 0x80.
|
||||
\brief Timer interrupt setup callback typedef.
|
||||
*/
|
||||
uint8_t SPIwriteCommand = 0b10000000;
|
||||
typedef void (*TimerSetupCb_t)(uint32_t len);
|
||||
|
||||
/*!
|
||||
\brief Callback to timer interrupt setup function when running in interrupt timing control mode.
|
||||
*/
|
||||
TimerSetupCb_t TimerSetupCb = nullptr;
|
||||
|
||||
/*!
|
||||
\brief Timer flag variable to be controlled by a platform-dependent interrupt.
|
||||
*/
|
||||
volatile bool TimerFlag = false;
|
||||
|
||||
#endif
|
||||
|
||||
// basic methods
|
||||
|
||||
@@ -107,349 +249,310 @@ class Module {
|
||||
|
||||
/*!
|
||||
\brief SPI read method that automatically masks unused bits. This method is the preferred SPI read mechanism.
|
||||
|
||||
\param reg Address of SPI register to read.
|
||||
|
||||
\param msb Most significant bit of the register variable. Bits above this one will be masked out.
|
||||
|
||||
\param lsb Least significant bit of the register variable. Bits below this one will be masked out.
|
||||
|
||||
\returns Masked register value or status code.
|
||||
*/
|
||||
int16_t SPIgetRegValue(uint8_t reg, uint8_t msb = 7, uint8_t lsb = 0);
|
||||
int16_t SPIgetRegValue(uint32_t reg, uint8_t msb = 7, uint8_t lsb = 0);
|
||||
|
||||
/*!
|
||||
\brief Overwrite-safe SPI write method with verification. This method is the preferred SPI write mechanism.
|
||||
|
||||
\param reg Address of SPI register to write.
|
||||
|
||||
\param value Single byte value that will be written to the SPI register.
|
||||
|
||||
\param msb Most significant bit of the register variable. Bits above this one will not be affected by the write operation.
|
||||
|
||||
\param lsb Least significant bit of the register variable. Bits below this one will not be affected by the write operation.
|
||||
|
||||
\param checkInterval Number of milliseconds between register writing and verification reading. Some registers need up to 10ms to process the change.
|
||||
|
||||
\param checkMask Mask of bits to check, only bits set to 1 will be verified.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb = 7, uint8_t lsb = 0, uint8_t checkInterval = 2, uint8_t checkMask = 0xFF);
|
||||
int16_t SPIsetRegValue(uint32_t reg, uint8_t value, uint8_t msb = 7, uint8_t lsb = 0, uint8_t checkInterval = 2, uint8_t checkMask = 0xFF);
|
||||
|
||||
/*!
|
||||
\brief SPI burst read method.
|
||||
|
||||
\param reg Address of SPI register to read.
|
||||
|
||||
\param numBytes Number of bytes that will be read.
|
||||
|
||||
\param inBytes Pointer to array that will hold the read data.
|
||||
*/
|
||||
void SPIreadRegisterBurst(uint8_t reg, uint8_t numBytes, uint8_t* inBytes);
|
||||
void SPIreadRegisterBurst(uint32_t reg, size_t numBytes, uint8_t* inBytes);
|
||||
|
||||
/*!
|
||||
\brief SPI basic read method. Use of this method is reserved for special cases, SPIgetRegValue should be used instead.
|
||||
|
||||
\param reg Address of SPI register to read.
|
||||
|
||||
\returns Value that was read from register.
|
||||
*/
|
||||
uint8_t SPIreadRegister(uint8_t reg);
|
||||
uint8_t SPIreadRegister(uint32_t reg);
|
||||
|
||||
/*!
|
||||
\brief SPI burst write method.
|
||||
|
||||
\param reg Address of SPI register to write.
|
||||
|
||||
\param data Pointer to array that holds the data that will be written.
|
||||
|
||||
\param numBytes Number of bytes that will be written.
|
||||
*/
|
||||
void SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, uint8_t numBytes);
|
||||
void SPIwriteRegisterBurst(uint32_t reg, uint8_t* data, size_t numBytes);
|
||||
|
||||
/*!
|
||||
\brief SPI basic write method. Use of this method is reserved for special cases, SPIsetRegValue should be used instead.
|
||||
|
||||
\param reg Address of SPI register to write.
|
||||
|
||||
\param data Value that will be written to the register.
|
||||
*/
|
||||
void SPIwriteRegister(uint8_t reg, uint8_t data);
|
||||
void SPIwriteRegister(uint32_t reg, uint8_t data);
|
||||
|
||||
/*!
|
||||
\brief SPI single transfer method.
|
||||
|
||||
\param cmd SPI access command (read/write/burst/...).
|
||||
|
||||
\param reg Address of SPI register to transfer to/from.
|
||||
|
||||
\param dataOut Data that will be transfered from master to slave.
|
||||
|
||||
\param dataIn Data that was transfered from slave to master.
|
||||
|
||||
\param dataOut Data that will be transferred from master to slave.
|
||||
\param dataIn Data that was transferred from slave to master.
|
||||
\param numBytes Number of bytes to transfer.
|
||||
*/
|
||||
void SPItransfer(uint8_t cmd, uint8_t reg, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes);
|
||||
void SPItransfer(uint16_t cmd, uint32_t reg, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes);
|
||||
|
||||
/*!
|
||||
\brief Method to check the result of last SPI stream transfer.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t SPIcheckStream();
|
||||
|
||||
/*!
|
||||
\brief Method to perform a read transaction with SPI stream.
|
||||
\param cmd SPI operation command.
|
||||
\param data Data that will be transferred from slave to master.
|
||||
\param numBytes Number of bytes to transfer.
|
||||
\param waitForGpio Whether to wait for some GPIO at the end of transfer (e.g. BUSY line on SX126x/SX128x).
|
||||
\param verify Whether to verify the result of the transaction after it is finished.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t SPIreadStream(uint16_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||
|
||||
/*!
|
||||
\brief Method to perform a read transaction with SPI stream.
|
||||
\param cmd SPI operation command.
|
||||
\param cmdLen SPI command length in bytes.
|
||||
\param data Data that will be transferred from slave to master.
|
||||
\param numBytes Number of bytes to transfer.
|
||||
\param waitForGpio Whether to wait for some GPIO at the end of transfer (e.g. BUSY line on SX126x/SX128x).
|
||||
\param verify Whether to verify the result of the transaction after it is finished.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t SPIreadStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||
|
||||
/*!
|
||||
\brief Method to perform a write transaction with SPI stream.
|
||||
\param cmd SPI operation command.
|
||||
\param data Data that will be transferred from master to slave.
|
||||
\param numBytes Number of bytes to transfer.
|
||||
\param waitForGpio Whether to wait for some GPIO at the end of transfer (e.g. BUSY line on SX126x/SX128x).
|
||||
\param verify Whether to verify the result of the transaction after it is finished.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t SPIwriteStream(uint16_t cmd, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||
|
||||
/*!
|
||||
\brief Method to perform a write transaction with SPI stream.
|
||||
\param cmd SPI operation command.
|
||||
\param cmdLen SPI command length in bytes.
|
||||
\param data Data that will be transferred from master to slave.
|
||||
\param numBytes Number of bytes to transfer.
|
||||
\param waitForGpio Whether to wait for some GPIO at the end of transfer (e.g. BUSY line on SX126x/SX128x).
|
||||
\param verify Whether to verify the result of the transaction after it is finished.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t SPIwriteStream(uint8_t* cmd, uint8_t cmdLen, uint8_t* data, size_t numBytes, bool waitForGpio = true, bool verify = true);
|
||||
|
||||
/*!
|
||||
\brief SPI single transfer method for modules with stream-type SPI interface (SX126x, SX128x etc.).
|
||||
\param cmd SPI operation command.
|
||||
\param cmdLen SPI command length in bytes.
|
||||
\param write Set to true for write commands, false for read commands.
|
||||
\param dataOut Data that will be transferred from master to slave.
|
||||
\param dataIn Data that was transferred from slave to master.
|
||||
\param numBytes Number of bytes to transfer.
|
||||
\param waitForGpio Whether to wait for some GPIO at the end of transfer (e.g. BUSY line on SX126x/SX128x).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t SPItransferStream(const uint8_t* cmd, uint8_t cmdLen, bool write, uint8_t* dataOut, uint8_t* dataIn, size_t numBytes, bool waitForGpio);
|
||||
|
||||
// pin number access methods
|
||||
|
||||
/*!
|
||||
\brief Access method to get the pin number of SPI chip select.
|
||||
|
||||
\returns Pin number of SPI chip select configured in the constructor.
|
||||
*/
|
||||
RADIOLIB_PIN_TYPE getCs() const { return(_cs); }
|
||||
uint32_t getCs() const { return(csPin); }
|
||||
|
||||
/*!
|
||||
\brief Access method to get the pin number of interrupt/GPIO.
|
||||
|
||||
\returns Pin number of interrupt/GPIO configured in the constructor.
|
||||
*/
|
||||
RADIOLIB_PIN_TYPE getIrq() const { return(_irq); }
|
||||
uint32_t getIrq() const { return(irqPin); }
|
||||
|
||||
/*!
|
||||
\brief Access method to get the pin number of hardware reset pin.
|
||||
|
||||
\returns Pin number of hardware reset pin configured in the constructor.
|
||||
*/
|
||||
RADIOLIB_PIN_TYPE getRst() const { return(_rst); }
|
||||
uint32_t getRst() const { return(rstPin); }
|
||||
|
||||
/*!
|
||||
\brief Access method to get the pin number of second interrupt/GPIO.
|
||||
|
||||
\returns Pin number of second interrupt/GPIO configured in the constructor.
|
||||
*/
|
||||
RADIOLIB_PIN_TYPE getGpio() const { return(_gpio); }
|
||||
uint32_t getGpio() const { return(gpioPin); }
|
||||
|
||||
/*!
|
||||
\brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state.
|
||||
When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch!
|
||||
\brief Some modules contain external RF switch controlled by pins.
|
||||
This function gives RadioLib control over those pins to
|
||||
automatically switch between various modes: When idle both pins
|
||||
will be LOW, during TX the `txEn` pin will be HIGH, during RX the
|
||||
`rxPin` will be HIGH.
|
||||
|
||||
Radiolib will automatically set the pin mode and value of these
|
||||
pins, so do not control them from the sketch.
|
||||
|
||||
When more than two pins or more control over the output values are
|
||||
needed, use the setRfSwitchTable() function.
|
||||
|
||||
\param rxEn RX enable pin.
|
||||
|
||||
\param txEn TX enable pin.
|
||||
*/
|
||||
void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
|
||||
void setRfSwitchPins(uint32_t rxEn, uint32_t txEn);
|
||||
|
||||
/*!
|
||||
\brief Some modules contain external RF switch controlled by pins.
|
||||
This function gives RadioLib control over those pins to
|
||||
automatically switch between various modes.
|
||||
|
||||
Radiolib will automatically set the pin mode and value of these
|
||||
pins, so do not control them from the sketch.
|
||||
|
||||
|
||||
\param pins A reference to an array of pins to control. This
|
||||
should always be an array of 3 elements. If you need less pins,
|
||||
use RADIOLIB_NC for the unused elements.
|
||||
|
||||
\param table A reference to an array of pin values to use for each
|
||||
supported mode. Each element is an RfSwitchMode_T struct that
|
||||
lists the mode for which it applies and the values for each of the
|
||||
pins passed in the pins argument respectively.
|
||||
|
||||
The `pins` array will be copied into the Module object, so the
|
||||
original array can be deallocated after this call. However,
|
||||
a reference to the `table` array will be stored, so that array
|
||||
must remain valid as long RadioLib is being used.
|
||||
|
||||
The `mode` field in each table row should normally use any of the
|
||||
`MODE_*` constants from the Module::OpMode_t enum. However, some
|
||||
radios support additional modes and will define their own OpMode_t
|
||||
enum.
|
||||
|
||||
The length of the table is variable (to support radios that add
|
||||
additional modes), so the table must always be terminated with the
|
||||
special END_OF_MODE_TABLE value.
|
||||
|
||||
Normally all modes should be listed in the table, but for some
|
||||
radios, modes can be omitted to indicate they are not supported
|
||||
(e.g. when a radio has a high power and low power TX mode but
|
||||
external circuitry only supports low power). If applicable, this
|
||||
is documented in the radio class itself.
|
||||
|
||||
#### Example
|
||||
For example, on a board that has an RF switch with an enable pin
|
||||
connected to PA0 and a TX/RX select pin connected to PA1:
|
||||
|
||||
\code
|
||||
// In global scope, define the pin array and mode table
|
||||
static const uint32_t rfswitch_pins[] =
|
||||
{PA0, PA1, RADIOLIB_NC};
|
||||
static const Module::RfSwitchMode_t rfswitch_table[] = {
|
||||
{Module::MODE_IDLE, {LOW, LOW}},
|
||||
{Module::MODE_RX, {HIGH, LOW}},
|
||||
{Module::MODE_TX, {HIGH, HIGH}},
|
||||
Module::END_OF_MODE_TABLE,
|
||||
};
|
||||
|
||||
void setup() {
|
||||
...
|
||||
// Then somewhere in setup, pass them to radiolib
|
||||
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
|
||||
...
|
||||
}
|
||||
\endcode
|
||||
*/
|
||||
|
||||
void setRfSwitchTable(const uint32_t (&pins)[RFSWITCH_MAX_PINS], const RfSwitchMode_t table[]);
|
||||
|
||||
/*!
|
||||
\brief Find a mode in the RfSwitchTable.
|
||||
\param mode The mode to find.
|
||||
\returns A pointer to the RfSwitchMode_t struct in the table that
|
||||
matches the passed mode. Returns nullptr if no rfswitch pins are
|
||||
configured, or the passed mode is not listed in the table.
|
||||
*/
|
||||
const RfSwitchMode_t *findRfSwitchMode(uint8_t mode) const;
|
||||
|
||||
/*!
|
||||
\brief Set RF switch state.
|
||||
|
||||
\param rxPinState Pin state to set on Tx enable pin (usually high to transmit).
|
||||
|
||||
\param txPinState Pin state to set on Rx enable pin (usually high to receive).
|
||||
\param mode The mode to set. This must be one of the MODE_ constants, or a radio-specific constant.
|
||||
*/
|
||||
void setRfSwitchState(RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState);
|
||||
|
||||
// Arduino core overrides
|
||||
void setRfSwitchState(uint8_t mode);
|
||||
|
||||
/*!
|
||||
\brief Arduino core pinMode override that checks RADIOLIB_NC as alias for unused pin.
|
||||
\brief Wait for time to elapse, either using the microsecond timer, or the TimerFlag.
|
||||
Note that in interrupt timing mode, it is up to the user to set up the timing interrupt!
|
||||
|
||||
\param pin Pin to change the mode of.
|
||||
|
||||
\param mode Which mode to set.
|
||||
\param start Waiting start timestamp, in microseconds.
|
||||
\param len Waiting duration, in microseconds;
|
||||
*/
|
||||
void pinMode(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_MODE mode);
|
||||
|
||||
/*!
|
||||
\brief Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin.
|
||||
|
||||
\param pin Pin to write to.
|
||||
|
||||
\param value Whether to set the pin high or low.
|
||||
*/
|
||||
void digitalWrite(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_STATUS value);
|
||||
|
||||
/*!
|
||||
\brief Arduino core digitalWrite override that checks RADIOLIB_NC as alias for unused pin.
|
||||
|
||||
\param pin Pin to read from.
|
||||
|
||||
\returns Pin value.
|
||||
*/
|
||||
RADIOLIB_PIN_STATUS digitalRead(RADIOLIB_PIN_TYPE pin);
|
||||
|
||||
/*!
|
||||
\brief Arduino core tone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone.
|
||||
|
||||
\param pin Pin to write to.
|
||||
|
||||
\param value Frequency to output.
|
||||
*/
|
||||
void tone(RADIOLIB_PIN_TYPE pin, uint16_t value, uint32_t duration = 0);
|
||||
|
||||
/*!
|
||||
\brief Arduino core noTone override that checks RADIOLIB_NC as alias for unused pin and RADIOLIB_TONE_UNSUPPORTED to make sure the platform does support tone.
|
||||
|
||||
\param pin Pin to write to.
|
||||
*/
|
||||
void noTone(RADIOLIB_PIN_TYPE pin);
|
||||
|
||||
/*!
|
||||
\brief Arduino core attachInterrupt override.
|
||||
|
||||
\param interruptNum Interrupt number.
|
||||
|
||||
\param userFunc Interrupt service routine.
|
||||
|
||||
\param mode Pin hcange direction.
|
||||
*/
|
||||
void attachInterrupt(RADIOLIB_PIN_TYPE interruptNum, void (*userFunc)(void), RADIOLIB_INTERRUPT_STATUS mode);
|
||||
|
||||
/*!
|
||||
\brief Arduino core detachInterrupt override.
|
||||
|
||||
\param interruptNum Interrupt number.
|
||||
*/
|
||||
void detachInterrupt(RADIOLIB_PIN_TYPE interruptNum);
|
||||
|
||||
/*!
|
||||
\brief Arduino core yield override.
|
||||
*/
|
||||
void yield();
|
||||
|
||||
/*!
|
||||
\brief Arduino core delay override.
|
||||
|
||||
\param ms Delay length in milliseconds.
|
||||
*/
|
||||
void delay(uint32_t ms);
|
||||
|
||||
/*!
|
||||
\brief Arduino core delayMicroseconds override.
|
||||
|
||||
\param us Delay length in microseconds.
|
||||
*/
|
||||
void delayMicroseconds(uint32_t us);
|
||||
|
||||
/*!
|
||||
\brief Arduino core millis override.
|
||||
*/
|
||||
uint32_t millis();
|
||||
|
||||
/*!
|
||||
\brief Arduino core micros override.
|
||||
*/
|
||||
uint32_t micros();
|
||||
|
||||
/*!
|
||||
\brief Arduino core pulseIn override.
|
||||
*/
|
||||
uint32_t pulseIn(RADIOLIB_PIN_TYPE pin, RADIOLIB_PIN_STATUS state, uint32_t timeout);
|
||||
|
||||
/*!
|
||||
\brief Arduino core SPI begin override.
|
||||
*/
|
||||
void begin();
|
||||
|
||||
/*!
|
||||
\brief Arduino core SPI beginTransaction override.
|
||||
*/
|
||||
void beginTransaction();
|
||||
|
||||
/*!
|
||||
\brief Arduino core SPI transfer override.
|
||||
*/
|
||||
uint8_t transfer(uint8_t b);
|
||||
|
||||
/*!
|
||||
\brief Arduino core SPI endTransaction override.
|
||||
*/
|
||||
void endTransaction();
|
||||
|
||||
/*!
|
||||
\brief Arduino core SPI end override.
|
||||
*/
|
||||
void end();
|
||||
|
||||
// helper functions to set up SPI overrides on Arduino
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
void SPIbegin();
|
||||
void SPIend();
|
||||
#endif
|
||||
virtual void SPIbeginTransaction();
|
||||
virtual uint8_t SPItransfer(uint8_t b);
|
||||
virtual void SPIendTransaction();
|
||||
void waitForMicroseconds(RadioLibTime_t start, RadioLibTime_t len);
|
||||
|
||||
/*!
|
||||
\brief Function to reflect bits within a byte.
|
||||
\param in The input to reflect.
|
||||
\param bits Number of bits to reflect.
|
||||
\return The reflected input.
|
||||
*/
|
||||
static uint8_t flipBits(uint8_t b);
|
||||
|
||||
/*!
|
||||
\brief Function to reflect bits within an integer.
|
||||
*/
|
||||
static uint16_t flipBits16(uint16_t i);
|
||||
static uint32_t reflect(uint32_t in, uint8_t bits);
|
||||
|
||||
#if RADIOLIB_DEBUG
|
||||
/*!
|
||||
\brief Function to dump data as hex into the debug port.
|
||||
|
||||
\param level RadioLib debug level, set to NULL to not print.
|
||||
\param data Data to dump.
|
||||
|
||||
\param len Number of bytes to dump.
|
||||
\param offset Address offset to add when printing the data.
|
||||
\param width Word width (1 for uint8_t, 2 for uint16_t, 4 for uint32_t).
|
||||
\param be Print multi-byte data as big endian. Defaults to false.
|
||||
*/
|
||||
static void hexdump(uint8_t* data, size_t len);
|
||||
static void hexdump(const char* level, uint8_t* data, size_t len, uint32_t offset = 0, uint8_t width = 1, bool be = false);
|
||||
|
||||
/*!
|
||||
\brief Function to dump device registers as hex into the debug port.
|
||||
|
||||
\param level RadioLib debug level, set to NULL to not print.
|
||||
\param start First address to dump.
|
||||
|
||||
\param len Number of bytes to dump.
|
||||
*/
|
||||
void regdump(uint8_t start, uint8_t len);
|
||||
|
||||
// hardware abstraction layer callbacks
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_PIN_MODE);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DIGITAL_WRITE);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DIGITAL_READ);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_TONE);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_NO_TONE);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_ATTACH_INTERRUPT);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DETACH_INTERRUPT);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_YIELD);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DELAY);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_DELAY_MICROSECONDS);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_MILLIS);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_MICROS);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_PULSE_IN);
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_BEGIN);
|
||||
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION);
|
||||
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_TRANSFER);
|
||||
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_END_TRANSACTION);
|
||||
RADIOLIB_GENERATE_CALLBACK_SPI(RADIOLIB_CB_ARGS_SPI_END);
|
||||
#else
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_BEGIN);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_BEGIN_TRANSACTION);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_TRANSFER);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_END_TRANSACTION);
|
||||
RADIOLIB_GENERATE_CALLBACK(RADIOLIB_CB_ARGS_SPI_END);
|
||||
void regdump(const char* level, uint16_t start, size_t len);
|
||||
#endif
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if RADIOLIB_DEBUG and defined(RADIOLIB_BUILD_ARDUINO)
|
||||
static size_t serialPrintf(const char* format, ...);
|
||||
#endif
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
uint32_t csPin = RADIOLIB_NC;
|
||||
uint32_t irqPin = RADIOLIB_NC;
|
||||
uint32_t rstPin = RADIOLIB_NC;
|
||||
uint32_t gpioPin = RADIOLIB_NC;
|
||||
|
||||
// pins
|
||||
RADIOLIB_PIN_TYPE _cs = RADIOLIB_NC;
|
||||
RADIOLIB_PIN_TYPE _irq = RADIOLIB_NC;
|
||||
RADIOLIB_PIN_TYPE _rst = RADIOLIB_NC;
|
||||
RADIOLIB_PIN_TYPE _gpio = RADIOLIB_NC;
|
||||
// RF switch pins and table
|
||||
uint32_t rfSwitchPins[RFSWITCH_MAX_PINS] = { RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC };
|
||||
const RfSwitchMode_t *rfSwitchTable = nullptr;
|
||||
|
||||
// SPI interface (Arduino only)
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
SPIClass* _spi = NULL;
|
||||
SPISettings _spiSettings = RADIOLIB_DEFAULT_SPI_SETTINGS;
|
||||
bool _initInterface = false;
|
||||
#if RADIOLIB_INTERRUPT_TIMING
|
||||
uint32_t prevTimingLen = 0;
|
||||
#endif
|
||||
|
||||
// RF switch presence and pins
|
||||
bool _useRfSwitch = false;
|
||||
RADIOLIB_PIN_TYPE _rxEn = RADIOLIB_NC;
|
||||
RADIOLIB_PIN_TYPE _txEn = RADIOLIB_NC;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,16 +38,22 @@
|
||||
#include "TypeDef.h"
|
||||
#include "Module.h"
|
||||
|
||||
#include "Hal.h"
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
#include "ArduinoHal.h"
|
||||
#endif
|
||||
|
||||
|
||||
// warnings are printed in this file since BuildOpt.h is compiled in multiple places
|
||||
|
||||
// check God mode
|
||||
#if defined(RADIOLIB_GODMODE)
|
||||
#if RADIOLIB_GODMODE
|
||||
#warning "God mode active, I hope it was intentional. Buckle up, lads."
|
||||
#endif
|
||||
|
||||
// print debug info
|
||||
#if defined(RADIOLIB_DEBUG)
|
||||
#pragma message "RADIOLIB_PLATFORM: " RADIOLIB_PLATFORM
|
||||
#if RADIOLIB_DEBUG
|
||||
#pragma message(RADIOLIB_INFO)
|
||||
#endif
|
||||
|
||||
// check unknown/unsupported platform
|
||||
@@ -55,22 +61,29 @@
|
||||
#warning "RadioLib might not be compatible with this Arduino board - check supported platforms at https://github.com/jgromes/RadioLib!"
|
||||
#endif
|
||||
|
||||
// print warning for low-end platforms
|
||||
#if defined(RADIOLIB_LOWEND_PLATFORM)
|
||||
#warning "Low-end platform detected, stability issues are likely!"
|
||||
#endif
|
||||
|
||||
#include "modules/CC1101/CC1101.h"
|
||||
#include "modules/LLCC68/LLCC68.h"
|
||||
#include "modules/LR11x0/LR1110.h"
|
||||
#include "modules/LR11x0/LR1120.h"
|
||||
#include "modules/LR11x0/LR1121.h"
|
||||
#include "modules/nRF24/nRF24.h"
|
||||
#include "modules/RF69/RF69.h"
|
||||
#include "modules/RFM2x/RFM22.h"
|
||||
#include "modules/RFM2x/RFM23.h"
|
||||
#include "modules/RFM9x/RFM95.h"
|
||||
#include "modules/RFM9x/RFM96.h"
|
||||
#include "modules/RFM9x/RFM97.h"
|
||||
#include "modules/Si443x/Si4430.h"
|
||||
#include "modules/Si443x/Si4431.h"
|
||||
#include "modules/Si443x/Si4432.h"
|
||||
#include "modules/SX1231/SX1231.h"
|
||||
#include "modules/SX123x/SX1231.h"
|
||||
#include "modules/SX123x/SX1233.h"
|
||||
#include "modules/SX126x/SX1261.h"
|
||||
#include "modules/SX126x/SX1262.h"
|
||||
#include "modules/SX126x/SX1268.h"
|
||||
#include "modules/SX126x/STM32WLx.h"
|
||||
#include "modules/SX127x/SX1272.h"
|
||||
#include "modules/SX127x/SX1273.h"
|
||||
#include "modules/SX127x/SX1276.h"
|
||||
@@ -87,13 +100,22 @@
|
||||
#include "protocols/AX25/AX25.h"
|
||||
#include "protocols/Hellschreiber/Hellschreiber.h"
|
||||
#include "protocols/Morse/Morse.h"
|
||||
#include "protocols/Pager/Pager.h"
|
||||
#include "protocols/RTTY/RTTY.h"
|
||||
#include "protocols/SSTV/SSTV.h"
|
||||
#include "protocols/FSK4/FSK4.h"
|
||||
#include "protocols/APRS/APRS.h"
|
||||
#include "protocols/ExternalRadio/ExternalRadio.h"
|
||||
#include "protocols/Print/Print.h"
|
||||
#include "protocols/BellModem/BellModem.h"
|
||||
#include "protocols/LoRaWAN/LoRaWAN.h"
|
||||
|
||||
// utilities
|
||||
#include "utils/CRC.h"
|
||||
#include "utils/Cryptography.h"
|
||||
|
||||
// only create Radio class when using RadioShield
|
||||
#if defined(RADIOLIB_RADIOSHIELD)
|
||||
#if RADIOLIB_RADIOSHIELD
|
||||
|
||||
// RadioShield pin definitions
|
||||
#define RADIOSHIELD_CS_A 10
|
||||
@@ -125,7 +147,7 @@ class Radio {
|
||||
ModuleB = new Module(RADIOSHIELD_CS_B, RADIOSHIELD_IRQ_B, RADIOSHIELD_RST_B, RADIOSHIELD_GPIO_B);
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_GODMODE)
|
||||
#if RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
+221
-5
@@ -1,6 +1,8 @@
|
||||
#if !defined(_RADIOLIB_TYPES_H)
|
||||
#define _RADIOLIB_TYPES_H
|
||||
|
||||
// user build options may override the default
|
||||
#include "BuildOptUser.h"
|
||||
#include "BuildOpt.h"
|
||||
|
||||
/*!
|
||||
@@ -15,22 +17,22 @@
|
||||
#define RADIOLIB_SHAPING_NONE (0x00)
|
||||
|
||||
/*!
|
||||
\brief Gaussin shaping filter, BT = 0.3
|
||||
\brief Gaussian shaping filter, BT = 0.3
|
||||
*/
|
||||
#define RADIOLIB_SHAPING_0_3 (0x01)
|
||||
|
||||
/*!
|
||||
\brief Gaussin shaping filter, BT = 0.5
|
||||
\brief Gaussian shaping filter, BT = 0.5
|
||||
*/
|
||||
#define RADIOLIB_SHAPING_0_5 (0x02)
|
||||
|
||||
/*!
|
||||
\brief Gaussin shaping filter, BT = 0.7
|
||||
\brief Gaussian shaping filter, BT = 0.7
|
||||
*/
|
||||
#define RADIOLIB_SHAPING_0_7 (0x03)
|
||||
|
||||
/*!
|
||||
\brief Gaussin shaping filter, BT = 1.0
|
||||
\brief Gaussian shaping filter, BT = 1.0
|
||||
*/
|
||||
#define RADIOLIB_SHAPING_1_0 (0x04)
|
||||
|
||||
@@ -63,6 +65,31 @@
|
||||
\}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\defgroup config_standby Standby mode type aliases.
|
||||
|
||||
\{
|
||||
*/
|
||||
|
||||
/*!
|
||||
\brief Default standby used by the module
|
||||
*/
|
||||
#define RADIOLIB_STANDBY_DEFAULT (0x00)
|
||||
|
||||
/*!
|
||||
\brief Warm standby (e.g. crystal left running).
|
||||
*/
|
||||
#define RADIOLIB_STANDBY_WARM (0x01)
|
||||
|
||||
/*!
|
||||
\brief Cold standby (e.g. only internal RC oscillator running).
|
||||
*/
|
||||
#define RADIOLIB_STANDBY_COLD (0x02)
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\defgroup status_codes Status Codes
|
||||
|
||||
@@ -218,6 +245,11 @@
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_RSSI_THRESHOLD (-27)
|
||||
|
||||
/*!
|
||||
\brief A `NULL` pointer has been encountered. If you see this, there may be a potential security vulnerability.
|
||||
*/
|
||||
#define RADIOLIB_ERR_NULL_POINTER (-28)
|
||||
|
||||
// RF69-specific status codes
|
||||
|
||||
/*!
|
||||
@@ -260,6 +292,11 @@
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_OOK_RSSI_PEAK_TYPE (-108)
|
||||
|
||||
/*!
|
||||
\brief Supplied Bitrate tolerance value is out of Range.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_BIT_RATE_TOLERANCE_VALUE (-109)
|
||||
|
||||
// APRS status codes
|
||||
|
||||
/*!
|
||||
@@ -278,10 +315,32 @@
|
||||
#define RADIOLIB_ERR_INVALID_MIC_E_TELEMETRY_LENGTH (-203)
|
||||
|
||||
/*!
|
||||
\brief Mic-E message cannot contaion both telemetry and status text.
|
||||
\brief Mic-E message cannot contain both telemetry and status text.
|
||||
*/
|
||||
#define RADIOLIB_ERR_MIC_E_TELEMETRY_STATUS (-204)
|
||||
|
||||
// SSDV status codes
|
||||
|
||||
/*!
|
||||
\brief SSDV mode is invalid.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_SSDV_MODE (-301)
|
||||
|
||||
/*!
|
||||
\brief Image size is invalid.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_IMAGE_SIZE (-302)
|
||||
|
||||
/*!
|
||||
\brief Image quality is invalid.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_IMAGE_QUALITY (-303)
|
||||
|
||||
/*!
|
||||
\brief Image subsampling is invalid.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_SUBSAMPLING (-304)
|
||||
|
||||
// RTTY status codes
|
||||
|
||||
/*!
|
||||
@@ -357,6 +416,11 @@
|
||||
|
||||
/*!
|
||||
\brief SX126x failed to execute SPI command.
|
||||
Often this means that the module is trying to use TCXO while
|
||||
XTAL is connected (or vice versa). Make sure your crystal setup
|
||||
(e.g. TCXO reference voltage) matches your hardware by setting
|
||||
"tcxoVoltage" to 0 when using XTAL module, or to appropriate value
|
||||
when using TCXO module.
|
||||
*/
|
||||
#define RADIOLIB_ERR_SPI_CMD_FAILED (-707)
|
||||
|
||||
@@ -405,6 +469,158 @@
|
||||
*/
|
||||
#define RADIOLIB_ERR_RANGING_TIMEOUT (-901)
|
||||
|
||||
// Pager-specific status codes
|
||||
|
||||
/*!
|
||||
\brief The provided payload data configuration is invalid.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_PAYLOAD (-1001)
|
||||
|
||||
/*!
|
||||
\brief The requested address was not found in the received data.
|
||||
*/
|
||||
#define RADIOLIB_ERR_ADDRESS_NOT_FOUND (-1002)
|
||||
|
||||
/*!
|
||||
\brief The function code is invalid. 2 Bits only.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_FUNCTION (-1003)
|
||||
|
||||
// LoRaWAN-specific status codes
|
||||
|
||||
/*!
|
||||
\brief Unable to restore existing LoRaWAN session because this node did not join any network yet.
|
||||
*/
|
||||
#define RADIOLIB_ERR_NETWORK_NOT_JOINED (-1101)
|
||||
|
||||
/*!
|
||||
\brief Malformed downlink packet received from network server.
|
||||
*/
|
||||
#define RADIOLIB_ERR_DOWNLINK_MALFORMED (-1102)
|
||||
|
||||
/*!
|
||||
\brief Network server requested switch to unsupported LoRaWAN revision.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_REVISION (-1103)
|
||||
|
||||
/*!
|
||||
\brief Invalid LoRaWAN uplink port requested by user, or downlink received at invalid port.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_PORT (-1104)
|
||||
|
||||
/*!
|
||||
\brief User did not enable downlink in time.
|
||||
*/
|
||||
#define RADIOLIB_ERR_NO_RX_WINDOW (-1105)
|
||||
|
||||
/*!
|
||||
\brief There are no channels available for the requested datarate.
|
||||
*/
|
||||
#define RADIOLIB_ERR_NO_CHANNEL_AVAILABLE (-1106)
|
||||
|
||||
/*!
|
||||
\brief Invalid LoRaWAN MAC command ID.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_CID (-1107)
|
||||
|
||||
/*!
|
||||
\brief User requested to start uplink while still inside RX window or under dutycycle.
|
||||
*/
|
||||
#define RADIOLIB_ERR_UPLINK_UNAVAILABLE (-1108)
|
||||
|
||||
/*!
|
||||
\brief Unable to push new MAC command because the queue is full.
|
||||
*/
|
||||
#define RADIOLIB_ERR_COMMAND_QUEUE_FULL (-1109)
|
||||
|
||||
/*!
|
||||
\brief Unable to delete MAC command because it was not found in the queue.
|
||||
*/
|
||||
#define RADIOLIB_ERR_COMMAND_QUEUE_ITEM_NOT_FOUND (-1110)
|
||||
|
||||
/*!
|
||||
\brief Unable to join network because JoinNonce is not higher than saved value.
|
||||
*/
|
||||
#define RADIOLIB_ERR_JOIN_NONCE_INVALID (-1111)
|
||||
|
||||
/*!
|
||||
\brief Received downlink Network frame counter is invalid (lower than last heard value).
|
||||
*/
|
||||
#define RADIOLIB_ERR_N_FCNT_DOWN_INVALID (-1112)
|
||||
|
||||
/*!
|
||||
\brief Received downlink Application frame counter is invalid (lower than last heard value).
|
||||
*/
|
||||
#define RADIOLIB_ERR_A_FCNT_DOWN_INVALID (-1113)
|
||||
|
||||
/*!
|
||||
\brief Uplink payload length at this datarate exceeds the active dwell time limitations.
|
||||
*/
|
||||
#define RADIOLIB_ERR_DWELL_TIME_EXCEEDED (-1114)
|
||||
|
||||
/*!
|
||||
\brief The buffer integrity check did not match the supplied checksum value.
|
||||
*/
|
||||
#define RADIOLIB_ERR_CHECKSUM_MISMATCH (-1115)
|
||||
|
||||
/*!
|
||||
\brief No JoinAccept was received - check your keys, or otherwise likely a range issue!
|
||||
*/
|
||||
#define RADIOLIB_ERR_NO_JOIN_ACCEPT (-1116)
|
||||
|
||||
/*!
|
||||
\brief The LoRaWAN session was successfully re-activated.
|
||||
*/
|
||||
#define RADIOLIB_LORAWAN_SESSION_RESTORED (-1117)
|
||||
|
||||
/*!
|
||||
\brief A new LoRaWAN session is started.
|
||||
*/
|
||||
#define RADIOLIB_LORAWAN_NEW_SESSION (-1118)
|
||||
|
||||
/*!
|
||||
\brief The supplied Nonces buffer is discarded as its activation information is invalid.
|
||||
*/
|
||||
#define RADIOLIB_ERR_NONCES_DISCARDED (-1119)
|
||||
|
||||
/*!
|
||||
\brief The supplied Session buffer is discarded as it doesn't match the Nonces.
|
||||
*/
|
||||
#define RADIOLIB_ERR_SESSION_DISCARDED (-1120)
|
||||
|
||||
/*!
|
||||
\brief The requested command is unavailable under the current LoRaWAN mode.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_MODE (-1121)
|
||||
|
||||
// LR11x0-specific status codes
|
||||
|
||||
/*!
|
||||
\brief The selected 802.11 WiFi type is invalid.
|
||||
*/
|
||||
#define RADIOLIB_ERR_INVALID_WIFI_TYPE (-1200)
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
|
||||
/*!
|
||||
\defgroup typedefs Type aliases used by RadioLib.
|
||||
|
||||
\{
|
||||
*/
|
||||
|
||||
/*!
|
||||
\brief Type used for durations in RadioLib
|
||||
*/
|
||||
typedef unsigned long RadioLibTime_t;
|
||||
|
||||
/*!
|
||||
\brief Type used for radio-agnostic IRQ flags. IRQ to enable corresponds to the bit index (RadioLibIrq_t).
|
||||
For example, if bit 0 is set, the module will enable its RADIOLIB_IRQ_TX_DONE (if it is supported).
|
||||
*/
|
||||
typedef uint32_t RadioLibIrqFlags_t;
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,12 @@
|
||||
#include "LLCC68.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
#if !RADIOLIB_EXCLUDE_SX126X
|
||||
|
||||
LLCC68::LLCC68(Module* mod) : SX1262(mod) {
|
||||
|
||||
chipType = RADIOLIB_LLCC68_CHIP_TYPE;
|
||||
this->XTAL = true;
|
||||
}
|
||||
|
||||
int16_t LLCC68::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
int16_t LLCC68::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t pwr, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
// execute common part
|
||||
int16_t state = SX126x::begin(cr, syncWord, preambleLength, tcxoVoltage, useRegulatorLDO);
|
||||
RADIOLIB_ASSERT(state);
|
||||
@@ -20,7 +21,7 @@ int16_t LLCC68::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
|
||||
state = setSpreadingFactor(sf);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
state = setOutputPower(pwr);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = SX126x::fixPaClamping();
|
||||
@@ -35,7 +36,7 @@ int16_t LLCC68::setBandwidth(float bw) {
|
||||
}
|
||||
|
||||
int16_t LLCC68::setSpreadingFactor(uint8_t sf) {
|
||||
switch(SX126x::_bw) {
|
||||
switch(SX126x::bandwidth) {
|
||||
case RADIOLIB_SX126X_LORA_BW_125_0:
|
||||
RADIOLIB_CHECK_RANGE(sf, 5, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||
break;
|
||||
@@ -52,4 +53,67 @@ int16_t LLCC68::setSpreadingFactor(uint8_t sf) {
|
||||
return(SX1262::setSpreadingFactor(sf));
|
||||
}
|
||||
|
||||
int16_t LLCC68::setDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
uint8_t modem = this->getPacketType();
|
||||
if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
|
||||
// set the bit rate
|
||||
state = this->setBitRate(dr.fsk.bitRate);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the frequency deviation
|
||||
state = this->setFrequencyDeviation(dr.fsk.freqDev);
|
||||
|
||||
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
|
||||
// set the spreading factor
|
||||
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the bandwidth
|
||||
state = this->setBandwidth(dr.lora.bandwidth);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the coding rate
|
||||
state = this->setCodingRate(dr.lora.codingRate);
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LLCC68::checkDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
uint8_t modem = this->getPacketType();
|
||||
if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
|
||||
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.6, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||
RADIOLIB_CHECK_RANGE(dr.fsk.freqDev, 0.6, 200.0, RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
|
||||
uint8_t bw_div2 = dr.lora.bandwidth / 2 + 0.01;
|
||||
switch (bw_div2) {
|
||||
case 62: // 125.0:
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 5, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||
break;
|
||||
case 125: // 250.0
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 5, 10, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||
break;
|
||||
case 250: // 500.0
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 5, 11, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,69 +3,74 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
#if !RADIOLIB_EXCLUDE_SX126X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "../SX126x/SX1262.h"
|
||||
|
||||
//RADIOLIB_SX126X_REG_VERSION_STRING
|
||||
#define RADIOLIB_LLCC68_CHIP_TYPE "LLCC68"
|
||||
|
||||
/*!
|
||||
\class LLCC68
|
||||
|
||||
\brief Derived class for %LLCC68 modules.
|
||||
*/
|
||||
class LLCC68: public SX1262 {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
LLCC68(Module* mod);
|
||||
LLCC68(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
/*!
|
||||
\brief Initialization method for LoRa modem.
|
||||
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
|
||||
\param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz.
|
||||
|
||||
\param sf LoRa spreading factor. Defaults to 9.
|
||||
|
||||
\param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
|
||||
|
||||
\param syncWord 2-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
|
||||
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
|
||||
\param syncWord 1-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
|
||||
\param pwr Output power in dBm. Defaults to 10 dBm.
|
||||
\param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols.
|
||||
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip.
|
||||
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 0 V (XTAL).
|
||||
If you are seeing -706/-707 error codes, it likely means you are using a module with TCXO.
|
||||
To use TCXO, either set this value to its reference voltage, or set SX126x::XTAL to false.
|
||||
\param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t pwr = 10, uint16_t preambleLength = 8, float tcxoVoltage = 0, bool useRegulatorLDO = false);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets LoRa bandwidth. Allowed values are 125.0, 250.0 and 500.0 kHz.
|
||||
|
||||
\param bw LoRa bandwidth to be set in kHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setBandwidth(float bw);
|
||||
|
||||
/*!
|
||||
\brief Sets LoRa spreading factor. Allowed values range from 5 to 11, depending on currently set spreading factor.
|
||||
|
||||
\param sf LoRa spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
/*!
|
||||
\brief Set data.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataRate(DataRate_t dr) override;
|
||||
|
||||
/*!
|
||||
\brief Check the data rate can be configured by this module.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkDataRate(DataRate_t dr) override;
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
#include "LR1110.h"
|
||||
#if !RADIOLIB_EXCLUDE_LR11X0
|
||||
|
||||
LR1110::LR1110(Module* mod) : LR11x0(mod) {
|
||||
chipType = RADIOLIB_LR11X0_DEVICE_LR1110;
|
||||
}
|
||||
|
||||
int16_t LR1110::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
|
||||
// execute common part
|
||||
int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR1110::beginGFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
|
||||
// execute common part
|
||||
int16_t state = LR11x0::beginGFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR1110::beginLRFHSS(float freq, uint8_t bw, uint8_t cr, int8_t power, float tcxoVoltage) {
|
||||
// execute common part
|
||||
int16_t state = LR11x0::beginLRFHSS(bw, cr, tcxoVoltage);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR1110::setFrequency(float freq) {
|
||||
return(this->setFrequency(freq, true));
|
||||
}
|
||||
|
||||
int16_t LR1110::setFrequency(float freq, bool calibrate, float band) {
|
||||
RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, RADIOLIB_ERR_INVALID_FREQUENCY);
|
||||
|
||||
// calibrate image rejection
|
||||
if(calibrate) {
|
||||
int16_t state = LR11x0::calibImage(freq - band, freq + band);
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
// set frequency
|
||||
return(LR11x0::setRfFrequency((uint32_t)(freq*1000000.0f)));
|
||||
}
|
||||
|
||||
int16_t LR1110::setOutputPower(int8_t power) {
|
||||
return(this->setOutputPower(power, false));
|
||||
}
|
||||
|
||||
int16_t LR1110::setOutputPower(int8_t power, bool forceHighPower) {
|
||||
// check if power value is configurable
|
||||
int16_t state = this->checkOutputPower(power, NULL, forceHighPower);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// determine whether to use HP or LP PA and check range accordingly
|
||||
bool useHp = forceHighPower || (power > 14);
|
||||
|
||||
// TODO how and when to configure OCP?
|
||||
|
||||
// update PA config - always use VBAT for high-power PA
|
||||
state = setPaConfig((uint8_t)useHp, (uint8_t)useHp, 0x04, 0x07);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set output power
|
||||
state = setTxParams(power, RADIOLIB_LR11X0_PA_RAMP_48U);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR1110::checkOutputPower(int8_t power, int8_t* clipped) {
|
||||
return(checkOutputPower(power, clipped, false));
|
||||
}
|
||||
|
||||
int16_t LR1110::checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower) {
|
||||
if(forceHighPower || (power > 14)) {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
|
||||
} else {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,133 @@
|
||||
#if !defined(_RADIOLIB_LR1110_H)
|
||||
#define _RADIOLIB_LR1110_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_LR11X0
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "LR11x0.h"
|
||||
|
||||
/*!
|
||||
\class LR1110
|
||||
\brief Derived class for %LR1110 modules.
|
||||
*/
|
||||
class LR1110: public LR11x0 {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
LR1110(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method for LoRa modem.
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
\param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz.
|
||||
\param sf LoRa spreading factor. Defaults to 9.
|
||||
\param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
|
||||
\param syncWord 1-byte LoRa sync word. Defaults to RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE (0x12).
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
\param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols.
|
||||
\param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
\param br FSK bit rate in kbps. Defaults to 4.8 kbps.
|
||||
\param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 5.0 kHz.
|
||||
\param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz.
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
\param preambleLength FSK preamble length in bits. Defaults to 16 bits.
|
||||
\param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginGFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for LR-FHSS modem.
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
\param bw LR-FHSS bandwidth, one of RADIOLIB_LR11X0_LR_FHSS_BW_* values. Defaults to 722.66 kHz.
|
||||
\param cr LR-FHSS coding rate, one of RADIOLIB_LR11X0_LR_FHSS_CR_* values. Defaults to 2/3 coding rate.
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
\param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginLRFHSS(float freq = 434.0, uint8_t bw = RADIOLIB_LR11X0_LR_FHSS_BW_722_66, uint8_t cr = RADIOLIB_LR11X0_LR_FHSS_CR_2_3, int8_t power = 10, float tcxoVoltage = 1.6);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz.
|
||||
Will also perform calibrations.
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz.
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
\param calibrate Run image calibration.
|
||||
\param band Half bandwidth for image calibration. For example,
|
||||
if carrier is 434 MHz and band is set to 4 MHz, then the image will be calibrate
|
||||
for band 430 - 438 MHz. Unused if calibrate is set to false, defaults to 4 MHz
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq, bool calibrate, float band = 4);
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are in range from -9 to 22 dBm (high-power PA) or -17 to 14 dBm (low-power PA).
|
||||
\param power Output power to be set in dBm, output PA is determined automatically preferring the low-power PA.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are in range from -9 to 22 dBm (high-power PA) or -17 to 14 dBm (low-power PA).
|
||||
\param power Output power to be set in dBm.
|
||||
\param forceHighPower Force using the high-power PA. If set to false, PA will be determined automatically
|
||||
based on configured output power, preferring the low-power PA. If set to true, only high-power PA will be used.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power, bool forceHighPower);
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
This method is needed for compatibility with PhysicalLayer::checkOutputPower.
|
||||
\param power Output power in dBm, PA will be determined automatically.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
\param power Output power in dBm.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\param forceHighPower Force using the high-power PA. If set to false, PA will be determined automatically
|
||||
based on configured output power, preferring the low-power PA. If set to true, only high-power PA will be used.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower);
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,131 @@
|
||||
#include "LR1120.h"
|
||||
#if !RADIOLIB_EXCLUDE_LR11X0
|
||||
|
||||
LR1120::LR1120(Module* mod) : LR11x0(mod) {
|
||||
chipType = RADIOLIB_LR11X0_DEVICE_LR1120;
|
||||
}
|
||||
|
||||
int16_t LR1120::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
|
||||
// execute common part
|
||||
int16_t state = LR11x0::begin(bw, sf, cr, syncWord, preambleLength, tcxoVoltage);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR1120::beginGFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage) {
|
||||
// execute common part
|
||||
int16_t state = LR11x0::beginGFSK(br, freqDev, rxBw, preambleLength, tcxoVoltage);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR1120::beginLRFHSS(float freq, uint8_t bw, uint8_t cr, int8_t power, float tcxoVoltage) {
|
||||
// execute common part
|
||||
int16_t state = LR11x0::beginLRFHSS(bw, cr, tcxoVoltage);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR1120::setFrequency(float freq) {
|
||||
return(this->setFrequency(freq, true));
|
||||
}
|
||||
|
||||
int16_t LR1120::setFrequency(float freq, bool calibrate, float band) {
|
||||
if(!(((freq >= 150.0) && (freq <= 960.0)) ||
|
||||
((freq >= 1900.0) && (freq <= 2200.0)) ||
|
||||
((freq >= 2400.0) && (freq <= 2500.0)))) {
|
||||
return(RADIOLIB_ERR_INVALID_FREQUENCY);
|
||||
}
|
||||
|
||||
// calibrate image rejection
|
||||
int16_t state;
|
||||
if(calibrate) {
|
||||
state = LR11x0::calibImage(freq - band, freq + band);
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
// set frequency
|
||||
state = LR11x0::setRfFrequency((uint32_t)(freq*1000000.0f));
|
||||
RADIOLIB_ASSERT(state);
|
||||
this->highFreq = (freq > 1000.0);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t LR1120::setOutputPower(int8_t power) {
|
||||
return(this->setOutputPower(power, false));
|
||||
}
|
||||
|
||||
int16_t LR1120::setOutputPower(int8_t power, bool forceHighPower) {
|
||||
// check if power value is configurable
|
||||
int16_t state = this->checkOutputPower(power, NULL, forceHighPower);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// determine whether to use HP or LP PA and check range accordingly
|
||||
uint8_t paSel = 0;
|
||||
uint8_t paSupply = 0;
|
||||
if(this->highFreq) {
|
||||
paSel = 2;
|
||||
} else if(forceHighPower || (power > 14)) {
|
||||
paSel = 1;
|
||||
paSupply = 1;
|
||||
}
|
||||
|
||||
// TODO how and when to configure OCP?
|
||||
|
||||
// update PA config - always use VBAT for high-power PA
|
||||
state = setPaConfig(paSel, paSupply, 0x04, 0x07);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set output power
|
||||
state = setTxParams(power, RADIOLIB_LR11X0_PA_RAMP_48U);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t LR1120::checkOutputPower(int8_t power, int8_t* clipped) {
|
||||
return(checkOutputPower(power, clipped, false));
|
||||
}
|
||||
|
||||
int16_t LR1120::checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower) {
|
||||
if(this->highFreq) {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-18, RADIOLIB_MIN(13, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -18, 13, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
if(forceHighPower || (power > 14)) {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
|
||||
} else {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,145 @@
|
||||
#if !defined(_RADIOLIB_LR1120_H)
|
||||
#define _RADIOLIB_LR1120_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_LR11X0
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "LR11x0.h"
|
||||
|
||||
/*!
|
||||
\class LR1120
|
||||
\brief Derived class for %LR1120 modules.
|
||||
*/
|
||||
class LR1120: public LR11x0 {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
LR1120(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method for LoRa modem.
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
\param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz.
|
||||
\param sf LoRa spreading factor. Defaults to 9.
|
||||
\param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
|
||||
\param syncWord 1-byte LoRa sync word. Defaults to RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE (0x12).
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
\param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols.
|
||||
\param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
\param br FSK bit rate in kbps. Defaults to 4.8 kbps.
|
||||
\param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 5.0 kHz.
|
||||
\param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz.
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
\param preambleLength FSK preamble length in bits. Defaults to 16 bits.
|
||||
\param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginGFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for LR-FHSS modem.
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
\param bw LR-FHSS bandwidth, one of RADIOLIB_LR11X0_LR_FHSS_BW_* values. Defaults to 722.66 kHz.
|
||||
\param cr LR-FHSS coding rate, one of RADIOLIB_LR11X0_LR_FHSS_CR_* values. Defaults to 2/3 coding rate.
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
\param tcxoVoltage TCXO reference voltage to be set. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set LR11x0::XTAL to true.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginLRFHSS(float freq = 434.0, uint8_t bw = RADIOLIB_LR11X0_LR_FHSS_BW_722_66, uint8_t cr = RADIOLIB_LR11X0_LR_FHSS_CR_2_3, int8_t power = 10, float tcxoVoltage = 1.6);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz,
|
||||
1900 - 2200 MHz and 2400 - 2500 MHz. Will also perform calibrations.
|
||||
NOTE: When switching between sub-GHz and high-frequency bands, after changing the frequency,
|
||||
setOutputPower() must be called in order to set the correct power amplifier!
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz,
|
||||
1900 - 2200 MHz and 2400 - 2500 MHz. Will also perform calibrations.
|
||||
NOTE: When switching between sub-GHz and high-frequency bands, after changing the frequency,
|
||||
setOutputPower() must be called in order to set the correct power amplifier!
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
\param calibrate Run image calibration.
|
||||
\param band Half bandwidth for image calibration. For example,
|
||||
if carrier is 434 MHz and band is set to 4 MHz, then the image will be calibrate
|
||||
for band 430 - 438 MHz. Unused if calibrate is set to false, defaults to 4 MHz
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq, bool calibrate, float band = 4);
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are in range from -9 to 22 dBm (high-power PA) or -17 to 14 dBm (low-power PA).
|
||||
\param power Output power to be set in dBm, output PA is determined automatically preferring the low-power PA.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are in range from -9 to 22 dBm (high-power PA), -17 to 14 dBm (low-power PA)
|
||||
or -18 to 13 dBm (high-frequency PA).
|
||||
\param power Output power to be set in dBm.
|
||||
\param forceHighPower Force using the high-power PA in sub-GHz bands, or high-frequency PA in 2.4 GHz band.
|
||||
If set to false, PA will be determined automatically based on configured output power and frequency,
|
||||
preferring the low-power PA but always using high-frequency PA in 2.4 GHz band.
|
||||
Ignored when operating in 2.4 GHz band.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power, bool forceHighPower);
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
This method is needed for compatibility with PhysicalLayer::checkOutputPower.
|
||||
\param power Output power in dBm, PA will be determined automatically.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
\param power Output power in dBm.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\param forceHighPower Force using the high-power PA. If set to false, PA will be determined automatically
|
||||
based on configured output power, preferring the low-power PA. If set to true, only high-power PA will be used.
|
||||
Ignored when operating in 2.4 GHz band.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower);
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
// flag to determine whether we are in the sub-GHz or 2.4 GHz range
|
||||
// this is needed to automatically detect which PA to use
|
||||
bool highFreq = false;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
#include "LR1121.h"
|
||||
#if !RADIOLIB_EXCLUDE_LR11X0
|
||||
|
||||
LR1121::LR1121(Module* mod) : LR1120(mod) {
|
||||
chipType = RADIOLIB_LR11X0_DEVICE_LR1121;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#if !defined(_RADIOLIB_LR1121_H)
|
||||
#define _RADIOLIB_LR1121_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_LR11X0
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "LR11x0.h"
|
||||
#include "LR1120.h"
|
||||
|
||||
/*!
|
||||
\class LR1121
|
||||
\brief Derived class for %LR1121 modules.
|
||||
*/
|
||||
class LR1121: public LR1120 {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
LR1121(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// TODO this is where overrides to disable GNSS+WiFi scanning methods on LR1121
|
||||
// will be put once those are implemented
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,38 @@
|
||||
#if !defined(_RADIOLIB_LR11X0_FIRMWARE_H)
|
||||
#define _RADIOLIB_LR11X0_FIRMWARE_H
|
||||
|
||||
#if defined(RADIOLIB_LR1110_FIRMWARE_IN_RAM)
|
||||
#define RADIOLIB_LR1110_FIRMWARE_ATTR
|
||||
#else
|
||||
#define RADIOLIB_LR1110_FIRMWARE_ATTR RADIOLIB_NONVOLATILE
|
||||
#endif
|
||||
|
||||
#define RADIOLIB_LR11X0_FIRMWARE_IMAGE_SIZE LR11XX_FIRMWARE_IMAGE_SIZE
|
||||
|
||||
#if defined(RADIOLIB_LR1110_FIRMWARE_0303)
|
||||
#include "firmware/lr1110_transceiver_0303.h"
|
||||
#elif defined(RADIOLIB_LR1110_FIRMWARE_0304)
|
||||
#include "firmware/lr1110_transceiver_0304.h"
|
||||
#elif defined(RADIOLIB_LR1110_FIRMWARE_0305)
|
||||
#include "firmware/lr1110_transceiver_0305.h"
|
||||
#elif defined(RADIOLIB_LR1110_FIRMWARE_0306)
|
||||
#include "firmware/lr1110_transceiver_0306.h"
|
||||
#elif defined(RADIOLIB_LR1110_FIRMWARE_0307)
|
||||
#include "firmware/lr1110_transceiver_0307.h"
|
||||
#elif defined(RADIOLIB_LR1110_FIRMWARE_0401)
|
||||
#include "firmware/lr1110_transceiver_0401.h"
|
||||
#elif defined(RADIOLIB_LR1120_FIRMWARE_0101)
|
||||
#include "firmware/lr1120_transceiver_0101.h"
|
||||
#elif defined(RADIOLIB_LR1120_FIRMWARE_0102)
|
||||
#include "firmware/lr1120_transceiver_0102.h"
|
||||
#elif defined(RADIOLIB_LR1120_FIRMWARE_0201)
|
||||
#include "firmware/lr1120_transceiver_0201.h"
|
||||
#elif defined(RADIOLIB_LR1121_FIRMWARE_0102)
|
||||
#include "firmware/lr1121_transceiver_0102.h"
|
||||
#elif defined(RADIOLIB_LR1121_FIRMWARE_0103)
|
||||
#include "firmware/lr1121_transceiver_0103.h"
|
||||
#else
|
||||
#error "No LR11x0 firmware image selected!"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_RFM2X)
|
||||
#if !RADIOLIB_EXCLUDE_RFM2X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "../Si443x/Si443x.h"
|
||||
@@ -11,10 +11,9 @@
|
||||
|
||||
/*!
|
||||
\class RFM22
|
||||
|
||||
\brief Only exists as alias for Si4432, since there seems to be no difference between %RFM22 and %Si4432 modules.
|
||||
*/
|
||||
RADIOLIB_TYPE_ALIAS(Si4432, RFM22);
|
||||
RADIOLIB_TYPE_ALIAS(Si4432, RFM22)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_RFM2X)
|
||||
#if !RADIOLIB_EXCLUDE_RFM2X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "../Si443x/Si443x.h"
|
||||
@@ -11,10 +11,9 @@
|
||||
|
||||
/*!
|
||||
\class RFM23
|
||||
|
||||
\brief Only exists as alias for Si4431, since there seems to be no difference between %RFM23 and %Si4431 modules.
|
||||
*/
|
||||
RADIOLIB_TYPE_ALIAS(Si4431, RFM23);
|
||||
RADIOLIB_TYPE_ALIAS(Si4431, RFM23)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
#include "RFM95.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
|
||||
|
||||
RFM95::RFM95(Module* mod) : SX1278(mod) {
|
||||
|
||||
}
|
||||
|
||||
int16_t RFM95::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength);
|
||||
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
|
||||
// SX127X_REG_VERSION might be set 0x12
|
||||
state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength);
|
||||
RADIOLIB_ASSERT(state);
|
||||
} else if(state != RADIOLIB_ERR_NONE) {
|
||||
// some other error
|
||||
return(state);
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tRFM95"));
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setBandwidth(bw);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setSpreadingFactor(sf);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setCodingRate(cr);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setGain(gain);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t RFM95::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
|
||||
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
|
||||
// SX127X_REG_VERSION might be set 0x12
|
||||
state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
|
||||
RADIOLIB_ASSERT(state);
|
||||
} else if(state != RADIOLIB_ERR_NONE) {
|
||||
// some other error
|
||||
return(state);
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tRFM95"));
|
||||
|
||||
// configure settings not accessible by API
|
||||
state = configFSK();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
if(enableOOK) {
|
||||
state = setDataShapingOOK(RADIOLIB_SHAPING_NONE);
|
||||
RADIOLIB_ASSERT(state);
|
||||
} else {
|
||||
state = setDataShaping(RADIOLIB_SHAPING_NONE);
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t RFM95::setFrequency(float freq) {
|
||||
RADIOLIB_CHECK_RANGE(freq, 862.0, 1020.0, RADIOLIB_ERR_INVALID_FREQUENCY);
|
||||
|
||||
// set frequency and if successful, save the new setting
|
||||
int16_t state = SX127x::setFrequencyRaw(freq);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_freq = freq;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
#if !defined(_RADIOLIB_RFM95_H)
|
||||
#define _RADIOLIB_RFM95_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "../SX127x/SX127x.h"
|
||||
#include "../SX127x/SX1278.h"
|
||||
|
||||
// SX127X_REG_VERSION
|
||||
#define RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL 0x11
|
||||
#define RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12
|
||||
|
||||
/*!
|
||||
\class RFM95
|
||||
|
||||
\brief Derived class for %RFM95 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class RFM95: public SX1278 {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
RFM95(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 868.0 MHz to 915.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
/*!
|
||||
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
|
||||
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of FSK preamble in bits.
|
||||
|
||||
\param enableOOK Use OOK modulation instead of FSK.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 868.0 MHz to 915.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
private:
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,91 +0,0 @@
|
||||
#include "RFM96.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
|
||||
|
||||
RFM96::RFM96(Module* mod) : SX1278(mod) {
|
||||
|
||||
}
|
||||
|
||||
int16_t RFM96::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, syncWord, preambleLength);
|
||||
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
|
||||
// SX127X_REG_VERSION might be set 0x12
|
||||
state = SX127x::begin(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, syncWord, preambleLength);
|
||||
RADIOLIB_ASSERT(state);
|
||||
} else if(state != RADIOLIB_ERR_NONE) {
|
||||
// some other error
|
||||
return(state);
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tRFM96"));
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setBandwidth(bw);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setSpreadingFactor(sf);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setCodingRate(cr);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setGain(gain);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t RFM96::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
|
||||
if(state == RADIOLIB_ERR_CHIP_NOT_FOUND) {
|
||||
// SX127X_REG_VERSION might be set 0x12
|
||||
state = SX127x::beginFSK(RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL, br, freqDev, rxBw, preambleLength, enableOOK);
|
||||
RADIOLIB_ASSERT(state);
|
||||
} else if(state != RADIOLIB_ERR_NONE) {
|
||||
// some other error
|
||||
return(state);
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1278"));
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tRFM96"));
|
||||
|
||||
// configure settings not accessible by API
|
||||
state = configFSK();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
if(enableOOK) {
|
||||
state = setDataShapingOOK(RADIOLIB_SHAPING_NONE);
|
||||
RADIOLIB_ASSERT(state);
|
||||
} else {
|
||||
state = setDataShaping(RADIOLIB_SHAPING_NONE);
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t RFM96::setFrequency(float freq) {
|
||||
RADIOLIB_CHECK_RANGE(freq, 410.0, 525.0, RADIOLIB_ERR_INVALID_FREQUENCY);
|
||||
|
||||
// set frequency and if successful, save the new setting
|
||||
int16_t state = SX127x::setFrequencyRaw(freq);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_freq = freq;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,108 +0,0 @@
|
||||
#if !defined(_RADIOLIB_RFM96_H)
|
||||
#define _RADIOLIB_RFM96_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "../SX127x/SX127x.h"
|
||||
#include "../SX127x/SX1278.h"
|
||||
|
||||
// SX127X_REG_VERSION
|
||||
#define RADIOLIB_RFM9X_CHIP_VERSION_OFFICIAL 0x11
|
||||
#define RADIOLIB_RFM9X_CHIP_VERSION_UNOFFICIAL 0x12 // according to datasheet, only 0x11 should be possible, but some modules seem to have 0x12
|
||||
|
||||
/*!
|
||||
\class RFM96
|
||||
|
||||
\brief Derived class for %RFM96 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class RFM96: public SX1278 {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
RFM96(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 433.0 MHz to 470.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
/*!
|
||||
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
|
||||
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of FSK preamble in bits.
|
||||
|
||||
\param enableOOK Use OOK modulation instead of FSK.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 433.0 MHz to 470.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
private:
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
\class RFM98
|
||||
|
||||
\brief Only exists as alias for RFM96, since there seems to be no difference between %RFM96 and %RFM98 modules.
|
||||
*/
|
||||
RADIOLIB_TYPE_ALIAS(RFM96, RFM98);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,42 +0,0 @@
|
||||
#include "RFM97.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
|
||||
|
||||
RFM97::RFM97(Module* mod) : RFM95(mod) {
|
||||
|
||||
};
|
||||
|
||||
int16_t RFM97::setSpreadingFactor(uint8_t sf) {
|
||||
// check active modem
|
||||
if(getActiveModem() != RADIOLIB_SX127X_LORA) {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
uint8_t newSpreadingFactor;
|
||||
|
||||
// check allowed spreading factor values
|
||||
switch(sf) {
|
||||
case 6:
|
||||
newSpreadingFactor = RADIOLIB_SX127X_SF_6;
|
||||
break;
|
||||
case 7:
|
||||
newSpreadingFactor = RADIOLIB_SX127X_SF_7;
|
||||
break;
|
||||
case 8:
|
||||
newSpreadingFactor = RADIOLIB_SX127X_SF_8;
|
||||
break;
|
||||
case 9:
|
||||
newSpreadingFactor = RADIOLIB_SX127X_SF_9;
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||
}
|
||||
|
||||
// set spreading factor and if successful, save the new setting
|
||||
int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_sf = sf;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,49 +0,0 @@
|
||||
#if !defined(_RADIOLIB_RFM97_H)
|
||||
#define _RADIOLIB_RFM97_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_RFM9X)
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "../SX127x/SX127x.h"
|
||||
#include "../SX127x/SX1278.h"
|
||||
#include "RFM95.h"
|
||||
|
||||
/*!
|
||||
\class RFM97
|
||||
|
||||
\brief Derived class for %RFM97 modules. Overrides some methods from RFM95 due to different parameter ranges.
|
||||
*/
|
||||
class RFM97: public RFM95 {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
RFM97(Module* mod);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
private:
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+18
-27
@@ -1,5 +1,5 @@
|
||||
#include "SX1231.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX1231)
|
||||
#if !RADIOLIB_EXCLUDE_SX1231
|
||||
|
||||
SX1231::SX1231(Module* mod) : RF69(mod) {
|
||||
|
||||
@@ -7,53 +7,44 @@ SX1231::SX1231(Module* mod) : RF69(mod) {
|
||||
|
||||
int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) {
|
||||
// set module properties
|
||||
_mod->init();
|
||||
_mod->pinMode(_mod->getIrq(), INPUT);
|
||||
_mod->pinMode(_mod->getRst(), OUTPUT);
|
||||
Module* mod = this->getMod();
|
||||
mod->init();
|
||||
mod->hal->pinMode(mod->getIrq(), mod->hal->GpioModeInput);
|
||||
mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput);
|
||||
|
||||
// try to find the SX1231 chip
|
||||
uint8_t i = 0;
|
||||
bool flagFound = false;
|
||||
while((i < 10) && !flagFound) {
|
||||
int16_t version = getChipVersion();
|
||||
if((version == 0x21) || (version == 0x22) || (version == 0x23)) {
|
||||
if((version == RADIOLIB_SX123X_CHIP_REVISION_2_A) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_B) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_C)) {
|
||||
flagFound = true;
|
||||
_chipRevision = version;
|
||||
this->chipRevision = version;
|
||||
} else {
|
||||
#if defined(RADIOLIB_DEBUG)
|
||||
RADIOLIB_DEBUG_PRINT(F("SX1231 not found! ("));
|
||||
RADIOLIB_DEBUG_PRINT(i + 1);
|
||||
RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RF69_REG_VERSION == "));
|
||||
|
||||
char buffHex[12];
|
||||
sprintf(buffHex, "0x%04X", version);
|
||||
RADIOLIB_DEBUG_PRINT(buffHex);
|
||||
RADIOLIB_DEBUG_PRINT(F(", expected 0x0021 / 0x0022 / 0x0023"));
|
||||
RADIOLIB_DEBUG_PRINTLN();
|
||||
#endif
|
||||
_mod->delay(10);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("SX1231 not found! (%d of 10 tries) RF69_REG_VERSION == 0x%04X, expected 0x0021 / 0x0022 / 0x0023", i + 1, version);
|
||||
mod->hal->delay(10);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if(!flagFound) {
|
||||
RADIOLIB_DEBUG_PRINTLN(F("No SX1231 found!"));
|
||||
_mod->term();
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("No SX1231 found!");
|
||||
mod->term();
|
||||
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSX1231"));
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSX1231");
|
||||
|
||||
// configure settings not accessible by API
|
||||
int16_t state = config();
|
||||
RADIOLIB_ASSERT(state);
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tRF69"));
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tRF69");
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure bitrate
|
||||
_rxBw = 125.0;
|
||||
this->rxBandwidth = 125.0;
|
||||
state = setBitRate(br);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
@@ -84,14 +75,14 @@ int16_t SX1231::begin(float freq, float br, float freqDev, float rxBw, int8_t po
|
||||
return(state);
|
||||
}
|
||||
|
||||
// SX1231 V2a only
|
||||
if(_chipRevision == RADIOLIB_SX1231_CHIP_REVISION_2_A) {
|
||||
// SX123x V2a only
|
||||
if(this->chipRevision == RADIOLIB_SX123X_CHIP_REVISION_2_A) {
|
||||
// modify default OOK threshold value
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable OCP with 95 mA limit
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
+78
-87
@@ -3,126 +3,117 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX1231)
|
||||
#if !RADIOLIB_EXCLUDE_SX1231
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "../RF69/RF69.h"
|
||||
|
||||
#define RADIOLIB_SX1231_CHIP_REVISION_2_A 0x21
|
||||
#define RADIOLIB_SX1231_CHIP_REVISION_2_B 0x22
|
||||
#define RADIOLIB_SX1231_CHIP_REVISION_2_C 0x23
|
||||
#define RADIOLIB_SX123X_CHIP_REVISION_2_A 0x21
|
||||
#define RADIOLIB_SX123X_CHIP_REVISION_2_B 0x22
|
||||
#define RADIOLIB_SX123X_CHIP_REVISION_2_C 0x23
|
||||
|
||||
//SX1231 specific register map
|
||||
#define RADIOLIB_SX1231_REG_TEST_OOK 0x6E
|
||||
// RADIOLIB_SX1231 specific register map
|
||||
#define RADIOLIB_SX1231_REG_TEST_OOK 0x6E
|
||||
|
||||
//SX1231_REG_TEST_OOK
|
||||
#define RADIOLIB_SX1231_OOK_DELTA_THRESHOLD 0x0C
|
||||
// RADIOLIB_SX1231_REG_TEST_OOK
|
||||
#define RADIOLIB_SX1231_OOK_DELTA_THRESHOLD 0x0C
|
||||
|
||||
// SX1231_REG_DIO_MAPPING_1
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_LOW_BAT 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_MODE_READY 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_PLL_LOCK 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_SYNC_ADDRESS 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_TIMEOUT 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_RSSI 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_MODE_READY 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_TX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_LOW_BAT 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_PLL_LOCK 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_CRC_OK 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_PAYLOAD_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_SYNC_ADDRESS 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_RSSI 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_PACKET_SENT 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_TX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_LOW_BAT 0b00100000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_PLL_LOCK 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_DCLK 0b00000000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_RX_READY 0b00010000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_SYNC_ADDRESS 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_TX_READY 0b00010000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_LEVEL 0b00000000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_FULL 0b00010000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_NOT_EMPTY 0b00100000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_PLL_LOCK 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_TIMEOUT 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO2_CONT_DATA 0b00000000 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO2_PACK_FIFO_NOT_EMPTY 0b00000000 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO2_PACK_LOW_BAT 0b00001000 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO2_PACK_AUTO_MODE 0b00001100 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO2_PACK_DATA 0b00000100 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_AUTO_MODE 0b00000010 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_RSSI 0b00000000 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_RX_READY 0b00000001 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_TIMEOUT 0b00000011 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_TX_READY 0b00000001 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_FIFO_FULL 0b00000000 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_LOW_BAT 0b00000010 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_PLL_LOCK 0b00000011 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_RSSI 0b00000001 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_SYNC_ADDRESSS 0b00000010 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_TX_READY 0b00000001 // 0 1
|
||||
// RADIOLIB_SX1231_REG_DIO_MAPPING_1
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_LOW_BAT 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_MODE_READY 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_PLL_LOCK 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_SYNC_ADDRESS 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_TIMEOUT 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_RSSI 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_MODE_READY 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_CONT_TX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_LOW_BAT 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_PLL_LOCK 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_CRC_OK 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_PAYLOAD_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_SYNC_ADDRESS 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_RSSI 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_PACKET_SENT 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO0_PACK_TX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_LOW_BAT 0b00100000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_PLL_LOCK 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_DCLK 0b00000000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_RX_READY 0b00010000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_SYNC_ADDRESS 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_CONT_TX_READY 0b00010000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_LEVEL 0b00000000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_FULL 0b00010000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_FIFO_NOT_EMPTY 0b00100000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_PLL_LOCK 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO1_PACK_TIMEOUT 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO2_CONT_DATA 0b00000000 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO2_PACK_FIFO_NOT_EMPTY 0b00000000 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO2_PACK_LOW_BAT 0b00001000 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO2_PACK_AUTO_MODE 0b00001100 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO2_PACK_DATA 0b00000100 // 3 2
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_AUTO_MODE 0b00000010 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_RSSI 0b00000000 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_RX_READY 0b00000001 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_TIMEOUT 0b00000011 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_CONT_TX_READY 0b00000001 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_FIFO_FULL 0b00000000 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_LOW_BAT 0b00000010 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_PLL_LOCK 0b00000011 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_RSSI 0b00000001 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_SYNC_ADDRESSS 0b00000010 // 0 1
|
||||
#define RADIOLIB_SX1231_DIO3_PACK_TX_READY 0b00000001 // 0 1
|
||||
|
||||
// SX1231_REG_DIO_MAPPING_2
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_LOW_BAT 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_PLL_LOCK 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_TIMEOUT 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_RX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_SYNC_ADDRESS 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_TX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_LOW_BAT 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_PLL_LOCK 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_TIMEOUT 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_RSSI 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_RX_READY 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_MODE_READY 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_TX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO5_CONT_LOW_BAT 0b00100000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_CONT_MODE_READY 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_CONT_CLK_OUT 0b00000000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_CONT_RSSI 0b00010000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_PACK_LOW_BAT 0b00100000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_PACK_MODE_READY 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_PACK_CLK_OUT 0b00000000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_PACK_DATA 0b00010000 // 5 4
|
||||
// RADIOLIB_SX1231_REG_DIO_MAPPING_2
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_LOW_BAT 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_PLL_LOCK 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_TIMEOUT 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_RX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_SYNC_ADDRESS 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_CONT_TX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_LOW_BAT 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_PLL_LOCK 0b11000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_TIMEOUT 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_RSSI 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_RX_READY 0b10000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_MODE_READY 0b00000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO4_PACK_TX_READY 0b01000000 // 7 6
|
||||
#define RADIOLIB_SX1231_DIO5_CONT_LOW_BAT 0b00100000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_CONT_MODE_READY 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_CONT_CLK_OUT 0b00000000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_CONT_RSSI 0b00010000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_PACK_LOW_BAT 0b00100000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_PACK_MODE_READY 0b00110000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_PACK_CLK_OUT 0b00000000 // 5 4
|
||||
#define RADIOLIB_SX1231_DIO5_PACK_DATA 0b00010000 // 5 4
|
||||
|
||||
/*!
|
||||
\class SX1231
|
||||
|
||||
\brief Control class for %SX1231 module. Overrides some methods from RF69 due to different register values.
|
||||
*/
|
||||
class SX1231: public RF69 {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
SX1231(Module* mod);
|
||||
SX1231(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
|
||||
\param br Bit rate to be used in kbps. Defaults to 4.8 kbps.
|
||||
|
||||
\param freqDev Frequency deviation from carrier frequency in kHz Defaults to 5.0 kHz.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Defaults to 125.0 kHz.
|
||||
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
|
||||
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
private:
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
uint8_t _chipRevision = 0;
|
||||
uint8_t chipRevision = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,127 @@
|
||||
#include "SX1233.h"
|
||||
#include <math.h>
|
||||
#if !RADIOLIB_EXCLUDE_SX1231
|
||||
|
||||
SX1233::SX1233(Module* mod) : SX1231(mod) {
|
||||
|
||||
}
|
||||
|
||||
int16_t SX1233::begin(float freq, float br, float freqDev, float rxBw, int8_t power, uint8_t preambleLen) {
|
||||
// set module properties
|
||||
Module* mod = this->getMod();
|
||||
mod->init();
|
||||
mod->hal->pinMode(mod->getIrq(), mod->hal->GpioModeInput);
|
||||
mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput);
|
||||
|
||||
// try to find the SX1233 chip
|
||||
uint8_t i = 0;
|
||||
bool flagFound = false;
|
||||
while((i < 10) && !flagFound) {
|
||||
int16_t version = getChipVersion();
|
||||
if((version == RADIOLIB_SX123X_CHIP_REVISION_2_A) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_B) || (version == RADIOLIB_SX123X_CHIP_REVISION_2_C)) {
|
||||
flagFound = true;
|
||||
this->chipRevision = version;
|
||||
} else {
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("SX1231 not found! (%d of 10 tries) RF69_REG_VERSION == 0x%04X, expected 0x0021 / 0x0022 / 0x0023", i + 1, version);
|
||||
mod->hal->delay(10);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
if(!flagFound) {
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("No SX1233 found!");
|
||||
mod->term();
|
||||
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
|
||||
}
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSX1233");
|
||||
|
||||
// configure settings not accessible by API
|
||||
int16_t state = config();
|
||||
RADIOLIB_ASSERT(state);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tRF69");
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure bitrate
|
||||
this->rxBandwidth = 125.0;
|
||||
state = setBitRate(br);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure default RX bandwidth
|
||||
state = setRxBandwidth(rxBw);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure default frequency deviation
|
||||
state = setFrequencyDeviation(freqDev);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure default TX output power
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure default preamble length
|
||||
state = setPreambleLength(preambleLen);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// default sync word values 0x2D01 is the same as the default in LowPowerLab RFM69 library
|
||||
uint8_t syncWord[] = {0x2D, 0x01};
|
||||
state = setSyncWord(syncWord, 2);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set default packet length mode
|
||||
state = variablePacketLengthMode();
|
||||
if (state != RADIOLIB_ERR_NONE) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
// SX123x V2a only
|
||||
if(this->chipRevision == RADIOLIB_SX123X_CHIP_REVISION_2_A) {
|
||||
// modify default OOK threshold value
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX1231_REG_TEST_OOK, RADIOLIB_SX1231_OOK_DELTA_THRESHOLD);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable OCP with 95 mA limit
|
||||
state = mod->SPIsetRegValue(RADIOLIB_RF69_REG_OCP, RADIOLIB_RF69_OCP_ON | RADIOLIB_RF69_OCP_TRIM, 4, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t SX1233::setBitRate(float br) {
|
||||
// check high bit-rate operation
|
||||
uint8_t pllBandwidth = RADIOLIB_SX1233_PLL_BW_LOW_BIT_RATE;
|
||||
if((fabsf(br - 500.0f) < 0.1) || (fabsf(br - 600.0f) < 0.1)) {
|
||||
pllBandwidth = RADIOLIB_SX1233_PLL_BW_HIGH_BIT_RATE;
|
||||
} else {
|
||||
// datasheet says 1.2 kbps should be the smallest possible, but 0.512 works fine
|
||||
RADIOLIB_CHECK_RANGE(br, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||
}
|
||||
|
||||
|
||||
// check bitrate-bandwidth ratio
|
||||
if(!(br < 2000 * this->rxBandwidth)) {
|
||||
return(RADIOLIB_ERR_INVALID_BIT_RATE_BW_RATIO);
|
||||
}
|
||||
|
||||
// set mode to standby
|
||||
setMode(RADIOLIB_RF69_STANDBY);
|
||||
|
||||
// set PLL bandwidth
|
||||
Module* mod = this->getMod();
|
||||
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX1233_REG_TEST_PLL, pllBandwidth, 7, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set bit rate
|
||||
uint16_t bitRate = 32000 / br;
|
||||
state = mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_MSB, (bitRate & 0xFF00) >> 8, 7, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_RF69_REG_BITRATE_LSB, bitRate & 0x00FF, 7, 0);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
this->bitRate = br;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,61 @@
|
||||
#if !defined(_RADIOLIB_SX1233_H)
|
||||
#define _RADIOLIB_SX1233_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_SX1231
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "../RF69/RF69.h"
|
||||
#include "SX1231.h"
|
||||
|
||||
// RADIOLIB_SX1233 specific register map
|
||||
#define RADIOLIB_SX1233_REG_TEST_PLL 0x5F
|
||||
|
||||
// RADIOLIB_SX1233_REG_TEST_PLL
|
||||
#define RADIOLIB_SX1233_PLL_BW_HIGH_BIT_RATE 0x0C
|
||||
#define RADIOLIB_SX1233_PLL_BW_LOW_BIT_RATE 0x08
|
||||
|
||||
/*!
|
||||
\class SX1233
|
||||
\brief Control class for %SX1233 module. Overrides some methods from SX1231/RF69 due to different register values.
|
||||
*/
|
||||
class SX1233: public SX1231 {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
SX1233(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
\param br Bit rate to be used in kbps. Defaults to 4.8 kbps.
|
||||
\param freqDev Frequency deviation from carrier frequency in kHz Defaults to 5.0 kHz.
|
||||
\param rxBw Receiver bandwidth in kHz. Defaults to 125.0 kHz.
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint8_t preambleLen = 16);
|
||||
|
||||
/*!
|
||||
\brief Sets bit rate. Allowed values range from 0.5 to 300.0 kbps.
|
||||
SX1233 also allows 500 kbps and 600 kbps operation.
|
||||
NOTE: For 500 kbps rate, the receiver frequency should be offset by 50 kHz from the transmitter.
|
||||
For 600 kbps rate, the receiver frequency should be offset by 40 kHz from the transmitter.
|
||||
\param br Bit rate to be set in kbps.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setBitRate(float br) override;
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
Copyright (c) 2018 Jan Gromeš
|
||||
Copyright (c) 2022 STMicroelectronics
|
||||
|
||||
This file is licensed under the MIT License: https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "STM32WLx.h"
|
||||
#if !RADIOLIB_EXCLUDE_STM32WLX
|
||||
|
||||
STM32WLx::STM32WLx(STM32WLx_Module* mod) : SX1262(mod) { }
|
||||
|
||||
int16_t STM32WLx::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
// Execute common part
|
||||
int16_t state = SX1262::begin(freq, bw, sf, cr, syncWord, power, preambleLength, tcxoVoltage, useRegulatorLDO);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// This overrides the value in SX126x::begin()
|
||||
// On STM32WL, DIO2 is hardwired to the radio IRQ on the MCU, so it
|
||||
// should really not be used as RfSwitch control output.
|
||||
state = setDio2AsRfSwitch(false);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t STM32WLx::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
// Execute common part
|
||||
int16_t state = SX1262::beginFSK(freq, br, freqDev, rxBw, power, preambleLength, tcxoVoltage, useRegulatorLDO);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// This overrides the value in SX126x::beginFSK()
|
||||
// On STM32WL, DIO2 is hardwired to the radio IRQ on the MCU, so it
|
||||
// should really not be used as RfSwitch control output.
|
||||
state = setDio2AsRfSwitch(false);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t STM32WLx::setOutputPower(int8_t power) {
|
||||
// get current OCP configuration
|
||||
uint8_t ocp = 0;
|
||||
int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// check the user did not request power output that is not possible
|
||||
Module* mod = this->getMod();
|
||||
bool hp_supported = mod->findRfSwitchMode(MODE_TX_HP);
|
||||
bool lp_supported = mod->findRfSwitchMode(MODE_TX_LP);
|
||||
if((!lp_supported && (power < -9)) || (!hp_supported && (power > 14))) {
|
||||
// LP not supported but requested power is below HP low bound or
|
||||
// HP not supported but requested power is above LP high bound
|
||||
return(RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
}
|
||||
|
||||
// set PA config based on which PAs are supported
|
||||
bool use_hp = false;
|
||||
if(hp_supported && lp_supported) {
|
||||
// both PAs supported, use HP when above 14 dBm
|
||||
if(power > 14) {
|
||||
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
state = SX126x::setPaConfig(0x04, 0x00, 0x07); // HP output up to 22dBm
|
||||
this->txMode = MODE_TX_HP;
|
||||
use_hp = true;
|
||||
} else {
|
||||
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
state = SX126x::setPaConfig(0x04, 0x01, 0x00); // LP output up to 14dBm
|
||||
this->txMode = MODE_TX_LP;
|
||||
}
|
||||
|
||||
} else if(!hp_supported && lp_supported) {
|
||||
// only LP supported
|
||||
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
state = SX126x::setPaConfig(0x04, 0x01, 0x00);
|
||||
this->txMode = MODE_TX_LP;
|
||||
|
||||
} else if(hp_supported && !lp_supported) {
|
||||
// only HP supported
|
||||
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
state = SX126x::setPaConfig(0x04, 0x00, 0x07);
|
||||
this->txMode = MODE_TX_HP;
|
||||
use_hp = true;
|
||||
|
||||
} else {
|
||||
// neither PA is supported
|
||||
return(RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
|
||||
}
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// Apply workaround for HP only
|
||||
state = SX126x::fixPaClamping(use_hp);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set output power with default 200us ramp
|
||||
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// restore OCP configuration
|
||||
return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
|
||||
}
|
||||
|
||||
int16_t STM32WLx::clearIrqStatus(uint16_t clearIrqParams) {
|
||||
int16_t res = SX126x::clearIrqStatus(clearIrqParams);
|
||||
// The NVIC interrupt is level-sensitive, so clear away any pending
|
||||
// flag that is only set because the radio IRQ status was not cleared
|
||||
// in the interrupt (to prevent each IRQ triggering twice and allow
|
||||
// reading the irq status through the pending flag).
|
||||
SubGhz.clearPendingInterrupt();
|
||||
if(SubGhz.hasInterrupt())
|
||||
SubGhz.enableInterrupt();
|
||||
return(res);
|
||||
}
|
||||
|
||||
void STM32WLx::setDio1Action(void (*func)(void)) {
|
||||
SubGhz.attachInterrupt([func]() {
|
||||
// Because the interrupt is level-triggered, we disable it in the
|
||||
// NVIC (otherwise we would need an SPI command to clear the IRQ in
|
||||
// the radio, or it would trigger over and over again).
|
||||
SubGhz.disableInterrupt();
|
||||
func();
|
||||
});
|
||||
}
|
||||
|
||||
void STM32WLx::clearDio1Action() {
|
||||
SubGhz.detachInterrupt();
|
||||
}
|
||||
|
||||
void STM32WLx::setPacketReceivedAction(void (*func)(void)) {
|
||||
this->setDio1Action(func);
|
||||
}
|
||||
|
||||
void STM32WLx::clearPacketReceivedAction() {
|
||||
this->clearDio1Action();
|
||||
}
|
||||
|
||||
void STM32WLx::setPacketSentAction(void (*func)(void)) {
|
||||
this->setDio1Action(func);
|
||||
}
|
||||
|
||||
void STM32WLx::clearPacketSentAction() {
|
||||
this->clearDio1Action();
|
||||
}
|
||||
|
||||
void STM32WLx::setChannelScanAction(void (*func)(void)) {
|
||||
this->setDio1Action(func);
|
||||
}
|
||||
|
||||
void STM32WLx::clearChannelScanAction() {
|
||||
this->clearDio1Action();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
Copyright (c) 2018 Jan Gromeš
|
||||
Copyright (c) 2022 STMicroelectronics
|
||||
|
||||
This file is licensed under the MIT License: https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#if !defined(_RADIOLIB_STM32WLx_H)
|
||||
#define _RADIOLIB_STM32WLx_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_STM32WLX
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "SX1262.h"
|
||||
#include "STM32WLx_Module.h"
|
||||
|
||||
/*!
|
||||
\class STM32WLx
|
||||
|
||||
\brief Derived class for STM32WL modules.
|
||||
|
||||
The radio integrated into these modules is essentially the same as the
|
||||
Semtech %SX126x external radio chips, so most of the documentation for
|
||||
those also applies here.
|
||||
|
||||
One notable difference with the %SX126x radios is that this radio
|
||||
essentially combines the %SX1261 and %SX1262 by integrating both the
|
||||
low-power (LP) and high-power (HP) amplifier. See setOutputPower() and
|
||||
setRfSwitchTable() for details on how this is handled.
|
||||
*/
|
||||
class STM32WLx : public SX1262 {
|
||||
// NOTE: This class could not be named STM32WL (or STM32WLxx), since
|
||||
// those are macros defined by
|
||||
// system/Drivers/CMSIS/Device/ST/STM32WLxxx/Include/stm32wlxx.h
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
\param mod Instance of STM32WLx_Module that will be used to communicate with the radio.
|
||||
*/
|
||||
STM32WLx(STM32WLx_Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
/*!
|
||||
\brief Custom operation modes for STMWLx.
|
||||
|
||||
This splits the TX mode into two modes: Low-power and high-power.
|
||||
These constants can be used with the setRfSwitchTable() method,
|
||||
instead of the Module::OpMode_t constants.
|
||||
*/
|
||||
enum OpMode_t {
|
||||
/*! End of table marker, use \ref END_OF_MODE_TABLE constant instead */
|
||||
MODE_END_OF_TABLE = Module::MODE_END_OF_TABLE,
|
||||
/*! Idle mode */
|
||||
MODE_IDLE = Module::MODE_IDLE,
|
||||
/*! Receive mode */
|
||||
MODE_RX = Module::MODE_RX,
|
||||
/*! Low power transmission mode */
|
||||
MODE_TX_LP = Module::MODE_TX,
|
||||
/*! High power transmission mode */
|
||||
MODE_TX_HP,
|
||||
};
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\copydoc SX1262::begin
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
|
||||
/*!
|
||||
\copydoc SX1262::beginFSK
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are in range from -17 to 22 dBm.
|
||||
|
||||
This automatically switches between the low-power (LP) and high-power (HP) amplifier.
|
||||
|
||||
LP is preferred and supports -17 to +14dBm. When a higher power is
|
||||
requested (or the LP amplifier is marked as unavailable using
|
||||
setRfSwitchTable()), HP is used, which supports -9 to +22dBm. If the LP is marked as unavailable,
|
||||
HP output will be used instead.
|
||||
|
||||
\param power Output power to be set in dBm.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
/*!
|
||||
\copybrief Module::setRfSwitchTable
|
||||
|
||||
This method works like Module::setRfSwitchTable(), except that you
|
||||
should use STM32WLx::OpMode_t constants for modes, which
|
||||
distinguishes between a low-power (LP) and high-power (HP) TX mode.
|
||||
|
||||
For boards that do not support both modes, just omit the
|
||||
unsupported mode from the table and it will not be used (and the
|
||||
valid power range is adjusted by setOutputPower() accordingly).
|
||||
|
||||
Note that the setRfSwitchTable() method should be called *before* the
|
||||
begin() method, to ensure the radio knows which modes are supported
|
||||
during initialization.
|
||||
*/
|
||||
// Note: This explicitly inherits this method only to override docs
|
||||
using SX126x::setRfSwitchTable;
|
||||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when DIO1/2/3 activates.
|
||||
\param func ISR to call.
|
||||
*/
|
||||
void setDio1Action(void (*func)(void));
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine to call when DIO1/2/3 activates.
|
||||
*/
|
||||
void clearDio1Action();
|
||||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when a packet is received.
|
||||
\param func ISR to call.
|
||||
*/
|
||||
void setPacketReceivedAction(void (*func)(void)) override;
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine to call when a packet is received.
|
||||
*/
|
||||
void clearPacketReceivedAction() override;
|
||||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when a packet is sent.
|
||||
\param func ISR to call.
|
||||
*/
|
||||
void setPacketSentAction(void (*func)(void)) override;
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine to call when a packet is sent.
|
||||
*/
|
||||
void clearPacketSentAction() override;
|
||||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when a channel scan is finished.
|
||||
\param func ISR to call.
|
||||
*/
|
||||
void setChannelScanAction(void (*func)(void)) override;
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine to call when a channel scan is finished.
|
||||
*/
|
||||
void clearChannelScanAction() override;
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
virtual int16_t clearIrqStatus(uint16_t clearIrqParams) override;
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2022 STMicroelectronics
|
||||
|
||||
This file is licensed under the MIT License: https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "STM32WLx_Module.h"
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_STM32WLX
|
||||
|
||||
#include "../../ArduinoHal.h"
|
||||
|
||||
// This defines some dummy pin numbers (starting at NUM_DIGITAL_PINS to
|
||||
// guarantee these are not valid regular pin numbers) that can be passed
|
||||
// to the parent Module class, to be stored here and then passed back to
|
||||
// the overridden callbacks when these are used.
|
||||
enum {
|
||||
RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS = NUM_DIGITAL_PINS,
|
||||
RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY,
|
||||
RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ,
|
||||
RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET,
|
||||
};
|
||||
|
||||
/*!
|
||||
\class Stm32wlxHal
|
||||
\brief Hardware Abstraction Layer for STM32WL.
|
||||
*/
|
||||
class Stm32wlxHal : public ArduinoHal {
|
||||
public:
|
||||
Stm32wlxHal(): ArduinoHal(SubGhz.SPI, SubGhz.spi_settings) {}
|
||||
|
||||
/*!
|
||||
\brief Pin mode override to handle STM32WL virtual pins.
|
||||
\param dwPin Pin to set.
|
||||
\param dwMode Mode to set.
|
||||
*/
|
||||
void pinMode(uint32_t dwPin, uint32_t dwMode) {
|
||||
switch(dwPin) {
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS:
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY:
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ:
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET:
|
||||
// Nothing to do
|
||||
break;
|
||||
default:
|
||||
::pinMode(dwPin, dwMode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Digital write override to handle STM32WL virtual pins.
|
||||
\param dwPin Pin to set.
|
||||
\param dwVal Value to set.
|
||||
*/
|
||||
void digitalWrite(uint32_t dwPin, uint32_t dwVal) {
|
||||
switch (dwPin) {
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS:
|
||||
SubGhz.setNssActive(dwVal == LOW);
|
||||
break;
|
||||
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET:
|
||||
SubGhz.setResetActive(dwVal == LOW);
|
||||
break;
|
||||
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY:
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ:
|
||||
// Should not (and cannot) be written, just ignore
|
||||
break;
|
||||
|
||||
default:
|
||||
::digitalWrite(dwPin, dwVal);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Digital read override to handle STM32WL virtual pins.
|
||||
\param ulPin Pin to read.
|
||||
\returns Value read on the pin.
|
||||
*/
|
||||
uint32_t digitalRead(uint32_t ulPin) {
|
||||
switch (ulPin) {
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY:
|
||||
return(SubGhz.isBusy() ? HIGH : LOW);
|
||||
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ:
|
||||
// We cannot use the radio IRQ output directly, but since:
|
||||
// - the pending flag will be set whenever the IRQ output is set,
|
||||
// and
|
||||
// - the pending flag will be cleared (by
|
||||
// STM32WLx::clearIrqStatus()) whenever the radio IRQ output is
|
||||
// cleared,
|
||||
// the pending flag should always reflect the current radio IRQ
|
||||
// output. There is one exception: when the ISR starts the pending
|
||||
// flag is cleared by hardware and not set again until after the
|
||||
// ISR finishes, so the value is incorrect *inside* the ISR, but
|
||||
// running RadioLib code inside the ISR (especially code that
|
||||
// polls the IRQ flag) is not supported and probably broken in
|
||||
// other ways too.
|
||||
return(SubGhz.isInterruptPending() ? HIGH : LOW);
|
||||
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS:
|
||||
return(SubGhz.isNssActive() ? LOW : HIGH);
|
||||
|
||||
case RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET:
|
||||
return(SubGhz.isResetActive() ? LOW : HIGH);
|
||||
|
||||
default:
|
||||
return(::digitalRead(ulPin));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
STM32WLx_Module::STM32WLx_Module():
|
||||
Module(
|
||||
new Stm32wlxHal,
|
||||
RADIOLIB_STM32WLx_VIRTUAL_PIN_NSS,
|
||||
RADIOLIB_STM32WLx_VIRTUAL_PIN_IRQ,
|
||||
RADIOLIB_STM32WLx_VIRTUAL_PIN_RESET,
|
||||
RADIOLIB_STM32WLx_VIRTUAL_PIN_BUSY
|
||||
) {}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2022 STMicroelectronics
|
||||
|
||||
This file is licensed under the MIT License: https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#if !defined(_RADIOLIB_STM32WLX_MODULE_H)
|
||||
#define _RADIOLIB_STM32WLX_MODULE_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_STM32WLX
|
||||
|
||||
#include "../../Module.h"
|
||||
|
||||
/*!
|
||||
* \class STM32WLx_Module
|
||||
*
|
||||
* This is a subclass of Module to be used with the STM32WLx driver.
|
||||
*
|
||||
* It is used to override some callbacks, allowing access to some of the
|
||||
* radio control signals that are wired to internal registers instead of
|
||||
* actual GPIO pins.
|
||||
*/
|
||||
class STM32WLx_Module : public Module {
|
||||
// Note: We cannot easily override any methods here, since most calls
|
||||
// are non-virtual and made through a Module*, so they would not be
|
||||
// calling any overridden methods. This means this class works by
|
||||
// overriding some of the callbacks in its constructor.
|
||||
|
||||
public:
|
||||
STM32WLx_Module();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,29 +1,38 @@
|
||||
#include "SX1261.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
#if !RADIOLIB_EXCLUDE_SX126X
|
||||
|
||||
SX1261::SX1261(Module* mod): SX1262(mod) {
|
||||
|
||||
chipType = RADIOLIB_SX1261_CHIP_TYPE;
|
||||
}
|
||||
|
||||
int16_t SX1261::setOutputPower(int8_t power) {
|
||||
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
// check if power value is configurable
|
||||
int16_t state = checkOutputPower(power, NULL);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// get current OCP configuration
|
||||
uint8_t ocp = 0;
|
||||
int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
|
||||
state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set PA config
|
||||
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1261, 0x00);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set output power
|
||||
/// \todo power ramp time configuration
|
||||
state = SX126x::setTxParams(power);
|
||||
// set output power with default 200us ramp
|
||||
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// restore OCP configuration
|
||||
return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
|
||||
}
|
||||
|
||||
int16_t SX1261::checkOutputPower(int8_t power, int8_t* clipped) {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-17, RADIOLIB_MIN(14, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,39 +3,46 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
#if !RADIOLIB_EXCLUDE_SX126X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "SX126x.h"
|
||||
#include "SX1262.h"
|
||||
|
||||
//RADIOLIB_SX126X_CMD_SET_PA_CONFIG
|
||||
#define RADIOLIB_SX126X_PA_CONFIG_SX1261 0x01
|
||||
#define RADIOLIB_SX126X_PA_CONFIG_SX1261 0x01
|
||||
|
||||
//RADIOLIB_SX126X_REG_VERSION_STRING
|
||||
#define RADIOLIB_SX1261_CHIP_TYPE "SX1261"
|
||||
|
||||
/*!
|
||||
\class SX1261
|
||||
|
||||
\brief Derived class for %SX1261 modules.
|
||||
*/
|
||||
class SX1261 : public SX1262 {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
SX1261(Module* mod);
|
||||
SX1261(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are in range from -17 to 14 dBm.
|
||||
|
||||
\param power Output power to be set in dBm.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
\param power Output power in dBm.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "SX1262.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
#if !RADIOLIB_EXCLUDE_SX126X
|
||||
|
||||
SX1262::SX1262(Module* mod) : SX126x(mod) {
|
||||
|
||||
chipType = RADIOLIB_SX1262_CHIP_TYPE;
|
||||
}
|
||||
|
||||
int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
@@ -20,10 +20,10 @@ int16_t SX1262::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
state = SX126x::fixPaClamping();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = SX126x::fixPaClamping();
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
@@ -38,39 +38,59 @@ int16_t SX1262::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
state = SX126x::fixPaClamping();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = SX126x::fixPaClamping();
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1262::setFrequency(float freq) {
|
||||
return(setFrequency(freq, true));
|
||||
}
|
||||
|
||||
int16_t SX1262::setFrequency(float freq, bool calibrate) {
|
||||
RADIOLIB_CHECK_RANGE(freq, 150.0, 960.0, RADIOLIB_ERR_INVALID_FREQUENCY);
|
||||
|
||||
// calibrate image
|
||||
// calibrate image rejection
|
||||
if(calibrate) {
|
||||
uint8_t data[2];
|
||||
if(freq > 900.0) {
|
||||
uint8_t data[2] = { 0, 0 };
|
||||
|
||||
// try to match the frequency ranges
|
||||
int freqBand = (int)freq;
|
||||
if((freqBand >= 902) && (freqBand <= 928)) {
|
||||
data[0] = RADIOLIB_SX126X_CAL_IMG_902_MHZ_1;
|
||||
data[1] = RADIOLIB_SX126X_CAL_IMG_902_MHZ_2;
|
||||
} else if(freq > 850.0) {
|
||||
} else if((freqBand >= 863) && (freqBand <= 870)) {
|
||||
data[0] = RADIOLIB_SX126X_CAL_IMG_863_MHZ_1;
|
||||
data[1] = RADIOLIB_SX126X_CAL_IMG_863_MHZ_2;
|
||||
} else if(freq > 770.0) {
|
||||
} else if((freqBand >= 779) && (freqBand <= 787)) {
|
||||
data[0] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_1;
|
||||
data[1] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_2;
|
||||
} else if(freq > 460.0) {
|
||||
} else if((freqBand >= 470) && (freqBand <= 510)) {
|
||||
data[0] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_1;
|
||||
data[1] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_2;
|
||||
} else {
|
||||
} else if((freqBand >= 430) && (freqBand <= 440)) {
|
||||
data[0] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_1;
|
||||
data[1] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_2;
|
||||
}
|
||||
int16_t state = SX126x::calibrateImage(data);
|
||||
|
||||
int16_t state;
|
||||
if(data[0]) {
|
||||
// matched with predefined ranges, do the calibration
|
||||
state = SX126x::calibrateImage(data);
|
||||
|
||||
} else {
|
||||
// if nothing matched, try custom calibration - the may or may not work
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("Failed to match predefined frequency range, trying custom");
|
||||
state = SX126x::calibrateImageRejection(freq - 4.0f, freq + 4.0f);
|
||||
|
||||
}
|
||||
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
}
|
||||
|
||||
// set frequency
|
||||
@@ -78,24 +98,33 @@ int16_t SX1262::setFrequency(float freq, bool calibrate) {
|
||||
}
|
||||
|
||||
int16_t SX1262::setOutputPower(int8_t power) {
|
||||
RADIOLIB_CHECK_RANGE(power, -17, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
// check if power value is configurable
|
||||
int16_t state = checkOutputPower(power, NULL);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// get current OCP configuration
|
||||
uint8_t ocp = 0;
|
||||
int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
|
||||
state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set PA config
|
||||
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1262);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set output power
|
||||
/// \todo power ramp time configuration
|
||||
state = SX126x::setTxParams(power);
|
||||
// set output power with default 200us ramp
|
||||
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// restore OCP configuration
|
||||
return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
|
||||
}
|
||||
|
||||
int16_t SX1262::checkOutputPower(int8_t power, int8_t* clipped) {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,99 +3,99 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
#if !RADIOLIB_EXCLUDE_SX126X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "SX126x.h"
|
||||
|
||||
//RADIOLIB_SX126X_CMD_SET_PA_CONFIG
|
||||
#define RADIOLIB_SX126X_PA_CONFIG_SX1262 0x00
|
||||
#define RADIOLIB_SX126X_PA_CONFIG_SX1262 0x00
|
||||
|
||||
//RADIOLIB_SX126X_REG_VERSION_STRING
|
||||
// Note: this should really be "2", however, it seems that all SX1262 devices report as SX1261
|
||||
#define RADIOLIB_SX1262_CHIP_TYPE "SX1261"
|
||||
|
||||
/*!
|
||||
\class SX1262
|
||||
|
||||
\brief Derived class for %SX1262 modules.
|
||||
*/
|
||||
class SX1262: public SX126x {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
SX1262(Module* mod);
|
||||
SX1262(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method for LoRa modem.
|
||||
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
|
||||
\param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz.
|
||||
|
||||
\param sf LoRa spreading factor. Defaults to 9.
|
||||
|
||||
\param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
|
||||
|
||||
\param syncWord 2-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
|
||||
|
||||
\param syncWord 1-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
|
||||
\param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols.
|
||||
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip.
|
||||
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set SX126x::XTAL to true.
|
||||
\param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
|
||||
\param br FSK bit rate in kbps. Defaults to 4.8 kbps.
|
||||
|
||||
\param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 5.0 kHz.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz.
|
||||
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
|
||||
\parma preambleLength FSK preamble length in bits. Defaults to 16 bits.
|
||||
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip.
|
||||
|
||||
\param preambleLength FSK preamble length in bits. Defaults to 16 bits.
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set SX126x::XTAL to true.
|
||||
\param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\param calibrate Run image calibration.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq, bool calibrate = true);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are in range from -17 to 22 dBm.
|
||||
|
||||
\param power Output power to be set in dBm.
|
||||
|
||||
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz.
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
\param calibrate Run image calibration.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
int16_t setFrequency(float freq, bool calibrate);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are in range from -9 to 22 dBm.
|
||||
This method is virtual to allow override from the SX1261 class.
|
||||
\param power Output power to be set in dBm.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
\param power Output power in dBm.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "SX1268.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
#if !RADIOLIB_EXCLUDE_SX126X
|
||||
|
||||
SX1268::SX1268(Module* mod) : SX126x(mod) {
|
||||
|
||||
chipType = RADIOLIB_SX1268_CHIP_TYPE;
|
||||
}
|
||||
|
||||
int16_t SX1268::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, float tcxoVoltage, bool useRegulatorLDO) {
|
||||
@@ -47,25 +47,45 @@ int16_t SX1268::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1268::setFrequency(float freq) {
|
||||
return(setFrequency(freq, true));
|
||||
}
|
||||
|
||||
/// \todo integers only (all modules - frequency, data rate, bandwidth etc.)
|
||||
int16_t SX1268::setFrequency(float freq, bool calibrate) {
|
||||
RADIOLIB_CHECK_RANGE(freq, 410.0, 810.0, RADIOLIB_ERR_INVALID_FREQUENCY);
|
||||
|
||||
// calibrate image
|
||||
// calibrate image rejection
|
||||
if(calibrate) {
|
||||
uint8_t data[2];
|
||||
if(freq > 770.0) {
|
||||
uint8_t data[2] = { 0, 0 };
|
||||
|
||||
// try to match the frequency ranges
|
||||
int freqBand = (int)freq;
|
||||
if((freqBand >= 779) && (freqBand <= 787)) {
|
||||
data[0] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_1;
|
||||
data[1] = RADIOLIB_SX126X_CAL_IMG_779_MHZ_2;
|
||||
} else if(freq > 460.0) {
|
||||
} else if((freqBand >= 470) && (freqBand <= 510)) {
|
||||
data[0] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_1;
|
||||
data[1] = RADIOLIB_SX126X_CAL_IMG_470_MHZ_2;
|
||||
} else {
|
||||
} else if((freqBand >= 430) && (freqBand <= 440)) {
|
||||
data[0] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_1;
|
||||
data[1] = RADIOLIB_SX126X_CAL_IMG_430_MHZ_2;
|
||||
}
|
||||
int16_t state = SX126x::calibrateImage(data);
|
||||
|
||||
int16_t state;
|
||||
if(data[0]) {
|
||||
// matched with predefined ranges, do the calibration
|
||||
state = SX126x::calibrateImage(data);
|
||||
|
||||
} else {
|
||||
// if nothing matched, try custom calibration - the may or may not work
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("Failed to match predefined frequency range, trying custom");
|
||||
state = SX126x::calibrateImageRejection(freq - 4.0f, freq + 4.0f);
|
||||
|
||||
}
|
||||
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
}
|
||||
|
||||
// set frequency
|
||||
@@ -73,24 +93,33 @@ int16_t SX1268::setFrequency(float freq, bool calibrate) {
|
||||
}
|
||||
|
||||
int16_t SX1268::setOutputPower(int8_t power) {
|
||||
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
// check if power value is configurable
|
||||
int16_t state = checkOutputPower(power, NULL);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// get current OCP configuration
|
||||
uint8_t ocp = 0;
|
||||
int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
|
||||
state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set PA config
|
||||
state = SX126x::setPaConfig(0x04, RADIOLIB_SX126X_PA_CONFIG_SX1268);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set output power
|
||||
/// \todo power ramp time configuration
|
||||
state = SX126x::setTxParams(power);
|
||||
// set output power with default 200us ramp
|
||||
state = SX126x::setTxParams(power, RADIOLIB_SX126X_PA_RAMP_200U);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// restore OCP configuration
|
||||
return(writeRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1));
|
||||
}
|
||||
|
||||
int16_t SX1268::checkOutputPower(int8_t power, int8_t* clipped) {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-9, RADIOLIB_MIN(22, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,72 +3,60 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX126X)
|
||||
#if !RADIOLIB_EXCLUDE_SX126X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "SX126x.h"
|
||||
|
||||
//RADIOLIB_SX126X_CMD_SET_PA_CONFIG
|
||||
#define RADIOLIB_SX126X_PA_CONFIG_SX1268 0x00
|
||||
#define RADIOLIB_SX126X_PA_CONFIG_SX1268 0x00
|
||||
|
||||
//RADIOLIB_SX126X_REG_VERSION_STRING
|
||||
#define RADIOLIB_SX1268_CHIP_TYPE "SX1268"
|
||||
|
||||
/*!
|
||||
\class SX1268
|
||||
|
||||
\brief Derived class for %SX1268 modules.
|
||||
*/
|
||||
class SX1268: public SX126x {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
SX1268(Module* mod);
|
||||
SX1268(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method for LoRa modem.
|
||||
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
|
||||
\param bw LoRa bandwidth in kHz. Defaults to 125.0 kHz.
|
||||
|
||||
\param sf LoRa spreading factor. Defaults to 9.
|
||||
|
||||
\param cr LoRa coding rate denominator. Defaults to 7 (coding rate 4/7).
|
||||
|
||||
\param syncWord 2-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
|
||||
|
||||
\param syncWord 1-byte LoRa sync word. Defaults to RADIOLIB_SX126X_SYNC_WORD_PRIVATE (0x12).
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
|
||||
\param preambleLength LoRa preamble length in symbols. Defaults to 8 symbols.
|
||||
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip.
|
||||
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set SX126x::XTAL to true.
|
||||
\param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX126X_SYNC_WORD_PRIVATE, int8_t power = 10, uint16_t preambleLength = 8, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem.
|
||||
|
||||
\param freq Carrier frequency in MHz. Defaults to 434.0 MHz.
|
||||
|
||||
\param br FSK bit rate in kbps. Defaults to 4.8 kbps.
|
||||
|
||||
\param freqDev Frequency deviation from carrier frequency in kHz. Defaults to 5.0 kHz.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Defaults to 156.2 kHz.
|
||||
|
||||
\param power Output power in dBm. Defaults to 10 dBm.
|
||||
|
||||
\parma preambleLength FSK preamble length in bits. Defaults to 16 bits.
|
||||
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V, set to 0 to skip.
|
||||
|
||||
\param preambleLength FSK preamble length in bits. Defaults to 16 bits.
|
||||
\param tcxoVoltage TCXO reference voltage to be set on DIO3. Defaults to 1.6 V.
|
||||
If you are seeing -706/-707 error codes, it likely means you are using non-0 value for module with XTAL.
|
||||
To use XTAL, either set this value to 0, or set SX126x::XTAL to true.
|
||||
\param useRegulatorLDO Whether to use only LDO regulator (true) or DC-DC regulator (false). Defaults to false.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 156.2, int8_t power = 10, uint16_t preambleLength = 16, float tcxoVoltage = 1.6, bool useRegulatorLDO = false);
|
||||
@@ -77,25 +65,35 @@ class SX1268: public SX126x {
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values are in range from 410.0 to 810.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\param calibrate Run image calibration.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq, bool calibrate = true);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values are in range from 150.0 to 960.0 MHz.
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
\param calibrate Run image calibration.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq, bool calibrate);
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are in range from -9 to 22 dBm.
|
||||
|
||||
\param power Output power to be set in dBm.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
\param power Output power in dBm.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Binary in this file originates from https://github.com/Lora-net/sx1302_hal/tree/master
|
||||
As such, license of the above repository is reproduced here.
|
||||
|
||||
Copyright (c) 2019, SEMTECH S.A.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Semtech corporation nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL SEMTECH S.A. BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if !defined(_RADIOLIB_SX126X_PATCH_SCAN_H)
|
||||
#define _RADIOLIB_SX126X_PATCH_SCAN_H
|
||||
|
||||
#include "../../../TypeDef.h"
|
||||
|
||||
#if !RADIOLIB_EXCLUDE_SX126X
|
||||
|
||||
// the following is a binary patch to the SX1262
|
||||
// this patch is needed to enable spectral scan functionality
|
||||
const uint32_t sx126x_patch_scan[] RADIOLIB_NONVOLATILE = {
|
||||
0x337fe1, 0x337fdb, 0x337fd5, 0x337fcf, 0x3a7fc8, 0x3f3fff,
|
||||
0x0378ff, 0x0379ff, 0x3a7fb7, 0x16a901, 0x16a801, 0x23ffff,
|
||||
0x0378ff, 0x0379ff, 0x3a7faf, 0x16a901, 0x16a801, 0x23ffff,
|
||||
0x0378ff, 0x0379ff, 0x3a7f34, 0x16a901, 0x16a801, 0x23ffff,
|
||||
0x0378ff, 0x0379ff, 0x3a7e80, 0x16a901, 0x16a801, 0x23ffff,
|
||||
0x0378ff, 0x0379ff, 0x3a7fc3, 0x16a901, 0x16a801, 0x337fc9,
|
||||
0x0378ff, 0x0379ff, 0x3a7fc0, 0x16a901, 0x16a801, 0x337fc9,
|
||||
0x0378ff, 0x0379ff, 0x3a7fbd, 0x16a901, 0x16a801, 0x337fc9,
|
||||
0x0378ff, 0x0379ff, 0x3a7fba, 0x16a901, 0x16a801, 0x337fc9,
|
||||
0x23ffff, 0x0ea1fc, 0x0ea0df, 0x0eafc9, 0x02cf0e, 0x23ffff,
|
||||
0x0eacff, 0x0eabff, 0x23ffff, 0x0eacff, 0x0eabff, 0x23ffff,
|
||||
0x0eacff, 0x0eabff, 0x23ffff, 0x0eacff, 0x0eabff, 0x23ffff,
|
||||
0x0378ff, 0x0379ff, 0x3a7fc8, 0x0eacfd, 0x0eabff, 0x16a901,
|
||||
0x16a801, 0x23ffff, 0x0374ff, 0x0375ff, 0x0378ff, 0x0379ff,
|
||||
0x16affe, 0x0ea5ff, 0x0ea465, 0x1dbb04, 0x0e1bfd, 0x307fa3,
|
||||
0x1caf00, 0x327fa0, 0x0eacf7, 0x0eabff, 0x337f3a, 0x1cad04,
|
||||
0x0eacfe, 0x0eabff, 0x0dbfdd, 0x307f97, 0x0dafcc, 0x0defbb,
|
||||
0x0dbfdd, 0x347f9b, 0x0eecef, 0x0caffc, 0x04ade8, 0x0cbdcd,
|
||||
0x01bde8, 0x04abe8, 0x0ebbbf, 0x01bbe8, 0x04abe8, 0x0ebbdf,
|
||||
0x01bbe8, 0x1ca800, 0x0ea9ff, 0x04abe3, 0x0e2b01, 0x01bbe3,
|
||||
0x04abee, 0x0e2b01, 0x01bbee, 0x1ca202, 0x1ca301, 0x02f300,
|
||||
0x02f201, 0x0ea064, 0x0ea1f7, 0x18ab00, 0x367f58, 0x0ea041,
|
||||
0x0ea1f7, 0x18ab00, 0x1c1b03, 0x317f3f, 0x1ea201, 0x1ea300,
|
||||
0x0cb23f, 0x327f4a, 0x1cab04, 0x0eaefe, 0x0dbfbb, 0x307f6c,
|
||||
0x0dafee, 0x0dbfbb, 0x347f6f, 0x04abee, 0x0cbbeb, 0x01bbee,
|
||||
0x0eacff, 0x0eabff, 0x0c1b9f, 0x327f64, 0x0c1c8f, 0x317f5c,
|
||||
0x3fffff, 0x0d1fcc, 0x0d5fbb, 0x0c1b9f, 0x327f5d, 0x0c1c8f,
|
||||
0x357f63, 0x0ea064, 0x0ea1f7, 0x18ab00, 0x327f7c, 0x1cad04,
|
||||
0x0eacfe, 0x0dbfdd, 0x307f51, 0x0dafcc, 0x0dbfdd, 0x347f54,
|
||||
0x0d8fcb, 0x04acee, 0x0c2bcb, 0x01bbee, 0x0eacfd, 0x0eabff,
|
||||
0x337f3a, 0x1cad04, 0x0eacfe, 0x0dbfdd, 0x307f43, 0x0dafcc,
|
||||
0x0dbfdd, 0x347f46, 0x0d8fcb, 0x04acee, 0x0c2bcb, 0x337f6a,
|
||||
0x0cb23f, 0x367f75, 0x0dbf22, 0x0dff33, 0x337f75, 0x16af02,
|
||||
0x16a901, 0x16a801, 0x16a501, 0x16a401, 0x23ffff, 0x0374ff,
|
||||
0x0375ff, 0x0378ff, 0x0379ff, 0x16afe0, 0x0ea5ff, 0x0ea465,
|
||||
0x1ca802, 0x0ea9ff, 0x0eafff, 0x02ff00, 0x0eaff7, 0x02ff01,
|
||||
0x0eafef, 0x02ff02, 0x0eafe7, 0x02ff03, 0x0eafdf, 0x02ff04,
|
||||
0x0eafd7, 0x02ff05, 0x0eafcf, 0x02ff06, 0x0eafc7, 0x02ff07,
|
||||
0x0eafbf, 0x02ff08, 0x0eafb7, 0x02ff09, 0x0eafaf, 0x02ff0a,
|
||||
0x0eafa7, 0x02ff0b, 0x0eaf9f, 0x02ff0c, 0x0eaf97, 0x02ff0d,
|
||||
0x0eaf8f, 0x02ff0e, 0x0eaf87, 0x02ff0f, 0x0eaf7f, 0x02ff10,
|
||||
0x0eaf77, 0x02ff11, 0x0eaf6f, 0x02ff12, 0x0eaf67, 0x02ff13,
|
||||
0x0eaf5f, 0x02ff14, 0x0eaf57, 0x02ff15, 0x0eaf4f, 0x02ff16,
|
||||
0x0eaf47, 0x02ff17, 0x0eaf3f, 0x02ff18, 0x0eaf37, 0x02ff19,
|
||||
0x0eaf2f, 0x02ff1a, 0x0eaf27, 0x02ff1b, 0x0eaf1f, 0x02ff1c,
|
||||
0x0eaf17, 0x02ff1d, 0x0eaf0f, 0x02ff1e, 0x0eaf07, 0x02ff1f,
|
||||
0x04abee, 0x0e2b01, 0x01bbee, 0x0eacff, 0x0eabff, 0x0cafc0,
|
||||
0x0ec0ff, 0x0cafb1, 0x0ed1fb, 0x0eafff, 0x02cf00, 0x0d1fcc,
|
||||
0x0d5fbb, 0x0e1bff, 0x327edb, 0x0e1c00, 0x347ee6, 0x0ea2ff,
|
||||
0x0ea3ff, 0x0ea032, 0x0ea1f8, 0x0eaff0, 0x02cf00, 0x0ea064,
|
||||
0x0ea1f7, 0x18ad00, 0x1c1300, 0x327ece, 0x1c1201, 0x317e9b,
|
||||
0x0e1dff, 0x367e9b, 0x0ea041, 0x0ea1f7, 0x18ab00, 0x0eebdf,
|
||||
0x0cafbc, 0x0eabff, 0x0ccccc, 0x0cdbbb, 0x0cafc0, 0x0ec0ff,
|
||||
0x0cafb1, 0x0ed1fb, 0x18ab01, 0x0eacff, 0x18ae02, 0x0eadff,
|
||||
0x0ccecc, 0x0cddbb, 0x0d1fcc, 0x0d5fbb, 0x0cafbe, 0x0eadff,
|
||||
0x02ce01, 0x02cc02, 0x0d1f22, 0x0d5f33, 0x0ea064, 0x0ea1f7,
|
||||
0x18ad00, 0x0eacff, 0x0eabff, 0x0c1b9f, 0x327ea9, 0x0c1c8f,
|
||||
0x317ea1, 0x3fffff, 0x0d1fcc, 0x0d5fbb, 0x0c1b9f, 0x327ea2,
|
||||
0x0c1c8f, 0x357ea8, 0x1c1300, 0x327e9e, 0x1c1201, 0x317e9b,
|
||||
0x0e1dff, 0x327ecb, 0x0e1dff, 0x367e90, 0x0ea032, 0x0ea1f8,
|
||||
0x0eaf00, 0x02cf00, 0x0ea1fb, 0x0ea0ff, 0x0eaf00, 0x02cf00,
|
||||
0x337e88, 0x0ea032, 0x0ea1f8, 0x0eaf0f, 0x02cf00, 0x0ea1fb,
|
||||
0x0ea0ff, 0x0eaf0f, 0x02cf00, 0x0eacfd, 0x0eabff, 0x16af20,
|
||||
0x16a901, 0x16a801, 0x16a501, 0x16a401, 0x23ffff, 0x0eacf7,
|
||||
0x0eabff, 0x23ffff
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "SX1272.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#include <math.h>
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
SX1272::SX1272(Module* mod) : SX127x(mod) {
|
||||
|
||||
@@ -7,7 +8,8 @@ SX1272::SX1272(Module* mod) : SX127x(mod) {
|
||||
|
||||
int16_t SX1272::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::begin(RADIOLIB_SX1272_CHIP_VERSION, syncWord, preambleLength);
|
||||
uint8_t version = RADIOLIB_SX1272_CHIP_VERSION;
|
||||
int16_t state = SX127x::begin(&version, 1, syncWord, preambleLength);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
@@ -29,12 +31,17 @@ int16_t SX1272::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
|
||||
state = setGain(gain);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set publicly accessible settings that are not a part of begin method
|
||||
state = setCRC(true);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1272::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::beginFSK(RADIOLIB_SX1272_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
|
||||
uint8_t version = RADIOLIB_SX1272_CHIP_VERSION;
|
||||
int16_t state = SX127x::beginFSK(&version, 1, freqDev, rxBw, preambleLength, enableOOK);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure settings not accessible by API
|
||||
@@ -45,6 +52,9 @@ int16_t SX1272::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setBitRate(br);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
@@ -56,15 +66,20 @@ int16_t SX1272::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
// set publicly accessible settings that are not a part of begin method
|
||||
state = setCRC(true);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
void SX1272::reset() {
|
||||
_mod->pinMode(_mod->getRst(), OUTPUT);
|
||||
_mod->digitalWrite(_mod->getRst(), HIGH);
|
||||
_mod->delay(1);
|
||||
_mod->digitalWrite(_mod->getRst(), LOW);
|
||||
_mod->delay(5);
|
||||
Module* mod = this->getMod();
|
||||
mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput);
|
||||
mod->hal->digitalWrite(mod->getRst(), mod->hal->GpioLevelHigh);
|
||||
mod->hal->delay(1);
|
||||
mod->hal->digitalWrite(mod->getRst(), mod->hal->GpioLevelLow);
|
||||
mod->hal->delay(5);
|
||||
}
|
||||
|
||||
int16_t SX1272::setFrequency(float freq) {
|
||||
@@ -73,7 +88,7 @@ int16_t SX1272::setFrequency(float freq) {
|
||||
// set frequency and if successful, save the new setting
|
||||
int16_t state = SX127x::setFrequencyRaw(freq);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_freq = freq;
|
||||
SX127x::frequency = freq;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
@@ -87,11 +102,11 @@ int16_t SX1272::setBandwidth(float bw) {
|
||||
uint8_t newBandwidth;
|
||||
|
||||
// check allowed bandwidth values
|
||||
if(fabs(bw - 125.0) <= 0.001) {
|
||||
if(fabsf(bw - 125.0) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1272_BW_125_00_KHZ;
|
||||
} else if(fabs(bw - 250.0) <= 0.001) {
|
||||
} else if(fabsf(bw - 250.0) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1272_BW_250_00_KHZ;
|
||||
} else if(fabs(bw - 500.0) <= 0.001) {
|
||||
} else if(fabsf(bw - 500.0) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1272_BW_500_00_KHZ;
|
||||
} else {
|
||||
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||
@@ -100,18 +115,16 @@ int16_t SX1272::setBandwidth(float bw) {
|
||||
// set bandwidth and if successful, save the new setting
|
||||
int16_t state = SX1272::setBandwidthRaw(newBandwidth);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_bw = bw;
|
||||
SX127x::bandwidth = bw;
|
||||
|
||||
// calculate symbol length and set low data rate optimization, if auto-configuration is enabled
|
||||
if(_ldroAuto) {
|
||||
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
||||
RADIOLIB_DEBUG_PRINT("Symbol length: ");
|
||||
RADIOLIB_DEBUG_PRINT(symbolLength);
|
||||
RADIOLIB_DEBUG_PRINTLN(" ms");
|
||||
if(this->ldroAuto) {
|
||||
float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth;
|
||||
Module* mod = this->getMod();
|
||||
if(symbolLength >= 16.0) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
|
||||
} else {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,18 +169,16 @@ int16_t SX1272::setSpreadingFactor(uint8_t sf) {
|
||||
// set spreading factor and if successful, save the new setting
|
||||
int16_t state = SX1272::setSpreadingFactorRaw(newSpreadingFactor);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_sf = sf;
|
||||
SX127x::spreadingFactor = sf;
|
||||
|
||||
// calculate symbol length and set low data rate optimization, if auto-configuration is enabled
|
||||
if(_ldroAuto) {
|
||||
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
||||
RADIOLIB_DEBUG_PRINT("Symbol length: ");
|
||||
RADIOLIB_DEBUG_PRINT(symbolLength);
|
||||
RADIOLIB_DEBUG_PRINTLN(" ms");
|
||||
if(this->ldroAuto) {
|
||||
float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth;
|
||||
Module* mod = this->getMod();
|
||||
if(symbolLength >= 16.0) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0);
|
||||
} else {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -203,40 +214,98 @@ int16_t SX1272::setCodingRate(uint8_t cr) {
|
||||
// set coding rate and if successful, save the new setting
|
||||
int16_t state = SX1272::setCodingRateRaw(newCodingRate);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_cr = cr;
|
||||
SX127x::codingRate = cr;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1272::setOutputPower(int8_t power, bool useRfo) {
|
||||
// check allowed power range
|
||||
if(useRfo) {
|
||||
RADIOLIB_CHECK_RANGE(power, -1, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
} else {
|
||||
RADIOLIB_CHECK_RANGE(power, 2, 20, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
int16_t SX1272::setBitRate(float br) {
|
||||
return(SX127x::setBitRateCommon(br, RADIOLIB_SX1272_REG_BIT_RATE_FRAC));
|
||||
}
|
||||
|
||||
int16_t SX1272::setDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
uint8_t modem = this->getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
// set the bit rate
|
||||
state = this->setBitRate(dr.fsk.bitRate);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the frequency deviation
|
||||
state = this->setFrequencyDeviation(dr.fsk.freqDev);
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||
// set the spreading factor
|
||||
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the bandwidth
|
||||
state = this->setBandwidth(dr.lora.bandwidth);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the coding rate
|
||||
state = this->setCodingRate(dr.lora.codingRate);
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1272::checkDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
int16_t modem = getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
|
||||
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 12, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1272::setOutputPower(int8_t power) {
|
||||
return(this->setOutputPower(power, false));
|
||||
}
|
||||
|
||||
int16_t SX1272::setOutputPower(int8_t power, bool useRfo) {
|
||||
// check if power value is configurable
|
||||
int16_t state = checkOutputPower(power, NULL, useRfo);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set mode to standby
|
||||
int16_t state = SX127x::standby();
|
||||
state = SX127x::standby();
|
||||
Module* mod = this->getMod();
|
||||
|
||||
if(useRfo) {
|
||||
// RFO output
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power + 1), 3, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power + 1), 3, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
|
||||
|
||||
} else {
|
||||
if(power <= 17) {
|
||||
// power is 2 - 17 dBm, enable PA1 + PA2 on PA_BOOST
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 2), 3, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 2), 3, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
|
||||
|
||||
} else {
|
||||
// power is 18 - 20 dBm, enable PA1 + PA2 on PA_BOOST and enable high power control
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 5), 3, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, (power - 5), 3, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0);
|
||||
|
||||
}
|
||||
|
||||
@@ -245,6 +314,26 @@ int16_t SX1272::setOutputPower(int8_t power, bool useRfo) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1272::checkOutputPower(int8_t power, int8_t* clipped) {
|
||||
return(checkOutputPower(power, clipped, false));
|
||||
}
|
||||
|
||||
int16_t SX1272::checkOutputPower(int8_t power, int8_t* clipped, bool useRfo) {
|
||||
// check allowed power range
|
||||
if(useRfo) {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-1, RADIOLIB_MIN(14, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -1, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
} else {
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(2, RADIOLIB_MIN(20, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, 2, 20, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t SX1272::setGain(uint8_t gain) {
|
||||
// check allowed range
|
||||
if(gain > 6) {
|
||||
@@ -253,27 +342,28 @@ int16_t SX1272::setGain(uint8_t gain) {
|
||||
|
||||
// set mode to standby
|
||||
int16_t state = SX127x::standby();
|
||||
Module* mod = this->getMod();
|
||||
|
||||
// get modem
|
||||
int16_t modem = getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_LORA){
|
||||
if(modem == RADIOLIB_SX127X_LORA) {
|
||||
// set gain
|
||||
if(gain == 0) {
|
||||
// gain set to 0, enable AGC loop
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_ON, 2, 2);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_ON, 2, 2);
|
||||
} else {
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_OFF, 2, 2);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_AGC_AUTO_OFF, 2, 2);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
|
||||
}
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
// set gain
|
||||
if(gain == 0) {
|
||||
// gain set to 0, enable AGC loop
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
|
||||
} else {
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -288,7 +378,7 @@ int16_t SX1272::setDataShaping(uint8_t sh) {
|
||||
}
|
||||
|
||||
// check modulation
|
||||
if(SX127x::_ook) {
|
||||
if(SX127x::ookEnabled) {
|
||||
return(RADIOLIB_ERR_INVALID_MODULATION);
|
||||
}
|
||||
|
||||
@@ -297,15 +387,16 @@ int16_t SX1272::setDataShaping(uint8_t sh) {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set data shaping
|
||||
Module* mod = this->getMod();
|
||||
switch(sh) {
|
||||
case RADIOLIB_SHAPING_NONE:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3));
|
||||
case RADIOLIB_SHAPING_0_3:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_3, 4, 3));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_3, 4, 3));
|
||||
case RADIOLIB_SHAPING_0_5:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_5, 4, 3));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_0_5, 4, 3));
|
||||
case RADIOLIB_SHAPING_1_0:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_1_0, 4, 3));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_FSK_GAUSSIAN_1_0, 4, 3));
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_DATA_SHAPING);
|
||||
}
|
||||
@@ -318,7 +409,7 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) {
|
||||
}
|
||||
|
||||
// check modulation
|
||||
if(!SX127x::_ook) {
|
||||
if(!SX127x::ookEnabled) {
|
||||
return(RADIOLIB_ERR_INVALID_MODULATION);
|
||||
}
|
||||
|
||||
@@ -326,15 +417,16 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) {
|
||||
int16_t state = SX127x::standby();
|
||||
|
||||
// set data shaping
|
||||
Module* mod = this->getMod();
|
||||
switch(sh) {
|
||||
case 0:
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_NO_SHAPING, 4, 3);
|
||||
break;
|
||||
case 1:
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_BR, 4, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_BR, 4, 3);
|
||||
break;
|
||||
case 2:
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_2BR, 4, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_OP_MODE, RADIOLIB_SX1272_OOK_FILTER_2BR, 4, 3);
|
||||
break;
|
||||
default:
|
||||
state = RADIOLIB_ERR_INVALID_DATA_SHAPING;
|
||||
@@ -344,63 +436,39 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
float SX1272::getRSSI(bool skipReceive) {
|
||||
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
|
||||
// RSSI calculation uses different constant for low-frequency and high-frequency ports
|
||||
float lastPacketRSSI = -139 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
|
||||
float SX1272::getRSSI() {
|
||||
return(SX1272::getRSSI(true, false));
|
||||
}
|
||||
|
||||
// spread-spectrum modulation signal can be received below noise floor
|
||||
// check last packet SNR and if it's less than 0, add it to reported RSSI to get the correct value
|
||||
float lastPacketSNR = SX127x::getSNR();
|
||||
if(lastPacketSNR < 0.0) {
|
||||
lastPacketRSSI += lastPacketSNR;
|
||||
}
|
||||
|
||||
return(lastPacketRSSI);
|
||||
|
||||
} else {
|
||||
// enable listen mode
|
||||
if(!skipReceive) {
|
||||
startReceive();
|
||||
}
|
||||
|
||||
// read the value for FSK
|
||||
float rssi = (float)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0;
|
||||
|
||||
// set mode back to standby
|
||||
if(!skipReceive) {
|
||||
standby();
|
||||
}
|
||||
|
||||
// return the value
|
||||
return(rssi);
|
||||
}
|
||||
float SX1272::getRSSI(bool packet, bool skipReceive) {
|
||||
return(SX127x::getRSSI(packet, skipReceive, -139));
|
||||
}
|
||||
|
||||
int16_t SX1272::setCRC(bool enable, bool mode) {
|
||||
Module* mod = this->getMod();
|
||||
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
|
||||
// set LoRa CRC
|
||||
SX127x::_crcEnabled = enable;
|
||||
SX127x::crcEnabled = enable;
|
||||
if(enable) {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_RX_CRC_MODE_ON, 2, 2));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_RX_CRC_MODE_ON, 1, 1));
|
||||
} else {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1272_RX_CRC_MODE_OFF, 2, 2));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_RX_CRC_MODE_OFF, 1, 1));
|
||||
}
|
||||
} else {
|
||||
// set FSK CRC
|
||||
int16_t state = RADIOLIB_ERR_NONE;
|
||||
if(enable) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4);
|
||||
} else {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4);
|
||||
}
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set FSK CRC mode
|
||||
if(mode) {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0));
|
||||
} else {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -410,11 +478,12 @@ int16_t SX1272::forceLDRO(bool enable) {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
_ldroAuto = false;
|
||||
this->ldroAuto = false;
|
||||
Module* mod = this->getMod();
|
||||
if(enable) {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON, 0, 0));
|
||||
} else {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,7 +492,7 @@ int16_t SX1272::autoLDRO() {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
_ldroAuto = true;
|
||||
this->ldroAuto = true;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
@@ -440,7 +509,8 @@ int16_t SX1272::setBandwidthRaw(uint8_t newBandwidth) {
|
||||
int16_t state = SX127x::standby();
|
||||
|
||||
// write register
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 6);
|
||||
Module* mod = this->getMod();
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 6);
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -449,16 +519,17 @@ int16_t SX1272::setSpreadingFactorRaw(uint8_t newSpreadingFactor) {
|
||||
int16_t state = SX127x::standby();
|
||||
|
||||
// write registers
|
||||
Module* mod = this->getMod();
|
||||
if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) {
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_IMPL_MODE | (SX127x::_crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_IMPL_MODE | (SX127x::crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
|
||||
} else {
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_EXPL_MODE | (SX127x::_crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1272_HEADER_EXPL_MODE | (SX127x::crcEnabled ? RADIOLIB_SX1272_RX_CRC_MODE_ON : RADIOLIB_SX1272_RX_CRC_MODE_OFF), 2, 1);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12);
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
@@ -468,7 +539,8 @@ int16_t SX1272::setCodingRateRaw(uint8_t newCodingRate) {
|
||||
int16_t state = SX127x::standby();
|
||||
|
||||
// write register
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 5, 3);
|
||||
Module* mod = this->getMod();
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 5, 3);
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -479,15 +551,16 @@ int16_t SX1272::setHeaderType(uint8_t headerType, size_t len) {
|
||||
}
|
||||
|
||||
// set requested packet mode
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 2, 2);
|
||||
Module* mod = this->getMod();
|
||||
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 2, 2);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set length to register
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// update cached value
|
||||
_packetLength = len;
|
||||
SX127x::packetLength = len;
|
||||
|
||||
return(state);
|
||||
}
|
||||
@@ -498,7 +571,8 @@ int16_t SX1272::configFSK() {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set fast PLL hop
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7);
|
||||
Module* mod = this->getMod();
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX1272_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7);
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -507,7 +581,8 @@ void SX1272::errataFix(bool rx) {
|
||||
|
||||
// mitigation of receiver spurious response
|
||||
// see SX1272/73 Errata, section 2.2 for details
|
||||
_mod->SPIsetRegValue(0x31, 0b10000000, 7, 7);
|
||||
Module* mod = this->getMod();
|
||||
mod->SPIsetRegValue(0x31, 0b10000000, 7, 7);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,92 +3,91 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "SX127x.h"
|
||||
|
||||
// SX1272 specific register map
|
||||
#define RADIOLIB_SX1272_REG_AGC_REF 0x43
|
||||
#define RADIOLIB_SX1272_REG_AGC_THRESH_1 0x44
|
||||
#define RADIOLIB_SX1272_REG_AGC_THRESH_2 0x45
|
||||
#define RADIOLIB_SX1272_REG_AGC_THRESH_3 0x46
|
||||
#define RADIOLIB_SX1272_REG_PLL_HOP 0x4B
|
||||
#define RADIOLIB_SX1272_REG_TCXO 0x58
|
||||
#define RADIOLIB_SX1272_REG_PA_DAC 0x5A
|
||||
#define RADIOLIB_SX1272_REG_PLL 0x5C
|
||||
#define RADIOLIB_SX1272_REG_PLL_LOW_PN 0x5E
|
||||
#define RADIOLIB_SX1272_REG_FORMER_TEMP 0x6C
|
||||
#define RADIOLIB_SX1272_REG_BIT_RATE_FRAC 0x70
|
||||
#define RADIOLIB_SX1272_REG_AGC_REF 0x43
|
||||
#define RADIOLIB_SX1272_REG_AGC_THRESH_1 0x44
|
||||
#define RADIOLIB_SX1272_REG_AGC_THRESH_2 0x45
|
||||
#define RADIOLIB_SX1272_REG_AGC_THRESH_3 0x46
|
||||
#define RADIOLIB_SX1272_REG_PLL_HOP 0x4B
|
||||
#define RADIOLIB_SX1272_REG_TCXO 0x58
|
||||
#define RADIOLIB_SX1272_REG_PA_DAC 0x5A
|
||||
#define RADIOLIB_SX1272_REG_PLL 0x5C
|
||||
#define RADIOLIB_SX1272_REG_PLL_LOW_PN 0x5E
|
||||
#define RADIOLIB_SX1272_REG_FORMER_TEMP 0x6C
|
||||
#define RADIOLIB_SX1272_REG_BIT_RATE_FRAC 0x70
|
||||
|
||||
// SX1272 LoRa modem settings
|
||||
// RADIOLIB_SX1272_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
|
||||
#define RADIOLIB_SX1272_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
|
||||
#define RADIOLIB_SX1272_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz
|
||||
#define RADIOLIB_SX1272_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
|
||||
#define RADIOLIB_SX1272_FRF_MSB 0xE4 // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
|
||||
#define RADIOLIB_SX1272_FRF_MID 0xC0 // 7 0 where F(XOSC) = 32 MHz
|
||||
#define RADIOLIB_SX1272_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
|
||||
|
||||
// RADIOLIB_SX127X_REG_MODEM_CONFIG_1
|
||||
#define RADIOLIB_SX1272_BW_125_00_KHZ 0b00000000 // 7 6 bandwidth: 125 kHz
|
||||
#define RADIOLIB_SX1272_BW_250_00_KHZ 0b01000000 // 7 6 250 kHz
|
||||
#define RADIOLIB_SX1272_BW_500_00_KHZ 0b10000000 // 7 6 500 kHz
|
||||
#define RADIOLIB_SX1272_CR_4_5 0b00001000 // 5 3 error coding rate: 4/5
|
||||
#define RADIOLIB_SX1272_CR_4_6 0b00010000 // 5 3 4/6
|
||||
#define RADIOLIB_SX1272_CR_4_7 0b00011000 // 5 3 4/7
|
||||
#define RADIOLIB_SX1272_CR_4_8 0b00100000 // 5 3 4/8
|
||||
#define RADIOLIB_SX1272_HEADER_EXPL_MODE 0b00000000 // 2 2 explicit header mode
|
||||
#define RADIOLIB_SX1272_HEADER_IMPL_MODE 0b00000100 // 2 2 implicit header mode
|
||||
#define RADIOLIB_SX1272_RX_CRC_MODE_OFF 0b00000000 // 1 1 CRC disabled
|
||||
#define RADIOLIB_SX1272_RX_CRC_MODE_ON 0b00000010 // 1 1 CRC enabled
|
||||
#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF 0b00000000 // 0 0 low data rate optimization disabled
|
||||
#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON 0b00000001 // 0 0 low data rate optimization enabled, mandatory for SF 11 and 12 with BW 125 kHz
|
||||
#define RADIOLIB_SX1272_BW_125_00_KHZ 0b00000000 // 7 6 bandwidth: 125 kHz
|
||||
#define RADIOLIB_SX1272_BW_250_00_KHZ 0b01000000 // 7 6 250 kHz
|
||||
#define RADIOLIB_SX1272_BW_500_00_KHZ 0b10000000 // 7 6 500 kHz
|
||||
#define RADIOLIB_SX1272_CR_4_5 0b00001000 // 5 3 error coding rate: 4/5
|
||||
#define RADIOLIB_SX1272_CR_4_6 0b00010000 // 5 3 4/6
|
||||
#define RADIOLIB_SX1272_CR_4_7 0b00011000 // 5 3 4/7
|
||||
#define RADIOLIB_SX1272_CR_4_8 0b00100000 // 5 3 4/8
|
||||
#define RADIOLIB_SX1272_HEADER_EXPL_MODE 0b00000000 // 2 2 explicit header mode
|
||||
#define RADIOLIB_SX1272_HEADER_IMPL_MODE 0b00000100 // 2 2 implicit header mode
|
||||
#define RADIOLIB_SX1272_RX_CRC_MODE_OFF 0b00000000 // 1 1 CRC disabled
|
||||
#define RADIOLIB_SX1272_RX_CRC_MODE_ON 0b00000010 // 1 1 CRC enabled
|
||||
#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_OFF 0b00000000 // 0 0 low data rate optimization disabled
|
||||
#define RADIOLIB_SX1272_LOW_DATA_RATE_OPT_ON 0b00000001 // 0 0 low data rate optimization enabled, mandatory for SF 11 and 12 with BW 125 kHz
|
||||
|
||||
// RADIOLIB_SX127X_REG_MODEM_CONFIG_2
|
||||
#define RADIOLIB_SX1272_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
|
||||
#define RADIOLIB_SX1272_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
|
||||
#define RADIOLIB_SX1272_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
|
||||
#define RADIOLIB_SX1272_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
|
||||
|
||||
// RADIOLIB_SX127X_REG_VERSION
|
||||
#define RADIOLIB_SX1272_CHIP_VERSION 0x22
|
||||
#define RADIOLIB_SX1272_CHIP_VERSION 0x22
|
||||
|
||||
// SX1272 FSK modem settings
|
||||
// RADIOLIB_SX127X_REG_OP_MODE
|
||||
#define RADIOLIB_SX1272_NO_SHAPING 0b00000000 // 4 3 data shaping: no shaping (default)
|
||||
#define RADIOLIB_SX1272_FSK_GAUSSIAN_1_0 0b00001000 // 4 3 FSK modulation Gaussian filter, BT = 1.0
|
||||
#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_5 0b00010000 // 4 3 FSK modulation Gaussian filter, BT = 0.5
|
||||
#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_3 0b00011000 // 4 3 FSK modulation Gaussian filter, BT = 0.3
|
||||
#define RADIOLIB_SX1272_OOK_FILTER_BR 0b00001000 // 4 3 OOK modulation filter, f_cutoff = BR
|
||||
#define RADIOLIB_SX1272_OOK_FILTER_2BR 0b00010000 // 4 3 OOK modulation filter, f_cutoff = 2*BR
|
||||
#define RADIOLIB_SX1272_NO_SHAPING 0b00000000 // 4 3 data shaping: no shaping (default)
|
||||
#define RADIOLIB_SX1272_FSK_GAUSSIAN_1_0 0b00001000 // 4 3 FSK modulation Gaussian filter, BT = 1.0
|
||||
#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_5 0b00010000 // 4 3 FSK modulation Gaussian filter, BT = 0.5
|
||||
#define RADIOLIB_SX1272_FSK_GAUSSIAN_0_3 0b00011000 // 4 3 FSK modulation Gaussian filter, BT = 0.3
|
||||
#define RADIOLIB_SX1272_OOK_FILTER_BR 0b00001000 // 4 3 OOK modulation filter, f_cutoff = BR
|
||||
#define RADIOLIB_SX1272_OOK_FILTER_2BR 0b00010000 // 4 3 OOK modulation filter, f_cutoff = 2*BR
|
||||
|
||||
// RADIOLIB_SX127X_REG_PA_RAMP
|
||||
#define RADIOLIB_SX1272_LOW_PN_TX_PLL_OFF 0b00010000 // 4 4 use standard PLL in transmit mode (default)
|
||||
#define RADIOLIB_SX1272_LOW_PN_TX_PLL_ON 0b00000000 // 4 4 use lower phase noise PLL in transmit mode
|
||||
#define RADIOLIB_SX1272_LOW_PN_TX_PLL_OFF 0b00010000 // 4 4 use standard PLL in transmit mode (default)
|
||||
#define RADIOLIB_SX1272_LOW_PN_TX_PLL_ON 0b00000000 // 4 4 use lower phase noise PLL in transmit mode
|
||||
|
||||
// RADIOLIB_SX127X_REG_SYNC_CONFIG
|
||||
#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_SYNC_ADDRESS 0b00000000 // 3 3 FIFO will be filled when sync address interrupt occurs (default)
|
||||
#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_ALWAYS 0b00001000 // 3 3 FIFO will be filled as long as this bit is set
|
||||
#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_SYNC_ADDRESS 0b00000000 // 3 3 FIFO will be filled when sync address interrupt occurs (default)
|
||||
#define RADIOLIB_SX1272_FIFO_FILL_CONDITION_ALWAYS 0b00001000 // 3 3 FIFO will be filled as long as this bit is set
|
||||
|
||||
// RADIOLIB_SX1272_REG_AGC_REF
|
||||
#define RADIOLIB_SX1272_AGC_REFERENCE_LEVEL 0x13 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]
|
||||
#define RADIOLIB_SX1272_AGC_REFERENCE_LEVEL 0x13 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]
|
||||
|
||||
// RADIOLIB_SX1272_REG_AGC_THRESH_1
|
||||
#define RADIOLIB_SX1272_AGC_STEP_1 0x0E // 4 0 1st AGC threshold
|
||||
#define RADIOLIB_SX1272_AGC_STEP_1 0x0E // 4 0 1st AGC threshold
|
||||
|
||||
// RADIOLIB_SX1272_REG_AGC_THRESH_2
|
||||
#define RADIOLIB_SX1272_AGC_STEP_2 0x50 // 7 4 2nd AGC threshold
|
||||
#define RADIOLIB_SX1272_AGC_STEP_3 0x0B // 4 0 3rd AGC threshold
|
||||
#define RADIOLIB_SX1272_AGC_STEP_2 0x50 // 7 4 2nd AGC threshold
|
||||
#define RADIOLIB_SX1272_AGC_STEP_3 0x0B // 4 0 3rd AGC threshold
|
||||
|
||||
// RADIOLIB_SX1272_REG_AGC_THRESH_3
|
||||
#define RADIOLIB_SX1272_AGC_STEP_4 0xD0 // 7 4 4th AGC threshold
|
||||
#define RADIOLIB_SX1272_AGC_STEP_5 0x0B // 4 0 5th AGC threshold
|
||||
#define RADIOLIB_SX1272_AGC_STEP_4 0xD0 // 7 4 4th AGC threshold
|
||||
#define RADIOLIB_SX1272_AGC_STEP_5 0x0B // 4 0 5th AGC threshold
|
||||
|
||||
// RADIOLIB_SX1272_REG_PLL_LOW_PN
|
||||
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_75_KHZ 0b00000000 // 7 6 low phase noise PLL bandwidth: 75 kHz
|
||||
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_150_KHZ 0b01000000 // 7 6 150 kHz
|
||||
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz
|
||||
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default)
|
||||
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_75_KHZ 0b00000000 // 7 6 low phase noise PLL bandwidth: 75 kHz
|
||||
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_150_KHZ 0b01000000 // 7 6 150 kHz
|
||||
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz
|
||||
#define RADIOLIB_SX1272_PLL_LOW_PN_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default)
|
||||
|
||||
/*!
|
||||
\class SX1272
|
||||
|
||||
\brief Derived class for %SX1272 modules. Also used as base class for SX1273.
|
||||
Both modules use the same basic hardware and only differ in parameter ranges.
|
||||
*/
|
||||
@@ -99,57 +98,38 @@ class SX1272: public SX127x {
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1272(Module* mod);
|
||||
SX1272(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
/*!
|
||||
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
|
||||
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of FSK preamble in bits.
|
||||
|
||||
\param enableOOK Use OOK modulation instead of FSK.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 915.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
|
||||
@@ -163,57 +143,91 @@ class SX1272: public SX127x {
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 860.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link bandwidth. Allowed values are 125, 250 and 500 kHz. Only available in %LoRa mode.
|
||||
|
||||
\param bw %LoRa link bandwidth to be set in kHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setBandwidth(float bw);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in %LoRa mode.
|
||||
|
||||
\param cr %LoRa link coding rate denominator to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCodingRate(uint8_t cr);
|
||||
|
||||
/*!
|
||||
\brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin).
|
||||
|
||||
\param power Transmission output power in dBm.
|
||||
|
||||
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output. Defaults to PA_BOOST.
|
||||
|
||||
\brief Sets FSK bit rate. Allowed values range from 0.5 to 300 kbps. Only available in FSK mode.
|
||||
\param br Bit rate to be set (in kbps).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power, bool useRfo = false);
|
||||
int16_t setBitRate(float br) override;
|
||||
|
||||
/*!
|
||||
\brief Set data.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataRate(DataRate_t dr) override;
|
||||
|
||||
/*!
|
||||
\brief Check the data rate can be configured by this module.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkDataRate(DataRate_t dr) override;
|
||||
|
||||
/*!
|
||||
\brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin).
|
||||
High power +20 dBm operation is also supported, on the PA_BOOST pin. Defaults to PA_BOOST.
|
||||
\param power Transmission output power in dBm.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
/*!
|
||||
\brief Sets transmission output power. Allowed values range from -1 to 14 dBm (RFO pin) or +2 to +20 dBm (PA_BOOST pin).
|
||||
\param power Transmission output power in dBm.
|
||||
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power, bool useRfo);
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
This method is needed for compatibility with PhysicalLayer::checkOutputPower.
|
||||
\param power Output power in dBm, assumes PA_BOOST pin.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
\param power Output power in dBm.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped, bool useRfo);
|
||||
|
||||
/*!
|
||||
\brief Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended). Only available in %LoRa mode.
|
||||
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
\param gain Gain of receiver LNA (low-noise amplifier) to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setGain(uint8_t gain);
|
||||
@@ -221,9 +235,7 @@ class SX1272: public SX127x {
|
||||
/*!
|
||||
\brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation.
|
||||
Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
|
||||
|
||||
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataShaping(uint8_t sh) override;
|
||||
@@ -232,29 +244,32 @@ class SX1272: public SX127x {
|
||||
\brief Sets filter cutoff frequency that will be used for data shaping.
|
||||
Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping.
|
||||
Only available in FSK mode with OOK modulation.
|
||||
|
||||
\param sh Cutoff frequency that will be used for data shaping
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataShapingOOK(uint8_t sh);
|
||||
|
||||
/*!
|
||||
\brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem.
|
||||
|
||||
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode.
|
||||
|
||||
\returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem.
|
||||
\brief Gets recorded signal strength indicator.
|
||||
Overload with packet mode enabled for PhysicalLayer compatibility.
|
||||
\returns RSSI value in dBm.
|
||||
*/
|
||||
float getRSSI(bool skipReceive = false);
|
||||
float getRSSI() override;
|
||||
|
||||
/*!
|
||||
\brief Gets recorded signal strength indicator.
|
||||
\param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK.
|
||||
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode.
|
||||
\returns RSSI value in dBm.
|
||||
*/
|
||||
float getRSSI(bool packet, bool skipReceive = false);
|
||||
|
||||
/*!
|
||||
\brief Enables/disables CRC check of received packets.
|
||||
|
||||
\param enable Enable (true) or disable (false) CRC.
|
||||
|
||||
\param mode Set CRC mode to RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false) or RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode.
|
||||
|
||||
\param mode Set CRC mode to RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT for CCITT,
|
||||
polynomial X16 + X12 + X5 + 1 (false) or RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM for IBM,
|
||||
polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCRC(bool enable, bool mode = false);
|
||||
@@ -262,9 +277,7 @@ class SX1272: public SX127x {
|
||||
/*!
|
||||
\brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to
|
||||
the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO()
|
||||
|
||||
\param enable Force LDRO to be always enabled (true) or disabled (false).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t forceLDRO(bool enable);
|
||||
@@ -272,28 +285,24 @@ class SX1272: public SX127x {
|
||||
/*!
|
||||
\brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically
|
||||
when symbol length exceeds 16 ms.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t autoLDRO();
|
||||
|
||||
/*!
|
||||
\brief Set implicit header mode for future reception/transmission. Required for spreading factor 6.
|
||||
|
||||
\brief Set implicit header mode for future reception/transmission. Required for spreading factor 6.
|
||||
\param len Payload length in bytes.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t implicitHeader(size_t len);
|
||||
|
||||
/*!
|
||||
\brief Set explicit header mode for future reception/transmission.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t explicitHeader();
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
int16_t setBandwidthRaw(uint8_t newBandwidth);
|
||||
@@ -302,13 +311,13 @@ class SX1272: public SX127x {
|
||||
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
|
||||
|
||||
int16_t configFSK();
|
||||
void errataFix(bool rx);
|
||||
void errataFix(bool rx) override;
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
bool _ldroAuto = true;
|
||||
bool _ldroEnabled = false;
|
||||
bool ldroAuto = true;
|
||||
bool ldroEnabled = false;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "SX1273.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
SX1273::SX1273(Module* mod) : SX1272(mod) {
|
||||
|
||||
@@ -7,7 +7,8 @@ SX1273::SX1273(Module* mod) : SX1272(mod) {
|
||||
|
||||
int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::begin(RADIOLIB_SX1272_CHIP_VERSION, syncWord, preambleLength);
|
||||
uint8_t version = RADIOLIB_SX1272_CHIP_VERSION;
|
||||
int16_t state = SX127x::begin(&version, 1, syncWord, preambleLength);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
@@ -29,6 +30,10 @@ int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
|
||||
state = setGain(gain);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set publicly accessible settings that are not a part of begin method
|
||||
state = setCRC(true);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -56,7 +61,55 @@ int16_t SX1273::setSpreadingFactor(uint8_t sf) {
|
||||
// set spreading factor and if successful, save the new setting
|
||||
int16_t state = setSpreadingFactorRaw(newSpreadingFactor);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_sf = sf;
|
||||
SX127x::spreadingFactor = sf;
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1273::setDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
uint8_t modem = this->getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
// set the bit rate
|
||||
state = this->setBitRate(dr.fsk.bitRate);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the frequency deviation
|
||||
state = this->setFrequencyDeviation(dr.fsk.freqDev);
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||
// set the spreading factor
|
||||
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the bandwidth
|
||||
state = this->setBandwidth(dr.lora.bandwidth);
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1273::checkDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
int16_t modem = getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
|
||||
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 100.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
}
|
||||
|
||||
return(state);
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
#include "SX1272.h"
|
||||
|
||||
/*!
|
||||
\class SX1273
|
||||
|
||||
\brief Derived class for %SX1273 modules. Overrides some methods from SX1272 due to different parameter ranges.
|
||||
*/
|
||||
class SX1273: public SX1272 {
|
||||
@@ -19,34 +18,24 @@ class SX1273: public SX1272 {
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1273(Module* mod);
|
||||
SX1273(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 9.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
@@ -55,14 +44,26 @@ class SX1273: public SX1272 {
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
/*!
|
||||
\brief Set data.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataRate(DataRate_t dr) override;
|
||||
|
||||
/*!
|
||||
\brief Check the data rate can be configured by this module.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkDataRate(DataRate_t dr) override;
|
||||
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "SX1276.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
SX1276::SX1276(Module* mod) : SX1278(mod) {
|
||||
|
||||
@@ -7,7 +7,8 @@ SX1276::SX1276(Module* mod) : SX1278(mod) {
|
||||
|
||||
int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength);
|
||||
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
|
||||
int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
@@ -29,12 +30,17 @@ int16_t SX1276::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
|
||||
state = setGain(gain);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set publicly accessible settings that are not a part of begin method
|
||||
state = setCRC(true);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1276::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
|
||||
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
|
||||
int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure settings not accessible by API
|
||||
@@ -45,6 +51,9 @@ int16_t SX1276::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setBitRate(br);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
@@ -65,7 +74,7 @@ int16_t SX1276::setFrequency(float freq) {
|
||||
// set frequency and if successful, save the new setting
|
||||
int16_t state = SX127x::setFrequencyRaw(freq);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_freq = freq;
|
||||
SX127x::frequency = freq;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
#include "SX1278.h"
|
||||
|
||||
/*!
|
||||
\class SX1276
|
||||
|
||||
\brief Derived class for %SX1276 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class SX1276: public SX1278 {
|
||||
@@ -19,56 +18,38 @@ class SX1276: public SX1278 {
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1276(Module* mod);
|
||||
SX1276(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
/*!
|
||||
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
|
||||
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of FSK preamble in bits.
|
||||
|
||||
\param enableOOK Use OOK modulation instead of FSK.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
|
||||
@@ -77,19 +58,29 @@ class SX1276: public SX1278 {
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
\class RFM95
|
||||
\brief Only exists as alias for SX1276, since there seems to be no difference between %RFM95 and %SX1276 modules.
|
||||
*/
|
||||
RADIOLIB_TYPE_ALIAS(SX1276, RFM95)
|
||||
|
||||
/*!
|
||||
\class RFM96
|
||||
\brief Only exists as alias for SX1276, since there seems to be no difference between %RFM96 and %SX1276 modules.
|
||||
*/
|
||||
RADIOLIB_TYPE_ALIAS(SX1276, RFM96)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "SX1277.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
SX1277::SX1277(Module* mod) : SX1278(mod) {
|
||||
|
||||
@@ -7,7 +7,8 @@ SX1277::SX1277(Module* mod) : SX1278(mod) {
|
||||
|
||||
int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength);
|
||||
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
|
||||
int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
@@ -29,12 +30,17 @@ int16_t SX1277::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
|
||||
state = setGain(gain);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set publicly accessible settings that are not a part of begin method
|
||||
state = setCRC(true);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1277::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
|
||||
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
|
||||
int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure settings not accessible by API
|
||||
@@ -45,6 +51,9 @@ int16_t SX1277::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setBitRate(br);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
@@ -65,7 +74,7 @@ int16_t SX1277::setFrequency(float freq) {
|
||||
// set frequency and if successful, save the new setting
|
||||
int16_t state = SX127x::setFrequencyRaw(freq);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_freq = freq;
|
||||
SX127x::frequency = freq;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
@@ -94,7 +103,55 @@ int16_t SX1277::setSpreadingFactor(uint8_t sf) {
|
||||
// set spreading factor and if successful, save the new setting
|
||||
int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_sf = sf;
|
||||
SX127x::spreadingFactor = sf;
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1277::setDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
uint8_t modem = this->getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
// set the bit rate
|
||||
state = this->setBitRate(dr.fsk.bitRate);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the frequency deviation
|
||||
state = this->setFrequencyDeviation(dr.fsk.freqDev);
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||
// set the spreading factor
|
||||
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the bandwidth
|
||||
state = this->setBandwidth(dr.lora.bandwidth);
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1277::checkDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
int16_t modem = getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
|
||||
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 9, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
}
|
||||
|
||||
return(state);
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
#include "SX1278.h"
|
||||
|
||||
/*!
|
||||
\class SX1277
|
||||
|
||||
\brief Derived class for %SX1277 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class SX1277: public SX1278 {
|
||||
@@ -19,56 +18,38 @@ class SX1277: public SX1278 {
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1277(Module* mod);
|
||||
SX1277(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 9.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
/*!
|
||||
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
|
||||
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of FSK preamble in bits.
|
||||
|
||||
\param enableOOK Use OOK modulation instead of FSK.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
|
||||
@@ -77,28 +58,44 @@ class SX1277: public SX1278 {
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
|
||||
/*!
|
||||
\brief Set data.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataRate(DataRate_t dr) override;
|
||||
|
||||
/*!
|
||||
\brief Check the data rate can be configured by this module.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkDataRate(DataRate_t dr) override;
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
\class RFM97
|
||||
\brief Only exists as alias for SX1277, since there seems to be no difference between %RFM97 and %SX1277 modules.
|
||||
*/
|
||||
RADIOLIB_TYPE_ALIAS(SX1277, RFM97)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "SX1278.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#include <math.h>
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
SX1278::SX1278(Module* mod) : SX127x(mod) {
|
||||
|
||||
@@ -7,7 +8,8 @@ SX1278::SX1278(Module* mod) : SX127x(mod) {
|
||||
|
||||
int16_t SX1278::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength);
|
||||
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
|
||||
int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
@@ -29,12 +31,17 @@ int16_t SX1278::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
|
||||
state = setGain(gain);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set publicly accessible settings that are not a part of begin method
|
||||
state = setCRC(true);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
|
||||
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
|
||||
int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure settings not accessible by API
|
||||
@@ -45,6 +52,9 @@ int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setBitRate(br);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
@@ -56,15 +66,20 @@ int16_t SX1278::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
// set publicly accessible settings that are not a part of begin method
|
||||
state = setCRC(true);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
void SX1278::reset() {
|
||||
_mod->pinMode(_mod->getRst(), OUTPUT);
|
||||
_mod->digitalWrite(_mod->getRst(), LOW);
|
||||
_mod->delay(1);
|
||||
_mod->digitalWrite(_mod->getRst(), HIGH);
|
||||
_mod->delay(5);
|
||||
Module* mod = this->getMod();
|
||||
mod->hal->pinMode(mod->getRst(), mod->hal->GpioModeOutput);
|
||||
mod->hal->digitalWrite(mod->getRst(), mod->hal->GpioLevelLow);
|
||||
mod->hal->delay(1);
|
||||
mod->hal->digitalWrite(mod->getRst(), mod->hal->GpioLevelHigh);
|
||||
mod->hal->delay(5);
|
||||
}
|
||||
|
||||
int16_t SX1278::setFrequency(float freq) {
|
||||
@@ -73,7 +88,7 @@ int16_t SX1278::setFrequency(float freq) {
|
||||
// set frequency and if successful, save the new setting
|
||||
int16_t state = SX127x::setFrequencyRaw(freq);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_freq = freq;
|
||||
SX127x::frequency = freq;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
@@ -87,25 +102,25 @@ int16_t SX1278::setBandwidth(float bw) {
|
||||
uint8_t newBandwidth;
|
||||
|
||||
// check allowed bandwidth values
|
||||
if(fabs(bw - 7.8) <= 0.001) {
|
||||
if(fabsf(bw - 7.8) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_7_80_KHZ;
|
||||
} else if(fabs(bw - 10.4) <= 0.001) {
|
||||
} else if(fabsf(bw - 10.4) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_10_40_KHZ;
|
||||
} else if(fabs(bw - 15.6) <= 0.001) {
|
||||
} else if(fabsf(bw - 15.6) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_15_60_KHZ;
|
||||
} else if(fabs(bw - 20.8) <= 0.001) {
|
||||
} else if(fabsf(bw - 20.8) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_20_80_KHZ;
|
||||
} else if(fabs(bw - 31.25) <= 0.001) {
|
||||
} else if(fabsf(bw - 31.25) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_31_25_KHZ;
|
||||
} else if(fabs(bw - 41.7) <= 0.001) {
|
||||
} else if(fabsf(bw - 41.7) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_41_70_KHZ;
|
||||
} else if(fabs(bw - 62.5) <= 0.001) {
|
||||
} else if(fabsf(bw - 62.5) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_62_50_KHZ;
|
||||
} else if(fabs(bw - 125.0) <= 0.001) {
|
||||
} else if(fabsf(bw - 125.0) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_125_00_KHZ;
|
||||
} else if(fabs(bw - 250.0) <= 0.001) {
|
||||
} else if(fabsf(bw - 250.0) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_250_00_KHZ;
|
||||
} else if(fabs(bw - 500.0) <= 0.001) {
|
||||
} else if(fabsf(bw - 500.0) <= 0.001) {
|
||||
newBandwidth = RADIOLIB_SX1278_BW_500_00_KHZ;
|
||||
} else {
|
||||
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||
@@ -114,18 +129,16 @@ int16_t SX1278::setBandwidth(float bw) {
|
||||
// set bandwidth and if successful, save the new setting
|
||||
int16_t state = SX1278::setBandwidthRaw(newBandwidth);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_bw = bw;
|
||||
SX127x::bandwidth = bw;
|
||||
|
||||
// calculate symbol length and set low data rate optimization, if auto-configuration is enabled
|
||||
if(_ldroAuto) {
|
||||
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
||||
RADIOLIB_DEBUG_PRINT("Symbol length: ");
|
||||
RADIOLIB_DEBUG_PRINT(symbolLength);
|
||||
RADIOLIB_DEBUG_PRINTLN(" ms");
|
||||
if(this->ldroAuto) {
|
||||
float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth;
|
||||
Module* mod = this->getMod();
|
||||
if(symbolLength >= 16.0) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
|
||||
} else {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,18 +183,16 @@ int16_t SX1278::setSpreadingFactor(uint8_t sf) {
|
||||
// set spreading factor and if successful, save the new setting
|
||||
int16_t state = SX1278::setSpreadingFactorRaw(newSpreadingFactor);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_sf = sf;
|
||||
SX127x::spreadingFactor = sf;
|
||||
|
||||
// calculate symbol length and set low data rate optimization, if auto-configuration is enabled
|
||||
if(_ldroAuto) {
|
||||
float symbolLength = (float)(uint32_t(1) << SX127x::_sf) / (float)SX127x::_bw;
|
||||
RADIOLIB_DEBUG_PRINT("Symbol length: ");
|
||||
RADIOLIB_DEBUG_PRINT(symbolLength);
|
||||
RADIOLIB_DEBUG_PRINTLN(" ms");
|
||||
if(this->ldroAuto) {
|
||||
float symbolLength = (float)(uint32_t(1) << SX127x::spreadingFactor) / (float)SX127x::bandwidth;
|
||||
Module* mod = this->getMod();
|
||||
if(symbolLength >= 16.0) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3);
|
||||
} else {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,25 +228,79 @@ int16_t SX1278::setCodingRate(uint8_t cr) {
|
||||
// set coding rate and if successful, save the new setting
|
||||
int16_t state = SX1278::setCodingRateRaw(newCodingRate);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_cr = cr;
|
||||
SX127x::codingRate = cr;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1278::setOutputPower(int8_t power, bool useRfo) {
|
||||
// check allowed power range
|
||||
if(useRfo) {
|
||||
// RFO output
|
||||
RADIOLIB_CHECK_RANGE(power, -3, 15, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
} else {
|
||||
// PA_BOOST output, check high-power operation
|
||||
if(power != 20) {
|
||||
RADIOLIB_CHECK_RANGE(power, 2, 17, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
}
|
||||
int16_t SX1278::setBitRate(float br) {
|
||||
return(SX127x::setBitRateCommon(br, RADIOLIB_SX1278_REG_BIT_RATE_FRAC));
|
||||
}
|
||||
|
||||
int16_t SX1278::setDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
uint8_t modem = this->getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
// set the bit rate
|
||||
state = this->setBitRate(dr.fsk.bitRate);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the frequency deviation
|
||||
state = this->setFrequencyDeviation(dr.fsk.freqDev);
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||
// set the spreading factor
|
||||
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the bandwidth
|
||||
state = this->setBandwidth(dr.lora.bandwidth);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set the coding rate
|
||||
state = this->setCodingRate(dr.lora.codingRate);
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1278::checkDataRate(DataRate_t dr) {
|
||||
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||
|
||||
// select interpretation based on active modem
|
||||
int16_t modem = getActiveModem();
|
||||
if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
RADIOLIB_CHECK_RANGE(dr.fsk.bitRate, 0.5, 300.0, RADIOLIB_ERR_INVALID_BIT_RATE);
|
||||
if(!((dr.fsk.freqDev + dr.fsk.bitRate/2.0 <= 250.0) && (dr.fsk.freqDev <= 200.0))) {
|
||||
return(RADIOLIB_ERR_INVALID_FREQUENCY_DEVIATION);
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_LORA) {
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.spreadingFactor, 6, 12, RADIOLIB_ERR_INVALID_SPREADING_FACTOR);
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.bandwidth, 0.0, 510.0, RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||
RADIOLIB_CHECK_RANGE(dr.lora.codingRate, 5, 8, RADIOLIB_ERR_INVALID_CODING_RATE);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1278::setOutputPower(int8_t power) {
|
||||
return(this->setOutputPower(power, false));
|
||||
}
|
||||
|
||||
int16_t SX1278::setOutputPower(int8_t power, bool useRfo) {
|
||||
// check if power value is configurable
|
||||
int16_t state = checkOutputPower(power, NULL, useRfo);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set mode to standby
|
||||
int16_t state = SX127x::standby();
|
||||
state = SX127x::standby();
|
||||
Module* mod = this->getMod();
|
||||
|
||||
if(useRfo) {
|
||||
uint8_t paCfg = 0;
|
||||
@@ -247,22 +312,22 @@ int16_t SX1278::setOutputPower(int8_t power, bool useRfo) {
|
||||
paCfg = RADIOLIB_SX1278_MAX_POWER | power;
|
||||
}
|
||||
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, paCfg, 6, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_RFO, 7, 7);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, paCfg, 6, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
|
||||
|
||||
} else {
|
||||
if(power != 20) {
|
||||
// power is 2 - 17 dBm, enable PA1 + PA2 on PA_BOOST
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | (power - 2), 6, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | (power - 2), 6, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_OFF, 2, 0);
|
||||
|
||||
} else {
|
||||
// power is 20 dBm, enable PA1 + PA2 on PA_BOOST and enable high power control
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | 0x0F, 6, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX127X_PA_SELECT_BOOST, 7, 7);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_CONFIG, RADIOLIB_SX1278_MAX_POWER | 0x0F, 6, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PA_DAC, RADIOLIB_SX127X_PA_BOOST_ON, 2, 0);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -270,6 +335,34 @@ int16_t SX1278::setOutputPower(int8_t power, bool useRfo) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1278::checkOutputPower(int8_t power, int8_t* clipped) {
|
||||
return(checkOutputPower(power, clipped, false));
|
||||
}
|
||||
|
||||
int16_t SX1278::checkOutputPower(int8_t power, int8_t* clipped, bool useRfo) {
|
||||
// check allowed power range
|
||||
if(useRfo) {
|
||||
// RFO output
|
||||
if(clipped) {
|
||||
*clipped = RADIOLIB_MAX(-3, RADIOLIB_MIN(15, power));
|
||||
}
|
||||
RADIOLIB_CHECK_RANGE(power, -3, 15, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
} else {
|
||||
// PA_BOOST output, check high-power operation
|
||||
if(clipped) {
|
||||
if(power != 20) {
|
||||
*clipped = RADIOLIB_MAX(2, RADIOLIB_MIN(17, power));
|
||||
} else {
|
||||
*clipped = 20;
|
||||
}
|
||||
}
|
||||
if(power != 20) {
|
||||
RADIOLIB_CHECK_RANGE(power, 2, 17, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
}
|
||||
}
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t SX1278::setGain(uint8_t gain) {
|
||||
// check allowed range
|
||||
if(gain > 6) {
|
||||
@@ -278,6 +371,7 @@ int16_t SX1278::setGain(uint8_t gain) {
|
||||
|
||||
// set mode to standby
|
||||
int16_t state = SX127x::standby();
|
||||
Module* mod = this->getMod();
|
||||
|
||||
// get modem
|
||||
int16_t modem = getActiveModem();
|
||||
@@ -285,20 +379,21 @@ int16_t SX1278::setGain(uint8_t gain) {
|
||||
// set gain
|
||||
if(gain == 0) {
|
||||
// gain set to 0, enable AGC loop
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_ON, 2, 2);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_ON, 2, 2);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, RADIOLIB_SX127X_LNA_BOOST_ON, 1, 0);
|
||||
} else {
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_OFF, 2, 2);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_AGC_AUTO_OFF, 2, 2);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
|
||||
}
|
||||
|
||||
} else if(modem == RADIOLIB_SX127X_FSK_OOK) {
|
||||
// set gain
|
||||
if(gain == 0) {
|
||||
// gain set to 0, enable AGC loop
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX127X_AGC_AUTO_ON, 3, 3);
|
||||
} else {
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX1278_AGC_AUTO_OFF, 3, 3);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_RX_CONFIG, RADIOLIB_SX1278_AGC_AUTO_OFF, 3, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_LNA, (gain << 5) | RADIOLIB_SX127X_LNA_BOOST_ON);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -313,7 +408,7 @@ int16_t SX1278::setDataShaping(uint8_t sh) {
|
||||
}
|
||||
|
||||
// check modulation
|
||||
if(SX127x::_ook) {
|
||||
if(SX127x::ookEnabled) {
|
||||
// we're in OOK mode, the only thing we can do is disable
|
||||
if(sh == RADIOLIB_SHAPING_NONE) {
|
||||
return(setDataShapingOOK(0));
|
||||
@@ -327,15 +422,16 @@ int16_t SX1278::setDataShaping(uint8_t sh) {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set data shaping
|
||||
Module* mod = this->getMod();
|
||||
switch(sh) {
|
||||
case RADIOLIB_SHAPING_NONE:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5));
|
||||
case RADIOLIB_SHAPING_0_3:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_3, 6, 5));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_3, 6, 5));
|
||||
case RADIOLIB_SHAPING_0_5:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_5, 6, 5));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_0_5, 6, 5));
|
||||
case RADIOLIB_SHAPING_1_0:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_1_0, 6, 5));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_FSK_GAUSSIAN_1_0, 6, 5));
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_DATA_SHAPING);
|
||||
}
|
||||
@@ -348,7 +444,7 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) {
|
||||
}
|
||||
|
||||
// check modulation
|
||||
if(!SX127x::_ook) {
|
||||
if(!SX127x::ookEnabled) {
|
||||
return(RADIOLIB_ERR_INVALID_MODULATION);
|
||||
}
|
||||
|
||||
@@ -356,15 +452,16 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) {
|
||||
int16_t state = SX127x::standby();
|
||||
|
||||
// set data shaping
|
||||
Module* mod = this->getMod();
|
||||
switch(sh) {
|
||||
case 0:
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_NO_SHAPING, 6, 5);
|
||||
break;
|
||||
case 1:
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_BR, 6, 5);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_BR, 6, 5);
|
||||
break;
|
||||
case 2:
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_2BR, 6, 5);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PA_RAMP, RADIOLIB_SX1278_OOK_FILTER_2BR, 6, 5);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_DATA_SHAPING);
|
||||
@@ -373,70 +470,43 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
float SX1278::getRSSI(bool skipReceive) {
|
||||
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
|
||||
// for LoRa, get RSSI of the last packet
|
||||
float lastPacketRSSI;
|
||||
float SX1278::getRSSI() {
|
||||
return(SX1278::getRSSI(true, false));
|
||||
}
|
||||
|
||||
// RSSI calculation uses different constant for low-frequency and high-frequency ports
|
||||
if(_freq < 868.0) {
|
||||
lastPacketRSSI = -164 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
|
||||
} else {
|
||||
lastPacketRSSI = -157 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
|
||||
}
|
||||
|
||||
// spread-spectrum modulation signal can be received below noise floor
|
||||
// check last packet SNR and if it's less than 0, add it to reported RSSI to get the correct value
|
||||
float lastPacketSNR = SX127x::getSNR();
|
||||
if(lastPacketSNR < 0.0) {
|
||||
lastPacketRSSI += lastPacketSNR;
|
||||
}
|
||||
|
||||
return(lastPacketRSSI);
|
||||
|
||||
} else {
|
||||
// enable listen mode
|
||||
if(!skipReceive) {
|
||||
startReceive();
|
||||
}
|
||||
|
||||
// read the value for FSK
|
||||
float rssi = (float)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0;
|
||||
|
||||
// set mode back to standby
|
||||
if(!skipReceive) {
|
||||
standby();
|
||||
}
|
||||
|
||||
// return the value
|
||||
return(rssi);
|
||||
float SX1278::getRSSI(bool packet, bool skipReceive) {
|
||||
int16_t offset = -157;
|
||||
if(frequency < 868.0) {
|
||||
offset = -164;
|
||||
}
|
||||
return(SX127x::getRSSI(packet, skipReceive, offset));
|
||||
}
|
||||
|
||||
int16_t SX1278::setCRC(bool enable, bool mode) {
|
||||
Module* mod = this->getMod();
|
||||
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
|
||||
// set LoRa CRC
|
||||
SX127x::_crcEnabled = enable;
|
||||
SX127x::crcEnabled = enable;
|
||||
if(enable) {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_ON, 2, 2));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_ON, 2, 2));
|
||||
} else {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_OFF, 2, 2));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX1278_RX_CRC_MODE_OFF, 2, 2));
|
||||
}
|
||||
} else {
|
||||
// set FSK CRC
|
||||
int16_t state = RADIOLIB_ERR_NONE;
|
||||
if(enable) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_ON, 4, 4);
|
||||
} else {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_OFF, 4, 4);
|
||||
}
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set FSK CRC mode
|
||||
if(mode) {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_IBM, 0, 0));
|
||||
} else {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PACKET_CONFIG_1, RADIOLIB_SX127X_CRC_WHITENING_TYPE_CCITT, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,11 +516,12 @@ int16_t SX1278::forceLDRO(bool enable) {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
_ldroAuto = false;
|
||||
Module* mod = this->getMod();
|
||||
this->ldroAuto = false;
|
||||
if(enable) {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON, 3, 3));
|
||||
} else {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3));
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SX1278_REG_MODEM_CONFIG_3, RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF, 3, 3));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,7 +530,7 @@ int16_t SX1278::autoLDRO() {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
_ldroAuto = true;
|
||||
this->ldroAuto = true;
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
@@ -476,7 +547,8 @@ int16_t SX1278::setBandwidthRaw(uint8_t newBandwidth) {
|
||||
int16_t state = SX127x::standby();
|
||||
|
||||
// write register
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 4);
|
||||
Module* mod = this->getMod();
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newBandwidth, 7, 4);
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -485,16 +557,17 @@ int16_t SX1278::setSpreadingFactorRaw(uint8_t newSpreadingFactor) {
|
||||
int16_t state = SX127x::standby();
|
||||
|
||||
// write registers
|
||||
Module* mod = this->getMod();
|
||||
if(newSpreadingFactor == RADIOLIB_SX127X_SF_6) {
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE | (SX127x::_crcEnabled ? RADIOLIB_SX1278_RX_CRC_MODE_ON : RADIOLIB_SX1278_RX_CRC_MODE_OFF), 7, 2);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_IMPL_MODE, 0, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, RADIOLIB_SX127X_SF_6 | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_6, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_6);
|
||||
} else {
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_EXPL_MODE, 0, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE | (SX127x::_crcEnabled ? RADIOLIB_SX1278_RX_CRC_MODE_ON : RADIOLIB_SX1278_RX_CRC_MODE_OFF), 7, 2);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, RADIOLIB_SX1278_HEADER_EXPL_MODE, 0, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_2, newSpreadingFactor | RADIOLIB_SX127X_TX_MODE_SINGLE, 7, 3);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECT_OPTIMIZE, RADIOLIB_SX127X_DETECT_OPTIMIZE_SF_7_12, 2, 0);
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DETECTION_THRESHOLD, RADIOLIB_SX127X_DETECTION_THRESHOLD_SF_7_12);
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
@@ -504,7 +577,8 @@ int16_t SX1278::setCodingRateRaw(uint8_t newCodingRate) {
|
||||
int16_t state = SX127x::standby();
|
||||
|
||||
// write register
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 3, 1);
|
||||
Module* mod = this->getMod();
|
||||
state |= mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, newCodingRate, 3, 1);
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -515,15 +589,16 @@ int16_t SX1278::setHeaderType(uint8_t headerType, size_t len) {
|
||||
}
|
||||
|
||||
// set requested packet mode
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 0, 0);
|
||||
Module* mod = this->getMod();
|
||||
int16_t state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_MODEM_CONFIG_1, headerType, 0, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set length to register
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX127X_REG_PAYLOAD_LENGTH, len);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// update cached value
|
||||
_packetLength = len;
|
||||
SX127x::packetLength = len;
|
||||
|
||||
return(state);
|
||||
}
|
||||
@@ -534,7 +609,8 @@ int16_t SX1278::configFSK() {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set fast PLL hop
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7);
|
||||
Module* mod = this->getMod();
|
||||
state = mod->SPIsetRegValue(RADIOLIB_SX1278_REG_PLL_HOP, RADIOLIB_SX127X_FAST_HOP_ON, 7, 7);
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -546,13 +622,14 @@ void SX1278::errataFix(bool rx) {
|
||||
|
||||
// sensitivity optimization for 500kHz bandwidth
|
||||
// see SX1276/77/78 Errata, section 2.1 for details
|
||||
if(fabs(_bw - 500.0) <= 0.001) {
|
||||
if((_freq >= 862.0) && (_freq <= 1020.0)) {
|
||||
_mod->SPIwriteRegister(0x36, 0x02);
|
||||
_mod->SPIwriteRegister(0x3a, 0x64);
|
||||
} else if((_freq >= 410.0) && (_freq <= 525.0)) {
|
||||
_mod->SPIwriteRegister(0x36, 0x02);
|
||||
_mod->SPIwriteRegister(0x3a, 0x7F);
|
||||
Module* mod = this->getMod();
|
||||
if(fabsf(SX127x::bandwidth - 500.0) <= 0.001) {
|
||||
if((frequency >= 862.0) && (frequency <= 1020.0)) {
|
||||
mod->SPIwriteRegister(0x36, 0x02);
|
||||
mod->SPIwriteRegister(0x3a, 0x64);
|
||||
} else if((frequency >= 410.0) && (frequency <= 525.0)) {
|
||||
mod->SPIwriteRegister(0x36, 0x02);
|
||||
mod->SPIwriteRegister(0x3a, 0x7F);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,53 +638,53 @@ void SX1278::errataFix(bool rx) {
|
||||
|
||||
// figure out what we need to set
|
||||
uint8_t fixedRegs[3] = { 0x00, 0x00, 0x00 };
|
||||
float rxFreq = _freq;
|
||||
if(fabs(_bw - 7.8) <= 0.001) {
|
||||
fixedRegs[0] = 0b0000000;
|
||||
float rxFreq = frequency;
|
||||
if(fabsf(SX127x::bandwidth - 7.8) <= 0.001) {
|
||||
fixedRegs[0] = 0b00000000;
|
||||
fixedRegs[1] = 0x48;
|
||||
fixedRegs[2] = 0x00;
|
||||
rxFreq += 0.00781;
|
||||
} else if(fabs(_bw - 10.4) <= 0.001) {
|
||||
fixedRegs[0] = 0b0000000;
|
||||
} else if(fabsf(SX127x::bandwidth - 10.4) <= 0.001) {
|
||||
fixedRegs[0] = 0b00000000;
|
||||
fixedRegs[1] = 0x44;
|
||||
fixedRegs[2] = 0x00;
|
||||
rxFreq += 0.01042;
|
||||
} else if(fabs(_bw - 15.6) <= 0.001) {
|
||||
fixedRegs[0] = 0b0000000;
|
||||
} else if(fabsf(SX127x::bandwidth - 15.6) <= 0.001) {
|
||||
fixedRegs[0] = 0b00000000;
|
||||
fixedRegs[1] = 0x44;
|
||||
fixedRegs[2] = 0x00;
|
||||
rxFreq += 0.01562;
|
||||
} else if(fabs(_bw - 20.8) <= 0.001) {
|
||||
fixedRegs[0] = 0b0000000;
|
||||
} else if(fabsf(SX127x::bandwidth - 20.8) <= 0.001) {
|
||||
fixedRegs[0] = 0b00000000;
|
||||
fixedRegs[1] = 0x44;
|
||||
fixedRegs[2] = 0x00;
|
||||
rxFreq += 0.02083;
|
||||
} else if(fabs(_bw - 31.25) <= 0.001) {
|
||||
fixedRegs[0] = 0b0000000;
|
||||
} else if(fabsf(SX127x::bandwidth - 31.25) <= 0.001) {
|
||||
fixedRegs[0] = 0b00000000;
|
||||
fixedRegs[1] = 0x44;
|
||||
fixedRegs[2] = 0x00;
|
||||
rxFreq += 0.03125;
|
||||
} else if(fabs(_bw - 41.7) <= 0.001) {
|
||||
fixedRegs[0] = 0b0000000;
|
||||
} else if(fabsf(SX127x::bandwidth - 41.7) <= 0.001) {
|
||||
fixedRegs[0] = 0b00000000;
|
||||
fixedRegs[1] = 0x44;
|
||||
fixedRegs[2] = 0x00;
|
||||
rxFreq += 0.04167;
|
||||
} else if(fabs(_bw - 62.5) <= 0.001) {
|
||||
fixedRegs[0] = 0b0000000;
|
||||
} else if(fabsf(SX127x::bandwidth - 62.5) <= 0.001) {
|
||||
fixedRegs[0] = 0b00000000;
|
||||
fixedRegs[1] = 0x40;
|
||||
fixedRegs[2] = 0x00;
|
||||
} else if(fabs(_bw - 125.0) <= 0.001) {
|
||||
fixedRegs[0] = 0b0000000;
|
||||
} else if(fabsf(SX127x::bandwidth - 125.0) <= 0.001) {
|
||||
fixedRegs[0] = 0b00000000;
|
||||
fixedRegs[1] = 0x40;
|
||||
fixedRegs[2] = 0x00;
|
||||
} else if(fabs(_bw - 250.0) <= 0.001) {
|
||||
fixedRegs[0] = 0b0000000;
|
||||
} else if(fabsf(SX127x::bandwidth - 250.0) <= 0.001) {
|
||||
fixedRegs[0] = 0b00000000;
|
||||
fixedRegs[1] = 0x40;
|
||||
fixedRegs[2] = 0x00;
|
||||
} else if(fabs(_bw - 500.0) <= 0.001) {
|
||||
fixedRegs[0] = 0b1000000;
|
||||
fixedRegs[1] = _mod->SPIreadRegister(0x2F);
|
||||
fixedRegs[2] = _mod->SPIreadRegister(0x30);
|
||||
} else if(fabsf(SX127x::bandwidth - 500.0) <= 0.001) {
|
||||
fixedRegs[0] = 0b10000000;
|
||||
fixedRegs[1] = mod->SPIreadRegister(0x2F);
|
||||
fixedRegs[2] = mod->SPIreadRegister(0x30);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@@ -619,13 +696,13 @@ void SX1278::errataFix(bool rx) {
|
||||
if(rx) {
|
||||
SX127x::setFrequencyRaw(rxFreq);
|
||||
} else {
|
||||
SX127x::setFrequencyRaw(_freq);
|
||||
SX127x::setFrequencyRaw(frequency);
|
||||
}
|
||||
|
||||
// finally, apply errata fixes
|
||||
_mod->SPIsetRegValue(0x31, fixedRegs[0], 7, 7);
|
||||
_mod->SPIsetRegValue(0x2F, fixedRegs[1]);
|
||||
_mod->SPIsetRegValue(0x30, fixedRegs[2]);
|
||||
mod->SPIsetRegValue(0x31, fixedRegs[0], 7, 7);
|
||||
mod->SPIsetRegValue(0x2F, fixedRegs[1]);
|
||||
mod->SPIsetRegValue(0x30, fixedRegs[2]);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,101 +3,102 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "SX127x.h"
|
||||
|
||||
// SX1278 specific register map
|
||||
#define RADIOLIB_SX1278_REG_MODEM_CONFIG_3 0x26
|
||||
#define RADIOLIB_SX1278_REG_PLL_HOP 0x44
|
||||
#define RADIOLIB_SX1278_REG_TCXO 0x4B
|
||||
#define RADIOLIB_SX1278_REG_PA_DAC 0x4D
|
||||
#define RADIOLIB_SX1278_REG_FORMER_TEMP 0x5B
|
||||
#define RADIOLIB_SX1278_REG_REG_BIT_RATE_FRAC 0x5D
|
||||
#define RADIOLIB_SX1278_REG_AGC_REF 0x61
|
||||
#define RADIOLIB_SX1278_REG_AGC_THRESH_1 0x62
|
||||
#define RADIOLIB_SX1278_REG_AGC_THRESH_2 0x63
|
||||
#define RADIOLIB_SX1278_REG_AGC_THRESH_3 0x64
|
||||
#define RADIOLIB_SX1278_REG_PLL 0x70
|
||||
#define RADIOLIB_SX1278_REG_MODEM_CONFIG_3 0x26
|
||||
#define RADIOLIB_SX1278_REG_PLL_HOP 0x44
|
||||
#define RADIOLIB_SX1278_REG_TCXO 0x4B
|
||||
#define RADIOLIB_SX1278_REG_PA_DAC 0x4D
|
||||
#define RADIOLIB_SX1278_REG_FORMER_TEMP 0x5B
|
||||
#define RADIOLIB_SX1278_REG_BIT_RATE_FRAC 0x5D
|
||||
#define RADIOLIB_SX1278_REG_AGC_REF 0x61
|
||||
#define RADIOLIB_SX1278_REG_AGC_THRESH_1 0x62
|
||||
#define RADIOLIB_SX1278_REG_AGC_THRESH_2 0x63
|
||||
#define RADIOLIB_SX1278_REG_AGC_THRESH_3 0x64
|
||||
#define RADIOLIB_SX1278_REG_PLL 0x70
|
||||
|
||||
// SX1278 LoRa modem settings
|
||||
// RADIOLIB_SX1278_REG_OP_MODE MSB LSB DESCRIPTION
|
||||
#define RADIOLIB_SX1278_HIGH_FREQ 0b00000000 // 3 3 access HF test registers
|
||||
#define RADIOLIB_SX1278_LOW_FREQ 0b00001000 // 3 3 access LF test registers
|
||||
// RADIOLIB_SX1278_REG_OP_MODE MSB LSB DESCRIPTION
|
||||
#define RADIOLIB_SX1278_HIGH_FREQ 0b00000000 // 3 3 access HF test registers
|
||||
#define RADIOLIB_SX1278_LOW_FREQ 0b00001000 // 3 3 access LF test registers
|
||||
|
||||
// RADIOLIB_SX1278_REG_FRF_MSB + REG_FRF_MID + REG_FRF_LSB
|
||||
#define RADIOLIB_SX1278_FRF_MSB 0x6C // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
|
||||
#define RADIOLIB_SX1278_FRF_MID 0x80 // 7 0 where F(XOSC) = 32 MHz
|
||||
#define RADIOLIB_SX1278_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
|
||||
#define RADIOLIB_SX1278_FRF_MSB 0x6C // 7 0 carrier frequency setting: f_RF = (F(XOSC) * FRF)/2^19
|
||||
#define RADIOLIB_SX1278_FRF_MID 0x80 // 7 0 where F(XOSC) = 32 MHz
|
||||
#define RADIOLIB_SX1278_FRF_LSB 0x00 // 7 0 FRF = 3 byte value of FRF registers
|
||||
|
||||
// RADIOLIB_SX1278_REG_PA_CONFIG
|
||||
#define RADIOLIB_SX1278_MAX_POWER 0b01110000 // 6 4 max power: P_max = 10.8 + 0.6*MAX_POWER [dBm]; P_max(MAX_POWER = 0b111) = 15 dBm
|
||||
#define RADIOLIB_SX1278_LOW_POWER 0b00100000 // 6 4
|
||||
#define RADIOLIB_SX1278_MAX_POWER 0b01110000 // 6 4 max power: P_max = 10.8 + 0.6*MAX_POWER [dBm]; P_max(MAX_POWER = 0b111) = 15 dBm
|
||||
#define RADIOLIB_SX1278_LOW_POWER 0b00100000 // 6 4
|
||||
|
||||
// RADIOLIB_SX1278_REG_LNA
|
||||
#define RADIOLIB_SX1278_LNA_BOOST_LF_OFF 0b00000000 // 4 3 default LNA current
|
||||
#define RADIOLIB_SX1278_LNA_BOOST_LF_OFF 0b00000000 // 4 3 default LNA current
|
||||
|
||||
// SX127X_REG_MODEM_CONFIG_1
|
||||
#define RADIOLIB_SX1278_BW_7_80_KHZ 0b00000000 // 7 4 bandwidth: 7.80 kHz
|
||||
#define RADIOLIB_SX1278_BW_10_40_KHZ 0b00010000 // 7 4 10.40 kHz
|
||||
#define RADIOLIB_SX1278_BW_15_60_KHZ 0b00100000 // 7 4 15.60 kHz
|
||||
#define RADIOLIB_SX1278_BW_20_80_KHZ 0b00110000 // 7 4 20.80 kHz
|
||||
#define RADIOLIB_SX1278_BW_31_25_KHZ 0b01000000 // 7 4 31.25 kHz
|
||||
#define RADIOLIB_SX1278_BW_41_70_KHZ 0b01010000 // 7 4 41.70 kHz
|
||||
#define RADIOLIB_SX1278_BW_62_50_KHZ 0b01100000 // 7 4 62.50 kHz
|
||||
#define RADIOLIB_SX1278_BW_125_00_KHZ 0b01110000 // 7 4 125.00 kHz
|
||||
#define RADIOLIB_SX1278_BW_250_00_KHZ 0b10000000 // 7 4 250.00 kHz
|
||||
#define RADIOLIB_SX1278_BW_500_00_KHZ 0b10010000 // 7 4 500.00 kHz
|
||||
#define RADIOLIB_SX1278_CR_4_5 0b00000010 // 3 1 error coding rate: 4/5
|
||||
#define RADIOLIB_SX1278_CR_4_6 0b00000100 // 3 1 4/6
|
||||
#define RADIOLIB_SX1278_CR_4_7 0b00000110 // 3 1 4/7
|
||||
#define RADIOLIB_SX1278_CR_4_8 0b00001000 // 3 1 4/8
|
||||
#define RADIOLIB_SX1278_HEADER_EXPL_MODE 0b00000000 // 0 0 explicit header mode
|
||||
#define RADIOLIB_SX1278_HEADER_IMPL_MODE 0b00000001 // 0 0 implicit header mode
|
||||
#define RADIOLIB_SX1278_BW_7_80_KHZ 0b00000000 // 7 4 bandwidth: 7.80 kHz
|
||||
#define RADIOLIB_SX1278_BW_10_40_KHZ 0b00010000 // 7 4 10.40 kHz
|
||||
#define RADIOLIB_SX1278_BW_15_60_KHZ 0b00100000 // 7 4 15.60 kHz
|
||||
#define RADIOLIB_SX1278_BW_20_80_KHZ 0b00110000 // 7 4 20.80 kHz
|
||||
#define RADIOLIB_SX1278_BW_31_25_KHZ 0b01000000 // 7 4 31.25 kHz
|
||||
#define RADIOLIB_SX1278_BW_41_70_KHZ 0b01010000 // 7 4 41.70 kHz
|
||||
#define RADIOLIB_SX1278_BW_62_50_KHZ 0b01100000 // 7 4 62.50 kHz
|
||||
#define RADIOLIB_SX1278_BW_125_00_KHZ 0b01110000 // 7 4 125.00 kHz
|
||||
#define RADIOLIB_SX1278_BW_250_00_KHZ 0b10000000 // 7 4 250.00 kHz
|
||||
#define RADIOLIB_SX1278_BW_500_00_KHZ 0b10010000 // 7 4 500.00 kHz
|
||||
#define RADIOLIB_SX1278_CR_4_5 0b00000010 // 3 1 error coding rate: 4/5
|
||||
#define RADIOLIB_SX1278_CR_4_6 0b00000100 // 3 1 4/6
|
||||
#define RADIOLIB_SX1278_CR_4_7 0b00000110 // 3 1 4/7
|
||||
#define RADIOLIB_SX1278_CR_4_8 0b00001000 // 3 1 4/8
|
||||
#define RADIOLIB_SX1278_HEADER_EXPL_MODE 0b00000000 // 0 0 explicit header mode
|
||||
#define RADIOLIB_SX1278_HEADER_IMPL_MODE 0b00000001 // 0 0 implicit header mode
|
||||
|
||||
// SX127X_REG_MODEM_CONFIG_2
|
||||
#define RADIOLIB_SX1278_RX_CRC_MODE_OFF 0b00000000 // 2 2 CRC disabled
|
||||
#define RADIOLIB_SX1278_RX_CRC_MODE_ON 0b00000100 // 2 2 CRC enabled
|
||||
#define RADIOLIB_SX1278_RX_CRC_MODE_OFF 0b00000000 // 2 2 CRC disabled
|
||||
#define RADIOLIB_SX1278_RX_CRC_MODE_ON 0b00000100 // 2 2 CRC enabled
|
||||
|
||||
// RADIOLIB_SX1278_REG_MODEM_CONFIG_3
|
||||
#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF 0b00000000 // 3 3 low data rate optimization disabled
|
||||
#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON 0b00001000 // 3 3 low data rate optimization enabled
|
||||
#define RADIOLIB_SX1278_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
|
||||
#define RADIOLIB_SX1278_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
|
||||
#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_OFF 0b00000000 // 3 3 low data rate optimization disabled
|
||||
#define RADIOLIB_SX1278_LOW_DATA_RATE_OPT_ON 0b00001000 // 3 3 low data rate optimization enabled
|
||||
#define RADIOLIB_SX1278_AGC_AUTO_OFF 0b00000000 // 2 2 LNA gain set by REG_LNA
|
||||
#define RADIOLIB_SX1278_AGC_AUTO_ON 0b00000100 // 2 2 LNA gain set by internal AGC loop
|
||||
|
||||
// SX127X_REG_VERSION
|
||||
#define RADIOLIB_SX1278_CHIP_VERSION 0x12
|
||||
#define RADIOLIB_SX1278_CHIP_VERSION 0x12 // this is the "official" version listed in datasheet
|
||||
#define RADIOLIB_SX1278_CHIP_VERSION_ALT 0x13 // appears sometimes
|
||||
#define RADIOLIB_SX1278_CHIP_VERSION_RFM9X 0x11 // this value is used for the RFM9x
|
||||
|
||||
// SX1278 FSK modem settings
|
||||
// SX127X_REG_PA_RAMP
|
||||
#define RADIOLIB_SX1278_NO_SHAPING 0b00000000 // 6 5 data shaping: no shaping (default)
|
||||
#define RADIOLIB_SX1278_FSK_GAUSSIAN_1_0 0b00100000 // 6 5 FSK modulation Gaussian filter, BT = 1.0
|
||||
#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_5 0b01000000 // 6 5 FSK modulation Gaussian filter, BT = 0.5
|
||||
#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_3 0b01100000 // 6 5 FSK modulation Gaussian filter, BT = 0.3
|
||||
#define RADIOLIB_SX1278_OOK_FILTER_BR 0b00100000 // 6 5 OOK modulation filter, f_cutoff = BR
|
||||
#define RADIOLIB_SX1278_OOK_FILTER_2BR 0b01000000 // 6 5 OOK modulation filter, f_cutoff = 2*BR
|
||||
#define RADIOLIB_SX1278_NO_SHAPING 0b00000000 // 6 5 data shaping: no shaping (default)
|
||||
#define RADIOLIB_SX1278_FSK_GAUSSIAN_1_0 0b00100000 // 6 5 FSK modulation Gaussian filter, BT = 1.0
|
||||
#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_5 0b01000000 // 6 5 FSK modulation Gaussian filter, BT = 0.5
|
||||
#define RADIOLIB_SX1278_FSK_GAUSSIAN_0_3 0b01100000 // 6 5 FSK modulation Gaussian filter, BT = 0.3
|
||||
#define RADIOLIB_SX1278_OOK_FILTER_BR 0b00100000 // 6 5 OOK modulation filter, f_cutoff = BR
|
||||
#define RADIOLIB_SX1278_OOK_FILTER_2BR 0b01000000 // 6 5 OOK modulation filter, f_cutoff = 2*BR
|
||||
|
||||
// RADIOLIB_SX1278_REG_AGC_REF
|
||||
#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_LF 0x19 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]: below 525 MHz
|
||||
#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_HF 0x1C // 5 0 above 779 MHz
|
||||
#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_LF 0x19 // 5 0 floor reference for AGC thresholds: AgcRef = -174 + 10*log(2*RxBw) + 8 + AGC_REFERENCE_LEVEL [dBm]: below 525 MHz
|
||||
#define RADIOLIB_SX1278_AGC_REFERENCE_LEVEL_HF 0x1C // 5 0 above 779 MHz
|
||||
|
||||
// RADIOLIB_SX1278_REG_AGC_THRESH_1
|
||||
#define RADIOLIB_SX1278_AGC_STEP_1_LF 0x0C // 4 0 1st AGC threshold: below 525 MHz
|
||||
#define RADIOLIB_SX1278_AGC_STEP_1_HF 0x0E // 4 0 above 779 MHz
|
||||
#define RADIOLIB_SX1278_AGC_STEP_1_LF 0x0C // 4 0 1st AGC threshold: below 525 MHz
|
||||
#define RADIOLIB_SX1278_AGC_STEP_1_HF 0x0E // 4 0 above 779 MHz
|
||||
|
||||
// RADIOLIB_SX1278_REG_AGC_THRESH_2
|
||||
#define RADIOLIB_SX1278_AGC_STEP_2_LF 0x40 // 7 4 2nd AGC threshold: below 525 MHz
|
||||
#define RADIOLIB_SX1278_AGC_STEP_2_HF 0x50 // 7 4 above 779 MHz
|
||||
#define RADIOLIB_SX1278_AGC_STEP_3 0x0B // 3 0 3rd AGC threshold
|
||||
#define RADIOLIB_SX1278_AGC_STEP_2_LF 0x40 // 7 4 2nd AGC threshold: below 525 MHz
|
||||
#define RADIOLIB_SX1278_AGC_STEP_2_HF 0x50 // 7 4 above 779 MHz
|
||||
#define RADIOLIB_SX1278_AGC_STEP_3 0x0B // 3 0 3rd AGC threshold
|
||||
|
||||
// RADIOLIB_SX1278_REG_AGC_THRESH_3
|
||||
#define RADIOLIB_SX1278_AGC_STEP_4 0xC0 // 7 4 4th AGC threshold
|
||||
#define RADIOLIB_SX1278_AGC_STEP_5 0x0C // 4 0 5th AGC threshold
|
||||
#define RADIOLIB_SX1278_AGC_STEP_4 0xC0 // 7 4 4th AGC threshold
|
||||
#define RADIOLIB_SX1278_AGC_STEP_5 0x0C // 4 0 5th AGC threshold
|
||||
|
||||
/*!
|
||||
\class SX1278
|
||||
|
||||
\brief Derived class for %SX1278 modules. Also used as base class for SX1276, SX1277, SX1279, RFM95 and RFM96.
|
||||
All of these modules use the same basic hardware and only differ in parameter ranges (and names).
|
||||
*/
|
||||
@@ -108,56 +109,38 @@ class SX1278: public SX127x {
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1278(Module* mod);
|
||||
SX1278(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
/*!
|
||||
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
|
||||
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of FSK preamble in bits.
|
||||
|
||||
\param enableOOK Use OOK modulation instead of FSK.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
|
||||
@@ -171,58 +154,92 @@ class SX1278: public SX127x {
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in %LoRa mode.
|
||||
|
||||
\param bw %LoRa link bandwidth to be set in kHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setBandwidth(float bw);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in %LoRa mode.
|
||||
|
||||
\param cr %LoRa link coding rate denominator to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCodingRate(uint8_t cr);
|
||||
|
||||
/*!
|
||||
\brief Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin).
|
||||
High power +20 dBm operation is also supported, on the PA_BOOST pin.
|
||||
|
||||
\param power Transmission output power in dBm.
|
||||
|
||||
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output. Defaults to PA_BOOST.
|
||||
|
||||
\brief Sets FSK bit rate. Allowed values range from 0.5 to 300 kbps. Only available in FSK mode.
|
||||
\param br Bit rate to be set (in kbps).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power, bool useRfo = false);
|
||||
int16_t setBitRate(float br) override;
|
||||
|
||||
/*!
|
||||
\brief Set data.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataRate(DataRate_t dr) override;
|
||||
|
||||
/*!
|
||||
\brief Check the data rate can be configured by this module.
|
||||
\param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkDataRate(DataRate_t dr) override;
|
||||
|
||||
/*!
|
||||
\brief Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin).
|
||||
High power +20 dBm operation is also supported, on the PA_BOOST pin. Defaults to PA_BOOST.
|
||||
\param power Transmission output power in dBm.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
/*!
|
||||
\brief Sets transmission output power. Allowed values range from -3 to 15 dBm (RFO pin) or +2 to +17 dBm (PA_BOOST pin).
|
||||
High power +20 dBm operation is also supported, on the PA_BOOST pin.
|
||||
\param power Transmission output power in dBm.
|
||||
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power, bool useRfo);
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
This method is needed for compatibility with PhysicalLayer::checkOutputPower.
|
||||
\param power Output power in dBm, assumes PA_BOOST pin.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped) override;
|
||||
|
||||
/*!
|
||||
\brief Check if output power is configurable.
|
||||
\param power Output power in dBm.
|
||||
\param clipped Clipped output power value to what is possible within the module's range.
|
||||
\param useRfo Whether to use the RFO (true) or the PA_BOOST (false) pin for the RF output.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t checkOutputPower(int8_t power, int8_t* clipped, bool useRfo);
|
||||
|
||||
/*!
|
||||
\brief Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended). Only available in %LoRa mode.
|
||||
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
\param gain Gain of receiver LNA (low-noise amplifier) to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setGain(uint8_t gain);
|
||||
@@ -230,9 +247,7 @@ class SX1278: public SX127x {
|
||||
/*!
|
||||
\brief Sets Gaussian filter bandwidth-time product that will be used for data shaping. Only available in FSK mode with FSK modulation.
|
||||
Allowed values are RADIOLIB_SHAPING_0_3, RADIOLIB_SHAPING_0_5 or RADIOLIB_SHAPING_1_0. Set to RADIOLIB_SHAPING_NONE to disable data shaping.
|
||||
|
||||
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataShaping(uint8_t sh) override;
|
||||
@@ -241,68 +256,65 @@ class SX1278: public SX127x {
|
||||
\brief Sets filter cutoff frequency that will be used for data shaping.
|
||||
Allowed values are 1 for frequency equal to bit rate and 2 for frequency equal to 2x bit rate. Set to 0 to disable data shaping.
|
||||
Only available in FSK mode with OOK modulation.
|
||||
|
||||
\param sh Cutoff frequency that will be used for data shaping
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataShapingOOK(uint8_t sh);
|
||||
|
||||
/*!
|
||||
\brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem.
|
||||
|
||||
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode.
|
||||
|
||||
\returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem.
|
||||
\brief Gets recorded signal strength indicator.
|
||||
Overload with packet mode enabled for PhysicalLayer compatibility.
|
||||
\returns RSSI value in dBm.
|
||||
*/
|
||||
float getRSSI(bool skipReceive = false);
|
||||
float getRSSI() override;
|
||||
|
||||
/*!
|
||||
\brief Gets recorded signal strength indicator.
|
||||
\param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK.
|
||||
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode.
|
||||
\returns RSSI value in dBm.
|
||||
*/
|
||||
float getRSSI(bool packet, bool skipReceive = false);
|
||||
|
||||
/*!
|
||||
\brief Enables/disables CRC check of received packets.
|
||||
|
||||
\param enable Enable (true) or disable (false) CRC.
|
||||
|
||||
\param mode Set CRC mode to SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false) or SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode.
|
||||
|
||||
\param mode Set CRC mode to SX127X_CRC_WHITENING_TYPE_CCITT for CCITT, polynomial X16 + X12 + X5 + 1 (false)
|
||||
or SX127X_CRC_WHITENING_TYPE_IBM for IBM, polynomial X16 + X15 + X2 + 1 (true). Only valid in FSK mode.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCRC(bool enable, bool mode = false);
|
||||
|
||||
/*!
|
||||
\brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method, LDRO will always be set to
|
||||
the provided value, regardless of symbol length. To re-enable automatic LDRO configuration, call SX1278::autoLDRO()
|
||||
|
||||
\brief Forces LoRa low data rate optimization. Only available in LoRa mode. After calling this method,
|
||||
LDRO will always be set to the provided value, regardless of symbol length.
|
||||
To re-enable automatic LDRO configuration, call SX1278::autoLDRO()
|
||||
\param enable Force LDRO to be always enabled (true) or disabled (false).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t forceLDRO(bool enable);
|
||||
|
||||
/*!
|
||||
\brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method, LDRO will be enabled automatically
|
||||
when symbol length exceeds 16 ms.
|
||||
|
||||
\brief Re-enables automatic LDRO configuration. Only available in LoRa mode. After calling this method,
|
||||
LDRO will be enabled automatically when symbol length exceeds 16 ms.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t autoLDRO();
|
||||
|
||||
/*!
|
||||
\brief Set implicit header mode for future reception/transmission. Required for spreading factor 6.
|
||||
|
||||
\brief Set implicit header mode for future reception/transmission. Required for spreading factor 6.
|
||||
\param len Payload length in bytes.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t implicitHeader(size_t len);
|
||||
|
||||
/*!
|
||||
\brief Set explicit header mode for future reception/transmission.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t explicitHeader();
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
int16_t setBandwidthRaw(uint8_t newBandwidth);
|
||||
@@ -311,16 +323,22 @@ class SX1278: public SX127x {
|
||||
int16_t setHeaderType(uint8_t headerType, size_t len = 0xFF);
|
||||
|
||||
int16_t configFSK();
|
||||
void errataFix(bool rx);
|
||||
void errataFix(bool rx) override;
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
bool _ldroAuto = true;
|
||||
bool _ldroEnabled = false;
|
||||
bool ldroAuto = true;
|
||||
bool ldroEnabled = false;
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
\class RFM98
|
||||
\brief Only exists as alias for SX1278, since there seems to be no difference between %RFM98 and %SX1278 modules.
|
||||
*/
|
||||
RADIOLIB_TYPE_ALIAS(SX1278, RFM98)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "SX1279.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
SX1279::SX1279(Module* mod) : SX1278(mod) {
|
||||
|
||||
@@ -7,7 +7,8 @@ SX1279::SX1279(Module* mod) : SX1278(mod) {
|
||||
|
||||
int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint16_t preambleLength, uint8_t gain) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::begin(RADIOLIB_SX1278_CHIP_VERSION, syncWord, preambleLength);
|
||||
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
|
||||
int16_t state = SX127x::begin(versions, 3, syncWord, preambleLength);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure publicly accessible settings
|
||||
@@ -29,12 +30,17 @@ int16_t SX1279::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t sync
|
||||
state = setGain(gain);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set publicly accessible settings that are not a part of begin method
|
||||
state = setCRC(true);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1279::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t power, uint16_t preambleLength, bool enableOOK) {
|
||||
// execute common part
|
||||
int16_t state = SX127x::beginFSK(RADIOLIB_SX1278_CHIP_VERSION, br, freqDev, rxBw, preambleLength, enableOOK);
|
||||
uint8_t versions[] = { RADIOLIB_SX1278_CHIP_VERSION, RADIOLIB_SX1278_CHIP_VERSION_ALT, RADIOLIB_SX1278_CHIP_VERSION_RFM9X };
|
||||
int16_t state = SX127x::beginFSK(versions, 3, freqDev, rxBw, preambleLength, enableOOK);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// configure settings not accessible by API
|
||||
@@ -45,6 +51,9 @@ int16_t SX1279::beginFSK(float freq, float br, float freqDev, float rxBw, int8_t
|
||||
state = setFrequency(freq);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setBitRate(br);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = setOutputPower(power);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
@@ -65,7 +74,7 @@ int16_t SX1279::setFrequency(float freq) {
|
||||
// set frequency and if successful, save the new setting
|
||||
int16_t state = SX127x::setFrequencyRaw(freq);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
SX127x::_freq = freq;
|
||||
SX127x::frequency = freq;
|
||||
}
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX127X)
|
||||
#if !RADIOLIB_EXCLUDE_SX127X
|
||||
|
||||
#include "SX1278.h"
|
||||
|
||||
/*!
|
||||
\class SX1279
|
||||
|
||||
\brief Derived class for %SX1279 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class SX1279: public SX1278 {
|
||||
@@ -19,56 +18,38 @@ class SX1279: public SX1278 {
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1279(Module* mod);
|
||||
SX1279(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 960.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = RADIOLIB_SX127X_SYNC_WORD, int8_t power = 10, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
/*!
|
||||
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
|
||||
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param preambleLength Length of FSK preamble in bits.
|
||||
|
||||
\param enableOOK Use OOK modulation instead of FSK.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 125.0, int8_t power = 10, uint16_t preambleLength = 16, bool enableOOK = false);
|
||||
@@ -77,14 +58,12 @@ class SX1279: public SX1278 {
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 960.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,20 +1,22 @@
|
||||
#include "SX1280.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX128X)
|
||||
#include <string.h>
|
||||
#if !RADIOLIB_EXCLUDE_SX128X
|
||||
|
||||
SX1280::SX1280(Module* mod) : SX1281(mod) {
|
||||
|
||||
}
|
||||
|
||||
int16_t SX1280::range(bool master, uint32_t addr) {
|
||||
int16_t SX1280::range(bool master, uint32_t addr, uint16_t calTable[3][6]) {
|
||||
// start ranging
|
||||
int16_t state = startRanging(master, addr);
|
||||
int16_t state = startRanging(master, addr, calTable);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// wait until ranging is finished
|
||||
uint32_t start = _mod->millis();
|
||||
while(!_mod->digitalRead(_mod->getIrq())) {
|
||||
_mod->yield();
|
||||
if(_mod->millis() - start > 10000) {
|
||||
Module* mod = this->getMod();
|
||||
RadioLibTime_t start = mod->hal->millis();
|
||||
while(!mod->hal->digitalRead(mod->getIrq())) {
|
||||
mod->hal->yield();
|
||||
if(mod->hal->millis() - start > 10000) {
|
||||
clearIrqStatus();
|
||||
standby();
|
||||
return(RADIOLIB_ERR_RANGING_TIMEOUT);
|
||||
@@ -31,7 +33,7 @@ int16_t SX1280::range(bool master, uint32_t addr) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX1280::startRanging(bool master, uint32_t addr) {
|
||||
int16_t SX1280::startRanging(bool master, uint32_t addr, uint16_t calTable[3][6]) {
|
||||
// check active modem
|
||||
uint8_t modem = getPacketType();
|
||||
if(!((modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) || (modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING))) {
|
||||
@@ -49,21 +51,23 @@ int16_t SX1280::startRanging(bool master, uint32_t addr) {
|
||||
}
|
||||
|
||||
// set modulation parameters
|
||||
state = setModulationParams(_sf, _bw, _cr);
|
||||
state = setModulationParams(this->spreadingFactor, this->bandwidth, this->codingRateLoRa);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set packet parameters
|
||||
state = setPacketParamsLoRa(_preambleLengthLoRa, _headerType, _payloadLen, _crcLoRa);
|
||||
state = setPacketParamsLoRa(this->preambleLengthLoRa, this->headerType, this->payloadLen, this->crcLoRa);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// check all address bits
|
||||
uint8_t regValue;
|
||||
state = readRegister(RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, ®Value, 1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
regValue &= 0b00111111;
|
||||
regValue |= 0b11000000;
|
||||
state = writeRegister(RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, ®Value, 1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
if(!master) {
|
||||
uint8_t regValue;
|
||||
state = readRegister(RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, ®Value, 1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
regValue &= 0b00111111;
|
||||
regValue |= 0b11000000;
|
||||
state = writeRegister(RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_WIDTH, ®Value, 1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
// set remaining parameter values
|
||||
uint32_t addrReg = RADIOLIB_SX128X_REG_SLAVE_RANGING_ADDRESS_BYTE_3;
|
||||
@@ -84,23 +88,30 @@ int16_t SX1280::startRanging(bool master, uint32_t addr) {
|
||||
state = setDioIrqParams(irqMask, irqDio1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set calibration values
|
||||
uint8_t index = (_sf >> 4) - 5;
|
||||
static const uint16_t calTable[3][6] = {
|
||||
// this is the default calibration from AN1200.29
|
||||
uint16_t calTbl[3][6] = {
|
||||
{ 10299, 10271, 10244, 10242, 10230, 10246 },
|
||||
{ 11486, 11474, 11453, 11426, 11417, 11401 },
|
||||
{ 13308, 13493, 13528, 13515, 13430, 13376 }
|
||||
};
|
||||
|
||||
// check if user provided some custom calibration
|
||||
if(calTable != NULL) {
|
||||
memcpy(calTbl, calTable, sizeof(calTbl));
|
||||
}
|
||||
|
||||
// set calibration values
|
||||
uint8_t index = (this->spreadingFactor >> 4) - 5;
|
||||
uint16_t val = 0;
|
||||
switch(_bw) {
|
||||
switch(this->bandwidth) {
|
||||
case(RADIOLIB_SX128X_LORA_BW_406_25):
|
||||
val = calTable[0][index];
|
||||
val = calTbl[0][index];
|
||||
break;
|
||||
case(RADIOLIB_SX128X_LORA_BW_812_50):
|
||||
val = calTable[1][index];
|
||||
val = calTbl[1][index];
|
||||
break;
|
||||
case(RADIOLIB_SX128X_LORA_BW_1625_00):
|
||||
val = calTable[2][index];
|
||||
val = calTbl[2][index];
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_BANDWIDTH);
|
||||
@@ -165,8 +176,9 @@ float SX1280::getRangingResult() {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// calculate the real result
|
||||
uint32_t raw = ((uint32_t)data[0] << 16) | ((uint32_t)data[1] << 8) | data[2];
|
||||
return((float)raw * 150.0 / (4.096 * _bwKhz));
|
||||
uint32_t uraw = ((uint32_t)data[0] << 16) | ((uint32_t)data[1] << 8) | data[2];
|
||||
int32_t raw = (uraw & ((1UL << 23) - 1)) | (uraw >> 23 << 31);
|
||||
return((float)raw * 150.0 / (4.096 * this->bandwidthKhz));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX128X)
|
||||
#if !RADIOLIB_EXCLUDE_SX128X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "SX128x.h"
|
||||
@@ -11,48 +11,41 @@
|
||||
|
||||
/*!
|
||||
\class SX1280
|
||||
|
||||
\brief Derived class for %SX1280 modules.
|
||||
*/
|
||||
class SX1280: public SX1281 {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
SX1280(Module* mod);
|
||||
SX1280(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
/*!
|
||||
\brief Blocking ranging method.
|
||||
|
||||
\param master Whether to execute ranging in master mode (true) or slave mode (false).
|
||||
|
||||
\param addr Ranging address to be used.
|
||||
|
||||
\param calTable Ranging calibration table - set to NULL to use the default.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t range(bool master, uint32_t addr);
|
||||
int16_t range(bool master, uint32_t addr, uint16_t calTable[3][6] = NULL);
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven ranging method.
|
||||
|
||||
\param master Whether to execute ranging in master mode (true) or slave mode (false).
|
||||
|
||||
\param addr Ranging address to be used.
|
||||
|
||||
\param calTable Ranging calibration table - set to NULL to use the default.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startRanging(bool master, uint32_t addr);
|
||||
int16_t startRanging(bool master, uint32_t addr, uint16_t calTable[3][6] = NULL);
|
||||
|
||||
/*!
|
||||
\brief Gets ranging result of the last ranging exchange.
|
||||
|
||||
\returns Ranging result in meters.
|
||||
*/
|
||||
float getRangingResult();
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "SX1281.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX128X)
|
||||
#if !RADIOLIB_EXCLUDE_SX128X
|
||||
|
||||
SX1281::SX1281(Module* mod) : SX128x(mod) {
|
||||
|
||||
|
||||
@@ -3,26 +3,24 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX128X)
|
||||
#if !RADIOLIB_EXCLUDE_SX128X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "SX128x.h"
|
||||
|
||||
/*!
|
||||
\class SX1281
|
||||
|
||||
\brief Derived class for %SX1281 modules.
|
||||
*/
|
||||
class SX1281: public SX128x {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
SX1281(Module* mod);
|
||||
SX1281(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "SX1282.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX128X)
|
||||
#if !RADIOLIB_EXCLUDE_SX128X
|
||||
|
||||
/// \todo implement advanced ranging
|
||||
SX1282::SX1282(Module* mod) : SX1280(mod) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SX128X)
|
||||
#if !RADIOLIB_EXCLUDE_SX128X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "SX128x.h"
|
||||
@@ -11,19 +11,17 @@
|
||||
|
||||
/*!
|
||||
\class SX1282
|
||||
|
||||
\brief Derived class for %SX1282 modules.
|
||||
*/
|
||||
class SX1282: public SX1280 {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
SX1282(Module* mod);
|
||||
SX1282(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
#include "Si4430.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SI443X)
|
||||
#if !RADIOLIB_EXCLUDE_SI443X
|
||||
|
||||
Si4430::Si4430(Module* mod) : Si4432(mod) {
|
||||
|
||||
@@ -9,7 +9,7 @@ int16_t Si4430::begin(float freq, float br, float freqDev, float rxBw, int8_t po
|
||||
// execute common part
|
||||
int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen);
|
||||
RADIOLIB_ASSERT(state);
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSi4430"));
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSi4430");
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
@@ -32,7 +32,8 @@ int16_t Si4430::setOutputPower(int8_t power) {
|
||||
RADIOLIB_CHECK_RANGE(power, -8, 13, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
|
||||
// set output power
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0));
|
||||
Module* mod = this->getMod();
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SI443X)
|
||||
#if !RADIOLIB_EXCLUDE_SI443X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "Si4432.h"
|
||||
|
||||
/*!
|
||||
\class Si4430
|
||||
|
||||
\brief Derived class for %Si4430 modules.
|
||||
*/
|
||||
class Si4430: public Si4432 {
|
||||
@@ -20,28 +19,20 @@ class Si4430: public Si4432 {
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio chip.
|
||||
*/
|
||||
Si4430(Module* mod);
|
||||
Si4430(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 900.0 MHz to 960.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps.
|
||||
|
||||
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16);
|
||||
@@ -50,28 +41,23 @@ class Si4430: public Si4432 {
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 900.0 MHz to 960.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values range from -8 to 13 dBm in 3 dBm steps.
|
||||
|
||||
\param power Output power to be set in dBm.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Si4431.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SI443X)
|
||||
#if !RADIOLIB_EXCLUDE_SI443X
|
||||
|
||||
Si4431::Si4431(Module* mod) : Si4432(mod) {
|
||||
|
||||
@@ -9,7 +9,7 @@ int16_t Si4431::begin(float freq, float br, float freqDev, float rxBw, int8_t po
|
||||
// execute common part
|
||||
int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen);
|
||||
RADIOLIB_ASSERT(state);
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSi4431"));
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSi4431");
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
@@ -25,7 +25,8 @@ int16_t Si4431::setOutputPower(int8_t power) {
|
||||
RADIOLIB_CHECK_RANGE(power, -8, 13, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
|
||||
// set output power
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0));
|
||||
Module* mod = this->getMod();
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 8) / 3), 2, 0));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SI443X)
|
||||
#if !RADIOLIB_EXCLUDE_SI443X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "Si4432.h"
|
||||
|
||||
/*!
|
||||
\class Si4431
|
||||
|
||||
\brief Derived class for %Si4431 modules.
|
||||
*/
|
||||
class Si4431: public Si4432 {
|
||||
@@ -20,28 +19,20 @@ class Si4431: public Si4432 {
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio chip.
|
||||
*/
|
||||
Si4431(Module* mod);
|
||||
Si4431(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 240.0 MHz to 930.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from -8 to 13 dBm in 3 dBm steps.
|
||||
|
||||
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16);
|
||||
@@ -50,19 +41,16 @@ class Si4431: public Si4432 {
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values range from -8 to 13 dBm in 3 dBm steps.
|
||||
|
||||
\param power Output power to be set in dBm.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "Si4432.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SI443X)
|
||||
#if !RADIOLIB_EXCLUDE_SI443X
|
||||
|
||||
Si4432::Si4432(Module* mod) : Si443x(mod) {
|
||||
|
||||
@@ -9,7 +9,7 @@ int16_t Si4432::begin(float freq, float br, float freqDev, float rxBw, int8_t po
|
||||
// execute common part
|
||||
int16_t state = Si443x::begin(br, freqDev, rxBw, preambleLen);
|
||||
RADIOLIB_ASSERT(state);
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSi4432"));
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSi4432");
|
||||
|
||||
// configure publicly accessible settings
|
||||
state = setFrequency(freq);
|
||||
@@ -32,7 +32,8 @@ int16_t Si4432::setOutputPower(int8_t power) {
|
||||
RADIOLIB_CHECK_RANGE(power, -1, 20, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
|
||||
|
||||
// set output power
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 1) / 3), 2, 0));
|
||||
Module* mod = this->getMod();
|
||||
return(mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TX_POWER, (uint8_t)((power + 1) / 3), 2, 0));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_SI443X)
|
||||
#if !RADIOLIB_EXCLUDE_SI443X
|
||||
|
||||
#include "../../Module.h"
|
||||
#include "Si443x.h"
|
||||
|
||||
/*!
|
||||
\class Si4432
|
||||
|
||||
\brief Derived class for %Si4432 modules.
|
||||
*/
|
||||
class Si4432: public Si443x {
|
||||
@@ -20,28 +19,20 @@ class Si4432: public Si443x {
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio chip.
|
||||
*/
|
||||
Si4432(Module* mod);
|
||||
Si4432(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 240.0 MHz to 930.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 0.123 to 256.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.625 to 320.0 kbps.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values range from 2.6 to 620.7 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from -1 to 20 dBm in 3 dBm steps.
|
||||
|
||||
\param preambleLen Preamble Length in bits. Defaults to 16 bits.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float br = 4.8, float freqDev = 5.0, float rxBw = 181.1, int8_t power = 10, uint8_t preambleLen = 16);
|
||||
@@ -50,28 +41,23 @@ class Si4432: public Si443x {
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 240.0 MHz to 930.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values range from -1 to 20 dBm in 3 dBm steps.
|
||||
|
||||
\param power Output power to be set in dBm.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
int16_t setOutputPower(int8_t power) override;
|
||||
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
protected:
|
||||
#endif
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1,32 +1,29 @@
|
||||
#include "Si443x.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_SI443X)
|
||||
#include <math.h>
|
||||
#if !RADIOLIB_EXCLUDE_SI443X
|
||||
|
||||
Si443x::Si443x(Module* mod) : PhysicalLayer(RADIOLIB_SI443X_FREQUENCY_STEP_SIZE, RADIOLIB_SI443X_MAX_PACKET_LENGTH) {
|
||||
_mod = mod;
|
||||
}
|
||||
|
||||
Module* Si443x::getMod() {
|
||||
return(_mod);
|
||||
this->mod = mod;
|
||||
}
|
||||
|
||||
int16_t Si443x::begin(float br, float freqDev, float rxBw, uint8_t preambleLen) {
|
||||
// set module properties
|
||||
_mod->init();
|
||||
_mod->pinMode(_mod->getIrq(), INPUT);
|
||||
_mod->pinMode(_mod->getRst(), OUTPUT);
|
||||
_mod->digitalWrite(_mod->getRst(), LOW);
|
||||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
|
||||
|
||||
// try to find the Si443x chip
|
||||
if(!Si443x::findChip()) {
|
||||
RADIOLIB_DEBUG_PRINTLN(F("No Si443x found!"));
|
||||
_mod->term();
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("No Si443x found!");
|
||||
this->mod->term();
|
||||
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
|
||||
} else {
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tSi443x"));
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tSi443x");
|
||||
}
|
||||
|
||||
// reset the device
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_SOFTWARE_RESET);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_SOFTWARE_RESET);
|
||||
|
||||
// clear POR interrupt
|
||||
clearIRQFlags();
|
||||
@@ -67,53 +64,46 @@ int16_t Si443x::begin(float br, float freqDev, float rxBw, uint8_t preambleLen)
|
||||
}
|
||||
|
||||
void Si443x::reset() {
|
||||
_mod->pinMode(_mod->getRst(), OUTPUT);
|
||||
_mod->digitalWrite(_mod->getRst(), HIGH);
|
||||
_mod->delay(1);
|
||||
_mod->digitalWrite(_mod->getRst(), LOW);
|
||||
_mod->delay(100);
|
||||
this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
|
||||
this->mod->hal->delay(1);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
|
||||
this->mod->hal->delay(100);
|
||||
}
|
||||
|
||||
int16_t Si443x::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
int16_t Si443x::transmit(const uint8_t* data, size_t len, uint8_t addr) {
|
||||
// calculate timeout (5ms + 500 % of expected time-on-air)
|
||||
uint32_t timeout = 5000000 + (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 5000000.0);
|
||||
RadioLibTime_t timeout = 5 + (uint32_t)((((float)(len * 8)) / this->bitRate) * 5);
|
||||
|
||||
// start transmission
|
||||
int16_t state = startTransmit(data, len, addr);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// wait for transmission end or timeout
|
||||
uint32_t start = _mod->micros();
|
||||
while(_mod->digitalRead(_mod->getIrq())) {
|
||||
_mod->yield();
|
||||
if(_mod->micros() - start > timeout) {
|
||||
standby();
|
||||
clearIRQFlags();
|
||||
RadioLibTime_t start = this->mod->hal->millis();
|
||||
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
|
||||
this->mod->hal->yield();
|
||||
if(this->mod->hal->millis() - start > timeout) {
|
||||
finishTransmit();
|
||||
return(RADIOLIB_ERR_TX_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
// clear interrupt flags
|
||||
clearIRQFlags();
|
||||
|
||||
// set mode to standby
|
||||
standby();
|
||||
|
||||
return(state);
|
||||
return(finishTransmit());
|
||||
}
|
||||
|
||||
int16_t Si443x::receive(uint8_t* data, size_t len) {
|
||||
// calculate timeout (500 ms + 400 full 64-byte packets at current bit rate)
|
||||
uint32_t timeout = 500000 + (1.0/(_br*1000.0))*(RADIOLIB_SI443X_MAX_PACKET_LENGTH*400.0);
|
||||
RadioLibTime_t timeout = 500 + (1.0/(this->bitRate))*(RADIOLIB_SI443X_MAX_PACKET_LENGTH*400.0);
|
||||
|
||||
// start reception
|
||||
int16_t state = startReceive();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// wait for packet reception or timeout
|
||||
uint32_t start = _mod->micros();
|
||||
while(_mod->digitalRead(_mod->getIrq())) {
|
||||
if(_mod->micros() - start > timeout) {
|
||||
RadioLibTime_t start = this->mod->hal->millis();
|
||||
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
|
||||
if(this->mod->hal->millis() - start > timeout) {
|
||||
standby();
|
||||
clearIRQFlags();
|
||||
return(RADIOLIB_ERR_RX_TIMEOUT);
|
||||
@@ -126,30 +116,33 @@ int16_t Si443x::receive(uint8_t* data, size_t len) {
|
||||
|
||||
int16_t Si443x::sleep() {
|
||||
// set RF switch (if present)
|
||||
_mod->setRfSwitchState(LOW, LOW);
|
||||
this->mod->setRfSwitchState(Module::MODE_IDLE);
|
||||
|
||||
// disable wakeup timer interrupt
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, 0x00);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, 0x00);
|
||||
RADIOLIB_ASSERT(state);
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable wakeup timer to set mode to sleep
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_ENABLE_WAKEUP_TIMER);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_ENABLE_WAKEUP_TIMER);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t Si443x::standby() {
|
||||
// set RF switch (if present)
|
||||
_mod->setRfSwitchState(LOW, LOW);
|
||||
return(standby(RADIOLIB_SI443X_XTAL_ON));
|
||||
}
|
||||
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_XTAL_ON, 7, 0, 10));
|
||||
int16_t Si443x::standby(uint8_t mode) {
|
||||
// set RF switch (if present)
|
||||
this->mod->setRfSwitchState(Module::MODE_IDLE);
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, mode, 7, 0, 10));
|
||||
}
|
||||
|
||||
int16_t Si443x::transmitDirect(uint32_t frf) {
|
||||
// set RF switch (if present)
|
||||
_mod->setRfSwitchState(LOW, HIGH);
|
||||
this->mod->setRfSwitchState(Module::MODE_TX);
|
||||
|
||||
// user requested to start transmitting immediately (required for RTTY)
|
||||
if(frf != 0) {
|
||||
@@ -169,13 +162,13 @@ int16_t Si443x::transmitDirect(uint32_t frf) {
|
||||
uint16_t freqCarrier = ((newFreq / (10 * ((bandSelect >> 5) + 1))) - freqBand - 24) * (uint32_t)64000;
|
||||
|
||||
// update registers
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_FREQUENCY_BAND_SELECT, RADIOLIB_SI443X_SIDE_BAND_SELECT_LOW | bandSelect | freqBand);
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8));
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF));
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_FREQUENCY_BAND_SELECT, RADIOLIB_SI443X_SIDE_BAND_SELECT_LOW | bandSelect | freqBand);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8));
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF));
|
||||
|
||||
// start direct transmission
|
||||
directMode();
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
@@ -185,39 +178,55 @@ int16_t Si443x::transmitDirect(uint32_t frf) {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// start transmitting
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t Si443x::receiveDirect() {
|
||||
// set RF switch (if present)
|
||||
_mod->setRfSwitchState(HIGH, LOW);
|
||||
this->mod->setRfSwitchState(Module::MODE_RX);
|
||||
|
||||
// activate direct mode
|
||||
int16_t state = directMode();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// start receiving
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t Si443x::packetMode() {
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_FSK, 1, 0);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_FSK, 1, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_TX_DATA_SOURCE_FIFO, 5, 4));
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_TX_DATA_SOURCE_FIFO, 5, 4));
|
||||
}
|
||||
|
||||
void Si443x::setIrqAction(void (*func)(void)) {
|
||||
_mod->attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, FALLING);
|
||||
this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, this->mod->hal->GpioInterruptFalling);
|
||||
}
|
||||
|
||||
void Si443x::clearIrqAction() {
|
||||
_mod->detachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()));
|
||||
this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()));
|
||||
}
|
||||
|
||||
int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
void Si443x::setPacketReceivedAction(void (*func)(void)) {
|
||||
this->setIrqAction(func);
|
||||
}
|
||||
|
||||
void Si443x::clearPacketReceivedAction() {
|
||||
this->clearIrqAction();
|
||||
}
|
||||
|
||||
void Si443x::setPacketSentAction(void (*func)(void)) {
|
||||
this->setIrqAction(func);
|
||||
}
|
||||
|
||||
void Si443x::clearPacketSentAction() {
|
||||
this->clearIrqAction();
|
||||
}
|
||||
|
||||
int16_t Si443x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) {
|
||||
// check packet length
|
||||
if(len > RADIOLIB_SI443X_MAX_PACKET_LENGTH) {
|
||||
return(RADIOLIB_ERR_PACKET_TOO_LONG);
|
||||
@@ -228,61 +237,77 @@ int16_t Si443x::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// clear Tx FIFO
|
||||
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_TX_FIFO_RESET, 0, 0);
|
||||
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_TX_FIFO_CLEAR, 0, 0);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_TX_FIFO_RESET, 0, 0);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_TX_FIFO_CLEAR, 0, 0);
|
||||
|
||||
// clear interrupt flags
|
||||
clearIRQFlags();
|
||||
|
||||
// set packet length
|
||||
if (_packetLengthConfig == RADIOLIB_SI443X_FIXED_PACKET_LENGTH_OFF) {
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
|
||||
if (this->packetLengthConfig == RADIOLIB_SI443X_FIXED_PACKET_LENGTH_OFF) {
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
|
||||
}
|
||||
|
||||
/// \todo use header as address field?
|
||||
(void)addr;
|
||||
|
||||
// write packet to FIFO
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, data, len);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, const_cast<uint8_t*>(data), len);
|
||||
|
||||
// set RF switch (if present)
|
||||
_mod->setRfSwitchState(LOW, HIGH);
|
||||
this->mod->setRfSwitchState(Module::MODE_TX);
|
||||
|
||||
// set interrupt mapping
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, RADIOLIB_SI443X_PACKET_SENT_ENABLED);
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, RADIOLIB_SI443X_PACKET_SENT_ENABLED);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
|
||||
|
||||
// set mode to transmit
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_TX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t Si443x::finishTransmit() {
|
||||
// clear interrupt flags
|
||||
clearIRQFlags();
|
||||
|
||||
// set mode to standby to disable transmitter/RF switch
|
||||
return(standby());
|
||||
}
|
||||
|
||||
int16_t Si443x::startReceive() {
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// clear Rx FIFO
|
||||
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_RX_FIFO_RESET, 1, 1);
|
||||
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_RX_FIFO_CLEAR, 1, 1);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_RX_FIFO_RESET, 1, 1);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_2, RADIOLIB_SI443X_RX_FIFO_CLEAR, 1, 1);
|
||||
|
||||
// clear interrupt flags
|
||||
clearIRQFlags();
|
||||
|
||||
// set RF switch (if present)
|
||||
_mod->setRfSwitchState(HIGH, LOW);
|
||||
this->mod->setRfSwitchState(Module::MODE_RX);
|
||||
|
||||
// set interrupt mapping
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, RADIOLIB_SI443X_VALID_PACKET_RECEIVED_ENABLED | RADIOLIB_SI443X_CRC_ERROR_ENABLED);
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_1, RADIOLIB_SI443X_VALID_PACKET_RECEIVED_ENABLED | RADIOLIB_SI443X_CRC_ERROR_ENABLED);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
|
||||
|
||||
// set mode to receive
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t Si443x::startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) {
|
||||
(void)timeout;
|
||||
(void)irqFlags;
|
||||
(void)irqMask;
|
||||
(void)len;
|
||||
return(startReceive());
|
||||
}
|
||||
|
||||
int16_t Si443x::readData(uint8_t* data, size_t len) {
|
||||
// clear interrupt flags
|
||||
clearIRQFlags();
|
||||
@@ -297,7 +322,7 @@ int16_t Si443x::readData(uint8_t* data, size_t len) {
|
||||
}
|
||||
|
||||
// read packet data
|
||||
_mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, length, data);
|
||||
this->mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_FIFO_ACCESS, length, data);
|
||||
|
||||
// dump the bytes that weren't requested
|
||||
if(dumpLen != 0) {
|
||||
@@ -305,7 +330,7 @@ int16_t Si443x::readData(uint8_t* data, size_t len) {
|
||||
}
|
||||
|
||||
// clear internal flag so getPacketLength can return the new packet length
|
||||
_packetLengthQueried = false;
|
||||
this->packetLengthQueried = false;
|
||||
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
@@ -333,12 +358,12 @@ int16_t Si443x::setBitRate(float br) {
|
||||
uint16_t txDr = (br * ((uint32_t)1 << exp)) / 1000.0;
|
||||
|
||||
// update registers
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, dataRateMode, 5, 5);
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TX_DATA_RATE_1, (uint8_t)((txDr & 0xFF00) >> 8));
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TX_DATA_RATE_0, (uint8_t)(txDr & 0xFF));
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, dataRateMode, 5, 5);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TX_DATA_RATE_1, (uint8_t)((txDr & 0xFF00) >> 8));
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_TX_DATA_RATE_0, (uint8_t)(txDr & 0xFF));
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
_br = br;
|
||||
this->bitRate = br;
|
||||
}
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
@@ -361,11 +386,11 @@ int16_t Si443x::setFrequencyDeviation(float freqDev) {
|
||||
uint16_t fdev = (uint16_t)(newFreqDev / 0.625);
|
||||
|
||||
// update registers
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, (uint8_t)((fdev & 0x0100) >> 6), 2, 2);
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_FREQUENCY_DEVIATION, (uint8_t)(fdev & 0xFF));
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, (uint8_t)((fdev & 0x0100) >> 6), 2, 2);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_FREQUENCY_DEVIATION, (uint8_t)(fdev & 0xFF));
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
_freqDev = newFreqDev;
|
||||
this->frequencyDev = newFreqDev;
|
||||
}
|
||||
|
||||
return(state);
|
||||
@@ -401,63 +426,63 @@ int16_t Si443x::setRxBandwidth(float rxBw) {
|
||||
|
||||
// this is the "Lord help thee who tread 'ere" section - no way to approximate this mess
|
||||
/// \todo float tolerance equality as macro?
|
||||
} else if(fabs(rxBw - 142.8) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 142.8) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 1;
|
||||
filterSet = 4;
|
||||
} else if(fabs(rxBw - 167.8) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 167.8) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 1;
|
||||
filterSet = 5;
|
||||
} else if(fabs(rxBw - 181.1) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 181.1) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 1;
|
||||
filterSet = 6;
|
||||
} else if(fabs(rxBw - 191.5) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 191.5) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 15;
|
||||
} else if(fabs(rxBw - 225.1) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 225.1) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 1;
|
||||
} else if(fabs(rxBw - 248.8) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 248.8) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 2;
|
||||
} else if(fabs(rxBw - 269.3) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 269.3) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 3;
|
||||
} else if(fabs(rxBw - 284.8) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 284.8) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 4;
|
||||
} else if(fabs(rxBw -335.5) <= 0.001) {
|
||||
} else if(fabsf(rxBw -335.5) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 8;
|
||||
} else if(fabs(rxBw - 391.8) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 391.8) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 9;
|
||||
} else if(fabs(rxBw - 420.2) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 420.2) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 10;
|
||||
} else if(fabs(rxBw - 468.4) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 468.4) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 11;
|
||||
} else if(fabs(rxBw - 518.8) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 518.8) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 12;
|
||||
} else if(fabs(rxBw - 577.0) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 577.0) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 13;
|
||||
} else if(fabs(rxBw - 620.7) <= 0.001) {
|
||||
} else if(fabsf(rxBw - 620.7) <= 0.001) {
|
||||
bypass = RADIOLIB_SI443X_BYPASS_DEC_BY_3_ON;
|
||||
decRate = 0;
|
||||
filterSet = 14;
|
||||
@@ -469,7 +494,7 @@ int16_t Si443x::setRxBandwidth(float rxBw) {
|
||||
decRate <<= 4;
|
||||
|
||||
// update register
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, bypass | decRate | filterSet);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, bypass | decRate | filterSet);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// update clock recovery
|
||||
@@ -486,11 +511,11 @@ int16_t Si443x::setSyncWord(uint8_t* syncWord, size_t len) {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set sync word length
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, (uint8_t)(len - 1) << 1, 2, 1);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, (uint8_t)(len - 1) << 1, 2, 1);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set sync word bytes
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_SI443X_REG_SYNC_WORD_3, syncWord, len);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_SI443X_REG_SYNC_WORD_3, syncWord, len);
|
||||
|
||||
return(state);
|
||||
}
|
||||
@@ -503,25 +528,25 @@ int16_t Si443x::setPreambleLength(uint8_t preambleLen) {
|
||||
|
||||
// set default preamble length
|
||||
uint8_t preLenNibbles = preambleLen / 4;
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_PREAMBLE_LENGTH, preLenNibbles);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_PREAMBLE_LENGTH, preLenNibbles);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set default preamble detection threshold to 5/8 of preamble length (in units of 4 bits)
|
||||
uint8_t preThreshold = 5*preLenNibbles / 8;
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_PREAMBLE_DET_CONTROL, preThreshold << 3, 7, 3));
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_PREAMBLE_DET_CONTROL, preThreshold << 3, 7, 3));
|
||||
}
|
||||
|
||||
size_t Si443x::getPacketLength(bool update) {
|
||||
if(!_packetLengthQueried && update) {
|
||||
if (_packetLengthConfig == RADIOLIB_SI443X_FIXED_PACKET_LENGTH_ON) {
|
||||
_packetLength = _mod->SPIreadRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH);
|
||||
if(!this->packetLengthQueried && update) {
|
||||
if (this->packetLengthConfig == RADIOLIB_SI443X_FIXED_PACKET_LENGTH_ON) {
|
||||
this->packetLength = this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH);
|
||||
} else {
|
||||
_packetLength = _mod->SPIreadRegister(RADIOLIB_SI443X_REG_RECEIVED_PACKET_LENGTH);
|
||||
this->packetLength = this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_RECEIVED_PACKET_LENGTH);
|
||||
}
|
||||
_packetLengthQueried = true;
|
||||
this->packetLengthQueried = true;
|
||||
}
|
||||
|
||||
return(_packetLength);
|
||||
return(this->packetLength);
|
||||
}
|
||||
|
||||
int16_t Si443x::setEncoding(uint8_t encoding) {
|
||||
@@ -533,11 +558,11 @@ int16_t Si443x::setEncoding(uint8_t encoding) {
|
||||
/// \todo - add inverted Manchester?
|
||||
switch(encoding) {
|
||||
case RADIOLIB_ENCODING_NRZ:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
|
||||
case RADIOLIB_ENCODING_MANCHESTER:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_ON | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_ON | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
|
||||
case RADIOLIB_ENCODING_WHITENING:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_ON, 2, 0));
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_ON, 2, 0));
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_ENCODING);
|
||||
}
|
||||
@@ -551,32 +576,33 @@ int16_t Si443x::setDataShaping(uint8_t sh) {
|
||||
// set data shaping
|
||||
switch(sh) {
|
||||
case RADIOLIB_SHAPING_NONE:
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
|
||||
case RADIOLIB_SHAPING_0_3:
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_OFF, 2, 0));
|
||||
case RADIOLIB_SHAPING_0_5:
|
||||
case RADIOLIB_SHAPING_1_0:
|
||||
/// \todo implement fiter configuration - docs claim this should be possible, but seems undocumented
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, RADIOLIB_SI443X_MANCHESTER_INVERTED_OFF | RADIOLIB_SI443X_MANCHESTER_OFF | RADIOLIB_SI443X_WHITENING_ON, 2, 0));
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_GFSK, 1, 0));
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_ENCODING);
|
||||
}
|
||||
}
|
||||
|
||||
void Si443x::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) {
|
||||
_mod->setRfSwitchPins(rxEn, txEn);
|
||||
void Si443x::setRfSwitchPins(uint32_t rxEn, uint32_t txEn) {
|
||||
this->mod->setRfSwitchPins(rxEn, txEn);
|
||||
}
|
||||
|
||||
void Si443x::setRfSwitchTable(const uint32_t (&pins)[Module::RFSWITCH_MAX_PINS], const Module::RfSwitchMode_t table[]) {
|
||||
this->mod->setRfSwitchTable(pins, table);
|
||||
}
|
||||
|
||||
uint8_t Si443x::randomByte() {
|
||||
// set mode to Rx
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_OP_FUNC_CONTROL_1, RADIOLIB_SI443X_RX_ON | RADIOLIB_SI443X_XTAL_ON);
|
||||
|
||||
// wait a bit for the RSSI reading to stabilise
|
||||
_mod->delay(10);
|
||||
this->mod->hal->delay(10);
|
||||
|
||||
// read RSSI value 8 times, always keep just the least significant bit
|
||||
uint8_t randByte = 0x00;
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
randByte |= ((_mod->SPIreadRegister(RADIOLIB_SI443X_REG_RSSI) & 0x01) << i);
|
||||
randByte |= ((this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_RSSI) & 0x01) << i);
|
||||
}
|
||||
|
||||
// set mode to standby
|
||||
@@ -586,16 +612,16 @@ uint8_t Si443x::randomByte() {
|
||||
}
|
||||
|
||||
int16_t Si443x::getChipVersion() {
|
||||
return(_mod->SPIgetRegValue(RADIOLIB_SI443X_REG_DEVICE_VERSION));
|
||||
return(this->mod->SPIgetRegValue(RADIOLIB_SI443X_REG_DEVICE_VERSION));
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
#if !RADIOLIB_EXCLUDE_DIRECT_RECEIVE
|
||||
void Si443x::setDirectAction(void (*func)(void)) {
|
||||
setIrqAction(func);
|
||||
}
|
||||
|
||||
void Si443x::readBit(RADIOLIB_PIN_TYPE pin) {
|
||||
updateDirectBuffer((uint8_t)digitalRead(pin));
|
||||
void Si443x::readBit(uint32_t pin) {
|
||||
updateDirectBuffer((uint8_t)this->mod->hal->digitalRead(pin));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -607,6 +633,10 @@ int16_t Si443x::variablePacketLengthMode(uint8_t maxLen) {
|
||||
return(Si443x::setPacketMode(RADIOLIB_SI443X_FIXED_PACKET_LENGTH_OFF, maxLen));
|
||||
}
|
||||
|
||||
Module* Si443x::getMod() {
|
||||
return(this->mod);
|
||||
}
|
||||
|
||||
int16_t Si443x::setFrequencyRaw(float newFreq) {
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
@@ -616,7 +646,7 @@ int16_t Si443x::setFrequencyRaw(float newFreq) {
|
||||
uint8_t bandSelect = RADIOLIB_SI443X_BAND_SELECT_LOW;
|
||||
uint8_t freqBand = (newFreq / 10) - 24;
|
||||
uint8_t afcLimiter = 80;
|
||||
_freq = newFreq;
|
||||
this->frequency = newFreq;
|
||||
if(newFreq >= 480.0) {
|
||||
bandSelect = RADIOLIB_SI443X_BAND_SELECT_HIGH;
|
||||
freqBand = (newFreq / 20) - 24;
|
||||
@@ -627,10 +657,10 @@ int16_t Si443x::setFrequencyRaw(float newFreq) {
|
||||
uint16_t freqCarrier = ((newFreq / (10 * ((bandSelect >> 5) + 1))) - freqBand - 24) * (uint32_t)64000;
|
||||
|
||||
// update registers
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_FREQUENCY_BAND_SELECT, bandSelect | freqBand, 5, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8));
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF));
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_AFC_LIMITER, afcLimiter);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_FREQUENCY_BAND_SELECT, bandSelect | freqBand, 5, 0);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_1, (uint8_t)((freqCarrier & 0xFF00) >> 8));
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_NOM_CARRIER_FREQUENCY_0, (uint8_t)(freqCarrier & 0xFF));
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_AFC_LIMITER, afcLimiter);
|
||||
|
||||
return(state);
|
||||
}
|
||||
@@ -642,15 +672,15 @@ int16_t Si443x::setPacketMode(uint8_t mode, uint8_t len) {
|
||||
}
|
||||
|
||||
// set to fixed packet length
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, mode, 3, 3);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, mode, 3, 3);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set length to register
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_TRANSMIT_PACKET_LENGTH, len);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// update cached value
|
||||
_packetLengthConfig = mode;
|
||||
this->packetLengthConfig = mode;
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -662,22 +692,12 @@ bool Si443x::findChip() {
|
||||
reset();
|
||||
|
||||
// check version register
|
||||
uint8_t version = _mod->SPIreadRegister(RADIOLIB_SI443X_REG_DEVICE_VERSION);
|
||||
uint8_t version = this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_DEVICE_VERSION);
|
||||
if(version == RADIOLIB_SI443X_DEVICE_VERSION) {
|
||||
flagFound = true;
|
||||
} else {
|
||||
#if defined(RADIOLIB_DEBUG)
|
||||
RADIOLIB_DEBUG_PRINT(F("Si443x not found! ("));
|
||||
RADIOLIB_DEBUG_PRINT(i + 1);
|
||||
RADIOLIB_DEBUG_PRINT(F(" of 10 tries) RADIOLIB_SI443X_REG_DEVICE_VERSION == "));
|
||||
|
||||
char buffHex[5];
|
||||
sprintf(buffHex, "0x%02X", version);
|
||||
RADIOLIB_DEBUG_PRINT(buffHex);
|
||||
RADIOLIB_DEBUG_PRINT(F(", expected 0x00"));
|
||||
RADIOLIB_DEBUG_PRINTLN(RADIOLIB_SI443X_DEVICE_VERSION, HEX);
|
||||
#endif
|
||||
_mod->delay(10);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("Si443x not found! (%d of 10 tries) RADIOLIB_SI443X_REG_DEVICE_VERSION == 0x%02X, expected 0x0%X", i + 1, version, RADIOLIB_SI443X_DEVICE_VERSION);
|
||||
this->mod->hal->delay(10);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@@ -687,12 +707,12 @@ bool Si443x::findChip() {
|
||||
|
||||
void Si443x::clearIRQFlags() {
|
||||
uint8_t buff[2];
|
||||
_mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_INTERRUPT_STATUS_1, 2, buff);
|
||||
this->mod->SPIreadRegisterBurst(RADIOLIB_SI443X_REG_INTERRUPT_STATUS_1, 2, buff);
|
||||
}
|
||||
|
||||
void Si443x::clearFIFO(size_t count) {
|
||||
while(count) {
|
||||
_mod->SPIreadRegister(RADIOLIB_SI443X_REG_FIFO_ACCESS);
|
||||
this->mod->SPIreadRegister(RADIOLIB_SI443X_REG_FIFO_ACCESS);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
@@ -703,22 +723,22 @@ int16_t Si443x::config() {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// disable POR and chip ready interrupts
|
||||
_mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_SI443X_REG_INTERRUPT_ENABLE_2, 0x00);
|
||||
|
||||
// enable AGC
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_AGC_OVERRIDE_1, RADIOLIB_SI443X_AGC_GAIN_INCREASE_ON | RADIOLIB_SI443X_AGC_ON, 6, 5);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_AGC_OVERRIDE_1, RADIOLIB_SI443X_AGC_GAIN_INCREASE_ON | RADIOLIB_SI443X_AGC_ON, 6, 5);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// disable packet header
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, RADIOLIB_SI443X_SYNC_WORD_TIMEOUT_OFF | RADIOLIB_SI443X_HEADER_LENGTH_HEADER_NONE, 7, 4);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_2, RADIOLIB_SI443X_SYNC_WORD_TIMEOUT_OFF | RADIOLIB_SI443X_HEADER_LENGTH_HEADER_NONE, 7, 4);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set antenna switching
|
||||
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO0_CONFIG, RADIOLIB_SI443X_GPIOX_TX_STATE_OUT, 4, 0);
|
||||
_mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO1_CONFIG, RADIOLIB_SI443X_GPIOX_RX_STATE_OUT, 4, 0);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO0_CONFIG, RADIOLIB_SI443X_GPIOX_TX_STATE_OUT, 4, 0);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO1_CONFIG, RADIOLIB_SI443X_GPIOX_RX_STATE_OUT, 4, 0);
|
||||
|
||||
// disable packet header checking
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_1, RADIOLIB_SI443X_BROADCAST_ADDR_CHECK_NONE | RADIOLIB_SI443X_RECEIVED_HEADER_CHECK_NONE);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_HEADER_CONTROL_1, RADIOLIB_SI443X_BROADCAST_ADDR_CHECK_NONE | RADIOLIB_SI443X_RECEIVED_HEADER_CHECK_NONE);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
@@ -726,9 +746,9 @@ int16_t Si443x::config() {
|
||||
|
||||
int16_t Si443x::updateClockRecovery() {
|
||||
// get the parameters
|
||||
uint8_t bypass = _mod->SPIgetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, 7, 7) >> 7;
|
||||
uint8_t decRate = _mod->SPIgetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, 6, 4) >> 4;
|
||||
uint8_t manch = _mod->SPIgetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, 1, 1) >> 1;
|
||||
uint8_t bypass = this->mod->SPIgetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, 7, 7) >> 7;
|
||||
uint8_t decRate = this->mod->SPIgetRegValue(RADIOLIB_SI443X_REG_IF_FILTER_BANDWIDTH, 6, 4) >> 4;
|
||||
uint8_t manch = this->mod->SPIgetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_1, 1, 1) >> 1;
|
||||
|
||||
// calculate oversampling ratio, NCO offset and clock recovery gain
|
||||
int8_t ndecExp = (int8_t)decRate - 3;
|
||||
@@ -739,61 +759,50 @@ int16_t Si443x::updateClockRecovery() {
|
||||
ndecExp *= -1;
|
||||
ndec = 1.0/(float)((uint16_t)1 << ndecExp);
|
||||
}
|
||||
float rxOsr = ((float)(500 * (1 + 2*bypass))) / (ndec * _br * ((float)(1 + manch)));
|
||||
uint32_t ncoOff = (_br * (1 + manch) * ((uint32_t)(1) << (20 + decRate))) / (500 * (1 + 2*bypass));
|
||||
uint16_t crGain = 2 + (((float)(65536.0 * (1 + manch)) * _br) / (rxOsr * (_freqDev / 0.625)));
|
||||
float rxOsr = ((float)(500 * (1 + 2*bypass))) / (ndec * this->bitRate * ((float)(1 + manch)));
|
||||
uint32_t ncoOff = (this->bitRate * (1 + manch) * ((uint32_t)(1) << (20 + decRate))) / (500 * (1 + 2*bypass));
|
||||
uint16_t crGain = 2 + (((float)(65536.0 * (1 + manch)) * this->bitRate) / (rxOsr * (this->frequencyDev / 0.625)));
|
||||
uint16_t rxOsr_fixed = (uint16_t)rxOsr;
|
||||
|
||||
// print that whole mess
|
||||
RADIOLIB_DEBUG_PRINTLN(bypass, HEX);
|
||||
RADIOLIB_DEBUG_PRINTLN(decRate, HEX);
|
||||
RADIOLIB_DEBUG_PRINTLN(manch, HEX);
|
||||
RADIOLIB_DEBUG_PRINT(rxOsr, 3);
|
||||
RADIOLIB_DEBUG_PRINT('\t');
|
||||
RADIOLIB_DEBUG_PRINT(rxOsr_fixed);
|
||||
RADIOLIB_DEBUG_PRINT('\t');
|
||||
RADIOLIB_DEBUG_PRINTLN(rxOsr_fixed, HEX);
|
||||
RADIOLIB_DEBUG_PRINT(ncoOff);
|
||||
RADIOLIB_DEBUG_PRINT('\t');
|
||||
RADIOLIB_DEBUG_PRINTLN(ncoOff, HEX);
|
||||
RADIOLIB_DEBUG_PRINT(crGain);
|
||||
RADIOLIB_DEBUG_PRINT('\t');
|
||||
RADIOLIB_DEBUG_PRINTLN(crGain, HEX);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("%X\n%X\n%X", bypass, decRate, manch);
|
||||
RADIOLIB_DEBUG_BASIC_PRINT_FLOAT(rxOsr, 2);
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("\t%d\t%X\n%lu\t%lX\n%d\t%X", rxOsr_fixed, rxOsr_fixed, (long unsigned int)ncoOff, (long unsigned int)ncoOff, crGain, crGain);
|
||||
|
||||
// update oversampling ratio
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((rxOsr_fixed & 0x0700) >> 3), 7, 5);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((rxOsr_fixed & 0x0700) >> 3), 7, 5);
|
||||
RADIOLIB_ASSERT(state);
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OVERSAMP_RATIO, (uint8_t)(rxOsr_fixed & 0x00FF));
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OVERSAMP_RATIO, (uint8_t)(rxOsr_fixed & 0x00FF));
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// update NCO offset
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((ncoOff & 0x0F0000) >> 16), 3, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_2, (uint8_t)((ncoOff & 0x0F0000) >> 16), 3, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_1, (uint8_t)((ncoOff & 0x00FF00) >> 8));
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_1, (uint8_t)((ncoOff & 0x00FF00) >> 8));
|
||||
RADIOLIB_ASSERT(state);
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_0, (uint8_t)(ncoOff & 0x0000FF));
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_OFFSET_0, (uint8_t)(ncoOff & 0x0000FF));
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// update clock recovery loop gain
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_1, (uint8_t)((crGain & 0x0700) >> 8), 2, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_1, (uint8_t)((crGain & 0x0700) >> 8), 2, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_0, (uint8_t)(crGain & 0x00FF));
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_CLOCK_REC_TIMING_LOOP_GAIN_0, (uint8_t)(crGain & 0x00FF));
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t Si443x::directMode() {
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_TX_DATA_SOURCE_GPIO, 5, 4);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_TX_DATA_SOURCE_GPIO, 5, 4);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO1_CONFIG, RADIOLIB_SI443X_GPIOX_TX_RX_DATA_CLK_OUT, 4, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO1_CONFIG, RADIOLIB_SI443X_GPIOX_TX_RX_DATA_CLK_OUT, 4, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO2_CONFIG, RADIOLIB_SI443X_GPIOX_TX_DATA_IN, 4, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_GPIO2_CONFIG, RADIOLIB_SI443X_GPIOX_TX_DATA_IN, 4, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_FSK, 1, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_SI443X_REG_MODULATION_MODE_CONTROL_2, RADIOLIB_SI443X_MODULATION_FSK, 1, 0);
|
||||
return(state);
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,36 +1,33 @@
|
||||
#include "nRF24.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_NRF24)
|
||||
#include <string.h>
|
||||
#if !RADIOLIB_EXCLUDE_NRF24
|
||||
|
||||
nRF24::nRF24(Module* mod) : PhysicalLayer(RADIOLIB_NRF24_FREQUENCY_STEP_SIZE, RADIOLIB_NRF24_MAX_PACKET_LENGTH) {
|
||||
_mod = mod;
|
||||
this->mod = mod;
|
||||
}
|
||||
|
||||
Module* nRF24::getMod() {
|
||||
return(_mod);
|
||||
}
|
||||
|
||||
int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrWidth) {
|
||||
int16_t nRF24::begin(int16_t freq, int16_t dr, int8_t pwr, uint8_t addrWidth) {
|
||||
// set module properties
|
||||
_mod->SPIreadCommand = RADIOLIB_NRF24_CMD_READ;
|
||||
_mod->SPIwriteCommand = RADIOLIB_NRF24_CMD_WRITE;
|
||||
_mod->init();
|
||||
_mod->pinMode(_mod->getIrq(), INPUT);
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_READ] = RADIOLIB_NRF24_CMD_READ;
|
||||
this->mod->spiConfig.cmds[RADIOLIB_MODULE_SPI_COMMAND_WRITE] = RADIOLIB_NRF24_CMD_WRITE;
|
||||
this->mod->init();
|
||||
this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput);
|
||||
|
||||
// set pin mode on RST (connected to nRF24 CE pin)
|
||||
_mod->pinMode(_mod->getRst(), OUTPUT);
|
||||
_mod->digitalWrite(_mod->getRst(), LOW);
|
||||
this->mod->hal->pinMode(this->mod->getRst(), this->mod->hal->GpioModeOutput);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
|
||||
|
||||
// wait for minimum power-on reset duration
|
||||
_mod->delay(100);
|
||||
this->mod->hal->delay(100);
|
||||
|
||||
// check SPI connection
|
||||
int16_t val = _mod->SPIgetRegValue(RADIOLIB_NRF24_REG_SETUP_AW);
|
||||
int16_t val = this->mod->SPIgetRegValue(RADIOLIB_NRF24_REG_SETUP_AW);
|
||||
if(!((val >= 0) && (val <= 3))) {
|
||||
RADIOLIB_DEBUG_PRINTLN(F("No nRF24 found!"));
|
||||
_mod->term();
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("No nRF24 found!");
|
||||
this->mod->term();
|
||||
return(RADIOLIB_ERR_CHIP_NOT_FOUND);
|
||||
}
|
||||
RADIOLIB_DEBUG_PRINTLN(F("M\tnRF24"));
|
||||
RADIOLIB_DEBUG_BASIC_PRINTLN("M\tnRF24");
|
||||
|
||||
// configure settings inaccessible by public API
|
||||
int16_t state = config();
|
||||
@@ -45,11 +42,11 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set data rate
|
||||
state = setDataRate(dataRate);
|
||||
state = setBitRate(dr);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set output power
|
||||
state = setOutputPower(power);
|
||||
state = setOutputPower(pwr);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set address width
|
||||
@@ -68,48 +65,47 @@ int16_t nRF24::begin(int16_t freq, int16_t dataRate, int8_t power, uint8_t addrW
|
||||
}
|
||||
|
||||
int16_t nRF24::sleep() {
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_DOWN, 1, 1));
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_DOWN, 1, 1));
|
||||
}
|
||||
|
||||
int16_t nRF24::standby() {
|
||||
// make sure carrier output is disabled
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_OFF, 7, 7);
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_OFF, 4, 4);
|
||||
_mod->digitalWrite(_mod->getRst(), LOW);
|
||||
|
||||
// use standby-1 mode
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_UP, 1, 1));
|
||||
return(standby(RADIOLIB_NRF24_POWER_UP));
|
||||
}
|
||||
|
||||
int16_t nRF24::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
int16_t nRF24::standby(uint8_t mode) {
|
||||
// make sure carrier output is disabled
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_OFF, 7, 7);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_OFF, 4, 4);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
|
||||
|
||||
// use standby-1 mode
|
||||
return(this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, mode, 1, 1));
|
||||
}
|
||||
|
||||
int16_t nRF24::transmit(const uint8_t* data, size_t len, uint8_t addr) {
|
||||
// start transmission
|
||||
int16_t state = startTransmit(data, len, addr);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// wait until transmission is finished
|
||||
uint32_t start = _mod->micros();
|
||||
while(_mod->digitalRead(_mod->getIrq())) {
|
||||
_mod->yield();
|
||||
uint32_t start = this->mod->hal->millis();
|
||||
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
|
||||
this->mod->hal->yield();
|
||||
|
||||
// check maximum number of retransmits
|
||||
if(getStatus(RADIOLIB_NRF24_MAX_RT)) {
|
||||
standby();
|
||||
clearIRQ();
|
||||
finishTransmit();
|
||||
return(RADIOLIB_ERR_ACK_NOT_RECEIVED);
|
||||
}
|
||||
|
||||
// check timeout: 15 retries * 4ms (max Tx time as per datasheet)
|
||||
if(_mod->micros() - start >= 60000) {
|
||||
standby();
|
||||
clearIRQ();
|
||||
// check timeout: 15 retries * 4ms (max Tx time as per datasheet) + 10 ms
|
||||
if(this->mod->hal->millis() - start >= ((15 * 4) + 10)) {
|
||||
finishTransmit();
|
||||
return(RADIOLIB_ERR_TX_TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
// clear interrupts
|
||||
clearIRQ();
|
||||
|
||||
return(state);
|
||||
return(finishTransmit());
|
||||
}
|
||||
|
||||
int16_t nRF24::receive(uint8_t* data, size_t len) {
|
||||
@@ -118,12 +114,12 @@ int16_t nRF24::receive(uint8_t* data, size_t len) {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// wait for Rx_DataReady or timeout
|
||||
uint32_t start = _mod->micros();
|
||||
while(_mod->digitalRead(_mod->getIrq())) {
|
||||
_mod->yield();
|
||||
uint32_t start = this->mod->hal->millis();
|
||||
while(this->mod->hal->digitalRead(this->mod->getIrq())) {
|
||||
this->mod->hal->yield();
|
||||
|
||||
// check timeout: 15 retries * 4ms (max Tx time as per datasheet)
|
||||
if(_mod->micros() - start >= 60000) {
|
||||
// check timeout: 15 retries * 4ms (max Tx time as per datasheet) + 10 ms
|
||||
if(this->mod->hal->millis() - start >= ((15 * 4) + 10)) {
|
||||
standby();
|
||||
clearIRQ();
|
||||
return(RADIOLIB_ERR_RX_TIMEOUT);
|
||||
@@ -138,14 +134,14 @@ int16_t nRF24::transmitDirect(uint32_t frf) {
|
||||
// set raw frequency value
|
||||
if(frf != 0) {
|
||||
uint8_t freqRaw = frf - 2400;
|
||||
_mod->SPIwriteRegister(RADIOLIB_NRF24_REG_RF_CH, freqRaw & 0b01111111);
|
||||
this->mod->SPIwriteRegister(RADIOLIB_NRF24_REG_RF_CH, freqRaw & 0b01111111);
|
||||
}
|
||||
|
||||
// output carrier
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_ON, 7, 7);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_ON, 4, 4);
|
||||
_mod->digitalWrite(_mod->getRst(), HIGH);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_CONT_WAVE_ON, 7, 7);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_PLL_LOCK_ON, 4, 4);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -156,10 +152,30 @@ int16_t nRF24::receiveDirect() {
|
||||
}
|
||||
|
||||
void nRF24::setIrqAction(void (*func)(void)) {
|
||||
_mod->attachInterrupt(RADIOLIB_DIGITAL_PIN_TO_INTERRUPT(_mod->getIrq()), func, FALLING);
|
||||
this->mod->hal->attachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()), func, this->mod->hal->GpioInterruptFalling);
|
||||
}
|
||||
|
||||
int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
void nRF24::clearIrqAction() {
|
||||
this->mod->hal->detachInterrupt(this->mod->hal->pinToInterrupt(this->mod->getIrq()));
|
||||
}
|
||||
|
||||
void nRF24::setPacketReceivedAction(void (*func)(void)) {
|
||||
this->setIrqAction(func);
|
||||
}
|
||||
|
||||
void nRF24::clearPacketReceivedAction() {
|
||||
this->clearIrqAction();
|
||||
}
|
||||
|
||||
void nRF24::setPacketSentAction(void (*func)(void)) {
|
||||
this->setIrqAction(func);
|
||||
}
|
||||
|
||||
void nRF24::clearPacketSentAction() {
|
||||
this->clearIrqAction();
|
||||
}
|
||||
|
||||
int16_t nRF24::startTransmit(const uint8_t* data, size_t len, uint8_t addr) {
|
||||
// suppress unused variable warning
|
||||
(void)addr;
|
||||
|
||||
@@ -173,13 +189,13 @@ int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable primary Tx mode
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PTX, 0, 0);
|
||||
|
||||
// clear interrupts
|
||||
clearIRQ();
|
||||
|
||||
// enable Tx_DataSent interrupt
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON, 5, 5);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON, 5, 5);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// flush Tx FIFO
|
||||
@@ -189,42 +205,58 @@ int16_t nRF24::startTransmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
uint8_t buff[32];
|
||||
memset(buff, 0x00, 32);
|
||||
memcpy(buff, data, len);
|
||||
SPIwriteTxPayload(data, len);
|
||||
SPIwriteTxPayload(const_cast<uint8_t*>(data), len);
|
||||
|
||||
// CE high to start transmitting
|
||||
_mod->digitalWrite(_mod->getRst(), HIGH);
|
||||
_mod->delay(1);
|
||||
_mod->digitalWrite(_mod->getRst(), LOW);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
|
||||
this->mod->hal->delay(1);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelLow);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t nRF24::finishTransmit() {
|
||||
// clear interrupt flags
|
||||
clearIRQ();
|
||||
|
||||
// set mode to standby to disable transmitter/RF switch
|
||||
return(standby());
|
||||
}
|
||||
|
||||
int16_t nRF24::startReceive() {
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable primary Rx mode
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PRX, 0, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_PRX, 0, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable Rx_DataReady interrupt
|
||||
clearIRQ();
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON, 6, 6);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON, 6, 6);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// flush Rx FIFO
|
||||
SPItransfer(RADIOLIB_NRF24_CMD_FLUSH_RX);
|
||||
|
||||
// CE high to start receiving
|
||||
_mod->digitalWrite(_mod->getRst(), HIGH);
|
||||
this->mod->hal->digitalWrite(this->mod->getRst(), this->mod->hal->GpioLevelHigh);
|
||||
|
||||
// wait to enter Rx state
|
||||
_mod->delay(1);
|
||||
this->mod->hal->delay(1);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t nRF24::startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) {
|
||||
(void)timeout;
|
||||
(void)irqFlags;
|
||||
(void)irqMask;
|
||||
(void)len;
|
||||
return(startReceive());
|
||||
}
|
||||
|
||||
int16_t nRF24::readData(uint8_t* data, size_t len) {
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
@@ -246,44 +278,56 @@ int16_t nRF24::readData(uint8_t* data, size_t len) {
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t nRF24::setFrequency(int16_t freq) {
|
||||
RADIOLIB_CHECK_RANGE(freq, 2400, 2525, RADIOLIB_ERR_INVALID_FREQUENCY);
|
||||
int16_t nRF24::setFrequency(float freq) {
|
||||
RADIOLIB_CHECK_RANGE((uint16_t)freq, 2400, 2525, RADIOLIB_ERR_INVALID_FREQUENCY);
|
||||
|
||||
// set frequency
|
||||
uint8_t freqRaw = freq - 2400;
|
||||
return(_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0));
|
||||
}
|
||||
uint8_t freqRaw = (uint16_t)freq - 2400;
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_CH, freqRaw, 6, 0);
|
||||
|
||||
int16_t nRF24::setDataRate(int16_t dataRate) {
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set data rate
|
||||
if(dataRate == 250) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 5, 5);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 3, 3);
|
||||
} else if(dataRate == 1000) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 5, 5);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 3, 3);
|
||||
} else if(dataRate == 2000) {
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 5, 5);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 3, 3);
|
||||
} else {
|
||||
return(RADIOLIB_ERR_INVALID_DATA_RATE);
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
this->frequency = freq;
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t nRF24::setOutputPower(int8_t power) {
|
||||
int16_t nRF24::setBitRate(float br) {
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set data rate
|
||||
uint16_t bitRate = (uint16_t)br;
|
||||
if(bitRate == 250) {
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 5, 5);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_250_KBPS, 3, 3);
|
||||
} else if(bitRate == 1000) {
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 5, 5);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_1_MBPS, 3, 3);
|
||||
} else if(bitRate == 2000) {
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 5, 5);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, RADIOLIB_NRF24_DR_2_MBPS, 3, 3);
|
||||
} else {
|
||||
return(RADIOLIB_ERR_INVALID_DATA_RATE);
|
||||
}
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
this->dataRate = bitRate;
|
||||
}
|
||||
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t nRF24::setOutputPower(int8_t pwr) {
|
||||
// set mode to standby
|
||||
int16_t state = standby();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// check allowed values
|
||||
uint8_t powerRaw = 0;
|
||||
switch(power) {
|
||||
switch(pwr) {
|
||||
case -18:
|
||||
powerRaw = RADIOLIB_NRF24_RF_PWR_18_DBM;
|
||||
break;
|
||||
@@ -301,7 +345,12 @@ int16_t nRF24::setOutputPower(int8_t power) {
|
||||
}
|
||||
|
||||
// write new register value
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, powerRaw, 2, 1);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RF_SETUP, powerRaw, 2, 1);
|
||||
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
this->power = pwr;
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
@@ -315,23 +364,25 @@ int16_t nRF24::setAddressWidth(uint8_t addrWidth) {
|
||||
case 2:
|
||||
// Even if marked as 'Illegal' on the datasheet this will work:
|
||||
// http://travisgoodspeed.blogspot.com/2011/02/promiscuity-is-nrf24l01s-duty.html
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_2_BYTES, 1, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_2_BYTES, 1, 0);
|
||||
break;
|
||||
case 3:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_3_BYTES, 1, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_3_BYTES, 1, 0);
|
||||
break;
|
||||
case 4:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_4_BYTES, 1, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_4_BYTES, 1, 0);
|
||||
break;
|
||||
case 5:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_5_BYTES, 1, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_AW, RADIOLIB_NRF24_ADDRESS_5_BYTES, 1, 0);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_ADDRESS_WIDTH);
|
||||
}
|
||||
|
||||
// save address width
|
||||
_addrWidth = addrWidth;
|
||||
if(state == RADIOLIB_ERR_NONE) {
|
||||
this->addressWidth = addrWidth;
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
@@ -342,11 +393,11 @@ int16_t nRF24::setTransmitPipe(uint8_t* addr) {
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set transmit address
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_TX_ADDR, addr, _addrWidth);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_TX_ADDR, addr, this->addressWidth);
|
||||
|
||||
// set Rx pipe 0 address (for ACK)
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, _addrWidth);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, this->addressWidth);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
|
||||
|
||||
return(state);
|
||||
}
|
||||
@@ -359,12 +410,12 @@ int16_t nRF24::setReceivePipe(uint8_t pipeNum, uint8_t* addr) {
|
||||
// write full pipe 0 - 1 address and enable the pipe
|
||||
switch(pipeNum) {
|
||||
case 0:
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, _addrWidth);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P0, addr, this->addressWidth);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_ON, 0, 0);
|
||||
break;
|
||||
case 1:
|
||||
_mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P1, addr, _addrWidth);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_ON, 1, 1);
|
||||
this->mod->SPIwriteRegisterBurst(RADIOLIB_NRF24_REG_RX_ADDR_P1, addr, this->addressWidth);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_ON, 1, 1);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_PIPE_NUMBER);
|
||||
@@ -381,20 +432,20 @@ int16_t nRF24::setReceivePipe(uint8_t pipeNum, uint8_t addrByte) {
|
||||
// write unique pipe 2 - 5 address and enable the pipe
|
||||
switch(pipeNum) {
|
||||
case 2:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P2, addrByte);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_ON, 2, 2);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P2, addrByte);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_ON, 2, 2);
|
||||
break;
|
||||
case 3:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P3, addrByte);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_ON, 3, 3);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P3, addrByte);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_ON, 3, 3);
|
||||
break;
|
||||
case 4:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P4, addrByte);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_ON, 4, 4);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P4, addrByte);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_ON, 4, 4);
|
||||
break;
|
||||
case 5:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P5, addrByte);
|
||||
state |= _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_ON, 5, 5);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_RX_ADDR_P5, addrByte);
|
||||
state |= this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_ON, 5, 5);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_PIPE_NUMBER);
|
||||
@@ -410,22 +461,22 @@ int16_t nRF24::disablePipe(uint8_t pipeNum) {
|
||||
|
||||
switch(pipeNum) {
|
||||
case 0:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_OFF, 0, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P0_OFF, 0, 0);
|
||||
break;
|
||||
case 1:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_OFF, 1, 1);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P1_OFF, 1, 1);
|
||||
break;
|
||||
case 2:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_OFF, 2, 2);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P2_OFF, 2, 2);
|
||||
break;
|
||||
case 3:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_OFF, 3, 3);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P3_OFF, 3, 3);
|
||||
break;
|
||||
case 4:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_OFF, 4, 4);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P4_OFF, 4, 4);
|
||||
break;
|
||||
case 5:
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_OFF, 5, 5);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_RXADDR, RADIOLIB_NRF24_P5_OFF, 5, 5);
|
||||
break;
|
||||
default:
|
||||
return(RADIOLIB_ERR_INVALID_PIPE_NUMBER);
|
||||
@@ -435,11 +486,11 @@ int16_t nRF24::disablePipe(uint8_t pipeNum) {
|
||||
}
|
||||
|
||||
int16_t nRF24::getStatus(uint8_t mask) {
|
||||
return(_mod->SPIgetRegValue(RADIOLIB_NRF24_REG_STATUS) & mask);
|
||||
return(this->mod->SPIgetRegValue(RADIOLIB_NRF24_REG_STATUS) & mask);
|
||||
}
|
||||
|
||||
bool nRF24::isCarrierDetected() {
|
||||
return(_mod->SPIgetRegValue(RADIOLIB_NRF24_REG_RPD, 0, 0) == 1);
|
||||
return(this->mod->SPIgetRegValue(RADIOLIB_NRF24_REG_RPD, 0, 0) == 1);
|
||||
}
|
||||
|
||||
int16_t nRF24::setFrequencyDeviation(float freqDev) {
|
||||
@@ -464,32 +515,32 @@ int16_t nRF24::setCrcFiltering(bool crcOn) {
|
||||
}
|
||||
|
||||
// Disable CRC
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, (crcOn ? RADIOLIB_NRF24_CRC_ON : RADIOLIB_NRF24_CRC_OFF), 3, 3);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, (crcOn ? RADIOLIB_NRF24_CRC_ON : RADIOLIB_NRF24_CRC_OFF), 3, 3);
|
||||
}
|
||||
|
||||
int16_t nRF24::setAutoAck(bool autoAckOn){
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_ALL_ON : RADIOLIB_NRF24_AA_ALL_OFF), 5, 0);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_ALL_ON : RADIOLIB_NRF24_AA_ALL_OFF), 5, 0);
|
||||
}
|
||||
|
||||
int16_t nRF24::setAutoAck(uint8_t pipeNum, bool autoAckOn){
|
||||
switch(pipeNum) {
|
||||
case 0:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P0_ON : RADIOLIB_NRF24_AA_P0_OFF), 0, 0);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P0_ON : RADIOLIB_NRF24_AA_P0_OFF), 0, 0);
|
||||
break;
|
||||
case 1:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P1_ON : RADIOLIB_NRF24_AA_P1_OFF), 1, 1);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P1_ON : RADIOLIB_NRF24_AA_P1_OFF), 1, 1);
|
||||
break;
|
||||
case 2:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P2_ON : RADIOLIB_NRF24_AA_P2_OFF), 2, 2);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P2_ON : RADIOLIB_NRF24_AA_P2_OFF), 2, 2);
|
||||
break;
|
||||
case 3:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P3_ON : RADIOLIB_NRF24_AA_P3_OFF), 3, 3);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P3_ON : RADIOLIB_NRF24_AA_P3_OFF), 3, 3);
|
||||
break;
|
||||
case 4:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P4_ON : RADIOLIB_NRF24_AA_P4_OFF), 4, 4);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P4_ON : RADIOLIB_NRF24_AA_P4_OFF), 4, 4);
|
||||
break;
|
||||
case 5:
|
||||
return _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P5_ON : RADIOLIB_NRF24_AA_P5_OFF), 5, 5);
|
||||
return this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_EN_AA, (autoAckOn ? RADIOLIB_NRF24_AA_P5_ON : RADIOLIB_NRF24_AA_P5_OFF), 5, 5);
|
||||
break;
|
||||
default:
|
||||
return (RADIOLIB_ERR_INVALID_PIPE_NUMBER);
|
||||
@@ -510,67 +561,51 @@ int16_t nRF24::setEncoding(uint8_t encoding) {
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
uint8_t nRF24::randomByte() {
|
||||
// nRF24 is unable to measure RSSI, hence no TRNG
|
||||
// this method is implemented only for PhysicalLayer compatibility
|
||||
return(0);
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
void nRF24::setDirectAction(void (*func)(void)) {
|
||||
// nRF24 is unable to perform direct mode actions
|
||||
// this method is implemented only for PhysicalLayer compatibility
|
||||
(void)func;
|
||||
}
|
||||
|
||||
void nRF24::readBit(RADIOLIB_PIN_TYPE pin) {
|
||||
// nRF24 is unable to perform direct mode actions
|
||||
// this method is implemented only for PhysicalLayer compatibility
|
||||
(void)pin;
|
||||
}
|
||||
#endif
|
||||
|
||||
void nRF24::clearIRQ() {
|
||||
// clear status bits
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
|
||||
|
||||
// disable interrupts
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF | RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF | RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF, 6, 4);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF | RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF | RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF, 6, 4);
|
||||
}
|
||||
|
||||
int16_t nRF24::config() {
|
||||
// enable 16-bit CRC
|
||||
int16_t state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_CRC_ON | RADIOLIB_NRF24_CRC_16, 3, 2);
|
||||
int16_t state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_CRC_ON | RADIOLIB_NRF24_CRC_16, 3, 2);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// set 15 retries and delay 1500 (5*250) us
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_RETR, (5 << 4) | 5);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_SETUP_RETR, (5 << 4) | 5);
|
||||
|
||||
// set features: dynamic payload on, payload with ACK packets off, dynamic ACK off
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_FEATURE, RADIOLIB_NRF24_DPL_ON | RADIOLIB_NRF24_ACK_PAY_OFF | RADIOLIB_NRF24_DYN_ACK_OFF, 2, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_FEATURE, RADIOLIB_NRF24_DPL_ON | RADIOLIB_NRF24_ACK_PAY_OFF | RADIOLIB_NRF24_DYN_ACK_OFF, 2, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// enable dynamic payloads
|
||||
state = _mod->SPIsetRegValue(RADIOLIB_NRF24_REG_DYNPD, RADIOLIB_NRF24_DPL_ALL_ON, 5, 0);
|
||||
state = this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_DYNPD, RADIOLIB_NRF24_DPL_ALL_ON, 5, 0);
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// reset IRQ
|
||||
clearIRQ();
|
||||
|
||||
// clear status
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_STATUS, RADIOLIB_NRF24_RX_DR | RADIOLIB_NRF24_TX_DS | RADIOLIB_NRF24_MAX_RT, 6, 4);
|
||||
|
||||
// flush FIFOs
|
||||
SPItransfer(RADIOLIB_NRF24_CMD_FLUSH_TX);
|
||||
SPItransfer(RADIOLIB_NRF24_CMD_FLUSH_RX);
|
||||
|
||||
// power up
|
||||
_mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_UP, 1, 1);
|
||||
_mod->delay(5);
|
||||
this->mod->SPIsetRegValue(RADIOLIB_NRF24_REG_CONFIG, RADIOLIB_NRF24_POWER_UP, 1, 1);
|
||||
this->mod->hal->delay(5);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
Module* nRF24::getMod() {
|
||||
return(this->mod);
|
||||
}
|
||||
|
||||
void nRF24::SPIreadRxPayload(uint8_t* data, uint8_t numBytes) {
|
||||
SPItransfer(RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD, false, NULL, data, numBytes);
|
||||
}
|
||||
@@ -580,27 +615,43 @@ void nRF24::SPIwriteTxPayload(uint8_t* data, uint8_t numBytes) {
|
||||
}
|
||||
|
||||
void nRF24::SPItransfer(uint8_t cmd, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes) {
|
||||
// start transfer
|
||||
_mod->digitalWrite(_mod->getCs(), LOW);
|
||||
_mod->SPIbeginTransaction();
|
||||
// prepare the buffers
|
||||
size_t buffLen = 1 + numBytes;
|
||||
#if RADIOLIB_STATIC_ONLY
|
||||
uint8_t buffOut[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
uint8_t buffIn[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#else
|
||||
uint8_t* buffOut = new uint8_t[buffLen];
|
||||
uint8_t* buffIn = new uint8_t[buffLen];
|
||||
#endif
|
||||
uint8_t* buffOutPtr = buffOut;
|
||||
|
||||
// send command
|
||||
_mod->SPItransfer(cmd);
|
||||
// copy the command
|
||||
*(buffOutPtr++) = cmd;
|
||||
|
||||
// send data
|
||||
// copy the data
|
||||
if(write) {
|
||||
for(uint8_t i = 0; i < numBytes; i++) {
|
||||
_mod->SPItransfer(dataOut[i]);
|
||||
}
|
||||
memcpy(buffOutPtr, dataOut, numBytes);
|
||||
} else {
|
||||
for(uint8_t i = 0; i < numBytes; i++) {
|
||||
dataIn[i] = _mod->SPItransfer(0x00);
|
||||
}
|
||||
memset(buffOutPtr, 0x00, numBytes);
|
||||
}
|
||||
|
||||
// stop transfer
|
||||
_mod->SPIendTransaction();
|
||||
_mod->digitalWrite(_mod->getCs(), HIGH);
|
||||
// do the transfer
|
||||
this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelLow);
|
||||
this->mod->hal->spiBeginTransaction();
|
||||
this->mod->hal->spiTransfer(buffOut, buffLen, buffIn);
|
||||
this->mod->hal->spiEndTransaction();
|
||||
this->mod->hal->digitalWrite(this->mod->getCs(), this->mod->hal->GpioLevelHigh);
|
||||
|
||||
// copy the data
|
||||
if(!write) {
|
||||
memcpy(dataIn, &buffIn[1], numBytes);
|
||||
}
|
||||
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] buffOut;
|
||||
delete[] buffIn;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#if !defined(_RADIOLIB_NRF24_H) && !defined(RADIOLIB_EXCLUDE_NRF24)
|
||||
#if !defined(_RADIOLIB_NRF24_H) && !RADIOLIB_EXCLUDE_NRF24
|
||||
#define _RADIOLIB_NRF24_H
|
||||
|
||||
#include "../../Module.h"
|
||||
@@ -7,173 +7,178 @@
|
||||
#include "../../protocols/PhysicalLayer/PhysicalLayer.h"
|
||||
|
||||
// nRF24 physical layer properties
|
||||
#define RADIOLIB_NRF24_FREQUENCY_STEP_SIZE 1000000.0
|
||||
#define RADIOLIB_NRF24_MAX_PACKET_LENGTH 32
|
||||
#define RADIOLIB_NRF24_FREQUENCY_STEP_SIZE 1000000.0
|
||||
#define RADIOLIB_NRF24_MAX_PACKET_LENGTH 32
|
||||
|
||||
// nRF24 SPI commands
|
||||
#define RADIOLIB_NRF24_CMD_READ 0b00000000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE 0b00100000
|
||||
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD 0b01100001
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD 0b10100000
|
||||
#define RADIOLIB_NRF24_CMD_FLUSH_TX 0b11100001
|
||||
#define RADIOLIB_NRF24_CMD_FLUSH_RX 0b11100010
|
||||
#define RADIOLIB_NRF24_CMD_REUSE_TX_PAXLOAD 0b11100011
|
||||
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD_WIDTH 0b01100000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_ACK_PAYLOAD 0b10101000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD_NOACK 0b10110000
|
||||
#define RADIOLIB_NRF24_CMD_NOP 0b11111111
|
||||
#define RADIOLIB_NRF24_CMD_READ 0b00000000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE 0b00100000
|
||||
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD 0b01100001
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD 0b10100000
|
||||
#define RADIOLIB_NRF24_CMD_FLUSH_TX 0b11100001
|
||||
#define RADIOLIB_NRF24_CMD_FLUSH_RX 0b11100010
|
||||
#define RADIOLIB_NRF24_CMD_REUSE_TX_PAXLOAD 0b11100011
|
||||
#define RADIOLIB_NRF24_CMD_READ_RX_PAYLOAD_WIDTH 0b01100000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_ACK_PAYLOAD 0b10101000
|
||||
#define RADIOLIB_NRF24_CMD_WRITE_TX_PAYLOAD_NOACK 0b10110000
|
||||
#define RADIOLIB_NRF24_CMD_NOP 0b11111111
|
||||
|
||||
// nRF24 register map
|
||||
#define RADIOLIB_NRF24_REG_CONFIG 0x00
|
||||
#define RADIOLIB_NRF24_REG_EN_AA 0x01
|
||||
#define RADIOLIB_NRF24_REG_EN_RXADDR 0x02
|
||||
#define RADIOLIB_NRF24_REG_SETUP_AW 0x03
|
||||
#define RADIOLIB_NRF24_REG_SETUP_RETR 0x04
|
||||
#define RADIOLIB_NRF24_REG_RF_CH 0x05
|
||||
#define RADIOLIB_NRF24_REG_RF_SETUP 0x06
|
||||
#define RADIOLIB_NRF24_REG_STATUS 0x07
|
||||
#define RADIOLIB_NRF24_REG_OBSERVE_TX 0x08
|
||||
#define RADIOLIB_NRF24_REG_RPD 0x09
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P0 0x0A
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P1 0x0B
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P2 0x0C
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P3 0x0D
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P4 0x0E
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P5 0x0F
|
||||
#define RADIOLIB_NRF24_REG_TX_ADDR 0x10
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P0 0x11
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P1 0x12
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P2 0x13
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P3 0x14
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P4 0x15
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P5 0x16
|
||||
#define RADIOLIB_NRF24_REG_FIFO_STATUS 0x17
|
||||
#define RADIOLIB_NRF24_REG_DYNPD 0x1C
|
||||
#define RADIOLIB_NRF24_REG_FEATURE 0x1D
|
||||
#define RADIOLIB_NRF24_REG_CONFIG 0x00
|
||||
#define RADIOLIB_NRF24_REG_EN_AA 0x01
|
||||
#define RADIOLIB_NRF24_REG_EN_RXADDR 0x02
|
||||
#define RADIOLIB_NRF24_REG_SETUP_AW 0x03
|
||||
#define RADIOLIB_NRF24_REG_SETUP_RETR 0x04
|
||||
#define RADIOLIB_NRF24_REG_RF_CH 0x05
|
||||
#define RADIOLIB_NRF24_REG_RF_SETUP 0x06
|
||||
#define RADIOLIB_NRF24_REG_STATUS 0x07
|
||||
#define RADIOLIB_NRF24_REG_OBSERVE_TX 0x08
|
||||
#define RADIOLIB_NRF24_REG_RPD 0x09
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P0 0x0A
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P1 0x0B
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P2 0x0C
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P3 0x0D
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P4 0x0E
|
||||
#define RADIOLIB_NRF24_REG_RX_ADDR_P5 0x0F
|
||||
#define RADIOLIB_NRF24_REG_TX_ADDR 0x10
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P0 0x11
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P1 0x12
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P2 0x13
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P3 0x14
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P4 0x15
|
||||
#define RADIOLIB_NRF24_REG_RX_PW_P5 0x16
|
||||
#define RADIOLIB_NRF24_REG_FIFO_STATUS 0x17
|
||||
#define RADIOLIB_NRF24_REG_DYNPD 0x1C
|
||||
#define RADIOLIB_NRF24_REG_FEATURE 0x1D
|
||||
|
||||
// NRF24_REG_CONFIG MSB LSB DESCRIPTION
|
||||
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF 0b01000000 // 6 6 RX_DR will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON 0b00000000 // 6 6 RX_DR will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF 0b00100000 // 5 5 TX_DS will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON 0b00000000 // 5 5 TX_DS will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF 0b00010000 // 4 4 MAX_RT will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_ON 0b00000000 // 4 4 MAX_RT will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_CRC_OFF 0b00000000 // 3 3 CRC calculation: disabled
|
||||
#define RADIOLIB_NRF24_CRC_ON 0b00001000 // 3 3 enabled (default)
|
||||
#define RADIOLIB_NRF24_CRC_8 0b00000000 // 2 2 CRC scheme: CRC8 (default)
|
||||
#define RADIOLIB_NRF24_CRC_16 0b00000100 // 2 2 CRC16
|
||||
#define RADIOLIB_NRF24_POWER_UP 0b00000010 // 1 1 power up
|
||||
#define RADIOLIB_NRF24_POWER_DOWN 0b00000000 // 1 1 power down
|
||||
#define RADIOLIB_NRF24_PTX 0b00000000 // 0 0 enable primary Tx
|
||||
#define RADIOLIB_NRF24_PRX 0b00000001 // 0 0 enable primary Rx
|
||||
// RADIOLIB_NRF24_REG_CONFIG MSB LSB DESCRIPTION
|
||||
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_OFF 0b01000000 // 6 6 RX_DR will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_RX_DR_IRQ_ON 0b00000000 // 6 6 RX_DR will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_OFF 0b00100000 // 5 5 TX_DS will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_TX_DS_IRQ_ON 0b00000000 // 5 5 TX_DS will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_OFF 0b00010000 // 4 4 MAX_RT will not be reflected on IRQ pin
|
||||
#define RADIOLIB_NRF24_MASK_MAX_RT_IRQ_ON 0b00000000 // 4 4 MAX_RT will be reflected on IRQ pin as active low (default)
|
||||
#define RADIOLIB_NRF24_CRC_OFF 0b00000000 // 3 3 CRC calculation: disabled
|
||||
#define RADIOLIB_NRF24_CRC_ON 0b00001000 // 3 3 enabled (default)
|
||||
#define RADIOLIB_NRF24_CRC_8 0b00000000 // 2 2 CRC scheme: CRC8 (default)
|
||||
#define RADIOLIB_NRF24_CRC_16 0b00000100 // 2 2 CRC16
|
||||
#define RADIOLIB_NRF24_POWER_UP 0b00000010 // 1 1 power up
|
||||
#define RADIOLIB_NRF24_POWER_DOWN 0b00000000 // 1 1 power down
|
||||
#define RADIOLIB_NRF24_PTX 0b00000000 // 0 0 enable primary Tx
|
||||
#define RADIOLIB_NRF24_PRX 0b00000001 // 0 0 enable primary Rx
|
||||
|
||||
// NRF24_REG_EN_AA
|
||||
#define RADIOLIB_NRF24_AA_ALL_OFF 0b00000000 // 5 0 auto-ACK on all pipes: disabled
|
||||
#define RADIOLIB_NRF24_AA_ALL_ON 0b00111111 // 5 0 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P5_OFF 0b00000000 // 5 5 auto-ACK on pipe 5: disabled
|
||||
#define RADIOLIB_NRF24_AA_P5_ON 0b00100000 // 5 5 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P4_OFF 0b00000000 // 4 4 auto-ACK on pipe 4: disabled
|
||||
#define RADIOLIB_NRF24_AA_P4_ON 0b00010000 // 4 4 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P3_OFF 0b00000000 // 3 3 auto-ACK on pipe 3: disabled
|
||||
#define RADIOLIB_NRF24_AA_P3_ON 0b00001000 // 3 3 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P2_OFF 0b00000000 // 2 2 auto-ACK on pipe 2: disabled
|
||||
#define RADIOLIB_NRF24_AA_P2_ON 0b00000100 // 2 2 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P1_OFF 0b00000000 // 1 1 auto-ACK on pipe 1: disabled
|
||||
#define RADIOLIB_NRF24_AA_P1_ON 0b00000010 // 1 1 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P0_OFF 0b00000000 // 0 0 auto-ACK on pipe 0: disabled
|
||||
#define RADIOLIB_NRF24_AA_P0_ON 0b00000001 // 0 0 enabled (default)
|
||||
// RADIOLIB_NRF24_REG_EN_AA
|
||||
#define RADIOLIB_NRF24_AA_ALL_OFF 0b00000000 // 5 0 auto-ACK on all pipes: disabled
|
||||
#define RADIOLIB_NRF24_AA_ALL_ON 0b00111111 // 5 0 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P5_OFF 0b00000000 // 5 5 auto-ACK on pipe 5: disabled
|
||||
#define RADIOLIB_NRF24_AA_P5_ON 0b00100000 // 5 5 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P4_OFF 0b00000000 // 4 4 auto-ACK on pipe 4: disabled
|
||||
#define RADIOLIB_NRF24_AA_P4_ON 0b00010000 // 4 4 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P3_OFF 0b00000000 // 3 3 auto-ACK on pipe 3: disabled
|
||||
#define RADIOLIB_NRF24_AA_P3_ON 0b00001000 // 3 3 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P2_OFF 0b00000000 // 2 2 auto-ACK on pipe 2: disabled
|
||||
#define RADIOLIB_NRF24_AA_P2_ON 0b00000100 // 2 2 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P1_OFF 0b00000000 // 1 1 auto-ACK on pipe 1: disabled
|
||||
#define RADIOLIB_NRF24_AA_P1_ON 0b00000010 // 1 1 enabled (default)
|
||||
#define RADIOLIB_NRF24_AA_P0_OFF 0b00000000 // 0 0 auto-ACK on pipe 0: disabled
|
||||
#define RADIOLIB_NRF24_AA_P0_ON 0b00000001 // 0 0 enabled (default)
|
||||
|
||||
// NRF24_REG_EN_RXADDR
|
||||
#define RADIOLIB_NRF24_P5_OFF 0b00000000 // 5 5 receive pipe 5: disabled (default)
|
||||
#define RADIOLIB_NRF24_P5_ON 0b00100000 // 5 5 enabled
|
||||
#define RADIOLIB_NRF24_P4_OFF 0b00000000 // 4 4 receive pipe 4: disabled (default)
|
||||
#define RADIOLIB_NRF24_P4_ON 0b00010000 // 4 4 enabled
|
||||
#define RADIOLIB_NRF24_P3_OFF 0b00000000 // 3 3 receive pipe 3: disabled (default)
|
||||
#define RADIOLIB_NRF24_P3_ON 0b00001000 // 3 3 enabled
|
||||
#define RADIOLIB_NRF24_P2_OFF 0b00000000 // 2 2 receive pipe 2: disabled (default)
|
||||
#define RADIOLIB_NRF24_P2_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_P1_OFF 0b00000000 // 1 1 receive pipe 1: disabled
|
||||
#define RADIOLIB_NRF24_P1_ON 0b00000010 // 1 1 enabled (default)
|
||||
#define RADIOLIB_NRF24_P0_OFF 0b00000000 // 0 0 receive pipe 0: disabled
|
||||
#define RADIOLIB_NRF24_P0_ON 0b00000001 // 0 0 enabled (default)
|
||||
// RADIOLIB_NRF24_REG_EN_RXADDR
|
||||
#define RADIOLIB_NRF24_P5_OFF 0b00000000 // 5 5 receive pipe 5: disabled (default)
|
||||
#define RADIOLIB_NRF24_P5_ON 0b00100000 // 5 5 enabled
|
||||
#define RADIOLIB_NRF24_P4_OFF 0b00000000 // 4 4 receive pipe 4: disabled (default)
|
||||
#define RADIOLIB_NRF24_P4_ON 0b00010000 // 4 4 enabled
|
||||
#define RADIOLIB_NRF24_P3_OFF 0b00000000 // 3 3 receive pipe 3: disabled (default)
|
||||
#define RADIOLIB_NRF24_P3_ON 0b00001000 // 3 3 enabled
|
||||
#define RADIOLIB_NRF24_P2_OFF 0b00000000 // 2 2 receive pipe 2: disabled (default)
|
||||
#define RADIOLIB_NRF24_P2_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_P1_OFF 0b00000000 // 1 1 receive pipe 1: disabled
|
||||
#define RADIOLIB_NRF24_P1_ON 0b00000010 // 1 1 enabled (default)
|
||||
#define RADIOLIB_NRF24_P0_OFF 0b00000000 // 0 0 receive pipe 0: disabled
|
||||
#define RADIOLIB_NRF24_P0_ON 0b00000001 // 0 0 enabled (default)
|
||||
|
||||
// NRF24_REG_SETUP_AW
|
||||
#define RADIOLIB_NRF24_ADDRESS_2_BYTES 0b00000000 // 1 0 address width: 2 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_3_BYTES 0b00000001 // 1 0 3 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_4_BYTES 0b00000010 // 1 0 4 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_5_BYTES 0b00000011 // 1 0 5 bytes (default)
|
||||
// RADIOLIB_NRF24_REG_SETUP_AW
|
||||
#define RADIOLIB_NRF24_ADDRESS_2_BYTES 0b00000000 // 1 0 address width: 2 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_3_BYTES 0b00000001 // 1 0 3 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_4_BYTES 0b00000010 // 1 0 4 bytes
|
||||
#define RADIOLIB_NRF24_ADDRESS_5_BYTES 0b00000011 // 1 0 5 bytes (default)
|
||||
|
||||
// NRF24_REG_SETUP_RETR
|
||||
#define RADIOLIB_NRF24_ARD 0b00000000 // 7 4 auto retransmit delay: t[us] = (NRF24_ARD + 1) * 250 us
|
||||
#define RADIOLIB_NRF24_ARC_OFF 0b00000000 // 3 0 auto retransmit count: auto retransmit disabled
|
||||
#define RADIOLIB_NRF24_ARC 0b00000011 // 3 0 up to 3 retransmits on AA fail (default)
|
||||
// RADIOLIB_NRF24_REG_SETUP_RETR
|
||||
#define RADIOLIB_NRF24_ARD 0b00000000 // 7 4 auto retransmit delay: t[us] = (NRF24_ARD + 1) * 250 us
|
||||
#define RADIOLIB_NRF24_ARC_OFF 0b00000000 // 3 0 auto retransmit count: auto retransmit disabled
|
||||
#define RADIOLIB_NRF24_ARC 0b00000011 // 3 0 up to 3 retransmits on AA fail (default)
|
||||
|
||||
// NRF24_REG_RF_CH
|
||||
#define RADIOLIB_NRF24_RF_CH 0b00000010 // 6 0 RF channel: f_CH[MHz] = 2400 MHz + NRF24_RF_CH
|
||||
// RADIOLIB_NRF24_REG_RF_CH
|
||||
#define RADIOLIB_NRF24_RF_CH 0b00000010 // 6 0 RF channel: f_CH[MHz] = 2400 MHz + NRF24_RF_CH
|
||||
|
||||
// NRF24_REG_RF_SETUP
|
||||
#define RADIOLIB_NRF24_CONT_WAVE_OFF 0b00000000 // 7 7 continuous carrier transmit: disabled (default)
|
||||
#define RADIOLIB_NRF24_CONT_WAVE_ON 0b10000000 // 7 7 enabled
|
||||
#define RADIOLIB_NRF24_DR_250_KBPS 0b00100000 // 5 5 data rate: 250 kbps
|
||||
#define RADIOLIB_NRF24_DR_1_MBPS 0b00000000 // 3 3 1 Mbps (default)
|
||||
#define RADIOLIB_NRF24_DR_2_MBPS 0b00001000 // 3 3 2 Mbps
|
||||
#define RADIOLIB_NRF24_PLL_LOCK_ON 0b00010000 // 4 4 force PLL lock: enabled
|
||||
#define RADIOLIB_NRF24_PLL_LOCK_OFF 0b00000000 // 4 4 disabled (default)
|
||||
#define RADIOLIB_NRF24_RF_PWR_18_DBM 0b00000000 // 2 1 output power: -18 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_12_DBM 0b00000010 // 2 1 -12 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_6_DBM 0b00000100 // 2 1 -6 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_0_DBM 0b00000110 // 2 1 0 dBm (default)
|
||||
// RADIOLIB_NRF24_REG_RF_SETUP
|
||||
#define RADIOLIB_NRF24_CONT_WAVE_OFF 0b00000000 // 7 7 continuous carrier transmit: disabled (default)
|
||||
#define RADIOLIB_NRF24_CONT_WAVE_ON 0b10000000 // 7 7 enabled
|
||||
#define RADIOLIB_NRF24_DR_250_KBPS 0b00100000 // 5 5 data rate: 250 kbps
|
||||
#define RADIOLIB_NRF24_DR_1_MBPS 0b00000000 // 3 3 1 Mbps (default)
|
||||
#define RADIOLIB_NRF24_DR_2_MBPS 0b00001000 // 3 3 2 Mbps
|
||||
#define RADIOLIB_NRF24_PLL_LOCK_ON 0b00010000 // 4 4 force PLL lock: enabled
|
||||
#define RADIOLIB_NRF24_PLL_LOCK_OFF 0b00000000 // 4 4 disabled (default)
|
||||
#define RADIOLIB_NRF24_RF_PWR_18_DBM 0b00000000 // 2 1 output power: -18 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_12_DBM 0b00000010 // 2 1 -12 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_6_DBM 0b00000100 // 2 1 -6 dBm
|
||||
#define RADIOLIB_NRF24_RF_PWR_0_DBM 0b00000110 // 2 1 0 dBm (default)
|
||||
|
||||
// NRF24_REG_STATUS
|
||||
#define RADIOLIB_NRF24_RX_DR 0b01000000 // 6 6 Rx data ready
|
||||
#define RADIOLIB_NRF24_TX_DS 0b00100000 // 5 5 Tx data sent
|
||||
#define RADIOLIB_NRF24_MAX_RT 0b00010000 // 4 4 maximum number of retransmits reached (must be cleared to continue)
|
||||
#define RADIOLIB_NRF24_RX_FIFO_EMPTY 0b00001110 // 3 1 Rx FIFO is empty
|
||||
#define RADIOLIB_NRF24_RX_P_NO 0b00000000 // 3 1 number of data pipe that received data
|
||||
#define RADIOLIB_NRF24_TX_FIFO_FULL 0b00000001 // 0 0 Tx FIFO is full
|
||||
// RADIOLIB_NRF24_REG_STATUS
|
||||
#define RADIOLIB_NRF24_RX_DR 0b01000000 // 6 6 Rx data ready
|
||||
#define RADIOLIB_NRF24_TX_DS 0b00100000 // 5 5 Tx data sent
|
||||
#define RADIOLIB_NRF24_MAX_RT 0b00010000 // 4 4 maximum number of retransmits reached (must be cleared to continue)
|
||||
#define RADIOLIB_NRF24_RX_FIFO_EMPTY 0b00001110 // 3 1 Rx FIFO is empty
|
||||
#define RADIOLIB_NRF24_RX_P_NO 0b00000000 // 3 1 number of data pipe that received data
|
||||
#define RADIOLIB_NRF24_TX_FIFO_FULL 0b00000001 // 0 0 Tx FIFO is full
|
||||
|
||||
// NRF24_REG_OBSERVE_TX
|
||||
#define RADIOLIB_NRF24_PLOS_CNT 0b00000000 // 7 4 number of lost packets
|
||||
#define RADIOLIB_NRF24_ARC_CNT 0b00000000 // 3 0 number of retransmitted packets
|
||||
// RADIOLIB_NRF24_REG_OBSERVE_TX
|
||||
#define RADIOLIB_NRF24_PLOS_CNT 0b00000000 // 7 4 number of lost packets
|
||||
#define RADIOLIB_NRF24_ARC_CNT 0b00000000 // 3 0 number of retransmitted packets
|
||||
|
||||
// NRF24_REG_RPD
|
||||
#define RADIOLIB_NRF24_RP_BELOW_64_DBM 0b00000000 // 0 0 received power in the current channel: less than -64 dBm
|
||||
#define RADIOLIB_NRF24_RP_ABOVE_64_DBM 0b00000001 // 0 0 more than -64 dBm
|
||||
// RADIOLIB_NRF24_REG_RPD
|
||||
#define RADIOLIB_NRF24_RP_BELOW_64_DBM 0b00000000 // 0 0 received power in the current channel: less than -64 dBm
|
||||
#define RADIOLIB_NRF24_RP_ABOVE_64_DBM 0b00000001 // 0 0 more than -64 dBm
|
||||
|
||||
// NRF24_REG_FIFO_STATUS
|
||||
#define RADIOLIB_NRF24_TX_REUSE 0b01000000 // 6 6 reusing last transmitted payload
|
||||
#define RADIOLIB_NRF24_TX_FIFO_FULL_FLAG 0b00100000 // 5 5 Tx FIFO is full
|
||||
#define RADIOLIB_NRF24_TX_FIFO_EMPTY_FLAG 0b00010000 // 4 4 Tx FIFO is empty
|
||||
#define RADIOLIB_NRF24_RX_FIFO_FULL_FLAG 0b00000010 // 1 1 Rx FIFO is full
|
||||
#define RADIOLIB_NRF24_RX_FIFO_EMPTY_FLAG 0b00000001 // 0 0 Rx FIFO is empty
|
||||
// RADIOLIB_NRF24_REG_FIFO_STATUS
|
||||
#define RADIOLIB_NRF24_TX_REUSE 0b01000000 // 6 6 reusing last transmitted payload
|
||||
#define RADIOLIB_NRF24_TX_FIFO_FULL_FLAG 0b00100000 // 5 5 Tx FIFO is full
|
||||
#define RADIOLIB_NRF24_TX_FIFO_EMPTY_FLAG 0b00010000 // 4 4 Tx FIFO is empty
|
||||
#define RADIOLIB_NRF24_RX_FIFO_FULL_FLAG 0b00000010 // 1 1 Rx FIFO is full
|
||||
#define RADIOLIB_NRF24_RX_FIFO_EMPTY_FLAG 0b00000001 // 0 0 Rx FIFO is empty
|
||||
|
||||
// NRF24_REG_DYNPD
|
||||
#define RADIOLIB_NRF24_DPL_P5_OFF 0b00000000 // 5 5 dynamic payload length on pipe 5: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P5_ON 0b00100000 // 5 5 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P4_OFF 0b00000000 // 4 4 dynamic payload length on pipe 4: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P4_ON 0b00010000 // 4 4 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P3_OFF 0b00000000 // 3 3 dynamic payload length on pipe 3: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P3_ON 0b00001000 // 3 3 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P2_OFF 0b00000000 // 2 2 dynamic payload length on pipe 2: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P2_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P1_OFF 0b00000000 // 1 1 dynamic payload length on pipe 1: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P1_ON 0b00000010 // 1 1 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P0_OFF 0b00000000 // 0 0 dynamic payload length on pipe 0: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P0_ON 0b00000001 // 0 0 enabled
|
||||
#define RADIOLIB_NRF24_DPL_ALL_OFF 0b00000000 // 5 0 disable all dynamic payloads
|
||||
#define RADIOLIB_NRF24_DPL_ALL_ON 0b00111111 // 5 0 enable all dynamic payloads
|
||||
// RADIOLIB_NRF24_REG_DYNPD
|
||||
#define RADIOLIB_NRF24_DPL_P5_OFF 0b00000000 // 5 5 dynamic payload length on pipe 5: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P5_ON 0b00100000 // 5 5 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P4_OFF 0b00000000 // 4 4 dynamic payload length on pipe 4: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P4_ON 0b00010000 // 4 4 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P3_OFF 0b00000000 // 3 3 dynamic payload length on pipe 3: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P3_ON 0b00001000 // 3 3 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P2_OFF 0b00000000 // 2 2 dynamic payload length on pipe 2: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P2_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P1_OFF 0b00000000 // 1 1 dynamic payload length on pipe 1: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P1_ON 0b00000010 // 1 1 enabled
|
||||
#define RADIOLIB_NRF24_DPL_P0_OFF 0b00000000 // 0 0 dynamic payload length on pipe 0: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_P0_ON 0b00000001 // 0 0 enabled
|
||||
#define RADIOLIB_NRF24_DPL_ALL_OFF 0b00000000 // 5 0 disable all dynamic payloads
|
||||
#define RADIOLIB_NRF24_DPL_ALL_ON 0b00111111 // 5 0 enable all dynamic payloads
|
||||
|
||||
// NRF24_REG_FEATURE
|
||||
#define RADIOLIB_NRF24_DPL_OFF 0b00000000 // 2 2 dynamic payload length: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_ACK_PAY_OFF 0b00000000 // 1 1 payload with ACK packets: disabled (default)
|
||||
#define RADIOLIB_NRF24_ACK_PAY_ON 0b00000010 // 1 1 enabled
|
||||
#define RADIOLIB_NRF24_DYN_ACK_OFF 0b00000000 // 0 0 payloads without ACK: disabled (default)
|
||||
#define RADIOLIB_NRF24_DYN_ACK_ON 0b00000001 // 0 0 enabled
|
||||
// RADIOLIB_NRF24_REG_FEATURE
|
||||
#define RADIOLIB_NRF24_DPL_OFF 0b00000000 // 2 2 dynamic payload length: disabled (default)
|
||||
#define RADIOLIB_NRF24_DPL_ON 0b00000100 // 2 2 enabled
|
||||
#define RADIOLIB_NRF24_ACK_PAY_OFF 0b00000000 // 1 1 payload with ACK packets: disabled (default)
|
||||
#define RADIOLIB_NRF24_ACK_PAY_ON 0b00000010 // 1 1 enabled
|
||||
#define RADIOLIB_NRF24_DYN_ACK_OFF 0b00000000 // 0 0 payloads without ACK: disabled (default)
|
||||
#define RADIOLIB_NRF24_DYN_ACK_ON 0b00000001 // 0 0 enabled
|
||||
|
||||
// RadioLib defaults
|
||||
#define RADIOLIB_NRF24_DEFAULT_FREQ 2400
|
||||
#define RADIOLIB_NRF24_DEFAULT_DR 1000
|
||||
#define RADIOLIB_NRF24_DEFAULT_POWER -12
|
||||
#define RADIOLIB_NRF24_DEFAULT_ADDRWIDTH 5
|
||||
|
||||
/*!
|
||||
\class nRF24
|
||||
|
||||
\brief Control class for %nRF24 module.
|
||||
*/
|
||||
class nRF24: public PhysicalLayer {
|
||||
@@ -186,82 +191,73 @@ class nRF24: public PhysicalLayer {
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the radio.
|
||||
*/
|
||||
nRF24(Module* mod);
|
||||
|
||||
Module* getMod();
|
||||
nRF24(Module* mod); // cppcheck-suppress noExplicitConstructor
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\param freq Carrier frequency in MHz. Defaults to 2400 MHz.
|
||||
|
||||
\param dataRate Data rate to be used in kbps. Defaults to 1000 kbps.
|
||||
|
||||
\param power Output power in dBm. Defaults to -12 dBm.
|
||||
|
||||
\param dr Data rate to be used in kbps. Defaults to 1000 kbps.
|
||||
\param pwr Output power in dBm. Defaults to -12 dBm.
|
||||
\param addrWidth Address width in bytes. Defaults to 5 bytes.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(int16_t freq = 2400, int16_t dataRate = 1000, int8_t power = -12, uint8_t addrWidth = 5);
|
||||
int16_t begin(
|
||||
int16_t freq = RADIOLIB_NRF24_DEFAULT_FREQ,
|
||||
int16_t dr = RADIOLIB_NRF24_DEFAULT_DR,
|
||||
int8_t pwr = RADIOLIB_NRF24_DEFAULT_POWER,
|
||||
uint8_t addrWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH);
|
||||
|
||||
/*!
|
||||
\brief Sets the module to sleep mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sleep();
|
||||
int16_t sleep() override;
|
||||
|
||||
/*!
|
||||
\brief Sets the module to standby mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t standby() override;
|
||||
|
||||
/*!
|
||||
\brief Blocking binary transmit method.
|
||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||
|
||||
\param data Binary data to be sent.
|
||||
|
||||
\param len Number of bytes to send.
|
||||
|
||||
\param addr Dummy address parameter, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\brief Sets the module to standby.
|
||||
\param mode Standby mode to be used.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(uint8_t* data, size_t len, uint8_t addr) override;
|
||||
int16_t standby(uint8_t mode) override;
|
||||
|
||||
/*!
|
||||
\brief Blocking binary transmit method.
|
||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||
\param data Binary data to be sent.
|
||||
\param len Number of bytes to send.
|
||||
\param addr Dummy address parameter, to ensure PhysicalLayer compatibility.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(const uint8_t* data, size_t len, uint8_t addr) override;
|
||||
|
||||
/*!
|
||||
\brief Blocking binary receive method.
|
||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||
|
||||
\param data Binary data to be sent.
|
||||
|
||||
\param len Number of bytes to send.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t receive(uint8_t* data, size_t len) override;
|
||||
|
||||
/*!
|
||||
\brief Starts direct mode transmission.
|
||||
|
||||
\param frf Raw RF frequency value. Defaults to 0, required for quick frequency shifts in RTTY.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmitDirect(uint32_t frf = 0) override;
|
||||
|
||||
/*!
|
||||
\brief Dummy direct mode reception method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t receiveDirect() override;
|
||||
@@ -270,39 +266,74 @@ class nRF24: public PhysicalLayer {
|
||||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when IRQ activates.
|
||||
|
||||
\param func ISR to call.
|
||||
*/
|
||||
void setIrqAction(void (*func)(void));
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine .
|
||||
*/
|
||||
void clearIrqAction();
|
||||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when a packet is received.
|
||||
\param func ISR to call.
|
||||
*/
|
||||
void setPacketReceivedAction(void (*func)(void)) override;
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine to call when a packet is received.
|
||||
*/
|
||||
void clearPacketReceivedAction() override;
|
||||
|
||||
/*!
|
||||
\brief Sets interrupt service routine to call when a packet is sent.
|
||||
\param func ISR to call.
|
||||
*/
|
||||
void setPacketSentAction(void (*func)(void)) override;
|
||||
|
||||
/*!
|
||||
\brief Clears interrupt service routine to call when a packet is sent.
|
||||
*/
|
||||
void clearPacketSentAction() override;
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven binary transmit method. IRQ will be activated when full packet is transmitted.
|
||||
Overloads for string-based transmissions are implemented in PhysicalLayer.
|
||||
|
||||
\param data Binary data to be sent.
|
||||
|
||||
\param len Number of bytes to send.
|
||||
|
||||
\param addr Dummy address parameter, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr) override;
|
||||
int16_t startTransmit(const uint8_t* data, size_t len, uint8_t addr) override;
|
||||
|
||||
/*!
|
||||
\brief Clean up after transmission is done.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t finishTransmit() override;
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven receive method. IRQ will be activated when full packet is received.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startReceive();
|
||||
int16_t startReceive() override;
|
||||
|
||||
/*!
|
||||
\brief Reads data received after calling startReceive method.
|
||||
\brief Interrupt-driven receive method, implemented for compatibility with PhysicalLayer.
|
||||
\param timeout Ignored.
|
||||
\param irqFlags Ignored.
|
||||
\param irqMask Ignored.
|
||||
\param len Ignored.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startReceive(uint32_t timeout, uint32_t irqFlags, uint32_t irqMask, size_t len) override;
|
||||
|
||||
/*!
|
||||
\brief Reads data received after calling startReceive method. When the packet length is not known in advance,
|
||||
getPacketLength method must be called BEFORE calling readData!
|
||||
\param data Pointer to array to save the received binary data.
|
||||
|
||||
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t readData(uint8_t* data, size_t len) override;
|
||||
@@ -311,198 +342,147 @@ class nRF24: public PhysicalLayer {
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 2400 MHz to 2525 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(int16_t freq);
|
||||
int16_t setFrequency(float freq) override;
|
||||
|
||||
/*!
|
||||
\brief Sets data rate. Allowed values are 2000, 1000 or 250 kbps.
|
||||
|
||||
\param dataRate Data rate to be set in kbps.
|
||||
|
||||
\brief Sets bit rate. Allowed values are 2000, 1000 or 250 kbps.
|
||||
\param br Bit rate to be set in kbps.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataRate(int16_t dataRate);
|
||||
int16_t setBitRate(float br) override;
|
||||
|
||||
/*!
|
||||
\brief Sets output power. Allowed values are -18, -12, -6 or 0 dBm.
|
||||
|
||||
\param power Output power to be set in dBm.
|
||||
|
||||
\param pwr Output power to be set in dBm.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
int16_t setOutputPower(int8_t pwr) override;
|
||||
|
||||
/*!
|
||||
\brief Sets address width of transmit and receive pipes in bytes. Allowed values are 3, 4 or 5 bytes.
|
||||
|
||||
\param addrWidth Address width to be set in bytes.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setAddressWidth(uint8_t addrWidth);
|
||||
|
||||
/*!
|
||||
\brief Sets address of transmit pipe. The address width must be the same as the same as the configured in setAddressWidth.
|
||||
|
||||
\brief Sets address of transmit pipe. The address width must be the same as the same
|
||||
as the configured in setAddressWidth.
|
||||
\param addr Address to which the next packet shall be transmitted.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setTransmitPipe(uint8_t* addr);
|
||||
|
||||
/*!
|
||||
\brief Sets address of receive pipes 0 or 1. The address width must be the same as the same as the configured in setAddressWidth.
|
||||
|
||||
\param pipeNum Number of pipe to which the address shall be set. Either 0 or 1, other pipes are handled using overloaded method.
|
||||
|
||||
\brief Sets address of receive pipes 0 or 1. The address width must be the same as the same
|
||||
as the configured in setAddressWidth.
|
||||
\param pipeNum Number of pipe to which the address shall be set. Either 0 or 1,
|
||||
other pipes are handled using overloaded method.
|
||||
\param addr Address from which %nRF24 shall receive new packets on the specified pipe.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setReceivePipe(uint8_t pipeNum, uint8_t* addr);
|
||||
|
||||
/*!
|
||||
\brief Sets address of receive pipes 2 - 5. The first 2 - 4 address bytes for these pipes are the same as for address pipe 1, only the last byte can be set.
|
||||
|
||||
\brief Sets address of receive pipes 2 - 5. The first 2 - 4 address bytes for these pipes
|
||||
are the same as for address pipe 1, only the last byte can be set.
|
||||
\param pipeNum Number of pipe to which the address shall be set. Allowed values range from 2 to 5.
|
||||
|
||||
\param addrByte LSB of address from which %nRF24 shall receive new packets on the specified pipe.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setReceivePipe(uint8_t pipeNum, uint8_t addrByte);
|
||||
|
||||
/*!
|
||||
\brief Disables specified receive pipe.
|
||||
|
||||
\param pipeNum Receive pipe to be disabled.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t disablePipe(uint8_t pipeNum);
|
||||
|
||||
/*!
|
||||
\brief Gets nRF24 status register.
|
||||
|
||||
\param mask Bit mask to be used on the returned register value.
|
||||
|
||||
\returns Status register value or \ref status_codes
|
||||
*/
|
||||
int16_t getStatus(uint8_t mask = 0xFF);
|
||||
|
||||
/*!
|
||||
\brief Checks if carrier was detected during last RX
|
||||
|
||||
\returns Whatever the carrier was above threshold.
|
||||
*/
|
||||
bool isCarrierDetected();
|
||||
|
||||
/*!
|
||||
\brief Dummy configuration method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param freqDev Dummy frequency deviation parameter, no configuration will be changed.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequencyDeviation(float freqDev) override;
|
||||
|
||||
/*!
|
||||
\brief Query modem for the packet length of received payload.
|
||||
|
||||
\param update Update received packet length. Will return cached value when set to false.
|
||||
|
||||
\returns Length of last received packet in bytes.
|
||||
*/
|
||||
size_t getPacketLength(bool update = true) override;
|
||||
|
||||
/*!
|
||||
\brief Enable CRC filtering and generation.
|
||||
|
||||
\param crcOn Set or unset CRC check.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCrcFiltering(bool crcOn = true);
|
||||
|
||||
/*!
|
||||
\brief Enable or disable auto-acknowledge packets on all pipes
|
||||
|
||||
\brief Enable or disable auto-acknowledge packets on all pipes.
|
||||
\param autoAckOn Enable (true) or disable (false) auto-acks.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setAutoAck(bool autoAckOn = true);
|
||||
|
||||
/*!
|
||||
\brief Enable or disable auto-acknowledge packets on given pipe.
|
||||
|
||||
\param pipeNum Number of pipe to which enable / disable auto-acks.
|
||||
|
||||
\param autoAckOn Enable (true) or disable (false) auto-acks.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setAutoAck(uint8_t pipeNum, bool autoAckOn);
|
||||
|
||||
/*!
|
||||
\brief Dummy data shaping configuration method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param sh Ignored.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataShaping(uint8_t sh) override;
|
||||
|
||||
/*!
|
||||
\brief Dummy encoding configuration method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param sh Ignored.
|
||||
|
||||
\param encoding Ignored.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setEncoding(uint8_t encoding) override;
|
||||
|
||||
/*!
|
||||
\brief Dummy random method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\returns Always returns 0.
|
||||
*/
|
||||
uint8_t randomByte();
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||
/*!
|
||||
\brief Dummy method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param func Ignored.
|
||||
*/
|
||||
void setDirectAction(void (*func)(void));
|
||||
|
||||
/*!
|
||||
\brief Dummy method, to ensure PhysicalLayer compatibility.
|
||||
|
||||
\param pin Ignored.
|
||||
*/
|
||||
void readBit(RADIOLIB_PIN_TYPE pin);
|
||||
#endif
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
|
||||
#if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL
|
||||
protected:
|
||||
#endif
|
||||
Module* _mod;
|
||||
Module* getMod() override;
|
||||
|
||||
void SPIreadRxPayload(uint8_t* data, uint8_t numBytes);
|
||||
void SPIwriteTxPayload(uint8_t* data, uint8_t numBytes);
|
||||
void SPItransfer(uint8_t cmd, bool write = false, uint8_t* dataOut = NULL, uint8_t* dataIn = NULL, uint8_t numBytes = 0);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
protected:
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
Module* mod;
|
||||
|
||||
uint8_t _addrWidth = 0;
|
||||
int16_t frequency = RADIOLIB_NRF24_DEFAULT_FREQ;
|
||||
int16_t dataRate = RADIOLIB_NRF24_DEFAULT_DR;
|
||||
int8_t power = RADIOLIB_NRF24_DEFAULT_POWER;
|
||||
uint8_t addressWidth = RADIOLIB_NRF24_DEFAULT_ADDRWIDTH;
|
||||
|
||||
int16_t config();
|
||||
void clearIRQ();
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
#include "AFSK.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
|
||||
AFSKClient::AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin): _pin(pin) {
|
||||
_phy = phy;
|
||||
AFSKClient::AFSKClient(PhysicalLayer* phy, uint32_t pin): outPin(pin) {
|
||||
phyLayer = phy;
|
||||
}
|
||||
|
||||
AFSKClient::AFSKClient(AFSKClient* aud) {
|
||||
phyLayer = aud->phyLayer;
|
||||
outPin = aud->outPin;
|
||||
}
|
||||
|
||||
int16_t AFSKClient::begin() {
|
||||
return(_phy->startDirect());
|
||||
return(phyLayer->startDirect());
|
||||
}
|
||||
|
||||
int16_t AFSKClient::tone(uint16_t freq, bool autoStart) {
|
||||
@@ -15,23 +20,23 @@ int16_t AFSKClient::tone(uint16_t freq, bool autoStart) {
|
||||
}
|
||||
|
||||
if(autoStart) {
|
||||
int16_t state = _phy->transmitDirect();
|
||||
int16_t state = phyLayer->transmitDirect();
|
||||
RADIOLIB_ASSERT(state);
|
||||
}
|
||||
|
||||
Module* mod = _phy->getMod();
|
||||
mod->tone(_pin, freq);
|
||||
Module* mod = phyLayer->getMod();
|
||||
mod->hal->tone(outPin, freq);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t AFSKClient::noTone(bool keepOn) {
|
||||
Module* mod = _phy->getMod();
|
||||
mod->noTone(_pin);
|
||||
Module* mod = phyLayer->getMod();
|
||||
mod->hal->noTone(outPin);
|
||||
if(keepOn) {
|
||||
return(0);
|
||||
}
|
||||
|
||||
return(_phy->standby());
|
||||
return(phyLayer->standby());
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
|
||||
#include "../../Module.h"
|
||||
|
||||
@@ -11,52 +11,49 @@
|
||||
|
||||
/*!
|
||||
\class AFSKClient
|
||||
|
||||
\brief Client for audio-based transmissions. Requires Arduino tone() function, and a module capable of direct mode transmission using DIO pins.
|
||||
*/
|
||||
class AFSKClient {
|
||||
public:
|
||||
/*!
|
||||
\brief Default contructor.
|
||||
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
|
||||
\param pin The pin that will be used for audio output.
|
||||
*/
|
||||
AFSKClient(PhysicalLayer* phy, RADIOLIB_PIN_TYPE pin);
|
||||
AFSKClient(PhysicalLayer* phy, uint32_t pin);
|
||||
|
||||
/*!
|
||||
\brief Copy contructor.
|
||||
\param aud Pointer to the AFSKClient instance to copy.
|
||||
*/
|
||||
explicit AFSKClient(AFSKClient* aud);
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin();
|
||||
|
||||
/*!
|
||||
\brief Start transmitting audio tone.
|
||||
|
||||
\param freq Frequency of the tone in Hz.
|
||||
|
||||
\param autoStart Whether to automatically enter transmission mode. Defaults to true.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t tone(uint16_t freq, bool autoStart = true);
|
||||
|
||||
/*!
|
||||
\brief Stops transmitting audio tone.
|
||||
|
||||
\param freq Keep transmitter on - this may limit noise when switching transmitter on or off.
|
||||
|
||||
\param keepOn Keep transmitter on - this may limit noise when switching transmitter on or off.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t noTone(bool keepOn = false);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
PhysicalLayer* _phy;
|
||||
RADIOLIB_PIN_TYPE _pin;
|
||||
PhysicalLayer* phyLayer;
|
||||
uint32_t outPin;
|
||||
|
||||
// allow specific classes access the private PhysicalLayer pointer
|
||||
friend class RTTYClient;
|
||||
@@ -65,6 +62,7 @@ class AFSKClient {
|
||||
friend class SSTVClient;
|
||||
friend class AX25Client;
|
||||
friend class FSK4Client;
|
||||
friend class BellClient;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,54 +1,84 @@
|
||||
#include "APRS.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#if !RADIOLIB_EXCLUDE_APRS
|
||||
|
||||
APRSClient::APRSClient(AX25Client* ax) {
|
||||
_ax = ax;
|
||||
axClient = ax;
|
||||
phyLayer = nullptr;
|
||||
}
|
||||
|
||||
int16_t APRSClient::begin(char symbol, bool alt) {
|
||||
RADIOLIB_CHECK_RANGE(symbol, ' ', '}', RADIOLIB_ERR_INVALID_SYMBOL);
|
||||
_symbol = symbol;
|
||||
APRSClient::APRSClient(PhysicalLayer* phy) {
|
||||
axClient = nullptr;
|
||||
phyLayer = phy;
|
||||
}
|
||||
|
||||
int16_t APRSClient::begin(char sym, char* callsign, uint8_t ssid, bool alt) {
|
||||
RADIOLIB_CHECK_RANGE(sym, ' ', '}', RADIOLIB_ERR_INVALID_SYMBOL);
|
||||
symbol = sym;
|
||||
|
||||
if(alt) {
|
||||
_table = '\\';
|
||||
table = '\\';
|
||||
} else {
|
||||
_table = '/';
|
||||
table = '/';
|
||||
}
|
||||
|
||||
// callsign is only processed for LoRa APRS
|
||||
if(!callsign) {
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
if(strlen(callsign) > RADIOLIB_AX25_MAX_CALLSIGN_LEN) {
|
||||
return(RADIOLIB_ERR_INVALID_CALLSIGN);
|
||||
}
|
||||
|
||||
memcpy(this->src, callsign, strlen(callsign));
|
||||
this->id = ssid;
|
||||
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
|
||||
int16_t APRSClient::sendPosition(char* destCallsign, uint8_t destSSID, char* lat, char* lon, char* msg, char* time) {
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
size_t len = 1 + strlen(lat) + 1 + strlen(lon);
|
||||
if(msg != NULL) {
|
||||
len += 1 + strlen(msg);
|
||||
}
|
||||
if(time != NULL) {
|
||||
len += strlen(time);
|
||||
}
|
||||
char* info = new char[len];
|
||||
size_t len = 1 + strlen(lat) + 1 + strlen(lon);
|
||||
if(msg != NULL) {
|
||||
len += 1 + strlen(msg);
|
||||
}
|
||||
if(time != NULL) {
|
||||
len += strlen(time);
|
||||
}
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
char* info = new char[len + 2];
|
||||
#else
|
||||
char info[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#endif
|
||||
|
||||
// build the info field
|
||||
if((msg == NULL) && (time == NULL)) {
|
||||
// no message, no timestamp
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_NO_TIME_NO_MSG "%s%c%s%c", lat, _table, lon, _symbol);
|
||||
} else if((msg != NULL) && (time == NULL)) {
|
||||
// message, no timestamp
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_NO_TIME_MSG "%s%c%s%c%s", lat, _table, lon, _symbol, msg);
|
||||
} else if((msg == NULL) && (time != NULL)) {
|
||||
// timestamp, no message
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_TIME_NO_MSG "%s%s%c%s%c", time, lat, _table, lon, _symbol);
|
||||
if(msg != NULL) {
|
||||
if(time != NULL) {
|
||||
// timestamp and message
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_TIME_MSG "%s%s%c%s%c%s", time, lat, table, lon, symbol, msg);
|
||||
} else {
|
||||
// message, no timestamp
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_NO_TIME_MSG "%s%c%s%c%s", lat, table, lon, symbol, msg);
|
||||
}
|
||||
|
||||
} else {
|
||||
// timestamp and message
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_TIME_MSG "%s%s%c%s%c%s", time, lat, _table, lon, _symbol, msg);
|
||||
if(time != NULL) {
|
||||
// timestamp, no message
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_TIME_NO_MSG "%s%s%c%s%c", time, lat, table, lon, symbol);
|
||||
} else {
|
||||
// no message, no timestamp
|
||||
sprintf(info, RADIOLIB_APRS_DATA_TYPE_POSITION_NO_TIME_NO_MSG "%s%c%s%c", lat, table, lon, symbol);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// send the frame
|
||||
info[len] = '\0';
|
||||
RADIOLIB_DEBUG_PROTOCOL_PRINTLN("APRS Info: %s, length = %d", info, (int)len);
|
||||
int16_t state = sendFrame(destCallsign, destSSID, info);
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] info;
|
||||
#endif
|
||||
return(state);
|
||||
@@ -71,7 +101,7 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
|
||||
// prepare buffers
|
||||
char destCallsign[7];
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
size_t infoLen = 10;
|
||||
if(telemLen > 0) {
|
||||
infoLen += 1 + telemLen;
|
||||
@@ -96,7 +126,7 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
// as discussed in https://github.com/jgromes/RadioLib/issues/430
|
||||
|
||||
// latitude first, because that is in the destination field
|
||||
float lat_abs = abs(lat);
|
||||
float lat_abs = RADIOLIB_ABS(lat);
|
||||
int lat_deg = (int)lat_abs;
|
||||
int lat_min = (lat_abs - (float)lat_deg) * 60.0f;
|
||||
int lat_hun = (((lat_abs - (float)lat_deg) * 60.0f) - lat_min) * 100.0f;
|
||||
@@ -129,7 +159,7 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
info[infoPos++] = RADIOLIB_APRS_MIC_E_GPS_DATA_CURRENT;
|
||||
|
||||
// encode the longtitude
|
||||
float lon_abs = abs(lon);
|
||||
float lon_abs = RADIOLIB_ABS(lon);
|
||||
int32_t lon_deg = (int32_t)lon_abs;
|
||||
int32_t lon_min = (lon_abs - (float)lon_deg) * 60.0f;
|
||||
int32_t lon_hun = (((lon_abs - (float)lon_deg) * 60.0f) - lon_min) * 100.0f;
|
||||
@@ -166,8 +196,8 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
|
||||
info[infoPos++] = speed_uni*10 + head_hun + 32;
|
||||
info[infoPos++] = head_ten_uni + 28;
|
||||
info[infoPos++] = _symbol;
|
||||
info[infoPos++] = _table;
|
||||
info[infoPos++] = symbol;
|
||||
info[infoPos++] = table;
|
||||
|
||||
// onto the optional stuff - check telemetry first
|
||||
if(telemLen > 0) {
|
||||
@@ -207,21 +237,43 @@ int16_t APRSClient::sendMicE(float lat, float lon, uint16_t heading, uint16_t sp
|
||||
info[infoPos++] = '\0';
|
||||
|
||||
// send the frame
|
||||
int16_t state = sendFrame(destCallsign, 0, info);
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
uint8_t destSSID = 0;
|
||||
if(this->phyLayer != nullptr) {
|
||||
// TODO make SSID configurable?
|
||||
destSSID = 1;
|
||||
}
|
||||
int16_t state = sendFrame(destCallsign, destSSID, info);
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] info;
|
||||
#endif
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t APRSClient::sendFrame(char* destCallsign, uint8_t destSSID, char* info) {
|
||||
// get AX.25 callsign
|
||||
char srcCallsign[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1];
|
||||
_ax->getCallsign(srcCallsign);
|
||||
// encoding depends on whether AX.25 should be used or not
|
||||
if(this->axClient != nullptr) {
|
||||
// AX.25/classical mode, get AX.25 callsign
|
||||
char srcCallsign[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1];
|
||||
axClient->getCallsign(srcCallsign);
|
||||
|
||||
AX25Frame frameUI(destCallsign, destSSID, srcCallsign, _ax->getSSID(), RADIOLIB_AX25_CONTROL_U_UNNUMBERED_INFORMATION |
|
||||
RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED | RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME,
|
||||
RADIOLIB_AX25_PID_NO_LAYER_3, (const char*)info);
|
||||
AX25Frame frameUI(destCallsign, destSSID, srcCallsign, axClient->getSSID(),
|
||||
RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME,
|
||||
RADIOLIB_AX25_PID_NO_LAYER_3, const_cast<char*>(info));
|
||||
|
||||
return(_ax->sendFrame(&frameUI));
|
||||
return(axClient->sendFrame(&frameUI));
|
||||
|
||||
} else if(this->phyLayer != nullptr) {
|
||||
// non-AX.25/LoRa mode
|
||||
size_t len = RADIOLIB_APRS_LORA_HEADER_LEN + strlen(this->src) + 4 + strlen(destCallsign) + 11 + strlen(info);
|
||||
char* buff = new char[len];
|
||||
snprintf(buff, len, RADIOLIB_APRS_LORA_HEADER "%s-%d>%s,WIDE%d-%d:%s", this->src, this->id, destCallsign, destSSID, destSSID, info);
|
||||
|
||||
int16_t res = this->phyLayer->transmit(reinterpret_cast<uint8_t*>(buff), strlen(buff));
|
||||
delete[] buff;
|
||||
return(res);
|
||||
}
|
||||
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#if !defined(_RADIOLIB_RADIOLIB_APRS_H)
|
||||
#define _RADIOLIB_RADIOLIB_APRS_H
|
||||
#if !defined(_RADIOLIB_APRS_H)
|
||||
#define _RADIOLIB_APRS_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_APRS)
|
||||
#if !RADIOLIB_EXCLUDE_APRS
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AX25/AX25.h"
|
||||
@@ -29,17 +29,33 @@
|
||||
|
||||
/*!
|
||||
\defgroup mic_e_message_types Mic-E message types.
|
||||
|
||||
\{
|
||||
*/
|
||||
|
||||
/*! \brief Mic-E "Off duty" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_OFF_DUTY 0b00000111
|
||||
|
||||
/*! \brief Mic-E "En route" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_EN_ROUTE 0b00000110
|
||||
|
||||
/*! \brief Mic-E "In service" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_IN_SERVICE 0b00000101
|
||||
|
||||
/*! \brief Mic-E "Returning" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_RETURNING 0b00000100
|
||||
|
||||
/*! \brief Mic-E "Commited" message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_COMMITTED 0b00000011
|
||||
|
||||
/*! \brief Mic-E special message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_SPECIAL 0b00000010
|
||||
|
||||
/*! \brief Mic-E priority message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_PRIORITY 0b00000001
|
||||
|
||||
/*! \brief Mic-E emergency message. */
|
||||
#define RADIOLIB_APRS_MIC_E_TYPE_EMERGENCY 0b00000000
|
||||
|
||||
/*!
|
||||
\}
|
||||
*/
|
||||
@@ -58,98 +74,89 @@
|
||||
// alias for unused altitude in Mic-E
|
||||
#define RADIOLIB_APRS_MIC_E_ALTITUDE_UNUSED -1000000
|
||||
|
||||
// special header applied for APRS over LoRa
|
||||
#define RADIOLIB_APRS_LORA_HEADER "<\xff\x01"
|
||||
#define RADIOLIB_APRS_LORA_HEADER_LEN (3)
|
||||
|
||||
/*!
|
||||
\class APRSClient
|
||||
|
||||
\brief Client for APRS communication.
|
||||
*/
|
||||
class APRSClient {
|
||||
public:
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\brief Constructor for "classic" mode using AX.25/AFSK.
|
||||
\param ax Pointer to the instance of AX25Client to be used for APRS.
|
||||
*/
|
||||
explicit APRSClient(AX25Client* ax);
|
||||
|
||||
/*!
|
||||
\brief Constructor for LoRa mode.
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit APRSClient(PhysicalLayer* phy);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\param symbol APRS symbol to be displayed.
|
||||
|
||||
\param sym APRS symbol to be displayed.
|
||||
\param callsign Source callsign. Required and only used for APRS over LoRa, ignored in classic mode.
|
||||
\param ssid Source SSID. Only used for APRS over LoRa, ignored in classic mode, defaults to 0.
|
||||
\param alt Whether to use the primary (false) or alternate (true) symbol table. Defaults to primary table.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(char symbol, bool alt = false);
|
||||
int16_t begin(char sym, char* callsign = NULL, uint8_t ssid = 0, bool alt = false);
|
||||
|
||||
/*!
|
||||
\brief Transmit position.
|
||||
|
||||
\param destCallsign Destination station callsign.
|
||||
|
||||
\param destSSID Destination station SSID.
|
||||
|
||||
\param lat Latitude as a null-terminated string.
|
||||
|
||||
\param long Longitude as a null-terminated string.
|
||||
|
||||
\param lon Longitude as a null-terminated string.
|
||||
\param msg Message to be transmitted. Defaults to NULL (no message).
|
||||
|
||||
\param msg Position timestamp. Defaults to NULL (no timestamp).
|
||||
|
||||
\param time Position timestamp. Defaults to NULL (no timestamp).
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sendPosition(char* destCallsign, uint8_t destSSID, char* lat, char* lon, char* msg = NULL, char* time = NULL);
|
||||
|
||||
/*
|
||||
/*!
|
||||
\brief Transmit position using Mic-E encoding.
|
||||
|
||||
\param lat Geographical latitude, positive for north, negative for south.
|
||||
|
||||
\param lon Geographical longitude, positive for east, negative for west.
|
||||
|
||||
\param heading Heading in degrees.
|
||||
|
||||
\param speed Speed in knots.
|
||||
|
||||
\param type Mic-E message type - see \ref mic_e_message_types.
|
||||
|
||||
\param telem Pointer to telemetry array (either 2 or 5 bytes long). NULL when telemetry is not used.
|
||||
|
||||
\param telemLen Telemetry length, 2 or 5. 0 when telemetry is not used.
|
||||
|
||||
\param grid Maidenhead grid locator. NULL when not used.
|
||||
|
||||
\param status Status message to send. NULL when not used.
|
||||
|
||||
\param alt Altitude to send. RADIOLIB_APRS_MIC_E_ALTITUDE_UNUSED when not used.
|
||||
*/
|
||||
int16_t sendMicE(float lat, float lon, uint16_t heading, uint16_t speed, uint8_t type, uint8_t* telem = NULL, size_t telemLen = 0, char* grid = NULL, char* status = NULL, int32_t alt = RADIOLIB_APRS_MIC_E_ALTITUDE_UNUSED);
|
||||
|
||||
/*!
|
||||
\brief Transmit generic APRS frame.
|
||||
|
||||
\param destCallsign Destination station callsign.
|
||||
|
||||
\param destSSID Destination station SSID.
|
||||
|
||||
\param info AX.25 info field contents.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sendFrame(char* destCallsign, uint8_t destSSID, char* info);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
AX25Client* _ax;
|
||||
AX25Client* axClient;
|
||||
PhysicalLayer* phyLayer;
|
||||
|
||||
// default APRS symbol (car)
|
||||
char _symbol = '>';
|
||||
char _table = '/';
|
||||
char symbol = '>';
|
||||
char table = '/';
|
||||
|
||||
// source callsign when using APRS over LoRa
|
||||
char src[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1] = { 0 };
|
||||
uint8_t id = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "AX25.h"
|
||||
#if !defined(RADIOLIB_EXCLUDE_AX25)
|
||||
#include <string.h>
|
||||
#if !RADIOLIB_EXCLUDE_AX25
|
||||
|
||||
AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control)
|
||||
: AX25Frame(destCallsign, destSSID, srcCallsign, srcSSID, control, 0, NULL, 0) {
|
||||
@@ -7,7 +8,7 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src
|
||||
}
|
||||
|
||||
AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control, uint8_t protocolID, const char* info)
|
||||
: AX25Frame(destCallsign, destSSID, srcCallsign, srcSSID, control, protocolID, (uint8_t*)info, strlen(info)) {
|
||||
: AX25Frame(destCallsign, destSSID, srcCallsign, srcSSID, control, protocolID, reinterpret_cast<uint8_t*>(const_cast<char*>(info)), strlen(info)) {
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +25,7 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src
|
||||
|
||||
// set repeaters
|
||||
this->numRepeaters = 0;
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->repeaterCallsigns = NULL;
|
||||
this->repeaterSSIDs = NULL;
|
||||
#endif
|
||||
@@ -42,19 +43,52 @@ AX25Frame::AX25Frame(const char* destCallsign, uint8_t destSSID, const char* src
|
||||
// info field
|
||||
this->infoLen = infoLen;
|
||||
if(infoLen > 0) {
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->info = new uint8_t[infoLen];
|
||||
#endif
|
||||
memcpy(this->info, info, infoLen);
|
||||
}
|
||||
}
|
||||
|
||||
AX25Frame::AX25Frame(const AX25Frame& frame) {
|
||||
*this = frame;
|
||||
AX25Frame::AX25Frame(const AX25Frame& frame)
|
||||
: destSSID(frame.destSSID),
|
||||
srcSSID(frame.srcSSID),
|
||||
numRepeaters(frame.numRepeaters),
|
||||
control(frame.control),
|
||||
protocolID(frame.protocolID),
|
||||
infoLen(frame.infoLen),
|
||||
rcvSeqNumber(frame.rcvSeqNumber),
|
||||
sendSeqNumber(frame.sendSeqNumber) {
|
||||
strncpy(this->destCallsign, frame.destCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
strncpy(this->srcCallsign, frame.srcCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
|
||||
if(frame.infoLen) {
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->info = new uint8_t[frame.infoLen];
|
||||
#endif
|
||||
memcpy(this->info, frame.info, frame.infoLen);
|
||||
}
|
||||
|
||||
if(frame.numRepeaters) {
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->repeaterCallsigns = new char*[frame.numRepeaters];
|
||||
for(uint8_t i = 0; i < frame.numRepeaters; i++) {
|
||||
this->repeaterCallsigns[i] = new char[strlen(frame.repeaterCallsigns[i]) + 1];
|
||||
}
|
||||
this->repeaterSSIDs = new uint8_t[frame.numRepeaters];
|
||||
#endif
|
||||
|
||||
this->numRepeaters = frame.numRepeaters;
|
||||
for(uint8_t i = 0; i < frame.numRepeaters; i++) {
|
||||
memcpy(this->repeaterCallsigns[i], frame.repeaterCallsigns[i], strlen(frame.repeaterCallsigns[i]));
|
||||
this->repeaterCallsigns[i][strlen(frame.repeaterCallsigns[i])] = '\0';
|
||||
}
|
||||
memcpy(this->repeaterSSIDs, frame.repeaterSSIDs, frame.numRepeaters);
|
||||
}
|
||||
}
|
||||
|
||||
AX25Frame::~AX25Frame() {
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
// deallocate info field
|
||||
if(infoLen > 0) {
|
||||
delete[] this->info;
|
||||
@@ -123,7 +157,7 @@ int16_t AX25Frame::setRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs
|
||||
}
|
||||
|
||||
// create buffers
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
this->repeaterCallsigns = new char*[numRepeaters];
|
||||
for(uint8_t i = 0; i < numRepeaters; i++) {
|
||||
this->repeaterCallsigns[i] = new char[strlen(repeaterCallsigns[i]) + 1];
|
||||
@@ -151,30 +185,65 @@ void AX25Frame::setSendSequence(uint8_t seqNumber) {
|
||||
}
|
||||
|
||||
AX25Client::AX25Client(PhysicalLayer* phy) {
|
||||
_phy = phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
_audio = nullptr;
|
||||
phyLayer = phy;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
audio = nullptr;
|
||||
bellModem = nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
AX25Client::AX25Client(AFSKClient* audio) {
|
||||
_phy = audio->_phy;
|
||||
_audio = audio;
|
||||
_afskMark = RADIOLIB_AX25_AFSK_MARK;
|
||||
_afskSpace = RADIOLIB_AX25_AFSK_SPACE;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
AX25Client::AX25Client(AFSKClient* aud)
|
||||
: audio(aud) {
|
||||
phyLayer = this->audio->phyLayer;
|
||||
bellModem = new BellClient(this->audio);
|
||||
bellModem->setModem(Bell202);
|
||||
}
|
||||
|
||||
int16_t AX25Client::setCorrection(int16_t mark, int16_t space) {
|
||||
_afskMark = RADIOLIB_AX25_AFSK_MARK + mark;
|
||||
_afskSpace = RADIOLIB_AX25_AFSK_SPACE + space;
|
||||
AX25Client::AX25Client(const AX25Client& ax25)
|
||||
: phyLayer(ax25.phyLayer),
|
||||
sourceSSID(ax25.sourceSSID),
|
||||
preambleLen(ax25.preambleLen) {
|
||||
strncpy(sourceCallsign, ax25.sourceCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(ax25.bellModem) {
|
||||
this->audio = ax25.audio;
|
||||
this->bellModem = new BellClient(ax25.audio);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
AX25Client& AX25Client::operator=(const AX25Client& ax25) {
|
||||
if(&ax25 != this) {
|
||||
this->phyLayer = ax25.phyLayer;
|
||||
this->sourceSSID = ax25.sourceSSID;
|
||||
this->preambleLen = ax25.preambleLen;
|
||||
strncpy(sourceCallsign, ax25.sourceCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(ax25.bellModem) {
|
||||
this->audio = ax25.audio;
|
||||
this->bellModem = new BellClient(ax25.audio);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return(*this);
|
||||
}
|
||||
|
||||
int16_t AX25Client::setCorrection(int16_t mark, int16_t space, float length) {
|
||||
BellModem_t modem;
|
||||
modem.freqMark = Bell202.freqMark + mark;
|
||||
modem.freqSpace = Bell202.freqSpace + space;
|
||||
modem.freqMarkReply = modem.freqMark;
|
||||
modem.freqSpaceReply = modem.freqSpace;
|
||||
modem.baudRate = length*(float)Bell202.baudRate;
|
||||
bellModem->setModem(modem);
|
||||
return(RADIOLIB_ERR_NONE);
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t preambleLen) {
|
||||
int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t preLen) {
|
||||
// set source SSID
|
||||
_srcSSID = srcSSID;
|
||||
sourceSSID = srcSSID;
|
||||
|
||||
// check source callsign length (6 characters max)
|
||||
if(strlen(srcCallsign) > RADIOLIB_AX25_MAX_CALLSIGN_LEN) {
|
||||
@@ -182,22 +251,30 @@ int16_t AX25Client::begin(const char* srcCallsign, uint8_t srcSSID, uint8_t prea
|
||||
}
|
||||
|
||||
// copy callsign
|
||||
memcpy(_srcCallsign, srcCallsign, strlen(srcCallsign));
|
||||
_srcCallsign[strlen(srcCallsign)] = '\0';
|
||||
memcpy(sourceCallsign, srcCallsign, strlen(srcCallsign));
|
||||
sourceCallsign[strlen(srcCallsign)] = '\0';
|
||||
|
||||
// save preamble length
|
||||
_preambleLen = preambleLen;
|
||||
preambleLen = preLen;
|
||||
|
||||
// configure for direct mode
|
||||
return(_phy->startDirect());
|
||||
return(phyLayer->startDirect());
|
||||
}
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
int16_t AX25Client::transmit(String& str, const char* destCallsign, uint8_t destSSID) {
|
||||
return(transmit(str.c_str(), destCallsign, destSSID));
|
||||
}
|
||||
#endif
|
||||
|
||||
int16_t AX25Client::transmit(const char* str, const char* destCallsign, uint8_t destSSID) {
|
||||
// create control field
|
||||
uint8_t controlField = RADIOLIB_AX25_CONTROL_U_UNNUMBERED_INFORMATION | RADIOLIB_AX25_CONTROL_POLL_FINAL_DISABLED | RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME;
|
||||
uint8_t controlField = RADIOLIB_AX25_CONTROL_UNNUMBERED_FRAME;
|
||||
|
||||
// build the frame
|
||||
AX25Frame frame(destCallsign, destSSID, _srcCallsign, _srcSSID, controlField, RADIOLIB_AX25_PID_NO_LAYER_3, (uint8_t*)str, strlen(str));
|
||||
AX25Frame frame(destCallsign, destSSID, sourceCallsign, sourceSSID, controlField,
|
||||
RADIOLIB_AX25_PID_NO_LAYER_3,
|
||||
reinterpret_cast<uint8_t*>(const_cast<char*>(str)), strlen(str));
|
||||
|
||||
// send Unnumbered Information frame
|
||||
return(sendFrame(&frame));
|
||||
@@ -210,7 +287,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
}
|
||||
|
||||
// check repeater configuration
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
if(!(((frame->repeaterCallsigns == NULL) && (frame->repeaterSSIDs == NULL) && (frame->numRepeaters == 0)) ||
|
||||
((frame->repeaterCallsigns != NULL) && (frame->repeaterSSIDs != NULL) && (frame->numRepeaters != 0)))) {
|
||||
return(RADIOLIB_ERR_INVALID_NUM_REPEATERS);
|
||||
@@ -225,7 +302,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
// calculate frame length without FCS (destination address, source address, repeater addresses, control, PID, info)
|
||||
size_t frameBuffLen = ((2 + frame->numRepeaters)*(RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1)) + 1 + 1 + frame->infoLen;
|
||||
// create frame buffer without preamble, start or stop flags
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
uint8_t* frameBuff = new uint8_t[frameBuffLen + 2];
|
||||
#else
|
||||
uint8_t frameBuff[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
@@ -292,27 +369,33 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
|
||||
// flip bit order
|
||||
for(size_t i = 0; i < frameBuffLen; i++) {
|
||||
frameBuff[i] = Module::flipBits(frameBuff[i]);
|
||||
frameBuff[i] = Module::reflect(frameBuff[i], 8);
|
||||
}
|
||||
|
||||
// calculate FCS
|
||||
uint16_t fcs = getFrameCheckSequence(frameBuff, frameBuffLen);
|
||||
// calculate
|
||||
RadioLibCRCInstance.size = 16;
|
||||
RadioLibCRCInstance.poly = RADIOLIB_CRC_CCITT_POLY;
|
||||
RadioLibCRCInstance.init = RADIOLIB_CRC_CCITT_INIT;
|
||||
RadioLibCRCInstance.out = RADIOLIB_CRC_CCITT_OUT;
|
||||
RadioLibCRCInstance.refIn = false;
|
||||
RadioLibCRCInstance.refOut = false;
|
||||
uint16_t fcs = RadioLibCRCInstance.checksum(frameBuff, frameBuffLen);
|
||||
*(frameBuffPtr++) = (uint8_t)((fcs >> 8) & 0xFF);
|
||||
*(frameBuffPtr++) = (uint8_t)(fcs & 0xFF);
|
||||
|
||||
// prepare buffer for the final frame (stuffed, with added preamble + flags and NRZI-encoded)
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
// worst-case scenario: sequence of 1s, will have 120% of the original length, stuffed frame also includes both flags
|
||||
uint8_t* stuffedFrameBuff = new uint8_t[_preambleLen + 1 + (6*frameBuffLen)/5 + 2];
|
||||
uint8_t* stuffedFrameBuff = new uint8_t[preambleLen + 1 + (6*frameBuffLen)/5 + 2];
|
||||
#else
|
||||
uint8_t stuffedFrameBuff[RADIOLIB_STATIC_ARRAY_SIZE];
|
||||
#endif
|
||||
|
||||
// initialize buffer to all zeros
|
||||
memset(stuffedFrameBuff, 0x00, _preambleLen + 1 + (6*frameBuffLen)/5 + 2);
|
||||
memset(stuffedFrameBuff, 0x00, preambleLen + 1 + (6*frameBuffLen)/5 + 2);
|
||||
|
||||
// stuff bits (skip preamble and both flags)
|
||||
uint16_t stuffedFrameBuffLenBits = 8*(_preambleLen + 1);
|
||||
uint16_t stuffedFrameBuffLenBits = 8*(preambleLen + 1);
|
||||
uint8_t count = 0;
|
||||
for(size_t i = 0; i < frameBuffLen + 2; i++) {
|
||||
for(int8_t shift = 7; shift >= 0; shift--) {
|
||||
@@ -345,12 +428,12 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
}
|
||||
|
||||
// deallocate memory
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] frameBuff;
|
||||
#endif
|
||||
|
||||
// set preamble bytes and start flag field
|
||||
for(uint16_t i = 0; i < _preambleLen + 1; i++) {
|
||||
for(uint16_t i = 0; i < preambleLen + 1; i++) {
|
||||
stuffedFrameBuff[i] = RADIOLIB_AX25_FLAG;
|
||||
}
|
||||
|
||||
@@ -368,7 +451,7 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
}
|
||||
|
||||
// convert to NRZI
|
||||
for(size_t i = _preambleLen + 1; i < stuffedFrameBuffLen*8; i++) {
|
||||
for(size_t i = preambleLen + 1; i < stuffedFrameBuffLen*8; i++) {
|
||||
size_t currBitPos = i + 7 - 2*(i%8);
|
||||
size_t prevBitPos = (i - 1) + 7 - 2*((i - 1)%8);
|
||||
if(TEST_BIT_IN_ARRAY(stuffedFrameBuff, currBitPos)) {
|
||||
@@ -391,40 +474,26 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
|
||||
// transmit
|
||||
int16_t state = RADIOLIB_ERR_NONE;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
if(_audio != nullptr) {
|
||||
Module* mod = _phy->getMod();
|
||||
_phy->transmitDirect();
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
if(bellModem != nullptr) {
|
||||
bellModem->idle();
|
||||
|
||||
// iterate over all bytes in the buffer
|
||||
for(uint32_t i = 0; i < stuffedFrameBuffLen; i++) {
|
||||
|
||||
// check each bit
|
||||
for(uint16_t mask = 0x80; mask >= 0x01; mask >>= 1) {
|
||||
uint32_t start = mod->micros();
|
||||
if(stuffedFrameBuff[i] & mask) {
|
||||
_audio->tone(_afskMark, false);
|
||||
} else {
|
||||
_audio->tone(_afskSpace, false);
|
||||
}
|
||||
while(mod->micros() - start < RADIOLIB_AX25_AFSK_TONE_DURATION) {
|
||||
mod->yield();
|
||||
}
|
||||
}
|
||||
|
||||
bellModem->write(stuffedFrameBuff[i]);
|
||||
}
|
||||
|
||||
_audio->noTone();
|
||||
bellModem->standby();
|
||||
|
||||
} else {
|
||||
#endif
|
||||
state = _phy->transmit(stuffedFrameBuff, stuffedFrameBuffLen);
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
state = phyLayer->transmit(stuffedFrameBuff, stuffedFrameBuffLen);
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
}
|
||||
#endif
|
||||
|
||||
// deallocate memory
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
delete[] stuffedFrameBuff;
|
||||
#endif
|
||||
|
||||
@@ -432,34 +501,11 @@ int16_t AX25Client::sendFrame(AX25Frame* frame) {
|
||||
}
|
||||
|
||||
void AX25Client::getCallsign(char* buff) {
|
||||
strncpy(buff, _srcCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN);
|
||||
strncpy(buff, sourceCallsign, RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1);
|
||||
}
|
||||
|
||||
uint8_t AX25Client::getSSID() {
|
||||
return(_srcSSID);
|
||||
}
|
||||
|
||||
/*
|
||||
CCITT CRC implementation based on https://github.com/kicksat/ax25
|
||||
|
||||
Licensed under Creative Commons Attribution-ShareAlike 4.0 International
|
||||
https://creativecommons.org/licenses/by-sa/4.0/
|
||||
*/
|
||||
uint16_t AX25Client::getFrameCheckSequence(uint8_t* buff, size_t len) {
|
||||
uint8_t outBit;
|
||||
uint16_t mask;
|
||||
uint16_t shiftReg = CRC_CCITT_INIT;
|
||||
|
||||
for(size_t i = 0; i < len; i++) {
|
||||
for(uint8_t b = 0x80; b > 0x00; b /= 2) {
|
||||
outBit = (shiftReg & 0x01) ? 0x01 : 0x00;
|
||||
shiftReg >>= 1;
|
||||
mask = XOR((buff[i] & b), outBit) ? CRC_CCITT_POLY_REVERSED : 0x0000;
|
||||
shiftReg ^= mask;
|
||||
}
|
||||
}
|
||||
|
||||
return(Module::flipBits16(~shiftReg));
|
||||
return(sourceSSID);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,29 +1,20 @@
|
||||
#if !defined(_RADIOLIB_RADIOLIB_AX25_H)
|
||||
#define _RADIOLIB_RADIOLIB_AX25_H
|
||||
#if !defined(_RADIOLIB_AX25_H)
|
||||
#define _RADIOLIB_AX25_H
|
||||
|
||||
#include "../../TypeDef.h"
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AX25)
|
||||
#if !RADIOLIB_EXCLUDE_AX25
|
||||
|
||||
#include "../PhysicalLayer/PhysicalLayer.h"
|
||||
#include "../AFSK/AFSK.h"
|
||||
|
||||
// macros to access bits in byte array, from http://www.mathcs.emory.edu/~cheung/Courses/255/Syllabus/1-C-intro/bit-array.html
|
||||
#define SET_BIT_IN_ARRAY(A, k) ( A[(k/8)] |= (1 << (k%8)) )
|
||||
#define CLEAR_BIT_IN_ARRAY(A, k) ( A[(k/8)] &= ~(1 << (k%8)) )
|
||||
#define TEST_BIT_IN_ARRAY(A, k) ( A[(k/8)] & (1 << (k%8)) )
|
||||
#define GET_BIT_IN_ARRAY(A, k) ( (A[(k/8)] & (1 << (k%8))) ? 1 : 0 )
|
||||
|
||||
// CRC-CCITT calculation macros
|
||||
#define XOR(A, B) ( ((A) || (B)) && !((A) && (B)) )
|
||||
#define CRC_CCITT_POLY 0x1021 // generator polynomial
|
||||
#define CRC_CCITT_POLY_REVERSED 0x8408 // CRC_CCITT_POLY in reversed bit order
|
||||
#define CRC_CCITT_INIT 0xFFFF // initial value
|
||||
#include "../BellModem/BellModem.h"
|
||||
#include "../../utils/CRC.h"
|
||||
#include "../../utils/FEC.h"
|
||||
|
||||
// maximum callsign length in bytes
|
||||
#define RADIOLIB_AX25_MAX_CALLSIGN_LEN 6
|
||||
|
||||
// flag field MSB LSB DESCRIPTION
|
||||
// flag field MSB LSB DESCRIPTION
|
||||
#define RADIOLIB_AX25_FLAG 0b01111110 // 7 0 AX.25 frame start/end flag
|
||||
|
||||
// address field
|
||||
@@ -73,16 +64,8 @@
|
||||
#define RADIOLIB_AX25_PID_NO_LAYER_3 0xF0
|
||||
#define RADIOLIB_AX25_PID_ESCAPE_CHARACTER 0xFF
|
||||
|
||||
// AFSK tones in Hz
|
||||
#define RADIOLIB_AX25_AFSK_MARK 1200
|
||||
#define RADIOLIB_AX25_AFSK_SPACE 2200
|
||||
|
||||
// tone duration in us (for 1200 baud AFSK)
|
||||
#define RADIOLIB_AX25_AFSK_TONE_DURATION 833
|
||||
|
||||
/*!
|
||||
\class AX25Frame
|
||||
|
||||
\brief Abstraction of AX.25 frame format.
|
||||
*/
|
||||
class AX25Frame {
|
||||
@@ -137,7 +120,7 @@ class AX25Frame {
|
||||
*/
|
||||
uint16_t sendSeqNumber;
|
||||
|
||||
#if !defined(RADIOLIB_STATIC_ONLY)
|
||||
#if !RADIOLIB_STATIC_ONLY
|
||||
/*!
|
||||
\brief The info field.
|
||||
*/
|
||||
@@ -171,62 +154,41 @@ class AX25Frame {
|
||||
|
||||
/*!
|
||||
\brief Overloaded constructor, for frames without info field.
|
||||
|
||||
\param destCallsign Callsign of the destination station.
|
||||
|
||||
\param destSSID SSID of the destination station.
|
||||
|
||||
\param srcCallsign Callsign of the source station.
|
||||
|
||||
\param srcSSID SSID of the source station.
|
||||
|
||||
\param control The control field.
|
||||
*/
|
||||
AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control);
|
||||
|
||||
/*!
|
||||
\brief Overloaded constructor, for frames with C-string info field.
|
||||
|
||||
\param destCallsign Callsign of the destination station.
|
||||
|
||||
\param destSSID SSID of the destination station.
|
||||
|
||||
\param srcCallsign Callsign of the source station.
|
||||
|
||||
\param srcSSID SSID of the source station.
|
||||
|
||||
\param control The control field.
|
||||
|
||||
\param protocolID The protocol identifier (PID) field. Set to zero if the frame doesn't have this field.
|
||||
|
||||
\param info Information field, in the form of null-terminated C-string.
|
||||
*/
|
||||
AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control, uint8_t protocolID, const char* info);
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param destCallsign Callsign of the destination station.
|
||||
|
||||
\param destSSID SSID of the destination station.
|
||||
|
||||
\param srcCallsign Callsign of the source station.
|
||||
|
||||
\param srcSSID SSID of the source station.
|
||||
|
||||
\param control The control field.
|
||||
|
||||
\param protocolID The protocol identifier (PID) field. Set to zero if the frame doesn't have this field.
|
||||
|
||||
\param info Information field, in the form of arbitrary binary buffer.
|
||||
|
||||
\param infoLen Number of bytes in the information field.
|
||||
*/
|
||||
AX25Frame(const char* destCallsign, uint8_t destSSID, const char* srcCallsign, uint8_t srcSSID, uint8_t control, uint8_t protocolID, uint8_t* info, uint16_t infoLen);
|
||||
|
||||
/*!
|
||||
\brief Copy constructor.
|
||||
|
||||
\param frame AX25Frame instance to copy.
|
||||
*/
|
||||
AX25Frame(const AX25Frame& frame);
|
||||
@@ -238,34 +200,27 @@ class AX25Frame {
|
||||
|
||||
/*!
|
||||
\brief Overload for assignment operator.
|
||||
|
||||
\param frame rvalue AX25Frame.
|
||||
*/
|
||||
AX25Frame& operator=(const AX25Frame& frame);
|
||||
|
||||
/*!
|
||||
\brief Method to set the repeater callsigns and SSIDs.
|
||||
|
||||
\param repeaterCallsigns Array of repeater callsigns in the form of null-terminated C-strings.
|
||||
|
||||
\param repeaterSSIDs Array of repeater SSIDs.
|
||||
|
||||
\param numRepeaters Number of repeaters, maximum is 8.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setRepeaters(char** repeaterCallsigns, uint8_t* repeaterSSIDs, uint8_t numRepeaters);
|
||||
|
||||
/*!
|
||||
\brief Method to set receive sequence number.
|
||||
|
||||
\param seqNumber Sequence number to set, 0 to 7.
|
||||
*/
|
||||
void setRecvSequence(uint8_t seqNumber);
|
||||
|
||||
/*!
|
||||
\brief Method to set send sequence number.
|
||||
|
||||
\param seqNumber Sequence number to set, 0 to 7.
|
||||
*/
|
||||
void setSendSequence(uint8_t seqNumber);
|
||||
@@ -273,92 +228,102 @@ class AX25Frame {
|
||||
|
||||
/*!
|
||||
\class AX25Client
|
||||
|
||||
\brief Client for AX25 communication.
|
||||
*/
|
||||
class AX25Client {
|
||||
public:
|
||||
/*!
|
||||
\brief Constructor for 2-FSK mode.
|
||||
|
||||
\param phy Pointer to the wireless module providing PhysicalLayer communication.
|
||||
*/
|
||||
explicit AX25Client(PhysicalLayer* phy);
|
||||
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
/*!
|
||||
\brief Constructor for AFSK mode.
|
||||
|
||||
\param audio Pointer to the AFSK instance providing audio.
|
||||
\param aud Pointer to the AFSK instance providing audio.
|
||||
*/
|
||||
explicit AX25Client(AFSKClient* audio);
|
||||
explicit AX25Client(AFSKClient* aud);
|
||||
|
||||
/*!
|
||||
\brief Set AFSK tone correction offset. On some platforms, this is required to get the audio produced by the setup to match the expected 1200/2200 Hz tones.
|
||||
\brief Copy constructor.
|
||||
\param ax25 AX25Client instance to copy.
|
||||
*/
|
||||
AX25Client(const AX25Client& ax25);
|
||||
|
||||
/*!
|
||||
\brief Overload for assignment operator.
|
||||
\param ax25 rvalue AX25Client.
|
||||
*/
|
||||
AX25Client& operator=(const AX25Client& ax25);
|
||||
|
||||
/*!
|
||||
\brief Set AFSK tone correction offset. On some platforms, this is required to get the audio produced
|
||||
by the setup to match the expected 1200/2200 Hz tones.
|
||||
\param mark Positive or negative correction offset for mark audio frequency in Hz.
|
||||
|
||||
\param space Positive or negative correction offset for space audio frequency in Hz.
|
||||
|
||||
\param length Audio tone length modifier, defaults to 1.0.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCorrection(int16_t mark, int16_t space);
|
||||
int16_t setCorrection(int16_t mark, int16_t space, float length = 1.0f);
|
||||
#endif
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method.
|
||||
|
||||
\param srcCallsign Callsign of the source station.
|
||||
|
||||
\param srcSSID 4-bit SSID of the source station (in case there are more stations with the same callsign). Defaults to 0.
|
||||
|
||||
\param preambleLen Number of "preamble" bytes (RADIOLIB_AX25_FLAG) sent ahead of the actual AX.25 frame. Does not include the first RADIOLIB_AX25_FLAG byte, which is considered part of the frame. Defaults to 8.
|
||||
|
||||
\param srcSSID 4-bit SSID of the source station (in case there are more stations with the same callsign).
|
||||
Defaults to 0.
|
||||
\param preLen Number of "preamble" bytes (RADIOLIB_AX25_FLAG) sent ahead of the actual AX.25 frame.
|
||||
Does not include the first RADIOLIB_AX25_FLAG byte, which is considered part of the frame. Defaults to 8.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(const char* srcCallsign, uint8_t srcSSID = 0x00, uint8_t preambleLen = 8);
|
||||
int16_t begin(const char* srcCallsign, uint8_t srcSSID = 0x00, uint8_t preLen = 8);
|
||||
|
||||
#if defined(RADIOLIB_BUILD_ARDUINO)
|
||||
/*!
|
||||
\brief Transmit unnumbered information (UI) frame.
|
||||
\param str Data to be sent as Arduino String.
|
||||
\param destCallsign Callsign of the destination station.
|
||||
\param destSSID 4-bit SSID of the destination station (in case there are more stations with the same callsign).
|
||||
Defaults to 0.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(String& str, const char* destCallsign, uint8_t destSSID = 0x00);
|
||||
#endif
|
||||
|
||||
/*!
|
||||
\brief Transmit unnumbered information (UI) frame.
|
||||
|
||||
\param str Data to be sent.
|
||||
|
||||
\param destCallsign Callsign of the destination station.
|
||||
|
||||
\param destSSID 4-bit SSID of the destination station (in case there are more stations with the same callsign). Defaults to 0.
|
||||
|
||||
\param destSSID 4-bit SSID of the destination station (in case there are more stations with the same callsign).
|
||||
Defaults to 0.
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(const char* str, const char* destCallsign, uint8_t destSSID = 0x00);
|
||||
|
||||
/*!
|
||||
\brief Transmit arbitrary AX.25 frame.
|
||||
|
||||
\param frame Frame to be sent.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sendFrame(AX25Frame* frame);
|
||||
|
||||
#if !defined(RADIOLIB_GODMODE)
|
||||
#if !RADIOLIB_GODMODE
|
||||
private:
|
||||
#endif
|
||||
friend class APRSClient;
|
||||
|
||||
PhysicalLayer* _phy;
|
||||
#if !defined(RADIOLIB_EXCLUDE_AFSK)
|
||||
AFSKClient* _audio;
|
||||
uint32_t _afskMark;
|
||||
uint32_t _afskSpace;
|
||||
PhysicalLayer* phyLayer;
|
||||
#if !RADIOLIB_EXCLUDE_AFSK
|
||||
AFSKClient* audio;
|
||||
BellClient* bellModem;
|
||||
#endif
|
||||
|
||||
char _srcCallsign[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1] = {0, 0, 0, 0, 0, 0, 0};
|
||||
uint8_t _srcSSID = 0;
|
||||
uint16_t _preambleLen = 0;
|
||||
|
||||
static uint16_t getFrameCheckSequence(uint8_t* buff, size_t len);
|
||||
char sourceCallsign[RADIOLIB_AX25_MAX_CALLSIGN_LEN + 1] = { 0 };
|
||||
uint8_t sourceSSID = 0;
|
||||
uint16_t preambleLen = 0;
|
||||
|
||||
void getCallsign(char* buff);
|
||||
uint8_t getSSID();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user