0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 22:31:25 +03:00

3rd test (lucky ?)

This commit is contained in:
OneOfEleven 2023-09-22 00:03:53 +01:00
parent 0206bde628
commit 0cc5abfecc
5 changed files with 119 additions and 108 deletions

101
app/app.c
View File

@ -62,6 +62,18 @@
#include "ui/status.h" #include "ui/status.h"
#include "ui/ui.h" #include "ui/ui.h"
// original QS front end gains
static uint16_t lna_short = 3; // 0dB
static uint16_t lna = 2; // -14dB
static uint16_t mixer = 3; // 0dB
static uint16_t pga = 6; // -3dB
#ifdef ENABLE_AM_FIX
// computes the average RSSI level over several samples
static unsigned int avg_rssi_counter = 0;
static uint16_t avg_rssi = 0;
#endif
static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
static void APP_CheckForIncoming(void) static void APP_CheckForIncoming(void)
@ -413,6 +425,11 @@ void APP_StartListening(FUNCTION_Type_t Function)
BK1080_Init(0, false); BK1080_Init(0, false);
#endif #endif
#ifdef ENABLE_AM_FIX
avg_rssi_counter = 0;
avg_rssi = 0;
#endif
gVFO_RSSI_Level[gEeprom.RX_CHANNEL == 0] = 0; gVFO_RSSI_Level[gEeprom.RX_CHANNEL == 0] = 0;
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
@ -475,29 +492,36 @@ void APP_StartListening(FUNCTION_Type_t Function)
if (gRxVfo->IsAM) if (gRxVfo->IsAM)
{ // AM { // AM
#ifdef ENABLE_AM_FIX
if (gSetting_AM_fix)
{ // original
lna_short = 3;
lna = 2;
mixer = 3;
pga = 6;
}
else
#endif
{
const uint32_t rx_frequency = gRxVfo->pRX->Frequency; const uint32_t rx_frequency = gRxVfo->pRX->Frequency;
uint16_t lna_short; // whats "LNA SHORT" mean ? // the RX gain abrutly reduces above this frequency
uint16_t lna; // I guess this is (one of) the freq the hardware switches the front ends over ?
uint16_t mixer;
uint16_t pga;
// the RX gain abrutly reduces above this frequency, why ?
if (rx_frequency <= 22640000) if (rx_frequency <= 22640000)
{ // decrease front end gain = better AM demodulation { // decrease front end gain - AM demodulator saturates at a slightly higher signal level
lna_short = 3; // 3 original lna_short = 3; // 3 original
lna = 2; // 2 original lna = 2; // 2 original
mixer = 3; // 3 original mixer = 3; // 3 original
pga = 3; // 6 original, 3 reduced pga = 3; // 6 original, 3 reduced
} }
else else
{ // increasing the front end to compensate the reduced gain, but more gain decreases dynamic range { // increase the front end to compensate the reduced gain, but more gain decreases dynamic range :(
lna_short = 3; // 3 original lna_short = 3; // 3 original
lna = 4; // 2 original, 4 increased lna = 4; // 2 original, 4 increased
mixer = 3; // 3 original mixer = 3; // 3 original
pga = 7; // 6 original, 7 increased pga = 7; // 6 original, 7 increased
} }
BK4819_WriteRegister(BK4819_REG_13, (lna_short << 8) | (lna << 5) | (mixer << 3) | (pga << 0)); }
// what do these 4 other gain settings do ??? // what do these 4 other gain settings do ???
//BK4819_WriteRegister(BK4819_REG_12, 0x037B); // 000000 11 011 11 011 //BK4819_WriteRegister(BK4819_REG_12, 0x037B); // 000000 11 011 11 011
@ -505,23 +529,19 @@ void APP_StartListening(FUNCTION_Type_t Function)
//BK4819_WriteRegister(BK4819_REG_10, 0x007A); // 000000 00 011 11 010 //BK4819_WriteRegister(BK4819_REG_10, 0x007A); // 000000 00 011 11 010
//BK4819_WriteRegister(BK4819_REG_14, 0x0019); // 000000 00 000 11 001 //BK4819_WriteRegister(BK4819_REG_14, 0x0019); // 000000 00 000 11 001
// AF gain (max it out) - see below FM mode bit for original setting
BK4819_WriteRegister(BK4819_REG_48,
(11u << 12) | // ??? .. 0 to 15, doesn't seem to make any difference
( 0u << 10) | // AF Rx Gain-1
(63u << 4) | // AF Rx Gain-2
(15u << 0)); // AF DAC Gain (after Gain-1 and Gain-2)
gNeverUsed = 0; gNeverUsed = 0;
} }
else else
{ // FM { // FM
// original // original
const uint16_t lna_short = 3; // whats 'LNA short' mean ? lna_short = 3; // whats 'LNA short' mean ?
const uint16_t lna = 2; lna = 2;
const uint16_t mixer = 3; mixer = 3;
const uint16_t pga = 6; pga = 6;
}
// apply the front end gain settings
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));
// AF gain - original // AF gain - original
@ -530,7 +550,6 @@ void APP_StartListening(FUNCTION_Type_t Function)
( 0u << 10) | // AF Rx Gain-1 ( 0u << 10) | // AF Rx Gain-1
(gEeprom.VOLUME_GAIN << 4) | // AF Rx Gain-2 (gEeprom.VOLUME_GAIN << 4) | // AF Rx Gain-2
(gEeprom.DAC_GAIN << 0)); // AF DAC Gain (after Gain-1 and Gain-2) (gEeprom.DAC_GAIN << 0)); // AF DAC Gain (after Gain-1 and Gain-2)
}
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
if (gVoiceWriteIndex == 0) if (gVoiceWriteIndex == 0)
@ -1318,7 +1337,9 @@ void APP_CheckKeys(void)
void adjustAMFrontEnd10ms(void) void adjustAMFrontEnd10ms(void)
{ {
if (!gRxVfo->IsAM) if (!gRxVfo->IsAM)
return; // FM return; // we don't play with the front end gains if in FM mode
// we're in AM mode
switch (gCurrentFunction) switch (gCurrentFunction)
{ {
@ -1327,6 +1348,7 @@ void APP_CheckKeys(void)
case FUNCTION_POWER_SAVE: case FUNCTION_POWER_SAVE:
return; return;
// only adjust the front end gains if in one of these modes
case FUNCTION_FOREGROUND: case FUNCTION_FOREGROUND:
case FUNCTION_RECEIVE: case FUNCTION_RECEIVE:
case FUNCTION_MONITOR: case FUNCTION_MONITOR:
@ -1334,8 +1356,6 @@ void APP_CheckKeys(void)
break; break;
} }
// AM
// REG_10 <15:0> 0x0038 Rx AGC Gain Table[0]. (Index Max->Min is 3,2,1,0,-1) // REG_10 <15:0> 0x0038 Rx AGC Gain Table[0]. (Index Max->Min is 3,2,1,0,-1)
// //
// <9:8> = LNA Gain Short // <9:8> = LNA Gain Short
@ -1369,37 +1389,24 @@ void APP_CheckKeys(void)
// 2 = -21dB // 2 = -21dB
// 1 = -27dB // 1 = -27dB
// 0 = -33dB // 0 = -33dB
//
// LNA_SHORT .. 0dB
// LNA ........ 14dB
// MIXER ...... 0dB
// PGA ........ -3dB
// original settings
static uint16_t lna_short = 3;
static uint16_t lna = 2;
static uint16_t mixer = 3;
static uint16_t pga = 6;
static unsigned int counter = 0;
static unsigned int avg_rssi = 0;
// start with current settings
register uint16_t new_lna_short = lna_short; register uint16_t new_lna_short = lna_short;
register uint16_t new_lna = lna; register uint16_t new_lna = lna;
register uint16_t new_mixer = mixer; register uint16_t new_mixer = mixer;
register uint16_t new_pga = pga; register uint16_t new_pga = pga;
{ // -86dBm, any higher and the AM demodulator starts to saturate
const uint16_t desired_rssi = (-86 + 160) * 2; // -86dBm const uint16_t desired_rssi = (-86 + 160) * 2;
// sample the current RSSI level
gCurrentRSSI = BK4819_GetRSSI(); gCurrentRSSI = BK4819_GetRSSI();
// compute the average
avg_rssi += gCurrentRSSI; avg_rssi += gCurrentRSSI;
if (++counter < 16) // 160ms if (++avg_rssi_counter < 16) // 160ms - rate at which we adjust the front end gains
return; return;
avg_rssi /= avg_rssi_counter;
avg_rssi /= counter;
counter = 0;
if (avg_rssi < (desired_rssi - 4)) if (avg_rssi < (desired_rssi - 4))
{ // increase gain { // increase gain
@ -1439,11 +1446,15 @@ void APP_CheckKeys(void)
if (new_mixer > 0) if (new_mixer > 0)
new_mixer--; new_mixer--;
} }
}
avg_rssi_counter = 0;
avg_rssi = 0;
if (lna_short == new_lna_short && lna == new_lna && mixer == new_mixer && pga == new_pga) if (lna_short == new_lna_short && lna == new_lna && mixer == new_mixer && pga == new_pga)
return; // no change return; // no change
// apply the adjusted gain settings
lna_short = new_lna_short; lna_short = new_lna_short;
lna = new_lna; lna = new_lna;
mixer = new_mixer; mixer = new_mixer;

View File

@ -710,7 +710,7 @@ void BOARD_EEPROM_Init(void)
#ifdef ENABLE_AUDIO_BAR #ifdef ENABLE_AUDIO_BAR
gSetting_mic_bar = (Data[7] & (1u << 4)) ? true : false; gSetting_mic_bar = (Data[7] & (1u << 4)) ? true : false;
#endif #endif
#ifdef ENABLE_AM_AGC_GAIN #ifdef ENABLE_AM_FIX
gSetting_AM_fix = (Data[7] & (1u << 5)) ? true : false; gSetting_AM_fix = (Data[7] & (1u << 5)) ? true : false;
#endif #endif

BIN
firmware

Binary file not shown.

Binary file not shown.

Binary file not shown.