diff --git a/config.h b/config.h index 18eca11..daeb2c1 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,19 @@ +// comment out for arduino-Lora usage +#define USE_RADIOLIB + +// Uncomment for SX126X module usage +//#define USE_SX126X + +// Check your module name at https://github.com/jgromes/RadioLib/wiki/Modules +#ifdef USE_SX126X +#define MODULE_NAME SX1268 +#else +#define MODULE_NAME SX1278 +#endif + +// generic options #define LED_TOGGLE_PERIOD 1000 - #define SERIAL_BAUD_RATE 115200 - #define CFG_LOG_LEVEL DebugLogLevel::LVL_INFO // change pinouts if not defined through native board LORA_* definitions @@ -11,25 +23,32 @@ #define LORA_IRQ 14 #endif +// redefine LED if not defined in Arduino to have module heartbeat indication #ifndef BUILTIN_LED #pragma message("BUILDIN_LED is not found, defining as 2") #define BUILTIN_LED 2 #endif +// select between client mode and APRS-IS gate mode #define CFG_IS_CLIENT_MODE true // false - server mode (APRS-IS gate mode) -// lora pinouts, CAD and ISR usage +// lora generic pinouts #define CFG_LORA_PIN_SS SS #define CFG_LORA_PIN_RST LORA_RST #define CFG_LORA_PIN_A LORA_IRQ // (sx127x - dio0, sx126x/sx128x - dio1) -#ifdef USE_RADIOLIB #define CFG_LORA_PIN_B RADIOLIB_NC // (sx127x - dio1, sx126x/sx128x - busy) + +// lora pinouts, SX126X RXEN/TXEN usage +#ifdef USE_SX126X +#define CFG_LORA_PIN_RXEN 4 // (sx127x - unused, sx126x - RXEN pin number) +#define CFG_LORA_PIN_TXEN 5 // (sx127x - unused, sx126x - TXEN pin number) #endif +// CAD and ISR usage selection #define CFG_LORA_USE_ISR true // true - read incoming data in ISR, false - do not read in ISR #define CFG_LORA_USE_CAD false // set to true to utilize carrier detection -// lora protocol parameters +// lora protocol default parameters #define CFG_LORA_FREQ 433.775E6 #define CFG_LORA_BW 125e3 #define CFG_LORA_SF 12 @@ -38,7 +57,7 @@ #define CFG_LORA_ENABLE_CRC true // set to false for speech data // wifi client and AP options -#define CFG_WIFI_ENABLE_AP false // run as wifi access point, for CFG_KISS_TCP_IP mode +#define CFG_WIFI_ENABLE_AP false // run as wifi access point (for CFG_KISS_TCP_IP mode) #define CFG_WIFI_SSID "" // connect to SSID or run as this SSID in AP mode #define CFG_WIFI_KEY "" // wifi key diff --git a/esp32_loraprs.ino b/esp32_loraprs.ino index a64e1e0..166dc5c 100644 --- a/esp32_loraprs.ino +++ b/esp32_loraprs.ino @@ -1,6 +1,7 @@ #include #include #include "WiFi.h" + #include "loraprs_service.h" #if __has_include("/tmp/esp32_loraprs_config.h") @@ -17,6 +18,10 @@ #pragma message("Configured for server mode") #endif +/* + * Initialize config from config.h options. + * Enables future use of EEPROM or allows user to dynamically modify config at run time. + */ void initializeConfig(LoraPrs::Config &cfg) { // log level @@ -39,6 +44,8 @@ void initializeConfig(LoraPrs::Config &cfg) { cfg.LoraPinRst = CFG_LORA_PIN_RST; cfg.LoraPinA = CFG_LORA_PIN_A; // (sx127x - dio0, sx126x/sx128x - dio1) cfg.LoraPinB = CFG_LORA_PIN_B; // (sx127x - dio1, sx126x/sx128x - busy) + cfg.LoraPinSwitchRx = CFG_LORA_PIN_RXEN; // (sx127x - unused, sx126x - RXEN pin number) + cfg.LoraPinSwitchTx = CFG_LORA_PIN_TXEN; // (sx127x - unused, sx126x - TXEN pin number) cfg.LoraUseIsr = CFG_LORA_USE_ISR; // set to true for incoming packet ISR usage (stream mode, e.g. speech) cfg.LoraUseCad = CFG_LORA_USE_CAD; // carrier detect diff --git a/loraprs_config.h b/loraprs_config.h index a9c3931..27fc4eb 100644 --- a/loraprs_config.h +++ b/loraprs_config.h @@ -25,6 +25,8 @@ struct Config byte LoraPinRst; // lora rst pin byte LoraPinA; // (sx127x - dio0, sx126x/sx128x - dio1) byte LoraPinB; // (sx127x - dio1, sx126x/sx128x - busy) + byte LoraPinSwitchRx; // (sx127x - unused, sx126x - RXEN pin number) + byte LoraPinSwitchTx; // (sx127x - unused, sx126x - TXEN pin number) bool LoraUseIsr; // true to use interrupts, false for fallback polling, e.g. if Dio0 is not connected bool LoraUseCad; // use carrier detect before transmitting diff --git a/loraprs_service.cpp b/loraprs_service.cpp index f95283e..e6d6f47 100644 --- a/loraprs_service.cpp +++ b/loraprs_service.cpp @@ -217,7 +217,7 @@ void Service::setupLora(long loraFreq, long bw, int sf, int cr, int pwr, int syn #ifdef USE_SX126X #pragma message("Using SX126X") LOG_INFO("Using SX126X module"); - radio_->setRfSwitchPins(4, 5); + radio_->setRfSwitchPins(config_.LoraPinSwitchRx, config_.LoraPinSwitchTx); radio_->clearDio1Action(); if (config_.LoraUseIsr) { radio_->setDio1Action(onLoraDataAvailableIsr); diff --git a/loraprs_service.h b/loraprs_service.h index 44f50b3..a25d3b7 100644 --- a/loraprs_service.h +++ b/loraprs_service.h @@ -5,13 +5,15 @@ #include #include -// When USE_RADIOLIB is defined then RadioLib will be used, otherwise arduino-LoRa will be used -// When using RadioLib, default module is SX1278, if you are using -// different module then update MODULE_NAME in module_name.h -#define USE_RADIOLIB +// some generic options (module name, library type) are loaded from config.h +#if __has_include("/tmp/esp32_loraprs_config.h") +#include "/tmp/esp32_loraprs_config.h" +#else +#include "config.h" +#endif + #ifdef USE_RADIOLIB #include -#include "module_name.h" #else #include #endif diff --git a/module_name.h b/module_name.h deleted file mode 100644 index 3aaac19..0000000 --- a/module_name.h +++ /dev/null @@ -1,9 +0,0 @@ -// Uncomment for SX126X module usage -//#define USE_SX126X - -// Check your module name at https://github.com/jgromes/RadioLib/wiki/Modules -#ifdef USE_SX126X -#define MODULE_NAME SX1268 -#else -#define MODULE_NAME SX1278 -#endif