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

FREQ/CTCSS/CDCSS search updates

This commit is contained in:
OneOfEleven 2023-10-30 11:23:56 +00:00
parent a188f846f5
commit c03ac606f1
19 changed files with 404 additions and 353 deletions

View File

@ -22,6 +22,7 @@ ENABLE_FMRADIO_64_76 := 0
ENABLE_FMRADIO_76_90 := 0
ENABLE_FMRADIO_76_108 := 0
ENABLE_FMRADIO_875_108 := 1
ENABLE_FMRADIO_64_108 := 0
# NOAA 1.2 kB
ENABLE_NOAA := 0
# Voice 1.7 kB
@ -57,8 +58,8 @@ ENABLE_DTMF_CALL_FLASH_LIGHT := 1
ENABLE_FLASH_LIGHT_SOS_TONE := 1
ENABLE_SHOW_CHARGE_LEVEL := 0
ENABLE_REVERSE_BAT_SYMBOL := 1
ENABLE_FREQ_SEARCH_TIMEOUT := 0
ENABLE_CODE_SEARCH_TIMEOUT := 0
ENABLE_FREQ_SEARCH_TIMEOUT := 1
ENABLE_CODE_SEARCH_TIMEOUT := 1
# Kill and Revive 400 B
ENABLE_KILL_REVIVE := 0
# AM Fix 800 B
@ -109,7 +110,7 @@ ifeq ($(ENABLE_LTO),1)
ENABLE_OVERLAY := 0
endif
ifeq ($(filter $(ENABLE_FMRADIO_64_76) $(ENABLE_FMRADIO_76_90) $(ENABLE_FMRADIO_76_108) $(ENABLE_FMRADIO_875_108), 1), 1)
ifeq ($(filter $(ENABLE_FMRADIO_64_76) $(ENABLE_FMRADIO_76_90) $(ENABLE_FMRADIO_76_108) $(ENABLE_FMRADIO_875_108) $(ENABLE_FMRADIO_64_108), 1), 1)
ENABLE_FMRADIO := 1
else
ENABLE_FMRADIO := 0
@ -311,6 +312,9 @@ endif
ifeq ($(ENABLE_FMRADIO_875_108),1)
CFLAGS += -DENABLE_FMRADIO_875_108
endif
ifeq ($(ENABLE_FMRADIO_64_108),1)
CFLAGS += -DENABLE_FMRADIO_64_108
endif
ifeq ($(ENABLE_FMRADIO),1)
CFLAGS += -DENABLE_FMRADIO
endif

View File

@ -49,6 +49,7 @@ ENABLE_FMRADIO_64_76 := 0 enable FM radio 64MHz ~ 76MHz
ENABLE_FMRADIO_76_90 := 0 enable FM radio 76MHz ~ 90MHz
ENABLE_FMRADIO_76_108 := 0 enable FM radio 76MHz ~ 108MHz
ENABLE_FMRADIO_875_108 := 1 enable FM radio 87.5MHz ~ 108MHz
ENABLE_FMRADIO_64_108 := 0 enable the FM radios full frequency range
ENABLE_NOAA := 0 everything NOAA (only of any use in the USA)
ENABLE_VOICE := 0 want to hear voices ?
ENABLE_MUTE_RADIO_FOR_VOICE := 1 mute the radios audio when a voice is playing

View File

