Re-enabled weak signal bandwidth reduction

This commit is contained in:
OneOfEleven 2023-09-24 13:00:02 +01:00
parent 4ea37929f7
commit 2486501332
13 changed files with 906 additions and 23 deletions

View File

@ -92,14 +92,20 @@ const uint8_t orig_pga = 6; // -3dB
// 1 = -27dB
// 0 = -33dB
// front end register dB values - needs a measuring/calibration update really
// 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
static const int16_t lna_short_dB[] = {-33, -30 -24, 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 by far 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[] =
{
@ -115,7 +121,7 @@ const uint8_t orig_pga = 6; // -3dB
{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 0
@ -288,6 +294,8 @@ const uint8_t orig_pga = 6; // -3dB
#else
unsigned int am_fix_gain_table_index = original_index; // start with original QS setting
#endif
// used to simply detect we've changed our table index/register settings
unsigned int am_fix_gain_table_index_prev = 0;
// moving average RSSI buffer
@ -299,14 +307,15 @@ const uint8_t orig_pga = 6; // -3dB
uint16_t sum; // sum of all samples in the buffer
} moving_avg_rssi = {0};
// used to prevent gain hunting, provides a peak hold time delay
// to help reduce gain hunting, provides a peak hold time delay
unsigned int am_gain_hold_counter = 0;
// used to correct the RSSI readings after our front end gain adjustments
int16_t rssi_db_gain_diff = 0;
void AM_fix_reset(void)
{
{ // reset the AM fixer
// reset the moving average filter
memset(&moving_avg_rssi, 0, sizeof(moving_avg_rssi));
@ -319,9 +328,17 @@ const uint8_t orig_pga = 6; // -3dB
#else
am_fix_gain_table_index = original_index; // re-start with original QS setting
#endif
am_fix_gain_table_index_prev = 0;
}
// adjust the RX RF 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 settings
//
void AM_fix_adjust_frontEnd_10ms(void)
{
#ifndef ENABLE_AM_FIX_TEST1
@ -329,12 +346,13 @@ const uint8_t orig_pga = 6; // -3dB
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
// they remain as per QS original
// we don't need to play with the front end gains if we're in FM mode, they
// remain as per QS original
//
if (!gRxVfo->IsAM)
return;
// we're in AM mode
// but we're not in FM mode, we're in AM mode
switch (gCurrentFunction)
{
@ -344,7 +362,7 @@ const uint8_t orig_pga = 6; // -3dB
case FUNCTION_FOREGROUND:
return;
// only adjust the front end if in one of these modes
// only adjust stuff if we're in one of these modes
case FUNCTION_RECEIVE:
case FUNCTION_MONITOR:
case FUNCTION_INCOMING:
@ -352,10 +370,11 @@ const uint8_t orig_pga = 6; // -3dB
}
// sample the current RSSI level
uint16_t rssi = BK4819_GetRSSI(); // supposed 9-bit value (0 .. 511) - never seen that though
uint16_t rssi = BK4819_GetRSSI(); // supposed 9-bit value (0 .. 511) - never seen that though
#if 1
// compute a moving average RSSI - just smooths any sharp spikes
// compute moving average RSSI - helps smooth any sharp spikes/troughs
// but can cause gain hunting/oscillation if too long a buffer (.samples)
if (moving_avg_rssi.count < ARRAY_SIZE(moving_avg_rssi.samples))
moving_avg_rssi.count++;
moving_avg_rssi.sum -= moving_avg_rssi.samples[moving_avg_rssi.index]; // subtract the oldest sample
@ -370,42 +389,42 @@ const uint8_t orig_pga = 6; // -3dB
#ifdef ENABLE_AM_FIX_TEST1
// user is manually adjusting a gain register - don't do anything automatically
am_fix_gain_table_index = 1 + gSetting_AM_fix_test1;
if (am_gain_hold_counter > 0)
if (--am_gain_hold_counter > 0)
return;
am_gain_hold_counter = 250; // 250ms
am_gain_hold_counter = 250; // 250ms hold
#else
// automatically choose a front end gain setting by monitoring the RSSI
if (rssi > desired_rssi)
{ // decrease gain
if (am_fix_gain_table_index > 1)
am_fix_gain_table_index--;
am_gain_hold_counter = 50; // 500ms
am_gain_hold_counter = 50; // 500ms hold
}
if (am_gain_hold_counter > 0)
am_gain_hold_counter--;
if (am_gain_hold_counter == 0)
{ // hold has been released, we're now free to increase gain
// hold has been released, we're free to increase gain
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))
am_fix_gain_table_index++;
}
}
if (am_fix_gain_table_index == am_fix_gain_table_index_prev)
return; // no gain changes have been made
#endif
// apply the new settings to the front end registers
@ -423,6 +442,7 @@ const uint8_t orig_pga = 6; // -3dB
// gain difference from original QS setting
rssi_db_gain_diff = am_dB_gain - orig_dB_gain;
// shall we or sharn't we ?
//gCurrentRSSI[gEeprom.RX_CHANNEL] = rssi - (rssi_db_gain_diff * 2);
}
@ -430,6 +450,7 @@ const uint8_t orig_pga = 6; // -3dB
am_fix_gain_table_index_prev = am_fix_gain_table_index;
#ifdef ENABLE_AM_FIX_SHOW_DATA
// trigger display update so the user can see the data as it changes
gUpdateDisplay = true;
#endif
}

