0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 06:11:24 +03:00

ctcss phase stuff + fast manual freq up/dn scanning update

This commit is contained in:
OneOfEleven 2023-10-31 22:02:54 +00:00
parent 2522b4184a
commit 010ee10516
20 changed files with 532 additions and 552 deletions

View File

@ -36,6 +36,7 @@ ENABLE_ALARM := 0
ENABLE_TX1750 := 0 ENABLE_TX1750 := 0
# MDC1200 2.8 kB # MDC1200 2.8 kB
ENABLE_MDC1200 := 1 ENABLE_MDC1200 := 1
ENABLE_MDC1200_SHOW_OP_ARG := 1
ENABLE_PWRON_PASSWORD := 0 ENABLE_PWRON_PASSWORD := 0
ENABLE_RESET_AES_KEY := 1 ENABLE_RESET_AES_KEY := 1
ENABLE_BIG_FREQ := 0 ENABLE_BIG_FREQ := 0
@ -360,6 +361,9 @@ endif
ifeq ($(ENABLE_MDC1200),1) ifeq ($(ENABLE_MDC1200),1)
CFLAGS += -DENABLE_MDC1200 CFLAGS += -DENABLE_MDC1200
endif endif
ifeq ($(ENABLE_MDC1200_SHOW_OP_ARG),1)
CFLAGS += -DENABLE_MDC1200_SHOW_OP_ARG
endif
ifeq ($(ENABLE_PWRON_PASSWORD),1) ifeq ($(ENABLE_PWRON_PASSWORD),1)
CFLAGS += -DENABLE_PWRON_PASSWORD CFLAGS += -DENABLE_PWRON_PASSWORD
endif endif

View File

@ -57,6 +57,8 @@ ENABLE_VOX := 0 voice operated transmission
ENABLE_REDUCE_LOW_MID_TX_POWER := 1 reduce the low and mid TX power levels (high remains unchanged) ENABLE_REDUCE_LOW_MID_TX_POWER := 1 reduce the low and mid TX power levels (high remains unchanged)
ENABLE_ALARM := 0 TX alarms ENABLE_ALARM := 0 TX alarms
ENABLE_1750HZ := 0 side key 1750Hz TX tone (older style repeater access) ENABLE_1750HZ := 0 side key 1750Hz TX tone (older style repeater access)
ENABLE_MDC1200 := 0 enable MDC1200 TX/RX + menu TX option
ENABLE_MDC1200_SHOW_OP_ARG := 1 show RX opcode and argument values when MDC1200 is RX'ed
ENABLE_PWRON_PASSWORD := 0 include power-on password code ENABLE_PWRON_PASSWORD := 0 include power-on password code
ENABLE_RESET_AES_KEY := 1 '1' = reset/clear the AES key stored in the eeprom (only if it's set) ENABLE_RESET_AES_KEY := 1 '1' = reset/clear the AES key stored in the eeprom (only if it's set)
ENABLE_BIG_FREQ := 0 big font frequencies (like original QS firmware) ENABLE_BIG_FREQ := 0 big font frequencies (like original QS firmware)

271
app/app.c
View File