@ -177,7 +177,7 @@ void ACTION_Scan(bool bRestart)
FM_EraseChannels();
g_fm_auto_scan = true;
g_fm_channel_position = 0;
Frequency = FM_RADIO_BAND.lower;
Frequency = BK1080_freq_lower;
}
else
{ // scan without auto store

195
app/app.c
View File

@ -1595,19 +1595,14 @@ void APP_process_scan(void)
void APP_process_search(void)
{
uint32_t Result;
int32_t Delta;
uint16_t CtcssFreq;
BK4819_CSS_scan_result_t ScanResult;
if (g_current_display_screen != DISPLAY_SEARCH)
return;
g_search_freq_css_timer_10ms++;
g_search_freq_css_tick_10ms++;
if (g_search_delay_10ms > 0)
if (g_search_tick_10ms > 0)
{
if (--g_search_delay_10ms > 0)
if (--g_search_tick_10ms > 0)
{
APP_check_keys();
return;
@ -1623,189 +1618,7 @@ void APP_process_search(void)
g_update_display = true;
GUI_SelectNextDisplay(DISPLAY_SEARCH);
switch (g_search_css_state)
{
case SEARCH_CSS_STATE_OFF:
if (g_search_freq_css_timer_10ms >= scan_freq_css_timeout_10ms)
{ // FREQ/CTCSS/CDCSS search timeout
if (!g_search_single_frequency)
{ // FREQ search timeout
#ifdef ENABLE_FREQ_SEARCH_TIMEOUT
BK4819_DisableFrequencyScan();
g_search_css_state = SEARCH_CSS_STATE_FREQ_FAILED;
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
break;
#endif
}
else
{ // CTCSS/CDCSS search timeout
#ifdef ENABLE_CODE_SEARCH_TIMEOUT
BK4819_DisableFrequencyScan();
g_search_css_state = SEARCH_CSS_STATE_FREQ_FAILED;
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
break;
#endif
}
}
if (!BK4819_GetFrequencyScanResult(&Result))
break; // still scanning
// accept only within 1kHz
Delta = Result - g_search_frequency;
g_search_hit_count = (abs(Delta) < 100) ? g_search_hit_count + 1 : 0;
BK4819_DisableFrequencyScan();
g_search_frequency = Result;
if (g_search_hit_count < 3)
{ // keep scanning for an RF carrier
BK4819_EnableFrequencyScan();
}
else
{ // RF carrier found
//
// stop RF search and start CTCSS/CDCSS search
BK4819_SetScanFrequency(g_search_frequency);
g_search_css_result_type = CODE_TYPE_NONE;
g_search_css_result_code = 0xff;
g_search_hit_count = 0;
g_search_use_css_result = false;
g_search_freq_css_timer_10ms = 0;
g_search_css_state = SEARCH_CSS_STATE_SCANNING;
g_update_status = true;
g_update_display = true;
GUI_SelectNextDisplay(DISPLAY_SEARCH);
}
g_search_delay_10ms = scan_freq_css_delay_10ms;
break;
case SEARCH_CSS_STATE_SCANNING:
if (g_search_freq_css_timer_10ms >= scan_freq_css_timeout_10ms)
{ // CTCSS/CDCSS search timeout
#if defined(ENABLE_CODE_SEARCH_TIMEOUT)
g_search_css_state = SEARCH_CSS_STATE_FAILED;
BK4819_Idle();
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
break;
#else
if (!g_search_single_frequency)
{
g_search_css_state = SEARCH_CSS_STATE_FAILED;
BK4819_Idle();
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
break;
}
#endif
}
ScanResult = BK4819_GetCxCSSScanResult(&Result, &CtcssFreq);
if (ScanResult == BK4819_CSS_RESULT_NOT_FOUND)
break;
BK4819_Idle();
if (ScanResult == BK4819_CSS_RESULT_CDCSS)
{ // found a CDCSS code
const uint8_t code = DCS_GetCdcssCode(Result);
if (code != 0xFF)
{
g_search_hit_count = 0;
g_search_css_result_type = CODE_TYPE_DIGITAL;
g_search_css_result_code = code;
g_search_css_state = SEARCH_CSS_STATE_FOUND;
g_search_use_css_result = true;
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
}
else
{
g_search_hit_count = 0;
g_search_css_result_type = CODE_TYPE_NONE;
g_search_css_result_code = code;
g_search_use_css_result = false;
}
}
else
if (ScanResult == BK4819_CSS_RESULT_CTCSS)
{ // found a CTCSS tone
const uint8_t code = DCS_GetCtcssCode(CtcssFreq);
if (code != 0xFF)
{
if (code == g_search_css_result_code &&
g_search_css_result_type == CODE_TYPE_CONTINUOUS_TONE)
{
if (++g_search_hit_count >= 3)
{
g_search_css_state = SEARCH_CSS_STATE_FOUND;
g_search_use_css_result = true;
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
}
}
else
{
g_search_hit_count = 1;
g_search_css_result_type = CODE_TYPE_CONTINUOUS_TONE;
g_search_css_result_code = code;
g_search_use_css_result = false;
}
}
else
{
g_search_hit_count = 0;
g_search_css_result_type = CODE_TYPE_NONE;
g_search_css_result_code = 0xff;
g_search_use_css_result = false;
}
}
if (g_search_css_state == SEARCH_CSS_STATE_OFF ||
g_search_css_state == SEARCH_CSS_STATE_SCANNING)
{ // re-start scan
BK4819_SetScanFrequency(g_search_frequency);
g_search_delay_10ms = scan_freq_css_delay_10ms;
}
GUI_SelectNextDisplay(DISPLAY_SEARCH);
break;
//case SEARCH_CSS_STATE_FOUND:
//case SEARCH_CSS_STATE_FAILED:
//case SEARCH_CSS_STATE_REPEAT:
default:
break;
}
SEARCH_process();
}
void APP_process_transmit(void)

View File

@ -52,7 +52,7 @@ uint16_t g_fm_restore_tick_10ms;
bool FM_CheckValidChannel(uint8_t Channel)
{
return (Channel < ARRAY_SIZE(g_fm_channels) && (g_fm_channels[Channel] >= FM_RADIO_BAND.lower && g_fm_channels[Channel] < FM_RADIO_BAND.upper)) ? true : false;
return (Channel < ARRAY_SIZE(g_fm_channels) && (g_fm_channels[Channel] >= BK1080_freq_lower && g_fm_channels[Channel] < BK1080_freq_upper)) ? true : false;
}
uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction)
@ -142,11 +142,11 @@ void FM_Tune(uint16_t Frequency, int8_t Step, bool flag)
if (!flag)
{
Frequency += Step;
if (Frequency < FM_RADIO_BAND.lower)
Frequency = FM_RADIO_BAND.upper;
if (Frequency < BK1080_freq_lower)
Frequency = BK1080_freq_upper - 1u;
else
if (Frequency > FM_RADIO_BAND.upper)
Frequency = FM_RADIO_BAND.lower;
if (Frequency > (BK1080_freq_upper - 1u))
Frequency = BK1080_freq_lower;
g_eeprom.fm_frequency_playing = Frequency;
}
@ -294,11 +294,10 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
Frequency /= 10000;
if (Frequency < FM_RADIO_BAND.lower || Frequency > FM_RADIO_BAND.upper)
{
g_request_display_screen = DISPLAY_FM;
return;
}
if (Frequency < BK1080_freq_lower)
Frequency = BK1080_freq_lower;
if (Frequency > (BK1080_freq_upper - 1u))
Frequency = BK1080_freq_upper - 1u;
g_eeprom.fm_selected_frequency = (uint16_t)Frequency;
@ -603,11 +602,11 @@ static void FM_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Step)
else
{ // no, frequency mode
uint16_t Frequency = g_eeprom.fm_selected_frequency + Step;
if (Frequency < FM_RADIO_BAND.lower)
Frequency = FM_RADIO_BAND.upper;
if (Frequency < BK1080_freq_lower)
Frequency = BK1080_freq_upper - 1u;
else
if (Frequency > FM_RADIO_BAND.upper)
Frequency = FM_RADIO_BAND.lower;
if (Frequency > (BK1080_freq_upper - 1u))
Frequency = BK1080_freq_lower;
g_eeprom.fm_frequency_playing = Frequency;
g_eeprom.fm_selected_frequency = g_eeprom.fm_frequency_playing;
@ -665,12 +664,12 @@ void FM_process_key(key_code_t Key, bool key_pressed, bool key_held)
void FM_Play(void)
{
if (!FM_CheckFrequencyLock(g_eeprom.fm_frequency_playing, FM_RADIO_BAND.lower))
if (!FM_CheckFrequencyLock(g_eeprom.fm_frequency_playing, BK1080_freq_lower))
{
if (!g_fm_auto_scan)
{
g_fm_play_tick_10ms = 0;
g_fm_found_frequency = true;
g_fm_play_tick_10ms = 0;
g_fm_found_frequency = true;
if (!g_eeprom.fm_channel_mode)
g_eeprom.fm_selected_frequency = g_eeprom.fm_frequency_playing;
@ -693,7 +692,7 @@ void FM_Play(void)
}
}
if (g_fm_auto_scan && g_eeprom.fm_frequency_playing >= FM_RADIO_BAND.upper)
if (g_fm_auto_scan && g_eeprom.fm_frequency_playing > (BK1080_freq_upper - 1))
FM_PlayAndUpdate();
else
FM_Tune(g_eeprom.fm_frequency_playing, g_fm_scan_state, false);

View File

@ -14,6 +14,8 @@
* limitations under the License.
*/
#include <stdlib.h> // abs()
#include "app/dtmf.h"
#include "app/generic.h"
#include "app/search.h"
@ -43,10 +45,11 @@ bool g_search_flag_stop_scan;
uint8_t g_search_show_chan_prefix;
bool g_search_single_frequency;
uint16_t g_search_freq_css_timer_10ms;
uint8_t g_search_delay_10ms;
uint8_t g_search_hit_count;
uint16_t g_search_freq_css_tick_10ms;
uint16_t g_search_tick_10ms;
search_edit_state_t g_search_edit_state;
uint8_t g_search_channel;
@ -55,8 +58,12 @@ step_setting_t g_search_step_setting;
static void SEARCH_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
{
if (key_held || key_pressed)
if (key_pressed)
{
if (!key_held)
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
return;
}
if (g_search_edit_state == SEARCH_EDIT_STATE_SAVE_CHAN)
{
@ -90,15 +97,17 @@ static void SEARCH_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
}
}
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
}
static void SEARCH_Key_EXIT(bool key_pressed, bool key_held)
{
if (key_held || key_pressed)
if (key_pressed)
{
if (!key_held)
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
return;
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
}
switch (g_search_edit_state)
{
@ -146,29 +155,23 @@ static void SEARCH_Key_MENU(bool key_pressed, bool key_held)
{
uint8_t Channel;
if (key_held || key_pressed)
if (key_pressed)
{
if (!key_held)
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
return;
}
// key released
if (g_search_css_state == SEARCH_CSS_STATE_OFF && !g_search_single_frequency)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
if (g_search_css_state == SEARCH_CSS_STATE_SCANNING)
{
if (g_search_single_frequency)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
}
if (g_search_css_state == SEARCH_CSS_STATE_SCANNING && g_search_single_frequency)
return;
if (g_search_css_state == SEARCH_CSS_STATE_FAILED && g_search_single_frequency)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
@ -210,7 +213,7 @@ static void SEARCH_Key_MENU(bool key_pressed, bool key_held)
#endif
g_request_display_screen = DISPLAY_SEARCH;
g_update_status = true;
g_update_status = true;
break;
case SEARCH_EDIT_STATE_SAVE_CHAN:
@ -220,16 +223,16 @@ static void SEARCH_Key_MENU(bool key_pressed, bool key_held)
if (g_input_box_index > 0)
break;
if (g_input_box_index == 0)
{
g_search_edit_state = SEARCH_EDIT_STATE_SAVE_CONFIRM;
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
g_request_display_screen = DISPLAY_SEARCH;
}
// Fallthrough
// break;
case SEARCH_EDIT_STATE_SAVE_CONFIRM:
@ -295,21 +298,22 @@ static void SEARCH_Key_MENU(bool key_pressed, bool key_held)
}
g_update_display = true;
break;
default:
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
break;
}
}
static void SEARCH_Key_STAR(bool key_pressed, bool key_held)
{
if (key_held || key_pressed)
if (key_pressed)
{
if (!key_held)
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
return;
}
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
g_search_flag_start_scan = true;
}
@ -374,8 +378,215 @@ void SEARCH_process_key(key_code_t Key, bool key_pressed, bool key_held)
GENERIC_Key_PTT(key_pressed);
break;
default:
if (!key_held && key_pressed)
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// if (!key_held && key_pressed)
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break;
}
}
void SEARCH_process(void)
{
uint32_t result;
int32_t delta;
uint16_t ctcss_freq;
BK4819_CSS_scan_result_t scan_result;
switch (g_search_css_state)
{
case SEARCH_CSS_STATE_OFF:
if (g_search_freq_css_tick_10ms >= search_freq_css_10ms)
{ // FREQ/CTCSS/CDCSS search timeout
if (!g_search_single_frequency)
{ // FREQ search timeout
#ifdef ENABLE_FREQ_SEARCH_TIMEOUT
BK4819_DisableFrequencyScan();
g_search_css_state = SEARCH_CSS_STATE_FREQ_FAILED;
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
break;
#endif
}
else
{ // CTCSS/CDCSS search timeout
#ifdef ENABLE_CODE_SEARCH_TIMEOUT
BK4819_DisableFrequencyScan();
g_search_css_state = SEARCH_CSS_STATE_FREQ_FAILED;
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
break;
#endif
}
}
if (!BK4819_GetFrequencyScanResult(&result))
break; // still scanning
// accept only within 1kHz
delta = result - g_search_frequency;
g_search_hit_count = (abs(delta) < 100) ? g_search_hit_count + 1 : 0;
BK4819_DisableFrequencyScan();
g_search_frequency = result;
if (g_search_hit_count < 3)
{ // keep scanning for an RF carrier
BK4819_EnableFrequencyScan();
}
else
{ // 3 matching consecutive results
//
// RF carrier found, move on to CTCSS/CDCSS search
BK4819_SetScanFrequency(g_search_frequency);
g_search_css_result_type = CODE_TYPE_NONE;
g_search_css_result_code = 0xff;
g_search_hit_count = 0;
g_search_use_css_result = false;
g_search_freq_css_tick_10ms = 0;
g_search_css_state = SEARCH_CSS_STATE_SCANNING;
g_update_status = true;
g_update_display = true;
GUI_SelectNextDisplay(DISPLAY_SEARCH);
}
g_search_tick_10ms = search_10ms;
break;
case SEARCH_CSS_STATE_SCANNING:
if (g_search_freq_css_tick_10ms >= search_freq_css_10ms)
{ // CTCSS/CDCSS search timeout
#if defined(ENABLE_CODE_SEARCH_TIMEOUT)
g_search_css_state = SEARCH_CSS_STATE_FAILED;
// g_search_hit_count = 0;
// g_search_css_result_type = CODE_TYPE_NONE;
// g_search_css_result_code = 0xff;
// g_search_use_css_result = false;
BK4819_Idle();
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
break;
#else
if (!g_search_single_frequency)
{
g_search_css_state = SEARCH_CSS_STATE_FAILED;
BK4819_Idle();
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
break;
}
#endif
}
scan_result = BK4819_GetCxCSSScanResult(&result, &ctcss_freq);
if (scan_result == BK4819_CSS_RESULT_NOT_FOUND)
break;
BK4819_Idle();
if (scan_result == BK4819_CSS_RESULT_CDCSS)
{ // found a CDCSS code
const uint8_t code = DCS_GetCdcssCode(result);
if (code != 0xFF)
{
g_search_hit_count = 0;
g_search_css_result_type = CODE_TYPE_DIGITAL;
g_search_css_result_code = code;
g_search_css_state = SEARCH_CSS_STATE_FOUND;
g_search_use_css_result = true;
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
}
else
{
g_search_hit_count = 0;
g_search_css_result_type = CODE_TYPE_NONE;
g_search_css_result_code = 0xff;
g_search_use_css_result = false;
}
}
else
if (scan_result == BK4819_CSS_RESULT_CTCSS)
{ // found a CTCSS tone
const uint8_t code = DCS_GetCtcssCode(ctcss_freq);
if (code != 0xFF)
{
if (code == g_search_css_result_code && g_search_css_result_type == CODE_TYPE_CONTINUOUS_TONE)
{ // same code
if (++g_search_hit_count >= 3)
{ // 3 matching consecutive results
g_search_css_state = SEARCH_CSS_STATE_FOUND;
g_search_use_css_result = true;
AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP);
g_update_status = true;
g_update_display = true;
}
}
else
{ // reset
g_search_hit_count = 1;
g_search_css_result_type = CODE_TYPE_CONTINUOUS_TONE;
g_search_css_result_code = code;
g_search_use_css_result = false;
}
}
else
{ // reset
g_search_hit_count = 0;
g_search_css_result_type = CODE_TYPE_NONE;
g_search_css_result_code = 0xff;
g_search_use_css_result = false;
}
}
if (g_search_css_state == SEARCH_CSS_STATE_OFF || g_search_css_state == SEARCH_CSS_STATE_SCANNING)
{ // re-start scan
BK4819_SetScanFrequency(g_search_frequency);
g_search_tick_10ms = search_10ms;
}
GUI_SelectNextDisplay(DISPLAY_SEARCH);
break;
//case SEARCH_CSS_STATE_FOUND:
//case SEARCH_CSS_STATE_FAILED:
//case SEARCH_CSS_STATE_REPEAT:
default:
break;
}
}
@ -438,24 +649,24 @@ void SEARCH_Start(void)
DTMF_clear_RX();
#ifdef ENABLE_VOX
g_vox_lost = false;
#endif
#ifdef ENABLE_VOX
g_vox_lost = false;
#endif
g_cxcss_tail_found = false;
g_cdcss_lost = false;
g_cdcss_code_type = 0;
g_ctcss_lost = false;
g_cxcss_tail_found = false;
g_cdcss_lost = false;
g_cdcss_code_type = 0;
g_ctcss_lost = false;
g_squelch_open = false;
g_search_delay_10ms = scan_freq_css_delay_10ms;
g_search_css_result_type = CODE_TYPE_NONE;
g_search_css_result_code = 0xff;
g_search_hit_count = 0;
g_search_use_css_result = false;
g_search_edit_state = SEARCH_EDIT_STATE_NONE;
g_search_freq_css_timer_10ms = 0;
// g_search_flag_start_scan = false;
g_squelch_open = false;
g_search_css_result_type = CODE_TYPE_NONE;
g_search_css_result_code = 0xff;
g_search_hit_count = 0;
g_search_use_css_result = false;
g_search_edit_state = SEARCH_EDIT_STATE_NONE;
g_search_freq_css_tick_10ms = 0;
g_search_tick_10ms = search_10ms;
// g_search_flag_start_scan = false;
g_request_display_screen = DISPLAY_SEARCH;
g_update_status = true;