BIN
firmware.bin Normal file

Binary file not shown.

BIN
firmware.packed.bin Normal file

Binary file not shown.

View File

@ -595,7 +595,8 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
case BK4819_FILTER_BW_WIDE:
case BK4819_FILTER_BW_NARROW:
#ifdef ENABLE_AM_FIX
BK4819_SetFilterBandwidth(Bandwidth, gRxVfo->IsAM && gSetting_AM_fix);
// BK4819_SetFilterBandwidth(Bandwidth, gRxVfo->IsAM && gSetting_AM_fix);
BK4819_SetFilterBandwidth(Bandwidth, false);
#else
BK4819_SetFilterBandwidth(Bandwidth, false);
#endif
@ -843,7 +844,8 @@ void RADIO_SetTxParameters(void)
case BK4819_FILTER_BW_WIDE:
case BK4819_FILTER_BW_NARROW:
#ifdef ENABLE_AM_FIX
BK4819_SetFilterBandwidth(Bandwidth, gCurrentVfo->IsAM && gSetting_AM_fix);
// BK4819_SetFilterBandwidth(Bandwidth, gCurrentVfo->IsAM && gSetting_AM_fix);
BK4819_SetFilterBandwidth(Bandwidth, false);
#else
BK4819_SetFilterBandwidth(Bandwidth, false);
#endif

17
utils/clean.bat Normal file
View File

@ -0,0 +1,17 @@
@echo off
del /S /Q *.~*
del /S /Q *.map
del /S /Q *.tds
del /S /Q *.obj
del /S /Q *.db
del /S /Q *.ilc
del /S /Q *.ild
del /S /Q *.ilf
del /S /Q *.ils
del /S /Q *.dcu
::del /S /Q *.dsk
rd /S /Q Debug
rd /S /Q Release
rd /S /Q ipch
::pause
@echo on

98
utils/gain_table.c Normal file
View File

