Skip to content

Commit

Permalink
[RP2XXX] build with LR11XX driver
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Dec 11, 2024
1 parent a95b44d commit 78f7224
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 34 deletions.
12 changes: 8 additions & 4 deletions software/firmware/source/SoftRF/src/driver/radio/almic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include "../EEPROM.h"
#include "../Battery.h"

#ifndef RadioSPI
#define RadioSPI SPI
#endif

extern size_t RF_tx_size;

static bool sx1276_probe(void);
Expand Down Expand Up @@ -126,7 +130,7 @@ static bool sx1276_probe()
v = sx1276_readReg(SX1276_RegVersion);

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

if (v == 0x12 || v == 0x13) {

Expand Down Expand Up @@ -185,7 +189,7 @@ static bool sx1262_probe()
v = sx1262_ReadReg(REG_LORASYNCWORDLSB);

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

u1_t fanet_sw_lsb = ((fanet_proto_desc.syncword[0] & 0x0F) << 4) | 0x04;
if (v == SX126X_DEF_LORASYNCWORDLSB || v == fanet_sw_lsb) {
Expand Down Expand Up @@ -498,7 +502,7 @@ static void sx1276_shutdown()
{
LMIC_shutdown();

SPI.end();
RadioSPI.end();
}

#if defined(USE_BASICMAC)
Expand All @@ -508,7 +512,7 @@ static void sx1262_shutdown()
sx126x_ll_ops.radio_sleep();
delay(1);

SPI.end();
RadioSPI.end();
}
#endif /* USE_BASICMAC */

Expand Down
14 changes: 9 additions & 5 deletions software/firmware/source/SoftRF/src/driver/radio/nordic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

#include "../EEPROM.h"

#ifndef RadioSPI
#define RadioSPI SPI
#endif

static bool nrf905_probe(void);
static void nrf905_setup(void);
static void nrf905_channel(int8_t);
Expand Down Expand Up @@ -63,20 +67,20 @@ static bool nrf905_probe()
SoC->SPI_begin();

#if defined(ARDUINO) && !defined(RASPBERRY_PI) && !defined(ARDUINO_ARCH_MBED)
SPI.setClockDivider(SPI_CLOCK_DIV2);
RadioSPI.setClockDivider(SPI_CLOCK_DIV2);
#endif /* ARDUINO */

digitalWrite(CS_N, LOW);

SPI.transfer(NRF905_CMD_R_TX_ADDRESS);
RadioSPI.transfer(NRF905_CMD_R_TX_ADDRESS);
for(uint8_t i=4;i--;) {
addr[i] = SPI.transfer(NRF905_CMD_NOP);
addr[i] = RadioSPI.transfer(NRF905_CMD_NOP);
}

digitalWrite(CS_N, HIGH);
pinMode(CS_N, INPUT);

SPI.end();
RadioSPI.end();

#if 0
delay(3000);
Expand Down Expand Up @@ -210,7 +214,7 @@ static bool nrf905_transmit()
static void nrf905_shutdown()
{
nRF905_powerDown();
SPI.end();
RadioSPI.end();
}

#endif /* EXCLUDE_NRF905 */
8 changes: 6 additions & 2 deletions software/firmware/source/SoftRF/src/driver/radio/ogn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include <rf/combo/rfm.h>
#endif /* WITH_SI4X32 */

#ifndef RadioSPI
#define RadioSPI SPI
#endif

static bool ognrf_probe(void);
static void ognrf_setup(void);
static void ognrf_channel(int8_t);
Expand Down Expand Up @@ -97,7 +101,7 @@ static bool ognrf_probe()
uint8_t ChipVersion = TRX.ReadVersion();

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

#if defined(WITH_RFM95)
if (ChipVersion == 0x12 || ChipVersion == 0x13) success = true;
Expand Down Expand Up @@ -286,7 +290,7 @@ static bool ognrf_transmit()
static void ognrf_shutdown()
{
TRX.WriteMode(RF_OPMODE_STANDBY);
SPI.end();
RadioSPI.end();

pinMode(lmic_pins.nss, INPUT);
}
Expand Down
18 changes: 11 additions & 7 deletions software/firmware/source/SoftRF/src/driver/radio/radiolib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const rfchip_ops_t lr1121_ops = {
#define USE_SX1262 0
#define USE_LR11XX 1

#ifndef RadioSPI
#define RadioSPI SPI
#endif

Module *mod;
#if USE_SX1262
SX1262 *radio;
Expand Down Expand Up @@ -94,9 +98,9 @@ static void hal_spi_select (int on) {

#if defined(SPI_HAS_TRANSACTION)
if (on)
SPI.beginTransaction(probe_settings);
RadioSPI.beginTransaction(probe_settings);
else
SPI.endTransaction();
RadioSPI.endTransaction();
#endif

//Serial.println(val?">>":"<<");
Expand Down Expand Up @@ -277,7 +281,7 @@ static bool lr1110_probe()
lr11xx_GetVersion(&hw, &device, &major, &minor);

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

if (device == RADIOLIB_LR11X0_DEVICE_LR1110) {

Expand Down Expand Up @@ -318,7 +322,7 @@ static bool lr1121_probe()
v = sx1262_ReadReg(REG_LORASYNCWORDLSB);

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

u1_t fanet_sw_lsb = ((fanet_proto_desc.syncword[0] & 0x0F) << 4) | 0x04;
if (v == SX126X_DEF_LORASYNCWORDLSB || v == fanet_sw_lsb) {
Expand Down Expand Up @@ -353,7 +357,7 @@ static bool lr1121_probe()
lr11xx_GetVersion(&hw, &device, &major, &minor);

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

if (device == RADIOLIB_LR11X0_DEVICE_LR1121) {

Expand Down Expand Up @@ -406,7 +410,7 @@ static void lr11xx_setup()
uint32_t busy = lmic_pins.busy == LMIC_UNUSED_PIN ?
RADIOLIB_NC : lmic_pins.busy;

mod = new Module(lmic_pins.nss, irq, lmic_pins.rst, busy, SPI);
mod = new Module(lmic_pins.nss, irq, lmic_pins.rst, busy, RadioSPI);
#if USE_SX1262
radio = new SX1262(mod);
#endif
Expand Down Expand Up @@ -1151,7 +1155,7 @@ static void lr11xx_shutdown()
state = radio->sleep(false, 0);
#endif

SPI.end();
RadioSPI.end();
}

#endif /* USE_RADIOLIB */
8 changes: 7 additions & 1 deletion software/firmware/source/SoftRF/src/platform/RP2XXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ struct rst_info {
#define SOC_GPIO_PIN_SCK (10u)
#define SOC_GPIO_PIN_SS (13u)

#define RadioSPI SPI1

/* NRF905 */
#define SOC_GPIO_PIN_TXE SOC_UNUSED_PIN
#define SOC_GPIO_PIN_CE SOC_UNUSED_PIN
Expand Down Expand Up @@ -185,6 +187,8 @@ struct rst_info {
#define SOC_GPIO_PIN_SCK (10u)
#define SOC_GPIO_PIN_SS (3u)

#define RadioSPI SPI1

/* NRF905 */
#define SOC_GPIO_PIN_TXE SOC_UNUSED_PIN
#define SOC_GPIO_PIN_CE SOC_UNUSED_PIN
Expand Down Expand Up @@ -327,7 +331,9 @@ struct rst_info {
#endif /* ARDUINO_ARCH_MBED */

#define USE_BASICMAC
//#define USE_RADIOLIB
#if defined(ARDUINO_GENERIC_RP2040)
#define USE_RADIOLIB
#endif /* ARDUINO_GENERIC_RP2040 */

#define USE_TIME_SLOTS

Expand Down
16 changes: 8 additions & 8 deletions software/firmware/source/SoftRF/src/platform/nRF52.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1380,18 +1380,18 @@ static void nRF52_setup()
nRF52_board == NRF52_LILYGO_TECHO_REV_1 ||
nRF52_board == NRF52_LILYGO_TECHO_REV_2 ||
nRF52_board == NRF52_LILYGO_TULTIMA) {
String NFC_name = SOFTRF_IDENT;
NFC_name += "-";
NFC_name += String(SoC->getChipId() & 0x00FFFFFFU, HEX);

if ((NRF_UICR->NFCPINS & UICR_NFCPINS_PROTECT_Msk) != (UICR_NFCPINS_PROTECT_NFC << UICR_NFCPINS_PROTECT_Pos)) {
Serial.println("*** NFC pins are disabled ***");
// nfcpins_enable();
}
} else {
String NFC_name = SOFTRF_IDENT;
NFC_name += "-";
NFC_name += String(SoC->getChipId() & 0x00FFFFFFU, HEX);

NFC.setTXTmessage((NFC_name+"-NFC").c_str(), "en");
NFC.start();
NFC.registerCallback(nfc_func);
NFC.setTXTmessage((NFC_name+"-NFC").c_str(), "en");
NFC.start();
NFC.registerCallback(nfc_func);
}
}
#endif /* ENABLE_NFC */
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
#include <cc13xx/cc13xx.h>
#endif /* ENERGIA_ARCH_CC13XX || ENERGIA_ARCH_CC13X2 */

#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RP2350)
#undef SPI
#define SPI SPI1
#endif /* ARDUINO_ARCH_RP2040 || ARDUINO_ARCH_RP2350 */

#if defined(ARDUINO_ARCH_RENESAS)
#include <SoftSPI.h>
extern SoftSPI RadioSPI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@

#endif /* ARDUINO_ARCH_NRF52 */

#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RP2350)

#undef SPI
#define SPI SPI1

#endif /* ARDUINO_ARCH_RP2040 || ARDUINO_ARCH_RP2350 */

#if defined(ARDUINO_ARCH_RENESAS)
#ifndef SPI_HAS_TRANSACTION
#define SPI_HAS_TRANSACTION 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
#include <cc13xx/cc13xx.h>
#endif /* ENERGIA_ARCH_CC13XX || ENERGIA_ARCH_CC13X2 */

#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RP2350)
#undef SPI
#define SPI SPI1
#endif /* ARDUINO_ARCH_RP2040 || ARDUINO_ARCH_RP2350 */

#if defined(ARDUINO_ARCH_RENESAS) // || defined(ARDUINO_ARCH_SILABS)
#include <SoftSPI.h>
extern SoftSPI RadioSPI;
Expand Down

0 comments on commit 78f7224

Please sign in to comment.