From 922bbaaecf6c10d00c68e2f8a6e960f7b47b3b75 Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Mon, 22 Jul 2024 08:37:41 +0300 Subject: [PATCH] [RadioLib] build with LR1110 radio driver as well --- .../firmware/source/SoftRF/src/driver/RF.cpp | 6 +- .../firmware/source/SoftRF/src/driver/RF.h | 6 +- .../SoftRF/src/driver/radio/radiolib.cpp | 148 +++++++++++++----- .../SoftRF/src/platform/iomap/Seeed_T1000.h | 40 +++++ .../source/SoftRF/src/platform/nRF52.cpp | 5 +- .../source/SoftRF/src/platform/nRF52.h | 2 + .../firmware/source/SoftRF/src/ui/Web.cpp | 3 +- 7 files changed, 163 insertions(+), 47 deletions(-) create mode 100644 software/firmware/source/SoftRF/src/platform/iomap/Seeed_T1000.h diff --git a/software/firmware/source/SoftRF/src/driver/RF.cpp b/software/firmware/source/SoftRF/src/driver/RF.cpp index 709db5b20..00bca480c 100644 --- a/software/firmware/source/SoftRF/src/driver/RF.cpp +++ b/software/firmware/source/SoftRF/src/driver/RF.cpp @@ -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()) { diff --git a/software/firmware/source/SoftRF/src/driver/RF.h b/software/firmware/source/SoftRF/src/driver/RF.h index 59550ca20..d0d78aac4 100644 --- a/software/firmware/source/SoftRF/src/driver/RF.h +++ b/software/firmware/source/SoftRF/src/driver/RF.h @@ -79,7 +79,8 @@ enum RF_IC_R820T, RF_IC_MSI001, RF_IC_SA8X8, - RF_IC_LR112X, + RF_IC_LR1110, + RF_IC_LR1121, }; enum @@ -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 */ diff --git a/software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp b/software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp index de832116f..f458b0154 100644 --- a/software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp +++ b/software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp @@ -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; @@ -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 }; @@ -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 @@ -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; @@ -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; @@ -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(); @@ -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); @@ -272,7 +322,7 @@ static void lr112x_channel(int8_t channel) } } -static void lr112x_setup() +static void lr11xx_setup() { int state; @@ -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) { @@ -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) { @@ -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) @@ -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 @@ -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; @@ -777,7 +845,7 @@ static bool lr112x_receive() return success; } -static bool lr112x_transmit() +static bool lr11xx_transmit() { u1_t crc8; u2_t crc16; @@ -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 diff --git a/software/firmware/source/SoftRF/src/platform/iomap/Seeed_T1000.h b/software/firmware/source/SoftRF/src/platform/iomap/Seeed_T1000.h new file mode 100644 index 000000000..aca015d87 --- /dev/null +++ b/software/firmware/source/SoftRF/src/platform/iomap/Seeed_T1000.h @@ -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 diff --git a/software/firmware/source/SoftRF/src/platform/nRF52.cpp b/software/firmware/source/SoftRF/src/platform/nRF52.cpp index 425f36a9b..a5810fc5f 100644 --- a/software/firmware/source/SoftRF/src/platform/nRF52.cpp +++ b/software/firmware/source/SoftRF/src/platform/nRF52.cpp @@ -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) { diff --git a/software/firmware/source/SoftRF/src/platform/nRF52.h b/software/firmware/source/SoftRF/src/platform/nRF52.h index cf593ed4f..c330d737e 100644 --- a/software/firmware/source/SoftRF/src/platform/nRF52.h +++ b/software/firmware/source/SoftRF/src/platform/nRF52.h @@ -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 { @@ -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 diff --git a/software/firmware/source/SoftRF/src/ui/Web.cpp b/software/firmware/source/SoftRF/src/ui/Web.cpp index 29f841088..6e252f3b1 100644 --- a/software/firmware/source/SoftRF/src/ui/Web.cpp +++ b/software/firmware/source/SoftRF/src/ui/Web.cpp @@ -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("\ \