2021-09-11 21:35:16 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "RadioLibInterface.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \brief Adapter for SX126x radio family. Implements common logic for child classes.
|
|
|
|
* \tparam T RadioLib module type for SX126x: SX1262, SX1268.
|
|
|
|
*/
|
|
|
|
template<class T>
|
|
|
|
class SX126xInterface : public RadioLibInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SX126xInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi);
|
|
|
|
|
|
|
|
/// Initialise the Driver transport hardware and software.
|
|
|
|
/// Make sure the Driver is properly configured before calling init().
|
|
|
|
/// \return true if initialisation succeeded.
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool init() override;
|
2021-09-11 21:35:16 +00:00
|
|
|
|
|
|
|
/// Apply any radio provisioning changes
|
|
|
|
/// Make sure the Driver is properly configured before calling init().
|
|
|
|
/// \return true if initialisation succeeded.
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool reconfigure() override;
|
2021-09-11 21:35:16 +00:00
|
|
|
|
|
|
|
/// Prepare hardware for sleep. Call this _only_ for deep sleep, not needed for light sleep.
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool sleep() override;
|
2021-09-11 21:35:16 +00:00
|
|
|
|
2022-01-24 17:24:40 +00:00
|
|
|
bool isIRQPending() override { return lora.getIrqStatus() != 0; }
|
2021-09-11 21:35:16 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2021-12-03 03:46:36 +00:00
|
|
|
float currentLimit = 140; // Higher OCP limit for SX126x PA
|
|
|
|
|
2021-09-11 21:35:16 +00:00
|
|
|
/**
|
|
|
|
* Specific module instance
|
|
|
|
*/
|
|
|
|
T lora;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Glue functions called from ISR land
|
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual void disableInterrupt() override;
|
2021-09-11 21:35:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enable a particular ISR callback glue function
|
|
|
|
*/
|
|
|
|
virtual void enableInterrupt(void (*callback)()) { lora.setDio1Action(callback); }
|
|
|
|
|
2022-04-20 18:04:44 +00:00
|
|
|
/** can we detect a LoRa preamble on the current channel? */
|
|
|
|
virtual bool isChannelActive() override;
|
|
|
|
|
2021-09-11 21:35:16 +00:00
|
|
|
/** are we actively receiving a packet (only called during receiving state) */
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool isActivelyReceiving() override;
|
2021-09-11 21:35:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Start waiting to receive a message
|
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual void startReceive() override;
|
2021-09-11 21:35:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* We override to turn on transmitter power as needed.
|
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual void configHardwareForSend() override;
|
2021-09-11 21:35:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add SNR data to received messages
|
|
|
|
*/
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual void addReceiveMetadata(MeshPacket *mp) override;
|
2021-09-11 21:35:16 +00:00
|
|
|
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual void setStandby() override;
|
2021-09-11 21:35:16 +00:00
|
|
|
|
|
|
|
private:
|
2022-01-24 17:24:40 +00:00
|
|
|
};
|