Skip to content

Commit

Permalink
[RadioLib] build with LR1110 radio driver as well
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Jul 22, 2024
1 parent f73d7c3 commit 922bbaa
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 47 deletions.
6 changes: 4 additions & 2 deletions software/firmware/source/SoftRF/src/driver/RF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ byte RF_setup(void)
rf_chip = &cc13xx_ops;
#endif /* EXCLUDE_CC13XX */
#if defined(USE_RADIOLIB)
} else if (lr112x_ops.probe()) {
rf_chip = &lr112x_ops;
} else if (lr1110_ops.probe()) {
rf_chip = &lr1110_ops;
} else if (lr1121_ops.probe()) {
rf_chip = &lr1121_ops;
#endif /* USE_RADIOLIB */
#if defined(USE_SA8X8)
} else if (sa8x8_ops.probe()) {
Expand Down
6 changes: 4 additions & 2 deletions software/firmware/source/SoftRF/src/driver/RF.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ enum
RF_IC_R820T,
RF_IC_MSI001,
RF_IC_SA8X8,
RF_IC_LR112X,
RF_IC_LR1110,
RF_IC_LR1121,
};

enum
Expand Down Expand Up @@ -171,7 +172,8 @@ extern const rfchip_ops_t sa8x8_ops;
#endif /* USE_SA8X8 */

#if defined(USE_RADIOLIB)
extern const rfchip_ops_t lr112x_ops;
extern const rfchip_ops_t lr1110_ops;
extern const rfchip_ops_t lr1121_ops;
#endif /* USE_RADIOLIB */

#endif /* RFHELPER_H */
148 changes: 108 additions & 40 deletions software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,46 @@

extern size_t RF_tx_size;

static bool lr112x_probe(void);
static void lr112x_setup(void);
static void lr112x_channel(int8_t);
static bool lr112x_receive(void);
static bool lr112x_transmit(void);
static void lr112x_shutdown(void);

