0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-29 23:01:26 +03:00

Simplified the frequency band table(s)

This commit is contained in:
OneOfEleven 2023-10-02 14:13:27 +01:00
parent 3ac330ddee
commit 9ac3525683
8 changed files with 72 additions and 108 deletions

View File

@ -134,9 +134,9 @@ static void AIRCOPY_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
NUMBER_Get(gInputBox, &Frequency); NUMBER_Get(gInputBox, &Frequency);
for (i = 0; i < 7; i++) for (i = 0; i < ARRAY_SIZE(frequencyBandTable); i++)
{ {
if (Frequency >= LowerLimitFrequencyBandTable[i] && Frequency <= UpperLimitFrequencyBandTable[i]) if (Frequency >= frequencyBandTable[i].lower && Frequency < frequencyBandTable[i].upper)
{ {
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key; gAnotherVoiceID = (VOICE_ID_t)Key;

View File

@ -613,7 +613,7 @@ uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step)
if (pInfo->StepFrequency == 833) if (pInfo->StepFrequency == 833)
{ {
const uint32_t Lower = LowerLimitFrequencyBandTable[pInfo->Band]; const uint32_t Lower = frequencyBandTable[pInfo->Band].lower;
const uint32_t Delta = Frequency - Lower; const uint32_t Delta = Frequency - Lower;
uint32_t Base = (Delta / 2500) * 2500; uint32_t Base = (Delta / 2500) * 2500;
const uint32_t Index = ((Delta - Base) % 2500) / 833; const uint32_t Index = ((Delta - Base) % 2500) / 833;
@ -624,11 +624,11 @@ uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step)
Frequency = Lower + Base + (Index * 833); Frequency = Lower + Base + (Index * 833);
} }
if (Frequency > UpperLimitFrequencyBandTable[pInfo->Band]) if (Frequency >= frequencyBandTable[pInfo->Band].upper)
Frequency = LowerLimitFrequencyBandTable[pInfo->Band]; Frequency = frequencyBandTable[pInfo->Band].lower;
else else
if (Frequency < LowerLimitFrequencyBandTable[pInfo->Band]) if (Frequency < frequencyBandTable[pInfo->Band].lower)
Frequency = FREQUENCY_FloorToStep(UpperLimitFrequencyBandTable[pInfo->Band], pInfo->StepFrequency, LowerLimitFrequencyBandTable[pInfo->Band]); Frequency = FREQUENCY_FloorToStep(frequencyBandTable[pInfo->Band].upper, pInfo->StepFrequency, frequencyBandTable[pInfo->Band].lower);
return Frequency; return Frequency;
} }

View File

@ -352,20 +352,20 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
NUMBER_Get(gInputBox, &Frequency); NUMBER_Get(gInputBox, &Frequency);
// clamp the frequency entered to some valid value // clamp the frequency entered to some valid value
if (Frequency < LowerLimitFrequencyBandTable[0]) if (Frequency < frequencyBandTable[0].lower)
{ {
Frequency = LowerLimitFrequencyBandTable[0]; Frequency = frequencyBandTable[0].lower;
} }
else else
if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz) if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
{ {
const uint32_t center = (bx_stop1_Hz + bx_start2_Hz) / 2; const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2;
Frequency = (Frequency < center) ? bx_stop1_Hz : bx_start2_Hz; Frequency = (Frequency < center) ? BX4819_band1.upper : BX4819_band2.lower;
} }
else else
if (Frequency > UpperLimitFrequencyBandTable[6]) if (Frequency > frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper)
{ {
Frequency = UpperLimitFrequencyBandTable[6]; Frequency = frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper;
} }
{ {
@ -389,12 +389,12 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
// Frequency += 75; // is this meant to be rounding ? // Frequency += 75; // is this meant to be rounding ?
Frequency += gTxVfo->StepFrequency / 2; // no idea, but this is Frequency += gTxVfo->StepFrequency / 2; // no idea, but this is
Frequency = FREQUENCY_FloorToStep(Frequency, gTxVfo->StepFrequency, LowerLimitFrequencyBandTable[gTxVfo->Band]); Frequency = FREQUENCY_FloorToStep(Frequency, gTxVfo->StepFrequency, frequencyBandTable[gTxVfo->Band].lower);
if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz) if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
{ // clamp the frequency to the limit { // clamp the frequency to the limit
const uint32_t center = (bx_stop1_Hz + bx_start2_Hz) / 2; const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2;
Frequency = (Frequency < center) ? bx_stop1_Hz - gTxVfo->StepFrequency : bx_start2_Hz; Frequency = (Frequency < center) ? BX4819_band1.upper - gTxVfo->StepFrequency : BX4819_band2.lower;
} }
gTxVfo->freq_config_RX.Frequency = Frequency; gTxVfo->freq_config_RX.Frequency = Frequency;

