mirror of
https://github.com/OneOfEleven/uv-k5-firmware-custom.git
synced 2025-04-28 22:31:25 +03:00
Optimize/reduce flash used in AM fix code
This commit is contained in:
parent
d449cc0976
commit
b0794ec582
4
Makefile
4
Makefile
@ -27,6 +27,7 @@ ENABLE_AM_FIX := 1
|
|||||||
ENABLE_AM_FIX_SHOW_DATA := 1
|
ENABLE_AM_FIX_SHOW_DATA := 1
|
||||||
ENABLE_SQUELCH1_LOWER := 0
|
ENABLE_SQUELCH1_LOWER := 0
|
||||||
ENABLE_AUDIO_BAR := 0
|
ENABLE_AUDIO_BAR := 0
|
||||||
|
ENABLE_COPY_CHAN_TO_VFO := 1
|
||||||
#ENABLE_SINGLE_VFO_CHAN := 1
|
#ENABLE_SINGLE_VFO_CHAN := 1
|
||||||
#ENABLE_BAND_SCOPE := 1
|
#ENABLE_BAND_SCOPE := 1
|
||||||
|
|
||||||
@ -226,6 +227,9 @@ endif
|
|||||||
ifeq ($(ENABLE_AUDIO_BAR),1)
|
ifeq ($(ENABLE_AUDIO_BAR),1)
|
||||||
CFLAGS += -DENABLE_AUDIO_BAR
|
CFLAGS += -DENABLE_AUDIO_BAR
|
||||||
endif
|
endif
|
||||||
|
ifeq ($(ENABLE_COPY_CHAN_TO_VFO),1)
|
||||||
|
CFLAGS += -DENABLE_COPY_CHAN_TO_VFO
|
||||||
|
endif
|
||||||
ifeq ($(ENABLE_SINGLE_VFO_CHAN),1)
|
ifeq ($(ENABLE_SINGLE_VFO_CHAN),1)
|
||||||
CFLAGS += -DENABLE_SINGLE_VFO_CHAN
|
CFLAGS += -DENABLE_SINGLE_VFO_CHAN
|
||||||
endif
|
endif
|
||||||
|
@ -47,6 +47,7 @@ ENABLE_AM_FIX := 1 dynamically adjust the front end gains
|
|||||||
ENABLE_AM_FIX_SHOW_DATA := 1 show debug data for the AM fix
|
ENABLE_AM_FIX_SHOW_DATA := 1 show debug data for the AM fix
|
||||||
ENABLE_SQUELCH1_LOWER := 0 adjusts squelch setting '1' to be more sensitive - I plan to let user adjust it in the menu
|
ENABLE_SQUELCH1_LOWER := 0 adjusts squelch setting '1' to be more sensitive - I plan to let user adjust it in the menu
|
||||||
ENABLE_AUDIO_BAR := 0 experimental, display an audo bar level when TX'ing
|
ENABLE_AUDIO_BAR := 0 experimental, display an audo bar level when TX'ing
|
||||||
|
#ENABLE_COPY_CHAN_TO_VFO := 1 not yet implemented - copy the channel into the VFO
|
||||||
#ENABLE_SINGLE_VFO_CHAN := 1 not yet implemented - single VFO on display when possible
|
#ENABLE_SINGLE_VFO_CHAN := 1 not yet implemented - single VFO on display when possible
|
||||||
#ENABLE_BAND_SCOPE := 1 not yet implemented - spectrum/pan-adapter
|
#ENABLE_BAND_SCOPE := 1 not yet implemented - spectrum/pan-adapter
|
||||||
```
|
```
|
||||||
|
194
am_fix.c
194
am_fix.c
@ -53,8 +53,8 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
uint8_t mixer; // 0 ~ 3
|
uint8_t mixer; // 0 ~ 3
|
||||||
uint8_t pga; // 0 ~ 7
|
uint8_t pga; // 0 ~ 7
|
||||||
#endif
|
#endif
|
||||||
} t_am_fix_gain_table;
|
} t_gain_table;
|
||||||
//} __attribute__((packed)) t_am_fix_gain_table;
|
//} __attribute__((packed)) t_gain_table;
|
||||||
|
|
||||||
// REG_10 AGC gain table
|
// REG_10 AGC gain table
|
||||||
//
|
//
|
||||||
@ -109,7 +109,7 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
|
|
||||||
// lookup table is hugely easier than writing code to do the same
|
// lookup table is hugely easier than writing code to do the same
|
||||||
//
|
//
|
||||||
static const t_am_fix_gain_table am_fix_gain_table[] =
|
static const t_gain_table 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
|
||||||
|
|
||||||
@ -126,74 +126,8 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
|
|
||||||
const unsigned int original_index = 1;
|
const unsigned int original_index = 1;
|
||||||
|
|
||||||
#elif 0
|
|
||||||
|
|
||||||
// in this table the 'lna-short' register I leave unchanged
|
|
||||||
|
|
||||||
{3, 0, 0, 0}, // 1 .. 0dB -24dB -8dB -33dB .. -65dB
|
|
||||||
{3, 0, 1, 0}, // 2 .. 0dB -24dB -6dB -33dB .. -63dB
|
|
||||||
{3, 0, 2, 0}, // 3 .. 0dB -24dB -3dB -33dB .. -60dB
|
|
||||||
{3, 0, 0, 1}, // 4 .. 0dB -24dB -8dB -27dB .. -59dB
|
|
||||||
{3, 1, 1, 0}, // 5 .. 0dB -19dB -6dB -33dB .. -58dB
|
|
||||||
{3, 0, 1, 1}, // 6 .. 0dB -24dB -6dB -27dB .. -57dB
|
|
||||||
{3, 1, 2, 0}, // 7 .. 0dB -19dB -3dB -33dB .. -55dB
|
|
||||||
{3, 1, 0, 1}, // 8 .. 0dB -19dB -8dB -27dB .. -54dB
|
|
||||||
{3, 0, 0, 2}, // 9 .. 0dB -24dB -8dB -21dB .. -53dB
|
|
||||||
{3, 1, 1, 1}, // 10 .. 0dB -19dB -6dB -27dB .. -52dB
|
|
||||||
{3, 0, 1, 2}, // 11 .. 0dB -24dB -6dB -21dB .. -51dB
|
|
||||||
{3, 2, 2, 0}, // 12 .. 0dB -14dB -3dB -33dB .. -50dB
|
|
||||||
{3, 2, 0, 1}, // 13 .. 0dB -14dB -8dB -27dB .. -49dB
|
|
||||||
{3, 0, 2, 2}, // 14 .. 0dB -24dB -3dB -21dB .. -48dB
|
|
||||||
{3, 2, 3, 0}, // 15 .. 0dB -14dB 0dB -33dB .. -47dB
|
|
||||||
{3, 1, 3, 1}, // 16 .. 0dB -19dB 0dB -27dB .. -46dB
|
|
||||||
{3, 0, 3, 2}, // 17 .. 0dB -24dB 0dB -21dB .. -45dB
|
|
||||||
{3, 3, 0, 1}, // 18 .. 0dB -9dB -8dB -27dB .. -44dB
|
|
||||||
{3, 1, 2, 2}, // 19 .. 0dB -19dB -3dB -21dB .. -43dB
|
|
||||||
{3, 0, 2, 3}, // 20 .. 0dB -24dB -3dB -15dB .. -42dB
|
|
||||||
{3, 0, 0, 4}, // 21 .. 0dB -24dB -8dB -9dB .. -41dB
|
|
||||||
{3, 1, 1, 3}, // 22 .. 0dB -19dB -6dB -15dB .. -40dB
|
|
||||||
{3, 0, 1, 4}, // 23 .. 0dB -24dB -6dB -9dB .. -39dB
|
|
||||||
{3, 0, 0, 5}, // 24 .. 0dB -24dB -8dB -6dB .. -38dB
|
|
||||||
{3, 1, 2, 3}, // 25 .. 0dB -19dB -3dB -15dB .. -37dB
|
|
||||||
{3, 0, 2, 4}, // 26 .. 0dB -24dB -3dB -9dB .. -36dB
|
|
||||||
{3, 4, 0, 2}, // 27 .. 0dB -6dB -8dB -21dB .. -35dB
|
|
||||||
{3, 1, 1, 4}, // 28 .. 0dB -19dB -6dB -9dB .. -34dB
|
|
||||||
{3, 1, 0, 5}, // 29 .. 0dB -19dB -8dB -6dB .. -33dB
|
|
||||||
{3, 3, 0, 3}, // 30 .. 0dB -9dB -8dB -15dB .. -32dB
|
|
||||||
{3, 5, 1, 2}, // 31 .. 0dB -4dB -6dB -21dB .. -31dB
|
|
||||||
{3, 1, 0, 6}, // 32 .. 0dB -19dB -8dB -3dB .. -30dB
|
|
||||||
{3, 2, 3, 3}, // 33 .. 0dB -14dB 0dB -15dB .. -29dB
|
|
||||||
{3, 1, 1, 6}, // 34 .. 0dB -19dB -6dB -3dB .. -28dB
|
|
||||||
{3, 4, 1, 3}, // 35 .. 0dB -6dB -6dB -15dB .. -27dB
|
|
||||||
{3, 2, 2, 4}, // 36 .. 0dB -14dB -3dB -9dB .. -26dB
|
|
||||||
{3, 1, 2, 6}, // 37 .. 0dB -19dB -3dB -3dB .. -25dB
|
|
||||||
{3, 3, 1, 4}, // 38 .. 0dB -9dB -6dB -9dB .. -24dB
|
|
||||||
{3, 2, 1, 6}, // 39 .. 0dB -14dB -6dB -3dB .. -23dB
|
|
||||||
{3, 5, 2, 3}, // 40 .. 0dB -4dB -3dB -15dB .. -22dB
|
|
||||||
{3, 4, 1, 4}, // 41 .. 0dB -6dB -6dB -9dB .. -21dB
|
|
||||||
{3, 4, 0, 5}, // 42 .. 0dB -6dB -8dB -6dB .. -20dB
|
|
||||||
{3, 5, 1, 4}, // 43 .. 0dB -4dB -6dB -9dB .. -19dB
|
|
||||||
{3, 3, 3, 4}, // 44 .. 0dB -9dB 0dB -9dB .. -18dB
|
|
||||||
{3, 2, 3, 6}, // 45 .. 0dB -14dB 0dB -3dB .. -17dB original
|
|
||||||
{3, 5, 1, 5}, // 46 .. 0dB -4dB -6dB -6dB .. -16dB
|
|
||||||
{3, 3, 1, 7}, // 47 .. 0dB -9dB -6dB 0dB .. -15dB
|
|
||||||
{3, 2, 3, 7}, // 48 .. 0dB -14dB 0dB 0dB .. -14dB
|
|
||||||
{3, 5, 1, 6}, // 49 .. 0dB -4dB -6dB -3dB .. -13dB
|
|
||||||
{3, 4, 2, 6}, // 50 .. 0dB -6dB -3dB -3dB .. -12dB
|
|
||||||
{3, 5, 2, 6}, // 51 .. 0dB -4dB -3dB -3dB .. -10dB
|
|
||||||
{3, 4, 3, 6}, // 52 .. 0dB -6dB 0dB -3dB .. -9dB
|
|
||||||
{3, 5, 2, 7}, // 53 .. 0dB -4dB -3dB 0dB .. -7dB
|
|
||||||
{3, 4, 3, 7}, // 54 .. 0dB -6dB 0dB 0dB .. -6dB
|
|
||||||
{3, 5, 3, 7} // 55 .. 0dB -4dB 0dB 0dB .. -4dB
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsigned int original_index = 45;
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// in this table I include adjusting the 'lna-short' register ~
|
|
||||||
// more gain adjustment range from doing so
|
|
||||||
|
|
||||||
{0, 0, 0, 0}, // 1 .. -33dB -24dB -8dB -33dB .. -98dB
|
{0, 0, 0, 0}, // 1 .. -33dB -24dB -8dB -33dB .. -98dB
|
||||||
{0, 0, 1, 0}, // 2 .. -33dB -24dB -6dB -33dB .. -96dB
|
{0, 0, 1, 0}, // 2 .. -33dB -24dB -6dB -33dB .. -96dB
|
||||||
{1, 0, 0, 0}, // 3 .. -30dB -24dB -8dB -33dB .. -95dB
|
{1, 0, 0, 0}, // 3 .. -30dB -24dB -8dB -33dB .. -95dB
|
||||||
@ -296,18 +230,21 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// the total gain for each table index
|
||||||
|
int8_t gain_dB[ARRAY_SIZE(gain_table)] = {0};
|
||||||
|
|
||||||
unsigned int counter = 0;
|
unsigned int counter = 0;
|
||||||
|
|
||||||
int16_t orig_dB_gain = -17;
|
int16_t orig_dB_gain = -17;
|
||||||
|
|
||||||
#ifdef ENABLE_AM_FIX_TEST1
|
#ifdef ENABLE_AM_FIX_TEST1
|
||||||
unsigned int am_fix_gain_table_index[2] = {1 + gSetting_AM_fix_test1, 1 + gSetting_AM_fix_test1};
|
unsigned int gain_table_index[2] = {1 + gSetting_AM_fix_test1, 1 + gSetting_AM_fix_test1};
|
||||||
#else
|
#else
|
||||||
unsigned int am_fix_gain_table_index[2] = {original_index, original_index};
|
unsigned int gain_table_index[2] = {original_index, original_index};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// used to simply detect we've changed our table index/register settings
|
// used to simply detect we've changed our table index/register settings
|
||||||
unsigned int am_fix_gain_table_index_prev[2] = {0, 0};
|
unsigned int gain_table_index_prev[2] = {0, 0};
|
||||||
|
|
||||||
// holds the previous RSSI level
|
// holds the previous RSSI level
|
||||||
int16_t prev_rssi[2] = {0, 0};
|
int16_t prev_rssi[2] = {0, 0};
|
||||||
@ -319,7 +256,7 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
int16_t rssi_db_gain_diff[2] = {0, 0};
|
int16_t rssi_db_gain_diff[2] = {0, 0};
|
||||||
|
|
||||||
// used to limit the max front end gain
|
// used to limit the max front end gain
|
||||||
unsigned int max_index = ARRAY_SIZE(am_fix_gain_table) - 1;
|
unsigned int max_index = ARRAY_SIZE(gain_table) - 1;
|
||||||
|
|
||||||
#ifndef ENABLE_AM_FIX_TEST1
|
#ifndef ENABLE_AM_FIX_TEST1
|
||||||
// -89dBm, any higher and the AM demodulator starts to saturate/clip/distort
|
// -89dBm, any higher and the AM demodulator starts to saturate/clip/distort
|
||||||
@ -330,35 +267,36 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
{ // called at boot-up
|
{ // called at boot-up
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < 2; i++)
|
for (i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_AM_FIX_TEST1
|
#ifdef ENABLE_AM_FIX_TEST1
|
||||||
am_fix_gain_table_index[i] = 1 + gSetting_AM_fix_test1;
|
gain_table_index[i] = 1 + gSetting_AM_fix_test1;
|
||||||
#else
|
#else
|
||||||
am_fix_gain_table_index[i] = original_index; // re-start with original QS setting
|
gain_table_index[i] = original_index; // re-start with original QS setting
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pre-compute the total gain DB for each table index
|
||||||
|
for (i = 0; i < ARRAY_SIZE(gain_table); i++)
|
||||||
|
{
|
||||||
|
const t_gain_table gains = gain_table[i];
|
||||||
|
gain_dB[i] = lna_short_dB[gains.lna_short] + lna_dB[gains.lna] + mixer_dB[gains.mixer] + pga_dB[gains.pga];
|
||||||
|
}
|
||||||
|
|
||||||
orig_dB_gain = lna_short_dB[orig_lna_short] + lna_dB[orig_lna] + mixer_dB[orig_mixer] + pga_dB[orig_pga];
|
orig_dB_gain = lna_short_dB[orig_lna_short] + lna_dB[orig_lna] + mixer_dB[orig_mixer] + pga_dB[orig_pga];
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
{ // set the maximum gain we want to use
|
{ // set a maximum gain to use
|
||||||
// const int16_t max_gain_dB = orig_dB_gain;
|
// const int16_t max_gain_dB = orig_dB_gain;
|
||||||
const int16_t max_gain_dB = -10;
|
const int16_t max_gain_dB = -10;
|
||||||
max_index = ARRAY_SIZE(am_fix_gain_table);
|
max_index = ARRAY_SIZE(gain_table);
|
||||||
while (--max_index > 1)
|
while (--max_index > 1)
|
||||||
{
|
if (gain_dB[max_index] <= max_gain_dB)
|
||||||
const uint8_t lna_short = am_fix_gain_table[max_index].lna_short;
|
|
||||||
const uint8_t lna = am_fix_gain_table[max_index].lna;
|
|
||||||
const uint8_t mixer = am_fix_gain_table[max_index].mixer;
|
|
||||||
const uint8_t pga = am_fix_gain_table[max_index].pga;
|
|
||||||
const int16_t gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga];
|
|
||||||
if (gain_dB <= max_gain_dB)
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
max_index = ARRAY_SIZE(am_fix_gain_table) - 1;
|
max_index = ARRAY_SIZE(gain_table) - 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,12 +312,12 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
rssi_db_gain_diff[vfo] = 0;
|
rssi_db_gain_diff[vfo] = 0;
|
||||||
|
|
||||||
#ifdef ENABLE_AM_FIX_TEST1
|
#ifdef ENABLE_AM_FIX_TEST1
|
||||||
// am_fix_gain_table_index[vfo] = 1 + gSetting_AM_fix_test1;
|
// gain_table_index[vfo] = 1 + gSetting_AM_fix_test1;
|
||||||
#else
|
#else
|
||||||
// am_fix_gain_table_index[vfo] = original_index; // re-start with original QS setting
|
// gain_table_index[vfo] = original_index; // re-start with original QS setting
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
am_fix_gain_table_index_prev[vfo] = 0;
|
gain_table_index_prev[vfo] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// adjust the RX RF gain to try and prevent the AM demodulator from
|
// adjust the RX RF gain to try and prevent the AM demodulator from
|
||||||
@ -415,8 +353,13 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (counter > 0)
|
if (counter > 0)
|
||||||
|
{
|
||||||
if (++counter >= 20) // limit display update rate to 200ms
|
if (++counter >= 20) // limit display update rate to 200ms
|
||||||
counter = 0;
|
{
|
||||||
|
counter = 0;
|
||||||
|
gUpdateDisplay = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{ // sample the current RSSI level
|
{ // sample the current RSSI level
|
||||||
// average it with the previous rssi (a bit of noise/spike immunity)
|
// average it with the previous rssi (a bit of noise/spike immunity)
|
||||||
@ -444,9 +387,9 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
|
|
||||||
{
|
{
|
||||||
int i = 1 + (int)gSetting_AM_fix_test1;
|
int i = 1 + (int)gSetting_AM_fix_test1;
|
||||||
i = (i < 1) ? 1 : (i > ((int)ARRAY_SIZE(am_fix_gain_table) - 1) ? ARRAY_SIZE(am_fix_gain_table) - 1 : i;
|
i = (i < 1) ? 1 : (i > ((int)ARRAY_SIZE(gain_table) - 1) ? ARRAY_SIZE(gain_table) - 1 : i;
|
||||||
|
|
||||||
if (am_fix_gain_table_index[vfo] == i)
|
if (gain_table_index[vfo] == i)
|
||||||
return; // no change
|
return; // no change
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,38 +405,18 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
if (diff_dB > 0)
|
if (diff_dB > 0)
|
||||||
{ // decrease gain
|
{ // decrease gain
|
||||||
|
|
||||||
unsigned int index = am_fix_gain_table_index[vfo]; // current position we're at
|
unsigned int index = gain_table_index[vfo]; // current position we're at
|
||||||
|
|
||||||
if (diff_dB >= 10)
|
if (diff_dB >= 10)
|
||||||
{ // jump immediately to a new gain setting
|
{ // jump immediately to a new gain setting
|
||||||
// this greatly speeds up initial gain reduction (but reduces noise/spike immunity)
|
// this greatly speeds up initial gain reduction (but reduces noise/spike immunity)
|
||||||
|
const int16_t desired_gain_dB = (int16_t)gain_dB[index] - diff_dB + 8; // get no closer than 8dB (bit of noise/spike immunity)
|
||||||
uint8_t lna_short = am_fix_gain_table[index].lna_short;
|
|
||||||
uint8_t lna = am_fix_gain_table[index].lna;
|
|
||||||
uint8_t mixer = am_fix_gain_table[index].mixer;
|
|
||||||
uint8_t pga = am_fix_gain_table[index].pga;
|
|
||||||
|
|
||||||
// const int16_t desired_gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga] - diff_dB;
|
|
||||||
const int16_t desired_gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga] - diff_dB + 8; // get no closer than 8dB (bit of noise/spike immunity)
|
|
||||||
|
|
||||||
// scan the table to see what index to jump straight too
|
// scan the table to see what index to jump straight too
|
||||||
while (index > 1)
|
while (index > 1)
|
||||||
{
|
if (gain_dB[--index] <= desired_gain_dB)
|
||||||
index--;
|
break;
|
||||||
|
|
||||||
lna_short = am_fix_gain_table[index].lna_short;
|
//index = (gain_table_index[vfo] + index) / 2; // easy does it
|
||||||
lna = am_fix_gain_table[index].lna;
|
|
||||||
mixer = am_fix_gain_table[index].mixer;
|
|
||||||
pga = am_fix_gain_table[index].pga;
|
|
||||||
|
|
||||||
{
|
|
||||||
const int16_t gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga];
|
|
||||||
if (gain_dB <= desired_gain_dB)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//index = (am_fix_gain_table_index[vfo] + index) / 2; // easy does it
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // incrementally reduce the gain .. taking it slow improves noise/spike immunity
|
{ // incrementally reduce the gain .. taking it slow improves noise/spike immunity
|
||||||
@ -507,10 +430,10 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
|
|
||||||
index = (index < 1) ? 1 : (index > max_index) ? max_index : index;
|
index = (index < 1) ? 1 : (index > max_index) ? max_index : index;
|
||||||
|
|
||||||
if (am_fix_gain_table_index[vfo] != index)
|
if (gain_table_index[vfo] != index)
|
||||||
{
|
{
|
||||||
am_fix_gain_table_index[vfo] = index;
|
gain_table_index[vfo] = index;
|
||||||
am_gain_hold_counter[vfo] = 30; // 300ms hold
|
am_gain_hold_counter[vfo] = 30; // 300ms hold
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,34 +442,30 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
|
|
||||||
if (am_gain_hold_counter[vfo] == 0)
|
if (am_gain_hold_counter[vfo] == 0)
|
||||||
{ // hold has been released, we're free to increase gain
|
{ // hold has been released, we're free to increase gain
|
||||||
const unsigned int index = am_fix_gain_table_index[vfo] + 1;
|
const unsigned int index = gain_table_index[vfo] + 1;
|
||||||
am_fix_gain_table_index[vfo] = (index > max_index) ? max_index : index; // limit the gain
|
gain_table_index[vfo] = (index > max_index) ? max_index : index; // limit the gain
|
||||||
}
|
}
|
||||||
|
|
||||||
if (am_fix_gain_table_index[vfo] == am_fix_gain_table_index_prev[vfo])
|
if (gain_table_index[vfo] == gain_table_index_prev[vfo])
|
||||||
return; // no gain changes have been made
|
return; // no gain changes have been made
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
{ // apply the new settings to the front end registers
|
{ // apply the new settings to the front end registers
|
||||||
|
|
||||||
const unsigned int index = am_fix_gain_table_index[vfo];
|
const unsigned int index = gain_table_index[vfo];
|
||||||
|
|
||||||
const uint8_t lna_short = am_fix_gain_table[index].lna_short;
|
const t_gain_table gains = gain_table[index];
|
||||||
const uint8_t lna = am_fix_gain_table[index].lna;
|
|
||||||
const uint8_t mixer = am_fix_gain_table[index].mixer;
|
|
||||||
const uint8_t pga = am_fix_gain_table[index].pga;
|
|
||||||
const int16_t gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga];
|
|
||||||
|
|
||||||
BK4819_WriteRegister(BK4819_REG_13, (lna_short << 8) | (lna << 5) | (mixer << 3) | (pga << 0));
|
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));
|
||||||
|
|
||||||
// offset the RSSI reading to the rest of the firmware to cancel out the gain adjustments we make
|
// offset the RSSI reading to the rest of the firmware to cancel out the gain adjustments we make
|
||||||
|
|
||||||
// gain difference from original QS setting
|
// gain difference from original QS setting
|
||||||
rssi_db_gain_diff[vfo] = gain_dB - orig_dB_gain;
|
rssi_db_gain_diff[vfo] = (int16_t)gain_dB[index] - orig_dB_gain;
|
||||||
|
|
||||||
// remember the new table index
|
// remember the new table index
|
||||||
am_fix_gain_table_index_prev[vfo] = index;
|
gain_table_index_prev[vfo] = index;
|
||||||
|
|
||||||
{ // save the corrected RSSI level
|
{ // save the corrected RSSI level
|
||||||
const int16_t new_rssi = rssi - (rssi_db_gain_diff[vfo] * 2);
|
const int16_t new_rssi = rssi - (rssi_db_gain_diff[vfo] * 2);
|
||||||
@ -576,14 +495,11 @@ const uint8_t orig_pga = 6; // -3dB
|
|||||||
void AM_fix_print_data(const int vfo, char *s)
|
void AM_fix_print_data(const int vfo, char *s)
|
||||||
{
|
{
|
||||||
// fetch current register settings
|
// fetch current register settings
|
||||||
const unsigned int index = am_fix_gain_table_index[vfo];
|
|
||||||
const uint8_t lna_short = am_fix_gain_table[index].lna_short;
|
|
||||||
const uint8_t lna = am_fix_gain_table[index].lna;
|
|
||||||
const uint8_t mixer = am_fix_gain_table[index].mixer;
|
|
||||||
const uint8_t pga = am_fix_gain_table[index].pga;
|
|
||||||
const int16_t gain_dB = lna_short_dB[lna_short] + lna_dB[lna] + mixer_dB[mixer] + pga_dB[pga];
|
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
sprintf(s, "idx %2d %4ddB %3u", index, gain_dB, prev_rssi[vfo]);
|
{
|
||||||
|
const unsigned int index = gain_table_index[vfo];
|
||||||
|
sprintf(s, "idx %2d %4ddB %3u", index, gain_dB[index], prev_rssi[vfo]);
|
||||||
|
}
|
||||||
counter = 1;
|
counter = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
34
app/app.c
34
app/app.c
@ -1294,7 +1294,8 @@ void APP_CheckKeys(void)
|
|||||||
Key == KEY_SIDE1 ||
|
Key == KEY_SIDE1 ||
|
||||||
Key == KEY_UP ||
|
Key == KEY_UP ||
|
||||||
Key == KEY_DOWN ||
|
Key == KEY_DOWN ||
|
||||||
Key == KEY_EXIT
|
Key == KEY_EXIT ||
|
||||||
|
Key == KEY_MENU
|
||||||
#ifdef ENABLE_MAIN_KEY_HOLD
|
#ifdef ENABLE_MAIN_KEY_HOLD
|
||||||
|| Key <= KEY_9 // keys 0-9 can be held down to bypass pressing the F-Key
|
|| Key <= KEY_9 // keys 0-9 can be held down to bypass pressing the F-Key
|
||||||
#endif
|
#endif
|
||||||
@ -2048,33 +2049,20 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gScanState != SCAN_OFF &&
|
if (Key != KEY_PTT &&
|
||||||
Key != KEY_PTT &&
|
|
||||||
Key != KEY_UP &&
|
Key != KEY_UP &&
|
||||||
Key != KEY_DOWN &&
|
Key != KEY_DOWN &&
|
||||||
Key != KEY_EXIT &&
|
Key != KEY_EXIT &&
|
||||||
Key != KEY_SIDE1 &&
|
Key != KEY_SIDE1 &&
|
||||||
Key != KEY_SIDE2 &&
|
Key != KEY_SIDE2 &&
|
||||||
Key != KEY_STAR)
|
Key != KEY_STAR)
|
||||||
{ // scanning
|
{
|
||||||
if (bKeyPressed && !bKeyHeld)
|
if (gScanState != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF)
|
||||||
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
|
{ // frequency or CTCSS/DCS scanning
|
||||||
return;
|
if (bKeyPressed && !bKeyHeld)
|
||||||
}
|
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
|
||||||
|
return;
|
||||||
if (gCssScanMode != CSS_SCAN_MODE_OFF &&
|
}
|
||||||
Key != KEY_PTT &&
|
|
||||||
Key != KEY_UP &&
|
|
||||||
Key != KEY_DOWN &&
|
|
||||||
Key != KEY_EXIT &&
|
|
||||||
Key != KEY_SIDE1 &&
|
|
||||||
Key != KEY_SIDE2 &&
|
|
||||||
Key != KEY_STAR &&
|
|
||||||
Key != KEY_MENU)
|
|
||||||
{ // code scanning
|
|
||||||
if (bKeyPressed && !bKeyHeld)
|
|
||||||
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gPttWasPressed && Key == KEY_PTT)
|
if (gPttWasPressed && Key == KEY_PTT)
|
||||||
@ -2099,7 +2087,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gWasFKeyPressed && Key > KEY_9 && Key != KEY_F && Key != KEY_STAR)
|
if (gWasFKeyPressed && Key > KEY_9 && Key != KEY_F && Key != KEY_STAR && Key != KEY_MENU)
|
||||||
{
|
{
|
||||||
gWasFKeyPressed = false;
|
gWasFKeyPressed = false;
|
||||||
gUpdateStatus = true;
|
gUpdateStatus = true;
|
||||||
|
116
app/main.c
116
app/main.c
@ -53,43 +53,12 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: do something useful with the key
|
// TODO: do something useful with the key
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_COPY_CHAN_VFO
|
|
||||||
{ // copy channel to VFO
|
|
||||||
int channel = -1;
|
|
||||||
int vfo = -1;
|
|
||||||
if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE))
|
|
||||||
{ // VFO mode
|
|
||||||
if (IS_MR_CHANNEL(gRxVfo->CHANNEL_SAVE))
|
|
||||||
{ // other vfo is in channel mode
|
|
||||||
channel = gRxVfo->CHANNEL_SAVE;
|
|
||||||
vfo = gTxVfo->CHANNEL_SAVE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (IS_FREQ_CHANNEL((gRxVfo->CHANNEL_SAVE + 1) & 1))
|
|
||||||
{ // VFO mode
|
|
||||||
if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE))
|
|
||||||
{ // other vfo is in channel mode
|
|
||||||
channel = gTxVfo->CHANNEL_SAVE;
|
|
||||||
vfo = gRxVfo->CHANNEL_SAVE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channel >= 0 && vfo >= 0)
|
|
||||||
{ // copy the channel into the VFO
|
|
||||||
|
|
||||||
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
|
|
||||||
|
|
||||||
|
|
||||||
// gRequestSaveVFO = true;
|
|
||||||
// gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
|
|
||||||
// gRequestDisplayScreen = DISPLAY_MAIN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -282,8 +251,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
|||||||
if (bKeyPressed)
|
if (bKeyPressed)
|
||||||
{
|
{
|
||||||
if (gScreenToDisplay == DISPLAY_MAIN)
|
if (gScreenToDisplay == DISPLAY_MAIN)
|
||||||
{ // we're going to go straight to the 0-9 key function
|
{
|
||||||
// without the need of the F-key
|
|
||||||
if (gInputBoxIndex > 0)
|
if (gInputBoxIndex > 0)
|
||||||
{ // delete any inputted chars
|
{ // delete any inputted chars
|
||||||
gInputBoxIndex = 0;
|
gInputBoxIndex = 0;
|
||||||
@ -317,9 +285,10 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
|||||||
if (!gWasFKeyPressed)
|
if (!gWasFKeyPressed)
|
||||||
{ // F-key wasn't pressed
|
{ // F-key wasn't pressed
|
||||||
|
|
||||||
uint8_t Vfo = gEeprom.TX_CHANNEL;
|
const uint8_t Vfo = gEeprom.TX_CHANNEL;
|
||||||
|
|
||||||
gKeyInputCountdown = key_input_timeout_500ms;
|
gKeyInputCountdown = key_input_timeout_500ms;
|
||||||
|
|
||||||
INPUTBOX_Append(Key);
|
INPUTBOX_Append(Key);
|
||||||
|
|
||||||
gRequestDisplayScreen = DISPLAY_MAIN;
|
gRequestDisplayScreen = DISPLAY_MAIN;
|
||||||
@ -508,9 +477,78 @@ static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void MAIN_Key_MENU(bool bKeyPressed, bool bKeyHeld)
|
static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
|
||||||
{
|
{
|
||||||
if (!bKeyHeld && bKeyPressed)
|
if (bKeyHeld)
|
||||||
|
{ // key held down (long press)
|
||||||
|
|
||||||
|
if (bKeyPressed)
|
||||||
|
{
|
||||||
|
if (gScreenToDisplay == DISPLAY_MAIN)
|
||||||
|
{
|
||||||
|
if (gInputBoxIndex > 0)
|
||||||
|
{ // delete any inputted chars
|
||||||
|
gInputBoxIndex = 0;
|
||||||
|
gRequestDisplayScreen = DISPLAY_MAIN;
|
||||||
|
}
|
||||||
|
|
||||||
|
gWasFKeyPressed = false;
|
||||||
|
gUpdateStatus = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: long press M-key
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef ENABLE_COPY_CHAN_TO_VFO
|
||||||
|
{ // copy channel to VFO
|
||||||
|
int channel = -1;
|
||||||
|
int vfo = -1;
|
||||||
|
//int selected = -1;
|
||||||
|
|
||||||
|
if (IS_FREQ_CHANNEL(gRxVfo->CHANNEL_SAVE))
|
||||||
|
{ // VFO mode
|
||||||
|
if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE))
|
||||||
|
{ // other VFO is in channel mode
|
||||||
|
channel = gTxVfo->CHANNEL_SAVE;
|
||||||
|
vfo = gRxVfo->CHANNEL_SAVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE))
|
||||||
|
{ // VFO mode
|
||||||
|
if (IS_MR_CHANNEL(gRxVfo->CHANNEL_SAVE))
|
||||||
|
{ // other VFO is in channel mode
|
||||||
|
channel = gRxVfo->CHANNEL_SAVE;
|
||||||
|
vfo = gTxVfo->CHANNEL_SAVE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (channel >= 0 && vfo >= 0)
|
||||||
|
{ // copy the channel into the VFO
|
||||||
|
|
||||||
|
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//gEeprom.RX_CHANNEL = () & 1; // swap to the VFO
|
||||||
|
|
||||||
|
|
||||||
|
// gRequestSaveVFO = true;
|
||||||
|
// gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
|
||||||
|
// gRequestDisplayScreen = DISPLAY_MAIN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!bKeyPressed)
|
||||||
{
|
{
|
||||||
bool bFlag;
|
bool bFlag;
|
||||||
|
|
||||||
|
BIN
firmware.bin
BIN
firmware.bin
Binary file not shown.
Binary file not shown.
@ -151,6 +151,8 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
|
|||||||
// if DTMF is enabled when TX'ing, it changes the TX audio filtering !! .. 1of11
|
// if DTMF is enabled when TX'ing, it changes the TX audio filtering !! .. 1of11
|
||||||
BK4819_DisableDTMF();
|
BK4819_DisableDTMF();
|
||||||
|
|
||||||
|
gDTMF_ReceivedSaved[0] = 0;
|
||||||
|
|
||||||
#if defined(ENABLE_FMRADIO)
|
#if defined(ENABLE_FMRADIO)
|
||||||
if (gFmRadioMode)
|
if (gFmRadioMode)
|
||||||
BK1080_Init(0, false);
|
BK1080_Init(0, false);
|
||||||
|
44
ui/main.c
44
ui/main.c
@ -36,6 +36,23 @@
|
|||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
#ifdef ENABLE_AUDIO_BAR
|
#ifdef ENABLE_AUDIO_BAR
|
||||||
|
|
||||||
|
unsigned int sqrt16(unsigned int value)
|
||||||
|
{ // return square root of 'value'
|
||||||
|
unsigned int shift = 15;
|
||||||
|
unsigned int bit = 1u << shift;
|
||||||
|
unsigned int sqrti = 0;
|
||||||
|
do {
|
||||||
|
const unsigned int temp = ((sqrti << 1) | bit) << shift--;
|
||||||
|
if (value >= temp)
|
||||||
|
{
|
||||||
|
value -= temp;
|
||||||
|
sqrti |= bit;
|
||||||
|
}
|
||||||
|
} while (bit >>= 1);
|
||||||
|
return sqrti;
|
||||||
|
}
|
||||||
|
|
||||||
void UI_DisplayAudioBar(void)
|
void UI_DisplayAudioBar(void)
|
||||||
{
|
{
|
||||||
if (gSetting_mic_bar)
|
if (gSetting_mic_bar)
|
||||||
@ -49,20 +66,27 @@
|
|||||||
if (gCurrentFunction != FUNCTION_TRANSMIT)
|
if (gCurrentFunction != FUNCTION_TRANSMIT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// TODO: logify this to make the bar visible with the mostly small value
|
const unsigned int voice_amp = BK4819_GetVoiceAmplitudeOut(); // 15:0
|
||||||
|
|
||||||
|
// const unsigned int max = 65535;
|
||||||
|
// const unsigned int level = ((voice_amp * lcd_width) + (max / 2)) / max; // with rounding
|
||||||
|
// const unsigned int len = (level <= lcd_width) ? level : lcd_width;
|
||||||
|
|
||||||
|
// make non-linear to make more sensitive at low values
|
||||||
|
const unsigned int level = voice_amp * 8;
|
||||||
|
const unsigned int sqrt_level = sqrt16((level < 65535) ? level : 65535);
|
||||||
|
const unsigned int len = (sqrt_level <= lcd_width) ? sqrt_level : lcd_width;
|
||||||
|
|
||||||
const uint16_t voice_amp = BK4819_GetVoiceAmplitudeOut(); // 15:0
|
|
||||||
const unsigned int max = 32767;
|
|
||||||
const unsigned int level = (((uint32_t)voice_amp * lcd_width) + (max / 2)) / max; // with rounding
|
|
||||||
#else
|
#else
|
||||||
// TX/RX AF input level (dB)
|
// TX/RX AF input level (dB)
|
||||||
const uint8_t af_tx_rx = BK4819_GetAfTxRx(); // 6:0
|
|
||||||
const unsigned int max = 63;
|
const uint8_t af_tx_rx = BK4819_GetAfTxRx(); // 6:0
|
||||||
const unsigned int level = (((uint16_t)af_tx_rx * lcd_width) + (max / 2)) / max; // with rounding
|
const unsigned int max = 63;
|
||||||
|
const unsigned int level = (((uint16_t)af_tx_rx * lcd_width) + (max / 2)) / max; // with rounding
|
||||||
|
const unsigned int len = (level <= lcd_width) ? level : lcd_width;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const unsigned int len = (level <= lcd_width) ? level : lcd_width;
|
|
||||||
uint8_t *pLine = gFrameBuffer[line];
|
uint8_t *pLine = gFrameBuffer[line];
|
||||||
memset(pLine, 0, lcd_width);
|
memset(pLine, 0, lcd_width);
|
||||||
#if 0
|
#if 0
|
||||||
@ -73,6 +97,7 @@
|
|||||||
pLine[i] = 0x3e;
|
pLine[i] = 0x3e;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if (gCurrentFunction == FUNCTION_TRANSMIT)
|
if (gCurrentFunction == FUNCTION_TRANSMIT)
|
||||||
ST7565_BlitFullScreen();
|
ST7565_BlitFullScreen();
|
||||||
}
|
}
|
||||||
@ -521,8 +546,9 @@ void UI_DisplayMain(void)
|
|||||||
#ifdef ENABLE_AUDIO_BAR
|
#ifdef ENABLE_AUDIO_BAR
|
||||||
UI_DisplayAudioBar();
|
UI_DisplayAudioBar();
|
||||||
|
|
||||||
if (!gSetting_mic_bar)
|
// if (!gSetting_mic_bar)
|
||||||
#endif
|
#endif
|
||||||
|
if (gCurrentFunction != FUNCTION_TRANSMIT)
|
||||||
{
|
{
|
||||||
if (gSetting_live_DTMF_decoder && gDTMF_ReceivedSaved[0] >= 32)
|
if (gSetting_live_DTMF_decoder && gDTMF_ReceivedSaved[0] >= 32)
|
||||||
{ // show live DTMF decode
|
{ // show live DTMF decode
|
||||||
|
Loading…
x
Reference in New Issue
Block a user