Refactor stepFruencyTable & drop ARRAY_SIZE for frequencyBandTable
This commit is contained in:
committed by
Krzysiek Egzmont
parent
335c2ec9cd
commit
82ddbcd375
@@ -133,7 +133,7 @@ static void AIRCOPY_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
|||||||
gInputBoxIndex = 0;
|
gInputBoxIndex = 0;
|
||||||
Frequency = StrToUL(INPUTBOX_GetAscii()) * 100;
|
Frequency = StrToUL(INPUTBOX_GetAscii()) * 100;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(frequencyBandTable); i++)
|
for (i = 0; i < BAND_N_ELEM; i++)
|
||||||
{
|
{
|
||||||
if (Frequency >= frequencyBandTable[i].lower && Frequency < frequencyBandTable[i].upper)
|
if (Frequency >= frequencyBandTable[i].lower && Frequency < frequencyBandTable[i].upper)
|
||||||
{
|
{
|
||||||
|
@@ -152,7 +152,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
|
|||||||
if (gTxVfo->Band == BAND5_350MHz && !gSetting_350EN) {
|
if (gTxVfo->Band == BAND5_350MHz && !gSetting_350EN) {
|
||||||
// skip if not enabled
|
// skip if not enabled
|
||||||
gTxVfo->Band += 1;
|
gTxVfo->Band += 1;
|
||||||
} else if (gTxVfo->Band >= BAND_LAST_ELEMENT){
|
} else if (gTxVfo->Band >= BAND_N_ELEM){
|
||||||
// go arround if overflowed
|
// go arround if overflowed
|
||||||
gTxVfo->Band = BAND1_50MHz;
|
gTxVfo->Band = BAND1_50MHz;
|
||||||
}
|
}
|
||||||
@@ -380,9 +380,9 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
|||||||
Frequency = (Frequency < center) ? BX4819_band1.upper : BX4819_band2.lower;
|
Frequency = (Frequency < center) ? BX4819_band1.upper : BX4819_band2.lower;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (Frequency > frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper)
|
if (Frequency > frequencyBandTable[BAND_N_ELEM - 1].upper)
|
||||||
{
|
{
|
||||||
Frequency = frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper;
|
Frequency = frequencyBandTable[BAND_N_ELEM - 1].upper;
|
||||||
}
|
}
|
||||||
|
|
||||||
const FREQUENCY_Band_t band = FREQUENCY_GetBand(Frequency);
|
const FREQUENCY_Band_t band = FREQUENCY_GetBand(Frequency);
|
||||||
|
@@ -40,7 +40,6 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "ui/inputbox.h"
|
#include "ui/inputbox.h"
|
||||||
#include "ui/menu.h"
|
#include "ui/menu.h"
|
||||||
#include "ui/menu.h"
|
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
#ifndef ARRAY_SIZE
|
#ifndef ARRAY_SIZE
|
||||||
@@ -123,7 +122,7 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax)
|
|||||||
|
|
||||||
case MENU_STEP:
|
case MENU_STEP:
|
||||||
*pMin = 0;
|
*pMin = 0;
|
||||||
*pMax = ARRAY_SIZE(gStepFrequencyTable) - 1;
|
*pMax = STEP_N_ELEM - 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MENU_ABR:
|
case MENU_ABR:
|
||||||
|
@@ -18,6 +18,7 @@
|
|||||||
#include "am_fix.h"
|
#include "am_fix.h"
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "driver/backlight.h"
|
#include "driver/backlight.h"
|
||||||
|
#include "frequencies.h"
|
||||||
#include "ui/helper.h"
|
#include "ui/helper.h"
|
||||||
#include "ui/main.h"
|
#include "ui/main.h"
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ struct FrequencyBandInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define F_MIN frequencyBandTable[0].lower
|
#define F_MIN frequencyBandTable[0].lower
|
||||||
#define F_MAX frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper
|
#define F_MAX frequencyBandTable[BAND_N_ELEM - 1].upper
|
||||||
|
|
||||||
const uint16_t RSSI_MAX_VALUE = 65535;
|
const uint16_t RSSI_MAX_VALUE = 65535;
|
||||||
|
|
||||||
|
@@ -29,7 +29,6 @@
|
|||||||
#include "../driver/systick.h"
|
#include "../driver/systick.h"
|
||||||
#include "../external/printf/printf.h"
|
#include "../external/printf/printf.h"
|
||||||
#include "../font.h"
|
#include "../font.h"
|
||||||
#include "../frequencies.h"
|
|
||||||
#include "../helper/battery.h"
|
#include "../helper/battery.h"
|
||||||
#include "../misc.h"
|
#include "../misc.h"
|
||||||
#include "../radio.h"
|
#include "../radio.h"
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include "frequencies.h"
|
#include "frequencies.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
#include <assert.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
|
||||||
|
|
||||||
@@ -61,9 +62,31 @@ const freq_band_table_t frequencyBandTable[] =
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
// this order of steps has to be preserved for backwards compatibility with other/stock firmwares
|
||||||
const uint16_t gStepFrequencyTable[] = {
|
const uint16_t gStepFrequencyTable[] = {
|
||||||
250, 500, 625, 1000, 1250, 2500, 833,
|
// standard steps
|
||||||
1, 5, 10, 25, 50, 100, 125, 1500, 3000, 5000, 10000, 12500, 25000, 50000
|
[STEP_2_5kHz] = 250,
|
||||||
|
[STEP_5kHz] = 500,
|
||||||
|
[STEP_6_25kHz] = 625,
|
||||||
|
[STEP_10kHz] = 1000,
|
||||||
|
[STEP_12_5kHz] = 1250,
|
||||||
|
[STEP_25kHz] = 2500,
|
||||||
|
[STEP_8_33kHz] = 833,
|
||||||
|
// custom steps
|
||||||
|
[STEP_0_01kHz] = 1,
|
||||||
|
[STEP_0_05kHz] = 5,
|
||||||
|
[STEP_0_1kHz] = 10,
|
||||||
|
[STEP_0_25kHz] = 25,
|
||||||
|
[STEP_0_5kHz] = 50,
|
||||||
|
[STEP_1kHz] = 100,
|
||||||
|
[STEP_1_25kHz] = 125,
|
||||||
|
[STEP_15kHz] = 1500,
|
||||||
|
[STEP_30kHz] = 3000,
|
||||||
|
[STEP_50kHz] = 5000,
|
||||||
|
[STEP_100kHz] = 10000,
|
||||||
|
[STEP_125kHz] = 12500,
|
||||||
|
[STEP_250kHz] = 25000,
|
||||||
|
[STEP_500kHz] = 50000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -86,15 +109,16 @@ uint32_t FREQUENCY_GetSortedIdxFromStepIdx(uint8_t stepIdx)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static_assert(ARRAY_SIZE(gStepFrequencyTable) == STEP_N_ELEM);
|
||||||
|
|
||||||
|
|
||||||
FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency)
|
FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency)
|
||||||
{
|
{
|
||||||
for (int band = ARRAY_SIZE(frequencyBandTable) - 1; band >= 0; band--)
|
for (int32_t band = BAND_N_ELEM - 1; band >= 0; band--)
|
||||||
if (Frequency >= frequencyBandTable[band].lower)
|
if (Frequency >= frequencyBandTable[band].lower)
|
||||||
// if (Frequency < frequencyBandTable[band].upper)
|
|
||||||
return (FREQUENCY_Band_t)band;
|
return (FREQUENCY_Band_t)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)
|
||||||
@@ -124,6 +148,7 @@ uint32_t FREQUENCY_RoundToStep(uint32_t freq, uint16_t step)
|
|||||||
int chno = (freq - base) / 700; // convert entered aviation 8.33Khz channel number scheme to actual frequency.
|
int chno = (freq - base) / 700; // convert entered aviation 8.33Khz channel number scheme to actual frequency.
|
||||||
return base + (chno * 833) + (chno == 3);
|
return base + (chno * 833) + (chno == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(step == 1)
|
if(step == 1)
|
||||||
return freq;
|
return freq;
|
||||||
if(step >= 1000)
|
if(step >= 1000)
|
||||||
@@ -135,8 +160,8 @@ int32_t 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 < frequencyBandTable[0].lower || Frequency > frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper)
|
if (Frequency < frequencyBandTable[0].lower || Frequency > frequencyBandTable[BAND_N_ELEM - 1].upper)
|
||||||
return -1; // not allowed outside this range
|
return 1; // not allowed outside this range
|
||||||
|
|
||||||
if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
|
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
|
||||||
@@ -212,7 +237,7 @@ int32_t 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 < frequencyBandTable[0].lower || Frequency > frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper)
|
if (Frequency < frequencyBandTable[0].lower || Frequency > frequencyBandTable[BAND_N_ELEM - 1].upper)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
|
if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
|
||||||
|
@@ -29,8 +29,6 @@ typedef struct {
|
|||||||
extern const freq_band_table_t BX4819_band1;
|
extern const freq_band_table_t BX4819_band1;
|
||||||
extern const freq_band_table_t BX4819_band2;
|
extern const freq_band_table_t BX4819_band2;
|
||||||
|
|
||||||
extern const freq_band_table_t frequencyBandTable[7];
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BAND_NONE = -1,
|
BAND_NONE = -1,
|
||||||
BAND1_50MHz = 0,
|
BAND1_50MHz = 0,
|
||||||
@@ -40,11 +38,13 @@ typedef enum {
|
|||||||
BAND5_350MHz,
|
BAND5_350MHz,
|
||||||
BAND6_400MHz,
|
BAND6_400MHz,
|
||||||
BAND7_470MHz,
|
BAND7_470MHz,
|
||||||
BAND_LAST_ELEMENT //keep this guard as last element
|
BAND_N_ELEM
|
||||||
} FREQUENCY_Band_t;
|
} FREQUENCY_Band_t;
|
||||||
|
|
||||||
|
extern const freq_band_table_t frequencyBandTable[];
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
// standard steps
|
||||||
STEP_2_5kHz,
|
STEP_2_5kHz,
|
||||||
STEP_5kHz,
|
STEP_5kHz,
|
||||||
STEP_6_25kHz,
|
STEP_6_25kHz,
|
||||||
@@ -52,6 +52,7 @@ typedef enum {
|
|||||||
STEP_12_5kHz,
|
STEP_12_5kHz,
|
||||||
STEP_25kHz,
|
STEP_25kHz,
|
||||||
STEP_8_33kHz,
|
STEP_8_33kHz,
|
||||||
|
// custom steps
|
||||||
STEP_0_01kHz,
|
STEP_0_01kHz,
|
||||||
STEP_0_05kHz,
|
STEP_0_05kHz,
|
||||||
STEP_0_1kHz,
|
STEP_0_1kHz,
|
||||||
@@ -66,10 +67,11 @@ typedef enum {
|
|||||||
STEP_125kHz,
|
STEP_125kHz,
|
||||||
STEP_250kHz,
|
STEP_250kHz,
|
||||||
STEP_500kHz,
|
STEP_500kHz,
|
||||||
|
STEP_N_ELEM
|
||||||
} STEP_Setting_t;
|
} STEP_Setting_t;
|
||||||
|
|
||||||
|
|
||||||
extern const uint16_t gStepFrequencyTable[21];
|
extern const uint16_t gStepFrequencyTable[];
|
||||||
|
|
||||||
#ifdef ENABLE_NOAA
|
#ifdef ENABLE_NOAA
|
||||||
extern const uint32_t NoaaFrequencyTable[10];
|
extern const uint32_t NoaaFrequencyTable[10];
|
||||||
|
14
radio.c
14
radio.c
@@ -253,7 +253,7 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure
|
|||||||
pVfo->Modulation = tmp;
|
pVfo->Modulation = tmp;
|
||||||
|
|
||||||
tmp = data[6];
|
tmp = data[6];
|
||||||
if (tmp >= ARRAY_SIZE(gStepFrequencyTable))
|
if (tmp >= STEP_N_ELEM)
|
||||||
tmp = STEP_12_5kHz;
|
tmp = STEP_12_5kHz;
|
||||||
pVfo->STEP_SETTING = tmp;
|
pVfo->STEP_SETTING = tmp;
|
||||||
pVfo->StepFrequency = gStepFrequencyTable[tmp];
|
pVfo->StepFrequency = gStepFrequencyTable[tmp];
|
||||||
@@ -412,13 +412,12 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure
|
|||||||
|
|
||||||
void RADIO_ConfigureSquelchAndOutputPower(VFO_Info_t *pInfo)
|
void RADIO_ConfigureSquelchAndOutputPower(VFO_Info_t *pInfo)
|
||||||
{
|
{
|
||||||
uint8_t Txp[3];
|
|
||||||
FREQUENCY_Band_t Band;
|
|
||||||
|
|
||||||
// *******************************
|
// *******************************
|
||||||
// squelch
|
// squelch
|
||||||
|
|
||||||
Band = FREQUENCY_GetBand(pInfo->pRX->Frequency);
|
FREQUENCY_Band_t Band = FREQUENCY_GetBand(pInfo->pRX->Frequency);
|
||||||
uint16_t Base = (Band < BAND4_174MHz) ? 0x1E60 : 0x1E00;
|
uint16_t Base = (Band < BAND4_174MHz) ? 0x1E60 : 0x1E00;
|
||||||
|
|
||||||
if (gEeprom.SQUELCH_LEVEL == 0)
|
if (gEeprom.SQUELCH_LEVEL == 0)
|
||||||
@@ -501,9 +500,9 @@ void RADIO_ConfigureSquelchAndOutputPower(VFO_Info_t *pInfo)
|
|||||||
|
|
||||||
Band = FREQUENCY_GetBand(pInfo->pTX->Frequency);
|
Band = FREQUENCY_GetBand(pInfo->pTX->Frequency);
|
||||||
|
|
||||||
|
uint8_t Txp[3];
|
||||||
EEPROM_ReadBuffer(0x1ED0 + (Band * 16) + (pInfo->OUTPUT_POWER * 3), Txp, 3);
|
EEPROM_ReadBuffer(0x1ED0 + (Band * 16) + (pInfo->OUTPUT_POWER * 3), Txp, 3);
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_REDUCE_LOW_MID_TX_POWER
|
#ifdef ENABLE_REDUCE_LOW_MID_TX_POWER
|
||||||
// make low and mid even lower
|
// make low and mid even lower
|
||||||
if (pInfo->OUTPUT_POWER == OUTPUT_POWER_LOW) {
|
if (pInfo->OUTPUT_POWER == OUTPUT_POWER_LOW) {
|
||||||
@@ -548,9 +547,8 @@ void RADIO_ApplyOffset(VFO_Info_t *pInfo)
|
|||||||
|
|
||||||
if (Frequency < frequencyBandTable[0].lower)
|
if (Frequency < frequencyBandTable[0].lower)
|
||||||
Frequency = frequencyBandTable[0].lower;
|
Frequency = frequencyBandTable[0].lower;
|
||||||
else
|
else if (Frequency > frequencyBandTable[BAND_N_ELEM - 1].upper)
|
||||||
if (Frequency > frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper)
|
Frequency = frequencyBandTable[BAND_N_ELEM - 1].upper;
|
||||||
Frequency = frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper;
|
|
||||||
|
|
||||||
pInfo->freq_config_TX.Frequency = Frequency;
|
pInfo->freq_config_TX.Frequency = Frequency;
|
||||||
}
|
}
|
||||||
|
@@ -33,7 +33,7 @@ enum POWER_OnDisplayMode_t {
|
|||||||
};
|
};
|
||||||
typedef enum POWER_OnDisplayMode_t POWER_OnDisplayMode_t;
|
typedef enum POWER_OnDisplayMode_t POWER_OnDisplayMode_t;
|
||||||
|
|
||||||
enum {
|
enum TxLockModes_t {
|
||||||
F_LOCK_DEF, //all default frequencies + configurable
|
F_LOCK_DEF, //all default frequencies + configurable
|
||||||
F_LOCK_FCC,
|
F_LOCK_FCC,
|
||||||
F_LOCK_CE,
|
F_LOCK_CE,
|
||||||
|
Reference in New Issue
Block a user