View File

@ -50,12 +50,13 @@ extern search_edit_state_t g_search_edit_state;
extern uint8_t g_search_channel;
extern uint32_t g_search_frequency;
extern step_setting_t g_search_step_setting;
extern uint16_t g_search_freq_css_timer_10ms;
extern uint8_t g_search_delay_10ms;
extern uint16_t g_search_freq_css_tick_10ms;
extern uint16_t g_search_tick_10ms;
extern uint8_t g_search_hit_count;
extern bool g_search_use_css_result;
void SEARCH_process_key(key_code_t Key, bool key_pressed, bool key_held);
void SEARCH_process(void);
void SEARCH_Start(void);
#endif

View File

@ -577,7 +577,7 @@ void BOARD_eeprom_load(void)
} __attribute__((packed)) fm;
EEPROM_ReadBuffer(0x0E88, &fm, sizeof(fm));
g_eeprom.fm_selected_frequency = (fm.freq >= FM_RADIO_BAND.lower && fm.freq < FM_RADIO_BAND.upper) ? fm.freq : FM_RADIO_BAND.lower;
g_eeprom.fm_selected_frequency = (fm.freq >= BK1080_freq_lower && fm.freq < BK1080_freq_upper) ? fm.freq : BK1080_freq_lower;
g_eeprom.fm_selected_channel = fm.chan;
g_eeprom.fm_channel_mode = fm.chan_mode ? true : false;
}