const rfchip_ops_t lr112x_ops = {
RF_IC_LR112X,
"LR112x",
lr112x_probe,
lr112x_setup,
lr112x_channel,
lr112x_receive,
lr112x_transmit,
lr112x_shutdown
static bool lr1110_probe(void);
static bool lr1121_probe(void);
static void lr11xx_setup(void);
static void lr11xx_channel(int8_t);
static bool lr11xx_receive(void);
static bool lr11xx_transmit(void);
static void lr11xx_shutdown(void);

const rfchip_ops_t lr1110_ops = {
RF_IC_LR1110,
"LR1110",
lr1110_probe,
lr11xx_setup,
lr11xx_channel,
lr11xx_receive,
lr11xx_transmit,
lr11xx_shutdown
};

const rfchip_ops_t lr1121_ops = {
RF_IC_LR1121,
"LR1121",
lr1121_probe,
lr11xx_setup,
lr11xx_channel,
lr11xx_receive,
lr11xx_transmit,
lr11xx_shutdown
};

#define USE_SX1262 1
#define USE_LR1121 0
#define USE_LR11XX 0

Module *mod;
#if USE_SX1262
#define RADIO_TYPE SX1262
#elif USE_LR1121
#define RADIO_TYPE LR1121
SX1262 *radio;
#elif USE_LR11XX
LR11x0 *radio;
#endif

Module *mod;
RADIO_TYPE *radio;

const rf_proto_desc_t *rl_protocol = &ogntp_proto_desc;

static int8_t lr112x_channel_prev = (int8_t) -1;
Expand Down Expand Up @@ -142,8 +152,8 @@ static uint8_t sx1262_ReadReg (uint16_t addr) {
}
#endif /* USE_SX1262 */

#if USE_LR1121
static void lr1121_GetVersion (uint8_t* hw, uint8_t* device,
#if USE_LR11XX
static void lr11xx_GetVersion (uint8_t* hw, uint8_t* device,
uint8_t* major, uint8_t* minor) {
uint8_t buf[4] = { 0 };

Expand All @@ -166,7 +176,7 @@ static void lr1121_GetVersion (uint8_t* hw, uint8_t* device,
if (major) { *major = buf[2]; }
if (minor) { *minor = buf[3]; }
}
#endif /* USE_LR1121 */
#endif /* USE_LR11XX */

// this function is called when a complete packet
// is received by the module
Expand All @@ -179,7 +189,47 @@ void lr112x_receive_handler(void) {
lr112x_receive_complete = true;
}

static bool lr112x_probe()
static bool lr1110_probe()
{
#if USE_SX1262
return false;
#endif
#if USE_LR11XX
u1_t device, device_reset;
u1_t hw, major, minor;

SoC->SPI_begin();

lmic_hal_init (nullptr);

// manually reset radio
hal_pin_rst(0); // drive RST pin low
hal_waitUntil(os_getTime()+ms2osticks(1)); // wait >100us

lr11xx_GetVersion(&hw, &device_reset, &major, &minor);

hal_pin_rst(2); // configure RST pin floating!
hal_waitUntil(os_getTime()+ms2osticks(5)); // wait 5ms

lr11xx_GetVersion(&hw, &device, &major, &minor);

pinMode(lmic_pins.nss, INPUT);
SPI.end();

if (device == RADIOLIB_LR11X0_DEVICE_LR1110) {

if (device_reset == RADIOLIB_LR11X0_DEVICE_LR1110) {
RF_SX12XX_RST_is_connected = false;
}

return true;
} else {
return false;
}
#endif
}

static bool lr1121_probe()
{
#if USE_SX1262
u1_t v, v_reset;
Expand Down Expand Up @@ -215,7 +265,7 @@ static bool lr112x_probe()
}
#endif

#if USE_LR1121
#if USE_LR11XX
u1_t device, device_reset;
u1_t hw, major, minor;

Expand All @@ -227,12 +277,12 @@ static bool lr112x_probe()
hal_pin_rst(0); // drive RST pin low
hal_waitUntil(os_getTime()+ms2osticks(1)); // wait >100us

lr1121_GetVersion(&hw, &device_reset, &major, &minor);
lr11xx_GetVersion(&hw, &device_reset, &major, &minor);

hal_pin_rst(2); // configure RST pin floating!
hal_waitUntil(os_getTime()+ms2osticks(5)); // wait 5ms

lr1121_GetVersion(&hw, &device, &major, &minor);
lr11xx_GetVersion(&hw, &device, &major, &minor);

pinMode(lmic_pins.nss, INPUT);
SPI.end();
Expand All @@ -250,7 +300,7 @@ static bool lr112x_probe()
#endif
}

static void lr112x_channel(int8_t channel)
static void lr11xx_channel(int8_t channel)
{
if (channel != -1 && channel != lr112x_channel_prev) {
uint32_t frequency = RF_FreqPlan.getChanFrequency((uint8_t) channel);
Expand All @@ -272,7 +322,7 @@ static void lr112x_channel(int8_t channel)
}
}

static void lr112x_setup()
static void lr11xx_setup()
{
int state;

Expand All @@ -284,7 +334,20 @@ static void lr112x_setup()
RADIOLIB_NC : lmic_pins.busy;

mod = new Module(lmic_pins.nss, irq, lmic_pins.rst, busy, SPI);
radio = new RADIO_TYPE(mod);
#if USE_SX1262
radio = new SX1262(mod);
#endif
#if USE_LR11XX
switch (rf_chip->type)
{
case RF_IC_LR1110:
radio = new LR1110(mod);
case RF_IC_LR1121:
default:
radio = new LR1121(mod);
break;
}
#endif

switch (settings->rf_protocol)
{
Expand Down Expand Up @@ -336,7 +399,12 @@ static void lr112x_setup()
switch (rl_protocol->modulation_type)
{
case RF_MODULATION_TYPE_LORA:
#if USE_SX1262
state = radio->begin(); // start LoRa mode (and disable FSK)
#endif
#if USE_LR11XX
state = radio->begin(125.0, 9, 7, RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, 10, 8, 1.6);
#endif

switch (RF_FreqPlan.Bandwidth)
{
Expand Down Expand Up @@ -373,8 +441,8 @@ static void lr112x_setup()
#if USE_SX1262
state = radio->beginFSK(); // start FSK mode (and disable LoRa)
#endif
#if USE_LR1121
state = radio->beginGFSK();
#if USE_LR11XX
state = radio->beginGFSK(4.8, 5.0, 156.2, 10, 16, 1.6);
#endif

switch (rl_protocol->bitrate)
Expand Down Expand Up @@ -531,7 +599,7 @@ static void lr112x_setup()
state = radio->setCurrentLimit(100.0);
#endif

#if USE_LR1121
#if USE_LR11XX
// LR1121
// set RF switch configuration for Wio WM1110
// Wio WM1110 uses DIO5 and DIO6 for RF switching
Expand Down Expand Up @@ -581,7 +649,7 @@ static bool memeqzero(const uint8_t *data, size_t length)
return memcmp((void *) data, (void *) p, length) == 0;
}

static bool lr112x_receive()
static bool lr11xx_receive()
{
bool success = false;
int state;
Expand Down Expand Up @@ -777,7 +845,7 @@ static bool lr112x_receive()
return success;
}

static bool lr112x_transmit()
static bool lr11xx_transmit()
{
u1_t crc8;
u2_t crc16;
Expand Down Expand Up @@ -950,13 +1018,13 @@ static bool lr112x_transmit()
return success;
}

static void lr112x_shutdown()
static void lr11xx_shutdown()
{
#if USE_SX1262
int state = radio->sleep(false);
#endif

#if USE_LR1121
#if USE_LR11XX
int state = radio->sleep(false, 0);
#endif

Expand Down
40 changes: 40 additions & 0 deletions software/firmware/source/SoftRF/src/platform/iomap/Seeed_T1000.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

/* Peripherals */
#define SOC_GPIO_PIN_CONS_T1000_RX _PINNUM(0, 17) // P0.17
#define SOC_GPIO_PIN_CONS_T1000_TX _PINNUM(0, 16) // P0.16

#define SOC_GPIO_PIN_GNSS_T1000_RX _PINNUM(0, 14) // P0.14
#define SOC_GPIO_PIN_GNSS_T1000_TX _PINNUM(0, 13) // P0.13

#define SOC_GPIO_PIN_GNSS_T1000_PPS SOC_UNUSED_PIN // TBD
#define SOC_GPIO_PIN_GNSS_T1000_IRQ _PINNUM(1, 12) // P1.12
#define SOC_GPIO_PIN_GNSS_T1000_RST _PINNUM(1, 15) // P1.15
#define SOC_GPIO_PIN_GNSS_T1000_EN _PINNUM(1, 11) // P1.11

/* SPI */
#define SOC_GPIO_PIN_T1000_MOSI _PINNUM(1, 9) // P1.09
#define SOC_GPIO_PIN_T1000_MISO _PINNUM(1, 8) // P1.08
#define SOC_GPIO_PIN_T1000_SCK _PINNUM(0, 11) // P0.11
#define SOC_GPIO_PIN_T1000_SS _PINNUM(0, 12) // P0.12

/* LR1110 */
#define SOC_GPIO_PIN_T1000_RST _PINNUM(1, 10) // P1.10
#define SOC_GPIO_PIN_T1000_DIO1 _PINNUM(1, 1) // P1.01
#define SOC_GPIO_PIN_T1000_BUSY _PINNUM(0, 7) // P0.07

/* I2C */
#define SOC_GPIO_PIN_T1000_SDA _PINNUM(0, 9) // P0.26 ?
#define SOC_GPIO_PIN_T1000_SCL _PINNUM(0, 10) // P0.27 ?

/* button */
#define SOC_GPIO_PIN_T1000_BUTTON _PINNUM(0, 6) // P0.06

/* LED */
#define SOC_GPIO_LED_T1000_GREEN _PINNUM(0, 24) // P0.24

/* ADC */
#define SOC_GPIO_PIN_T1000_BATTERY _PINNUM(0, 2) // P0.02

/* buzzer */
#define SOC_GPIO_PIN_T1000_BUZZER _PINNUM(0, 25) // P0.25
#define SOC_GPIO_PIN_T1000_BUZZER_EN _PINNUM(1, 5) // P1.05
5 changes: 3 additions & 2 deletions software/firmware/source/SoftRF/src/platform/nRF52.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,9 @@ static void nRF52_post_init()

Serial.print(F("RADIO : "));
Serial.println(hw_info.rf == RF_IC_SX1262 ||
hw_info.rf == RF_IC_SX1262 ||
hw_info.rf == RF_IC_LR112X ? F("PASS") : F("FAIL"));
hw_info.rf == RF_IC_SX1276 ||
hw_info.rf == RF_IC_LR1110 ||
hw_info.rf == RF_IC_LR1121 ? F("PASS") : F("FAIL"));
Serial.flush();
Serial.print(F("GNSS : "));
if (nRF52_board == NRF52_LILYGO_TULTIMA) {
Expand Down
2 changes: 2 additions & 0 deletions software/firmware/source/SoftRF/src/platform/nRF52.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ enum nRF52_board_id {
NRF52_LILYGO_TECHO_REV_1, /* 2020-12-12 */
NRF52_LILYGO_TECHO_REV_2, /* 2021-3-26 */
NRF52_LILYGO_TULTIMA,
NRF52_SEEED_T1000,
};

enum nRF52_display_id {
Expand Down Expand Up @@ -253,6 +254,7 @@ struct rst_info {
#define SOC_GPIO_PIN_R_INT _PINNUM(0, 16) // P0.16

#include "iomap/LilyGO_TUltima.h"
#include "iomap/Seeed_T1000.h"

#define EXCLUDE_WIFI
//#define EXCLUDE_OTA
Expand Down
3 changes: 2 additions & 1 deletion software/firmware/source/SoftRF/src/ui/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ void handleSettings() {
/* Radio specific part 1 */
if (hw_info.rf == RF_IC_SX1276 ||
hw_info.rf == RF_IC_SX1262 ||
hw_info.rf == RF_IC_LR112X) {
hw_info.rf == RF_IC_LR1110 ||
hw_info.rf == RF_IC_LR1121) {
snprintf_P ( offset, size,
PSTR("\
<tr>\
Expand Down

0 comments on commit 922bbaa

Please sign in to comment.