@ -0,0 +1,98 @@
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
{0, 0, 0, 0}, // 1 .. -33dB -24dB -8dB -33dB .. -98dB
{0, 0, 1, 0}, // 2 .. -33dB -24dB -6dB -33dB .. -96dB
{1, 0, 0, 0}, // 3 .. -30dB -24dB -8dB -33dB .. -95dB
{0, 1, 0, 0}, // 4 .. -33dB -19dB -8dB -33dB .. -93dB
{0, 0, 0, 1}, // 5 .. -33dB -24dB -8dB -27dB .. -92dB
{0, 1, 1, 0}, // 6 .. -33dB -19dB -6dB -33dB .. -91dB
{0, 0, 1, 1}, // 7 .. -33dB -24dB -6dB -27dB .. -90dB
{1, 0, 0, 1}, // 8 .. -30dB -24dB -8dB -27dB .. -89dB
{0, 1, 2, 0}, // 9 .. -33dB -19dB -3dB -33dB .. -88dB
{1, 0, 3, 0}, // 10 .. -30dB -24dB 0dB -33dB .. -87dB
{0, 0, 0, 2}, // 11 .. -33dB -24dB -8dB -21dB .. -86dB
{1, 1, 2, 0}, // 12 .. -30dB -19dB -3dB -33dB .. -85dB
{0, 0, 3, 1}, // 13 .. -33dB -24dB 0dB -27dB .. -84dB
{0, 3, 0, 0}, // 14 .. -33dB -9dB -8dB -33dB .. -83dB
{1, 1, 3, 0}, // 15 .. -30dB -19dB 0dB -33dB .. -82dB
{1, 0, 3, 1}, // 16 .. -30dB -24dB 0dB -27dB .. -81dB
{0, 2, 3, 0}, // 17 .. -33dB -14dB 0dB -33dB .. -80dB
{1, 2, 0, 1}, // 18 .. -30dB -14dB -8dB -27dB .. -79dB
{0, 3, 2, 0}, // 19 .. -33dB -9dB -3dB -33dB .. -78dB
{1, 4, 0, 0}, // 20 .. -30dB -6dB -8dB -33dB .. -77dB
{0, 2, 0, 2}, // 21 .. -33dB -14dB -8dB -21dB .. -76dB
{0, 3, 3, 0}, // 22 .. -33dB -9dB 0dB -33dB .. -75dB
{1, 3, 0, 1}, // 23 .. -30dB -9dB -8dB -27dB .. -74dB
{1, 2, 0, 2}, // 24 .. -30dB -14dB -8dB -21dB .. -73dB
{1, 1, 0, 3}, // 25 .. -30dB -19dB -8dB -15dB .. -72dB
{1, 4, 0, 1}, // 26 .. -30dB -6dB -8dB -27dB .. -71dB
{1, 5, 2, 0}, // 27 .. -30dB -4dB -3dB -33dB .. -70dB
{1, 4, 1, 1}, // 28 .. -30dB -6dB -6dB -27dB .. -69dB
{2, 2, 2, 1}, // 29 .. -24dB -14dB -3dB -27dB .. -68dB
{2, 1, 2, 2}, // 30 .. -24dB -19dB -3dB -21dB .. -67dB
{2, 0, 2, 3}, // 31 .. -24dB -24dB -3dB -15dB .. -66dB
{1, 0, 0, 6}, // 32 .. -30dB -24dB -8dB -3dB .. -65dB
{2, 1, 1, 3}, // 33 .. -24dB -19dB -6dB -15dB .. -64dB
{0, 3, 1, 3}, // 34 .. -33dB -9dB -6dB -15dB .. -63dB
{2, 3, 0, 2}, // 35 .. -24dB -9dB -8dB -21dB .. -62dB
{2, 1, 2, 3}, // 36 .. -24dB -19dB -3dB -15dB .. -61dB
{2, 3, 1, 2}, // 37 .. -24dB -9dB -6dB -21dB .. -60dB
{2, 2, 3, 2}, // 38 .. -24dB -14dB 0dB -21dB .. -59dB
{2, 1, 1, 4}, // 39 .. -24dB -19dB -6dB -9dB .. -58dB
{2, 4, 1, 2}, // 40 .. -24dB -6dB -6dB -21dB .. -57dB
{1, 2, 2, 4}, // 41 .. -30dB -14dB -3dB -9dB .. -56dB
{2, 1, 1, 5}, // 42 .. -24dB -19dB -6dB -6dB .. -55dB
{2, 3, 3, 2}, // 43 .. -24dB -9dB 0dB -21dB .. -54dB
{1, 3, 0, 5}, // 44 .. -30dB -9dB -8dB -6dB .. -53dB
{1, 5, 2, 3}, // 45 .. -30dB -4dB -3dB -15dB .. -52dB
{1, 3, 1, 5}, // 46 .. -30dB -9dB -6dB -6dB .. -51dB
{0, 2, 2, 7}, // 47 .. -33dB -14dB -3dB 0dB .. -50dB
{2, 1, 1, 7}, // 48 .. -24dB -19dB -6dB 0dB .. -49dB
{0, 4, 2, 5}, // 49 .. -33dB -6dB -3dB -6dB .. -48dB
{1, 2, 3, 6}, // 50 .. -30dB -14dB 0dB -3dB .. -47dB
{1, 5, 1, 5}, // 51 .. -30dB -4dB -6dB -6dB .. -46dB
{3, 0, 3, 2}, // 52 .. 0dB -24dB 0dB -21dB .. -45dB
{3, 2, 2, 1}, // 53 .. 0dB -14dB -3dB -27dB .. -44dB
{2, 5, 1, 4}, // 54 .. -24dB -4dB -6dB -9dB .. -43dB
{1, 4, 2, 6}, // 55 .. -30dB -6dB -3dB -3dB .. -42dB
{3, 0, 0, 4}, // 56 .. 0dB -24dB -8dB -9dB .. -41dB
{0, 5, 3, 6}, // 57 .. -33dB -4dB 0dB -3dB .. -40dB
{2, 4, 2, 5}, // 58 .. -24dB -6dB -3dB -6dB .. -39dB
{3, 0, 0, 5}, // 59 .. 0dB -24dB -8dB -6dB .. -38dB
{0, 5, 3, 7}, // 60 .. -33dB -4dB 0dB 0dB .. -37dB
{2, 3, 3, 6}, // 61 .. -24dB -9dB 0dB -3dB .. -36dB
{3, 4, 0, 2}, // 62 .. 0dB -6dB -8dB -21dB .. -35dB
{3, 1, 1, 4}, // 63 .. 0dB -19dB -6dB -9dB .. -34dB
{3, 0, 3, 4}, // 64 .. 0dB -24dB 0dB -9dB .. -33dB
{3, 3, 0, 3}, // 65 .. 0dB -9dB -8dB -15dB .. -32dB
{3, 1, 1, 5}, // 66 .. 0dB -19dB -6dB -6dB .. -31dB
{3, 0, 2, 6}, // 67 .. 0dB -24dB -3dB -3dB .. -30dB
{3, 2, 3, 3}, // 68 .. 0dB -14dB 0dB -15dB .. -29dB
{3, 2, 0, 5}, // 69 .. 0dB -14dB -8dB -6dB .. -28dB
{3, 4, 1, 3}, // 70 .. 0dB -6dB -6dB -15dB .. -27dB
{3, 2, 2, 4}, // 71 .. 0dB -14dB -3dB -9dB .. -26dB
{3, 1, 2, 6}, // 72 .. 0dB -19dB -3dB -3dB .. -25dB
{3, 3, 1, 4}, // 73 .. 0dB -9dB -6dB -9dB .. -24dB
{3, 2, 1, 6}, // 74 .. 0dB -14dB -6dB -3dB .. -23dB
{3, 5, 2, 3}, // 75 .. 0dB -4dB -3dB -15dB .. -22dB
{3, 4, 1, 4}, // 76 .. 0dB -6dB -6dB -9dB .. -21dB
{3, 4, 0, 5}, // 77 .. 0dB -6dB -8dB -6dB .. -20dB
{3, 5, 1, 4}, // 78 .. 0dB -4dB -6dB -9dB .. -19dB
{3, 3, 3, 4}, // 79 .. 0dB -9dB 0dB -9dB .. -18dB
{3, 2, 3, 6}, // 80 .. 0dB -14dB 0dB -3dB .. -17dB original
{3, 5, 1, 5}, // 81 .. 0dB -4dB -6dB -6dB .. -16dB
{3, 3, 1, 7}, // 82 .. 0dB -9dB -6dB 0dB .. -15dB
{3, 2, 3, 7}, // 83 .. 0dB -14dB 0dB 0dB .. -14dB
{3, 5, 1, 6}, // 84 .. 0dB -4dB -6dB -3dB .. -13dB
{3, 4, 2, 6}, // 85 .. 0dB -6dB -3dB -3dB .. -12dB
{3, 5, 2, 6}, // 86 .. 0dB -4dB -3dB -3dB .. -10dB
{3, 4, 3, 6}, // 87 .. 0dB -6dB 0dB -3dB .. -9dB
{3, 5, 2, 7}, // 88 .. 0dB -4dB -3dB 0dB .. -7dB
{3, 4, 3, 7}, // 89 .. 0dB -6dB 0dB 0dB .. -6dB
{3, 5, 3, 7}, // 90 .. 0dB -4dB 0dB 0dB .. -4dB
};
const unsigned int original_index = 80;

