From 14269286eb6eaa66b53d41ebfe02265bc6fb7c71 Mon Sep 17 00:00:00 2001 From: Leeroy <135471162+LeeroysHub@users.noreply.github.com> Date: Thu, 12 Feb 2026 18:04:53 +1100 Subject: [PATCH 1/3] TX Power: Use correct Offset and Values for FM PA table. --- .../main/subghz/helpers/subghz_txrx.c | 50 +++++++++++++------ .../scenes/subghz_scene_radio_settings.c | 6 +-- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index 46d0a7eef..93f197399 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -110,25 +110,45 @@ void subghz_txrx_set_preset( uint8_t* subghz_txrx_set_tx_power(uint8_t* preset_data, size_t preset_data_size, uint32_t tx_power) { -#define TX_POWER_OFFSET 7 -#define TX_PRESET_POWER_COUNT 11 - const uint32_t tx_power_value[TX_PRESET_POWER_COUNT] = { +#define TX_POWER_OFFSET_FM 8 +#define TX_POWER_OFFSET_AM 7 +#define TX_PRESET_POWER_COUNT 9 + //I had to skip the +10dBM and -6dBm Values, use only ones AM/FM have in common. + //Highest Value is 12dBm for AM, 10 for FM. So Menu needs to reflect that. + const uint8_t tx_power_value_AM[TX_PRESET_POWER_COUNT] = { 0, - 0xC0, - 0xC5, - 0xCD, - 0x86, - 0x50, - 0x37, - 0x26, - 0x1D, - 0x17, - 0x03, + 0xC0, //12dBm + 0xCD, //7dBm + 0x86, //5dBm + 0x50, //0dBm + 0x26, // -10dBm + 0x1D, // -15dBm + 0x17, //-20dBm + 0x03 //-30dBm + }; + + //FM PATable Values. We have 8, not 10 (missing 12dBM and -6dBm that are in AM) + const uint8_t tx_power_value_FM[TX_PRESET_POWER_COUNT] = { + 0, + 0xC0, // 10dBm + 0xC8, //7dBm + 0x84, //5dBm + 0x60, //0dBm + 0x34, //-10dBm + 0x1D, //-15dBm + 0x0E, // -20dBm + 0x12, //-30dBm }; //Set the TX Power Here in the CC1101 register... - if(tx_power) - preset_data[preset_data_size - TX_POWER_OFFSET] = (uint8_t)tx_power_value[tx_power]; + if(tx_power) { + //Are we on an AM or FM preset? The PA table is different! + if(preset_data[preset_data_size - TX_POWER_OFFSET_FM]) { + preset_data[preset_data_size - TX_POWER_OFFSET_FM] = tx_power_value_FM[tx_power]; + } else if(preset_data[preset_data_size - TX_POWER_OFFSET_AM]) { + preset_data[preset_data_size - TX_POWER_OFFSET_AM] = tx_power_value_AM[tx_power]; + } //else //Must be a custom Preset with weird PA table not in FW code, dont touch it. + } //Pass back the preset_so we can call one liners. return preset_data; diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index 87e2d8269..be75723be 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -67,15 +67,13 @@ const int32_t debug_counter_val[DEBUG_COUNTER_COUNT] = { }; //TX Power -#define TX_POWER_COUNT 11 +#define TX_POWER_COUNT 9 const char* const tx_power_text[TX_POWER_COUNT] = { "Preset", - "12dBm", - "10dBm", + "10dBm +", "7dBm", "5dBm", "0dBm", - "-6dBm", "-10dBm", "-15dBm", "-20dBm", From c6421c9fff228f8ea5ca714cc9d48449f092e5fa Mon Sep 17 00:00:00 2001 From: Leeroy <135471162+LeeroysHub@users.noreply.github.com> Date: Thu, 12 Feb 2026 21:42:03 +1100 Subject: [PATCH 2/3] REFACTOR: Tx power fixes (Use 1 array, dont play with Weird Custom Presets) --- .../main/subghz/helpers/subghz_txrx.c | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index 93f197399..4c2765196 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -110,12 +110,14 @@ void subghz_txrx_set_preset( uint8_t* subghz_txrx_set_tx_power(uint8_t* preset_data, size_t preset_data_size, uint32_t tx_power) { -#define TX_POWER_OFFSET_FM 8 -#define TX_POWER_OFFSET_AM 7 -#define TX_PRESET_POWER_COUNT 9 +#define PRESET_POWER_OFFSET_FM 8 +#define PRESET_POWER_OFFSET_AM 7 +#define TX_PATABLE_OFFSET_AM 8 +#define TX_PATABLE_COUNT 17 + //I had to skip the +10dBM and -6dBm Values, use only ones AM/FM have in common. //Highest Value is 12dBm for AM, 10 for FM. So Menu needs to reflect that. - const uint8_t tx_power_value_AM[TX_PRESET_POWER_COUNT] = { + const uint8_t tx_pa_table[TX_PATABLE_COUNT] = { 0, 0xC0, //12dBm 0xCD, //7dBm @@ -124,12 +126,7 @@ uint8_t* 0x26, // -10dBm 0x1D, // -15dBm 0x17, //-20dBm - 0x03 //-30dBm - }; - - //FM PATable Values. We have 8, not 10 (missing 12dBM and -6dBm that are in AM) - const uint8_t tx_power_value_FM[TX_PRESET_POWER_COUNT] = { - 0, + 0x03, //-30dBm 0xC0, // 10dBm 0xC8, //7dBm 0x84, //5dBm @@ -142,12 +139,19 @@ uint8_t* //Set the TX Power Here in the CC1101 register... if(tx_power) { - //Are we on an AM or FM preset? The PA table is different! - if(preset_data[preset_data_size - TX_POWER_OFFSET_FM]) { - preset_data[preset_data_size - TX_POWER_OFFSET_FM] = tx_power_value_FM[tx_power]; - } else if(preset_data[preset_data_size - TX_POWER_OFFSET_AM]) { - preset_data[preset_data_size - TX_POWER_OFFSET_AM] = tx_power_value_AM[tx_power]; - } //else //Must be a custom Preset with weird PA table not in FW code, dont touch it. + //Grab the AM and FM byte now, so we can do proper checks. + uint8_t fm_byte = preset_data[preset_data_size - PRESET_POWER_OFFSET_FM]; + uint8_t am_byte = preset_data[preset_data_size - PRESET_POWER_OFFSET_AM]; + + //If we have both bytes 1st bytes set or none, this isnt a preset we can deal with here. + if(fm_byte & !am_byte) { + //Use FM Table + preset_data[preset_data_size - PRESET_POWER_OFFSET_FM] = tx_pa_table[tx_power]; + } else if(am_byte & !fm_byte) { + //Use AM Table + preset_data[preset_data_size - PRESET_POWER_OFFSET_AM] = + tx_pa_table[TX_PATABLE_OFFSET_AM + tx_power]; + } } //Pass back the preset_so we can call one liners. From 9eb8e475ccb46aa28e193d25a325401bf5b0d68c Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 12 Feb 2026 20:24:32 +0300 Subject: [PATCH 3/3] fix switching, etc. --- .../main/subghz/helpers/subghz_txrx.c | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index cf066acbf..9e972ad40 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -109,7 +109,7 @@ void subghz_txrx_set_preset( } uint8_t* - subghz_txrx_set_tx_power(uint8_t* preset_data, size_t preset_data_size, uint32_t tx_power) { + subghz_txrx_set_tx_power(uint8_t* preset_data, size_t preset_data_size, uint8_t tx_power) { #define PRESET_POWER_OFFSET_FM 8 #define PRESET_POWER_OFFSET_AM 7 #define TX_PATABLE_OFFSET_AM 8 @@ -137,20 +137,29 @@ uint8_t* 0x12, //-30dBm }; - //Set the TX Power Here in the CC1101 register... - if(tx_power) { - //Grab the AM and FM byte now, so we can do proper checks. - uint8_t fm_byte = preset_data[preset_data_size - PRESET_POWER_OFFSET_FM]; - uint8_t am_byte = preset_data[preset_data_size - PRESET_POWER_OFFSET_AM]; + //Grab the AM and FM byte now, so we can do proper checks. + uint8_t fm_byte = preset_data[preset_data_size - PRESET_POWER_OFFSET_FM]; + uint8_t am_byte = preset_data[preset_data_size - PRESET_POWER_OFFSET_AM]; - //If we have both bytes 1st bytes set or none, this isnt a preset we can deal with here. - if(fm_byte & !am_byte) { - //Use FM Table - preset_data[preset_data_size - PRESET_POWER_OFFSET_FM] = tx_pa_table[tx_power]; - } else if(am_byte & !fm_byte) { - //Use AM Table - preset_data[preset_data_size - PRESET_POWER_OFFSET_AM] = + //Set the TX Power Here in the CC1101 register... + + //If we have both bytes 1st bytes set or none, this isnt a preset we can deal with here. + if(fm_byte && !am_byte) { + //Use FM Table + if(tx_power) { + preset_data[preset_data_size - PRESET_POWER_OFFSET_FM] = tx_pa_table[TX_PATABLE_OFFSET_AM + tx_power]; + } else { + preset_data[preset_data_size - PRESET_POWER_OFFSET_FM] = + tx_pa_table[1]; //Max Power 0xC0 10dBm + } + } else if(am_byte && !fm_byte) { + //Use AM Table + if(tx_power) { + preset_data[preset_data_size - PRESET_POWER_OFFSET_AM] = tx_pa_table[tx_power]; + } else { + preset_data[preset_data_size - PRESET_POWER_OFFSET_AM] = + tx_pa_table[1]; //Max Power 0xC0 12dBm } }