0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 14:21:25 +03:00

removed round to step when user enters freq

This commit is contained in:
OneOfEleven 2023-11-04 09:51:01 +00:00
parent d59d4eae15
commit e795b90bf5
8 changed files with 106 additions and 149 deletions

View File

@ -36,7 +36,7 @@ ENABLE_REDUCE_LOW_MID_TX_POWER := 1
ENABLE_ALARM := 0
ENABLE_TX1750 := 0
# MDC1200 2.8 kB
ENABLE_MDC1200 := 1
ENABLE_MDC1200 := 0
ENABLE_MDC1200_SHOW_OP_ARG := 1
ENABLE_PWRON_PASSWORD := 0
ENABLE_RESET_AES_KEY := 0

View File

@ -569,33 +569,6 @@ bool APP_start_listening(void)
return true;
}
uint32_t APP_set_frequency_by_step(vfo_info_t *pInfo, int8_t Step)
{
uint32_t Frequency = pInfo->freq_config_rx.frequency + (Step * pInfo->step_freq);
if (pInfo->step_freq == 833)
{
const uint32_t Lower = FREQ_BAND_TABLE[pInfo->channel_attributes.band].lower;
const uint32_t Delta = Frequency - Lower;
uint32_t Base = (Delta / 2500) * 2500;
const uint32_t Index = ((Delta - Base) % 2500) / 833;
if (Index == 2)
Base++;
Frequency = Lower + Base + (Index * 833);
}
// if (Frequency >= FREQ_BAND_TABLE[pInfo->channel_attributes.band].upper)
// Frequency = FREQ_BAND_TABLE[pInfo->channel_attributes.band].lower;
// else
// if (Frequency < FREQ_BAND_TABLE[pInfo->channel_attributes.band].lower)
// Frequency = FREQUENCY_floor_to_step(FREQ_BAND_TABLE[pInfo->channel_attributes.band].upper, pInfo->step_freq, FREQ_BAND_TABLE[pInfo->channel_attributes.band].lower);
Frequency = FREQUENCY_wrap_to_step_band(Frequency, pInfo->step_freq, pInfo->channel_attributes.band);
return Frequency;
}
void APP_stop_scan(void)
{
if (g_scan_state_dir == SCAN_STATE_DIR_OFF)
@ -674,37 +647,40 @@ void APP_stop_scan(void)
static void APP_next_freq(void)
{
frequency_band_t new_band;
const frequency_band_t old_band = FREQUENCY_GetBand(g_rx_vfo->freq_config_rx.frequency);
uint32_t frequency = APP_set_frequency_by_step(g_rx_vfo, g_scan_state_dir);
g_rx_vfo->freq_config_rx.frequency = frequency;
uint32_t freq = g_rx_vfo->freq_config_rx.frequency;
const uint32_t step = g_rx_vfo->step_freq;
const frequency_band_t band = FREQUENCY_GetBand(freq);
const uint32_t upper = FREQ_BAND_TABLE[band].upper;
const uint32_t lower = FREQ_BAND_TABLE[band].lower;
#ifdef ENABLE_SCAN_IGNORE_LIST
while (FI_freq_ignored(frequency) >= 0)
{
uint32_t next_frequency;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// UART_printf("skipping %u\r\n", frequency);
#endif
next_frequency = APP_set_frequency_by_step(g_rx_vfo, g_scan_state_dir); // skip to next frequency
if (frequency == next_frequency)
break;
frequency = next_frequency;
g_rx_vfo->freq_config_rx.frequency = frequency;
}
do {
#endif
freq += step * g_scan_state_dir;
new_band = FREQUENCY_GetBand(frequency);
// wrap-a-round
while (freq >= upper)
freq -= upper - lower;
while (freq < lower)
freq += upper - lower;
if (band == BAND2_108MHz) // air band uses set channels
freq = lower + ((((freq - lower) + (step / 2)) / step) * step);
#ifdef ENABLE_SCAN_IGNORE_LIST
} while (FI_freq_ignored(freq) >= 0);
#endif
g_rx_vfo->freq_in_channel = 0xff;
g_rx_vfo->freq_config_rx.frequency = freq;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// UART_printf("APP_next_freq %u %u\r\n", frequency, new_band);
// UART_printf("APP_next_freq %u %u\r\n", freq, new_band);
#endif
if (new_band != old_band)
{ // original slower method
#if 0
// original slower method
RADIO_ApplyOffset(g_rx_vfo, false);
RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo);
@ -716,20 +692,23 @@ static void APP_next_freq(void)
#else
g_scan_pause_tick_10ms = scan_pause_freq_10ms;
#endif
}
else
{ // don't need to go through all the other stuff .. lets speed things up !!
BK4819_set_rf_frequency(frequency, true);
BK4819_set_rf_filter_path(frequency);
#else
// don't need to go through all the other stuff .. speed things up !!
// RADIO_ApplyOffset(g_rx_vfo, false);
BK4819_set_rf_frequency(g_rx_vfo->freq_config_rx.frequency, true);
BK4819_set_rf_filter_path(g_rx_vfo->freq_config_rx.frequency);
#ifdef ENABLE_FASTER_CHANNEL_SCAN
// g_scan_pause_tick_10ms = 10; // 100ms
//g_scan_pause_tick_10ms = 10; // 100ms
g_scan_pause_tick_10ms = 6; // 60ms
#else
g_scan_pause_tick_10ms = scan_pause_freq_10ms;
#endif
}
#endif
g_scan_pause_time_mode = false;
g_update_display = true;

View File

@ -32,7 +32,6 @@ void APP_end_tx(void);
void APP_stop_scan(void);
void APP_channel_next(const bool remember_current, const scan_state_dir_t scan_direction);
bool APP_start_listening(void);
uint32_t APP_set_frequency_by_step(vfo_info_t *pInfo, int8_t Step);
void APP_time_slice_10ms(void);
void APP_time_slice_500ms(void);

View File

@ -577,8 +577,10 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
RADIO_configure_channel(vfo, VFO_CONFIGURE_RELOAD);
}
#if 0
Frequency += g_tx_vfo->step_freq / 2; // for rounding to nearest step size
Frequency = FREQUENCY_floor_to_step(Frequency, g_tx_vfo->step_freq, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].lower, FREQ_BAND_TABLE[g_tx_vfo->channel_attributes.band].upper);
#endif
if (Frequency >= BX4819_BAND1.upper && Frequency < BX4819_BAND2.lower)
{ // clamp the frequency to the limit
@ -875,7 +877,7 @@ void MAIN_Key_STAR(bool key_pressed, bool key_held)
g_update_status = true;
}
void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Direction)
void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t direction)
{
#ifdef ENABLE_SQ_OPEN_WITH_UP_DN_BUTTS
static bool monitor_was_enabled = false;
@ -904,17 +906,18 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
}
#endif
g_tx_vfo->freq_config_tx.frequency = g_tx_vfo->freq_config_rx.frequency;
g_rx_vfo->freq_config_tx.frequency = g_rx_vfo->freq_config_rx.frequency;
// find the first channel that contains this frequency
g_tx_vfo->freq_in_channel = SETTINGS_find_channel(g_tx_vfo->freq_config_rx.frequency);
g_rx_vfo->freq_in_channel = SETTINGS_find_channel(g_rx_vfo->freq_config_rx.frequency);
SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, 1);
// SETTINGS_save_channel(g_rx_vfo->channel_save, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, 1);
SETTINGS_save_channel(g_rx_vfo->channel_save, g_rx_vfo_num, g_rx_vfo, 1);
RADIO_ApplyOffset(g_tx_vfo, true);
RADIO_ApplyOffset(g_rx_vfo, true);
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// UART_printf("save chan %u\r\n", g_tx_vfo->channel_save);
// UART_printf("save chan %u\r\n", g_rx_vfo->channel_save);
#endif
}
@ -964,43 +967,46 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
if (IS_FREQ_CHANNEL(Channel))
{ // frequency mode
frequency_band_t new_band;
const frequency_band_t old_band = FREQUENCY_GetBand(g_tx_vfo->freq_config_rx.frequency);
const uint32_t frequency = APP_set_frequency_by_step(g_tx_vfo, Direction);
uint32_t freq = g_rx_vfo->freq_config_rx.frequency;
const uint32_t step = g_rx_vfo->step_freq;
const frequency_band_t band = FREQUENCY_GetBand(freq);
const uint32_t upper = FREQ_BAND_TABLE[band].upper;
const uint32_t lower = FREQ_BAND_TABLE[band].lower;
if (FREQUENCY_rx_freq_check(frequency) < 0)
freq += step * direction;
// wrap-a-round
while (freq >= upper)
freq -= upper - lower;
while (freq < lower)
freq += upper - lower;
if (band == BAND2_108MHz) // air band uses set channels. so round to those channels
freq = lower + ((((freq - lower) + (step / 2)) / step) * step);
if (FREQUENCY_rx_freq_check(freq) < 0)
{ // frequency not allowed
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
// compute the frequency band for the frequency
new_band = FREQUENCY_GetBand(frequency);
g_rx_vfo->freq_config_rx.frequency = freq;
// save the new frequency into the VFO
g_tx_vfo->freq_config_rx.frequency = frequency;
g_tx_vfo->freq_config_tx.frequency = frequency;
RADIO_ApplyOffset(g_rx_vfo, false);
// find the first channel that contains this frequency
//
// this currently takes to long to look through all the channels (200)
// with every frequency step, because we have to read each channel from eeprom
// before checking the channels frequency
//
// TODO: include this once we have the entire eeprom loaded
// find the first channel that contains this frequency .. currently takes too long
//
//if (!key_held && key_pressed)
// g_tx_vfo->freq_in_channel = SETTINGS_find_channel(frequency);
// g_rx_vfo->freq_in_channel = SETTINGS_find_channel(freq);
//else
//if (key_held && key_pressed)
g_tx_vfo->freq_in_channel = 0xff;
g_rx_vfo->freq_in_channel = 0xff;
if (new_band != old_band)
{ // original slow method
#if 0
// original slow method
g_request_save_channel = 1;
}
else
{ // don't need to go through all the other stuff
#else
// don't need to go through all the other stuff
// lets speed things up by simply setting the VCO/PLL frequency
// and the RF filter path (LNA and PA)
@ -1017,9 +1023,9 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
}
#endif
BK4819_set_rf_frequency(frequency, true); // set the VCO/PLL
BK4819_set_rf_filter_path(frequency); // set the proper LNA/PA filter path
}
BK4819_set_rf_frequency(freq, true); // set the VCO/PLL
BK4819_set_rf_filter_path(freq); // set the proper LNA/PA filter path
#endif
return;
}
@ -1028,7 +1034,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
g_tx_vfo->freq_in_channel = 0xff;
Next = RADIO_FindNextChannel(Channel + Direction, Direction, false, 0);
Next = RADIO_FindNextChannel(Channel + direction, direction, false, 0);
if (Next == 0xFF)
return;
@ -1079,7 +1085,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
// jump to the next channel
APP_channel_next(false, Direction);
APP_channel_next(false, direction);
// go NOW
g_scan_pause_tick_10ms = 0;

