Skip to content

Commit

Permalink
initial build infra for RadioHead driver
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Feb 20, 2025
1 parent b1c96bb commit 4a28db1
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 19 deletions.
35 changes: 18 additions & 17 deletions software/firmware/source/SoftRF/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -144,23 +144,24 @@ PLAT_CPPS := $(PLATFORM_PATH)/ESP8266.cpp \
$(PLATFORM_PATH)/EFR32.cpp \
$(PLATFORM_PATH)/CH32.cpp

DRV_CPPS := $(DRIVER_PATH)/RF.cpp \
$(DRIVER_PATH)/radio/nordic.cpp \
$(DRIVER_PATH)/radio/almic.cpp \
$(DRIVER_PATH)/radio/uatm.cpp \
$(DRIVER_PATH)/radio/easylink.cpp \
$(DRIVER_PATH)/radio/ogn.cpp \
$(DRIVER_PATH)/radio/nicerf.cpp \
$(DRIVER_PATH)/radio/radiolib.cpp \
$(DRIVER_PATH)/GNSS.cpp \
$(DRIVER_PATH)/Baro.cpp \
$(DRIVER_PATH)/LED.cpp \
$(DRIVER_PATH)/OLED.cpp \
$(DRIVER_PATH)/Battery.cpp \
$(DRIVER_PATH)/EEPROM.cpp \
$(DRIVER_PATH)/Bluetooth.cpp \
$(DRIVER_PATH)/Sound.cpp \
$(DRIVER_PATH)/WiFi.cpp \
DRV_CPPS := $(DRIVER_PATH)/RF.cpp \
$(DRIVER_PATH)/radio/nordic.cpp \
$(DRIVER_PATH)/radio/almic.cpp \
$(DRIVER_PATH)/radio/uatm.cpp \
$(DRIVER_PATH)/radio/easylink.cpp \
$(DRIVER_PATH)/radio/ogn.cpp \
$(DRIVER_PATH)/radio/nicerf.cpp \
$(DRIVER_PATH)/radio/radiolib.cpp \
$(DRIVER_PATH)/radio/radiohead.cpp \
$(DRIVER_PATH)/GNSS.cpp \
$(DRIVER_PATH)/Baro.cpp \
$(DRIVER_PATH)/LED.cpp \
$(DRIVER_PATH)/OLED.cpp \
$(DRIVER_PATH)/Battery.cpp \
$(DRIVER_PATH)/EEPROM.cpp \
$(DRIVER_PATH)/Bluetooth.cpp \
$(DRIVER_PATH)/Sound.cpp \
$(DRIVER_PATH)/WiFi.cpp \
$(DRIVER_PATH)/EPD.cpp