366
utils/main.cpp Normal file
View File

@ -0,0 +1,366 @@
#include <vcl.h>
#include <stdint.h>
#include <stdio.h>
#include <vector>
#pragma hdrstop
// ************************************************************************
// create a front end gain table for the firmware
// <9:8> = LNA Gain Short
// 3 = 0dB < original value
// 2 = -11dB
// 1 = -16dB
// 0 = -19dB
//
// <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 __fastcall create_gain_table(String filename)
{
String s;
std::vector <t_gain_table> gain_table;
// 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];
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 = 5; // 5
const uint8_t mixer_max = 3; // 3
const uint8_t pga_max = 7; // 7
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 QS original index
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;
}
const int save_handle = FileCreate(filename);
if (save_handle <= 0)
return;
s = "\r\n";
FileWrite(save_handle, s.c_str(), s.Length());
s = "\tconst t_am_fix_gain_table am_fix_gain_table[] =\r\n";
FileWrite(save_handle, s.c_str(), s.Length());
s = "\t{\r\n";
FileWrite(save_handle, s.c_str(), s.Length());
s = "\t\t{.lna_short = 3, .lna = 2, .mixer = 3, .pga = 6}, // 0 0dB -14dB 0dB -3dB .. -17dB original\r\n";
FileWrite(save_handle, s.c_str(), s.Length());
s = "\r\n";
FileWrite(save_handle, s.c_str(), s.Length());
for (unsigned int i = 0; i < gain_table.size(); i++)
{
const t_gain_table entry = gain_table[i];
// {0, 0, 0, 0}, // 00 -19dB -24dB -8dB -33dB .. -84dB
s.printf("\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)
s += " original";
s += "\r\n";
FileWrite(save_handle, s.c_str(), s.Length());
}
s = "\t};\r\n";
FileWrite(save_handle, s.c_str(), s.Length());
s.printf("\r\n\tconst unsigned int original_index = %u;\r\n", 1 + original_index);
FileWrite(save_handle, s.c_str(), s.Length());
FileClose(save_handle);
}
// ************************************************************************
// "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
void __fastcall rotate_font(String filename1, String filename2)
{
std::vector <uint8_t> data;
// ****************************
// load the file
const int load_handle = FileOpen(filename1, fmOpenRead | fmShareDenyNone);
if (load_handle <= 0)
return;
const int file_size = FileSeek(load_handle, 0, 2);
FileSeek(load_handle, 0, 0);
if (file_size <= 0)
{
FileClose(load_handle);
return;
}
data.resize(file_size);
const int bytes_loaded = FileRead(load_handle, &data[0], file_size);
FileClose(load_handle);
if (bytes_loaded != (int)data.size())
return;
// ***************************
// rotate the font 90-deg clockwise
for (unsigned int i = 0; i <= (data.size() - 8); i += 8)
{
uint8_t c1[8];
uint8_t c2[8];
memcpy(c1, &data[i], 8);
memset(c2, 0, 8);
for (unsigned int k = 0; k < 8; k++)
{
uint8_t b = c1[k];
for (unsigned int m = 0; m < 8; m++)
{
if (b & 0x80)
c2[m] |= 1u << k;
b <<= 1;
}
}
memcpy(&data[i], c2, 8);
}
// ***************************
// save file
String s;
const int save_handle = FileCreate(filename2);
if (save_handle <= 0)
return;
s.printf("const uint8_t gFontSmall[95][7] =\r\n");
FileWrite(save_handle, s.c_str(), s.Length());
s = "{\r\n";
FileWrite(save_handle, s.c_str(), s.Length());
for (unsigned int i = 0; i < data.size(); )
{
s = "";
// for (unsigned int k = 0; k < 8 && i < data.size(); k++)
for (unsigned int k = 0; k < 7 && i < data.size(); k++)
{
String s2;
s2.printf("0x%02X", data[i++]);
if (k == 0)
s += "\t{";
// if (k < 7)
if (k < 6)
s += s2 + ", ";
else
s += s2 + "},\r\n";
}
i++;
FileWrite(save_handle, s.c_str(), s.Length());
}
s = "};\r\n";
FileWrite(save_handle, s.c_str(), s.Length());
FileClose(save_handle);
// ***************************
}
#pragma argsused
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_bold.bin", "uv-k5_small_bold.c");
return 0;
}

