From 5554cc46a72acb56bee55613a39bd1e44095ecba Mon Sep 17 00:00:00 2001 From: Andrew Yong Date: Wed, 8 May 2024 20:15:06 +0800 Subject: [PATCH 1/5] Add REGULATORY_ prefix to LORA_REGIONCODE Add REGULATORY_ prefix to LORA_REGIONCODE to prepare for more regulatory configuration options, and update comment block accordingly too. Signed-off-by: Andrew Yong --- src/configuration.h | 6 +++--- src/mesh/RadioInterface.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 462210cf2..6dcca72dc 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -75,11 +75,11 @@ along with this program. If not, see . #endif // ----------------------------------------------------------------------------- -// Regulatory overrides for producing regional builds +// Regulatory overrides // ----------------------------------------------------------------------------- -// Define if region should override user saved region -// #define LORA_REGIONCODE meshtastic_Config_LoRaConfig_RegionCode_SG_923 +// Override user saved region, for producing region-locked builds +// #define REGULATORY_LORA_REGIONCODE meshtastic_Config_LoRaConfig_RegionCode_SG_923 // ----------------------------------------------------------------------------- // Feature toggles diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index cc6ccca07..7a1fcfb94 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -154,8 +154,8 @@ static uint8_t bytes[MAX_RHPACKETLEN]; void initRegion() { const RegionInfo *r = regions; -#ifdef LORA_REGIONCODE - for (; r->code != meshtastic_Config_LoRaConfig_RegionCode_UNSET && r->code != LORA_REGIONCODE; r++) +#ifdef REGULATORY_LORA_REGIONCODE + for (; r->code != meshtastic_Config_LoRaConfig_RegionCode_UNSET && r->code != REGULATORY_LORA_REGIONCODE; r++) ; LOG_INFO("Wanted region %d, regulatory override to %s\n", config.lora.region, r->name); #else From 3cda5986732593f23ba2c293c2b0d68ba87fe1ef Mon Sep 17 00:00:00 2001 From: Andrew Yong Date: Thu, 9 May 2024 02:27:08 +0800 Subject: [PATCH 2/5] Add REGULATORY_GAIN configuration to remain within regulatory ERP limit REGULATORY_GAIN is the total system gain in dBm to subtract from the configured Tx power, to remain within regulatory ERP limit for non-licensed operators. This value should be set in variant.h and is PA gain + antenna gain (if system ships with an antenna). This is similar to antenna_gain/NL80211_ATTR_WIPHY_ANTENNA_GAIN/NL80211_ATTR_REG_RULE_POWER_MAX_ANT_GAIN setting in Linux Regulatory/OpenWrt/mac80211/nl80211/iw. Signed-off-by: Andrew Yong --- src/configuration.h | 6 ++++++ src/mesh/RadioInterface.cpp | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index 6dcca72dc..eab2d0120 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -81,6 +81,12 @@ along with this program. If not, see . // Override user saved region, for producing region-locked builds // #define REGULATORY_LORA_REGIONCODE meshtastic_Config_LoRaConfig_RegionCode_SG_923 +// Total system gain in dBm to subtract from Tx power to remain within regulatory ERP limit for non-licensed operators +// This value should be set in variant.h and is PA gain + antenna gain (if system ships with an antenna) +#ifndef REGULATORY_GAIN +#define REGULATORY_GAIN 0 +#endif + // ----------------------------------------------------------------------------- // Feature toggles // ----------------------------------------------------------------------------- diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 7a1fcfb94..8e77beee4 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -478,8 +478,8 @@ void RadioInterface::applyModemConfig() power = loraConfig.tx_power; - if ((power == 0) || ((power > myRegion->powerLimit) && !devicestate.owner.is_licensed)) - power = myRegion->powerLimit; + if ((power == 0) || ((power + REGULATORY_GAIN > myRegion->powerLimit) && !devicestate.owner.is_licensed)) + power = myRegion->powerLimit - REGULATORY_GAIN; if (power == 0) power = 17; // Default to this power level if we don't have a valid regional power limit (powerLimit of myRegion defaults From d1d49efc6e4f5fd5294a4a3f120b739c25f522e5 Mon Sep 17 00:00:00 2001 From: Andrew Yong Date: Thu, 9 May 2024 02:27:29 +0800 Subject: [PATCH 3/5] Implement REGULATORY_GAIN and SX126X_MAX_POWER in XIAO BLE EBYTE E22 Specify REGULATORY_GAIN and SX126X_MAX_POWER to prevent exceeding regulatory and hardware limits (i.e. overloading the PA input) respectively. Also update the build flag to define EBYTE_E22_900M30S instead of just EBYTE_E22, since all the builds on the Discourse topic [New 1W DIY variant: Xiao nRF52840 + Ebyte E22-900M30S](https://meshtastic.discourse.group/t/new-1w-diy-variant-xiao-nrf52840-ebyte-e22-900m30s/7904) are using this module. That should make it clearer as well that the variant header file should be tweaked if DIY builds are using stronger (E22-900M33S, not commonly available at this time) or weaker (E22-900M22S, not popular for DIY builds due to lack of differentiation from ordinary SX1262 modules). Retain EBYTE_E22 flag alongside EBYTE_E22_900M30S build flag to prevent possible regressions in code paths generally intended for EBYTE E22 modules. Signed-off-by: Andrew Yong --- variants/xiao_ble/platformio.ini | 2 +- variants/xiao_ble/variant.h | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/variants/xiao_ble/platformio.ini b/variants/xiao_ble/platformio.ini index 8e9a663a9..165536cce 100644 --- a/variants/xiao_ble/platformio.ini +++ b/variants/xiao_ble/platformio.ini @@ -3,7 +3,7 @@ extends = nrf52840_base board = xiao_ble_sense board_level = extra -build_flags = ${nrf52840_base.build_flags} -Ivariants/xiao_ble -Dxiao_ble -D EBYTE_E22 +build_flags = ${nrf52840_base.build_flags} -Ivariants/xiao_ble -Dxiao_ble -DEBYTE_E22 -DEBYTE_E22_900M30S -L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard" build_src_filter = ${nrf52_base.build_src_filter} +<../variants/xiao_ble> lib_deps = diff --git a/variants/xiao_ble/variant.h b/variants/xiao_ble/variant.h index 77af08278..1869e4eee 100644 --- a/variants/xiao_ble/variant.h +++ b/variants/xiao_ble/variant.h @@ -142,6 +142,11 @@ static const uint8_t SCK = PIN_SPI_SCK; // (which is the default for the sx1262interface code) #define SX126X_DIO2_AS_RF_SWITCH #define SX126X_DIO3_TCXO_VOLTAGE 1.8 +#ifdef EBYTE_E22_900M30S +// 10dB PA gain and 30dB rated output; based on PA output table from Ebyte Robin +#define REGULATORY_GAIN 10 +#define SX126X_MAX_POWER 20 +#endif #endif /* From 537814df588f1c42b2a7bd4b768f743ad4d046f9 Mon Sep 17 00:00:00 2001 From: Andrew Yong Date: Wed, 22 May 2024 03:16:27 +0800 Subject: [PATCH 4/5] xiao_ble: Add EBYTE E22-900M33S PA gain and limits Signed-off-by: Andrew Yong --- variants/xiao_ble/variant.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/variants/xiao_ble/variant.h b/variants/xiao_ble/variant.h index 1869e4eee..4ca38f928 100644 --- a/variants/xiao_ble/variant.h +++ b/variants/xiao_ble/variant.h @@ -147,6 +147,11 @@ static const uint8_t SCK = PIN_SPI_SCK; #define REGULATORY_GAIN 10 #define SX126X_MAX_POWER 20 #endif +#ifdef EBYTE_E22_900M33S +// 25dB PA gain and 33dB rated output; based on TX Power Curve from E22-900M33S_UserManual_EN_v1.0.pdf +#define REGULATORY_GAIN 25 +#define SX126X_MAX_POWER 8 +#endif #endif /* From 08e1c2f68122e21030879cc3cfe34a5edef54444 Mon Sep 17 00:00:00 2001 From: Andrew Yong Date: Thu, 23 May 2024 23:28:07 +0800 Subject: [PATCH 5/5] Rename REGULATORY_GAIN to REGULATORY_GAIN_LORA to allow for other RF gain controls For example, Wi-Fi or BLE gain control (#3962) Signed-off-by: Andrew Yong --- src/configuration.h | 4 ++-- src/mesh/RadioInterface.cpp | 4 ++-- variants/xiao_ble/variant.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/configuration.h b/src/configuration.h index eab2d0120..a8b059d2c 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -83,8 +83,8 @@ along with this program. If not, see . // Total system gain in dBm to subtract from Tx power to remain within regulatory ERP limit for non-licensed operators // This value should be set in variant.h and is PA gain + antenna gain (if system ships with an antenna) -#ifndef REGULATORY_GAIN -#define REGULATORY_GAIN 0 +#ifndef REGULATORY_GAIN_LORA +#define REGULATORY_GAIN_LORA 0 #endif // ----------------------------------------------------------------------------- diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index 8e77beee4..ae05ed004 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -478,8 +478,8 @@ void RadioInterface::applyModemConfig() power = loraConfig.tx_power; - if ((power == 0) || ((power + REGULATORY_GAIN > myRegion->powerLimit) && !devicestate.owner.is_licensed)) - power = myRegion->powerLimit - REGULATORY_GAIN; + if ((power == 0) || ((power + REGULATORY_GAIN_LORA > myRegion->powerLimit) && !devicestate.owner.is_licensed)) + power = myRegion->powerLimit - REGULATORY_GAIN_LORA; if (power == 0) power = 17; // Default to this power level if we don't have a valid regional power limit (powerLimit of myRegion defaults diff --git a/variants/xiao_ble/variant.h b/variants/xiao_ble/variant.h index 4ca38f928..a86ddfde2 100644 --- a/variants/xiao_ble/variant.h +++ b/variants/xiao_ble/variant.h @@ -144,12 +144,12 @@ static const uint8_t SCK = PIN_SPI_SCK; #define SX126X_DIO3_TCXO_VOLTAGE 1.8 #ifdef EBYTE_E22_900M30S // 10dB PA gain and 30dB rated output; based on PA output table from Ebyte Robin -#define REGULATORY_GAIN 10 +#define REGULATORY_GAIN_LORA 10 #define SX126X_MAX_POWER 20 #endif #ifdef EBYTE_E22_900M33S // 25dB PA gain and 33dB rated output; based on TX Power Curve from E22-900M33S_UserManual_EN_v1.0.pdf -#define REGULATORY_GAIN 25 +#define REGULATORY_GAIN_LORA 25 #define SX126X_MAX_POWER 8 #endif #endif