View File

@ -33,7 +33,7 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif
static uint16_t gBK4819_GpioOutState;
static uint16_t g_bk4819_gpio_out_state;
//const uint32_t rf_filter_transition_freq = 28000000; // original
const uint32_t rf_filter_transition_freq = 26500000;
@ -50,6 +50,8 @@ __inline uint16_t scale_freq(const uint16_t freq)
void BK4819_Init(void)
{
g_bk4819_gpio_out_state = 0x9000;
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCN);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
@ -104,40 +106,18 @@ void BK4819_Init(void)
BK4819_config_sub_audible();
#if 1
const uint8_t dtmf_coeffs[] = {111, 107, 103, 98, 80, 71, 58, 44, 65, 55, 37, 23, 228, 203, 181, 159};
for (unsigned int i = 0; i < ARRAY_SIZE(dtmf_coeffs); i++)
BK4819_WriteRegister(0x09, (i << 12) | dtmf_coeffs[i]);
#else
// original code
BK4819_WriteRegister(0x09, 0x006F); // 6F
BK4819_WriteRegister(0x09, 0x106B); // 6B
BK4819_WriteRegister(0x09, 0x2067); // 67
BK4819_WriteRegister(0x09, 0x3062); // 62
BK4819_WriteRegister(0x09, 0x4050); // 50
BK4819_WriteRegister(0x09, 0x5047); // 47
BK4819_WriteRegister(0x09, 0x603A); // 3A
BK4819_WriteRegister(0x09, 0x702C); // 2C
BK4819_WriteRegister(0x09, 0x8041); // 41
BK4819_WriteRegister(0x09, 0x9037); // 37
BK4819_WriteRegister(0x09, 0xA025); // 25
BK4819_WriteRegister(0x09, 0xB017); // 17
BK4819_WriteRegister(0x09, 0xC0E4); // E4
BK4819_WriteRegister(0x09, 0xD0CB); // CB
BK4819_WriteRegister(0x09, 0xE0B5); // B5
BK4819_WriteRegister(0x09, 0xF09F); // 9F
#endif
BK4819_WriteRegister(0x1F, 0x5454);
BK4819_WriteRegister(0x3E, 0xA037);
gBK4819_GpioOutState = 0x9000;
BK4819_WriteRegister(0x33, 0x9000);
BK4819_WriteRegister(0x3F, 0);
BK4819_WriteRegister(0x1F, 0x5454); // 0101 0100 01 01 0100
BK4819_WriteRegister(0x3E, 41015); // band selection threshold = VCO max frequency (Hz) / 96 / 640
BK4819_WriteRegister(0x33, 0x9000); // 1001 0000 0000 0000 .. GPIO
BK4819_WriteRegister(0x3F, 0); // disable interrupts
#if 0
// rt-890
// RT-890
// BK4819_WriteRegister(0x37, 0x1D0F);
// DisableAGC(0);
@ -150,17 +130,12 @@ void BK4819_Init(void)
BK4819_WriteRegister(0x49, 0x2A38);
BK4819_WriteRegister(0x7B, 0x8420);
BK4819_WriteRegister(0x33, 0x1F00);
BK4819_WriteRegister(0x35, 0x0000);
BK4819_WriteRegister(0x1E, 0x4C58);
BK4819_WriteRegister(0x1F, 0xA656);
// BK4819_WriteRegister(0x3E, gCalibration.BandSelectionThreshold);
BK4819_WriteRegister(0x3F, 0x0000);
BK4819_WriteRegister(0x2A, 0x4F18);
BK4819_WriteRegister(0x53, 0xE678);
BK4819_WriteRegister(0x2C, 0x5705);
BK4819_WriteRegister(0x4B, 0x7102);
BK4819_WriteRegister(0x26, 0x13A0);
BK4819_WriteRegister(0x1E, 0x4C58); // ???
BK4819_WriteRegister(0x2A, 0x4F18); // ???
BK4819_WriteRegister(0x53, 0xE678); // ???
BK4819_WriteRegister(0x2C, 0x5705); // ???
BK4819_WriteRegister(0x4B, 0x7102); // AF gains
BK4819_WriteRegister(0x26, 0x13A0); // ???
#endif
}
@ -397,11 +372,11 @@ void BK4819_EnableAGC(void)
void BK4819_set_GPIO_pin(bk4819_gpio_pin_t Pin, bool bSet)
{
if (bSet)
gBK4819_GpioOutState |= (0x40u >> Pin);
g_bk4819_gpio_out_state |= (0x40u >> Pin);
else
gBK4819_GpioOutState &= ~(0x40u >> Pin);
g_bk4819_gpio_out_state &= ~(0x40u >> Pin);
BK4819_WriteRegister(0x33, gBK4819_GpioOutState);
BK4819_WriteRegister(0x33, g_bk4819_gpio_out_state);
}
void BK4819_EnableVox(uint16_t VoxEnableThreshold, uint16_t VoxDisableThreshold)
@ -411,24 +386,22 @@ void BK4819_EnableVox(uint16_t VoxEnableThreshold, uint16_t VoxDisableThreshold)
//else
//if (vox_amp < VoxDisableThreshold) (After Delay) VOX = 0;
const uint16_t REG_31_Value = BK4819_ReadRegister(0x31);
if (VoxEnableThreshold > 2047)
VoxEnableThreshold = 2047;
if (VoxDisableThreshold > 2047)
VoxDisableThreshold = 2047;
// 0xA000 is undocumented?
BK4819_WriteRegister(0x46, 0xA000 | VoxEnableThreshold);
// 0xA000 is undocumented
BK4819_WriteRegister(0x46, (20u << 11) | VoxEnableThreshold); // ???, amp threshold for vox on
// 0x1800 is undocumented?
BK4819_WriteRegister(0x79, 0x1800 | VoxDisableThreshold);
BK4819_WriteRegister(0x79, (3u << 11) | VoxDisableThreshold); // vox det interval time, amp threshold for vox off
// Bottom 12 bits are undocumented, 15:12 vox disable delay *128ms
BK4819_WriteRegister(0x7A, 0x289A); // vox disable delay = 128*5 = 640ms
BK4819_WriteRegister(0x7A, (2u << 12) | 0x089A); // vox disable delay = 128*5 = 640ms
// 0010 100010011010
// Enable VOX
BK4819_WriteRegister(0x31, REG_31_Value | (1u << 2));
BK4819_WriteRegister(0x31, BK4819_ReadRegister(0x31) | (1u << 2));
}
void BK4819_set_TX_deviation(const bool narrow)
@ -775,7 +748,7 @@ void BK4819_set_scrambler(const int index)
}
else
{ // enable
uint16_t freq = 2600 + ((index - 1) * 50); // 50 Hz steps
uint16_t freq = 2600 + ((index - 1) * 50); // 2600Hz ++ 50 Hz steps
if (freq > 12000)
freq = 12000;

Binary file not shown.

Binary file not shown.

View File

@ -294,9 +294,9 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur
else
if (frequency >= FREQ_BAND_TABLE[attributes.band].upper)
frequency = FREQUENCY_floor_to_step(frequency, p_vfo->step_freq, FREQ_BAND_TABLE[attributes.band].lower, FREQ_BAND_TABLE[attributes.band].upper);
else
if (channel >= FREQ_CHANNEL_FIRST)
frequency = FREQUENCY_floor_to_step(frequency, p_vfo->step_freq, FREQ_BAND_TABLE[attributes.band].lower, FREQ_BAND_TABLE[attributes.band].upper);
// else
// if (channel >= FREQ_CHANNEL_FIRST)
// frequency = FREQUENCY_floor_to_step(frequency, p_vfo->step_freq, FREQ_BAND_TABLE[attributes.band].lower, FREQ_BAND_TABLE[attributes.band].upper);
if (!g_eeprom.config.setting.enable_350 && frequency >= 35000000 && frequency < 40000000)
{ // 350~400Mhz not allowed