3
utils/misc.bpf Normal file
View File

@ -0,0 +1,3 @@
This file is used by the project manager only and should be treated like the project file
main

119
utils/misc.bpr Normal file
View File

@ -0,0 +1,119 @@
<?xml version='1.0' encoding='utf-8' ?>
<!-- C++Builder XML Project -->
<PROJECT>
<MACROS>
<VERSION value="BCB.06.00"/>
<PROJECT value="misc.exe"/>
<OBJFILES value="main.obj"/>
<RESFILES value="misc.res"/>
<IDLFILES value=""/>
<IDLGENFILES value=""/>
<DEFFILE value=""/>
<RESDEPEN value="$(RESFILES)"/>
<LIBFILES value=""/>
<LIBRARIES value=""/>
<SPARELIBS value=""/>
<PACKAGES value="vcl.bpi rtl.bpi dbrtl.bpi vcldb.bpi vclx.bpi bdertl.bpi dsnap.bpi cds.bpi
bcbsmp.bpi vclie.bpi xmlrtl.bpi inet.bpi inetdbbde.bpi inetdbxpress.bpi
nmfast.bpi webdsnap.bpi bcbie.bpi dclocx.bpi dbexpress.bpi dbxcds.bpi
indy.bpi bcb2kaxserver.bpi adortl.bpi vcldbx.bpi ibxpress.bpi bdecds.bpi
qrpt.bpi teeui.bpi teedb.bpi tee.bpi dss.bpi teeqr.bpi visualclx.bpi
visualdbclx.bpi dsnapcrba.bpi dsnapcon.bpi inetdb.bpi websnap.bpi
soaprtl.bpi"/>
<PATHCPP value=".;"/>
<PATHPAS value=".;"/>
<PATHRC value=".;"/>
<PATHASM value=".;"/>
<DEBUGLIBPATH value="$(BCB)\lib\debug"/>
<RELEASELIBPATH value="$(BCB)\lib\release"/>
<LINKER value="ilink32"/>
<USERDEFINES value="_DEBUG"/>
<SYSDEFINES value="NO_STRICT;_NO_VCL;_RTLDLL;USEPACKAGES"/>
<MAINSOURCE value="misc.bpf"/>
<INCLUDEPATH value="..\..\uv-k5-firmware\uv-k5-firmware-custom\misc;$(BCB)\include;$(BCB)\include\vcl"/>
<LIBPATH value="&quot;..\..\uv-k5-firmware\uv-k5-firmware-custom\misc&quot;;$(BCB)\lib\obj;$(BCB)\lib"/>
<WARNINGS value="-w-par"/>
<OTHERFILES value=""/>
</MACROS>
<OPTIONS>
<IDLCFLAGS value="-I..\..\uv-k5-firmware\uv-k5-firmware-custom\misc -I$(BCB)\include
-I$(BCB)\include\vcl -src_suffix cpp -D_DEBUG -boa"/>
<CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -tWC
-tWM -c"/>
<PFLAGS value="-$YD -$W -$O- -$A8 -v -JPHNE -M"/>
<RFLAGS value=""/>
<AFLAGS value="/mx /w2 /zd"/>
<LFLAGS value="-D&quot;&quot; -ap -Tpe -x -Gn -v"/>
<OTHERFILES value=""/>
</OPTIONS>
<LINKER>
<ALLOBJ value="c0x32.obj $(PACKAGES) $(OBJFILES)"/>
<ALLRES value="$(RESFILES)"/>
<ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cw32mti.lib"/>
<OTHERFILES value=""/>
</LINKER>
<FILELIST>
<FILE FILENAME="misc.res" FORMNAME="" UNITNAME="misc.res" CONTAINERID="ResTool" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="misc.bpf" FORMNAME="" UNITNAME="misc" CONTAINERID="BPF" DESIGNCLASS="" LOCALCOMMAND=""/>
<FILE FILENAME="main.cpp" FORMNAME="" UNITNAME="main" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
</FILELIST>
<BUILDTOOLS>
</BUILDTOOLS>
<IDEOPTIONS>
[Version Info]
IncludeVerInfo=1
AutoIncBuild=0
MajorVer=0
MinorVer=0
Release=1
Build=0
Debug=0
PreRelease=0
Special=0
Private=0
DLL=0
Locale=2057
CodePage=1252
[Version Info Keys]
CompanyName=
FileDescription=
FileVersion=0.0.1.0
InternalName=
LegalCopyright=
LegalTrademarks=
OriginalFilename=
ProductName=
ProductVersion=1.0.0.0
Comments=
[Excluded Packages]
c:\program files (x86)\borland\cbuilder6\Bin\dclite60.bpl=Borland Integrated Translation Environment
[Debugging]
DebugSourceDirs=$(BCB)\source\vcl
[Parameters]
RunParams=
Launcher=
UseLauncher=0
DebugCWD=
HostApplication=
RemoteHost=
RemotePath=
RemoteLauncher=
RemoteCWD=
RemoteDebug=0
[Compiler]
ShowInfoMsgs=0
LinkDebugVcl=0
LinkCGLIB=0
[CORBA]
AddServerUnit=1
AddClientUnit=1
PrecompiledHeaders=1
</IDEOPTIONS>
</PROJECT>