View File

@ -19,18 +19,9 @@
#include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/system.h"
#include "frequencies.h"
#include "misc.h"
#if defined(ENABLE_FMRADIO_64_76)
#define BAND 3u
#elif defined(ENABLE_FMRADIO_76_90)
#define BAND 2u
#elif defined(ENABLE_FMRADIO_76_108)
#define BAND 1u
#elif defined(ENABLE_FMRADIO_875_108)
#define BAND 0u
#endif
//#define CHAN_SPACING 0u // 200kHz
#define CHAN_SPACING 1u // 100kHz
//#define CHAN_SPACING 2u // 50kHz
@ -39,6 +30,36 @@
#define SEEK_THRESHOLD 10u
#if defined(ENABLE_FMRADIO_64_108)
const freq_band_table_t FM_RADIO_FREQ_BAND_TABLE[] =
{
{875, 1080},
{760, 1080},
{760, 900},
{640, 760}
};
#elif defined(ENABLE_FMRADIO_875_108)
const freq_band_table_t FM_RADIO_FREQ_BAND_TABLE[] =
{
{875, 1080}
};
#elif defined(ENABLE_FMRADIO_76_108)
const freq_band_table_t FM_RADIO_FREQ_BAND_TABLE[] =
{
{760, 1080}
};
#elif defined(ENABLE_FMRADIO_76_90)
const freq_band_table_t FM_RADIO_FREQ_BAND_TABLE[] =
{
{760, 900}
};
#elif defined(ENABLE_FMRADIO_64_76)
const freq_band_table_t FM_RADIO_FREQ_BAND_TABLE[] =
{
{640, 760}
};
#endif
static const uint16_t BK1080_RegisterTable[] =
{
0x0008, // 0x00
@ -46,7 +67,7 @@ static const uint16_t BK1080_RegisterTable[] =
(1u << 9) | (1u << 0), // 0x02 0x0201 0000001000000001
0x0000, // 0x03
0x40C0, // 0x04 0100000011000000
(SEEK_THRESHOLD << 8) | (BAND << 6) | (CHAN_SPACING << 4) | (VOLUME << 0), // 0x0A1F, // 0x05 00001010 00 01 1111
(SEEK_THRESHOLD << 8) | (0u << 6) | (CHAN_SPACING << 4) | (VOLUME << 0), // 0x0A1F, // 0x05 00001010 00 01 1111
0x002E, // 0x06 0000000000101110
0x02FF, // 0x07 0000001011111111
0x5B11, // 0x08 0101101100010001
@ -78,6 +99,8 @@ static const uint16_t BK1080_RegisterTable[] =
};
bool is_init;
uint16_t BK1080_freq_lower;
uint16_t BK1080_freq_upper;
uint16_t BK1080_BaseFrequency;
uint16_t BK1080_FrequencyDeviation;
@ -85,6 +108,24 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
{
unsigned int i;
BK1080_freq_lower = 0xffff;
BK1080_freq_upper = 0;
for (i = 0; i < ARRAY_SIZE(FM_RADIO_FREQ_BAND_TABLE); i++)
{
const unsigned int lower = FM_RADIO_FREQ_BAND_TABLE[i].lower;
const unsigned int upper = FM_RADIO_FREQ_BAND_TABLE[i].upper;
if (BK1080_freq_lower > lower)
BK1080_freq_lower = lower;
if (BK1080_freq_lower > upper)
BK1080_freq_lower = upper;
if (BK1080_freq_upper < lower)
BK1080_freq_upper = lower;
if (BK1080_freq_upper < upper)
BK1080_freq_upper = upper;
}
if (bDoScan)
{
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BK1080);
@ -108,9 +149,6 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, (1u << 9) | (1u << 0));
}
// BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, 0x0A5F);
BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, (SEEK_THRESHOLD << 8) | (BAND << 6) | (CHAN_SPACING << 4) | (VOLUME << 0));
BK1080_SetFrequency(Frequency);
}
else
@ -128,7 +166,6 @@ uint16_t BK1080_ReadRegister(BK1080_Register_t Register)
I2C_Write((Register << 1) | I2C_READ);
I2C_ReadBuffer(Value, sizeof(Value));
I2C_Stop();
return (Value[0] << 8) | Value[1];
}
@ -153,27 +190,22 @@ void BK1080_Mute(bool Mute)
void BK1080_SetFrequency(uint16_t Frequency)
{
#if defined(ENABLE_FMRADIO_64_76)
uint16_t band;
uint16_t channel;
const uint16_t channel = Frequency - 640; // 100kHz channel spacing
// determine which band to use
for (band = 0; band < ARRAY_SIZE(FM_RADIO_FREQ_BAND_TABLE); band++)
if (Frequency >= FM_RADIO_FREQ_BAND_TABLE[band].lower && Frequency < FM_RADIO_FREQ_BAND_TABLE[band].upper)
break;
#elif defined(ENABLE_FMRADIO_76_90)
if (band >= ARRAY_SIZE(FM_RADIO_FREQ_BAND_TABLE))
return;
channel = Frequency - FM_RADIO_FREQ_BAND_TABLE[band].lower; // 100kHz channel spacing
const uint16_t channel = Frequency - 760; // 100kHz channel spacing
#elif defined(ENABLE_FMRADIO_76_108)
const uint16_t channel = Frequency - 760; // 100kHz channel spacing
#elif defined(ENABLE_FMRADIO_875_108)
// const uint16_t channel = Frequency - 760;
const uint16_t channel = Frequency - 875; // 100kHz channel spacing
#endif
BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, (SEEK_THRESHOLD << 8) | (band << 6) | (CHAN_SPACING << 4) | (VOLUME << 0));
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, channel);
// SYSTEM_DelayMs(10);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, channel | (1u << 15));
}

