From 38925993002f6e6f27f83ef8ef47e04a830221e3 Mon Sep 17 00:00:00 2001 From: mikecarper Date: Fri, 23 Oct 2026 01:55:23 -0700 Subject: [PATCH] Use buffered radio SPI and acknowledged RX reuse on direct-I/O boards --- .github/workflows/run-unit-tests.yml | 3 + src/helpers/radiolib/CustomSX1262.h | 9 +- src/helpers/radiolib/SX126xBufferedRadioHal.h | 39 +++++ test/test_esp32_buffered_radio_targets.py | 145 +++++++++++++++ test/test_lr1110_profile_switch.py | 1 + test/test_profile_sx1262_iq_cache.py | 46 +++-- test/test_rak3401_onboard_radio.py | 4 +- test/test_sx126x_buffered_radio_hal.py | 145 +++++++++++++++ test/test_sx126x_nrf_rp_constructors.py | 165 ++++++++++++++++++ variants/ebyte_eora_s3/target.cpp | 7 +- variants/gat562_30s_mesh_kit/target.cpp | 4 +- variants/gat562_mesh_evb_pro/target.cpp | 4 +- variants/gat562_mesh_tracker_pro/target.cpp | 4 +- variants/gat562_mesh_watch13/target.cpp | 4 +- variants/generic-e22/target.cpp | 7 +- variants/heltec_ct62/target.cpp | 4 +- variants/heltec_e213/target.cpp | 7 +- variants/heltec_e290/target.cpp | 7 +- variants/heltec_mesh_solar/target.cpp | 4 +- variants/heltec_rc32/target.cpp | 8 +- variants/heltec_t096/target.cpp | 7 +- variants/heltec_t1/target.cpp | 7 +- variants/heltec_t114/target.cpp | 7 +- variants/heltec_t190/target.cpp | 7 +- variants/heltec_tower_v2/target.cpp | 4 +- variants/heltec_tracker/target.cpp | 7 +- variants/heltec_tracker_v2/target.cpp | 7 +- variants/heltec_v3/target.cpp | 9 +- variants/heltec_v4/target.cpp | 17 +- variants/heltec_v4_r8/target.cpp | 7 +- variants/heltec_wireless_paper/target.cpp | 7 +- variants/ikoka_handheld_nrf/target.cpp | 4 +- variants/ikoka_nano_nrf/target.cpp | 4 +- variants/ikoka_stick_nrf/target.cpp | 4 +- variants/keepteen_lt1/target.cpp | 4 +- variants/lilygo_t3s3/target.cpp | 4 +- variants/lilygo_t_impulse_plus/target.cpp | 4 +- variants/lilygo_tbeam_1w/target.cpp | 4 +- variants/lilygo_tbeam_SX1262/target.cpp | 7 +- .../lilygo_tbeam_supreme_SX1262/target.cpp | 4 +- variants/lilygo_techo/target.cpp | 4 +- variants/lilygo_techo_card/target.cpp | 4 +- variants/lilygo_techo_lite/target.cpp | 4 +- variants/lilygo_teth_elite/target.cpp | 4 +- variants/lilygo_tlora_c6/target.cpp | 7 +- variants/m5stack_unit_c6l/UnitC6LBoard.cpp | 7 +- variants/mesh_pocket/target.cpp | 4 +- variants/meshadventurer/target.cpp | 4 +- variants/meshtiny/target.cpp | 4 +- variants/mke_s3/target.cpp | 7 +- variants/muzi_base/target.cpp | 6 + variants/muziworks_r1_neo/target.cpp | 4 +- variants/nano_g2_ultra/target.cpp | 4 +- variants/nibble_screen_connect/target.cpp | 70 ++++---- variants/nibble_zero_connect/target.cpp | 4 +- variants/promicro/target.cpp | 4 +- variants/rak11310/target.cpp | 4 +- variants/rak3112/target.cpp | 7 +- variants/rak4631/target.cpp | 4 +- variants/rak_wismesh_tag/target.cpp | 4 +- variants/rpi_picow/target.cpp | 4 +- variants/sensecap_solar/target.cpp | 4 +- variants/station_g2/target.cpp | 7 +- variants/station_g3_esp32/target.cpp | 18 +- variants/tenstar_c3/target.cpp | 7 +- variants/thinknode_m1/target.cpp | 4 +- variants/thinknode_m2/target.cpp | 7 +- variants/thinknode_m4/target.cpp | 6 +- variants/thinknode_m5/target.cpp | 7 +- variants/thinknode_m6/target.cpp | 4 +- variants/thinknode_m8/target.cpp | 4 +- variants/waveshare_rp2040_lora/target.cpp | 4 +- variants/wio-tracker-l1-1w/target.cpp | 4 +- variants/wio-tracker-l1/target.cpp | 4 +- variants/wio-tracker-l2/target.cpp | 4 +- variants/xiao_c3/target.cpp | 7 +- variants/xiao_c6/XiaoC6Board.cpp | 7 +- variants/xiao_nrf52/target.cpp | 4 +- variants/xiao_rp2040/target.cpp | 4 +- variants/xiao_s3/target.cpp | 7 +- 80 files changed, 846 insertions(+), 173 deletions(-) create mode 100644 src/helpers/radiolib/SX126xBufferedRadioHal.h create mode 100644 test/test_esp32_buffered_radio_targets.py create mode 100644 test/test_sx126x_buffered_radio_hal.py create mode 100644 test/test_sx126x_nrf_rp_constructors.py diff --git a/.github/workflows/run-unit-tests.yml b/.github/workflows/run-unit-tests.yml index e31315b30..4b2b545ee 100644 --- a/.github/workflows/run-unit-tests.yml +++ b/.github/workflows/run-unit-tests.yml @@ -813,6 +813,9 @@ jobs: python3 -B test/test_rak_shutdown_power.py -v python3 -B test/test_rak3401_onboard_radio.py -v python3 -B test/test_rak3401_buffered_radio_hal.py -v + python3 -B test/test_sx126x_buffered_radio_hal.py -v + python3 -B test/test_sx126x_nrf_rp_constructors.py -v + python3 -B test/test_esp32_buffered_radio_targets.py -v python3 -B test/test_xiao_battery_safety.py -v python3 -B test/test_peripheral_mode_prefs.py -v python3 -B test/test_t1000e_sensor_power.py -v diff --git a/src/helpers/radiolib/CustomSX1262.h b/src/helpers/radiolib/CustomSX1262.h index 4f9bb2cd0..2855c639f 100644 --- a/src/helpers/radiolib/CustomSX1262.h +++ b/src/helpers/radiolib/CustomSX1262.h @@ -28,14 +28,15 @@ #endif #ifndef MC_SX1262_FAST_IQ_CACHE -// An additional optimization, enabled per board only after hardware testing. -#define MC_SX1262_FAST_IQ_CACHE 0 +// Reuse only acknowledged IQ state inside the owned warm RX path. Follow +// the direct-I/O FS policy; explicit board opt-outs and overrides still win. +#define MC_SX1262_FAST_IQ_CACHE MC_SX1262_FAST_FS #endif #ifndef MC_SX1262_FAST_MODEM_CACHE // Reuse the LoRa modem confirmation only inside an acknowledged owned RX hop. -// Keep this board-qualified optimization off until its hardware comparison. -#define MC_SX1262_FAST_MODEM_CACHE 0 +// Expander targets that opt out of FS retain their previous live-query path. +#define MC_SX1262_FAST_MODEM_CACHE MC_SX1262_FAST_FS #endif #if (MC_SX1262_FAST_FS || MC_SX1262_FAST_PACKET_CACHE || MC_SX1262_FAST_IQ_CACHE || MC_SX1262_FAST_MODEM_CACHE) && !MC_SX1262_FAST_PROFILE_SWITCH diff --git a/src/helpers/radiolib/SX126xBufferedRadioHal.h b/src/helpers/radiolib/SX126xBufferedRadioHal.h new file mode 100644 index 000000000..e1e2bd570 --- /dev/null +++ b/src/helpers/radiolib/SX126xBufferedRadioHal.h @@ -0,0 +1,39 @@ +#pragma once + +#ifndef MC_SX1262_SPI_HZ +#define MC_SX1262_SPI_HZ 8000000 +#endif + +#if defined(NRF52_PLATFORM) + #include "Nrf52BufferedRadioHal.h" + using SX126xBufferedRadioHalBase = Nrf52BufferedRadioHal; +#elif defined(ESP32_PLATFORM) + #include "ESP32BufferedRadioHal.h" + using SX126xBufferedRadioHalBase = ESP32BufferedRadioHal; +#elif defined(RP2040_PLATFORM) + #include + // Earle Philhower's HardwareSPI bulk API retains full-duplex blocking + // completion while filling/draining the controller FIFO in one call. + class SX126xBufferedRadioHalBase : public ArduinoHal { + public: + explicit SX126xBufferedRadioHalBase(SPIClass& bus, uint32_t hz) + : ArduinoHal(bus, SPISettings(hz, MSBFIRST, SPI_MODE0)) {} + void spiTransfer(uint8_t* out, size_t len, uint8_t* in) override { + if (len) spi->transfer(out, in, len); + } + }; +#else + #error "SX126x buffered radio SPI requires nRF52, ESP32 or RP2040" +#endif + +// Keep the board's existing SPI controller and pin setup. Only the default +// SPI fallback owns begin/end; explicitly supplied buses remain board-owned. +// RadioLib still controls CS, BUSY, command status and IRQ acknowledgement. +class SX126xBufferedRadioHal : public SX126xBufferedRadioHalBase { + public: + explicit SX126xBufferedRadioHal(SPIClass& bus, + uint32_t hz = MC_SX1262_SPI_HZ, bool initializeBus = false) + : SX126xBufferedRadioHalBase(bus, hz) { + initInterface = initializeBus; + } +}; diff --git a/test/test_esp32_buffered_radio_targets.py b/test/test_esp32_buffered_radio_targets.py new file mode 100644 index 000000000..383566130 --- /dev/null +++ b/test/test_esp32_buffered_radio_targets.py @@ -0,0 +1,145 @@ +"""Execute actual ESP32 radio constructors with local and default SPI buses.""" +from pathlib import Path +import os +import re +import shutil +import subprocess +import tempfile +import unittest + +from test_sx126x_buffered_radio_hal import MOCK + + +ROOT = Path(__file__).resolve().parents[1] +TARGETS = ( + "ebyte_eora_s3", "generic-e22", "heltec_ct62", "heltec_e213", + "heltec_e290", "heltec_rc32", "heltec_t190", "heltec_tracker", + "heltec_tracker_v2", "heltec_v3", "heltec_v4", "heltec_v4_r8", + "heltec_wireless_paper", "lilygo_t3s3", "lilygo_tbeam_1w", + "lilygo_tbeam_SX1262", "lilygo_tbeam_supreme_SX1262", "lilygo_tdeck", + "lilygo_teth_elite", "lilygo_tlora_c6", "m5stack_unit_c6l", + "meshadventurer", "mke_s3", "nibble_screen_connect", + "nibble_zero_connect", "rak3112", "station_g2", "station_g3_esp32", + "tenstar_c3", "thinknode_m2", "thinknode_m5", "wio-tracker-l2", + "xiao_c3", "xiao_c6", "xiao_s3", "xiao_s3_wio", +) +LEGACY_FALLBACKS = {"lilygo_tdeck", "xiao_s3_wio"} + + +def construction(target): + filename = {"xiao_c6": "XiaoC6Board.cpp", + "m5stack_unit_c6l": "UnitC6LBoard.cpp"}.get(target, "target.cpp") + source = (ROOT / "variants" / target / filename).read_text(encoding="ascii") + prefix = source[:source.index("WRAPPER_CLASS radio_driver")] + # Only the target's actual global constructors are under test. The real + # portable and platform HAL headers are included once by the harness; + # unrelated board/sensor/display classes have inert stand-ins. + prefix = re.sub(r"^\s*#include[^\n]*\n", "", prefix, flags=re.MULTILINE) + opened = len(re.findall(r"^\s*#if(?:def|ndef)?\b", prefix, re.MULTILINE)) + closed = len(re.findall(r"^\s*#endif\b", prefix, re.MULTILINE)) + prefix += "\n#endif\n" * (opened - closed) + board = re.search(r"^\s*(\w+) board;", prefix, re.MULTILINE).group(1) + return prefix, board + + +class Esp32BufferedRadioTargetTests(unittest.TestCase): + def test_actual_constructors_keep_bus_pins_clock_and_initialization_ownership(self): + compiler = shutil.which(os.environ.get("CXX", "g++")) + self.assertIsNotNone(compiler) + mock = MOCK.replace("struct SPIClass {", """struct SPIClass { + explicit SPIClass(int = 0) {}""") + prelude = r''' +#include +#include +SPIClass SPI; +constexpr unsigned FSPI=2, HSPI=3; +constexpr unsigned P_LORA_NSS=1, P_LORA_DIO_1=2, P_LORA_RESET=3, P_LORA_BUSY=4; +struct InertBoard {}; +struct Module { + ArduinoHal* hal; + bool owned=false; + Module(ArduinoHal* h,unsigned cs,unsigned irq,unsigned reset,unsigned busy):hal(h) { + assert(cs==1 && irq==2 && reset==3 && busy==4); + } + Module(unsigned cs,unsigned irq,unsigned reset,unsigned busy) + :Module(new ArduinoHal(SPI,SPISettings(2000000,MSBFIRST,SPI_MODE0)),cs,irq,reset,busy) { + owned=true;hal->initInterface=true; + } + ~Module() { if(owned) delete hal; } +}; +struct Radio { + Module* module; + Radio(Module* m):module(m) {} + ~Radio() { delete module; } +}; +#define RADIO_CLASS Radio +''' + declarations = {8000000: [], 8888888: []} + calls = {8000000: [], 8888888: []} + for index, target in enumerate(TARGETS): + prefix, board = construction(target) + self.assertNotIn("sensecap_indicator", target) + for local in (True, False): + has_local = "static SPIClass spi" in prefix + if not local and has_local and "defined(P_LORA_SCLK)" not in prefix: + continue + if local and not has_local: + continue + clock = 8888888 if target == "lilygo_tdeck" else 8000000 + buffered = local or target not in LEGACY_FALLBACKS + expected = (4000000 if local else 2000000) if target == "heltec_rc32" else ( + clock if buffered else 2000000) + selected = "spi" if local else "::SPI" + name = f"target_{index}_{int(local)}" + options = f"#define P_LORA_SCLK 5\n" if local else "" + check = f''' +void check() {{ + auto& bus={selected};auto& hal=*radio.module->hal; + assert(hal.spi==&bus && hal.spiSettings.hz=={expected}); + assert(hal.spiSettings.order==MSBFIRST && hal.spiSettings.mode==SPI_MODE0); + bus.begins=bus.ends=bus.bursts=bus.bytes=0; + hal.init();hal.term(); + assert(bus.begins=={int(not local)} && bus.ends=={int(not local)}); + uint8_t tx[]={{1,2,3,4,5,6,7}},rx[7]={{}}; + hal.spiTransfer(tx,sizeof(tx),rx); + assert(bus.bursts=={int(buffered)} && bus.bytes=={0 if buffered else 7}); + for(unsigned i=0;i<7;++i) assert(rx[i]==uint8_t(tx[i]^0xa5)); +}} +''' + declarations[clock].append(options + f"namespace {name} {{\nusing {board}=InertBoard;\n" + + prefix + check + "}\n#undef P_LORA_SCLK\n") + calls[clock].append(f"{name}::check();") + self.assertEqual(len(TARGETS), 36) + self.assertEqual(sum(len(group) for group in calls.values()), 63) + with tempfile.TemporaryDirectory(prefix="esp32-buffered-targets-") as folder: + work = Path(folder) + (work / "hal/Arduino").mkdir(parents=True) + (work / "hal/Arduino/ArduinoHal.h").write_text(mock, encoding="ascii") + cpp, binary = work / "test.cpp", work / "test" + flags = [] if os.name == "nt" else ["-fsanitize=address,undefined", "-fno-pie", "-no-pie"] + # Parse the real helper's default argument once per recipe clock, + # without rewriting any production constructor or HAL type. + for clock in declarations: + code = (prelude + "\n".join(declarations[clock]) + + "\nint main(){" + "".join(calls[clock]) + "}\n") + legacy = code.replace( + "new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY)", + "new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY)", 1) + self.assertNotEqual(legacy, code) + for text, succeeds in ((code, True), (legacy, False)): + with self.subTest(clock=clock, buffered=succeeds): + cpp.write_text(text, encoding="ascii") + built = subprocess.run([compiler, "-std=c++17", "-Wall", "-Wextra", + "-DESP32_PLATFORM", f"-DMC_SX1262_SPI_HZ={clock}", *flags, + "-I", str(work), "-I", str(ROOT / "src"), + str(cpp), "-o", str(binary)], capture_output=True, text=True, timeout=60) + self.assertEqual(built.returncode, 0, built.stdout + built.stderr) + ran = subprocess.run([str(binary)], capture_output=True, text=True, timeout=20) + if succeeds: + self.assertEqual(ran.returncode, 0, ran.stdout + ran.stderr) + else: + self.assertNotEqual(ran.returncode, 0, "unbuffered constructor negative control passed") + + +if __name__ == "__main__": + unittest.main() diff --git a/test/test_lr1110_profile_switch.py b/test/test_lr1110_profile_switch.py index 39310748f..0fe08cbed 100644 --- a/test/test_lr1110_profile_switch.py +++ b/test/test_lr1110_profile_switch.py @@ -18,6 +18,7 @@ class LR1110ProfileSwitchTests(unittest.TestCase): "t1000-e": "Nrf52BufferedRadioHal", "wio_wm1110": "Nrf52BufferedRadioHal", "thinknode_m3": "Nrf52BufferedRadioHal", + "thinknode_m4": "Nrf52BufferedRadioHal", "minewsemi_me25ls01": "Nrf52BufferedRadioHal", "thinknode_m7": "ESP32BufferedRadioHal", "thinknode_m9": "ESP32BufferedRadioHal", diff --git a/test/test_profile_sx1262_iq_cache.py b/test/test_profile_sx1262_iq_cache.py index 6bf242af2..b39007f11 100644 --- a/test/test_profile_sx1262_iq_cache.py +++ b/test/test_profile_sx1262_iq_cache.py @@ -14,15 +14,35 @@ ROOT = Path(__file__).resolve().parents[1] class ProfileIqCacheTest(unittest.TestCase): - def test_only_qualified_recipes_opt_in(self): - opt_ins = [] - for recipe in (ROOT / "variants").glob("*/platformio.ini"): - if re.search(r"^\s*-D\s+MC_SX1262_FAST_IQ_CACHE=1\s*$", - recipe.read_text(), re.MULTILINE): - opt_ins.append(recipe.relative_to(ROOT).as_posix()) - self.assertCountEqual(opt_ins, ["variants/sensecap_indicator-espnow/platformio.ini", - "variants/lilygo_tdeck/platformio.ini", - "variants/rak3401/platformio.ini"]) + def test_shared_defaults_preserve_opt_outs_and_indicator_policy(self): + source = (ROOT / "src/helpers/radiolib/CustomSX1262.h").read_text() + defaults = source[source.index("#ifndef MC_SX1262_FAST_PROFILE_SWITCH"): + source.index("#ifndef SX126X_TX_BUSY_TIMEOUT_MS")] + cases = ( + ("", (1, 1, 1, 1, 1)), + ("#define MC_SX1262_FAST_PROFILE_SWITCH 0", (0, 0, 0, 0, 0)), + ("#define MC_SX1262_FAST_FS 0", (1, 0, 1, 0, 0)), + ("#define MC_SX1262_FAST_IQ_CACHE 0\n" + "#define MC_SX1262_FAST_MODEM_CACHE 0", (1, 1, 1, 0, 0)), + ("#define MC_SX1262_FAST_PACKET_CACHE 0", (1, 1, 0, 1, 1)), + ) + # Use the real expander recipe: its explicit IQ reuse remains on, + # while its FS and packet opt-outs keep modem-query reuse off. + indicator = (ROOT / "variants/sensecap_indicator-espnow/platformio.ini").read_text() + section = indicator.split("[SenseCapIndicator-LoRa]", 1)[1].split("\n[", 1)[0] + flags = re.findall(r"^\s*-D\s+(MC_SX1262_FAST_\w+=\d+)\s*$", + section, re.MULTILINE) + self.assertGreaterEqual(len(flags), 4) + cases += (("\n".join("#define " + flag.replace("=", " ") for flag in flags), + (1, 0, 0, 1, 0)),) + names = ("PROFILE_SWITCH", "FS", "PACKET_CACHE", "IQ_CACHE", "MODEM_CACHE") + for overrides, expected in cases: + with self.subTest(overrides=overrides): + assertions = "\n".join( + f'static_assert(MC_SX1262_FAST_{name} == {value}, "{name}");' + for name, value in zip(names, expected)) + self.compile_run(overrides + "\n" + defaults + "\n" + assertions + + "\nint main() {}\n") def compile_run(self, source): with tempfile.TemporaryDirectory() as folder: @@ -246,12 +266,10 @@ int main() { with self.subTest(definitions=definitions): self.compile_run(fixture.replace("@DEFINES@", definitions)) - def test_unqualified_boards_keep_the_original_live_modem_query_and_iq_path(self): + def test_explicit_cache_opt_outs_keep_live_queries_and_owned_gates(self): source = (ROOT / "src/helpers/radiolib/CustomSX1262.h").read_text() - self.assertIn("#define MC_SX1262_FAST_IQ_CACHE 0", source) - self.assertIn("#define MC_SX1262_FAST_MODEM_CACHE 0", source) - # Execute the shared production-method fixture: default-off builds must - # query the modem, while opted-in/HIL reuse must retain all ownership, + # Execute the shared production-method fixture: explicit opt-outs must + # query the modem, while enabled/HIL reuse must retain all ownership, # initialization and failure gates. Do not depend on an if's spelling. modem_cache.ModemCacheTests.test_confirmed_modem_requires_owned_warm_rx_and_survives_no_failure(self) helper = method(source, "int16_t writeProfilePacketParams(") diff --git a/test/test_rak3401_onboard_radio.py b/test/test_rak3401_onboard_radio.py index 9353da1bc..498b7c022 100644 --- a/test/test_rak3401_onboard_radio.py +++ b/test/test_rak3401_onboard_radio.py @@ -468,7 +468,9 @@ class Rak3401OnboardRadioTests(unittest.TestCase): self.assertIn("digitalWrite(SX126X_POWER_EN, HIGH);", begin) init = extract_braced(target, "bool radio_init()") self.assertIn("radio.std_init(&SPI)", init) - self.assertIn("P_LORA_RESET, P_LORA_BUSY, SPI)", target) + self.assertIn("SX126xBufferedRadioHal radioHal(SPI)", target) + self.assertIn("new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, " + "P_LORA_RESET, P_LORA_BUSY)", target) # External-radio construction and retry must retain their SPI1 owner. external_target = (VARIANT / "target.cpp").read_text() self.assertIn("Nrf52BufferedRadioHal radioHal(SPI1, 8000000)", external_target) diff --git a/test/test_sx126x_buffered_radio_hal.py b/test/test_sx126x_buffered_radio_hal.py new file mode 100644 index 000000000..f0af406db --- /dev/null +++ b/test/test_sx126x_buffered_radio_hal.py @@ -0,0 +1,145 @@ +"""Execute portable radio SPI buffering, settings and bus ownership.""" +from pathlib import Path +import os +import re +import shutil +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[1] +RADIO = ROOT / "src/helpers/radiolib" + +MOCK = r''' +#pragma once +#include +#include +#include +constexpr unsigned MSBFIRST=1, SPI_MODE0=0; +struct SPISettings { + unsigned hz, order, mode; + SPISettings(unsigned h, unsigned o, unsigned m) : hz(h), order(o), mode(m) {} +}; +struct SPIClass { + unsigned bursts=0, bytes=0, begins=0, ends=0; + const void* lastOut=nullptr; void* lastIn=nullptr; size_t lastLength=0; + void begin() { ++begins; } + void end() { ++ends; } + void burst(const void* out, void* in, size_t length) { + ++bursts; lastOut=out; lastIn=in; lastLength=length; + const auto* tx=static_cast(out); + auto* rx=static_cast(in); + for (size_t i=0; ibegin(); } + virtual void term() { if (initInterface) spi->end(); } + virtual void spiTransfer(uint8_t* out,size_t length,uint8_t* in) { + for (size_t i=0;itransfer(out[i]); + } +}; +''' + +FIXTURE = r''' +#include +#include +#include +SPIClass unused, explicitBus, fallbackBus; +int main() { + SX126xBufferedRadioHal external(explicitBus); + SX126xBufferedRadioHal fallback(fallbackBus,MC_SX1262_SPI_HZ,true); + SX126xBufferedRadioHal slower(explicitBus,4000000); + assert(external.spiSettings.hz == MC_SX1262_SPI_HZ); + assert(slower.spiSettings.hz == 4000000); + assert(external.spiSettings.order == MSBFIRST && external.spiSettings.mode == SPI_MODE0); + assert(!external.initInterface && fallback.initInterface); + ArduinoHal& hal=external; + hal.init(); hal.term(); + assert(explicitBus.begins==0 && explicitBus.ends==0); + fallback.init(); fallback.term(); + assert(fallbackBus.begins==1 && fallbackBus.ends==1); + // A board/storage handoff can restart this SAME bus without replacing HAL. + explicitBus.end(); explicitBus.begin(); + assert(hal.spi == &explicitBus); + std::array tx{}, rx{}; + for (size_t i=0;i +constexpr unsigned P_LORA_NSS=1,P_LORA_DIO_1=2,P_LORA_RESET=3,P_LORA_BUSY=4; +struct Module { + ArduinoHal* hal; bool owned=false; + Module(ArduinoHal* adapter,unsigned cs,unsigned irq,unsigned reset,unsigned busy) + : hal(adapter) { assert(cs==1 && irq==2 && reset==3 && busy==4); } + Module(unsigned cs,unsigned irq,unsigned reset,unsigned busy,SPIClass& bus) + : hal(new ArduinoHal(bus,SPISettings(2000000,MSBFIRST,SPI_MODE0))),owned(true) { + assert(cs==1 && irq==2 && reset==3 && busy==4); + } + ~Module() { if (owned) delete hal; } +}; +struct Radio { + Module* mod; + Radio(Module* value) : mod(value) {} + ~Radio() { delete mod; } +}; +#define RADIO_CLASS Radio +''' + + +def target_sources(architecture): + sources=set() + for config in sorted((ROOT/"variants").glob("*/platformio.ini")): + text=config.read_text() + if not re.search(r"^\s*-D\s+RADIO_CLASS=CustomSX1262\s*$",text,re.MULTILINE): + continue + base=re.search(r"^extends\s*=\s*(\S+)",text,re.MULTILINE) + if not base or base.group(1) not in architecture: + continue + if config.parent.name=="rak3401": + continue # Dedicated physical-board test pins its qualified SPI1 setup. + source=config.with_name("target.cpp") + if config.parent.name=="wio-tracker-l1-eink": + source=ROOT/"variants/wio-tracker-l1/target.cpp" + sources.add(source) + return sorted(sources) + + +class SX126xTargetConstructors(unittest.TestCase): + def compile_run(self,architecture,source,*,defines=()): + compiler=shutil.which(os.environ.get("CXX","g++")) + self.assertIsNotNone(compiler) + with tempfile.TemporaryDirectory(prefix="sx126x-target-constructors-") as folder: + base=Path(folder) + (base/"hal/Arduino").mkdir(parents=True) + (base/"hal/Arduino/ArduinoHal.h").write_text(MOCK,encoding="ascii") + cpp,executable=base/"test.cpp",base/"test" + cpp.write_text(source,encoding="ascii") + built=subprocess.run([compiler,"-std=c++17","-Wall","-Wextra","-Werror", + f"-D{architecture}",*[f"-D{item}" for item in defines],"-I",str(base), + "-I",str(ROOT/"src"),str(cpp),"-o",str(executable)], + capture_output=True,text=True,timeout=60) + self.assertEqual(built.returncode,0,built.stdout+built.stderr) + ran=subprocess.run([str(executable)],capture_output=True,text=True,timeout=10) + self.assertEqual(ran.returncode,0,ran.stdout+ran.stderr) + + def test_all_actual_nrf52_and_rp2040_constructions_keep_selected_bus(self): + for arch,bases in (("NRF52_PLATFORM",{"nrf52_base","rak4631_hw"}), + ("RP2040_PLATFORM",{"rp2040_base"})): + with self.subTest(architecture=arch): + cases=[] + sources=target_sources(bases) + self.assertTrue(sources) + for source in sources: + text=source.read_text() + self.assertIn("#include ", + text,str(source)) + constructions=re.findall( + r"^static SX126xBufferedRadioHal radioHal\(([^;]+)\);\n" + r"(RADIO_CLASS radio = new Module\(&radioHal,[^;]+;)", + text,re.MULTILINE) + self.assertTrue(constructions,str(source)) + # Every direct Module construction is now buffered except + # the deliberately unchanged Muzi Duo LR1121 selection. + legacy=re.findall(r"new Module\(P_LORA_NSS[^;]+;",text) + self.assertEqual(len(legacy),1 if source.parent.name=="muzi_base" else 0, + str(source)) + for ordinal,(arguments,module) in enumerate(constructions): + bus=arguments.split(",")[0] + expected_bus="SPI1" if source.parent.name in { + "rak11310","rpi_picow","waveshare_rp2040_lora"} else "SPI" + self.assertEqual(bus,expected_bus,str(source)) + # These are the pre-existing Module() default-bus + # branches. Every other constructor passed its bus + # explicitly and must leave begin/end board-owned. + owns=source.parent.name=="xiao_rp2040" or ( + source.parent.name in {"heltec_t096","heltec_t1","heltec_t114"} + and ordinal==1) + name=f"case_{len(cases)}" + cases.append((name,f''' +namespace {name} {{ +SPIClass SPI,SPI1; +static SX126xBufferedRadioHal radioHal({arguments}); +{module} +void check() {{ + assert(radio.mod->hal==&radioHal && radioHal.spi==&{bus}); + assert(radioHal.spiSettings.hz==8000000); + assert(radioHal.initInterface=={str(owns).lower()}); + radio.mod->hal->init();radio.mod->hal->term(); + assert({bus}.begins=={int(owns)} && {bus}.ends=={int(owns)}); +}} +}} +''')) + fixture=PREFIX+"\n".join(code for _,code in cases) + fixture+="\nint main() {"+"".join(f"{name}::check();" for name,_ in cases)+"}\n" + self.compile_run(arch,fixture) + + def test_muzi_uno_selection_does_not_change_the_lr1121_duo_constructor(self): + text=(ROOT/"variants/muzi_base/target.cpp").read_text() + block=re.search(r"^#if defined\(USE_SX1262\)\nstatic SX126xBufferedRadioHal " + r"radioHal\([^#]+#else\n[^#]+#endif",text,re.MULTILINE) + self.assertIsNotNone(block) + fixture=PREFIX+"\nSPIClass SPI;\n"+block.group(0)+r''' +int main() { + assert(radio.mod->hal->spi==&SPI); +#ifdef USE_SX1262 + assert(!radio.mod->owned && radio.mod->hal==&radioHal); + assert(radio.mod->hal->spiSettings.hz==8000000); +#else + assert(radio.mod->owned && radio.mod->hal->spiSettings.hz==2000000); +#endif +} +''' + for definitions in ((),("USE_SX1262",)): + with self.subTest(defines=definitions): + self.compile_run("NRF52_PLATFORM",fixture,defines=definitions) + + def test_lr1110_m4_keeps_manual_spi_start_and_uses_buffered_8mhz_bus(self): + text=(ROOT/"variants/thinknode_m4/target.cpp").read_text() + construction=re.search(r"^static Nrf52BufferedRadioHal radioHal\([^;]+;\n" + r"RADIO_CLASS radio = new Module\([^;]+;",text,re.MULTILINE) + self.assertIsNotNone(construction) + self.assertIn("SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);",text) + self.assertIn("SPI.begin();",text) + self.assertIn("int status = radio.begin(",text) + fixture=PREFIX+"\nSPIClass SPI;\n"+construction.group(0)+r''' +int main() { + assert(radio.mod->hal==&radioHal && radioHal.spi==&SPI); + assert(radioHal.spiSettings.hz==8000000 && !radioHal.initInterface); + radio.mod->hal->init();radio.mod->hal->term(); + assert(SPI.begins==0 && SPI.ends==0); + uint8_t tx[]={1,0x7f,0xff},rx[3]={}; + radio.mod->hal->spiTransfer(tx,3,rx); + assert(SPI.bursts==1 && SPI.bytes==0 && rx[0]==(1^0xa5)); +} +''' + self.compile_run("NRF52_PLATFORM",fixture) + + +if __name__=="__main__": + unittest.main() diff --git a/variants/ebyte_eora_s3/target.cpp b/variants/ebyte_eora_s3/target.cpp index 91d851ff3..d8b0b0a6a 100644 --- a/variants/ebyte_eora_s3/target.cpp +++ b/variants/ebyte_eora_s3/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include ESP32Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/gat562_30s_mesh_kit/target.cpp b/variants/gat562_30s_mesh_kit/target.cpp index 8f84a7a19..e2468f37a 100644 --- a/variants/gat562_30s_mesh_kit/target.cpp +++ b/variants/gat562_30s_mesh_kit/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include GAT56230SMeshKitBoard board; @@ -18,7 +19,8 @@ GAT56230SMeshKitBoard board; #endif -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/gat562_mesh_evb_pro/target.cpp b/variants/gat562_mesh_evb_pro/target.cpp index 8dc203de9..478f3adbb 100644 --- a/variants/gat562_mesh_evb_pro/target.cpp +++ b/variants/gat562_mesh_evb_pro/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include GAT562EVBProBoard board; @@ -17,7 +18,8 @@ GAT562EVBProBoard board; #endif -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/gat562_mesh_tracker_pro/target.cpp b/variants/gat562_mesh_tracker_pro/target.cpp index d16b45381..e6ed605ea 100644 --- a/variants/gat562_mesh_tracker_pro/target.cpp +++ b/variants/gat562_mesh_tracker_pro/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include GAT562MeshTrackerProBoard board; @@ -18,7 +19,8 @@ GAT562MeshTrackerProBoard board; #endif -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/gat562_mesh_watch13/target.cpp b/variants/gat562_mesh_watch13/target.cpp index 95bcf6dc2..0384d046c 100644 --- a/variants/gat562_mesh_watch13/target.cpp +++ b/variants/gat562_mesh_watch13/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include GAT56MeshWatch13Board board; @@ -15,7 +16,8 @@ GAT56MeshWatch13Board board; #endif -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/generic-e22/target.cpp b/variants/generic-e22/target.cpp index 26bba1c07..882894380 100644 --- a/variants/generic-e22/target.cpp +++ b/variants/generic-e22/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include ESP32Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_ct62/target.cpp b/variants/heltec_ct62/target.cpp index 522c31992..f13c6a6e8 100644 --- a/variants/heltec_ct62/target.cpp +++ b/variants/heltec_ct62/target.cpp @@ -1,9 +1,11 @@ #include #include "target.h" +#include Heltec_CT62_Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); +RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); ESP32RTCClock fallback_clock; diff --git a/variants/heltec_e213/target.cpp b/variants/heltec_e213/target.cpp index 6914769d9..55b2d069b 100644 --- a/variants/heltec_e213/target.cpp +++ b/variants/heltec_e213/target.cpp @@ -1,13 +1,16 @@ #include "target.h" +#include #include HeltecE213Board board; #if defined(P_LORA_SCLK) static SPIClass spi(FSPI); - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_e290/target.cpp b/variants/heltec_e290/target.cpp index f23279548..e2179aa03 100644 --- a/variants/heltec_e290/target.cpp +++ b/variants/heltec_e290/target.cpp @@ -1,13 +1,16 @@ #include "target.h" +#include #include HeltecE290Board board; #if defined(P_LORA_SCLK) static SPIClass spi(FSPI); - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_mesh_solar/target.cpp b/variants/heltec_mesh_solar/target.cpp index dd95882ba..493256076 100644 --- a/variants/heltec_mesh_solar/target.cpp +++ b/variants/heltec_mesh_solar/target.cpp @@ -1,11 +1,13 @@ #include #include "target.h" +#include #include #include MeshSolarBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_rc32/target.cpp b/variants/heltec_rc32/target.cpp index 233b31bd8..8cc736d73 100644 --- a/variants/heltec_rc32/target.cpp +++ b/variants/heltec_rc32/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #if defined(UI_HAS_ROTARY_INPUT) #include "HeltecRC32RotaryInput.h" #endif @@ -8,10 +9,11 @@ HeltecRC32Board board; #if defined(P_LORA_SCLK) static SPIClass spi(FSPI); - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi, - SPISettings(4000000, MSBFIRST, SPI_MODE0)); + static SX126xBufferedRadioHal radio_hal(spi, 4000000); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, 2000000, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_t096/target.cpp b/variants/heltec_t096/target.cpp index 0ff5b7dba..0a24e675f 100644 --- a/variants/heltec_t096/target.cpp +++ b/variants/heltec_t096/target.cpp @@ -1,4 +1,5 @@ #include "target.h" +#include #include #include @@ -10,9 +11,11 @@ T096Board board; #if defined(P_LORA_SCLK) -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +static SX126xBufferedRadioHal radioHal(SPI, MC_SX1262_SPI_HZ, true); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_t1/target.cpp b/variants/heltec_t1/target.cpp index af771582d..f54f9c19c 100644 --- a/variants/heltec_t1/target.cpp +++ b/variants/heltec_t1/target.cpp @@ -1,4 +1,5 @@ #include "target.h" +#include #include #include @@ -10,9 +11,11 @@ T1Board board; #if defined(P_LORA_SCLK) -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +static SX126xBufferedRadioHal radioHal(SPI, MC_SX1262_SPI_HZ, true); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_t114/target.cpp b/variants/heltec_t114/target.cpp index 90a902f80..8d4cb076e 100644 --- a/variants/heltec_t114/target.cpp +++ b/variants/heltec_t114/target.cpp @@ -1,4 +1,5 @@ #include "target.h" +#include #include #include @@ -10,9 +11,11 @@ T114Board board; #if defined(P_LORA_SCLK) -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +static SX126xBufferedRadioHal radioHal(SPI, MC_SX1262_SPI_HZ, true); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_t190/target.cpp b/variants/heltec_t190/target.cpp index 6a2eab7d8..f54552cbd 100644 --- a/variants/heltec_t190/target.cpp +++ b/variants/heltec_t190/target.cpp @@ -1,13 +1,16 @@ #include "target.h" +#include #include HeltecT190Board board; #if defined(P_LORA_SCLK) static SPIClass spi(FSPI); - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_tower_v2/target.cpp b/variants/heltec_tower_v2/target.cpp index ec8e7a17d..e44e6afa6 100644 --- a/variants/heltec_tower_v2/target.cpp +++ b/variants/heltec_tower_v2/target.cpp @@ -1,4 +1,5 @@ #include "target.h" +#include #include #include @@ -6,7 +7,8 @@ HeltecTowerV2Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_tracker/target.cpp b/variants/heltec_tracker/target.cpp index 9d514fae3..10c18164b 100644 --- a/variants/heltec_tracker/target.cpp +++ b/variants/heltec_tracker/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include @@ -7,9 +8,11 @@ HeltecV3Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_tracker_v2/target.cpp b/variants/heltec_tracker_v2/target.cpp index bd50ac6e6..903e59970 100644 --- a/variants/heltec_tracker_v2/target.cpp +++ b/variants/heltec_tracker_v2/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include HeltecTrackerV2Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_v3/target.cpp b/variants/heltec_v3/target.cpp index 94f8e7964..09f2166e7 100644 --- a/variants/heltec_v3/target.cpp +++ b/variants/heltec_v3/target.cpp @@ -1,5 +1,8 @@ #include #include "target.h" +#ifndef SIM_BUILD +#include +#endif HeltecV3Board board; @@ -8,9 +11,11 @@ HeltecV3Board board; #else #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_v4/target.cpp b/variants/heltec_v4/target.cpp index 03205e5f5..65dd07c7f 100644 --- a/variants/heltec_v4/target.cpp +++ b/variants/heltec_v4/target.cpp @@ -1,11 +1,7 @@ #include #include "target.h" -// Normal V4 images retain the established RadioLib Arduino HAL. The KISS -// modem can opt into buffered SPI for its on-board dual-profile RX scanner. -#if defined(MC_SX1262_BUFFERED_RADIO_HAL) && MC_SX1262_BUFFERED_RADIO_HAL - #include -#endif +#include HeltecV4Board board; @@ -34,14 +30,11 @@ const char meshcore_capability_heltec_v4_tft_kit[] = #if defined(P_LORA_SCLK) static SPIClass spi; - #if defined(MC_SX1262_BUFFERED_RADIO_HAL) && MC_SX1262_BUFFERED_RADIO_HAL - static ESP32BufferedRadioHal radio_hal(spi); - RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); - #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); - #endif + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_v4_r8/target.cpp b/variants/heltec_v4_r8/target.cpp index 4fa967560..353fc398d 100644 --- a/variants/heltec_v4_r8/target.cpp +++ b/variants/heltec_v4_r8/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include HeltecV4R8Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/heltec_wireless_paper/target.cpp b/variants/heltec_wireless_paper/target.cpp index be21695ec..490dcbbde 100644 --- a/variants/heltec_wireless_paper/target.cpp +++ b/variants/heltec_wireless_paper/target.cpp @@ -1,13 +1,16 @@ #include "target.h" +#include #include HeltecWirelessPaperBoard board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/ikoka_handheld_nrf/target.cpp b/variants/ikoka_handheld_nrf/target.cpp index 6c53c5e32..995c2f441 100644 --- a/variants/ikoka_handheld_nrf/target.cpp +++ b/variants/ikoka_handheld_nrf/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include #include IkokaNrf52Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/ikoka_nano_nrf/target.cpp b/variants/ikoka_nano_nrf/target.cpp index baf02c3d1..37d3412d7 100644 --- a/variants/ikoka_nano_nrf/target.cpp +++ b/variants/ikoka_nano_nrf/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include IkokaNanoNRFBoard board; @@ -9,7 +10,8 @@ IkokaNanoNRFBoard board; // MomentaryButton user_btn(PIN_USER_BTN, 1000, true); #endif -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/ikoka_stick_nrf/target.cpp b/variants/ikoka_stick_nrf/target.cpp index bb140505a..4403e8004 100644 --- a/variants/ikoka_stick_nrf/target.cpp +++ b/variants/ikoka_stick_nrf/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include IkokaStickNRFBoard board; @@ -9,7 +10,8 @@ IkokaStickNRFBoard board; MomentaryButton user_btn(PIN_USER_BTN, 1000, true); #endif -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/keepteen_lt1/target.cpp b/variants/keepteen_lt1/target.cpp index 72c627b41..898dedf3d 100644 --- a/variants/keepteen_lt1/target.cpp +++ b/variants/keepteen_lt1/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include #include KeepteenLT1Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/lilygo_t3s3/target.cpp b/variants/lilygo_t3s3/target.cpp index 34df31c3b..ff357d367 100644 --- a/variants/lilygo_t3s3/target.cpp +++ b/variants/lilygo_t3s3/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include ESP32Board board; static SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +static SX126xBufferedRadioHal radio_hal(spi); +RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); ESP32RTCClock fallback_clock; diff --git a/variants/lilygo_t_impulse_plus/target.cpp b/variants/lilygo_t_impulse_plus/target.cpp index 87b3dbfed..62d80b205 100644 --- a/variants/lilygo_t_impulse_plus/target.cpp +++ b/variants/lilygo_t_impulse_plus/target.cpp @@ -1,11 +1,13 @@ #include #include "target.h" +#include #include #include TImpulsePlusBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/lilygo_tbeam_1w/target.cpp b/variants/lilygo_tbeam_1w/target.cpp index d57e3f4e0..2bdd783cc 100644 --- a/variants/lilygo_tbeam_1w/target.cpp +++ b/variants/lilygo_tbeam_1w/target.cpp @@ -2,6 +2,7 @@ #include #include #include "target.h" +#include TBeam1WBoard board; @@ -20,7 +21,8 @@ static SPIClass spi; static bool target_peripherals_initialized = false; static bool target_radio_available = false; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +static SX126xBufferedRadioHal radio_hal(spi); +RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/lilygo_tbeam_SX1262/target.cpp b/variants/lilygo_tbeam_SX1262/target.cpp index 657e01f16..74715d4ec 100644 --- a/variants/lilygo_tbeam_SX1262/target.cpp +++ b/variants/lilygo_tbeam_SX1262/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include TBeamBoard board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/lilygo_tbeam_supreme_SX1262/target.cpp b/variants/lilygo_tbeam_supreme_SX1262/target.cpp index 58d5e79a6..128613c46 100644 --- a/variants/lilygo_tbeam_supreme_SX1262/target.cpp +++ b/variants/lilygo_tbeam_supreme_SX1262/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include TBeamBoard board; @@ -10,7 +11,8 @@ TBeamBoard board; static SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +static SX126xBufferedRadioHal radio_hal(spi); +RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/lilygo_techo/target.cpp b/variants/lilygo_techo/target.cpp index 278fc76da..29c422810 100644 --- a/variants/lilygo_techo/target.cpp +++ b/variants/lilygo_techo/target.cpp @@ -1,11 +1,13 @@ #include #include "target.h" +#include #include #include TechoBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/lilygo_techo_card/target.cpp b/variants/lilygo_techo_card/target.cpp index 8bbe03633..bc5bca598 100644 --- a/variants/lilygo_techo_card/target.cpp +++ b/variants/lilygo_techo_card/target.cpp @@ -1,11 +1,13 @@ #include #include "target.h" +#include #include #include TechoCardBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/lilygo_techo_lite/target.cpp b/variants/lilygo_techo_lite/target.cpp index 95a62fcd2..20628820f 100644 --- a/variants/lilygo_techo_lite/target.cpp +++ b/variants/lilygo_techo_lite/target.cpp @@ -1,11 +1,13 @@ #include #include "target.h" +#include #include #include TechoBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/lilygo_teth_elite/target.cpp b/variants/lilygo_teth_elite/target.cpp index 4dc377d62..adbde4d7d 100644 --- a/variants/lilygo_teth_elite/target.cpp +++ b/variants/lilygo_teth_elite/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include TETHEliteBoard board; static SPIClass spi(HSPI); -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +static SX126xBufferedRadioHal radio_hal(spi); +RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); ESP32RTCClock fallback_clock; diff --git a/variants/lilygo_tlora_c6/target.cpp b/variants/lilygo_tlora_c6/target.cpp index d70e9b791..0d6e50531 100644 --- a/variants/lilygo_tlora_c6/target.cpp +++ b/variants/lilygo_tlora_c6/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include ESP32Board board; #if defined(P_LORA_SCLK) static SPIClass spi(0); - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/m5stack_unit_c6l/UnitC6LBoard.cpp b/variants/m5stack_unit_c6l/UnitC6LBoard.cpp index ab192ebef..66529618d 100644 --- a/variants/m5stack_unit_c6l/UnitC6LBoard.cpp +++ b/variants/m5stack_unit_c6l/UnitC6LBoard.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include UnitC6LBoard board; #if defined(P_LORA_SCLK) static SPIClass spi(0); - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/mesh_pocket/target.cpp b/variants/mesh_pocket/target.cpp index ee8f944de..c8d147a75 100644 --- a/variants/mesh_pocket/target.cpp +++ b/variants/mesh_pocket/target.cpp @@ -1,11 +1,13 @@ #include #include "target.h" +#include #include #include HeltecMeshPocket board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/meshadventurer/target.cpp b/variants/meshadventurer/target.cpp index a9213dfb5..067825239 100644 --- a/variants/meshadventurer/target.cpp +++ b/variants/meshadventurer/target.cpp @@ -1,12 +1,14 @@ #include #include "target.h" +#include #include MeshadventurerBoard board; static SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +static SX126xBufferedRadioHal radio_hal(spi); +RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); ESP32RTCClock fallback_clock; diff --git a/variants/meshtiny/target.cpp b/variants/meshtiny/target.cpp index 50d678266..dd5e13277 100644 --- a/variants/meshtiny/target.cpp +++ b/variants/meshtiny/target.cpp @@ -1,11 +1,13 @@ #include "target.h" +#include #include #include MeshtinyBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/mke_s3/target.cpp b/variants/mke_s3/target.cpp index 0878c623b..8df0dcd4f 100644 --- a/variants/mke_s3/target.cpp +++ b/variants/mke_s3/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include MKES3Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/muzi_base/target.cpp b/variants/muzi_base/target.cpp index 3d89a7c27..7e394994b 100644 --- a/variants/muzi_base/target.cpp +++ b/variants/muzi_base/target.cpp @@ -1,11 +1,17 @@ #include #include #include "target.h" +#include #include "variant.h" MuziBaseBoard board; +#if defined(USE_SX1262) +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +#else RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +#endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/muziworks_r1_neo/target.cpp b/variants/muziworks_r1_neo/target.cpp index b0840a34e..e3a62b72b 100644 --- a/variants/muziworks_r1_neo/target.cpp +++ b/variants/muziworks_r1_neo/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include #include R1NeoBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); #ifdef DISPLAY_CLASS diff --git a/variants/nano_g2_ultra/target.cpp b/variants/nano_g2_ultra/target.cpp index 04b373341..aa5f00050 100644 --- a/variants/nano_g2_ultra/target.cpp +++ b/variants/nano_g2_ultra/target.cpp @@ -1,4 +1,5 @@ #include "target.h" +#include #include #include @@ -6,7 +7,8 @@ NanoG2Ultra board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/nibble_screen_connect/target.cpp b/variants/nibble_screen_connect/target.cpp index ceb9fe49c..0bc824f99 100644 --- a/variants/nibble_screen_connect/target.cpp +++ b/variants/nibble_screen_connect/target.cpp @@ -1,34 +1,36 @@ -#include -#include "target.h" - -ESP32Board board; - -static SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); -WRAPPER_CLASS radio_driver(radio, board); - -ESP32RTCClock fallback_clock; -AutoDiscoverRTCClock rtc_clock(fallback_clock); -SensorManager sensors; - -#ifdef DISPLAY_CLASS - DISPLAY_CLASS display; - MomentaryButton user_btn(PIN_USER_BTN, 1000, true); -#endif - -#ifndef LORA_CR - #define LORA_CR 5 -#endif - -bool radio_init() { - fallback_clock.begin(); - rtc_clock.begin(Wire); - - return radio.std_init(&spi); -} - -mesh::LocalIdentity radio_new_identity() { - RadioNoiseListener rng(radio); - return mesh::LocalIdentity(&rng); -} - +#include +#include "target.h" +#include + +ESP32Board board; + +static SPIClass spi; +static SX126xBufferedRadioHal radio_hal(spi); +RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +WRAPPER_CLASS radio_driver(radio, board); + +ESP32RTCClock fallback_clock; +AutoDiscoverRTCClock rtc_clock(fallback_clock); +SensorManager sensors; + +#ifdef DISPLAY_CLASS + DISPLAY_CLASS display; + MomentaryButton user_btn(PIN_USER_BTN, 1000, true); +#endif + +#ifndef LORA_CR + #define LORA_CR 5 +#endif + +bool radio_init() { + fallback_clock.begin(); + rtc_clock.begin(Wire); + + return radio.std_init(&spi); +} + +mesh::LocalIdentity radio_new_identity() { + RadioNoiseListener rng(radio); + return mesh::LocalIdentity(&rng); +} + diff --git a/variants/nibble_zero_connect/target.cpp b/variants/nibble_zero_connect/target.cpp index d53b6a1c3..a60cc37fc 100644 --- a/variants/nibble_zero_connect/target.cpp +++ b/variants/nibble_zero_connect/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include ESP32Board board; static SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +static SX126xBufferedRadioHal radio_hal(spi); +RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); ESP32RTCClock fallback_clock; diff --git a/variants/promicro/target.cpp b/variants/promicro/target.cpp index 065d628f1..b13df7665 100644 --- a/variants/promicro/target.cpp +++ b/variants/promicro/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include #include PromicroBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/rak11310/target.cpp b/variants/rak11310/target.cpp index 4c2889750..85b0ebb7d 100644 --- a/variants/rak11310/target.cpp +++ b/variants/rak11310/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include #include RAK11310Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI1); +static SX126xBufferedRadioHal radioHal(SPI1); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/rak3112/target.cpp b/variants/rak3112/target.cpp index 57829aae5..261250154 100644 --- a/variants/rak3112/target.cpp +++ b/variants/rak3112/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include RAK3112Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/rak4631/target.cpp b/variants/rak4631/target.cpp index a41ba7207..5edd7b0cf 100644 --- a/variants/rak4631/target.cpp +++ b/variants/rak4631/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include RAK4631Board board; @@ -17,7 +18,8 @@ RAK4631Board board; #endif #endif -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/rak_wismesh_tag/target.cpp b/variants/rak_wismesh_tag/target.cpp index 4547ef510..4bacfd6dc 100644 --- a/variants/rak_wismesh_tag/target.cpp +++ b/variants/rak_wismesh_tag/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include RAKWismeshTagBoard board; @@ -13,7 +14,8 @@ RAKWismeshTagBoard board; MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true); #endif -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/rpi_picow/target.cpp b/variants/rpi_picow/target.cpp index 9318b7f0f..848837ffa 100644 --- a/variants/rpi_picow/target.cpp +++ b/variants/rpi_picow/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include #include PicoWBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI1); +static SX126xBufferedRadioHal radioHal(SPI1); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/sensecap_solar/target.cpp b/variants/sensecap_solar/target.cpp index 022e8a9b4..3ada0ab02 100644 --- a/variants/sensecap_solar/target.cpp +++ b/variants/sensecap_solar/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include #if ENV_INCLUDE_GPS @@ -8,7 +9,8 @@ SenseCapSolarBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/station_g2/target.cpp b/variants/station_g2/target.cpp index 8018c20eb..9992c9a50 100644 --- a/variants/station_g2/target.cpp +++ b/variants/station_g2/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include StationG2Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/station_g3_esp32/target.cpp b/variants/station_g3_esp32/target.cpp index a971cff57..17ffa5dcd 100644 --- a/variants/station_g3_esp32/target.cpp +++ b/variants/station_g3_esp32/target.cpp @@ -3,12 +3,7 @@ #include "StationG3BootRecovery.h" #include -// The normal Station G3 roles retain the established RadioLib Arduino HAL. -// The KISS modem can opt into buffered SPI for its on-board dual-profile RX -// scanner without changing the regular Station firmware. -#if defined(MC_SX1262_BUFFERED_RADIO_HAL) && MC_SX1262_BUFFERED_RADIO_HAL - #include -#endif +#include StationG3Board board; @@ -20,14 +15,11 @@ const char meshcore_capability_station_g3_auto_slots[] __attribute__((used)) = #if defined(P_LORA_SCLK) static SPIClass spi; - #if defined(MC_SX1262_BUFFERED_RADIO_HAL) && MC_SX1262_BUFFERED_RADIO_HAL - static ESP32BufferedRadioHal radio_hal(spi); - RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); - #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); - #endif + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/tenstar_c3/target.cpp b/variants/tenstar_c3/target.cpp index 909625edf..3e12e4f8e 100644 --- a/variants/tenstar_c3/target.cpp +++ b/variants/tenstar_c3/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include XiaoC3Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/thinknode_m1/target.cpp b/variants/thinknode_m1/target.cpp index 2cfab4bae..7ce5fd6c7 100644 --- a/variants/thinknode_m1/target.cpp +++ b/variants/thinknode_m1/target.cpp @@ -1,11 +1,13 @@ #include #include "target.h" +#include #include #include ThinkNodeM1Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/thinknode_m2/target.cpp b/variants/thinknode_m2/target.cpp index ff0dd6cf4..013223ba0 100644 --- a/variants/thinknode_m2/target.cpp +++ b/variants/thinknode_m2/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include ThinknodeM2Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/thinknode_m4/target.cpp b/variants/thinknode_m4/target.cpp index 7da3f400d..8472c23bd 100644 --- a/variants/thinknode_m4/target.cpp +++ b/variants/thinknode_m4/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include #include ThinkNodeM4Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static Nrf52BufferedRadioHal radioHal(SPI, 8000000); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); @@ -81,4 +83,4 @@ bool radio_init() { mesh::LocalIdentity radio_new_identity() { RadioNoiseListener rng(radio); return mesh::LocalIdentity(&rng); // create new random identity -} \ No newline at end of file +} diff --git a/variants/thinknode_m5/target.cpp b/variants/thinknode_m5/target.cpp index be534f67d..ac851fc5a 100644 --- a/variants/thinknode_m5/target.cpp +++ b/variants/thinknode_m5/target.cpp @@ -1,14 +1,17 @@ #include #include "target.h" +#include #include ThinknodeM5Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/thinknode_m6/target.cpp b/variants/thinknode_m6/target.cpp index de167194e..27cfb574d 100644 --- a/variants/thinknode_m6/target.cpp +++ b/variants/thinknode_m6/target.cpp @@ -1,11 +1,13 @@ #include #include "target.h" +#include #include #include ThinkNodeM6Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/thinknode_m8/target.cpp b/variants/thinknode_m8/target.cpp index ac4ac100e..21a1fa7d6 100644 --- a/variants/thinknode_m8/target.cpp +++ b/variants/thinknode_m8/target.cpp @@ -1,12 +1,14 @@ #include #include "target.h" +#include #include #include #include ThinkNodeM8Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/waveshare_rp2040_lora/target.cpp b/variants/waveshare_rp2040_lora/target.cpp index ef47708fb..227caf924 100644 --- a/variants/waveshare_rp2040_lora/target.cpp +++ b/variants/waveshare_rp2040_lora/target.cpp @@ -1,11 +1,13 @@ #include "target.h" +#include #include #include WaveshareBoard board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI1); +static SX126xBufferedRadioHal radioHal(SPI1); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); VolatileRTCClock fallback_clock; diff --git a/variants/wio-tracker-l1-1w/target.cpp b/variants/wio-tracker-l1-1w/target.cpp index 7a573258e..7fdb7519a 100644 --- a/variants/wio-tracker-l1-1w/target.cpp +++ b/variants/wio-tracker-l1-1w/target.cpp @@ -1,11 +1,13 @@ #include #include "target.h" +#include #include #include WioTrackerL1Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/wio-tracker-l1/target.cpp b/variants/wio-tracker-l1/target.cpp index f82feff9d..7c0a12be3 100644 --- a/variants/wio-tracker-l1/target.cpp +++ b/variants/wio-tracker-l1/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include #ifdef ENV_INCLUDE_GPS @@ -8,7 +9,8 @@ WioTrackerL1Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/wio-tracker-l2/target.cpp b/variants/wio-tracker-l2/target.cpp index a20480628..5d3dba018 100644 --- a/variants/wio-tracker-l2/target.cpp +++ b/variants/wio-tracker-l2/target.cpp @@ -1,10 +1,12 @@ #include #include "target.h" +#include WioTrackerL2Board board; static SPIClass spi; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); +static SX126xBufferedRadioHal radio_hal(spi); +RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/xiao_c3/target.cpp b/variants/xiao_c3/target.cpp index 1768fe00c..6e26380d7 100644 --- a/variants/xiao_c3/target.cpp +++ b/variants/xiao_c3/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include XiaoC3Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/xiao_c6/XiaoC6Board.cpp b/variants/xiao_c6/XiaoC6Board.cpp index bbf72134e..37ca46331 100644 --- a/variants/xiao_c6/XiaoC6Board.cpp +++ b/variants/xiao_c6/XiaoC6Board.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include XiaoC6Board board; #if defined(P_LORA_SCLK) static SPIClass spi(0); - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/xiao_nrf52/target.cpp b/variants/xiao_nrf52/target.cpp index 37f3639f5..777a94763 100644 --- a/variants/xiao_nrf52/target.cpp +++ b/variants/xiao_nrf52/target.cpp @@ -1,5 +1,6 @@ #include #include "target.h" +#include #include #ifdef USE_CC310_HW_CRYPTO #include @@ -14,7 +15,8 @@ static bool target_radio_available = false; XiaoNrf52Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); +static SX126xBufferedRadioHal radioHal(SPI); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/xiao_rp2040/target.cpp b/variants/xiao_rp2040/target.cpp index fe2c62c3d..c08b8171d 100644 --- a/variants/xiao_rp2040/target.cpp +++ b/variants/xiao_rp2040/target.cpp @@ -1,11 +1,13 @@ #include "target.h" +#include #include #include XiaoRP2040Board board; -RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); +static SX126xBufferedRadioHal radioHal(SPI, MC_SX1262_SPI_HZ, true); +RADIO_CLASS radio = new Module(&radioHal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); WRAPPER_CLASS radio_driver(radio, board); diff --git a/variants/xiao_s3/target.cpp b/variants/xiao_s3/target.cpp index 1b4e11a24..3fdac46ee 100644 --- a/variants/xiao_s3/target.cpp +++ b/variants/xiao_s3/target.cpp @@ -1,13 +1,16 @@ #include #include "target.h" +#include XiaoS3Board board; #if defined(P_LORA_SCLK) static SPIClass spi; - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, spi); + static SX126xBufferedRadioHal radio_hal(spi); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #else - RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); + static SX126xBufferedRadioHal radio_hal(SPI, MC_SX1262_SPI_HZ, true); + RADIO_CLASS radio = new Module(&radio_hal, P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY); #endif WRAPPER_CLASS radio_driver(radio, board);