257
utils/misc.dsk Normal file
View File

@ -0,0 +1,257 @@
[Closed Files]
File_0=SourceModule,'C:\Radios\Quansheng_UV-K5\uv-k5-firmware\uv-k5-firmware-custom\misc\Unit1.cpp',0,1,1,1,1,0,0
File_1=SourceModule,'c:\program files (x86)\borland\cbuilder6\include\vcl\sysmac.H',0,1,32,9,50,0,0
File_2=SourceModule,'C:\Radios\Quansheng_UV-K5\k5prog\k5prog-win\SerialPort.cpp',0,1,396,16,415,0,0
File_3=SourceModule,'c:\program files (x86)\borland\cbuilder6\include\vcl\dstring.h',0,1,235,1,254,0,0
File_4=SourceModule,'c:\program files (x86)\borland\cbuilder6\include\vcl\CGAUGES.h',0,1,41,20,60,0,0
File_5=SourceModule,'c:\program files (x86)\borland\cbuilder6\include\winbase.h',0,1,799,17,818,0,0
File_6=SourceModule,'C:\Radios\Quansheng_UV-K5\k5prog\k5prog-win\CriticalSection.h',0,1,1,1,32,0,0
File_7=SourceModule,'C:\Radios\Quansheng_UV-K5\k5prog\k5prog-win\HighResolutionTick.h',0,1,35,1,44,0,0
File_8=SourceModule,'c:\program files (x86)\borland\cbuilder6\include\vcl\Forms.hpp',0,1,417,27,436,0,0
File_9=SourceModule,'C:\Radios\Quansheng_UV-K5\k5prog\mine\CriticalSection.h',0,1,72,7,91,0,0
[Modules]
Module0=C:\Radios\Quansheng_UV-K5\uv-k5-firmware\uv-k5-firmware-custom\misc\main.cpp
Count=1
EditWindowCount=1
[C:\Radios\Quansheng_UV-K5\uv-k5-firmware\uv-k5-firmware-custom\misc\main.cpp]
ModuleType=SourceModule
FormState=0
FormOnTop=0
[C:\Radios\Quansheng_UV-K5\uv-k5-firmware\uv-k5-firmware-custom\misc\misc.bpr]
FormState=0
FormOnTop=0
[C:\Radios\Quansheng_UV-K5\uv-k5-firmware\uv-k5-firmware-custom\misc\ProjectGroup1.bpg]
FormState=0
FormOnTop=0
[EditWindow0]
ViewCount=1
CurrentView=0
View0=0
CodeExplorer=CodeExplorer@EditWindow0
MessageView=MessageView@EditWindow0
ClassHierarchy=ClassHierarchy@EditWindow0
Create=1
Visible=1
State=0
Left=319
Top=140
Width=1305
Height=872
MaxLeft=-1
MaxTop=-1
ClientWidth=1289
ClientHeight=833
LeftPanelSize=0
LeftPanelClients=CodeExplorer@EditWindow0
LeftPanelData=00000400010000000C000000436F64654578706C6F726572000000000000000000000000000000000001000000000000000000000000FFFFFFFF
RightPanelSize=0
BottomPanelSize=0
BottomPanelClients=MessageView@EditWindow0
BottomPanelData=00000400010000000B0000004D6573736167655669657700000000000000000000000000000000000100000000000000000B0000004D65737361676556696577FFFFFFFF
[View0]
Module=C:\Radios\Quansheng_UV-K5\uv-k5-firmware\uv-k5-firmware-custom\misc\main.cpp
CursorX=26
CursorY=366
TopLine=366
LeftCol=1
[Watches]
Count=0
[Breakpoints]
Count=0
[AddressBreakpoints]
Count=0
[Main Window]
Create=1
Visible=1
State=2
Left=0
Top=0
Width=1920
Height=123
MaxLeft=-1
MaxTop=-1
MaxWidth=1936
MaxHeight=123
ClientWidth=1920
ClientHeight=84
[ProjectManager]
Create=1
Visible=0
State=0
Left=369
Top=372
Width=446
Height=318
MaxLeft=-1
MaxTop=-1
ClientWidth=430
ClientHeight=279
TBDockHeight=318
LRDockWidth=446
Dockable=1
[CPUWindow]
Create=1
Visible=0
State=0
Left=693
Top=363
Width=533
Height=353
MaxLeft=-1
MaxTop=-1
ClientWidth=517
ClientHeight=314
DumpPane=79
DisassemblyPane=187
RegisterPane=231
FlagPane=64
[WatchWindow]
Create=1
Visible=0
State=0
Left=714
Top=971
Width=897
Height=168
MaxLeft=-1
MaxTop=-1
ClientWidth=881
ClientHeight=129
TBDockHeight=129
LRDockWidth=421
Dockable=1
[AlignmentPalette]
Create=1
Visible=0
State=0
Left=200
Top=125
Width=156
Height=89
MaxLeft=-1
MaxTop=-1
ClientWidth=150
ClientHeight=60
[PropertyInspector]
Create=1
Visible=1
State=0
Left=0
Top=143
Width=309
Height=892
MaxLeft=-1
MaxTop=-1
ClientWidth=293
ClientHeight=853
TBDockHeight=908
LRDockWidth=309
Dockable=1
SplitPos=135
ArrangeBy=Name
SelectedItem=
ExpandedItems=Constraints
HiddenCategories=
[ObjectTree]
Create=1
Visible=0
State=0
Left=0
Top=123
Width=190
Height=370
MaxLeft=-1
MaxTop=-1
ClientWidth=174
ClientHeight=331
TBDockHeight=370
LRDockWidth=190
Dockable=1
[CodeguardLog]
Create=1
Visible=0
State=0
Left=191
Top=108
Width=448
Height=190
MaxLeft=-1
MaxTop=-1
ClientWidth=432
ClientHeight=151
TBDockHeight=190
LRDockWidth=448
Dockable=1
[ClassHierarchy@EditWindow0]
Create=1
Visible=0
State=0
Left=218
Top=113
Width=403
Height=284
MaxLeft=-1
MaxTop=-1
ClientWidth=387
ClientHeight=245
TBDockHeight=284
LRDockWidth=403
Dockable=1
TreeWidth=121
Col1Width=120
Col2Width=120
[CodeExplorer@EditWindow0]
Create=1
Visible=0
State=0
Left=0
Top=12
Width=170
Height=626
MaxLeft=-1
MaxTop=-1
ClientWidth=170
ClientHeight=626
TBDockHeight=388
LRDockWidth=170
Dockable=1
ClassViewDisplayMode=0
[MessageView@EditWindow0]
Create=1
Visible=0
State=0
Left=12
Top=0
Width=1277
Height=85
MaxLeft=-1
MaxTop=-1
ClientWidth=1277
ClientHeight=85
TBDockHeight=85
LRDockWidth=443
Dockable=1
[DockHosts]
DockHostCount=0

BIN
utils/misc.res Normal file

Binary file not shown.

BIN
utils/uv-k5_small.fon Normal file

Binary file not shown.

BIN
utils/uv-k5_small_bold.fon Normal file

Binary file not shown.