90 lines
2.3 KiB
C++
90 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <Tactility/hal/radio/RadioDevice.h>
|
|
#include <Tactility/hal/spi/Spi.h>
|
|
|
|
#include <RadioLib.h>
|
|
#include "RadiolibTactilityHal.h"
|
|
|
|
#include <utility>
|
|
|
|
class Sx1262 final : public tt::hal::radio::RadioDevice {
|
|
|
|
public:
|
|
struct Configuration {
|
|
spi_host_device_t spiHostDevice;
|
|
int spiFrequency;
|
|
gpio_num_t csPin;
|
|
gpio_num_t resetPin;
|
|
gpio_num_t busyPin;
|
|
gpio_num_t irqPin;
|
|
float tcxoVoltage;
|
|
bool useRegulatorLdo;
|
|
};
|
|
|
|
private:
|
|
static constexpr auto SX1262_DIO1_EVENT_BIT = BIT8;
|
|
|
|
enum class ExchangeState {
|
|
Idle,
|
|
Receive,
|
|
//TransmitInitiated,
|
|
TransmitWaiting
|
|
};
|
|
|
|
std::string name;
|
|
const Configuration configuration;
|
|
std::shared_ptr<tt::Lock> lock;
|
|
RadiolibTactilityHal hal;
|
|
Module radioModule;
|
|
SX1262 radio;
|
|
TxPacket currentTx;
|
|
ExchangeState exchangeState;
|
|
|
|
int8_t power = 0;
|
|
float frequency = 0.0;
|
|
float bandwidth = 0.0;
|
|
uint8_t spreadFactor = 0.0;
|
|
uint8_t codingRate = 0;
|
|
uint8_t syncWord = 0;
|
|
uint16_t preambleLength = 0;
|
|
float bitRate = 0.0;
|
|
float frequencyDeviation = 0.0;
|
|
|
|
int32_t threadMain();
|
|
void registerDio1Isr();
|
|
void unregisterDio1Isr();
|
|
|
|
public:
|
|
|
|
explicit Sx1262(const std::string& name, const Configuration& configuration, std::shared_ptr<tt::Lock> lock = nullptr)
|
|
: RadioDevice(name, 4096)
|
|
, name(name)
|
|
, configuration(configuration)
|
|
, hal(configuration.spiHostDevice, configuration.spiFrequency, configuration.csPin, lock)
|
|
, radioModule(&hal, configuration.csPin, configuration.irqPin, configuration.resetPin, configuration.busyPin)
|
|
, radio(&radioModule)
|
|
, exchangeState(ExchangeState::Idle) {}
|
|
|
|
~Sx1262() override = default;
|
|
|
|
std::string getName() const override { return name; }
|
|
|
|
std::string getDescription() const override { return "SX1262 LoRa and FSK capable radio"; }
|
|
|
|
bool configure(const Parameter parameter, const float value) override;
|
|
|
|
bool isCapableOf(const Modulation modulation) {
|
|
return (modulation == Modulation::Fsk) || (modulation == Modulation::LoRa);
|
|
}
|
|
|
|
bool hasReceived();
|
|
|
|
void dio1Event();
|
|
//void IRAM_ATTR setRxEvent() { rxFlag = true; }
|
|
|
|
protected:
|
|
|
|
int32_t threadMain(const Modulation modulation) override;
|
|
};
|