View File

@ -22,6 +22,8 @@
#include "driver/bk1080-regs.h"
extern uint16_t BK1080_freq_lower;
extern uint16_t BK1080_freq_upper;
extern uint16_t BK1080_BaseFrequency;
extern uint16_t BK1080_FrequencyDeviation;

View File

@ -94,6 +94,8 @@ void BK4819_Init(void)
(58u << 4) | // AF Rx Gain-2
( 8u << 0)); // AF DAC Gain (after Gain-1 and Gain-2)
BK4819_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++)
@ -1258,18 +1260,19 @@ void BK4819_PrepareTransmit(void)
{
// BK4819_ExitBypass();
BK4819_ExitTxMute();
BK4819_TxOn_Beep();
BK4819_sub_audible();
}
void BK4819_TxOn_Beep(void)
void BK4819_sub_audible(void)
{
BK4819_WriteRegister(0x37, 0x1D0F); // 0001110100001111
#ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT
BK4819_WriteRegister(0x52, (1u << 15) | (2u << 13) | (0u << 12) | (10u << 6) | (15u << 0));
#else
BK4819_WriteRegister(0x52, (0u << 15) | (0u << 13) | (0u << 12) | (10u << 6) | (15u << 0)); // 0x028F); // 0 00 0 001010 001111
#endif
#ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT
BK4819_GenTail(2); // 180 deg
#else
// BK4819_GenTail(4);
BK4819_WriteRegister(0x52, (0u << 15) | (0u << 13) | (0u << 12) | (10u << 6) | (15u << 0)); // 0x028F); // 0 00 0 001010 001111
#endif
BK4819_WriteRegister(0x30, 0);
BK4819_WriteRegister(0x30,
@ -1505,11 +1508,11 @@ void BK4819_TransmitTone(bool bLocalLoopback, uint32_t Frequency)
BK4819_ExitTxMute();
}
void BK4819_GenTail(uint8_t Tail)
void BK4819_GenTail(const unsigned int tail)
{
// REG_52
//
// <15> 0 Enable 120/180/240 degree shift CTCSS or 134.4Hz Tail when CDCSS mode
// <15> 0 120/180/240 degree shift CTCSS or 134.4Hz Tail when CDCSS mode
// 0 = Normal
// 1 = Enable
//
@ -1519,49 +1522,49 @@ void BK4819_GenTail(uint8_t Tail)
// 10 = CTCSS0 180° phase shift
// 11 = CTCSS0 240° phase shift
//
// <12> 0 CTCSSDetectionThreshold Mode
// <12> 0 CTCSS Detection Threshold Mode
// 1 = ~0.1%
// 0 = 0.1 Hz
//
// <11:6> 0x0A CTCSS found detect threshold
// <11:6> 10 CTCSS found detect threshold 0 ~ 63
//
// <5:0> 0x0F CTCSS lost detect threshold
// <5:0> 15 CTCSS lost detect threshold 0 ~ 63
// REG_07 <15:0>
//
// When <13> = 0 for CTC1
// <12:0> = CTC1 frequency control word =
// freq(Hz) * 20.64888 for XTAL 13M/26M or
// freq(Hz) * 20.97152 for XTAL 12.8M/19.2M/25.6M/38.4M
//
// When <13> = 1 for CTC2 (Tail 55Hz Rx detection)
// <12:0> = CTC2 (should below 100Hz) frequency control word =
// 25391 / freq(Hz) for XTAL 13M/26M or
// 25000 / freq(Hz) for XTAL 12.8M/19.2M/25.6M/38.4M
//
// When <13> = 2 for CDCSS 134.4Hz
// <12:0> = CDCSS baud rate frequency (134.4Hz) control word =
// freq(Hz) * 20.64888 for XTAL 13M/26M or
// freq(Hz)*20.97152 for XTAL 12.8M/19.2M/25.6M/38.4M
switch (Tail)
uint16_t tail_phase_shift = 1;
uint16_t ctcss_tail_mode_selection = 0;
uint16_t ctcss_detect_threshold_mode = 0;
// uint16_t ctcss_found_threshold = 10;
// uint16_t ctcss_lost_threshold = 15;
uint16_t ctcss_found_threshold = 20;
uint16_t ctcss_lost_threshold = 30;
switch (tail)
{
case 0: // 134.4Hz CTCSS Tail
BK4819_WriteRegister(0x52, 0x828F); // 1 00 0 001010 001111
break;
case 1: // 120° phase shift
BK4819_WriteRegister(0x52, 0xA28F); // 1 01 0 001010 001111
ctcss_tail_mode_selection = 1;
break;
case 2: // 180° phase shift
BK4819_WriteRegister(0x52, 0xC28F); // 1 10 0 001010 001111
ctcss_tail_mode_selection = 2;
break;
case 3: // 240° phase shift
BK4819_WriteRegister(0x52, 0xE28F); // 1 11 0 001010 001111
ctcss_tail_mode_selection = 3;
break;
default:
case 4: // 55Hz tone freq
BK4819_WriteRegister(0x07, 0x046f); // 0 00 0 010001 101111
tail_phase_shift = 0;
ctcss_found_threshold = 17;
ctcss_lost_threshold = 47;
break;
}
BK4819_WriteRegister(0x52,
(tail_phase_shift << 15) |
(ctcss_tail_mode_selection << 13) |
(ctcss_detect_threshold_mode << 12) |
(ctcss_found_threshold << 6) |
(ctcss_lost_threshold << 0));
}
void BK4819_EnableCDCSS(void)

View File

@ -119,7 +119,7 @@ void BK4819_TurnsOffTones_TurnsOnRX(void);
void BK4819_reset_fsk(void);
void BK4819_Idle(void);
void BK4819_PrepareTransmit(void);
void BK4819_TxOn_Beep(void);
void BK4819_sub_audible(void);
void BK4819_ExitSubAu(void);
void BK4819_Conditional_RX_TurnOn(void);
@ -133,7 +133,7 @@ void BK4819_PlayDTMFString(const char *pString, bool bDelayFirst, uint16_t F
void BK4819_TransmitTone(bool bLocalLoopback, uint32_t Frequency);
void BK4819_GenTail(uint8_t Tail);
void BK4819_GenTail(const unsigned int tail);
void BK4819_EnableCDCSS(void);
void BK4819_EnableCTCSS(void);

Binary file not shown.

Binary file not shown.

View File

@ -26,17 +26,6 @@ uint32_t g_aircopy_freq = 41002500;
const freq_band_table_t AIR_BAND = {10800000, 13700000};
// FM broadcast band lower/upper limit
#if defined(ENABLE_FMRADIO_64_76)
const freq_band_table_t FM_RADIO_BAND = {640, 760};
#elif defined(ENABLE_FMRADIO_76_90)
const freq_band_table_t FM_RADIO_BAND = {760, 900};
#elif defined(ENABLE_FMRADIO_76_108)
const freq_band_table_t FM_RADIO_BAND = {760, 1080};
#elif defined(ENABLE_FMRADIO_875_108)
const freq_band_table_t FM_RADIO_BAND = {875, 1080};
#endif
// 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};

View File

@ -43,10 +43,6 @@ extern uint32_t g_aircopy_freq;
extern const freq_band_table_t AIR_BAND;
#ifdef ENABLE_FMRADIO
extern const freq_band_table_t FM_RADIO_BAND;
#endif
extern const freq_band_table_t BX4819_BAND1;
extern const freq_band_table_t BX4819_BAND2;

4
misc.c
View File

@ -52,8 +52,8 @@ const uint8_t key_debounce_10ms = 30 / 10; // 30ms
const uint8_t key_long_press_10ms = 300 / 10; // 300ms
const uint8_t key_repeat_10ms = 50 / 10; // 50ms
const uint16_t scan_freq_css_timeout_10ms = 10000 / 10; // 10 seconds
const uint8_t scan_freq_css_delay_10ms = 210 / 10; // 210ms .. don't reduce this
const uint16_t search_freq_css_10ms = 10000 / 10; // 10 seconds
const uint16_t search_10ms = 210 / 10; // 210ms .. don't reduce this
#ifdef ENABLE_VOX
const uint16_t dual_watch_delay_after_vox_10ms = 200 / 10; // 200ms

4
misc.h
View File

@ -140,8 +140,8 @@ extern const uint8_t key_debounce_10ms;
extern const uint8_t key_long_press_10ms;
extern const uint8_t key_repeat_10ms;
extern const uint16_t scan_freq_css_timeout_10ms;
extern const uint8_t scan_freq_css_delay_10ms;
extern const uint16_t search_freq_css_10ms;
extern const uint16_t search_10ms;
extern const uint16_t battery_save_count_10ms;

View File

@ -133,7 +133,7 @@ void UI_DisplaySearch(void)
case SEARCH_CSS_STATE_SCANNING: // rolling indicator
memset(String, 0, sizeof(String));
memset(String, '.', 15);
String[(g_search_freq_css_timer_10ms / 32) % 15] = '#';
String[(g_search_freq_css_tick_10ms / 32) % 15] = '#';
break;
case SEARCH_CSS_STATE_FOUND: