Radio: Some minor corrections and tweaks
This commit is contained in:
parent
933ce93fb1
commit
2a55eb34ab
@ -23,7 +23,7 @@ static DeviceVector createDevices() {
|
||||
auto tca8418 = std::make_shared<Tca8418>(I2C_NUM_0);
|
||||
auto keyboard = std::make_shared<TpagerKeyboard>(tca8418);
|
||||
|
||||
auto sx1262 = std::make_shared<Sx1262>("SX1262", Sx1262::Configuration{
|
||||
auto sx1262 = std::make_shared<Sx1262>(Sx1262::Configuration{
|
||||
.spiHostDevice = SPI2_HOST,
|
||||
.spiFrequency = 10'000'000,
|
||||
.csPin = GPIO_NUM_36,
|
||||
|
||||
@ -54,11 +54,16 @@ void RadiolibTactilityHal::attachInterrupt(uint32_t interruptNum, void (*interru
|
||||
return;
|
||||
}
|
||||
|
||||
gpio_install_isr_service((int)ESP_INTR_FLAG_IRAM);
|
||||
if (!isrServiceInitialized) {
|
||||
gpio_install_isr_service((int)ESP_INTR_FLAG_IRAM);
|
||||
isrServiceInitialized = true;
|
||||
}
|
||||
gpio_set_intr_type((gpio_num_t)interruptNum, (gpio_int_type_t)(mode & 0x7));
|
||||
|
||||
// this uses function typecasting, which is not defined when the functions have different signatures
|
||||
// untested and might not work
|
||||
// TODO: I think the wisest course of action is forbidding registration via RadioLib entirely,
|
||||
// as it doesn't suit Tactility with its lack of context passing
|
||||
gpio_isr_handler_add((gpio_num_t)interruptNum, (void (*)(void*))interruptCb, NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -21,9 +21,10 @@ private:
|
||||
spi_device_handle_t spiDeviceHandle;
|
||||
std::shared_ptr<tt::Lock> lock;
|
||||
bool spiInitialized;
|
||||
bool isrServiceInitialized;
|
||||
|
||||
public:
|
||||
explicit RadiolibTactilityHal(spi_host_device_t spiHostDevice, int spiFrequency, gpio_num_t csPin, std::shared_ptr<tt::Lock> spiLock)
|
||||
explicit RadiolibTactilityHal(spi_host_device_t spiHostDevice, int spiFrequency, gpio_num_t csPin)
|
||||
: RadioLibHal(
|
||||
GPIO_MODE_INPUT,
|
||||
GPIO_MODE_OUTPUT,
|
||||
@ -34,10 +35,9 @@ public:
|
||||
, spiHostDevice(spiHostDevice)
|
||||
, spiFrequency(spiFrequency)
|
||||
, csPin(csPin)
|
||||
, lock(spiLock)
|
||||
, spiInitialized(false) {
|
||||
if (!lock) lock = tt::hal::spi::getLock(spiHostDevice);
|
||||
}
|
||||
, lock(tt::hal::spi::getLock(spiHostDevice))
|
||||
, spiInitialized(false)
|
||||
, isrServiceInitialized(false) {}
|
||||
|
||||
void init() override;
|
||||
void term() override;
|
||||
|
||||
@ -245,7 +245,7 @@ tt::hal::radio::Unit Sx1262::getParameterUnit(const Parameter parameter) const {
|
||||
case Power:
|
||||
return Unit(Unit::Name::DecibelMilliwatts);
|
||||
case Frequency:
|
||||
return Unit(Unit::Prefix::Kilo, Unit::Name::Herz);
|
||||
return Unit(Unit::Prefix::Mega, Unit::Name::Herz);
|
||||
case Bandwidth:
|
||||
return Unit(Unit::Prefix::Kilo, Unit::Name::Herz);
|
||||
case SpreadFactor:
|
||||
@ -369,11 +369,18 @@ void Sx1262::doTransmit() {
|
||||
TT_LOG_W(TAG, "RadioLib returned %hi on standby", rc);
|
||||
}
|
||||
|
||||
rc = radio.startTransmit(currentTx.packet.data.data(), currentTx.packet.data.size());
|
||||
if (getModulation() == Modulation::Fsk) {
|
||||
rc = radio.startTransmit(currentTx.packet.data.data(), currentTx.packet.data.size(),
|
||||
currentTx.packet.address);
|
||||
} else {
|
||||
rc = radio.startTransmit(currentTx.packet.data.data(), currentTx.packet.data.size());
|
||||
}
|
||||
|
||||
if (rc == RADIOLIB_ERR_NONE) {
|
||||
currentTx.callback(currentTx.id, TransmissionState::PendingTransmit);
|
||||
|
||||
auto txEventFlags = events.wait(SX1262_INTERRUPT_BIT | SX1262_DIO1_EVENT_BIT, tt::EventFlag::WaitAny, pdMS_TO_TICKS(2000));
|
||||
auto txEventFlags = events.wait(SX1262_INTERRUPT_BIT | SX1262_DIO1_EVENT_BIT, tt::EventFlag::WaitAny,
|
||||
pdMS_TO_TICKS(SX1262_TX_TIMEOUT_MILLIS));
|
||||
|
||||
// Thread might've been interrupted in the meanwhile
|
||||
if (isThreadInterrupted()) {
|
||||
|
||||
@ -25,7 +25,9 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
static constexpr auto SX1262_DEFAULT_NAME = "SX1262";
|
||||
static constexpr auto SX1262_COOLDOWN_MILLIS = 100;
|
||||
static constexpr auto SX1262_TX_TIMEOUT_MILLIS = 2000;
|
||||
static constexpr auto SX1262_INTERRUPT_BIT = BIT0;
|
||||
static constexpr auto SX1262_DIO1_EVENT_BIT = BIT1;
|
||||
static constexpr auto SX1262_QUEUED_TX_BIT = BIT2;
|
||||
@ -73,11 +75,11 @@ protected:
|
||||
|
||||
public:
|
||||
|
||||
explicit Sx1262(const std::string& name, const Configuration& configuration, std::shared_ptr<tt::Lock> lock = nullptr)
|
||||
explicit Sx1262(const Configuration& configuration, const std::string& name = SX1262_DEFAULT_NAME)
|
||||
: RadiolibThreadedDevice(name, 4096)
|
||||
, name(name)
|
||||
, configuration(configuration)
|
||||
, hal(configuration.spiHostDevice, configuration.spiFrequency, configuration.csPin, lock)
|
||||
, hal(configuration.spiHostDevice, configuration.spiFrequency, configuration.csPin)
|
||||
, radioModule(&hal, configuration.csPin, configuration.irqPin, configuration.resetPin, configuration.busyPin)
|
||||
, radio(&radioModule)
|
||||
{}
|
||||
@ -85,7 +87,6 @@ public:
|
||||
~Sx1262() override = default;
|
||||
|
||||
std::string getName() const override { return name; }
|
||||
|
||||
std::string getDescription() const override { return "Semtech SX1262 LoRa, FSK and LR-FHSS capable radio"; }
|
||||
|
||||
ParameterStatus setParameter(const Parameter parameter, const float value) override;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user