Move RF switch pin selection to config, allow to specify all options in config.h

pull/42/head
sh123 2021-11-15 15:44:37 +02:00
rodzic 7ce5cb5a96
commit 901030ef47
6 zmienionych plików z 42 dodań i 21 usunięć

Wyświetl plik

@ -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 "<ssid>" // connect to SSID or run as this SSID in AP mode
#define CFG_WIFI_KEY "<key>" // wifi key

Wyświetl plik

@ -1,6 +1,7 @@
#include <arduino-timer.h>
#include <DebugLog.h>
#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

Wyświetl plik

@ -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

Wyświetl plik

@ -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);

Wyświetl plik

@ -5,13 +5,15 @@
#include <SPI.h>
#include <DebugLog.h>
// 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 <RadioLib.h>
#include "module_name.h"
#else
#include <LoRa.h>
#endif

Wyświetl plik

@ -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