Binary file not shown.

Binary file not shown.

View File

@ -19,52 +19,27 @@
#include "settings.h" #include "settings.h"
// the BK4819 has 2 bands it covers, 18MHz ~ 630MHz and 760MHz ~ 1300MHz // the BK4819 has 2 bands it covers, 18MHz ~ 630MHz and 760MHz ~ 1300MHz
const freq_band_table_t BX4819_band1 = { 1800000, 63000000};
const freq_band_table_t BX4819_band2 = {84000000, 130000000};
const uint32_t bx_start1_Hz = 1800000; // 18MHz const freq_band_table_t frequencyBandTable[7] =
const uint32_t bx_stop1_Hz = 63000000; // 630MHz
//const uint32_t bx_start2_Hz = 76000000; // 760MHz // my one radio the BK chip managed to lock down to this frequency
const uint32_t bx_start2_Hz = 84000000; // 840MHz // but best to go with datasheet specification really
const uint32_t bx_stop2_Hz = 130000000; // 1300MHz
const uint32_t LowerLimitFrequencyBandTable[7] =
{ {
#ifndef ENABLE_WIDE_RX #ifndef ENABLE_WIDE_RX
5000000, { 5000000, 7600000},
{10800000, 13600000},
{13600000, 17400000},
{17400000, 35000000},
{35000000, 40000000},
{40000000, 47000000},
{47000000, 60000000}
#else #else
1800000, { 1800000, 10800000},
#endif {10800000, 13600000},
10800000, {13600000, 17400000},
13600000, {17400000, 35000000},
17400000, {35000000, 40000000},
35000000, {40000000, 47000000},
40000000, {47000000, 130000000}
47000000
};
const uint32_t MiddleFrequencyBandTable[7] =
{
6500000,
12200000,
15000000,
26000000,
37000000,
43500000,
55000000
};
const uint32_t UpperLimitFrequencyBandTable[7] =
{
7600000,
13599990,
17399990,
34999990,
39999990,
46999990,
#ifndef ENABLE_WIDE_RX
60000000
#else
130000000
#endif #endif
}; };
@ -111,10 +86,12 @@ const uint32_t UpperLimitFrequencyBandTable[7] =
FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency) FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency)
{ {
int band; int band;
for (band = BAND7_470MHz; band >= BAND1_50MHz; band--) for (band = ARRAY_SIZE(frequencyBandTable) - 1; band >= 0; band--)
if (Frequency >= LowerLimitFrequencyBandTable[band]) if (Frequency >= frequencyBandTable[band].lower)
// if (Frequency < frequencyBandTable[band].upper)
return band; return band;
return BAND1_50MHz; return BAND1_50MHz;
// return BAND_NONE;
} }
uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, int32_t LowerLimit, int32_t Middle, int32_t UpperLimit, int32_t Frequency) uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, int32_t LowerLimit, int32_t Middle, int32_t UpperLimit, int32_t Frequency)
@ -161,10 +138,10 @@ int TX_freq_check(const uint32_t Frequency)
{ // return '0' if TX frequency is allowed { // return '0' if TX frequency is allowed
// otherwise return '-1' // otherwise return '-1'
if (Frequency < LowerLimitFrequencyBandTable[0] || Frequency > UpperLimitFrequencyBandTable[6]) if (Frequency < frequencyBandTable[0].lower || Frequency > frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper)
return -1; // not allowed outside this range return -1; // not allowed outside this range
if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz) if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
return -1; // BX chip does not work in this range return -1; // BX chip does not work in this range
switch (gSetting_F_LOCK) switch (gSetting_F_LOCK)
@ -229,9 +206,10 @@ int RX_freq_check(const uint32_t Frequency)
{ // return '0' if RX frequency is allowed { // return '0' if RX frequency is allowed
// otherwise return '-1' // otherwise return '-1'
if (Frequency < LowerLimitFrequencyBandTable[0] || Frequency > UpperLimitFrequencyBandTable[6]) if (Frequency < frequencyBandTable[0].lower || Frequency > frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper)
return -1; return -1;
if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz)
if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
return -1; return -1;
return 0; // OK frequency return 0; // OK frequency

