From efb35bdaf37f6752b4a1ae6dd98af12e9d4cd115 Mon Sep 17 00:00:00 2001 From: sh123 Date: Sun, 7 Feb 2021 17:53:35 +0200 Subject: [PATCH] Make LED and LORA pinouts work natively if board defines them --- README.md | 9 +++------ config.h | 23 ++++++++++++++--------- esp32_loraprs.ino | 12 +++--------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 9457713..374fd1c 100644 --- a/README.md +++ b/README.md @@ -39,12 +39,9 @@ All work was done on ESP32-WROOM with custom made LoRa shield, if your ESP32 boa - MISO: GPIO_19/VSPI_MISO - SCK: GPIO_18/VSPI_SCK -Supported: -- **T-Beam LoRa**, **WIFI LoRa 32 (V2)**, uncomment `#define BOARD_T_BEAM` in `esp32_loraprs.ino` see [Discussion](https://github.com/sh123/esp32_loraprs/issues/11) - - Uses different pinout mapping as - - SS: GPIO_18 - - RST: GPIO_23 - - DIO0: GPIO_26 +Supported/Tested: +- **T-Beam LoRa**, +- **WIFI LoRa 32 (V2)** # Software Dependencies Install via libraries: diff --git a/config.h b/config.h index 6ffd12e..de7f8ea 100644 --- a/config.h +++ b/config.h @@ -1,14 +1,19 @@ +// change pinouts if not defined through native board LORA_* definitions +#ifndef LORA_CS +#define LORA_CS 5 +#define LORA_RST 26 +#define LORA_IRQ 14 +#endif + +#ifndef BUILTIN_LED +#define BUILTIN_LED 2 +#endif + #define CFG_IS_CLIENT_MODE true -#ifdef BOARD_T_BEAM -#define CFG_LORA_PIN_SS 18 -#define CFG_LORA_PIN_RST 23 -#define CFG_LORA_PIN_DIO0 26 -#else -#define CFG_LORA_PIN_SS 5 -#define CFG_LORA_PIN_RST 26 -#define CFG_LORA_PIN_DIO0 14 -#endif +#define CFG_LORA_PIN_SS LORA_CS +#define CFG_LORA_PIN_RST LORA_RST +#define CFG_LORA_PIN_DIO0 LORA_IRQ #define CFG_LORA_FREQ 433.775E6 #define CFG_LORA_BW 125e3 diff --git a/esp32_loraprs.ino b/esp32_loraprs.ino index 2388056..f3607a2 100644 --- a/esp32_loraprs.ino +++ b/esp32_loraprs.ino @@ -4,8 +4,6 @@ #define LED_TOGGLE_PERIOD 1000 -//#define BOARD_T_BEAM // enable for TTG T-Beam board support - #if __has_include("/tmp/esp32_loraprs_config.h") #pragma message("Using external config") #include "/tmp/esp32_loraprs_config.h" @@ -20,10 +18,6 @@ #pragma message("Configured for server mode") #endif -#ifndef LED_BUILTIN -#define LED_BUILTIN 2 -#endif - void initializeConfig(LoraPrs::Config &cfg) { // client/server mode switch @@ -75,8 +69,8 @@ LoraPrs::Service loraPrsService; auto watchdogLedTimer = timer_create_default(); void setup() { - pinMode(LED_BUILTIN, OUTPUT); - digitalWrite(LED_BUILTIN, 1); + pinMode(BUILTIN_LED, OUTPUT); + digitalWrite(BUILTIN_LED, 1); Serial.begin(115200); while (!Serial); @@ -95,6 +89,6 @@ void loop() { } bool toggleWatchdogLed(void *) { - digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN)); + digitalWrite(BUILTIN_LED, !digitalRead(BUILTIN_LED)); return true; }