Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions src/helpers/radiolib/CustomLR1121.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#pragma once

#include <RadioLib.h>


#ifndef LR11X0_DIO3_TCXO_VOLTAGE
#define LR11X0_DIO3_TCXO_VOLTAGE 3.0
#endif

#ifndef LORA_CR
#define LORA_CR 5
#endif

class CustomLR1121 : public LR1121 {
private:
bool _rx_boosted = false;

public:
CustomLR1121(Module* mod) : LR1121(mod) {}

#ifdef RP2040_PLATFORM
bool std_init(SPIClassRP2040* spi = NULL)
#else
bool std_init(SPIClass* spi = NULL)
#endif
{
float tcxo = LR11X0_DIO3_TCXO_VOLTAGE;
uint8_t cr = LORA_CR;

#if defined(P_LORA_SCLK)
#ifdef NRF52_PLATFORM
if (spi) { spi->setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); spi->begin(); }
#elif defined(RP2040_PLATFORM)
if (spi) {
spi->setMISO(P_LORA_MISO);
//spi->setCS(P_LORA_NSS); // Setting CS results in freeze
spi->setSCK(P_LORA_SCLK);
spi->setMOSI(P_LORA_MOSI);
spi->begin();
}
#else
if (spi) spi->begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
#endif
#endif
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, 10, 16, tcxo);
if (status != RADIOLIB_ERR_NONE) {
Serial.print("ERROR: radio init failed: ");
Serial.println(status);
return false; // fail
}

// Waveshare Core1121 (LR1121-HF) RFSwitch Table
static const uint32_t rfswitch_dio_pins[] = {
RADIOLIB_LR11X0_DIO5,
RADIOLIB_LR11X0_DIO6,
RADIOLIB_NC, // DIO7 NC
RADIOLIB_NC, // DIO8 NC
RADIOLIB_NC // DIO9 NC
};

static const Module::RfSwitchMode_t rfswitch_table[] = {
{ LR11x0::MODE_STBY, { LOW, LOW } },
{ LR11x0::MODE_RX, { HIGH, LOW } },
{ LR11x0::MODE_TX, { LOW, HIGH } },
{ LR11x0::MODE_TX_HP, { LOW, HIGH } },
{ LR11x0::MODE_TX_HF, { LOW, LOW } },
{ LR11x0::MODE_GNSS, { LOW, LOW } },
{ LR11x0::MODE_WIFI, { LOW, LOW } },
END_OF_MODE_TABLE
};

setRfSwitchTable(rfswitch_dio_pins, rfswitch_table);

setCRC(2);
explicitHeader();

return true; // success
}

size_t getPacketLength(bool update) override {
size_t len = LR1121::getPacketLength(update);
if (len == 0 && getIrqStatus() & RADIOLIB_LR11X0_IRQ_HEADER_ERR) {
// we've just received a corrupted packet
// this may have triggered a bug causing subsequent packets to be shifted
// call standby() to return radio to known-good state
// recvRaw will call startReceive() to restart rx
MESH_DEBUG_PRINTLN("LR1121: got header err, calling standby()");
standby();
}
return len;
}

bool isReceiving() {
uint16_t irq = getIrqFlags();
bool detected = (irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID) || (irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED);
return detected;
}

int16_t setRxBoostedGainMode(bool en) {
_rx_boosted = en;
return LR1121::setRxBoostedGainMode(en);
}

bool getRxBoostedGainMode() const {
return _rx_boosted;
}

int16_t getSpreadingFactor() const {
return spreadingFactor;
}

float getFreqMHz() const { return freqMHz; }
};
63 changes: 63 additions & 0 deletions src/helpers/radiolib/CustomLR1121Wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once

#include "RadioLibWrappers.h"
#include "CustomLR1121.h"
#include "LR11x0Reset.h"

#ifndef USE_LR1121
#define USE_LR1121
#endif

class CustomLR1121Wrapper : public RadioLibWrapper {
public:
CustomLR1121Wrapper(CustomLR1121& radio, mesh::MainBoard& board) : RadioLibWrapper(radio, board) {}

void setParams(float freq, float bw, uint8_t sf, uint8_t cr) override {
((CustomLR1121*)_radio)->setFrequency(freq);
((CustomLR1121*)_radio)->setSpreadingFactor(sf);
((CustomLR1121*)_radio)->setBandwidth(bw);
((CustomLR1121*)_radio)->setCodingRate(cr);
updatePreamble(sf);
}

void doResetAGC() override {
lr11x0ResetAGC((LR11x0*)_radio, ((CustomLR1121*)_radio)->getFreqMHz());
}

bool isReceivingPacket() override {
return ((CustomLR1121*)_radio)->isReceiving();
}

float getCurrentRSSI() override {
float rssi = -110;
((CustomLR1121*)_radio)->getRssiInst(&rssi);
return rssi;
}

void onSendFinished() override {
RadioLibWrapper::onSendFinished();
((CustomLR1121*)_radio)->explicitHeader();
_radio->setPreambleLength(preambleLengthForSF(getSpreadingFactor()));
}

float getLastRSSI() const override {
return ((CustomLR1121*)_radio)->getRSSI();
}

float getLastSNR() const override {
return ((CustomLR1121*)_radio)->getSNR();
}

uint8_t getSpreadingFactor() const override {
return ((CustomLR1121*)_radio)->getSpreadingFactor();
}

void setRxBoostedGainMode(bool en) override {
((CustomLR1121*)_radio)->setRxBoostedGainMode(en);
}

bool getRxBoostedGainMode() const override {
return ((CustomLR1121*)_radio)->getRxBoostedGainMode();
}

};
63 changes: 63 additions & 0 deletions variants/ESP32_S3_Supermini/SuperminiBoard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#pragma once

#include <Arduino.h>
#include "target.h"
#include <MeshCore.h>
#include <helpers/ESP32Board.h>
#include <driver/rtc_io.h>


class SuperminiBoard : public ESP32Board {
private:
float adc_mult = ADC_MULTIPLIER;
public:
SuperminiBoard() {}

void begin() {
ESP32Board::begin();

pinMode(PIN_VBAT_READ, INPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);

esp_reset_reason_t reason = esp_reset_reason();
if (reason == ESP_RST_DEEPSLEEP) {
long wakeup_source = esp_sleep_get_ext1_wakeup_status();
if (wakeup_source & (1 << P_LORA_DIO_1)) { // received a LoRa packet (while in deep sleep)
startup_reason = BD_STARTUP_RX_PACKET;
}

rtc_gpio_hold_dis((gpio_num_t)P_LORA_NSS);
rtc_gpio_deinit((gpio_num_t)P_LORA_DIO_1);
}
}

void enterDeepSleep(uint32_t secs, int pin_wake_btn = -1) {
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);

rtc_gpio_set_direction((gpio_num_t)P_LORA_DIO_1, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pulldown_en((gpio_num_t)P_LORA_DIO_1);

rtc_gpio_hold_en((gpio_num_t)P_LORA_NSS);

if (pin_wake_btn < 0) {
esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet
}
else {
esp_sleep_enable_ext1_wakeup((1L << P_LORA_DIO_1) | (1L << pin_wake_btn), ESP_EXT1_WAKEUP_ANY_HIGH); // wake up on: recv LoRa packet OR wake btn
}

if (secs > 0) {
esp_sleep_enable_timer_wakeup(secs * 1000000);
}

esp_deep_sleep_start();
}

void powerOff() override {
enterDeepSleep(0);
}

const char* getManufacturerName() const override {
return "ESP32 Supermini";
}
};
Loading