View File

@ -21,15 +21,18 @@
//#include "radio.h" //#include "radio.h"
extern const uint32_t bx_start1_Hz; typedef struct {
extern const uint32_t bx_stop1_Hz; const uint32_t lower;
const uint32_t upper;
} freq_band_table_t;
extern const uint32_t bx_start2_Hz; extern const freq_band_table_t BX4819_band1;
extern const uint32_t bx_stop2_Hz; extern const freq_band_table_t BX4819_band2;
enum FREQUENCY_Band_t extern const freq_band_table_t frequencyBandTable[7];
{
BAND1_NONE = -1, enum FREQUENCY_Band_t {
BAND_NONE = -1,
BAND1_50MHz = 0, BAND1_50MHz = 0,
BAND2_108MHz, BAND2_108MHz,
BAND3_136MHz, BAND3_136MHz,
@ -63,10 +66,6 @@ typedef enum FREQUENCY_Band_t FREQUENCY_Band_t;
#endif #endif
typedef enum STEP_Setting_t STEP_Setting_t; typedef enum STEP_Setting_t STEP_Setting_t;
extern const uint32_t LowerLimitFrequencyBandTable[7];
extern const uint32_t MiddleFrequencyBandTable[7];
extern const uint32_t UpperLimitFrequencyBandTable[7];
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
extern const uint32_t NoaaFrequencyTable[10]; extern const uint32_t NoaaFrequencyTable[10];
#endif #endif
@ -77,7 +76,6 @@ FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency);
uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, int32_t LowerLimit, int32_t Middle, int32_t UpperLimit, int32_t Frequency); uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, int32_t LowerLimit, int32_t Middle, int32_t UpperLimit, int32_t Frequency);
uint32_t FREQUENCY_FloorToStep(uint32_t Upper, uint32_t Step, uint32_t Lower); uint32_t FREQUENCY_FloorToStep(uint32_t Upper, uint32_t Step, uint32_t Lower);
//int TX_freq_check(VFO_Info_t *pInfo);
int TX_freq_check(const uint32_t Frequency); int TX_freq_check(const uint32_t Frequency);
int RX_freq_check(const uint32_t Frequency); int RX_freq_check(const uint32_t Frequency);

42
radio.c
View File

