Remove ENABLE_AM_FIX

This commit is contained in:
Armel FAUVEAU committed 2026-08-22 13:52:04 +02:00
1 parent 7d550585d0
commit 66fb8b1ed4
19 files changed
+4 -900

No files matched your search

-397
View File
@@ -1,397 +0,0 @@
/* Copyright 2023 OneOfEleven
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// code to 'try' and reduce the AM demodulator saturation problem
//
// that is until someone works out how to properly configure the BK chip !
#include <string.h>
#include "am_fix.h"
#include "app/main.h"
#include "board.h"
#include "driver/bk4819.h"
#include "external/printf/printf.h"
#include "frequencies.h"
#include "functions.h"
#include "misc.h"
#include "settings.h"
#ifdef ENABLE_AGC_SHOW_DATA
#include "ui/main.h"
#endif
#ifdef ENABLE_AM_FIX
typedef struct
{
uint16_t reg_val;
int8_t gain_dB;
} __attribute__((packed)) t_gain_table;
// REG_10 AGC gain table
//
// <15:10> ???
//
// <9:8> = LNA Gain Short
// 3 = 0dB < original value
// 2 = -19dB // was -11
// 1 = -24dB // was -16
// 0 = -28dB // was -19
//
// <7:5> = LNA Gain
// 7 = 0dB
// 6 = -2dB
// 5 = -4dB < original value
// 4 = -6dB
// 3 = -9dB
// 2 = -14dB
// 1 = -19dB
// 0 = -24dB
//
// <4:3> = MIXER Gain
// 3 = 0dB < original value
// 2 = -3dB
// 1 = -6dB
// 0 = -8dB
//
// <2:0> = PGA Gain
// 7 = 0dB
// 6 = -3dB < original value
// 5 = -6dB
// 4 = -9dB
// 3 = -15dB
// 2 = -21dB
// 1 = -27dB
// 0 = -33dB
// front end register dB values
//
// these values need to be accurate for the code to properly/reliably switch
// between table entries when adjusting the front end registers.
//
// these 4 tables need a measuring/calibration update
//
//// static const int16_t lna_short_dB[] = { -19, -16, -11, 0}; // was (but wrong)
// static const int16_t lna_short_dB[] = { (-28), (-24), (-19), 0}; // corrected'ish
// static const int16_t lna_dB[] = { (-24), (-19), (-14), ( -9), (-6), (-4), (-2), 0};
// static const int16_t mixer_dB[] = { ( -8), ( -6), ( -3), 0};
// static const int16_t pga_dB[] = { (-33), (-27), (-21), (-15), (-9), (-6), (-3), 0};
// lookup table is hugely easier than writing code to do the same
//
#define LOOKUP_TABLE 1
#if LOOKUP_TABLE
static const t_gain_table gain_table[] =
{
{0x03BE, -7}, // 0 .. 3 5 3 6 .. 0dB -4dB 0dB -3dB .. -7dB original
{0x0000,-93}, // 1 .. 0 0 0 0 .. -28dB -24dB -8dB -33dB .. -93dB
{0x0008,-91}, // 2 .. 0 0 1 0 .. -28dB -24dB -6dB -33dB .. -91dB
{0x0010,-88}, // 3 .. 0 0 2 0 .. -28dB -24dB -3dB -33dB .. -88dB
{0x0001,-87}, // 4 .. 0 0 0 1 .. -28dB -24dB -8dB -27dB .. -87dB
{0x0009,-85}, // 5 .. 0 0 1 1 .. -28dB -24dB -6dB -27dB .. -85dB
{0x0011,-82}, // 6 .. 0 0 2 1 .. -28dB -24dB -3dB -27dB .. -82dB
{0x0002,-81}, // 7 .. 0 0 0 2 .. -28dB -24dB -8dB -21dB .. -81dB
{0x000A,-79}, // 8 .. 0 0 1 2 .. -28dB -24dB -6dB -21dB .. -79dB
{0x0012,-76}, // 9 .. 0 0 2 2 .. -28dB -24dB -3dB -21dB .. -76dB
{0x0003,-75}, // 10 .. 0 0 0 3 .. -28dB -24dB -8dB -15dB .. -75dB
{0x000B,-73}, // 11 .. 0 0 1 3 .. -28dB -24dB -6dB -15dB .. -73dB
{0x0013,-70}, // 12 .. 0 0 2 3 .. -28dB -24dB -3dB -15dB .. -70dB
{0x0004,-69}, // 13 .. 0 0 0 4 .. -28dB -24dB -8dB -9dB .. -69dB
{0x000C,-67}, // 14 .. 0 0 1 4 .. -28dB -24dB -6dB -9dB .. -67dB
{0x000D,-64}, // 15 .. 0 0 1 5 .. -28dB -24dB -6dB -6dB .. -64dB
{0x001C,-61}, // 16 .. 0 0 3 4 .. -28dB -24dB 0dB - 9dB .. -61dB
{0x001D,-58}, // 17 .. 0 0 3 5 .. -28dB -24dB 0dB -6dB .. -58dB
{0x001E,-55}, // 18 .. 0 0 3 6 .. -28dB -24dB 0dB -3dB .. -55dB
{0x001F,-52}, // 19 .. 0 0 3 7 .. -28dB -24dB 0dB 0dB .. -52dB
{0x003E,-50}, // 20 .. 0 1 3 6 .. -28dB -19dB 0dB -3dB .. -50dB
{0x003F,-47}, // 21 .. 0 1 3 7 .. -28dB -19dB 0dB 0dB .. -47dB
{0x005E,-45}, // 22 .. 0 2 3 6 .. -28dB -14dB 0dB -3dB .. -45dB
{0x005F,-42}, // 23 .. 0 2 3 7 .. -28dB -14dB 0dB 0dB .. -42dB
{0x007E,-40}, // 24 .. 0 3 3 6 .. -28dB -9dB 0dB -3dB .. -40dB
{0x007F,-37}, // 25 .. 0 3 3 7 .. -28dB -9dB 0dB 0dB .. -37dB
{0x009F,-34}, // 26 .. 0 4 3 7 .. -28dB -6dB 0dB 0dB .. -34dB
{0x00BF,-32}, // 27 .. 0 5 3 7 .. -28dB -4dB 0dB 0dB .. -32dB
{0x00DF,-30}, // 28 .. 0 6 3 7 .. -28dB -2dB 0dB 0dB .. -30dB
{0x00FF,-28}, // 29 .. 0 7 3 7 .. -28dB 0dB 0dB 0dB .. -28dB
{0x01DF,-26}, // 30 .. 1 6 3 7 .. -24dB -2dB 0dB 0dB .. -26dB
{0x01FF,-24}, // 31 .. 1 7 3 7 .. -24dB 0dB 0dB 0dB .. -24dB
{0x02BF,-23}, // 32 .. 2 5 3 7 .. -19dB -4dB 0dB 0dB .. -23dB
{0x02DF,-21}, // 33 .. 2 6 3 7 .. -19dB -2dB 0dB -0dB .. -21dB
{0x02FF,-19}, // 34 .. 2 7 3 7 .. -19dB 0dB 0dB 0dB .. -19dB
{0x035E,-17}, // 35 .. 3 2 3 6 .. 0dB -14dB 0dB -3dB .. -17dB
{0x035F,-14}, // 36 .. 3 2 3 7 .. 0dB -14dB 0dB 0dB .. -14dB
{0x037E,-12}, // 37 .. 3 3 3 6 .. 0dB -9dB 0dB -3dB .. -12dB
{0x037F,-9}, // 38 .. 3 3 3 7 .. 0dB -9dB 0dB 0dB .. -9dB
{0x038F,-6}, // 39 .. 3 4 3 7 .. 0dB - 6dB 0dB 0dB .. -6dB
{0x03BF,-4}, // 40 .. 3 5 3 7 .. 0dB -4dB 0dB 0dB .. -4dB
{0x03DF,-2}, // 41 .. 3 6 3 7 .. 0dB - 2dB 0dB 0dB .. -2dB
{0x03FF,0} // 42 .. 3 7 3 7 .. 0dB 0dB 0dB 0dB .. 0dB
};
const uint8_t gain_table_size = ARRAY_SIZE(gain_table);
#else
t_gain_table gain_table[100] = {{0x03BE, -7}}; //original
uint8_t gain_table_size = 0;
void CreateTable()
{
typedef union {
struct {
uint8_t pgaIdx:3;
uint8_t mixerIdx:2;
uint8_t lnaIdx:3;
uint8_t lnaSIdx:2;
};
uint16_t __raw;
} GainData;
static const int8_t lna_short_dB[] = {-28, -24, -19, 0}; // corrected'ish
static const int8_t lna_dB[] = {-24, -19, -14, -9, -6, -4, -2, 0};
static const int8_t mixer_dB[] = { -8, -6, -3, 0};
static const int8_t pga_dB[] = {-33, -27, -21, -15, -9, -6, -3, 0};
unsigned i;
for (uint8_t lnaSIdx = 0; lnaSIdx < ARRAY_SIZE(lna_short_dB); lnaSIdx++) {
for (uint8_t lnaIdx = 0; lnaIdx < ARRAY_SIZE(lna_dB); lnaIdx++) {
for (uint8_t mixerIdx = 0; mixerIdx < ARRAY_SIZE(mixer_dB); mixerIdx++) {
for (uint8_t pgaIdx = 0; pgaIdx < ARRAY_SIZE(pga_dB); pgaIdx++) {
int16_t db = lna_short_dB[lnaSIdx] + lna_dB[lnaIdx] + mixer_dB[mixerIdx] + pga_dB[pgaIdx];
GainData gainData = {{
pgaIdx,
mixerIdx,
lnaIdx,
lnaSIdx,
}};
for (i = 1; i < ARRAY_SIZE(gain_table); i++) {
t_gain_table * gain = &gain_table[i];
if (db == gain->gain_dB)
break;
if (db > gain->gain_dB)
continue;
if (db < gain->gain_dB) {
if(gain->gain_dB)
memmove(gain + 1, gain, 100 - i);
gain->gain_dB = db;
gain->reg_val = gainData.__raw;
break;
}
gain->gain_dB = db;
gain->reg_val = gainData.__raw;
break;
}
}
}
}
}
gain_table_size = i+1;
}
#endif
#ifdef ENABLE_AM_FIX_SHOW_DATA
// display update rate
static const unsigned int display_update_rate = 250 / 10; // max 250ms display update rate
unsigned int counter = 0;
#endif
unsigned int gain_table_index[2] = {0, 0};
// used simply to detect a changed gain setting
unsigned int gain_table_index_prev[2] = {0, 0};
// holds the previous RSSI level .. we do an average of old + new RSSI reading
int16_t prev_rssi[2] = {0, 0};
// to help reduce gain hunting, peak hold count down tick
unsigned int hold_counter[2] = {0, 0};
// -89dBm, any higher and the AM demodulator starts to saturate/clip/distort
const int16_t desired_rssi = (-89 + 160) * 2;
int8_t currentGainDiff;
bool enabled = true;
void AM_fix_init(void)
{ // called at boot-up
for (int i = 0; i < 2; i++) {
gain_table_index[i] = 0; // re-start with original QS setting
}
#if !LOOKUP_TABLE
CreateTable();
#endif
}
void AM_fix_reset(const unsigned vfo)
{ // reset the AM fixer upper
if (vfo > 1)
return;
#ifdef ENABLE_AM_FIX_SHOW_DATA
counter = 0;
#endif
prev_rssi[vfo] = 0;
hold_counter[vfo] = 0;
gain_table_index_prev[vfo] = 0;
}
// adjust the RX gain to try and prevent the AM demodulator from
// saturating/overloading/clipping (distorted AM audio)
//
// we're actually doing the BK4819's job for it here, but as the chip
// won't/don't do it for itself, we're left to bodging it ourself by
// playing with the RF front end gain setting
//
void AM_fix_10ms(const unsigned vfo)
{
if(!gSetting_AM_fix || !enabled || vfo > 1 )
return;
if (gCurrentFunction != FUNCTION_FOREGROUND && !FUNCTION_IsRx()) {
#ifdef ENABLE_AM_FIX_SHOW_DATA
counter = display_update_rate; // queue up a display update as soon as we switch to RX mode
#endif
return;
}
#ifdef ENABLE_AM_FIX_SHOW_DATA
if (counter > 0) {
if (++counter >= display_update_rate) { // trigger a display update
counter = 0;
gUpdateDisplay = true;
}
}
#endif
static uint32_t lastFreq[2];
if(gEeprom.VfoInfo[vfo].pRX->Frequency != lastFreq[vfo]) {
lastFreq[vfo] = gEeprom.VfoInfo[vfo].pRX->Frequency;
AM_fix_reset(vfo);
}
int16_t rssi;
{ // sample the current RSSI level
// average it with the previous rssi (a bit of noise/spike immunity)
const int16_t new_rssi = BK4819_GetRSSI();
rssi = (prev_rssi[vfo] > 0) ? (prev_rssi[vfo] + new_rssi) / 2 : new_rssi;
prev_rssi[vfo] = new_rssi;
}
#ifdef ENABLE_AM_FIX_SHOW_DATA
{
static int16_t lastRssi;
if (lastRssi != rssi) { // rssi changed
lastRssi = rssi;
if (counter == 0) {
counter = 1;
gUpdateDisplay = true; // trigger a display update
}
}
}
#endif
// automatically adjust the RF RX gain
// update the gain hold counter
if (hold_counter[vfo] > 0)
hold_counter[vfo]--;
// dB difference between actual and desired RSSI level
int16_t diff_dB = (rssi - desired_rssi) / 2;
if (diff_dB > 0) { // decrease gain
unsigned int index = gain_table_index[vfo]; // current position we're at
if (diff_dB >= 10) { // jump immediately to a new gain setting
// this greatly speeds up initial gain reduction (but reduces noise/spike immunity)
const int16_t desired_gain_dB = (int16_t)gain_table[index].gain_dB - diff_dB + 8; // get no closer than 8dB (bit of noise/spike immunity)
// scan the table to see what index to jump straight too
while (index > 1)
if (gain_table[--index].gain_dB <= desired_gain_dB)
break;
}
else
{ // incrementally reduce the gain .. taking it slow improves noise/spike immunity
if (index > 1)
index--; // slow step-by-step gain reduction
}
index = MAX(1u, index);
if (gain_table_index[vfo] != index)
{
gain_table_index[vfo] = index;
hold_counter[vfo] = 30; // 300ms hold
}
}
if (diff_dB >= -6) // 6dB hysterisis (help reduce gain hunting)
hold_counter[vfo] = 30; // 300ms hold
if (hold_counter[vfo] == 0)
{ // hold has been released, we're free to increase gain
const unsigned int index = gain_table_index[vfo] + 1; // move up to next gain index
gain_table_index[vfo] = MIN(index, gain_table_size - 1u);
}
{ // apply the new settings to the front end registers
const unsigned int index = gain_table_index[vfo];
// remember the new table index
gain_table_index_prev[vfo] = index;
currentGainDiff = gain_table[0].gain_dB - gain_table[index].gain_dB;
BK4819_WriteRegister(BK4819_REG_13, gain_table[index].reg_val);
#ifdef ENABLE_AGC_SHOW_DATA
UI_MAIN_PrintAGC(true);
#endif
}
#ifdef ENABLE_AM_FIX_SHOW_DATA
if (counter == 0) {
counter = 1;
gUpdateDisplay = true;
}
#endif
}
#ifdef ENABLE_AM_FIX_SHOW_DATA
void AM_fix_print_data(const unsigned vfo, char *s) {
if (s != NULL && vfo < ARRAY_SIZE(gain_table_index)) {
const unsigned int index = gain_table_index[vfo];
sprintf(s, "%2u %4ddB %3u", index, gain_table[index].gain_dB, prev_rssi[vfo]);
counter = 0;
}
}
#endif
int8_t AM_fix_get_gain_diff()
{
return currentGainDiff;
}
void AM_fix_enable(bool on)
{
enabled = on;
}
#endif
-35
View File
@@ -1,35 +0,0 @@
/* Copyright 2023 OneOfEleven
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef AM_FIXH
#include <stdint.h>
#include <stdbool.h>
#ifdef ENABLE_AM_FIX
void AM_fix_init(void);
void AM_fix_reset(const unsigned vfo);
void AM_fix_10ms(const unsigned vfo);
#ifdef ENABLE_AM_FIX_SHOW_DATA
void AM_fix_print_data(const unsigned vfo, char *s);
#endif
int8_t AM_fix_get_gain_diff();
void AM_fix_enable(bool on);
#endif
#endif
-4
View File
@@ -675,11 +675,7 @@ void ACTION_Wn(void)
} }
#endif #endif
#ifdef ENABLE_AM_FIX
BK4819_SetFilterBandwidth(bw, true);
#else
BK4819_SetFilterBandwidth(bw, false); BK4819_SetFilterBandwidth(bw, false);
#endif
} }
void ACTION_BackLight(void) void ACTION_BackLight(void)
-7
View File
@@ -18,7 +18,6 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include "am_fix.h"
#include "app/action.h" #include "app/action.h"
#ifdef ENABLE_AIRCOPY #ifdef ENABLE_AIRCOPY
@@ -1605,12 +1604,6 @@ void APP_TimeSlice10ms(void)
gFlashLightBlinkCounter++; gFlashLightBlinkCounter++;
#ifdef ENABLE_AM_FIX
if (gRxVfo->Modulation == MODULATION_AM) {
AM_fix_10ms(gEeprom.RX_VFO);
}
#endif
#ifdef ENABLE_UART #ifdef ENABLE_UART
if (UART_IsCommandAvailable(UART_PORT_UART)) { if (UART_IsCommandAvailable(UART_PORT_UART)) {
// SCHEDULER_Disable(); // SCHEDULER_Disable();
-4
View File
@@ -553,11 +553,7 @@ static void ScanFastApplyChannelShape(ModulationMode_t modulation)
} }
else else
{ {
#ifdef ENABLE_AM_FIX
BK4819_SetFilterBandwidth(BK4819_FILTER_BW_WIDE, true);
#else
BK4819_SetFilterBandwidth(BK4819_FILTER_BW_WIDE, false); BK4819_SetFilterBandwidth(BK4819_FILTER_BW_WIDE, false);
#endif
} }
if (modulationChanged) if (modulationChanged)
-23
View File
@@ -233,11 +233,6 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax)
break; break;
#endif #endif
#ifndef ENABLE_FEAT_F4HWN
#ifdef ENABLE_AM_FIX
case MENU_AM_FIX:
#endif
#endif
#ifdef ENABLE_AUDIO_BAR #ifdef ENABLE_AUDIO_BAR
case MENU_MIC_BAR: case MENU_MIC_BAR:
#endif #endif
@@ -844,16 +839,6 @@ void MENU_AcceptSetting(void)
gRequestSaveChannel = 1; gRequestSaveChannel = 1;
return; return;
#ifndef ENABLE_FEAT_F4HWN
#ifdef ENABLE_AM_FIX
case MENU_AM_FIX:
gSetting_AM_fix = gSubMenuSelection;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
gFlagResetVfos = true;
break;
#endif
#endif
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
case MENU_NOAA_S: case MENU_NOAA_S:
gEeprom.NOAA_AUTO_SCAN = gSubMenuSelection; gEeprom.NOAA_AUTO_SCAN = gSubMenuSelection;
@@ -1344,14 +1329,6 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gTxVfo->Modulation; gSubMenuSelection = gTxVfo->Modulation;
break; break;
#ifndef ENABLE_FEAT_F4HWN
#ifdef ENABLE_AM_FIX
case MENU_AM_FIX:
gSubMenuSelection = gSetting_AM_fix;
break;
#endif
#endif
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
case MENU_NOAA_S: case MENU_NOAA_S:
gSubMenuSelection = gEeprom.NOAA_AUTO_SCAN; gSubMenuSelection = gEeprom.NOAA_AUTO_SCAN;
-11
View File
@@ -14,7 +14,6 @@
* limitations under the License. * limitations under the License.
*/ */
#include "app/spectrum.h" #include "app/spectrum.h"
#include "am_fix.h"
#include "audio.h" #include "audio.h"
#include "misc.h" #include "misc.h"
@@ -608,10 +607,6 @@ uint16_t GetRssi()
// Discard first read (AGC may still be transitioning), keep second // Discard first read (AGC may still be transitioning), keep second
BK4819_GetRSSI(); BK4819_GetRSSI();
uint16_t rssi = BK4819_GetRSSI(); uint16_t rssi = BK4819_GetRSSI();
#ifdef ENABLE_AM_FIX
if (settings.modulationType == MODULATION_AM && gSetting_AM_fix)
rssi += AM_fix_get_gain_diff() * 2;
#endif
return rssi; return rssi;
} }
@@ -2474,12 +2469,6 @@ static void Tick()
if (gNextTimeslice) if (gNextTimeslice)
{ {
gNextTimeslice = false; gNextTimeslice = false;
#ifdef ENABLE_AM_FIX
if (settings.modulationType == MODULATION_AM && !lockAGC)
{
AM_fix_10ms(vfo); // allow AM_Fix to apply its AGC action
}
#endif
BACKLIGHT_Update(); BACKLIGHT_Update();
} }
-1
View File
@@ -7,7 +7,6 @@
#include "driver/bk4819.h" #include "driver/bk4819.h"
#include "string.h" #include "string.h"
#include "external/printf/printf.h" #include "external/printf/printf.h"
#include "am_fix.h"
static inline void LogUart(const char *const str) static inline void LogUart(const char *const str)
{ {
-8
View File
@@ -18,10 +18,6 @@
#include <string.h> #include <string.h>
#include <stdio.h> // NULL #include <stdio.h> // NULL
#ifdef ENABLE_AM_FIX
#include "am_fix.h"
#endif
#include "audio.h" #include "audio.h"
#include "board.h" #include "board.h"
#ifdef ENABLE_FEAT_F4HWN_RXTX_LOG #ifdef ENABLE_FEAT_F4HWN_RXTX_LOG
@@ -138,10 +134,6 @@ void Main(void)
BATTERY_GetReadings(false); BATTERY_GetReadings(false);
#ifdef ENABLE_AM_FIX
AM_fix_init();
#endif
BOOT_Mode_t BootMode = BOOT_GetMode(); BOOT_Mode_t BootMode = BOOT_GetMode();
#ifdef ENABLE_FEAT_F4HWN_MULTIBOOT #ifdef ENABLE_FEAT_F4HWN_MULTIBOOT
-4
View File
@@ -107,10 +107,6 @@ bool gSetting_ScrambleEnable;
enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx; enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx;
#ifdef ENABLE_AM_FIX
bool gSetting_AM_fix = true;
#endif
#ifdef ENABLE_FEAT_F4HWN_SLEEP #ifdef ENABLE_FEAT_F4HWN_SLEEP
uint8_t gSetting_set_off = 1; uint8_t gSetting_set_off = 1;
bool gWakeUp = false; bool gWakeUp = false;
-4
View File
@@ -159,10 +159,6 @@ extern bool gSetting_ScrambleEnable;
extern enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx; extern enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx;
#ifdef ENABLE_AM_FIX
extern bool gSetting_AM_fix;
#endif
#ifdef ENABLE_FEAT_F4HWN_SLEEP #ifdef ENABLE_FEAT_F4HWN_SLEEP
extern uint8_t gSetting_set_off; extern uint8_t gSetting_set_off;
extern bool gWakeUp; extern bool gWakeUp;
-19
View File
@@ -17,7 +17,6 @@
#include "driver/bk4819-regs.h" #include "driver/bk4819-regs.h"
#include <string.h> #include <string.h>
#include "am_fix.h"
#include "app/dtmf.h" #include "app/dtmf.h"
#ifdef ENABLE_FEAT_F4HWN_RXTX_LOG #ifdef ENABLE_FEAT_F4HWN_RXTX_LOG
#include "app/rxtx_log.h" #include "app/rxtx_log.h"
@@ -767,12 +766,7 @@ void RADIO_SetupRegisters(bool switchToForeground)
case BK4819_FILTER_BW_WIDE: case BK4819_FILTER_BW_WIDE:
case BK4819_FILTER_BW_NARROW: case BK4819_FILTER_BW_NARROW:
case BK4819_FILTER_BW_NARROWER: case BK4819_FILTER_BW_NARROWER:
#ifdef ENABLE_AM_FIX
// BK4819_SetFilterBandwidth(Bandwidth, gRxVfo->Modulation == MODULATION_AM && gSetting_AM_fix);
BK4819_SetFilterBandwidth(Bandwidth, true);
#else
BK4819_SetFilterBandwidth(Bandwidth, false); BK4819_SetFilterBandwidth(Bandwidth, false);
#endif
break; break;
} }
} }
@@ -994,12 +988,7 @@ void RADIO_SetTxParameters(void)
case BK4819_FILTER_BW_WIDE: case BK4819_FILTER_BW_WIDE:
case BK4819_FILTER_BW_NARROW: case BK4819_FILTER_BW_NARROW:
case BK4819_FILTER_BW_NARROWER: case BK4819_FILTER_BW_NARROWER:
#ifdef ENABLE_AM_FIX
// BK4819_SetFilterBandwidth(Bandwidth, gCurrentVfo->Modulation == MODULATION_AM && gSetting_AM_fix);
BK4819_SetFilterBandwidth(Bandwidth, true);
#else
BK4819_SetFilterBandwidth(Bandwidth, false); BK4819_SetFilterBandwidth(Bandwidth, false);
#endif
break; break;
} }
@@ -1150,14 +1139,6 @@ void RADIO_SetupAGC(bool listeningAM, bool disable)
return; return;
lastSettings = newSettings; lastSettings = newSettings;
#ifdef ENABLE_AM_FIX
if (listeningAM && gSetting_AM_fix) {
BK4819_SetAGC(0);
AM_fix_enable(!disable);
return;
}
#endif
BK4819_SetAGC(!disable); BK4819_SetAGC(!disable);
BK4819_InitAGC(listeningAM); BK4819_InitAGC(listeningAM);
} }
+3 -13
View File
@@ -375,11 +375,7 @@ gEeprom.FreqChannel[1] = IS_FREQ_CHANNEL(Data16[5]) ? Data16[5] : (FREQ_CHANNE
#ifdef ENABLE_AUDIO_BAR #ifdef ENABLE_AUDIO_BAR
gSetting_mic_bar = !!(Data[7] & (1u << 4)); gSetting_mic_bar = !!(Data[7] & (1u << 4));
#endif #endif
#ifndef ENABLE_FEAT_F4HWN // Data[7] bit 5 is reserved (legacy ENABLE_AM_FIX).
#ifdef ENABLE_AM_FIX
gSetting_AM_fix = !!(Data[7] & (1u << 5));
#endif
#endif
gSetting_backlight_on_tx_rx = (Data[7] >> 6) & 3u; gSetting_backlight_on_tx_rx = (Data[7] >> 6) & 3u;
if (!gEeprom.VFO_OPEN) if (!gEeprom.VFO_OPEN)
@@ -1076,11 +1072,7 @@ void SETTINGS_SaveSettings(void)
#ifdef ENABLE_AUDIO_BAR #ifdef ENABLE_AUDIO_BAR
if (!gSetting_mic_bar) State[7] &= ~(1u << 4); if (!gSetting_mic_bar) State[7] &= ~(1u << 4);
#endif #endif
#ifndef ENABLE_FEAT_F4HWN // State[7] bit 5 is preserved (legacy ENABLE_AM_FIX).
#ifdef ENABLE_AM_FIX
if (!gSetting_AM_fix) State[7] &= ~(1u << 5);
#endif
#endif
State[7] = (State[7] & ~(3u << 6)) | ((gSetting_backlight_on_tx_rx & 3u) << 6); State[7] = (State[7] & ~(3u << 6)) | ((gSetting_backlight_on_tx_rx & 3u) << 6);
PY25Q16_WriteBuffer(0x00A150, SecBuf, 8, false); PY25Q16_WriteBuffer(0x00A150, SecBuf, 8, false);
@@ -1305,9 +1297,7 @@ State[1] = 0
#ifdef ENABLE_FEAT_F4HWN_GAME #ifdef ENABLE_FEAT_F4HWN_GAME
| (1 << 3) | (1 << 3)
#endif #endif
#ifdef ENABLE_AM_FIX // Bit 4 is reserved (legacy ENABLE_AM_FIX).
| (1 << 4)
#endif
#ifdef ENABLE_SPECTRUM #ifdef ENABLE_SPECTRUM
| (1 << 5) | (1 << 5)
#endif #endif
-26
View File
@@ -28,9 +28,6 @@
#include "app/beam.h" #include "app/beam.h"
#endif #endif
#ifdef ENABLE_AM_FIX
#include "am_fix.h"
#endif
#include "bitmaps.h" #include "bitmaps.h"
#include "board.h" #include "board.h"
#include "driver/bk4819.h" #include "driver/bk4819.h"
@@ -1074,9 +1071,6 @@ void DisplayRSSIBar(const bool now)
#ifdef ENABLE_FEAT_F4HWN #ifdef ENABLE_FEAT_F4HWN
int16_t rssi_dBm = int16_t rssi_dBm =
BK4819_GetRSSI_dBm() BK4819_GetRSSI_dBm()
#ifdef ENABLE_AM_FIX
+ ((gSetting_AM_fix && gRxVfo->Modulation == MODULATION_AM) ? AM_fix_get_gain_diff() : 0)
#endif
+ dBmCorrTable[gRxVfo->Band]; + dBmCorrTable[gRxVfo->Band];
// IARU VHF/UHF S-meter: S9 = -93 dBm, 1 S-unit = 6 dB // IARU VHF/UHF S-meter: S9 = -93 dBm, 1 S-unit = 6 dB
@@ -1113,9 +1107,6 @@ void DisplayRSSIBar(const bool now)
const int16_t s0_dBm = -gEeprom.S0_LEVEL; // S0 .. base level const int16_t s0_dBm = -gEeprom.S0_LEVEL; // S0 .. base level
const int16_t rssi_dBm = const int16_t rssi_dBm =
BK4819_GetRSSI_dBm() BK4819_GetRSSI_dBm()
#ifdef ENABLE_AM_FIX
+ ((gSetting_AM_fix && gRxVfo->Modulation == MODULATION_AM) ? AM_fix_get_gain_diff() : 0)
#endif
+ dBmCorrTable[gRxVfo->Band]; + dBmCorrTable[gRxVfo->Band];
int s0_9 = gEeprom.S0_LEVEL - gEeprom.S9_LEVEL; int s0_9 = gEeprom.S0_LEVEL - gEeprom.S9_LEVEL;
@@ -2346,23 +2337,6 @@ void UI_DisplayMain(void)
else else
#endif #endif
#if defined(ENABLE_AM_FIX) && defined(ENABLE_AM_FIX_SHOW_DATA)
if (rx && gEeprom.VfoInfo[gEeprom.RX_VFO].Modulation == MODULATION_AM && gSetting_AM_fix)
{
if (gScreenToDisplay != DISPLAY_MAIN
#ifdef ENABLE_DTMF_CALLING
|| gDTMF_CallState != DTMF_CALL_STATE_NONE
#endif
)
return;
center_line = CENTER_LINE_AM_FIX_DATA;
AM_fix_print_data(gEeprom.RX_VFO, String);
UI_PrintStringSmallNormal(String, 2, 0, 3);
}
else
#endif
#ifdef ENABLE_RSSI_BAR #ifdef ENABLE_RSSI_BAR
if (rx) { if (rx) {
center_line = CENTER_LINE_RSSI; center_line = CENTER_LINE_RSSI;
-1
View File
@@ -27,7 +27,6 @@ enum center_line_t {
CENTER_LINE_AUDIO_BAR, CENTER_LINE_AUDIO_BAR,
CENTER_LINE_AUDIO_SCOPE, CENTER_LINE_AUDIO_SCOPE,
CENTER_LINE_RSSI, CENTER_LINE_RSSI,
CENTER_LINE_AM_FIX_DATA,
CENTER_LINE_DTMF_DEC, CENTER_LINE_DTMF_DEC,
CENTER_LINE_CHARGE_DATA, CENTER_LINE_CHARGE_DATA,
#ifdef ENABLE_FEAT_F4HWN_BEAM #ifdef ENABLE_FEAT_F4HWN_BEAM
-10
View File
@@ -127,11 +127,6 @@ const t_menu_item MenuList[] =
{"D List", MENU_D_LIST }, {"D List", MENU_D_LIST },
#endif #endif
{"D Live", MENU_D_LIVE_DEC }, // live DTMF decoder {"D Live", MENU_D_LIVE_DEC }, // live DTMF decoder
#ifndef ENABLE_FEAT_F4HWN
#ifdef ENABLE_AM_FIX
{"AM Fix", MENU_AM_FIX },
#endif
#endif
{"VOX", MENU_VOX }, {"VOX", MENU_VOX },
#ifdef ENABLE_FEAT_F4HWN #ifdef ENABLE_FEAT_F4HWN
{"SysInf", MENU_VOL }, // was "VOL" {"SysInf", MENU_VOL }, // was "VOL"
@@ -1147,11 +1142,6 @@ void UI_DisplayMenu(void)
strcpy(String, gSubMenu_RX_TX[gSubMenuSelection]); strcpy(String, gSubMenu_RX_TX[gSubMenuSelection]);
break; break;
#ifndef ENABLE_FEAT_F4HWN
#ifdef ENABLE_AM_FIX
case MENU_AM_FIX:
#endif
#endif
case MENU_BCL: case MENU_BCL:
case MENU_BEEP: case MENU_BEEP:
case MENU_STE: case MENU_STE:
-3
View File
@@ -98,9 +98,6 @@ enum
MENU_VOL, MENU_VOL,
MENU_BAT_TXT, MENU_BAT_TXT,
MENU_AM, MENU_AM,
#ifdef ENABLE_AM_FIX
MENU_AM_FIX,
#endif
#ifndef ENABLE_FEAT_F4HWN #ifndef ENABLE_FEAT_F4HWN
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
MENU_NOAA_S, MENU_NOAA_S,
+1 -2
View File
@@ -274,11 +274,10 @@ Specialized presets extend Fusion for specific uses:
- Improved VFO persistence and restoration. - Improved VFO persistence and restoration.
- Extensive code refactoring and memory optimization. - Extensive code refactoring and memory optimization.
- DTMF calling and the scrambler remain disabled in Fusion. - DTMF calling and the scrambler remain disabled in Fusion.
- Legacy AM Fix code is not used by this firmware. - Legacy AM Fix support has been removed.
## Main features from Egzumer: ## Main features from Egzumer:
* many of OneOfEleven mods: * many of OneOfEleven mods:
* AM fix, huge improvement in reception quality
* long press buttons functions replicating F+ action * long press buttons functions replicating F+ action
* fast scanning * fast scanning
* channel name editing in the menu * channel name editing in the menu
-328
View File
@@ -20,332 +20,6 @@
#include <string.h> #include <string.h>
#include <vector> #include <vector>
// ************************************************************************
// create a front end gain table for the firmware
// <9:8> = LNA Gain Short
// 3 = 0dB < original value
// 2 = -24dB // was -11
// 1 = -30dB // was -16
// 0 = -33dB // was -19
//
// <7:5> = LNA Gain
// 7 = 0dB
// 6 = -2dB
// 5 = -4dB
// 4 = -6dB
// 3 = -9dB
// 2 = -14dB < original value
// 1 = -19dB
// 0 = -24dB
//
// <4:3> = MIXER Gain
// 3 = 0dB < original value
// 2 = -3dB
// 1 = -6dB
// 0 = -8dB
//
// <2:0> = PGA Gain
// 7 = 0dB
// 6 = -3dB < original value
// 5 = -6dB
// 4 = -9dB
// 3 = -15dB
// 2 = -21dB
// 1 = -27dB
// 0 = -33dB
typedef struct
{
uint8_t lna_short;
uint8_t lna;
uint8_t mixer;
uint8_t pga;
int16_t lna_short_dB;
int16_t lna_dB;
int16_t mixer_dB;
int16_t pga_dB;
int16_t sum_dB;
} t_gain_table;
void create_gain_table(const char *filename)
{
std::vector <t_gain_table> gain_table;
if (filename == NULL)
return;
// front end register dB values
// const int16_t lna_short_dB[4] = { (-19), (-16), (-11), (0)}; // was
const int16_t lna_short_dB[4] = { (-33), (-30), (-24), (0)}; // corrected
const int16_t lna_dB[8] = { (-24), (-19), (-14), (-9), (-6), (-4), (-2), (0)};
const int16_t mixer_dB[4] = { (-8), (-6), (-3), (0)};
const int16_t pga_dB[8] = { (-33), (-27), (-21), (-15), (-9), (-6), (-3), (0)};
const uint8_t orig_lna_short = 3;
const uint8_t orig_lna = 2;
const uint8_t orig_mixer = 3;
const uint8_t orig_pga = 6;
const int16_t orig_gain_dB =
lna_short_dB[orig_lna_short] +
lna_dB[orig_lna] +
mixer_dB[orig_mixer] +
pga_dB[orig_pga];
#if 1
// full table
const uint8_t lna_short_min = 0; // 0
const uint8_t lna_min = 0; // 0
const uint8_t mixer_min = 0; // 0
const uint8_t pga_min = 0; // 0
const uint8_t lna_short_max = 3; // 3
const uint8_t lna_max = 7; // 5
const uint8_t mixer_max = 3; // 3
const uint8_t pga_max = 7; // 7
#else
// just one register changes
const uint8_t lna_short_min = 0;
const uint8_t lna_min = 2;
const uint8_t mixer_min = 3;
const uint8_t pga_min = 6;
const uint8_t lna_short_max = 3;
const uint8_t lna_max = 2;
const uint8_t mixer_max = 3;
const uint8_t pga_max = 6;
#endif
uint8_t lna_short = lna_short_min;
uint8_t lna = lna_min;
uint8_t mixer = mixer_min;
uint8_t pga = pga_min;
unsigned int original_index = 0;
while (true)
{
t_gain_table entry;
entry.lna_short = lna_short;
entry.lna = lna;
entry.mixer = mixer;
entry.pga = pga;
entry.lna_short_dB = lna_short_dB[lna_short];
entry.lna_dB = lna_dB[lna];
entry.mixer_dB = mixer_dB[mixer];
entry.pga_dB = pga_dB[pga];
entry.sum_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga];
if (entry.sum_dB != orig_gain_dB)
gain_table.push_back(entry);
else
if (lna_short == orig_lna_short && lna == orig_lna && mixer == orig_mixer && pga == orig_pga)
gain_table.push_back(entry);
if (++pga <= pga_max)
continue;
pga = pga_min;
if (++mixer <= mixer_max)
continue;
mixer = mixer_min;
if (++lna <= lna_max)
continue;
lna = lna_min;
if (++lna_short <= lna_short_max)
continue;
// lna_short = lna_short_min;
break;
}
// sort the table according top the sum dB
for (unsigned int i = 0; i < (gain_table.size() - 1); i++)
{
t_gain_table entry1 = gain_table[i];
for (unsigned int k = i + 1; k < gain_table.size(); k++)
{
t_gain_table entry2 = gain_table[k];
if (entry2.sum_dB < entry1.sum_dB)
{ // swap
const t_gain_table entry = entry1;
entry1 = entry2;
entry2 = entry;
gain_table[i] = entry1;
gain_table[k] = entry2;
}
}
}
{ // remove sum_dB duplicates
unsigned int i = 0;
while (i < gain_table.size())
{
const t_gain_table entry1 = gain_table[i++];
if (entry1.lna_short == orig_lna_short &&
entry1.lna == orig_lna &&
entry1.mixer == orig_mixer &&
entry1.pga == orig_pga)
continue; // leave the original inplace
while (i < gain_table.size())
{
const t_gain_table entry2 = gain_table[i];
if (entry2.lna_short == orig_lna_short &&
entry2.lna == orig_lna &&
entry2.mixer == orig_mixer &&
entry2.pga == orig_pga)
break; // leave the original inplace
if (entry2.sum_dB != entry1.sum_dB)
break;
gain_table.erase(gain_table.begin() + i, gain_table.begin() + i + 1);
}
}
}
// find the index for the original Quansheng register settings
for (int i = (int)gain_table.size() - 1; i >= 0; i--)
{
const t_gain_table entry = gain_table[i];
if (entry.sum_dB != orig_gain_dB)
continue;
if (entry.lna_short != orig_lna_short ||
entry.lna != orig_lna ||
entry.mixer != orig_mixer ||
entry.pga != orig_pga)
continue;
original_index = i;
break;
}
// ***************************
// save the table to a file
/*
typedef struct
{
#if 1
// bitfields take up less flash bytes
uint8_t lna_short:2; // 0 ~ 3
uint8_t lna:3; // 0 ~ 7
uint8_t mixer:2; // 0 ~ 3
uint8_t pga:3; // 0 ~ 7
#else
uint8_t lna_short; // 0 ~ 3
uint8_t lna; // 0 ~ 7
uint8_t mixer; // 0 ~ 3
uint8_t pga; // 0 ~ 7
#endif
} t_am_fix_gain_table;
//} __attribute__((packed)) t_am_fix_gain_table;
*/
FILE *file = fopen(filename, "w");
if (file == NULL)
return;
fprintf(file, "\n");
fprintf(file, "\tstatic const t_am_fix_gain_table am_fix_gain_table[] =\n");
fprintf(file, "\t{\n");
#if 0
fprintf(file, "\t\t{.lna_short = 3, .lna = 2, .mixer = 3, .pga = 6}, // 0 0dB -14dB 0dB -3dB .. -17dB original\n\n");
for (unsigned int i = 0; i < gain_table.size(); i++)
{
char s[1024];
const t_gain_table entry = gain_table[i];
sprintf(s, "\t\t{%u, %u, %u, %u}, // %3u .. %3ddB %3ddB %2ddB %3ddB .. %3ddB",
entry.lna_short,
entry.lna,
entry.mixer,
entry.pga,
1 + i,
entry.lna_short_dB,
entry.lna_dB,
entry.mixer_dB,
entry.pga_dB,
entry.sum_dB);
if (i == original_index)
strcat(s, " original");
fprintf(file, "%s\n", s);
}
#else
{
//BK4819_WriteRegister(BK4819_REG_13, ((uint16_t)gains.lna_short << 8) | ((uint16_t)gains.lna << 5) | ((uint16_t)gains.mixer << 3) | ((uint16_t)gains.pga << 0));
uint16_t reg_val;
int16_t sum_dB;
reg_val = ((uint16_t)orig_lna_short << 8) | ((uint16_t)orig_lna << 5) | ((uint16_t)orig_mixer << 3) | ((uint16_t)orig_pga << 0);
sum_dB = lna_short_dB[orig_lna_short] + lna_dB[orig_lna] + mixer_dB[orig_mixer] + pga_dB[orig_pga];
fprintf(file, "\t\t{0x%04X, %-3d}, // 0 .. %u %u %u %u .. 0dB -14dB 0dB -3dB .. -17dB original\n\n",
reg_val,
sum_dB,
orig_lna_short,
orig_lna,
orig_mixer,
orig_pga);
for (unsigned int i = 0; i < gain_table.size(); i++)
{
char s[1024];
const t_gain_table entry = gain_table[i];
reg_val = ((uint16_t)entry.lna_short << 8) | ((uint16_t)entry.lna << 5) | ((uint16_t)entry.mixer << 3) | ((uint16_t)entry.pga << 0);
sum_dB = lna_short_dB[entry.lna_short] + lna_dB[entry.lna] + mixer_dB[entry.mixer] + pga_dB[entry.pga];
sprintf(s, "\t\t{0x%04X, %-3d}, // %3u .. %u %u %u %u .. %3ddB %3ddB %2ddB %3ddB .. %3ddB",
reg_val,
sum_dB,
1 + i,
entry.lna_short,
entry.lna,
entry.mixer,
entry.pga,
entry.lna_short_dB,
entry.lna_dB,
entry.mixer_dB,
entry.pga_dB,
entry.sum_dB);
if (i == original_index)
strcat(s, " original");
fprintf(file, "%s\n", s);
}
}
#endif
fprintf(file, "\t};\n\n");
fprintf(file, "\tstatic const unsigned int original_index = %u;\n", 1 + original_index);
fclose(file);
}
// ************************************************************************ // ************************************************************************
// "rotate_font()" has nothing to do with this program at all, I just needed // "rotate_font()" has nothing to do with this program at all, I just needed
// to write a bit of code to rotate some fonts I've drawn // to write a bit of code to rotate some fonts I've drawn
@@ -464,8 +138,6 @@ void rotate_font(const char *filename1, const char *filename2)
#pragma argsused #pragma argsused
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
create_gain_table("gain_table.c");
rotate_font("uv-k5_small.bin", "uv-k5_small.c"); rotate_font("uv-k5_small.bin", "uv-k5_small.c");
rotate_font("uv-k5_small_bold.bin", "uv-k5_small_bold.c"); rotate_font("uv-k5_small_bold.bin", "uv-k5_small_bold.c");