mirror of
https://github.com/OneOfEleven/uv-k5-firmware-custom.git
synced 2025-04-28 14:21:25 +03:00
Tidy ups
This commit is contained in:
parent
81446c2f70
commit
d3aff9d013
76
am_fix.c
76
am_fix.c
@ -46,7 +46,7 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
// bitfields take less flash bytes
|
// bitfields take up less flash bytes
|
||||||
uint8_t lna_short:2; // 0 ~ 3
|
uint8_t lna_short:2; // 0 ~ 3
|
||||||
uint8_t lna:3; // 0 ~ 7
|
uint8_t lna:3; // 0 ~ 7
|
||||||
uint8_t mixer:2; // 0 ~ 3
|
uint8_t mixer:2; // 0 ~ 3
|
||||||
@ -107,7 +107,27 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
static const t_am_fix_gain_table am_fix_gain_table[] =
|
static const t_am_fix_gain_table am_fix_gain_table[] =
|
||||||
{
|
{
|
||||||
{.lna_short = 3, .lna = 2, .mixer = 3, .pga = 6}, // 0 0dB -14dB 0dB -3dB .. -17dB original
|
{.lna_short = 3, .lna = 2, .mixer = 3, .pga = 6}, // 0 0dB -14dB 0dB -3dB .. -17dB original
|
||||||
#if 1
|
|
||||||
|
#ifdef ENABLE_AM_FIX_TEST1
|
||||||
|
|
||||||
|
// test table that lets me manually set the lna-short register
|
||||||
|
|
||||||
|
{0, 2, 3, 6}, // 1 -33dB -14dB 0dB -3dB .. -50dB
|
||||||
|
{1, 2, 3, 6}, // 2 -30dB -14dB 0dB -3dB .. -47dB
|
||||||
|
{2, 2, 3, 6}, // 3 -24dB -14dB 0dB -3dB .. -41dB
|
||||||
|
{3, 2, 3, 6} // 4 0dB -14dB 0dB -3dB .. -17dB
|
||||||
|
|
||||||
|
const unsigned int original_index = 1;
|
||||||
|
|
||||||
|
#elif 1
|
||||||
|
|
||||||
|
|
||||||
|
// NOTE: adjusting the 'lna-short' register causes a 'clicking' sound in the
|
||||||
|
// received audio, so playing with it whilst a signal is present is going
|
||||||
|
// to be a no no it seems.
|
||||||
|
// so in this table the 'lna-short' register I leave alone
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{3, 0, 0, 0}, // 1 0dB -24dB -8dB -33dB .. -65dB
|
{3, 0, 0, 0}, // 1 0dB -24dB -8dB -33dB .. -65dB
|
||||||
{3, 0, 1, 0}, // 2 0dB -24dB -6dB -33dB .. -63dB
|
{3, 0, 1, 0}, // 2 0dB -24dB -6dB -33dB .. -63dB
|
||||||
@ -170,6 +190,11 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
// in this table I include adjusting the 'lna-short' register ~
|
||||||
|
// more gain adjustment range from doing so but 'clicking' sound
|
||||||
|
// from doing so :(
|
||||||
|
|
||||||
|
|
||||||
{1, 0, 0, 0}, // 1 -54dB -24dB -8dB -33dB .. -119dB
|
{1, 0, 0, 0}, // 1 -54dB -24dB -8dB -33dB .. -119dB
|
||||||
{1, 0, 1, 0}, // 2 -54dB -24dB -6dB -33dB .. -117dB
|
{1, 0, 1, 0}, // 2 -54dB -24dB -6dB -33dB .. -117dB
|
||||||
{1, 0, 2, 0}, // 3 -54dB -24dB -3dB -33dB .. -114dB
|
{1, 0, 2, 0}, // 3 -54dB -24dB -3dB -33dB .. -114dB
|
||||||
@ -282,6 +307,7 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
};
|
};
|
||||||
|
|
||||||
const unsigned int original_index = 99;
|
const unsigned int original_index = 99;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// current table index we're using
|
// current table index we're using
|
||||||
@ -326,7 +352,13 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
|
|
||||||
void AM_fix_adjust_frontEnd_10ms(void)
|
void AM_fix_adjust_frontEnd_10ms(void)
|
||||||
{
|
{
|
||||||
|
#ifndef ENABLE_AM_FIX_TEST1
|
||||||
|
// -89dBm, any higher and the AM demodulator starts to saturate/clip/distort
|
||||||
|
const uint16_t desired_rssi = (-89 + 160) * 2; // dBm to ADC sample
|
||||||
|
#endif
|
||||||
|
|
||||||
// we don't play with the front end gains if in FM mode
|
// we don't play with the front end gains if in FM mode
|
||||||
|
// they remain as per QS original
|
||||||
if (!gRxVfo->IsAM)
|
if (!gRxVfo->IsAM)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -347,15 +379,11 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef ENABLE_AM_FIX_TEST1
|
|
||||||
// -89dBm, any higher and the AM demodulator starts to saturate/clip (distort)
|
|
||||||
const uint16_t desired_rssi = (-89 + 160) * 2; // dBm to ADC sample
|
|
||||||
#endif
|
|
||||||
// sample the current RSSI level
|
// sample the current RSSI level
|
||||||
uint16_t rssi = BK4819_GetRSSI(); // 9-bit value (0 .. 511)
|
uint16_t rssi = BK4819_GetRSSI(); // supposed 9-bit value (0 .. 511) - never seen that though
|
||||||
//gCurrentRSSI = rssi - (rssi_db_gain_diff * 2);
|
|
||||||
#if 1
|
#if 1
|
||||||
// compute the moving average RSSI
|
// compute a moving average RSSI - just smooths any sharp spikes
|
||||||
if (moving_avg_rssi.count < ARRAY_SIZE(moving_avg_rssi.samples))
|
if (moving_avg_rssi.count < ARRAY_SIZE(moving_avg_rssi.samples))
|
||||||
moving_avg_rssi.count++;
|
moving_avg_rssi.count++;
|
||||||
moving_avg_rssi.sum -= moving_avg_rssi.samples[moving_avg_rssi.index]; // subtract the oldest sample
|
moving_avg_rssi.sum -= moving_avg_rssi.samples[moving_avg_rssi.index]; // subtract the oldest sample
|
||||||
@ -366,7 +394,10 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
rssi = moving_avg_rssi.sum / moving_avg_rssi.count; // compute the average of the past 'n' samples
|
rssi = moving_avg_rssi.sum / moving_avg_rssi.count; // compute the average of the past 'n' samples
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//gCurrentRSSI[gEeprom.RX_CHANNEL] = rssi - (rssi_db_gain_diff * 2);
|
||||||
|
|
||||||
#ifdef ENABLE_AM_FIX_TEST1
|
#ifdef ENABLE_AM_FIX_TEST1
|
||||||
|
|
||||||
am_fix_gain_table_index = 1 + gSetting_AM_fix_test1;
|
am_fix_gain_table_index = 1 + gSetting_AM_fix_test1;
|
||||||
|
|
||||||
if (am_gain_hold_counter > 0)
|
if (am_gain_hold_counter > 0)
|
||||||
@ -376,6 +407,7 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
am_gain_hold_counter = 250; // 250ms
|
am_gain_hold_counter = 250; // 250ms
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
if (rssi > desired_rssi)
|
if (rssi > desired_rssi)
|
||||||
{ // decrease gain
|
{ // decrease gain
|
||||||
|
|
||||||
@ -391,7 +423,7 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
if (am_gain_hold_counter == 0)
|
if (am_gain_hold_counter == 0)
|
||||||
{ // hold has been released, we're now free to increase gain
|
{ // hold has been released, we're now free to increase gain
|
||||||
|
|
||||||
if (rssi < (desired_rssi - 10)) // 5dB hysterisis (helps prevent gain hunting)
|
if (rssi < (desired_rssi - 10)) // 5dB hysterisis (helps reduce gain hunting)
|
||||||
{ // increase gain
|
{ // increase gain
|
||||||
|
|
||||||
if (am_fix_gain_table_index < (ARRAY_SIZE(am_fix_gain_table) - 1))
|
if (am_fix_gain_table_index < (ARRAY_SIZE(am_fix_gain_table) - 1))
|
||||||
@ -400,26 +432,28 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (am_fix_gain_table_index == am_fix_gain_table_index_prev)
|
if (am_fix_gain_table_index == am_fix_gain_table_index_prev)
|
||||||
return; // no gain changes
|
return; // no gain changes have been made
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// apply the new gain settings to the front end
|
// apply the new settings to the front end registers
|
||||||
|
|
||||||
// remember the new gain settings - for the next time this function is called
|
|
||||||
const uint16_t lna_short = am_fix_gain_table[am_fix_gain_table_index].lna_short;
|
const uint16_t lna_short = am_fix_gain_table[am_fix_gain_table_index].lna_short;
|
||||||
const uint16_t lna = am_fix_gain_table[am_fix_gain_table_index].lna;
|
const uint16_t lna = am_fix_gain_table[am_fix_gain_table_index].lna;
|
||||||
const uint16_t mixer = am_fix_gain_table[am_fix_gain_table_index].mixer;
|
const uint16_t mixer = am_fix_gain_table[am_fix_gain_table_index].mixer;
|
||||||
const uint16_t pga = am_fix_gain_table[am_fix_gain_table_index].pga;
|
const uint16_t pga = am_fix_gain_table[am_fix_gain_table_index].pga;
|
||||||
|
|
||||||
BK4819_WriteRegister(BK4819_REG_13, (lna_short << 8) | (lna << 5) | (mixer << 3) | (pga << 0));
|
BK4819_WriteRegister(BK4819_REG_13, (lna_short << 8) | (lna << 5) | (mixer << 3) | (pga << 0));
|
||||||
|
|
||||||
{ // offset the RSSI reading to the rest of the firmware to cancel out the gain adjustments we've made here
|
{ // offset the RSSI reading to the rest of the firmware to cancel out the gain adjustments we've made here
|
||||||
const int16_t orig_dB_gain = lna_short_dB[orig_lna_short & 3u] + lna_dB[orig_lna & 7u] + mixer_dB[orig_mixer & 3u] + pga_dB[orig_pga & 7u];
|
|
||||||
const int16_t am_dB_gain = lna_short_dB[lna_short & 3u] + lna_dB[lna & 7u] + mixer_dB[mixer & 3u] + pga_dB[pga & 7u];
|
const int16_t orig_dB_gain = lna_short_dB[orig_lna_short] + lna_dB[orig_lna] + mixer_dB[orig_mixer] + pga_dB[orig_pga];
|
||||||
|
const int16_t am_dB_gain = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga];
|
||||||
|
|
||||||
rssi_db_gain_diff = am_dB_gain - orig_dB_gain;
|
rssi_db_gain_diff = am_dB_gain - orig_dB_gain;
|
||||||
|
|
||||||
|
//gCurrentRSSI[gEeprom.RX_CHANNEL] = rssi - (rssi_db_gain_diff * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// remember the new table index
|
||||||
am_fix_gain_table_index_prev = am_fix_gain_table_index;
|
am_fix_gain_table_index_prev = am_fix_gain_table_index;
|
||||||
|
|
||||||
#ifdef ENABLE_AM_FIX_SHOW_DATA
|
#ifdef ENABLE_AM_FIX_SHOW_DATA
|
||||||
@ -428,20 +462,24 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_AM_FIX_SHOW_DATA
|
#ifdef ENABLE_AM_FIX_SHOW_DATA
|
||||||
|
|
||||||
void AM_fix_print_data(char *s)
|
void AM_fix_print_data(char *s)
|
||||||
{
|
{
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// fetch current register settings
|
||||||
const uint16_t lna_short = am_fix_gain_table[am_fix_gain_table_index].lna_short;
|
const uint16_t lna_short = am_fix_gain_table[am_fix_gain_table_index].lna_short;
|
||||||
const uint16_t lna = am_fix_gain_table[am_fix_gain_table_index].lna;
|
const uint16_t lna = am_fix_gain_table[am_fix_gain_table_index].lna;
|
||||||
const uint16_t mixer = am_fix_gain_table[am_fix_gain_table_index].mixer;
|
const uint16_t mixer = am_fix_gain_table[am_fix_gain_table_index].mixer;
|
||||||
const uint16_t pga = am_fix_gain_table[am_fix_gain_table_index].pga;
|
const uint16_t pga = am_fix_gain_table[am_fix_gain_table_index].pga;
|
||||||
|
|
||||||
const int16_t am_dB_gain = lna_short_dB[lna_short & 3u] + lna_dB[lna & 7u] + mixer_dB[mixer & 3u] + pga_dB[pga & 7u];
|
// compute the current front end gain
|
||||||
|
const int16_t dB_gain = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga];
|
||||||
|
|
||||||
sprintf(s, "idx %2d %4ddB %3u", am_fix_gain_table_index, am_dB_gain, BK4819_GetRSSI());
|
sprintf(s, "idx %2d %4ddB %3u", am_fix_gain_table_index, dB_gain, BK4819_GetRSSI());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
12
app/app.c
12
app/app.c
@ -1134,14 +1134,14 @@ void APP_Update(void)
|
|||||||
{ // dual watch mode, go back to sleep
|
{ // dual watch mode, go back to sleep
|
||||||
|
|
||||||
// sample the RSSI
|
// sample the RSSI
|
||||||
gCurrentRSSI = (int16_t)BK4819_GetRSSI();
|
gCurrentRSSI[gEeprom.RX_CHANNEL] = (int16_t)BK4819_GetRSSI();
|
||||||
#ifdef ENABLE_AM_FIX
|
#ifdef ENABLE_AM_FIX
|
||||||
// with compensation
|
// with compensation
|
||||||
if (gSetting_AM_fix)
|
if (gSetting_AM_fix)
|
||||||
gCurrentRSSI -= rssi_db_gain_diff * 2;
|
gCurrentRSSI[gEeprom.RX_CHANNEL] -= rssi_db_gain_diff * 2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
UI_UpdateRSSI(gCurrentRSSI);
|
UI_UpdateRSSI(gCurrentRSSI[gEeprom.RX_CHANNEL]);
|
||||||
|
|
||||||
// go back to sleep
|
// go back to sleep
|
||||||
|
|
||||||
@ -1660,14 +1660,14 @@ void APP_TimeSlice500ms(void)
|
|||||||
|
|
||||||
if (gCurrentFunction != FUNCTION_POWER_SAVE)
|
if (gCurrentFunction != FUNCTION_POWER_SAVE)
|
||||||
{
|
{
|
||||||
gCurrentRSSI = (int16_t)BK4819_GetRSSI();
|
gCurrentRSSI[gEeprom.RX_CHANNEL] = (int16_t)BK4819_GetRSSI();
|
||||||
#ifdef ENABLE_AM_FIX
|
#ifdef ENABLE_AM_FIX
|
||||||
// with compensation
|
// with compensation
|
||||||
if (gSetting_AM_fix)
|
if (gSetting_AM_fix)
|
||||||
gCurrentRSSI -= rssi_db_gain_diff * 2;
|
gCurrentRSSI[gEeprom.RX_CHANNEL] -= rssi_db_gain_diff * 2;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
UI_UpdateRSSI(gCurrentRSSI);
|
UI_UpdateRSSI(gCurrentRSSI[gEeprom.RX_CHANNEL]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_FMRADIO
|
#ifdef ENABLE_FMRADIO
|
||||||
|
2
misc.c
2
misc.c
@ -221,7 +221,7 @@ volatile bool gFlagTailNoteEliminationComplete;
|
|||||||
|
|
||||||
volatile uint8_t boot_counter_10ms;
|
volatile uint8_t boot_counter_10ms;
|
||||||
|
|
||||||
int16_t gCurrentRSSI = 0;
|
int16_t gCurrentRSSI[2] = {0, 0}; // now one per VFO
|
||||||
|
|
||||||
uint8_t gIsLocked = 0xFF;
|
uint8_t gIsLocked = 0xFF;
|
||||||
|
|
||||||
|
2
misc.h
2
misc.h
@ -278,7 +278,7 @@ extern volatile bool gFlagTailNoteEliminationComplete;
|
|||||||
#ifdef ENABLE_FMRADIO
|
#ifdef ENABLE_FMRADIO
|
||||||
extern volatile bool gScheduleFM;
|
extern volatile bool gScheduleFM;
|
||||||
#endif
|
#endif
|
||||||
extern int16_t gCurrentRSSI;
|
extern int16_t gCurrentRSSI[2]; // now one per VFO
|
||||||
extern uint8_t gIsLocked;
|
extern uint8_t gIsLocked;
|
||||||
extern volatile uint8_t boot_counter_10ms;
|
extern volatile uint8_t boot_counter_10ms;
|
||||||
|
|
||||||
|
@ -434,7 +434,7 @@ void UI_DisplayMenu(void)
|
|||||||
|
|
||||||
#ifdef ENABLE_AM_FIX
|
#ifdef ENABLE_AM_FIX
|
||||||
case MENU_AM_FIX:
|
case MENU_AM_FIX:
|
||||||
strcpy(String, (gSubMenuSelection == 0) ? "OFF" : "FIXED");
|
strcpy(String, (gSubMenuSelection == 0) ? "OFF" : "YES'ish");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "audio.h" // VOICE_ID_t
|
#include "audio.h" // VOICE_ID_t
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char name[7]; // menu display only has room for 6 characters
|
const char name[7]; // menu display area only has room for 6 characters
|
||||||
VOICE_ID_t voice_id;
|
VOICE_ID_t voice_id;
|
||||||
uint8_t menu_id;
|
uint8_t menu_id;
|
||||||
} t_menu_item;
|
} t_menu_item;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user