@ -210,7 +210,7 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure
Index = Channel - FREQ_CHANNEL_FIRST; Index = Channel - FREQ_CHANNEL_FIRST;
RADIO_InitInfo(pRadio, Channel, LowerLimitFrequencyBandTable[Index]); RADIO_InitInfo(pRadio, Channel, frequencyBandTable[Index].lower);
return; return;
} }
@ -369,14 +369,14 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure
Band = FREQUENCY_GetBand(Frequency); Band = FREQUENCY_GetBand(Frequency);
#endif #endif
if (Frequency < LowerLimitFrequencyBandTable[Band]) if (Frequency < frequencyBandTable[Band].lower)
Frequency = LowerLimitFrequencyBandTable[Band]; Frequency = frequencyBandTable[Band].lower;
else else
if (Frequency > UpperLimitFrequencyBandTable[Band]) if (Frequency > frequencyBandTable[Band + 1].upper)
Frequency = UpperLimitFrequencyBandTable[Band]; Frequency = frequencyBandTable[Band + 1].upper;
else else
if (Channel >= FREQ_CHANNEL_FIRST) if (Channel >= FREQ_CHANNEL_FIRST)
Frequency = FREQUENCY_FloorToStep(Frequency, gEeprom.VfoInfo[VFO].StepFrequency, LowerLimitFrequencyBandTable[Band]); Frequency = FREQUENCY_FloorToStep(Frequency, gEeprom.VfoInfo[VFO].StepFrequency, frequencyBandTable[Band].lower);
pRadio->freq_config_RX.Frequency = Frequency; pRadio->freq_config_RX.Frequency = Frequency;
@ -485,9 +485,9 @@ void RADIO_ConfigureSquelchAndOutputPower(VFO_Info_t *pInfo)
Txp[0], Txp[0],
Txp[1], Txp[1],
Txp[2], Txp[2],
LowerLimitFrequencyBandTable[Band], frequencyBandTable[Band].lower,
MiddleFrequencyBandTable[Band], (frequencyBandTable[Band].lower + frequencyBandTable[Band].upper) / 2,
UpperLimitFrequencyBandTable[Band], frequencyBandTable[Band].upper,
pInfo->pTX->Frequency); pInfo->pTX->Frequency);
} }
@ -507,20 +507,11 @@ void RADIO_ApplyOffset(VFO_Info_t *pInfo)
break; break;
} }
#if 0 if (Frequency < frequencyBandTable[0].lower)
// limit to 50MHz to 600MHz Frequency = frequencyBandTable[0].lower;
if (Frequency < 5000000)
Frequency = 5000000;
else else
if (Frequency > 60000000) if (Frequency > frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper)
Frequency = 60000000; Frequency = frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper;
#else
if (Frequency < LowerLimitFrequencyBandTable[0])
Frequency = LowerLimitFrequencyBandTable[0];
else
if (Frequency > UpperLimitFrequencyBandTable[ARRAY_SIZE(UpperLimitFrequencyBandTable) - 1])
Frequency = UpperLimitFrequencyBandTable[ARRAY_SIZE(UpperLimitFrequencyBandTable) - 1];
#endif
pInfo->freq_config_TX.Frequency = Frequency; pInfo->freq_config_TX.Frequency = Frequency;
} }
@ -807,7 +798,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
void RADIO_SetTxParameters(void) void RADIO_SetTxParameters(void)
{ {
BK4819_FilterBandwidth_t Bandwidth; BK4819_FilterBandwidth_t Bandwidth = gCurrentVfo->CHANNEL_BANDWIDTH;
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
@ -815,7 +806,6 @@ void RADIO_SetTxParameters(void)
BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2, false); BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2, false);
Bandwidth = gCurrentVfo->CHANNEL_BANDWIDTH;
switch (Bandwidth) switch (Bandwidth)
{ {
default: default:
@ -865,9 +855,7 @@ void RADIO_SetTxParameters(void)
case CODE_TYPE_DIGITAL: case CODE_TYPE_DIGITAL:
case CODE_TYPE_REVERSE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL:
BK4819_SetCDCSSCodeWord( BK4819_SetCDCSSCodeWord(DCS_GetGolayCodeWord(gCurrentVfo->pTX->CodeType, gCurrentVfo->pTX->Code));
DCS_GetGolayCodeWord(gCurrentVfo->pTX->CodeType, gCurrentVfo->pTX->Code)
);
break; break;
} }
} }