0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 06:11:24 +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);
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
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)
{
const uint32_t Lower = LowerLimitFrequencyBandTable[pInfo->Band];
const uint32_t Lower = frequencyBandTable[pInfo->Band].lower;
const uint32_t Delta = Frequency - Lower;
uint32_t Base = (Delta / 2500) * 2500;
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);
}
if (Frequency > UpperLimitFrequencyBandTable[pInfo->Band])
Frequency = LowerLimitFrequencyBandTable[pInfo->Band];
if (Frequency >= frequencyBandTable[pInfo->Band].upper)
Frequency = frequencyBandTable[pInfo->Band].lower;
else
if (Frequency < LowerLimitFrequencyBandTable[pInfo->Band])
Frequency = FREQUENCY_FloorToStep(UpperLimitFrequencyBandTable[pInfo->Band], pInfo->StepFrequency, LowerLimitFrequencyBandTable[pInfo->Band]);
if (Frequency < frequencyBandTable[pInfo->Band].lower)
Frequency = FREQUENCY_FloorToStep(frequencyBandTable[pInfo->Band].upper, pInfo->StepFrequency, frequencyBandTable[pInfo->Band].lower);
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);
// 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
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;
Frequency = (Frequency < center) ? bx_stop1_Hz : bx_start2_Hz;
const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2;
Frequency = (Frequency < center) ? BX4819_band1.upper : BX4819_band2.lower;
}
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 += 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
const uint32_t center = (bx_stop1_Hz + bx_start2_Hz) / 2;
Frequency = (Frequency < center) ? bx_stop1_Hz - gTxVfo->StepFrequency : bx_start2_Hz;
const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2;
Frequency = (Frequency < center) ? BX4819_band1.upper - gTxVfo->StepFrequency : BX4819_band2.lower;
}
gTxVfo->freq_config_RX.Frequency = Frequency;

Binary file not shown.

Binary file not shown.

View File

@ -19,52 +19,27 @@
#include "settings.h"
// 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 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] =
const freq_band_table_t frequencyBandTable[7] =
{
#ifndef ENABLE_WIDE_RX
5000000,
{ 5000000, 7600000},
{10800000, 13600000},
{13600000, 17400000},
{17400000, 35000000},
{35000000, 40000000},
{40000000, 47000000},
{47000000, 60000000}
#else
1800000,
#endif
10800000,
13600000,
17400000,
35000000,
40000000,
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
{ 1800000, 10800000},
{10800000, 13600000},
{13600000, 17400000},
{17400000, 35000000},
{35000000, 40000000},
{40000000, 47000000},
{47000000, 130000000}
#endif
};
@ -111,10 +86,12 @@ const uint32_t UpperLimitFrequencyBandTable[7] =
FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency)
{
int band;
for (band = BAND7_470MHz; band >= BAND1_50MHz; band--)
if (Frequency >= LowerLimitFrequencyBandTable[band])
for (band = ARRAY_SIZE(frequencyBandTable) - 1; band >= 0; band--)
if (Frequency >= frequencyBandTable[band].lower)
// if (Frequency < frequencyBandTable[band].upper)
return band;
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)
@ -161,10 +138,10 @@ int TX_freq_check(const uint32_t Frequency)
{ // return '0' if TX frequency is allowed
// 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
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
switch (gSetting_F_LOCK)
@ -229,9 +206,10 @@ int RX_freq_check(const uint32_t Frequency)
{ // return '0' if RX frequency is allowed
// otherwise return '-1'
if (Frequency < LowerLimitFrequencyBandTable[0] || Frequency > UpperLimitFrequencyBandTable[6])
if (Frequency < frequencyBandTable[0].lower || Frequency > frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper)
return -1;
if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz)
if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
return -1;
return 0; // OK frequency

View File

@ -21,15 +21,18 @@
//#include "radio.h"
extern const uint32_t bx_start1_Hz;
extern const uint32_t bx_stop1_Hz;
typedef struct {
const uint32_t lower;
const uint32_t upper;
} freq_band_table_t;
extern const uint32_t bx_start2_Hz;
extern const uint32_t bx_stop2_Hz;
extern const freq_band_table_t BX4819_band1;
extern const freq_band_table_t BX4819_band2;
enum FREQUENCY_Band_t
{
BAND1_NONE = -1,
extern const freq_band_table_t frequencyBandTable[7];
enum FREQUENCY_Band_t {
BAND_NONE = -1,
BAND1_50MHz = 0,
BAND2_108MHz,
BAND3_136MHz,
@ -63,21 +66,16 @@ typedef enum FREQUENCY_Band_t FREQUENCY_Band_t;
#endif
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
extern const uint32_t NoaaFrequencyTable[10];
extern const uint32_t NoaaFrequencyTable[10];
#endif
extern const uint16_t StepFrequencyTable[7];
extern const uint16_t StepFrequencyTable[7];
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);
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 RX_freq_check(const uint32_t Frequency);

44
radio.c
View File

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