UI_CPPS := $(UI_PATH)/Web.cpp \
Expand Down
4 changes: 3 additions & 1 deletion software/firmware/source/SoftRF/src/driver/RF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ byte RF_setup(void)
} else if (cc1101_ops.probe()) {
rf_chip = &cc1101_ops;
#endif /* EXCLUDE_CC1101 */
#endif /* USE_RADIOLIB */
#if defined(USE_RADIOLIB) || defined(USE_RADIOHEAD)
#if !defined(EXCLUDE_SX1231)
} else if (sx1231_ops.probe()) {
rf_chip = &sx1231_ops;
Expand All @@ -121,7 +123,7 @@ byte RF_setup(void)
} else if (si4432_ops.probe()) {
rf_chip = &si4432_ops;
#endif /* EXCLUDE_SI443X */
#endif /* USE_RADIOLIB */
#endif /* USE_RADIOLIB || USE_RADIOHEAD */
#if !defined(EXCLUDE_NRF905)
} else if (nrf905_ops.probe()) {
rf_chip = &nrf905_ops;
Expand Down
8 changes: 7 additions & 1 deletion software/firmware/source/SoftRF/src/driver/RF.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#if defined(USE_RADIOLIB)
#include <RadioLib.h>
#endif
#if defined(USE_RADIOHEAD)
#include <RadioHead.h>
#endif

#include "GNSS.h"
#include "../protocol/radio/Legacy.h"
Expand Down Expand Up @@ -178,8 +181,11 @@ extern const rfchip_ops_t sa8x8_ops;
extern const rfchip_ops_t lr1110_ops;
extern const rfchip_ops_t lr1121_ops;
extern const rfchip_ops_t cc1101_ops;
#endif /* USE_RADIOLIB */

#if defined(USE_RADIOLIB) || defined(USE_RADIOHEAD)
extern const rfchip_ops_t sx1231_ops;
extern const rfchip_ops_t si4432_ops;
#endif /* USE_RADIOLIB */
#endif /* USE_RADIOLIB || USE_RADIOHEAD */

#endif /* RFHELPER_H */
171 changes: 171 additions & 0 deletions software/firmware/source/SoftRF/src/driver/radio/radiohead.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* radiohead.cpp
* Copyright (C) 2025 Linar Yusupov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "../RF.h"

#if defined(USE_RADIOHEAD) && !defined(USE_RADIOLIB)

#include "../EEPROM.h"
#include "../Battery.h"

#include <manchester.h>

#ifndef RadioSPI
#define RadioSPI SPI
#endif

#if !defined(USE_BASICMAC)
#include <SPI.h>

static const SPISettings probe_settings(1000000UL, MSBFIRST, SPI_MODE0);

static void hal_spi_select (int on) {

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

//Serial.println(val?">>":"<<");
digitalWrite(lmic_pins.nss, !on ? HIGH : LOW);
}

// Datasheet defins typical times until busy goes low. Most are < 200us,
// except when waking up from sleep, which typically takes 3500us. Since
// we cannot know here if we are in sleep, we'll have to assume we are.
// Since 3500 is typical, not maximum, wait a bit more than that.
static unsigned long MAX_BUSY_TIME = 5000;

static void hal_pin_busy_wait (void) {
if (lmic_pins.busy == LMIC_UNUSED_PIN) {
// TODO: We could probably keep some state so we know the chip
// is in sleep, since otherwise the delay can be much shorter.
// Also, all delays after commands (rather than waking up from
// sleep) are measured from the *end* of the previous SPI
// transaction, so we could wait shorter if we remember when
// that was.
delayMicroseconds(MAX_BUSY_TIME);
} else {
unsigned long start = micros();

while((micros() - start) < MAX_BUSY_TIME && digitalRead(lmic_pins.busy)) /* wait */;
}
}
#endif /* USE_BASICMAC */

#if !defined(EXCLUDE_SI443X)

#include <RH_RF22.h>

#define RADIOHEAD_SI443X_DEVICE_VERSION 0x06 // 4 0 chip version register

static bool si4432_probe(void);
static void si4432_setup(void);
static void si4432_channel(int8_t);
static bool si4432_receive(void);
static bool si4432_transmit(void);
static void si4432_shutdown(void);

const rfchip_ops_t si4432_ops = {
RF_IC_SI4432,
"SI4432",
si4432_probe,
si4432_setup,
si4432_channel,
si4432_receive,
si4432_transmit,
si4432_shutdown
};

RH_RF22 *radio_silabs;

static u1_t si4432_readReg (u1_t addr) {
#if defined(USE_BASICMAC)
hal_spi_select(1);
#else
hal_pin_nss(0);
#endif
hal_spi(addr & 0x7F);
u1_t val = hal_spi(0x00);
#if defined(USE_BASICMAC)
hal_spi_select(0);
#else
hal_pin_nss(1);
#endif
return val;
}

static bool si4432_probe()
{
SoC->SPI_begin();

lmic_hal_init (nullptr);

hal_pin_rst(1); // drive SDN pin high
delay(1);

hal_pin_rst(0); // drive SDN pin low
delay(100);

u1_t v = si4432_readReg(RH_RF22_REG_01_VERSION_CODE);

#if 1
Serial.print("si4432 version = "); Serial.println(v, HEX);
#endif

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

hal_pin_rst(2); // configure SDN pin floating!

if (v == RADIOHEAD_SI443X_DEVICE_VERSION) {
return true;
} else {
return false;
}
}

static void si4432_channel(int8_t channel)
{
/* TBD */
}

static void si4432_setup()
{
/* TBD */
}

static bool si4432_receive()
{
return false; /* TBD */
}

static bool si4432_transmit()
{
return false; /* TBD */
}

static void si4432_shutdown()
{
/* TBD */
}
#endif /* EXCLUDE_SI443X */

#endif /* USE_RADIOHEAD */
1 change: 1 addition & 0 deletions software/firmware/source/SoftRF/src/platform/SAMD.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ struct rst_info {
//#define USE_BASICMAC
//#define EXCLUDE_SX1276 // - 3 kb
//#define USE_RADIOLIB
//#define USE_RADIOHEAD
//#define EXCLUDE_LR11XX
#define EXCLUDE_CC1101
#define EXCLUDE_SI443X
Expand Down

0 comments on commit 4a28db1

Please sign in to comment.