79 lines
2.0 KiB
C++
79 lines
2.0 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;
|
|
gpio_num_t csPin;
|
|
gpio_num_t resetPin;
|
|
gpio_num_t busyPin;
|
|
gpio_num_t irqPin;
|
|
float tcxoVoltage;
|
|
bool useRegulatorLdo;
|
|
};
|
|
|
|
private:
|
|
|
|
std::string name;
|
|
const Configuration configuration;
|
|
std::shared_ptr<tt::Lock> lock;
|
|
RadiolibTactilityHal hal;
|
|
Module radioModule;
|
|
SX1262 radio;
|
|
IsrTrampolines<Sx1262>::SlotNumber isrTrampolineSlot;
|
|
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)
|
|
: RadioDevice(name, 1024)
|
|
, name(name)
|
|
, configuration(configuration)
|
|
, hal(configuration.spiHostDevice, configuration.csPin)
|
|
, radioModule(&hal, configuration.csPin, configuration.irqPin, configuration.resetPin, configuration.busyPin)
|
|
, radio(&radioModule) {
|
|
registerDio1Isr();
|
|
}
|
|
|
|
~Sx1262() override {
|
|
unregisterDio1Isr();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
void IRAM_ATTR setRxEvent() { getEventFlag().set(RADIO_RECEIVED_BIT); }
|
|
|
|
protected:
|
|
|
|
int32_t threadMain(const Modulation modulation) override;
|
|
};
|