From 12df55c3d472fb363d299db2b7d5248363ac3944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Wed, 2 Nov 2022 13:12:15 +0100 Subject: [PATCH 1/5] Support for TLORA 2.1-1.8 --- src/main.cpp | 10 +++--- src/mesh/InterfacesTemplates.cpp | 2 +- ...X1281Interface.cpp => SX1280Interface.cpp} | 4 +-- .../{SX1281Interface.h => SX1280Interface.h} | 6 ++-- src/mesh/SX128xInterface.h | 2 +- src/platform/esp32/architecture.h | 2 ++ variants/tlora_v2_1_18/platformio.ini | 7 ++++ variants/tlora_v2_1_18/variant.h | 33 +++++++++++++++++++ 8 files changed, 54 insertions(+), 12 deletions(-) rename src/mesh/{SX1281Interface.cpp => SX1280Interface.cpp} (72%) rename src/mesh/{SX1281Interface.h => SX1280Interface.h} (52%) create mode 100644 variants/tlora_v2_1_18/platformio.ini create mode 100644 variants/tlora_v2_1_18/variant.h diff --git a/src/main.cpp b/src/main.cpp index 20bbcd085d..8836b64600 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -51,7 +51,7 @@ #include "RF95Interface.h" #include "SX1262Interface.h" #include "SX1268Interface.h" -#include "SX1281Interface.h" +#include "SX1280Interface.h" #if !HAS_RADIO && defined(ARCH_PORTDUINO) #include "platform/portduino/SimRadio.h" #endif @@ -372,15 +372,15 @@ void setup() } #endif -#if defined(USE_SX1281) && !defined(ARCH_PORTDUINO) +#if defined(USE_SX1280) && !defined(ARCH_PORTDUINO) if (!rIf) { - rIf = new SX1281Interface(SX126X_CS, SX126X_DIO1, SX126X_RESET, SX126X_BUSY, SPI); + rIf = new SX1280Interface(SX128X_CS, SX128X_DIO1, SX128X_RESET, SX128X_BUSY, SPI); if (!rIf->init()) { - DEBUG_MSG("Warning: Failed to find SX1281 radio\n"); + DEBUG_MSG("Warning: Failed to find SX1280 radio\n"); delete rIf; rIf = NULL; } else { - DEBUG_MSG("SX1281 Radio init succeeded, using SX1281 radio\n"); + DEBUG_MSG("SX1280 Radio init succeeded, using SX1280 radio\n"); rIf_wide_lora = true; } } diff --git a/src/mesh/InterfacesTemplates.cpp b/src/mesh/InterfacesTemplates.cpp index 6707813dbd..ccef2df234 100644 --- a/src/mesh/InterfacesTemplates.cpp +++ b/src/mesh/InterfacesTemplates.cpp @@ -9,5 +9,5 @@ template class SX126xInterface; template class SX126xInterface; #if !defined(ARCH_PORTDUINO) -template class SX128xInterface; +template class SX128xInterface; #endif \ No newline at end of file diff --git a/src/mesh/SX1281Interface.cpp b/src/mesh/SX1280Interface.cpp similarity index 72% rename from src/mesh/SX1281Interface.cpp rename to src/mesh/SX1280Interface.cpp index 50805cfe0f..37aad1d409 100644 --- a/src/mesh/SX1281Interface.cpp +++ b/src/mesh/SX1280Interface.cpp @@ -1,10 +1,10 @@ #include "configuration.h" -#include "SX1281Interface.h" +#include "SX1280Interface.h" #include "error.h" #if !defined(ARCH_PORTDUINO) -SX1281Interface::SX1281Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, +SX1280Interface::SX1280Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi) : SX128xInterface(cs, irq, rst, busy, spi) { diff --git a/src/mesh/SX1281Interface.h b/src/mesh/SX1280Interface.h similarity index 52% rename from src/mesh/SX1281Interface.h rename to src/mesh/SX1280Interface.h index 3bd65309af..1c2e24900a 100644 --- a/src/mesh/SX1281Interface.h +++ b/src/mesh/SX1280Interface.h @@ -3,15 +3,15 @@ #include "SX128xInterface.h" /** - * Our adapter for SX1281 radios + * Our adapter for SX1280 radios */ #if !defined(ARCH_PORTDUINO) -class SX1281Interface : public SX128xInterface +class SX1280Interface : public SX128xInterface { public: - SX1281Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi); + SX1280Interface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy, SPIClass &spi); }; #endif \ No newline at end of file diff --git a/src/mesh/SX128xInterface.h b/src/mesh/SX128xInterface.h index d01dfc5103..f712b8bc43 100644 --- a/src/mesh/SX128xInterface.h +++ b/src/mesh/SX128xInterface.h @@ -6,7 +6,7 @@ /** * \brief Adapter for SX128x radio family. Implements common logic for child classes. - * \tparam T RadioLib module type for SX128x: SX1281. + * \tparam T RadioLib module type for SX128x: SX1280. */ template class SX128xInterface : public RadioLibInterface diff --git a/src/platform/esp32/architecture.h b/src/platform/esp32/architecture.h index 18253abe5e..00d221691f 100644 --- a/src/platform/esp32/architecture.h +++ b/src/platform/esp32/architecture.h @@ -70,6 +70,8 @@ #define HW_VENDOR HardwareModel_TLORA_V1_1P3 #elif defined(TLORA_V2_1_16) #define HW_VENDOR HardwareModel_TLORA_V2_1_1P6 +#elif defined(TLORA_V2_1_18) + #define HW_VENDOR HardwareModel_TLORA_V2_1_1P8 #elif defined(GENIEBLOCKS) #define HW_VENDOR HardwareModel_GENIEBLOCKS #elif defined(PRIVATE_HW) diff --git a/variants/tlora_v2_1_18/platformio.ini b/variants/tlora_v2_1_18/platformio.ini new file mode 100644 index 0000000000..2cb1c3d2fb --- /dev/null +++ b/variants/tlora_v2_1_18/platformio.ini @@ -0,0 +1,7 @@ +[env:tlora-v2-1-1.8] +extends = esp32_base +board = ttgo-lora32-v21 +lib_deps = + ${esp32_base.lib_deps} +build_flags = + ${esp32_base.build_flags} -D TLORA_V2_1_18 -I variants/tlora_v2_1_18 \ No newline at end of file diff --git a/variants/tlora_v2_1_18/variant.h b/variants/tlora_v2_1_18/variant.h new file mode 100644 index 0000000000..cd693a3d2b --- /dev/null +++ b/variants/tlora_v2_1_18/variant.h @@ -0,0 +1,33 @@ +#undef GPS_RX_PIN +#undef GPS_TX_PIN +#define GPS_RX_PIN 15 // per @der_bear on the forum, 36 is incorrect for this board type and 15 is a better pick +#define GPS_TX_PIN 13 + +#define EXT_NOTIFY_OUT 2 // Default pin to use for Ext Notify Module. + +#define BATTERY_PIN 35 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage +// ratio of voltage divider = 2.0 (R42=100k, R43=100k) +#define ADC_MULTIPLIER 2.11 // 2.0 + 10% for correction of display undervoltage. + +#define I2C_SDA 21 // I2C pins for this board +#define I2C_SCL 22 + +// #define RESET_OLED 16 // If defined, this pin will be used to reset the display controller. Crashes on newer ESP-IDF and not needed per schematic + +#define VEXT_ENABLE 21 // active low, powers the oled display and the lora antenna boost +#define LED_PIN 25 // If defined we will blink this LED +#define BUTTON_PIN 12 // If defined, this will be used for user button presses, + +#define BUTTON_NEED_PULLUP + +#define USE_SX1280 +#define LORA_DIO0 26 // a No connect on the SX1262 module +#define LORA_RESET 23 + +#define SX128X_CS 18 // FIXME - we really should define LORA_CS instead +#define SX128X_DIO1 33 +#define SX128X_BUSY 32 +#define SX128X_RESET LORA_RESET +#define SX128X_E22 // Not really an E22 but TTGO seems to be trying to clone that +// Internally the TTGO module hooks the SX1280-DIO2 in to control the TX/RX switch (which is the default for the sx1280interface +// code) From b2969b2faf8f07df2f3856b6e3f0572a05c9bbfa Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Wed, 2 Nov 2022 13:18:15 +0100 Subject: [PATCH 2/5] Don't allow arbitrary channel name for admin (#1886) Co-authored-by: Ben Meadors --- src/mesh/MeshModule.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/mesh/MeshModule.cpp b/src/mesh/MeshModule.cpp index 7b204ae496..ca1fb5b506 100644 --- a/src/mesh/MeshModule.cpp +++ b/src/mesh/MeshModule.cpp @@ -109,10 +109,7 @@ void MeshModule::callPlugins(const MeshPacket &mp, RxSource src) /// Also: if a packet comes in on the local PC interface, we don't check for bound channels, because it is TRUSTED and it needs to /// to be able to fetch the initial admin packets without yet knowing any channels. - bool rxChannelOk = !pi.boundChannel || (mp.from == 0) || - !ch || - strlen(ch->settings.name) > 0 || - (strcasecmp(ch->settings.name, pi.boundChannel) == 0); + bool rxChannelOk = !pi.boundChannel || (mp.from == 0) || (strcasecmp(ch->settings.name, pi.boundChannel) == 0); if (!rxChannelOk) { // no one should have already replied! From 39c1637030da260eeefe30eba3f32f53d987af36 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 2 Nov 2022 07:48:14 -0500 Subject: [PATCH 3/5] Experimental DIY nrf52840 feather support (#1884) * Experimental DIY nrf52840 feather support * Fix target * sx1262 wiring * Remove lib --- .github/workflows/main_matrix.yml | 2 ++ src/platform/nrf52/architecture.h | 2 +- variants/feather_diy/platformio.ini | 11 ++++++++++ variants/feather_diy/variant.h | 33 +++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 variants/feather_diy/platformio.ini create mode 100644 variants/feather_diy/variant.h diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index 06a2293123..66bf7539c9 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -42,6 +42,7 @@ jobs: - board: m5stack-core - board: m5stack-coreink - board: tbeam-s3-core + - board: feather_diy # - board: pico runs-on: ubuntu-latest @@ -181,6 +182,7 @@ jobs: - board: rak4631_eink - board: t-echo - board: pca10059_diy_eink + - board: feather_diy runs-on: ubuntu-latest steps: diff --git a/src/platform/nrf52/architecture.h b/src/platform/nrf52/architecture.h index 47d95c92d0..986a864c9c 100644 --- a/src/platform/nrf52/architecture.h +++ b/src/platform/nrf52/architecture.h @@ -45,7 +45,7 @@ #define HW_VENDOR HardwareModel_T_ECHO #elif defined(NORDIC_PCA10059) #define HW_VENDOR HardwareModel_NRF52840_PCA10059 -#elif defined(PRIVATE_HW) +#elif defined(PRIVATE_HW) || defined(FEATHER_DIY) #define HW_VENDOR HardwareModel_PRIVATE_HW #else #define HW_VENDOR HardwareModel_NRF52_UNKNOWN diff --git a/variants/feather_diy/platformio.ini b/variants/feather_diy/platformio.ini new file mode 100644 index 0000000000..446011cb98 --- /dev/null +++ b/variants/feather_diy/platformio.ini @@ -0,0 +1,11 @@ +; The very slick RAK wireless RAK 4631 / 4630 board - Unified firmware for 5005/19003, with or without OLED RAK 1921 +[env:feather_diy] +extends = nrf52840_base +board = adafruit_feather_nrf52840 +build_flags = ${nrf52840_base.build_flags} -Ivariants/feather_diy -D feather_diy +build_src_filter = ${nrf52_base.build_src_filter} +<../variants/feather_diy> +lib_deps = + ${nrf52840_base.lib_deps} +debug_tool = jlink +; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm) +;upload_protocol = jlink \ No newline at end of file diff --git a/variants/feather_diy/variant.h b/variants/feather_diy/variant.h new file mode 100644 index 0000000000..8327e6050e --- /dev/null +++ b/variants/feather_diy/variant.h @@ -0,0 +1,33 @@ +// For OLED LCD +#define I2C_SDA 22 +#define I2C_SCL 23 + +#define BUTTON_PIN 7 + +#define LORA_DIO0 -1 // a No connect on the SX1262/SX1268 module +#define LORA_RESET 13 // RST for SX1276, and for SX1262/SX1268 +#define LORA_DIO1 11 // IRQ for SX1262/SX1268 +#define LORA_DIO2 12 // BUSY for SX1262/SX1268 +#define LORA_DIO3 // Not connected on PCB, but internally on the TTGO SX1262/SX1268, if DIO3 is high the TXCO is enabled + +#define RF95_SCK SCK +#define RF95_MISO MI +#define RF95_MOSI MO +#define RF95_NSS D2 + +// supported modules list +#define USE_SX1262 + +// common pinouts for SX126X modules +#define SX126X_CS RF95_NSS // NSS for SX126X +#define SX126X_DIO1 LORA_DIO1 +#define SX126X_BUSY LORA_DIO2 +#define SX126X_RESET LORA_RESET +#define SX126X_RXEN 10 +#define SX126X_TXEN 9 + +#ifdef EBYTE_E22 +// Internally the TTGO module hooks the SX126x-DIO2 in to control the TX/RX switch +// (which is the default for the sx1262interface code) +#define SX126X_E22 +#endif From 5715ddc3613fc52d048f1028a4e3c48a338b9d1c Mon Sep 17 00:00:00 2001 From: GUVWAF <78759985+GUVWAF@users.noreply.github.com> Date: Wed, 2 Nov 2022 20:32:18 +0100 Subject: [PATCH 4/5] Don't consider Response as ACK for FloodingRouter (#1885) Co-authored-by: Ben Meadors --- src/mesh/FloodingRouter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mesh/FloodingRouter.cpp b/src/mesh/FloodingRouter.cpp index b6519abdb5..818bacf450 100644 --- a/src/mesh/FloodingRouter.cpp +++ b/src/mesh/FloodingRouter.cpp @@ -29,8 +29,8 @@ bool FloodingRouter::shouldFilterReceived(MeshPacket *p) void FloodingRouter::sniffReceived(const MeshPacket *p, const Routing *c) { - PacketId ackId = ((c && c->error_reason == Routing_Error_NONE) || !c) ? p->decoded.request_id : 0; - if (ackId && p->to != getNodeNum()) { + bool isAck = ((c && c->error_reason == Routing_Error_NONE)); // consider only ROUTING_APP message without error as ACK + if (isAck && p->to != getNodeNum()) { // do not flood direct message that is ACKed DEBUG_MSG("Receiving an ACK not for me, but don't need to rebroadcast this direct message anymore.\n"); Router::cancelSending(p->to, p->decoded.request_id); // cancel rebroadcast for this DM From 593301146e6beaaf41a2885c396b564e7f3ea7dc Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 2 Nov 2022 15:57:47 -0500 Subject: [PATCH 5/5] Fix feather diy (#1892) * Fix variant * Fix feather diy target --- variants/feather_diy/platformio.ini | 2 +- variants/feather_diy/variant.cpp | 24 ++++++++ variants/feather_diy/variant.h | 94 +++++++++++++++++++++++++++-- 3 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 variants/feather_diy/variant.cpp diff --git a/variants/feather_diy/platformio.ini b/variants/feather_diy/platformio.ini index 446011cb98..84c582ab09 100644 --- a/variants/feather_diy/platformio.ini +++ b/variants/feather_diy/platformio.ini @@ -2,7 +2,7 @@ [env:feather_diy] extends = nrf52840_base board = adafruit_feather_nrf52840 -build_flags = ${nrf52840_base.build_flags} -Ivariants/feather_diy -D feather_diy +build_flags = ${nrf52840_base.build_flags} -Ivariants/feather_diy -Dfeather_diy build_src_filter = ${nrf52_base.build_src_filter} +<../variants/feather_diy> lib_deps = ${nrf52840_base.lib_deps} diff --git a/variants/feather_diy/variant.cpp b/variants/feather_diy/variant.cpp new file mode 100644 index 0000000000..7311c9019b --- /dev/null +++ b/variants/feather_diy/variant.cpp @@ -0,0 +1,24 @@ +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "variant.h" +#include "nrf.h" +#include "wiring_constants.h" +#include "wiring_digital.h" diff --git a/variants/feather_diy/variant.h b/variants/feather_diy/variant.h index 8327e6050e..703d322025 100644 --- a/variants/feather_diy/variant.h +++ b/variants/feather_diy/variant.h @@ -1,9 +1,80 @@ -// For OLED LCD -#define I2C_SDA 22 -#define I2C_SCL 23 +/* + Copyright (c) 2014-2015 Arduino LLC. All right reserved. + Copyright (c) 2016 Sandeep Mistry All right reserved. + Copyright (c) 2018, Adafruit Industries (adafruit.com) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + This library 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 Lesser General Public License for more details. + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _VARIANT_FEATHER_DIY_ +#define _VARIANT_FEATHER_DIY_ + +/** Master clock frequency */ +#define VARIANT_MCK (64000000ul) + +#define USE_LFXO // Board uses 32khz crystal for LF +// define USE_LFRC // Board uses RC for LF + +/*---------------------------------------------------------------------------- + * Headers + *----------------------------------------------------------------------------*/ + +#include "WVariant.h" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Number of pins defined in PinDescription array +#define PINS_COUNT (48) +#define NUM_DIGITAL_PINS (48) +#define NUM_ANALOG_INPUTS (6) +#define NUM_ANALOG_OUTPUTS (0) + +#define WIRE_INTERFACES_COUNT 1 + +#define PIN_WIRE_SDA 22 +#define PIN_WIRE_SCL 23 + +#define PIN_LED1 3 +#define PIN_LED2 4 + +#define LED_BUILTIN PIN_LED1 + +#define LED_GREEN PIN_LED2 // Actually red +#define LED_BLUE PIN_LED1 + +#define LED_STATE_ON 1 // State when LED is litted #define BUTTON_PIN 7 +/* + * Serial interfaces + */ +#define PIN_SERIAL1_RX 1 +#define PIN_SERIAL1_TX 0 + +#define PIN_SERIAL2_RX (-1) +#define PIN_SERIAL2_TX (-1) + +#define SPI_INTERFACES_COUNT 1 + +#define PIN_SPI_MISO 24 +#define PIN_SPI_MOSI 25 +#define PIN_SPI_SCK 26 + +#define SS 2 + #define LORA_DIO0 -1 // a No connect on the SX1262/SX1268 module #define LORA_RESET 13 // RST for SX1276, and for SX1262/SX1268 #define LORA_DIO1 11 // IRQ for SX1262/SX1268 @@ -13,7 +84,12 @@ #define RF95_SCK SCK #define RF95_MISO MI #define RF95_MOSI MO -#define RF95_NSS D2 +#define RF95_NSS SS + +// enables 3.3V periphery like GPS or IO Module +#define PIN_3V3_EN (34) + +#undef USE_EINK // supported modules list #define USE_SX1262 @@ -31,3 +107,13 @@ // (which is the default for the sx1262interface code) #define SX126X_E22 #endif + +#ifdef __cplusplus +} +#endif + +/*---------------------------------------------------------------------------- + * Arduino objects - C++ only + *----------------------------------------------------------------------------*/ + +#endif