kopia lustrzana https://github.com/sh123/esp32_loraprs
Move RF switch pin selection to config, allow to specify all options in config.h
rodzic
7ce5cb5a96
commit
901030ef47
31
config.h
31
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 LED_TOGGLE_PERIOD 1000
|
||||||
|
|
||||||
#define SERIAL_BAUD_RATE 115200
|
#define SERIAL_BAUD_RATE 115200
|
||||||
|
|
||||||
#define CFG_LOG_LEVEL DebugLogLevel::LVL_INFO
|
#define CFG_LOG_LEVEL DebugLogLevel::LVL_INFO
|
||||||
|
|
||||||
// change pinouts if not defined through native board LORA_* definitions
|
// change pinouts if not defined through native board LORA_* definitions
|
||||||
|
@ -11,25 +23,32 @@
|
||||||
#define LORA_IRQ 14
|
#define LORA_IRQ 14
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// redefine LED if not defined in Arduino to have module heartbeat indication
|
||||||
#ifndef BUILTIN_LED
|
#ifndef BUILTIN_LED
|
||||||
#pragma message("BUILDIN_LED is not found, defining as 2")
|
#pragma message("BUILDIN_LED is not found, defining as 2")
|
||||||
#define BUILTIN_LED 2
|
#define BUILTIN_LED 2
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// select between client mode and APRS-IS gate mode
|
||||||
#define CFG_IS_CLIENT_MODE true // false - server mode (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_SS SS
|
||||||
#define CFG_LORA_PIN_RST LORA_RST
|
#define CFG_LORA_PIN_RST LORA_RST
|
||||||
#define CFG_LORA_PIN_A LORA_IRQ // (sx127x - dio0, sx126x/sx128x - dio1)
|
#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)
|
#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
|
#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_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
|
#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_FREQ 433.775E6
|
||||||
#define CFG_LORA_BW 125e3
|
#define CFG_LORA_BW 125e3
|
||||||
#define CFG_LORA_SF 12
|
#define CFG_LORA_SF 12
|
||||||
|
@ -38,7 +57,7 @@
|
||||||
#define CFG_LORA_ENABLE_CRC true // set to false for speech data
|
#define CFG_LORA_ENABLE_CRC true // set to false for speech data
|
||||||
|
|
||||||
// wifi client and AP options
|
// 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 "<ssid>" // connect to SSID or run as this SSID in AP mode
|
#define CFG_WIFI_SSID "<ssid>" // connect to SSID or run as this SSID in AP mode
|
||||||
#define CFG_WIFI_KEY "<key>" // wifi key
|
#define CFG_WIFI_KEY "<key>" // wifi key
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <arduino-timer.h>
|
#include <arduino-timer.h>
|
||||||
#include <DebugLog.h>
|
#include <DebugLog.h>
|
||||||
#include "WiFi.h"
|
#include "WiFi.h"
|
||||||
|
|
||||||
#include "loraprs_service.h"
|
#include "loraprs_service.h"
|
||||||
|
|
||||||
#if __has_include("/tmp/esp32_loraprs_config.h")
|
#if __has_include("/tmp/esp32_loraprs_config.h")
|
||||||
|
@ -17,6 +18,10 @@
|
||||||
#pragma message("Configured for server mode")
|
#pragma message("Configured for server mode")
|
||||||
#endif
|
#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) {
|
void initializeConfig(LoraPrs::Config &cfg) {
|
||||||
|
|
||||||
// log level
|
// log level
|
||||||
|
@ -39,6 +44,8 @@ void initializeConfig(LoraPrs::Config &cfg) {
|
||||||
cfg.LoraPinRst = CFG_LORA_PIN_RST;
|
cfg.LoraPinRst = CFG_LORA_PIN_RST;
|
||||||
cfg.LoraPinA = CFG_LORA_PIN_A; // (sx127x - dio0, sx126x/sx128x - dio1)
|
cfg.LoraPinA = CFG_LORA_PIN_A; // (sx127x - dio0, sx126x/sx128x - dio1)
|
||||||
cfg.LoraPinB = CFG_LORA_PIN_B; // (sx127x - dio1, sx126x/sx128x - busy)
|
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.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
|
cfg.LoraUseCad = CFG_LORA_USE_CAD; // carrier detect
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,8 @@ struct Config
|
||||||
byte LoraPinRst; // lora rst pin
|
byte LoraPinRst; // lora rst pin
|
||||||
byte LoraPinA; // (sx127x - dio0, sx126x/sx128x - dio1)
|
byte LoraPinA; // (sx127x - dio0, sx126x/sx128x - dio1)
|
||||||
byte LoraPinB; // (sx127x - dio1, sx126x/sx128x - busy)
|
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 LoraUseIsr; // true to use interrupts, false for fallback polling, e.g. if Dio0 is not connected
|
||||||
bool LoraUseCad; // use carrier detect before transmitting
|
bool LoraUseCad; // use carrier detect before transmitting
|
||||||
|
|
||||||
|
|
|
@ -217,7 +217,7 @@ void Service::setupLora(long loraFreq, long bw, int sf, int cr, int pwr, int syn
|
||||||
#ifdef USE_SX126X
|
#ifdef USE_SX126X
|
||||||
#pragma message("Using SX126X")
|
#pragma message("Using SX126X")
|
||||||
LOG_INFO("Using SX126X module");
|
LOG_INFO("Using SX126X module");
|
||||||
radio_->setRfSwitchPins(4, 5);
|
radio_->setRfSwitchPins(config_.LoraPinSwitchRx, config_.LoraPinSwitchTx);
|
||||||
radio_->clearDio1Action();
|
radio_->clearDio1Action();
|
||||||
if (config_.LoraUseIsr) {
|
if (config_.LoraUseIsr) {
|
||||||
radio_->setDio1Action(onLoraDataAvailableIsr);
|
radio_->setDio1Action(onLoraDataAvailableIsr);
|
||||||
|
|
|
@ -5,13 +5,15 @@
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <DebugLog.h>
|
#include <DebugLog.h>
|
||||||
|
|
||||||
// When USE_RADIOLIB is defined then RadioLib will be used, otherwise arduino-LoRa will be used
|
// some generic options (module name, library type) are loaded from config.h
|
||||||
// When using RadioLib, default module is SX1278, if you are using
|
#if __has_include("/tmp/esp32_loraprs_config.h")
|
||||||
// different module then update MODULE_NAME in module_name.h
|
#include "/tmp/esp32_loraprs_config.h"
|
||||||
#define USE_RADIOLIB
|
#else
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_RADIOLIB
|
#ifdef USE_RADIOLIB
|
||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
#include "module_name.h"
|
|
||||||
#else
|
#else
|
||||||
#include <LoRa.h>
|
#include <LoRa.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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
|
|
Ładowanie…
Reference in New Issue