@ -92,8 +92,7 @@ static void APP_update_rssi(const int vfo)
g_current_rssi[vfo] = rssi; g_current_rssi[vfo] = rssi;
// if (g_squelch_open || g_monitor_enabled) UI_update_rssi(rssi, vfo);
UI_update_rssi(rssi, vfo);
} }
static void APP_check_for_new_receive(void) static void APP_check_for_new_receive(void)
@ -109,7 +108,7 @@ static void APP_check_for_new_receive(void)
if (g_css_scan_mode != CSS_SCAN_MODE_OFF && g_rx_reception_mode == RX_MODE_NONE) if (g_css_scan_mode != CSS_SCAN_MODE_OFF && g_rx_reception_mode == RX_MODE_NONE)
{ // CTCSS/DTS scanning { // CTCSS/DTS scanning
g_scan_pause_tick_10ms = scan_pause_code_10ms; g_scan_pause_tick_10ms = scan_pause_code_10ms;
g_scan_pause_time_mode = false; g_scan_pause_time_mode = false;
g_rx_reception_mode = RX_MODE_DETECTED; g_rx_reception_mode = RX_MODE_DETECTED;
} }
@ -121,7 +120,7 @@ static void APP_check_for_new_receive(void)
if (g_is_noaa_mode) if (g_is_noaa_mode)
{ {
g_noaa_tick_10ms = noaa_tick_3_10ms; g_noaa_tick_10ms = noaa_tick_3_10ms;
g_schedule_noaa = false; g_schedule_noaa = false;
} }
#endif #endif
@ -150,7 +149,7 @@ static void APP_check_for_new_receive(void)
g_rx_reception_mode = RX_MODE_DETECTED; g_rx_reception_mode = RX_MODE_DETECTED;
done: done:
// if (g_current_function != FUNCTION_NEW_RECEIVE) if (g_current_function != FUNCTION_NEW_RECEIVE)
{ {
FUNCTION_Select(FUNCTION_NEW_RECEIVE); FUNCTION_Select(FUNCTION_NEW_RECEIVE);
@ -162,11 +161,10 @@ done:
//BK4819_WriteRegister(0x59, (1u << 12) | fsk_reg59); //BK4819_WriteRegister(0x59, (1u << 12) | fsk_reg59);
} }
#endif #endif
APP_update_rssi(g_eeprom.rx_vfo);
g_update_rssi = true;
} }
APP_update_rssi(g_eeprom.rx_vfo);
g_update_rssi = true;
// }
} }
static void APP_process_new_receive(void) static void APP_process_new_receive(void)
@ -194,14 +192,14 @@ static void APP_process_new_receive(void)
if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_noaa_tick_10ms > 0) if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_noaa_tick_10ms > 0)
{ {
g_noaa_tick_10ms = 0; g_noaa_tick_10ms = 0;
flag = true; flag = true;
} }
#endif #endif
if (g_ctcss_lost && g_current_code_type == CODE_TYPE_CONTINUOUS_TONE) if (g_ctcss_lost && g_current_code_type == CODE_TYPE_CONTINUOUS_TONE)
{ {
flag = true;
g_found_ctcss = false; g_found_ctcss = false;
flag = true;
} }
if (g_cdcss_lost && g_cdcss_code_type == CDCSS_POSITIVE_CODE && (g_current_code_type == CODE_TYPE_DIGITAL || g_current_code_type == CODE_TYPE_REVERSE_DIGITAL)) if (g_cdcss_lost && g_cdcss_code_type == CDCSS_POSITIVE_CODE && (g_current_code_type == CODE_TYPE_DIGITAL || g_current_code_type == CODE_TYPE_REVERSE_DIGITAL))
@ -229,7 +227,7 @@ static void APP_process_new_receive(void)
if (g_rx_reception_mode == RX_MODE_DETECTED) if (g_rx_reception_mode == RX_MODE_DETECTED)
{ {
g_dual_watch_tick_10ms = g_eeprom.scan_hold_time_500ms * 50; g_dual_watch_tick_10ms = g_eeprom.scan_hold_time_500ms * 50;
g_rx_reception_mode = RX_MODE_LISTENING; g_rx_reception_mode = RX_MODE_LISTENING;
g_update_status = true; g_update_status = true;
g_update_display = true; g_update_display = true;
@ -269,7 +267,7 @@ static void APP_process_rx(void)
case SCAN_RESUME_TIME: // stay only for a limited time case SCAN_RESUME_TIME: // stay only for a limited time
break; break;
case SCAN_RESUME_CARRIER: // stay untill the carrier goes away case SCAN_RESUME_CARRIER: // stay untill the carrier goes away
g_scan_pause_tick_10ms = g_eeprom.scan_hold_time_500ms * 50; g_scan_pause_tick_10ms = g_eeprom.scan_hold_time_500ms * 50;
g_scan_pause_time_mode = false; g_scan_pause_time_mode = false;
break; break;
case SCAN_RESUME_STOP: // stop scan once we find any signal case SCAN_RESUME_STOP: // stop scan once we find any signal
@ -321,11 +319,11 @@ static void APP_process_rx(void)
switch (g_current_code_type) switch (g_current_code_type)
{ {
case CODE_TYPE_NONE: case CODE_TYPE_NONE:
if (g_eeprom.squelch_level) if (g_eeprom.squelch_level > 0)
{ {
if (g_cxcss_tail_found) if (g_cxcss_tail_found)
{ {
Mode = END_OF_RX_MODE_TTE; Mode = END_OF_RX_MODE_TTE;
g_cxcss_tail_found = false; g_cxcss_tail_found = false;
} }
} }
@ -339,13 +337,13 @@ static void APP_process_rx(void)
else else
if (!g_found_ctcss) if (!g_found_ctcss)
{ {
g_found_ctcss = true; g_found_ctcss = true;
g_found_ctcss_tick_10ms = 100; // 1 sec g_found_ctcss_tick_10ms = 100; // 1 sec
} }
if (g_cxcss_tail_found) if (g_cxcss_tail_found)
{ {
Mode = END_OF_RX_MODE_TTE; Mode = END_OF_RX_MODE_TTE;
g_cxcss_tail_found = false; g_cxcss_tail_found = false;
} }
break; break;
@ -359,7 +357,7 @@ static void APP_process_rx(void)
else else
if (!g_found_cdcss) if (!g_found_cdcss)
{ {
g_found_cdcss = true; g_found_cdcss = true;
g_found_cdcss_tick_10ms = 100; // 1 sec g_found_cdcss_tick_10ms = 100; // 1 sec
} }
@ -412,10 +410,9 @@ Skip:
break; break;
case END_OF_RX_MODE_TTE: case END_OF_RX_MODE_TTE:
if (g_eeprom.tail_note_elimination) if (g_eeprom.tail_note_elimination)
{ {
if (!g_squelch_open && !g_monitor_enabled) if (!g_monitor_enabled)
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
g_tail_tone_elimination_tick_10ms = 20; // 200ms g_tail_tone_elimination_tick_10ms = 20; // 200ms
@ -470,6 +467,11 @@ bool APP_start_listening(void)
if (g_scan_state_dir != SCAN_STATE_DIR_OFF) if (g_scan_state_dir != SCAN_STATE_DIR_OFF)
{ // we're RF scanning { // we're RF scanning
g_rx_vfo->freq_in_channel = 0xff;
if (IS_FREQ_CHANNEL(g_scan_next_channel))
g_rx_vfo->freq_in_channel = BOARD_find_channel(g_rx_vfo->freq_config_rx.frequency);
switch (g_eeprom.scan_resume_mode) switch (g_eeprom.scan_resume_mode)
{ {
case SCAN_RESUME_TIME: case SCAN_RESUME_TIME:
@ -629,6 +631,9 @@ void APP_stop_scan(void)
g_rx_vfo->freq_config_rx.frequency = g_scan_restore_frequency; g_rx_vfo->freq_config_rx.frequency = g_scan_restore_frequency;
// find the first channel that contains this frequency
g_rx_vfo->freq_in_channel = BOARD_find_channel(g_rx_vfo->freq_config_rx.frequency);
RADIO_ApplyOffset(g_rx_vfo, false); RADIO_ApplyOffset(g_rx_vfo, false);
RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo); RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo);
RADIO_setup_registers(true); RADIO_setup_registers(true);
@ -670,6 +675,8 @@ static void APP_next_freq(void)
g_rx_vfo->freq_config_rx.frequency = frequency; g_rx_vfo->freq_config_rx.frequency = frequency;
g_rx_vfo->freq_in_channel = 0xff;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) #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", frequency, new_band);
#endif #endif
@ -864,81 +871,111 @@ void APP_process_radio_interrupts(void)
if (g_current_display_screen == DISPLAY_SEARCH) if (g_current_display_screen == DISPLAY_SEARCH)
return; return;
while (BK4819_ReadRegister(0x0C) & (1u << 0)) while (1)
{ // BK chip interrupt request { // BK4819 chip interrupt request
uint16_t interrupt_bits; uint16_t int_bits;
const uint16_t reg_c = BK4819_ReadRegister(0x0C);
if ((reg_c & 1u) == 0)
break;
BK4819_WriteRegister(0x02, 0); BK4819_WriteRegister(0x02, 0);
interrupt_bits = BK4819_ReadRegister(0x02); int_bits = BK4819_ReadRegister(0x02);
if (interrupt_bits & BK4819_REG_02_DTMF_5TONE_FOUND) #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("reg_c int_bits %04X\r\n", reg_c, int_bits);
#endif
if (int_bits & BK4819_REG_02_DTMF_5TONE_FOUND)
{ // save the RX'ed DTMF character { // save the RX'ed DTMF character
const char c = DTMF_GetCharacter(BK4819_GetDTMF_5TONE_Code()); const char c = DTMF_GetCharacter(BK4819_GetDTMF_5TONE_Code());
if (c != 0xff) if (c != 0xff && g_current_function != FUNCTION_TRANSMIT)
{ {
if (g_current_function != FUNCTION_TRANSMIT) if (g_setting_live_dtmf_decoder)
{ {
if (g_setting_live_dtmf_decoder) size_t len = strlen(g_dtmf_rx_live);
{ if (len >= (sizeof(g_dtmf_rx_live) - 1))
size_t len = strlen(g_dtmf_rx_live); { // make room
if (len >= (sizeof(g_dtmf_rx_live) - 1)) memmove(&g_dtmf_rx_live[0], &g_dtmf_rx_live[1], sizeof(g_dtmf_rx_live) - 1);
{ // make room len--;
memmove(&g_dtmf_rx_live[0], &g_dtmf_rx_live[1], sizeof(g_dtmf_rx_live) - 1);
len--;
}
g_dtmf_rx_live[len++] = c;
g_dtmf_rx_live[len] = 0;
g_dtmf_rx_live_timeout = dtmf_rx_live_timeout_500ms; // time till we delete it
g_update_display = true;
} }
g_dtmf_rx_live[len++] = c;
g_dtmf_rx_live[len] = 0;
g_dtmf_rx_live_timeout = dtmf_rx_live_timeout_500ms; // time till we delete it
g_update_display = true;
}
#ifdef ENABLE_KILL_REVIVE #ifdef ENABLE_KILL_REVIVE
if (g_rx_vfo->dtmf_decoding_enable || g_setting_radio_disabled) if (g_rx_vfo->dtmf_decoding_enable || g_setting_radio_disabled)
#else #else
if (g_rx_vfo->dtmf_decoding_enable) if (g_rx_vfo->dtmf_decoding_enable)
#endif #endif
{ {
if (g_dtmf_rx_index >= (sizeof(g_dtmf_rx) - 1)) if (g_dtmf_rx_index >= (sizeof(g_dtmf_rx) - 1))
{ // make room { // make room
memmove(&g_dtmf_rx[0], &g_dtmf_rx[1], sizeof(g_dtmf_rx) - 1); memmove(&g_dtmf_rx[0], &g_dtmf_rx[1], sizeof(g_dtmf_rx) - 1);
g_dtmf_rx_index--; g_dtmf_rx_index--;
}
g_dtmf_rx[g_dtmf_rx_index++] = c;
g_dtmf_rx[g_dtmf_rx_index] = 0;
g_dtmf_rx_timeout = dtmf_rx_timeout_500ms; // time till we delete it
g_dtmf_rx_pending = true;
DTMF_HandleRequest();
} }
g_dtmf_rx[g_dtmf_rx_index++] = c;
g_dtmf_rx[g_dtmf_rx_index] = 0;
g_dtmf_rx_timeout = dtmf_rx_timeout_500ms; // time till we delete it
g_dtmf_rx_pending = true;
DTMF_HandleRequest();
} }
} }
} }
if (interrupt_bits & BK4819_REG_02_CxCSS_TAIL) if (int_bits & BK4819_REG_02_CxCSS_TAIL)
g_cxcss_tail_found = true; {
g_cxcss_tail_found = true;
g_ctcss_tail_phase_shift_rx = (reg_c >> 12) & 3u;
if (interrupt_bits & BK4819_REG_02_CDCSS_LOST) #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("cxcss tail %u\r\n", g_ctcss_tail_phase_shift_rx);
#endif
}
if (int_bits & BK4819_REG_02_CDCSS_LOST)
{ {
g_cdcss_lost = true; g_cdcss_lost = true;
g_cdcss_code_type = BK4819_get_CDCSS_code_type(); g_cdcss_code_type = BK4819_get_CDCSS_code_type();
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_printf("cdcss lost %u\r\n", g_cdcss_code_type);
#endif
} }
if (interrupt_bits & BK4819_REG_02_CDCSS_FOUND) if (int_bits & BK4819_REG_02_CDCSS_FOUND)
{
g_cdcss_lost = false; g_cdcss_lost = false;
if (interrupt_bits & BK4819_REG_02_CTCSS_LOST) #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("cdcss found\r\n");
#endif
}
if (int_bits & BK4819_REG_02_CTCSS_LOST)
{
g_ctcss_lost = true; g_ctcss_lost = true;
if (interrupt_bits & BK4819_REG_02_CTCSS_FOUND) #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
UART_SendText("cdcss lost\r\n");
#endif
}
if (int_bits & BK4819_REG_02_CTCSS_FOUND)
{
g_ctcss_lost = false; g_ctcss_lost = false;
#ifdef ENABLE_MDC1200 #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
MDC1200_process_rx(interrupt_bits); UART_SendText("ctcss found\r\n");
#endif #endif
}
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
if (interrupt_bits & BK4819_REG_02_VOX_LOST) if (int_bits & BK4819_REG_02_VOX_LOST)
{ {
g_vox_lost = true; g_vox_lost = true;
g_vox_pause_tick_10ms = 10; g_vox_pause_tick_10ms = 10;
@ -960,14 +997,14 @@ void APP_process_radio_interrupts(void)
} }
} }
if (interrupt_bits & BK4819_REG_02_VOX_FOUND) if (int_bits & BK4819_REG_02_VOX_FOUND)
{ {
g_vox_lost = false; g_vox_lost = false;
g_vox_pause_tick_10ms = 0; g_vox_pause_tick_10ms = 0;
} }
#endif #endif
if (interrupt_bits & BK4819_REG_02_SQUELCH_CLOSED) if (int_bits & BK4819_REG_02_SQUELCH_CLOSED)
{ {
g_squelch_open = false; g_squelch_open = false;
@ -986,7 +1023,7 @@ void APP_process_radio_interrupts(void)
g_update_display = true; g_update_display = true;
} }
if (interrupt_bits & BK4819_REG_02_SQUELCH_OPENED) if (int_bits & BK4819_REG_02_SQUELCH_OPENED)
{ {
g_squelch_open = true; g_squelch_open = true;
@ -1002,6 +1039,10 @@ void APP_process_radio_interrupts(void)
g_update_display = true; g_update_display = true;
} }
#ifdef ENABLE_MDC1200
MDC1200_process_rx(int_bits);
#endif
} }
} }
@ -1016,13 +1057,13 @@ void APP_end_tx(void)
//if (g_eeprom.tail_note_elimination && g_eeprom.repeater_tail_tone_elimination > 0) //if (g_eeprom.tail_note_elimination && g_eeprom.repeater_tail_tone_elimination > 0)
if (g_eeprom.tail_note_elimination) if (g_eeprom.tail_note_elimination)
{ // send the CTCSS/DCS tail tone - allows the receivers to mute the usual FM squelch tail/crash { // send the CTCSS/DCS tail tone - allows the receivers to mute the usual FM squelch tail/crash
RADIO_EnableCxCSS(); RADIO_enable_CxCSS_tail();
} }
#if 1 #if 1
else else
{ // TX a short blank carrier after disabling the CTCSS/CDCSS { // TX a short blank carrier after disabling the CTCSS/CDCSS
// this gives the receivers time to mute their RX audio before we drop carrier // this gives the receivers time to mute their RX audio before we drop carrier
BK4819_ExitSubAu(); BK4819_disable_sub_audible();
SYSTEM_DelayMs(200); SYSTEM_DelayMs(200);
} }
#endif #endif
@ -1031,10 +1072,7 @@ void APP_end_tx(void)
RADIO_setup_registers(false); RADIO_setup_registers(false);
if (g_monitor_enabled) if (g_monitor_enabled)
APP_start_listening(); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
if (g_squelch_open || g_monitor_enabled)
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
} }
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
@ -1089,16 +1127,14 @@ void APP_end_tx(void)
APP_end_tx(); APP_end_tx();
if (g_eeprom.repeater_tail_tone_elimination == 0) if (g_eeprom.repeater_tail_tone_elimination == 0)
{ FUNCTION_Select(FUNCTION_FOREGROUND);
//if (g_current_function != FUNCTION_FOREGROUND)
FUNCTION_Select(FUNCTION_FOREGROUND);
}
else else
g_rtte_count_down = g_eeprom.repeater_tail_tone_elimination * 10; g_rtte_count_down = g_eeprom.repeater_tail_tone_elimination * 10;
} }
g_update_status = true; g_update_status = true;
g_update_display = true; g_update_display = true;
g_flag_end_tx = false; g_flag_end_tx = false;
} }
return; return;
@ -1124,7 +1160,7 @@ void APP_end_tx(void)
// called every 10ms // called every 10ms
void APP_check_keys(void) void APP_check_keys(void)
{ {
const bool ptt_pressed = !GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) && (g_serial_config_tick_500ms == 0) && g_setting_tx_enable; const bool ptt_pressed = !GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT);
key_code_t key; key_code_t key;
@ -1138,43 +1174,48 @@ void APP_check_keys(void)
if (ptt_pressed) if (ptt_pressed)
{ // PTT pressed { // PTT pressed
#ifdef ENABLE_KILL_REVIVE
if (!g_setting_radio_disabled) if (!g_ptt_is_pressed && g_serial_config_tick_500ms == 0 && g_setting_tx_enable)
#endif
{ {
#ifdef ENABLE_AIRCOPY #ifdef ENABLE_KILL_REVIVE
if (!g_ptt_is_pressed && g_current_display_screen != DISPLAY_AIRCOPY) if (!g_setting_radio_disabled)
#else #endif
if (!g_ptt_is_pressed)
#endif
{ {
if (++g_ptt_debounce >= 3) // 30ms #ifdef ENABLE_AIRCOPY
{ // start TX'ing if (!g_ptt_is_pressed && g_current_display_screen != DISPLAY_AIRCOPY)
#else
if (!g_ptt_is_pressed)
#endif
{
if (++g_ptt_debounce >= 3) // 30ms debounce
{ // start TX'ing
g_boot_tick_10ms = 0; // cancel the boot-up screen g_boot_tick_10ms = 0; // cancel the boot-up screen
g_ptt_is_pressed = true; g_ptt_is_pressed = ptt_pressed;
g_ptt_was_released = false; g_ptt_was_released = false;
g_ptt_debounce = 0; g_ptt_debounce = 0;
APP_process_key(KEY_PTT, true, false); APP_process_key(KEY_PTT, true, false);
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// UART_printf(" ptt key %3u %u %u\r\n", KEY_PTT, g_ptt_is_pressed, g_ptt_was_released); // UART_printf(" ptt key %3u %u %u\r\n", KEY_PTT, g_ptt_is_pressed, g_ptt_was_released);
#endif #endif
}
} }
else
g_ptt_debounce = 0;
} }
else
g_ptt_debounce = 0;
} }
} }
else else
{ // PTT released { // PTT released
if (g_ptt_is_pressed)
if (g_ptt_is_pressed && g_current_function == FUNCTION_TRANSMIT)
{ {
if (++g_ptt_debounce >= 3) // 30ms if (++g_ptt_debounce >= 3 || g_serial_config_tick_500ms > 0 || !g_setting_tx_enable) // 30ms debounce
{ // stop TX'ing { // stop TX'ing
g_ptt_is_pressed = false; // g_ptt_is_pressed = false;
g_ptt_was_released = true; g_ptt_was_released = true;
g_ptt_debounce = 0; g_ptt_debounce = 0;
@ -1186,7 +1227,12 @@ void APP_check_keys(void)
} }
} }
else else
{
g_ptt_debounce = 0; g_ptt_debounce = 0;
if (g_ptt_is_pressed && !ptt_pressed)
g_ptt_is_pressed = false;
}
} }
// ***************** // *****************
@ -1293,17 +1339,19 @@ void APP_check_keys(void)
#else #else
APP_process_key(g_key_prev, true, g_key_held); APP_process_key(g_key_prev, true, g_key_held);
#endif #endif
//g_update_status = true;
//g_update_display = true;
} }
} }
else else
if (key == KEY_UP || key == KEY_DOWN) if (key == KEY_UP || key == KEY_DOWN)
{ // only the up and down keys are repeatable { // only the up and down keys are repeatable
if (++g_key_debounce_repeat >= (key_long_press_10ms + key_repeat_10ms))
// go much faster if the user is moving up/down freq/channel
const uint8_t repeat_10ms = (g_manual_scanning && g_monitor_enabled && g_current_display_screen == DISPLAY_MAIN) ? 1 : key_repeat_10ms;
if (++g_key_debounce_repeat >= (key_long_press_10ms + repeat_10ms))
{ // key repeat { // key repeat
g_key_debounce_repeat -= key_repeat_10ms;
g_key_debounce_repeat = key_long_press_10ms;
#if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
// UART_printf("rept key %3u %3u, %3u %3u, %u\r\n", key, g_key_prev, g_key_debounce_press, g_key_debounce_repeat, g_key_held); // UART_printf("rept key %3u %3u, %3u %3u, %u\r\n", key, g_key_prev, g_key_debounce_press, g_key_debounce_repeat, g_key_held);
@ -1317,9 +1365,6 @@ void APP_check_keys(void)
#else #else
APP_process_key(g_key_prev, true, g_key_held); APP_process_key(g_key_prev, true, g_key_held);
#endif #endif
//g_update_status = true;
//g_update_display = true;
} }
} }
} }
@ -1373,7 +1418,7 @@ void APP_cancel_user_input_modes(void)
if (g_eeprom.alarm_mode == ALARM_MODE_TONE) if (g_eeprom.alarm_mode == ALARM_MODE_TONE)
{ {
RADIO_tx_eot(); RADIO_tx_eot();
RADIO_EnableCxCSS(); RADIO_enable_CxCSS_tail();
} }
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
@ -1652,7 +1697,7 @@ void APP_process_transmit(void)
{ {
g_alarm_state = ALARM_STATE_ALARM; g_alarm_state = ALARM_STATE_ALARM;
RADIO_EnableCxCSS(); RADIO_enable_CxCSS_tail();
BK4819_SetupPowerAmplifier(0, 0); BK4819_SetupPowerAmplifier(0, 0);
BK4819_set_GPIO_pin(BK4819_GPIO1_PIN29_PA_ENABLE, false); // PA off BK4819_set_GPIO_pin(BK4819_GPIO1_PIN29_PA_ENABLE, false); // PA off
BK4819_Enable_AfDac_DiscMode_TxDsp(); BK4819_Enable_AfDac_DiscMode_TxDsp();

View File

@ -43,6 +43,8 @@
#include "ui/menu.h" #include "ui/menu.h"
#include "ui/ui.h" #include "ui/ui.h"
bool g_manual_scanning;
bool scanning_paused(void) bool scanning_paused(void)
{ {
if ((g_scan_state_dir != SCAN_STATE_DIR_OFF || g_eeprom.dual_watch != DUAL_WATCH_OFF) && if ((g_scan_state_dir != SCAN_STATE_DIR_OFF || g_eeprom.dual_watch != DUAL_WATCH_OFF) &&
@ -862,15 +864,15 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
if (key_pressed && !key_held) if (key_pressed && !key_held)
{ // key just pressed { // key just pressed
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
g_manual_scanning = false;
} }
if (!key_pressed) if (!key_pressed)
{ { // key released
if (g_scan_state_dir == SCAN_STATE_DIR_OFF &&
(Channel <= USER_CHANNEL_LAST || IS_FREQ_CHANNEL(Channel)))
{ // key released
if (g_scan_state_dir == SCAN_STATE_DIR_OFF && (Channel <= USER_CHANNEL_LAST || IS_FREQ_CHANNEL(Channel)))
{
#ifdef ENABLE_SQ_OPEN_WITH_UP_DN_BUTTS #ifdef ENABLE_SQ_OPEN_WITH_UP_DN_BUTTS
if (key_held && !monitor_was_enabled) if (key_held && !monitor_was_enabled)
{ // re-enable the squelch { // re-enable the squelch
@ -894,6 +896,8 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
// UART_printf("save chan %u\r\n", g_tx_vfo->channel_save); // UART_printf("save chan %u\r\n", g_tx_vfo->channel_save);
#endif #endif
} }
g_manual_scanning = false;
} }
if (key_held || !key_pressed) if (key_held || !key_pressed)
@ -985,6 +989,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
if (key_held && key_pressed && !monitor_was_enabled) if (key_held && key_pressed && !monitor_was_enabled)
{ // open the squelch if the user holds the key down { // open the squelch if the user holds the key down
g_manual_scanning = true;
g_monitor_enabled = true; g_monitor_enabled = true;
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
// APP_start_listening(); // APP_start_listening();
@ -1002,18 +1007,6 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
g_tx_vfo->freq_in_channel = 0xff; g_tx_vfo->freq_in_channel = 0xff;
#ifdef ENABLE_SQ_OPEN_WITH_UP_DN_BUTTS
if (!key_held && key_pressed)
monitor_was_enabled = g_monitor_enabled;
if (key_held && key_pressed && !monitor_was_enabled)
{ // open the squelch if the user holds the key down
g_monitor_enabled = true;
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
// APP_start_listening();
}
#endif
Next = RADIO_FindNextChannel(Channel + Direction, Direction, false, 0); Next = RADIO_FindNextChannel(Channel + Direction, Direction, false, 0);
if (Next == 0xFF) if (Next == 0xFF)
return; return;
@ -1021,6 +1014,19 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio
if (Channel == Next) if (Channel == Next)
return; return;
#ifdef ENABLE_SQ_OPEN_WITH_UP_DN_BUTTS
if (!key_held && key_pressed)
monitor_was_enabled = g_monitor_enabled;
if (key_held && key_pressed && !monitor_was_enabled)
{ // open the squelch if the user holds the key down
g_manual_scanning = true;
g_monitor_enabled = true;
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
// APP_start_listening();
}
#endif
g_eeprom.user_channel[g_eeprom.tx_vfo] = Next; g_eeprom.user_channel[g_eeprom.tx_vfo] = Next;
g_eeprom.screen_channel[g_eeprom.tx_vfo] = Next; g_eeprom.screen_channel[g_eeprom.tx_vfo] = Next;

View File

@ -19,6 +19,8 @@
#include "driver/keyboard.h" #include "driver/keyboard.h"
extern bool g_manual_scanning;
void MAIN_process_key(key_code_t Key, bool bKeyPressed, bool bKeyHeld); void MAIN_process_key(key_code_t Key, bool bKeyPressed, bool bKeyHeld);
#endif #endif

View File

@ -177,13 +177,13 @@ int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax)
case MENU_TX_CDCSS: case MENU_TX_CDCSS:
*pMin = 0; *pMin = 0;
*pMax = 208; *pMax = 208;
//*pMax = (ARRAY_SIZE(DCS_OPTIONS) * 2); //*pMax = (ARRAY_SIZE(DCS_CODE_LIST) * 2);
break; break;
case MENU_RX_CTCSS: case MENU_RX_CTCSS:
case MENU_TX_CTCSS: case MENU_TX_CTCSS:
*pMin = 0; *pMin = 0;
*pMax = ARRAY_SIZE(CTCSS_OPTIONS) - 1; *pMax = ARRAY_SIZE(CTCSS_TONE_LIST) - 1;
break; break;
case MENU_BANDWIDTH: case MENU_BANDWIDTH:
@ -477,7 +477,7 @@ void MENU_AcceptSetting(void)
pConfig->code = Code; pConfig->code = Code;
pConfig->code_type = CODE_TYPE_NONE; pConfig->code_type = CODE_TYPE_NONE;
BK4819_ExitSubAu(); BK4819_disable_sub_audible();
} }
else else
{ {
@ -485,7 +485,7 @@ void MENU_AcceptSetting(void)
Code = g_sub_menu_selection - 1; Code = g_sub_menu_selection - 1;
pConfig->code = Code; pConfig->code = Code;
BK4819_SetCTCSSFrequency(CTCSS_OPTIONS[Code]); BK4819_set_CTCSS_freq(CTCSS_TONE_LIST[Code]);
} }
g_request_save_channel = 1; g_request_save_channel = 1;
@ -910,10 +910,10 @@ void MENU_SelectNextCode(void)
if (g_menu_cursor == MENU_RX_CDCSS) if (g_menu_cursor == MENU_RX_CDCSS)
UpperLimit = 208; UpperLimit = 208;
//UpperLimit = ARRAY_SIZE(DCS_OPTIONS); //UpperLimit = ARRAY_SIZE(DCS_CODE_LIST);
else else
if (g_menu_cursor == MENU_RX_CTCSS) if (g_menu_cursor == MENU_RX_CTCSS)
UpperLimit = ARRAY_SIZE(CTCSS_OPTIONS) - 1; UpperLimit = ARRAY_SIZE(CTCSS_TONE_LIST) - 1;
else else
return; return;

View File

@ -450,7 +450,7 @@ void SEARCH_process(void)
// //
// RF carrier found, move on to CTCSS/CDCSS search // RF carrier found, move on to CTCSS/CDCSS search
BK4819_SetScanFrequency(g_search_frequency); BK4819_set_scan_frequency(g_search_frequency);
g_search_css_result_type = CODE_TYPE_NONE; g_search_css_result_type = CODE_TYPE_NONE;
g_search_css_result_code = 0xff; g_search_css_result_code = 0xff;
@ -576,7 +576,7 @@ void SEARCH_process(void)
if (g_search_css_state == SEARCH_CSS_STATE_OFF || g_search_css_state == SEARCH_CSS_STATE_SCANNING) if (g_search_css_state == SEARCH_CSS_STATE_OFF || g_search_css_state == SEARCH_CSS_STATE_SCANNING)
{ // re-start scan { // re-start scan
BK4819_SetScanFrequency(g_search_frequency); BK4819_set_scan_frequency(g_search_frequency);
g_search_tick_10ms = search_10ms; g_search_tick_10ms = search_10ms;
} }
@ -630,7 +630,7 @@ void SEARCH_Start(void)
BK4819_set_rf_filter_path(g_search_frequency); BK4819_set_rf_filter_path(g_search_frequency);
BK4819_SetScanFrequency(g_search_frequency); BK4819_set_scan_frequency(g_search_frequency);
} }
else else
{ {

18
dcs.c
View File

@ -21,7 +21,7 @@
#endif #endif
// CTCSS Hz * 10 // CTCSS Hz * 10
const uint16_t CTCSS_OPTIONS[50] = { const uint16_t CTCSS_TONE_LIST[50] = {
670, 693, 719, 744, 770, 797, 825, 854, 885, 915, 670, 693, 719, 744, 770, 797, 825, 854, 885, 915,
948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273, 948, 974, 1000, 1035, 1072, 1109, 1148, 1188, 1230, 1273,
1318, 1365, 1413, 1462, 1514, 1567, 1598, 1622, 1655, 1679, 1318, 1365, 1413, 1462, 1514, 1567, 1598, 1622, 1655, 1679,
@ -29,7 +29,7 @@ const uint16_t CTCSS_OPTIONS[50] = {
2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541 2035, 2065, 2107, 2181, 2257, 2291, 2336, 2418, 2503, 2541
}; };
const uint16_t DCS_OPTIONS[104] = { const uint16_t DCS_CODE_LIST[104] = {
0x0013, 0x0015, 0x0016, 0x0019, 0x001A, 0x001E, 0x0023, 0x0027, 0x0013, 0x0015, 0x0016, 0x0019, 0x001A, 0x001E, 0x0023, 0x0027,
0x0029, 0x002B, 0x002C, 0x0035, 0x0039, 0x003A, 0x003B, 0x003C, 0x0029, 0x002B, 0x002C, 0x0035, 0x0039, 0x003A, 0x003B, 0x003C,
0x004C, 0x004D, 0x004E, 0x0052, 0x0055, 0x0059, 0x005A, 0x005C, 0x004C, 0x004D, 0x004E, 0x0052, 0x0055, 0x0059, 0x005A, 0x005C,
@ -60,7 +60,7 @@ static uint32_t DCS_CalculateGolay(uint32_t CodeWord)
uint32_t DCS_GetGolayCodeWord(dcs_code_type_t code_type, uint8_t Option) uint32_t DCS_GetGolayCodeWord(dcs_code_type_t code_type, uint8_t Option)
{ {
uint32_t code = DCS_CalculateGolay(DCS_OPTIONS[Option] + 0x800U); uint32_t code = DCS_CalculateGolay(DCS_CODE_LIST[Option] + 0x800U);
if (code_type == CODE_TYPE_REVERSE_DIGITAL) if (code_type == CODE_TYPE_REVERSE_DIGITAL)
code ^= 0x7FFFFF; code ^= 0x7FFFFF;
return code; return code;
@ -76,8 +76,8 @@ uint8_t DCS_GetCdcssCode(uint32_t Code)
if (((Code >> 9) & 0x7U) == 4) if (((Code >> 9) & 0x7U) == 4)
{ {
unsigned int j; unsigned int j;
for (j = 0; j < ARRAY_SIZE(DCS_OPTIONS); j++) for (j = 0; j < ARRAY_SIZE(DCS_CODE_LIST); j++)
if (DCS_OPTIONS[j] == (Code & 0x1FF)) if (DCS_CODE_LIST[j] == (Code & 0x1FF))
if (DCS_GetGolayCodeWord(2, j) == Code) if (DCS_GetGolayCodeWord(2, j) == Code)
return j; return j;
} }
@ -95,13 +95,13 @@ uint8_t DCS_GetCtcssCode(int Code)
{ {
unsigned int i; unsigned int i;
uint8_t Result = 0xFF; uint8_t Result = 0xFF;
int Smallest = ARRAY_SIZE(CTCSS_OPTIONS); int Smallest = ARRAY_SIZE(CTCSS_TONE_LIST);
for (i = 0; i < ARRAY_SIZE(CTCSS_OPTIONS); i++) for (i = 0; i < ARRAY_SIZE(CTCSS_TONE_LIST); i++)
{ {
int Delta = Code - CTCSS_OPTIONS[i]; int Delta = Code - CTCSS_TONE_LIST[i];
if (Delta < 0) if (Delta < 0)
Delta = -(Code - CTCSS_OPTIONS[i]); Delta = -(Code - CTCSS_TONE_LIST[i]);
if (Smallest > Delta) if (Smallest > Delta)
{ {
Smallest = Delta; Smallest = Delta;

4
dcs.h
View File

@ -34,8 +34,8 @@ enum {
CDCSS_NEGATIVE_CODE = 2U, CDCSS_NEGATIVE_CODE = 2U,
}; };
extern const uint16_t CTCSS_OPTIONS[50]; extern const uint16_t CTCSS_TONE_LIST[50];
extern const uint16_t DCS_OPTIONS[104]; extern const uint16_t DCS_CODE_LIST[104];
uint32_t DCS_GetGolayCodeWord(dcs_code_type_t code_type, uint8_t Option); uint32_t DCS_GetGolayCodeWord(dcs_code_type_t code_type, uint8_t Option);
uint8_t DCS_GetCdcssCode(uint32_t Code); uint8_t DCS_GetCdcssCode(uint32_t Code);

View File

@ -51,8 +51,9 @@ void BK4819_Init(void)
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SCL);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_BK4819_SDA);
BK4819_WriteRegister(0x00, 0x8000); // reset the chip
BK4819_WriteRegister(0x00, 0x0000); BK4819_WriteRegister(0x00, (1u << 15));
BK4819_WriteRegister(0x00, 0);
BK4819_WriteRegister(0x37, 0x1D0F); BK4819_WriteRegister(0x37, 0x1D0F);
BK4819_WriteRegister(0x36, 0x0022); BK4819_WriteRegister(0x36, 0x0022);
@ -92,7 +93,7 @@ void BK4819_Init(void)
(58u << 4) | // AF Rx Gain-2 (58u << 4) | // AF Rx Gain-2
( 8u << 0)); // AF DAC Gain (after Gain-1 and Gain-2) ( 8u << 0)); // AF DAC Gain (after Gain-1 and Gain-2)
BK4819_sub_audible(); BK4819_config_sub_audible();
#if 1 #if 1
const uint8_t dtmf_coeffs[] = {111, 107, 103, 98, 80, 71, 58, 44, 65, 55, 37, 23, 228, 203, 181, 159}; const uint8_t dtmf_coeffs[] = {111, 107, 103, 98, 80, 71, 58, 44, 65, 55, 37, 23, 228, 203, 181, 159};
@ -395,172 +396,6 @@ void BK4819_set_GPIO_pin(bk4819_gpio_pin_t Pin, bool bSet)
BK4819_WriteRegister(0x33, gBK4819_GpioOutState); BK4819_WriteRegister(0x33, gBK4819_GpioOutState);
} }
void BK4819_SetCDCSSCodeWord(uint32_t CodeWord)
{
// REG_51
//
// <15> 0
// 1 = Enable TxCTCSS/CDCSS
// 0 = Disable
//
// <14> 0
// 1 = GPIO0Input for CDCSS
// 0 = Normal Mode (for BK4819 v3)
//
// <13> 0
// 1 = Transmit negative CDCSS code
// 0 = Transmit positive CDCSS code
//
// <12> 0 CTCSS/CDCSS mode selection
// 1 = CTCSS
// 0 = CDCSS
//
// <11> 0 CDCSS 24/23bit selection
// 1 = 24bit
// 0 = 23bit
//
// <10> 0 1050HzDetectionMode
// 1 = 1050/4 Detect Enable, CTC1 should be set to 1050/4 Hz
//
// <9> 0 Auto CDCSS Bw Mode
// 1 = Disable
// 0 = Enable
//
// <8> 0 Auto CTCSS Bw Mode
// 0 = Enable
// 1 = Disable
//
// <6:0> 0 CTCSS/CDCSS Tx Gain1 Tuning
// 0 = min
// 127 = max
// Enable CDCSS
// Transmit positive CDCSS code
// CDCSS Mode
// CDCSS 23bit
// Enable Auto CDCSS Bw Mode
// Enable Auto CTCSS Bw Mode
// CTCSS/CDCSS Tx Gain1 Tuning = 51
//
BK4819_WriteRegister(0x51,
BK4819_REG_51_ENABLE_CxCSS |
BK4819_REG_51_GPIO6_PIN2_NORMAL |
BK4819_REG_51_TX_CDCSS_POSITIVE |
BK4819_REG_51_MODE_CDCSS |
BK4819_REG_51_CDCSS_23_BIT |
BK4819_REG_51_1050HZ_NO_DETECTION |
BK4819_REG_51_AUTO_CDCSS_BW_ENABLE |
BK4819_REG_51_AUTO_CTCSS_BW_ENABLE |
(51u << BK4819_REG_51_SHIFT_CxCSS_TX_GAIN1));
// 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
//
BK4819_WriteRegister(0x07, BK4819_REG_07_MODE_CTC1 | 2775u);
// REG_08 <15:0> <15> = 1 for CDCSS high 12bit
// <15> = 0 for CDCSS low 12bit
// <11:0> = CDCSShigh/low 12bit code
//
BK4819_WriteRegister(0x08, (0u << 15) | ((CodeWord >> 0) & 0x0FFF)); // LS 12-bits
BK4819_WriteRegister(0x08, (1u << 15) | ((CodeWord >> 12) & 0x0FFF)); // MS 12-bits
}
void BK4819_SetCTCSSFrequency(uint32_t FreqControlWord)
{
// REG_51 <15> 0 1 = Enable TxCTCSS/CDCSS 0 = Disable
// REG_51 <14> 0 1 = GPIO0Input for CDCSS 0 = Normal Mode.(for BK4819v3)
// REG_51 <13> 0 1 = Transmit negative CDCSS code 0 = Transmit positive CDCSScode
// REG_51 <12> 0 CTCSS/CDCSS mode selection 1 = CTCSS 0 = CDCSS
// REG_51 <11> 0 CDCSS 24/23bit selection 1 = 24bit 0 = 23bit
// REG_51 <10> 0 1050HzDetectionMode 1 = 1050/4 Detect Enable, CTC1 should be set to 1050/4 Hz
// REG_51 <9> 0 Auto CDCSS Bw Mode 1 = Disable 0 = Enable.
// REG_51 <8> 0 Auto CTCSS Bw Mode 0 = Enable 1 = Disable
// REG_51 <6:0> 0 CTCSS/CDCSS Tx Gain1 Tuning 0 = min 127 = max
uint16_t Config;
if (FreqControlWord == 2625)
{ // Enables 1050Hz detection mode
// Enable TxCTCSS
// CTCSS Mode
// 1050/4 Detect Enable
// Enable Auto CDCSS Bw Mode
// Enable Auto CTCSS Bw Mode
// CTCSS/CDCSS Tx Gain1 Tuning = 74
//
Config = 0x944A; // 1 0 0 1 0 1 0 0 0 1001010
}
else
{ // Enable TxCTCSS
// CTCSS Mode
// Enable Auto CDCSS Bw Mode
// Enable Auto CTCSS Bw Mode
// CTCSS/CDCSS Tx Gain1 Tuning = 74
//
Config = 0x904A; // 1 0 0 1 0 0 0 0 0 1001010
}
BK4819_WriteRegister(0x51, Config);
// 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 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
//
BK4819_WriteRegister(0x07, BK4819_REG_07_MODE_CTC1 | (((FreqControlWord * 206488u) + 50000u) / 100000u)); // with rounding
}
// freq_10Hz is CTCSS Hz * 10
void BK4819_SetTailDetection(const uint32_t freq_10Hz)
{
// 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 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
//
BK4819_WriteRegister(0x07, BK4819_REG_07_MODE_CTC2 | ((253910 + (freq_10Hz / 2)) / freq_10Hz)); // with rounding
#ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT
#endif
}
void BK4819_EnableVox(uint16_t VoxEnableThreshold, uint16_t VoxDisableThreshold) void BK4819_EnableVox(uint16_t VoxEnableThreshold, uint16_t VoxDisableThreshold)
{ {
//VOX Algorithm //VOX Algorithm
@ -1251,19 +1086,8 @@ void BK4819_PrepareTransmit(void)
{ {
// BK4819_ExitBypass(); // BK4819_ExitBypass();
BK4819_ExitTxMute(); BK4819_ExitTxMute();
BK4819_sub_audible();
}
void BK4819_sub_audible(void) BK4819_config_sub_audible();
{
BK4819_WriteRegister(0x37, 0x1D0F); // 0001110100001111
#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, 0);
BK4819_WriteRegister(0x30, BK4819_WriteRegister(0x30,
@ -1280,48 +1104,6 @@ void BK4819_sub_audible(void)
0); 0);
} }
void BK4819_ExitSubAu(void)
{
// REG_51
//
// <15> 0
// 1 = Enable TxCTCSS/CDCSS
// 0 = Disable
//
// <14> 0
// 1 = GPIO0Input for CDCSS
// 0 = Normal Mode (for BK4819 v3)
//
// <13> 0
// 1 = Transmit negative CDCSS code
// 0 = Transmit positive CDCSS code
//
// <12> 0 CTCSS/CDCSS mode selection
// 1 = CTCSS
// 0 = CDCSS
//
// <11> 0 CDCSS 24/23bit selection
// 1 = 24bit
// 0 = 23bit
//
// <10> 0 1050HzDetectionMode
// 1 = 1050/4 Detect Enable, CTC1 should be set to 1050/4 Hz
//
// <9> 0 Auto CDCSS Bw Mode
// 1 = Disable
// 0 = Enable
//
// <8> 0 Auto CTCSS Bw Mode
// 0 = Enable
// 1 = Disable
//
// <6:0> 0 CTCSS/CDCSS Tx Gain1 Tuning
// 0 = min
// 127 = max
//
BK4819_WriteRegister(0x51, 0);
}
void BK4819_Conditional_RX_TurnOn(void) void BK4819_Conditional_RX_TurnOn(void)
{ {
if (g_rx_idle_mode) if (g_rx_idle_mode)
@ -1499,44 +1281,96 @@ void BK4819_TransmitTone(bool bLocalLoopback, uint32_t Frequency)
BK4819_ExitTxMute(); BK4819_ExitTxMute();
} }
void BK4819_GenTail(const unsigned int tail) void BK4819_disable_sub_audible(void)
{
BK4819_WriteRegister(0x51, 0);
}
void BK4819_config_sub_audible(void)
{
// #ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT
// BK4819_gen_tail(2); // 180 deg
// #else
// BK4819_gen_tail(4);
BK4819_WriteRegister(0x52, (0u << 15) | (0u << 13) | (0u << 12) | (10u << 6) | (15u << 0)); // 0x028F); // 0 00 0 001010 001111
// #endif
}
// freq_10Hz is CTCSS Hz * 10
void BK4819_set_tail_detection(const uint32_t freq_10Hz)
{
// REG_07 <15:0>
//
// <15) ???
//
// <14:13> 0 = CTC-1, 1 = CTC-2 (tail detection), 2 = CDCSS 134.4Hz
//
// if <14:13> == 0
// <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
//
// if <14:13> == 1
// <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
//
// if <14:13> == 2
// <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
//
#ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT
BK4819_WriteRegister(0x07, (0u << 13) | (((freq_10Hz * 206488u) + 50000u) / 100000u));
#else
BK4819_WriteRegister(0x07, (1u << 13) | ((253910 + (freq_10Hz / 2)) / freq_10Hz)); // with rounding
#endif
}
void BK4819_gen_tail(const unsigned int tail)
{ {
// REG_52 // REG_52
// //
// <15> 0 120/180/240 degree shift CTCSS or 134.4Hz Tail when CDCSS mode // <15> degree shift CTCSS or 134.4Hz tail CDCSS
// 0 = Normal // 0 = normal
// 1 = Enable // 1 = enable
// //
// <14:13> 0 CTCSS tail mode selection (only valid when REG_52 <15> = 1) // <14:13> CTCSS tail mode selection (only valid when <15> == 1)
// 00 = for 134.4Hz CTCSS Tail when CDCSS mode // 0 = for 134.4Hz CTCSS Tail when CDCSS mode
// 01 = CTCSS0 120° phase shift // 1 = CTCSS0 120° phase shift
// 10 = CTCSS0 180° phase shift // 2 = CTCSS0 180° phase shift
// 11 = CTCSS0 240° phase shift // 3 = CTCSS0 240° phase shift
// //
// <12> 0 CTCSS Detection Threshold Mode // <12> CTCSS Detection Threshold Mode
// 1 = ~0.1% // 1 = ~0.1%
// 0 = 0.1 Hz // 0 = 0.1Hz
// //
// <11:6> 10 CTCSS found detect threshold 0 ~ 63 // <11:6> 10 CTCSS found detect threshold 0 ~ 63
// //
// <5:0> 15 CTCSS lost detect threshold 0 ~ 63 // <5:0> 15 CTCSS lost detect threshold 0 ~ 63
uint16_t tail_phase_shift = 1; uint16_t tail_phase_shift = 1;
uint16_t ctcss_tail_mode_selection = 0; uint16_t ctcss_tail_mode_selection = 0;
uint16_t ctcss_detect_threshold_mode = 0; uint16_t ctcss_detect_threshold_mode = 0;
// uint16_t ctcss_found_threshold = 10; #if 0
// uint16_t ctcss_lost_threshold = 15; // original QS setting
uint16_t ctcss_found_threshold = 20; uint16_t ctcss_found_threshold = 10;
uint16_t ctcss_lost_threshold = 30; uint16_t ctcss_lost_threshold = 15;
#else
// increase it to help reduce false detections when doing CTCSS/CDCSS searching
uint16_t ctcss_found_threshold = 15;
uint16_t ctcss_lost_threshold = 23;
#endif
switch (tail) switch (tail)
{ {
case 0: // 134.4Hz CTCSS Tail case 0: // 134.4Hz CTCSS Tail
// ctcss_tail_mode_selection = 0;
break; break;
case 1: // 120° phase shift case 1: // 120° phase shift
ctcss_tail_mode_selection = 1; ctcss_tail_mode_selection = 1;
break; break;
case 2: // 180° phase shift case 2: // 180° phase shift 1 10 0 001010 001111
ctcss_tail_mode_selection = 2; ctcss_tail_mode_selection = 2;
break; break;
case 3: // 240° phase shift case 3: // 240° phase shift
@ -1558,60 +1392,148 @@ void BK4819_GenTail(const unsigned int tail)
(ctcss_lost_threshold << 0)); (ctcss_lost_threshold << 0));
} }
void BK4819_EnableCDCSS(void) void BK4819_set_CDCSS_code(const uint32_t control_word)
{ {
BK4819_GenTail(0); // CTC134 BK4819_WriteRegister(0x51,
BK4819_WriteRegister(0x51, 0x804A); ( 1u << 15) | // TX CTCSS/CDCSS 1 = enable 0 = disable
( 0u << 14) | // GPIO input for CDCSS 0 = normal (for BK4819v3)
( 0u << 13) | // TX CDCSS code 1 = negative 0 = positive
( 0u << 12) | // CTCSS/CDCSS mode selection 1 = CTCSS 0 = CDCSS
( 0u << 11) | // CDCSS 24/23bit selection 1 = 24bit 0 = 23bit
( 0u << 10) | // 1050Hz detection mode 1 = enable, CTC1 should be set to 1050/4 Hz
( 1u << 9) | // Auto CDCSS BW Mode 1 = disable 0 = enable
( 1u << 8) | // Auto CTCSS BW Mode 1 = disable 0 = enable
( 0u << 7) | // ???
(51u << 0)); // CTCSS/CDCSS TX gain 1 0 ~ 127
// REG_07 <15:0>
//
// <15) ???
//
// <14:13> 0 = CTC-1, 1 = CTC-2 (tail detection), 2 = CDCSS 134.4Hz
//
// <14:13> == 0
// <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
//
// <14:13> == 1
// <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
//
// <14:13> == 2
// <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
//
BK4819_WriteRegister(0x07, (0u << 13) | 2775u);
// REG_08 <15:0> <15> = 1 for CDCSS high 12bit
// <15> = 0 for CDCSS low 12bit
// <11:0> = CDCSShigh/low 12bit code
//
BK4819_WriteRegister(0x08, (0u << 15) | ((control_word >> 0) & 0x0FFF)); // LS 12-bits
BK4819_WriteRegister(0x08, (1u << 15) | ((control_word >> 12) & 0x0FFF)); // MS 12-bits
} }
void BK4819_EnableCTCSS(void) void BK4819_set_CTCSS_freq(const uint32_t control_word)
{
if (control_word == 0)
{ // NOAA 1050Hz tone stuff
BK4819_WriteRegister(0x51,
( 1u << 15) | // TX CTCSS/CDCSS 1 = enable 0 = disable
( 0u << 14) | // GPIO input for CDCSS 0 = normal (for BK4819v3)
( 0u << 13) | // TX CDCSS code 1 = negative 0 = positive
( 1u << 12) | // CTCSS/CDCSS mode selection 1 = CTCSS 0 = CDCSS
( 0u << 11) | // CDCSS 24/23bit selection 1 = 24bit 0 = 23bit
( 1u << 10) | // 1050Hz detection mode 1 = enable, CTC1 should be set to 1050/4 Hz
( 0u << 9) | // Auto CDCSS BW Mode 1 = disable 0 = enable
( 0u << 8) | // Auto CTCSS BW Mode 1 = disable 0 = enable
( 0u << 7) | // ???
(74u << 0)); // CTCSS/CDCSS TX gain 1 0 ~ 127
}
else
{ // normal CTCSS
BK4819_WriteRegister(0x51,
( 1u << 15) | // TX CTCSS/CDCSS 1 = enable 0 = disable
( 0u << 14) | // GPIO input for CDCSS 0 = normal (for BK4819v3)
( 0u << 13) | // TX CDCSS code 1 = negative 0 = positive
( 1u << 12) | // CTCSS/CDCSS mode selection 1 = CTCSS 0 = CDCSS
( 0u << 11) | // CDCSS 24/23bit selection 1 = 24bit 0 = 23bit
( 0u << 10) | // 1050Hz detection mode 1 = enable, CTC1 should be set to 1050/4 Hz
( 0u << 9) | // Auto CDCSS BW Mode 1 = disable 0 = enable
( 0u << 8) | // Auto CTCSS BW Mode 1 = disable 0 = enable
( 0u << 7) | // ???
(74u << 0)); // CTCSS/CDCSS TX gain 1 0 ~ 127
}
// REG_07 <15:0>
//
// <15) 0
//
// <14:13> 0 = CTC-1, 1 = CTC-2 (tail detection), 2 = CDCSS 134.4Hz
//
// if <14:13> == 0
// <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
//
// if <14:13> == 1
// <12:0> CTC2 (should be 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
//
// if <14:13> == 2
// <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
//
#ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT
BK4819_WriteRegister(0x07, (0u << 13) | (((control_word * 206488u) + 50000u) / 100000u));
#else
BK4819_WriteRegister(0x07, (1u << 13) | ((253910 + (control_word / 2)) / control_word));
#endif
}
void BK4819_enable_CDCSS_tail(void)
{
BK4819_gen_tail(0); // CTC134
BK4819_WriteRegister(0x51, // 0x804A); // 1 0 0 0 0 0 0 0 0 1001010
( 1u << 15) | // TX CTCSS/CDCSS 1 = enable 0 = disable
( 0u << 14) | // GPIO0 input for CDCSS 0 = normal (for BK4819v3)
( 0u << 13) | // TX CDCSS code 1 = negative 0 = positive
( 0u << 12) | // CTCSS/CDCSS mode selection 1 = CTCSS 0 = CDCSS
( 0u << 11) | // CDCSS 24/23bit selection 1 = 24bit 0 = 23bit
( 0u << 10) | // 1050Hz detection mode 1 = enable, CTC1 should be set to 1050/4 Hz
( 0u << 9) | // Auto CDCSS BW Mode 1 = disable 0 = enable
( 0u << 8) | // Auto CTCSS BW Mode 1 = disable 0 = enable
( 0u << 7) | // ???
(74u << 0)); // CTCSS/CDCSS TX gain 1 0 ~ 127
}
void BK4819_enable_CTCSS_tail(void)
{ {
#ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT #ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT
//BK4819_GenTail(1); // 120° phase shift //BK4819_gen_tail(1); // 120° phase shift
BK4819_GenTail(2); // 180° phase shift BK4819_gen_tail(2); // 180° phase shift
//BK4819_GenTail(3); // 240° phase shift //BK4819_gen_tail(3); // 240° phase shift
#else #else
BK4819_GenTail(4); // 55Hz tone freq BK4819_gen_tail(4); // 55Hz tone freq
#endif #endif
// REG_51 BK4819_WriteRegister(0x51, // 0x804A); // 1 0 0 0 0 0 0 0 0 1001010
// ( 1u << 15) | // TX CTCSS/CDCSS 1 = enable 0 = disable
// <15> 0 ( 0u << 14) | // GPIO0 input for CDCSS 0 = normal (for BK4819v3)
// 1 = Enable TxCTCSS/CDCSS ( 0u << 13) | // TX CDCSS code 1 = negative 0 = positive
// 0 = Disable ( 1u << 12) | // CTCSS/CDCSS mode selection 1 = CTCSS 0 = CDCSS
// ( 0u << 11) | // CDCSS 24/23bit selection 1 = 24bit 0 = 23bit
// <14> 0 ( 0u << 10) | // 1050Hz detection mode 1 = enable, CTC1 should be set to 1050/4 Hz
// 1 = GPIO0Input for CDCSS ( 0u << 9) | // Auto CDCSS BW Mode 1 = disable 0 = enable
// 0 = Normal Mode (for BK4819 v3) ( 0u << 8) | // Auto CTCSS BW Mode 1 = disable 0 = enable
// ( 0u << 7) | // ???
// <13> 0 (74u << 0)); // CTCSS/CDCSS TX gain 1 0 ~ 127
// 1 = Transmit negative CDCSS code
// 0 = Transmit positive CDCSS code
//
// <12> 0 CTCSS/CDCSS mode selection
// 1 = CTCSS
// 0 = CDCSS
//
// <11> 0 CDCSS 24/23bit selection
// 1 = 24bit
// 0 = 23bit
//
// <10> 0 1050HzDetectionMode
// 1 = 1050/4 Detect Enable, CTC1 should be set to 1050/4 Hz
//
// <9> 0 Auto CDCSS Bw Mode
// 1 = Disable
// 0 = Enable
//
// <8> 0 Auto CTCSS Bw Mode
// 0 = Enable
// 1 = Disable
//
// <6:0> 0 CTCSS/CDCSS Tx Gain1 Tuning
// 0 = min
// 127 = max
BK4819_WriteRegister(0x51, 0x904A); // 1 0 0 1 0 0 0 0 0 1001010
} }
uint16_t BK4819_GetRSSI(void) uint16_t BK4819_GetRSSI(void)
@ -1763,56 +1685,21 @@ void BK4819_EnableFrequencyScan(void)
( 1u << 0)); // 1 frequency scan enable ( 1u << 0)); // 1 frequency scan enable
} }
void BK4819_SetScanFrequency(uint32_t Frequency) void BK4819_set_scan_frequency(uint32_t Frequency)
{ {
BK4819_set_rf_frequency(Frequency, false); BK4819_set_rf_frequency(Frequency, false);
// REG_51
//
// <15> 0
// 1 = Enable TxCTCSS/CDCSS
// 0 = Disable
//
// <14> 0
// 1 = GPIO-0 input for CDCSS
// 0 = Normal Mode (for BK4819 v3)
//
// <13> 0
// 1 = Transmit negative CDCSS code
// 0 = Transmit positive CDCSS code
//
// <12> 0 CTCSS/CDCSS mode selection
// 1 = CTCSS
// 0 = CDCSS
//
// <11> 0 CDCSS 24/23bit selection
// 1 = 24bit
// 0 = 23bit
//
// <10> 0 1050Hz detection mode
// 1 = 1050/4 detect enable, CTC1 should be set to 1050/4 Hz
//
// <9> 0 Auto CDCSS Bw Mode
// 1 = Disable
// 0 = Enable
//
// <8> 0 Auto CTCSS Bw Mode
// 0 = Enable
// 1 = Disable
//
// <6:0> 0 CTCSS/CDCSS Tx Gain1 Tuning
// 0 = min
// 127 = max
//
BK4819_WriteRegister(0x51, BK4819_WriteRegister(0x51,
BK4819_REG_51_DISABLE_CxCSS | (0u << 15) | // TX CTCSS/CDCSS 1 = enable 0 = disable
BK4819_REG_51_GPIO6_PIN2_NORMAL | (0u << 14) | // GPIO input for CDCSS 0 = normal (for BK4819v3)
BK4819_REG_51_TX_CDCSS_POSITIVE | (0u << 13) | // TX CDCSS code 1 = negative 0 = positive
BK4819_REG_51_MODE_CDCSS | (0u << 12) | // CTCSS/CDCSS mode selection 1 = CTCSS 0 = CDCSS
BK4819_REG_51_CDCSS_23_BIT | (0u << 11) | // CDCSS 24/23bit selection 1 = 24bit 0 = 23bit
BK4819_REG_51_1050HZ_NO_DETECTION | (0u << 10) | // 1050Hz detection mode 1 = enable, CTC1 should be set to 1050/4 Hz
BK4819_REG_51_AUTO_CDCSS_BW_DISABLE | (1u << 9) | // Auto CDCSS BW Mode 1 = disable 0 = enable
BK4819_REG_51_AUTO_CTCSS_BW_DISABLE); (1u << 8) | // Auto CTCSS BW Mode 1 = disable 0 = enable
(0u << 7) | // ???
(0u << 0)); // CTCSS/CDCSS TX gain 1 0 ~ 127
BK4819_RX_TurnOn(); BK4819_RX_TurnOn();
} }
@ -1858,9 +1745,11 @@ void BK4819_reset_fsk(void)
(1u << 3) | // 0 or 1 sync length selection (1u << 3) | // 0 or 1 sync length selection
(0u << 0); // 0 ~ 7 ??? (0u << 0); // 0 ~ 7 ???
BK4819_WriteRegister(0x3F, 0); // disable interrupts BK4819_WriteRegister(0x3F, 0); // disable interrupts
BK4819_WriteRegister(0x59, (1u << 15) | (1u << 14) | fsk_reg59); // clear FIFO's BK4819_WriteRegister(0x59, (1u << 15) | (1u << 14) | fsk_reg59); // clear FIFO's
BK4819_WriteRegister(0x59, (0u << 15) | (0u << 14) | fsk_reg59); BK4819_WriteRegister(0x59, fsk_reg59);
BK4819_WriteRegister(0x30, 0); BK4819_WriteRegister(0x30, 0);
} }

View File

@ -72,9 +72,9 @@ void BK4819_EnableAGC(void);
void BK4819_set_GPIO_pin(bk4819_gpio_pin_t Pin, bool bSet); void BK4819_set_GPIO_pin(bk4819_gpio_pin_t Pin, bool bSet);
void BK4819_SetCDCSSCodeWord(uint32_t CodeWord); void BK4819_set_CDCSS_code(const uint32_t control_word);
void BK4819_SetCTCSSFrequency(uint32_t BaudRate); void BK4819_set_CTCSS_freq(const uint32_t control_word);
void BK4819_SetTailDetection(const uint32_t freq_10Hz); void BK4819_set_tail_detection(const uint32_t freq_10Hz);
void BK4819_EnableVox(uint16_t Vox1Threshold, uint16_t Vox0Threshold); void BK4819_EnableVox(uint16_t Vox1Threshold, uint16_t Vox0Threshold);
void BK4819_set_TX_deviation(const bool narrow); void BK4819_set_TX_deviation(const bool narrow);
@ -120,8 +120,12 @@ void BK4819_TurnsOffTones_TurnsOnRX(void);
void BK4819_reset_fsk(void); void BK4819_reset_fsk(void);
void BK4819_Idle(void); void BK4819_Idle(void);
void BK4819_PrepareTransmit(void); void BK4819_PrepareTransmit(void);
void BK4819_sub_audible(void);
void BK4819_ExitSubAu(void); void BK4819_config_sub_audible(void);
void BK4819_gen_tail(const unsigned int tail);
void BK4819_enable_CDCSS_tail(void);
void BK4819_enable_CTCSS_tail(void);
void BK4819_disable_sub_audible(void);
void BK4819_Conditional_RX_TurnOn(void); void BK4819_Conditional_RX_TurnOn(void);
@ -134,10 +138,6 @@ void BK4819_PlayDTMFString(const char *pString, bool bDelayFirst, uint16_t F
void BK4819_TransmitTone(bool bLocalLoopback, uint32_t Frequency); void BK4819_TransmitTone(bool bLocalLoopback, uint32_t Frequency);
void BK4819_GenTail(const unsigned int tail);
void BK4819_EnableCDCSS(void);
void BK4819_EnableCTCSS(void);
uint16_t BK4819_GetRSSI(void); uint16_t BK4819_GetRSSI(void);
uint8_t BK4819_GetGlitchIndicator(void); uint8_t BK4819_GetGlitchIndicator(void);
uint8_t BK4819_GetExNoiceIndicator(void); uint8_t BK4819_GetExNoiceIndicator(void);
@ -148,7 +148,7 @@ bool BK4819_GetFrequencyScanResult(uint32_t *pFrequency);
BK4819_CSS_scan_result_t BK4819_GetCxCSSScanResult(uint32_t *pCdcssFreq, uint16_t *pCtcssFreq); BK4819_CSS_scan_result_t BK4819_GetCxCSSScanResult(uint32_t *pCdcssFreq, uint16_t *pCtcssFreq);
void BK4819_DisableFrequencyScan(void); void BK4819_DisableFrequencyScan(void);
void BK4819_EnableFrequencyScan(void); void BK4819_EnableFrequencyScan(void);
void BK4819_SetScanFrequency(uint32_t Frequency); void BK4819_set_scan_frequency(uint32_t Frequency);
void BK4819_StopScan(void); void BK4819_StopScan(void);

Binary file not shown.

Binary file not shown.

4
misc.c
View File

@ -201,10 +201,14 @@ bool g_flag_save_channel;
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
bool g_flag_save_fm; bool g_flag_save_fm;
#endif #endif
bool g_cdcss_lost; bool g_cdcss_lost;
uint8_t g_cdcss_code_type; uint8_t g_cdcss_code_type;
bool g_ctcss_lost; bool g_ctcss_lost;
bool g_cxcss_tail_found; bool g_cxcss_tail_found;
uint8_t g_ctcss_tail_phase_shift_rx;
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
bool g_vox_lost; bool g_vox_lost;
bool g_vox_noise_detected; bool g_vox_noise_detected;

3
misc.h
View File

@ -294,10 +294,13 @@ extern bool g_flag_save_channel;
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
extern bool g_flag_save_fm; extern bool g_flag_save_fm;
#endif #endif
extern bool g_cdcss_lost; extern bool g_cdcss_lost;
extern uint8_t g_cdcss_code_type; extern uint8_t g_cdcss_code_type;
extern bool g_ctcss_lost; extern bool g_ctcss_lost;
extern bool g_cxcss_tail_found; extern bool g_cxcss_tail_found;
extern uint8_t g_ctcss_tail_phase_shift_rx;
#ifdef ENABLE_VOX #ifdef ENABLE_VOX
extern bool g_vox_lost; extern bool g_vox_lost;
extern bool g_vox_noise_detected; extern bool g_vox_noise_detected;

70
radio.c
View File

@ -280,11 +280,11 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur
p_vfo->freq_config_rx.code = 0; p_vfo->freq_config_rx.code = 0;
break; break;
case CODE_TYPE_CONTINUOUS_TONE: case CODE_TYPE_CONTINUOUS_TONE:
p_vfo->freq_config_rx.code = (m_channel.rx_ctcss_cdcss_code < ARRAY_SIZE(CTCSS_OPTIONS)) ? m_channel.rx_ctcss_cdcss_code : 0; p_vfo->freq_config_rx.code = (m_channel.rx_ctcss_cdcss_code < ARRAY_SIZE(CTCSS_TONE_LIST)) ? m_channel.rx_ctcss_cdcss_code : 0;
break; break;
case CODE_TYPE_DIGITAL: case CODE_TYPE_DIGITAL:
case CODE_TYPE_REVERSE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL:
p_vfo->freq_config_rx.code = (m_channel.rx_ctcss_cdcss_code < ARRAY_SIZE(DCS_OPTIONS)) ? m_channel.rx_ctcss_cdcss_code : 0; p_vfo->freq_config_rx.code = (m_channel.rx_ctcss_cdcss_code < ARRAY_SIZE(DCS_CODE_LIST)) ? m_channel.rx_ctcss_cdcss_code : 0;
break; break;
} }
@ -297,11 +297,11 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur
p_vfo->freq_config_tx.code = 0; p_vfo->freq_config_tx.code = 0;
break; break;
case CODE_TYPE_CONTINUOUS_TONE: case CODE_TYPE_CONTINUOUS_TONE:
p_vfo->freq_config_tx.code = (m_channel.tx_ctcss_cdcss_code < ARRAY_SIZE(CTCSS_OPTIONS)) ? m_channel.tx_ctcss_cdcss_code : 0; p_vfo->freq_config_tx.code = (m_channel.tx_ctcss_cdcss_code < ARRAY_SIZE(CTCSS_TONE_LIST)) ? m_channel.tx_ctcss_cdcss_code : 0;
break; break;
case CODE_TYPE_DIGITAL: case CODE_TYPE_DIGITAL:
case CODE_TYPE_REVERSE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL:
p_vfo->freq_config_tx.code = (m_channel.tx_ctcss_cdcss_code < ARRAY_SIZE(DCS_OPTIONS)) ? m_channel.tx_ctcss_cdcss_code : 0; p_vfo->freq_config_tx.code = (m_channel.tx_ctcss_cdcss_code < ARRAY_SIZE(DCS_CODE_LIST)) ? m_channel.tx_ctcss_cdcss_code : 0;
break; break;
} }
@ -741,45 +741,49 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
if (g_rx_vfo->am_mode == 0) if (g_rx_vfo->am_mode == 0)
{ // FM { // FM
uint8_t code_type = g_selected_code_type; uint8_t code_type = g_selected_code_type;
uint8_t Code = g_selected_code; uint8_t code = g_selected_code;
if (g_css_scan_mode == CSS_SCAN_MODE_OFF) if (g_css_scan_mode == CSS_SCAN_MODE_OFF)
{ {
code_type = g_rx_vfo->p_rx->code_type; code_type = g_rx_vfo->p_rx->code_type;
Code = g_rx_vfo->p_rx->code; code = g_rx_vfo->p_rx->code;
} }
switch (code_type) switch (code_type)
{ {
default: default:
case CODE_TYPE_NONE: case CODE_TYPE_NONE:
BK4819_SetCTCSSFrequency(670); BK4819_set_CTCSS_freq(670);
BK4819_set_tail_detection(550); // QS's 55Hz tone method
//#ifndef ENABLE_CTCSS_TAIL_PHASE_SHIFT
BK4819_SetTailDetection(550); // QS's 55Hz tone method
//#else
// BK4819_SetTailDetection(670); // 67Hz
//#endif
interrupt_mask |= BK4819_REG_3F_CxCSS_TAIL; interrupt_mask |= BK4819_REG_3F_CxCSS_TAIL;
break; break;
case CODE_TYPE_CONTINUOUS_TONE: case CODE_TYPE_CONTINUOUS_TONE:
BK4819_SetCTCSSFrequency(CTCSS_OPTIONS[Code]); BK4819_set_CTCSS_freq(CTCSS_TONE_LIST[code]);
//#ifndef ENABLE_CTCSS_TAIL_PHASE_SHIFT // #ifdef ENABLE_CTCSS_TAIL_PHASE_SHIFT
BK4819_SetTailDetection(550); // QS's 55Hz tone method // BK4819_set_tail_detection(CTCSS_TONE_LIST[code]); // doesn't work in RX mode
//#else // #else
// BK4819_SetTailDetection(CTCSS_OPTIONS[Code]); // BK4819_set_tail_detection(550); // QS's 55Hz tone method
//#endif // #endif
interrupt_mask |=
BK4819_REG_3F_CxCSS_TAIL |
BK4819_REG_3F_CTCSS_FOUND |
BK4819_REG_3F_CTCSS_LOST;
interrupt_mask |= BK4819_REG_3F_CxCSS_TAIL | BK4819_REG_3F_CTCSS_FOUND | BK4819_REG_3F_CTCSS_LOST;
break; break;
case CODE_TYPE_DIGITAL: case CODE_TYPE_DIGITAL:
case CODE_TYPE_REVERSE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL:
BK4819_SetCDCSSCodeWord(DCS_GetGolayCodeWord(code_type, Code)); BK4819_set_CDCSS_code(DCS_GetGolayCodeWord(code_type, code));
interrupt_mask |= BK4819_REG_3F_CxCSS_TAIL | BK4819_REG_3F_CDCSS_FOUND | BK4819_REG_3F_CDCSS_LOST;
interrupt_mask |=
BK4819_REG_3F_CxCSS_TAIL |
BK4819_REG_3F_CDCSS_FOUND |
BK4819_REG_3F_CDCSS_LOST;
break; break;
} }
@ -792,7 +796,8 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
else else
{ {
BK4819_SetCTCSSFrequency(2625); BK4819_set_CTCSS_freq(0); // NOAA 1050Hz stuff
interrupt_mask |= BK4819_REG_3F_CTCSS_FOUND | BK4819_REG_3F_CTCSS_LOST; interrupt_mask |= BK4819_REG_3F_CTCSS_FOUND | BK4819_REG_3F_CTCSS_LOST;
} }
#endif #endif
@ -934,7 +939,7 @@ void RADIO_enableTX(const bool fsk_tx)
if (fsk_tx) if (fsk_tx)
{ {
BK4819_ExitSubAu(); BK4819_disable_sub_audible();
} }
else else
{ {
@ -942,16 +947,18 @@ void RADIO_enableTX(const bool fsk_tx)
{ {
default: default:
case CODE_TYPE_NONE: case CODE_TYPE_NONE:
BK4819_ExitSubAu(); BK4819_disable_sub_audible();
break; break;
case CODE_TYPE_CONTINUOUS_TONE: case CODE_TYPE_CONTINUOUS_TONE:
BK4819_SetCTCSSFrequency(CTCSS_OPTIONS[g_current_vfo->p_tx->code]); BK4819_gen_tail(4);
BK4819_set_CTCSS_freq(CTCSS_TONE_LIST[g_current_vfo->p_tx->code]);
break; break;
case CODE_TYPE_DIGITAL: case CODE_TYPE_DIGITAL:
case CODE_TYPE_REVERSE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL:
BK4819_SetCDCSSCodeWord(DCS_GetGolayCodeWord(g_current_vfo->p_tx->code_type, g_current_vfo->p_tx->code)); BK4819_gen_tail(4);
BK4819_set_CDCSS_code(DCS_GetGolayCodeWord(g_current_vfo->p_tx->code_type, g_current_vfo->p_tx->code));
break; break;
} }
} }
@ -1094,7 +1101,7 @@ void RADIO_PrepareTX(void)
g_dtmf_reply_state = DTMF_REPLY_NONE; g_dtmf_reply_state = DTMF_REPLY_NONE;
} }
void RADIO_EnableCxCSS(void) void RADIO_enable_CxCSS_tail(void)
{ {
switch (g_current_vfo->p_tx->code_type) switch (g_current_vfo->p_tx->code_type)
{ {
@ -1103,13 +1110,13 @@ void RADIO_EnableCxCSS(void)
break; break;
case CODE_TYPE_CONTINUOUS_TONE: case CODE_TYPE_CONTINUOUS_TONE:
BK4819_EnableCTCSS(); BK4819_enable_CTCSS_tail();
SYSTEM_DelayMs(200); SYSTEM_DelayMs(200);
break; break;
case CODE_TYPE_DIGITAL: case CODE_TYPE_DIGITAL:
case CODE_TYPE_REVERSE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL:
BK4819_EnableCDCSS(); BK4819_enable_CDCSS_tail();
SYSTEM_DelayMs(200); SYSTEM_DelayMs(200);
break; break;
} }
@ -1123,7 +1130,8 @@ void RADIO_PrepareCssTX(void)
SYSTEM_DelayMs(200); SYSTEM_DelayMs(200);
RADIO_EnableCxCSS(); RADIO_enable_CxCSS_tail();
RADIO_setup_registers(true); RADIO_setup_registers(true);
} }

