From 8c20fe5ec4ab85eba49e14157c418093ec589eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 30 Dec 2022 21:44:51 +0100 Subject: [PATCH] Start working on RF95 attached to Raspberry Pi --- arch/portduino/portduino.ini | 1 + src/mesh/RF95Interface.cpp | 2 +- src/platform/portduino/PortduinoGlue.cpp | 26 ++++++++++++++++- variants/portduino/platformio.ini | 4 +-- variants/portduino/variant.h | 36 +++++++++++++++++++++++- 5 files changed, 64 insertions(+), 5 deletions(-) diff --git a/arch/portduino/portduino.ini b/arch/portduino/portduino.ini index cd962b671..f04e9016c 100644 --- a/arch/portduino/portduino.ini +++ b/arch/portduino/portduino.ini @@ -1,6 +1,7 @@ ; The Portduino based sim environment on top of any host OS, all hardware will be simulated [portduino_base] platform = https://github.com/meshtastic/platform-native.git#096b3c3e9c5c8e19d4c3b6cd803fffef2a9be4c5 +platform_packages = framework-portduino@https://github.com/caveman99/framework-portduino.git framework = arduino build_src_filter = ${env.build_src_filter} diff --git a/src/mesh/RF95Interface.cpp b/src/mesh/RF95Interface.cpp index 4502d0810..8a0dfec51 100644 --- a/src/mesh/RF95Interface.cpp +++ b/src/mesh/RF95Interface.cpp @@ -14,7 +14,7 @@ RF95Interface::RF95Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, SPIClass &spi) : RadioLibInterface(cs, irq, rst, RADIOLIB_NC, spi) { - // FIXME - we assume devices never get destroyed + LOG_WARN("RF95Interface(cs=%d, irq=%d, rst=%d)\n", cs, irq, rst); } /** Some boards require GPIO control of tx vs rx paths */ diff --git a/src/platform/portduino/PortduinoGlue.cpp b/src/platform/portduino/PortduinoGlue.cpp index b041391f8..332b40791 100644 --- a/src/platform/portduino/PortduinoGlue.cpp +++ b/src/platform/portduino/PortduinoGlue.cpp @@ -88,7 +88,31 @@ void portduinoSetup() { printf("Setting up Meshtastic on Portduino...\n"); -#ifdef PORTDUINO_LINUX_HARDWARE +#ifdef ARCH_RASPBERRY_PI + printf("using GPIOD Version: %s\n", gpiod_version_string()); + // We need to create SPI + SPI.begin(); + if(!spiChip->isSimulated()) { + printf("Connecting to RFM95 board...\n"); + loraIrq = new LinuxGPIOPin(LORA_DIO0, GPIOD_CHIP_LABEL, LORA_DIO0_LABEL, "loraIrq"); + loraIrq->setSilent(); + gpioBind(loraIrq); + +#if (RF95_NSS != RADIOLIB_NC) + auto loraCs = new LinuxGPIOPin(RF95_NSS, GPIOD_CHIP_LABEL, RF95_NSS_LABEL, "loraCs"); + loraCs->setSilent(); + gpioBind(loraCs); +#endif + + auto loraReset = new LinuxGPIOPin(LORA_RESET, GPIOD_CHIP_LABEL, LORA_RESET_LABEL, "loraReset"); + loraReset->setSilent(); + gpioBind(loraReset); + + } + else + + +#elif defined(PORTDUINO_LINUX_HARDWARE) SPI.begin(); // We need to create SPI bool usePineLora = !spiChip->isSimulated(); if(usePineLora) { diff --git a/variants/portduino/platformio.ini b/variants/portduino/platformio.ini index 5bbde2adf..13f298440 100644 --- a/variants/portduino/platformio.ini +++ b/variants/portduino/platformio.ini @@ -14,9 +14,9 @@ lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} ; The Portduino based sim environment on top of a linux OS and touching linux hardware devices -[env:linux-arm] +[env:raspbian] extends = portduino_base -build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino +build_flags = ${portduino_base.build_flags} -O0 -lgpiod -I variants/portduino -DARCH_RASPBERRY_PI -DRADIOLIB_DEBUG -DRADIOLIB_VERBOSE board = linux_arm lib_deps = ${portduino_base.lib_deps} build_src_filter = ${portduino_base.build_src_filter} diff --git a/variants/portduino/variant.h b/variants/portduino/variant.h index 76696b7af..d84c15d4a 100644 --- a/variants/portduino/variant.h +++ b/variants/portduino/variant.h @@ -1,3 +1,35 @@ +#if defined(ARCH_RASPBERRY_PI) + +#define GPIOD_CHIP_LABEL "pinctrl-bcm2711" + +#define USE_RF95 +#define USE_SX1262 + +#define NO_SCREEN + +#define RF95_SCK 11 +#define RF95_MISO 9 +#define RF95_MOSI 10 +#define RF95_NSS RADIOLIB_NC + +#define LORA_DIO0 4 // a No connect on the SX1262 module +#define LORA_DIO0_LABEL "GPIO_GCLK" +#define LORA_RESET 17 +#define LORA_RESET_LABEL "GPIO17" +#define LORA_DIO1 RADIOLIB_NC // SX1262 IRQ, called DIO0 on pinelora schematic, pin 7 on ch341f "ack" - FIXME, enable hwints in linux +#define LORA_DIO2 RADIOLIB_NC // SX1262 BUSY, actually connected to "DIO5" on pinelora schematic, pin 8 on ch341f "slct" +#define LORA_DIO3 RADIOLIB_NC // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled + +#ifdef USE_SX1262 +#define SX126X_CS RF95_NSS +#define SX126X_DIO1 LORA_DIO0 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +// HOPE RFM90 does not have a TCXO therefore not SX126X_E22 +#endif + +#else // Pine64 mode. + // Pine64 uses a common pinout for their SX1262 vs RF95 modules - both can be enabled and we will probe at runtime for RF95 and if // not found then probe for SX1262. Currently the RF95 code is disabled because I think the RF95 module won't need to ship. // #define USE_RF95 @@ -13,7 +45,7 @@ #define LORA_RESET 14 #define LORA_DIO1 33 // SX1262 IRQ, called DIO0 on pinelora schematic, pin 7 on ch341f "ack" - FIXME, enable hwints in linux #define LORA_DIO2 32 // SX1262 BUSY, actually connected to "DIO5" on pinelora schematic, pin 8 on ch341f "slct" -#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled +#define LORA_DIO3 RADIOLIB_NC // Not connected on PCB, but internally on the TTGO SX1262, if DIO3 is high the TXCO is enabled #ifdef USE_SX1262 #define SX126X_CS 20 // CS0 on pinelora schematic, hooked to gpio D0 on ch341f @@ -23,3 +55,5 @@ // HOPE RFM90 does not have a TCXO therefore not SX126X_E22 #endif +#endif +