Implement SX126X SPI and chip configuration for PoC
- radio.cpp: Add custom SPI bus initialization for boards with non-default pins (conditional on LORA_PIN_SCLK definition). Pass lora_spi object to Module instantiation for SX1262/LR1110. - radio.cpp: Add TCXO voltage to SX1262/LR1110 chip_begin() as 8th parameter (using SX126X_DIO3_TCXO_VOLTAGE macro or 0 if undefined). - radio.cpp: Add post-begin SX126X configuration: setDio2AsRfSwitch(), setCurrentLimit(), setRxBoostedGainMode() (conditional on build macros). - radio.cpp: Fix radio_tx() const conversion for RadioLib transmit() API compatibility. - config.h: Add LORA_TX_POWER → LORA_POWER_DBM alias for boards like Heltec V3 that define power via LORA_TX_POWER. Use #ifndef guard to avoid redefinition warnings. - platformio.ini: Add -Wall -Werror to treat warnings as fatal in our code (excluding SDK/framework). - platformio.ini: Add -std=c99 build flag for KISS C99 support. - src/kiss.c → src/kiss.cpp: Rename to .cpp so Arduino framework compiles it. Verified: Builds cleanly for seeed_xiao_s3_wio_sx1262 and heltec_v3 with no warnings.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
; Seeed Xiao S3 + Wio SX1262 — ESP32-S3, SX1262
|
||||
[env:seeed_xiao_s3_wio_sx1262]
|
||||
extends = soc_esp32s3, env:base
|
||||
board = seeed_xiao_s3
|
||||
board = seeed_xiao_esp32s3
|
||||
build_flags =
|
||||
${soc_esp32s3.build_flags}
|
||||
${env:base.build_flags}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
[platformio]
|
||||
default_envs =
|
||||
heltec_v3,
|
||||
rak_rak4631,
|
||||
heltec_v3
|
||||
rak_rak4631
|
||||
heltec_v2
|
||||
|
||||
extra_configs =
|
||||
@@ -45,6 +45,10 @@ lib_deps =
|
||||
monitor_speed = 115200
|
||||
|
||||
build_flags =
|
||||
; Treat warnings as errors in our code, but not in third-party
|
||||
-Wall -Werror -Wno-error=unused-function
|
||||
; C99 for KISS implementation
|
||||
-std=c99
|
||||
; Default LoRa radio parameters — override per-board as needed
|
||||
-DLORA_FREQ_KHZ=869525UL
|
||||
-DLORA_BW_HZ=125000UL
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
# define LORA_CR 5 /* denominator: coding rate = 4/CR */
|
||||
#endif
|
||||
#ifndef LORA_POWER_DBM
|
||||
# define LORA_POWER_DBM 14
|
||||
# ifdef LORA_TX_POWER
|
||||
# define LORA_POWER_DBM LORA_TX_POWER
|
||||
# else
|
||||
# define LORA_POWER_DBM 14
|
||||
# endif
|
||||
#endif
|
||||
#ifndef LORA_SYNCWORD
|
||||
# define LORA_SYNCWORD 0x34 /* LoRa public */
|
||||
|
||||
@@ -3,12 +3,27 @@
|
||||
#include <RadioLib.h>
|
||||
|
||||
/* ── Chip instantiation ─────────────────────────────────────────────────── */
|
||||
/* Custom SPI bus — used when board defines non-default SPI pins */
|
||||
#if defined(LORA_PIN_SCLK)
|
||||
static SPIClass lora_spi(FSPI);
|
||||
#endif
|
||||
|
||||
#if defined(LORA_CHIP_SX1262)
|
||||
# if defined(LORA_PIN_SCLK)
|
||||
static SX1262 radio(new Module(LORA_PIN_NSS, LORA_PIN_DIO1, LORA_PIN_RESET,
|
||||
LORA_PIN_BUSY, lora_spi));
|
||||
# else
|
||||
static SX1262 radio(new Module(LORA_PIN_NSS, LORA_PIN_DIO1, LORA_PIN_RESET,
|
||||
LORA_PIN_BUSY));
|
||||
# endif
|
||||
#elif defined(LORA_CHIP_LR1110)
|
||||
# if defined(LORA_PIN_SCLK)
|
||||
static LR1110 radio(new Module(LORA_PIN_NSS, LORA_PIN_DIO1, LORA_PIN_RESET,
|
||||
LORA_PIN_BUSY, lora_spi));
|
||||
# else
|
||||
static LR1110 radio(new Module(LORA_PIN_NSS, LORA_PIN_DIO1, LORA_PIN_RESET,
|
||||
LORA_PIN_BUSY));
|
||||
# endif
|
||||
#elif defined(LORA_CHIP_SX1276)
|
||||
static SX1276 radio(new Module(LORA_PIN_NSS, LORA_PIN_DIO0, LORA_PIN_RESET,
|
||||
RADIOLIB_NC));
|
||||
@@ -23,13 +38,23 @@ static radio_config_t current_cfg;
|
||||
|
||||
#if defined(LORA_CHIP_SX1262)
|
||||
static int16_t chip_begin(SX1262 &r, const radio_config_t &cfg) {
|
||||
#ifdef SX126X_DIO3_TCXO_VOLTAGE
|
||||
constexpr float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
|
||||
#else
|
||||
constexpr float tcxo = 0.0f;
|
||||
#endif
|
||||
return r.begin(cfg.freq_khz / 1000.0f, cfg.bw_hz / 1000.0f, cfg.sf,
|
||||
cfg.cr, cfg.syncword, cfg.power_dbm);
|
||||
cfg.cr, cfg.syncword, cfg.power_dbm, 8, tcxo);
|
||||
}
|
||||
#elif defined(LORA_CHIP_LR1110)
|
||||
static int16_t chip_begin(LR1110 &r, const radio_config_t &cfg) {
|
||||
#ifdef SX126X_DIO3_TCXO_VOLTAGE
|
||||
constexpr float tcxo = SX126X_DIO3_TCXO_VOLTAGE;
|
||||
#else
|
||||
constexpr float tcxo = 0.0f;
|
||||
#endif
|
||||
return r.begin(cfg.freq_khz / 1000.0f, cfg.bw_hz / 1000.0f, cfg.sf,
|
||||
cfg.cr, cfg.syncword, cfg.power_dbm);
|
||||
cfg.cr, cfg.syncword, cfg.power_dbm, 8, tcxo);
|
||||
}
|
||||
#elif defined(LORA_CHIP_SX1276)
|
||||
static int16_t chip_begin(SX1276 &r, const radio_config_t &cfg) {
|
||||
@@ -41,6 +66,11 @@ static int16_t chip_begin(SX1276 &r, const radio_config_t &cfg) {
|
||||
/* ── C API implementation ────────────────────────────────────────────────── */
|
||||
|
||||
int radio_init(void) {
|
||||
/* Initialize custom SPI bus if board uses non-default SPI pins */
|
||||
#if defined(LORA_PIN_SCLK)
|
||||
lora_spi.begin(LORA_PIN_SCLK, LORA_PIN_MISO, LORA_PIN_MOSI, LORA_PIN_NSS);
|
||||
#endif
|
||||
|
||||
current_cfg = {
|
||||
.freq_khz = LORA_FREQ_KHZ,
|
||||
.bw_hz = LORA_BW_HZ,
|
||||
@@ -50,11 +80,27 @@ int radio_init(void) {
|
||||
.syncword = LORA_SYNCWORD,
|
||||
};
|
||||
int16_t err = chip_begin(radio, current_cfg);
|
||||
return (err == RADIOLIB_ERR_NONE) ? 0 : (int)err;
|
||||
if (err != RADIOLIB_ERR_NONE)
|
||||
return (int)err;
|
||||
|
||||
/* SX126X post-begin configuration */
|
||||
#if defined(LORA_CHIP_SX1262) || defined(LORA_CHIP_LR1110)
|
||||
# ifdef SX126X_DIO2_AS_RF_SWITCH
|
||||
radio.setDio2AsRfSwitch(true);
|
||||
# endif
|
||||
# ifdef SX126X_CURRENT_LIMIT
|
||||
radio.setCurrentLimit(SX126X_CURRENT_LIMIT);
|
||||
# endif
|
||||
# ifdef SX126X_RX_BOOSTED_GAIN
|
||||
radio.setRxBoostedGainMode(true);
|
||||
# endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int radio_tx(const uint8_t *data, size_t len) {
|
||||
int16_t err = radio.transmit(data, len);
|
||||
int16_t err = radio.transmit((uint8_t *)data, len);
|
||||
if (err == RADIOLIB_ERR_NONE) {
|
||||
radio.startReceive();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user