View File

@ -157,7 +157,7 @@ void RADIO_enableTX(const bool fsk_tx);
void RADIO_set_vfo_state(vfo_state_t State); void RADIO_set_vfo_state(vfo_state_t State);
void RADIO_PrepareTX(void); void RADIO_PrepareTX(void);
void RADIO_EnableCxCSS(void); void RADIO_enable_CxCSS_tail(void);
void RADIO_PrepareCssTX(void); void RADIO_PrepareCssTX(void);
void RADIO_tx_eot(void); void RADIO_tx_eot(void);

View File

@ -789,22 +789,35 @@ void UI_DisplayMain(void)
} }
#else #else
{ {
strcpy(str, " "); const bool is_freq_chan = IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo_num]);
const uint8_t freq_in_channel = g_eeprom.vfo_info[vfo_num].freq_in_channel;
// const uint8_t freq_in_channel = BOARD_find_channel(frequency); // currently way to slow
if (IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo_num])) // if (g_eeprom.vfo_info[vfo_num].compand)
{ {
//g_eeprom.vfo_info[vfo_num].freq_in_channel = BOARD_find_channel(frequency); strcpy(str, " ");
if (g_eeprom.vfo_info[vfo_num].freq_in_channel <= USER_CHANNEL_LAST)
if (is_freq_chan && freq_in_channel <= USER_CHANNEL_LAST)
{ // the channel number that contains this VFO frequency { // the channel number that contains this VFO frequency
str[0] = 'F'; // strcpy(str, "F");
sprintf(str, "%03u", freq_in_channel);
}
if (g_eeprom.vfo_info[vfo_num].compand)
strcat(str, "C");
// UI_PrintStringSmall(str, LCD_WIDTH - (7 * 2), 0, line + 1);
UI_PrintStringSmall(str, LCD_WIDTH - (7 * 4), 0, line + 1);
}
/* else
{
if (is_freq_chan && freq_in_channel <= USER_CHANNEL_LAST)
{ // the channel number that contains this VFO frequency
sprintf(str, "%03u", freq_in_channel);
UI_PrintStringSmall(str, LCD_WIDTH - (7 * 3), 0, line + 1);
} }
} }
*/ }
if (g_eeprom.vfo_info[vfo_num].compand)
str[1] = 'C';
UI_PrintStringSmall(str, LCD_WIDTH - 1 - (6 * 2), 0, line + 1);
}
#endif #endif
} }
@ -941,7 +954,11 @@ void UI_DisplayMain(void)
if (mdc1200_rx_ready_tick_500ms > 0) if (mdc1200_rx_ready_tick_500ms > 0)
{ {
g_center_line = CENTER_LINE_MDC1200; g_center_line = CENTER_LINE_MDC1200;
sprintf(str, "MDC1200 %02X %02X %04X", mdc1200_op, mdc1200_arg, mdc1200_unit_id); #ifdef ENABLE_MDC1200_SHOW_OP_ARG
sprintf(str, "MDC1200 %02X %02X %04X", mdc1200_op, mdc1200_arg, mdc1200_unit_id);
#else
sprintf(str, "MDC1200 ID %04X", mdc1200_unit_id);
#endif
#ifdef ENABLE_SMALL_BOLD #ifdef ENABLE_SMALL_BOLD
UI_PrintStringSmallBold(str, 2, 0, 3); UI_PrintStringSmallBold(str, 2, 0, 3);
#else #else

View File

@ -610,9 +610,9 @@ void UI_DisplayMenu(void)
strcat(str, "OFF"); strcat(str, "OFF");
else else
if (g_sub_menu_selection < 105) if (g_sub_menu_selection < 105)
sprintf(str + strlen(str), "D%03oN", DCS_OPTIONS[g_sub_menu_selection - 1]); sprintf(str + strlen(str), "D%03oN", DCS_CODE_LIST[g_sub_menu_selection - 1]);
else else
sprintf(str + strlen(str), "D%03oI", DCS_OPTIONS[g_sub_menu_selection - 105]); sprintf(str + strlen(str), "D%03oI", DCS_CODE_LIST[g_sub_menu_selection - 105]);
break; break;
case MENU_RX_CTCSS: case MENU_RX_CTCSS:
@ -634,23 +634,23 @@ void UI_DisplayMenu(void)
pConfig->code_type = CODE_TYPE_NONE; pConfig->code_type = CODE_TYPE_NONE;
pConfig->code = Code; pConfig->code = Code;
BK4819_ExitSubAu(); BK4819_disable_sub_audible();
} }
else else
{ {
sprintf(str + strlen(str), "%u.%uHz", CTCSS_OPTIONS[g_sub_menu_selection - 1] / 10, CTCSS_OPTIONS[g_sub_menu_selection - 1] % 10); sprintf(str + strlen(str), "%u.%uHz", CTCSS_TONE_LIST[g_sub_menu_selection - 1] / 10, CTCSS_TONE_LIST[g_sub_menu_selection - 1] % 10);
pConfig->code_type = CODE_TYPE_CONTINUOUS_TONE; pConfig->code_type = CODE_TYPE_CONTINUOUS_TONE;
Code = g_sub_menu_selection - 1; Code = g_sub_menu_selection - 1;
pConfig->code = Code; pConfig->code = Code;
BK4819_SetCTCSSFrequency(CTCSS_OPTIONS[Code]); BK4819_set_CTCSS_freq(CTCSS_TONE_LIST[Code]);
} }
#else #else
if (g_sub_menu_selection == 0) if (g_sub_menu_selection == 0)
strcat(str, "OFF"); strcat(str, "OFF");
else else
sprintf(str + strlen(str), "%u.%uHz", CTCSS_OPTIONS[g_sub_menu_selection - 1] / 10, CTCSS_OPTIONS[g_sub_menu_selection - 1] % 10); sprintf(str + strlen(str), "%u.%uHz", CTCSS_TONE_LIST[g_sub_menu_selection - 1] / 10, CTCSS_TONE_LIST[g_sub_menu_selection - 1] % 10);
#endif #endif
break; break;

View File

@ -96,11 +96,11 @@ void UI_DisplaySearch(void)
case CODE_TYPE_NONE: case CODE_TYPE_NONE:
break; break;
case CODE_TYPE_CONTINUOUS_TONE: case CODE_TYPE_CONTINUOUS_TONE:
sprintf(String, "CTCSS %u.%uHz", CTCSS_OPTIONS[g_search_css_result_code] / 10, CTCSS_OPTIONS[g_search_css_result_code] % 10); sprintf(String, "CTCSS %u.%uHz", CTCSS_TONE_LIST[g_search_css_result_code] / 10, CTCSS_TONE_LIST[g_search_css_result_code] % 10);
break; break;
case CODE_TYPE_DIGITAL: case CODE_TYPE_DIGITAL:
case CODE_TYPE_REVERSE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL:
sprintf(String, "CDCSS D%03oN", DCS_OPTIONS[g_search_css_result_code]); sprintf(String, "CDCSS D%03oN", DCS_CODE_LIST[g_search_css_result_code]);
break; break;
} }
} }