diff --git a/app/action.c b/app/action.c index e14750b..14178b0 100644 --- a/app/action.c +++ b/app/action.c @@ -76,13 +76,13 @@ void ACTION_Monitor(void) { if (g_current_function != FUNCTION_MONITOR) { // enable the monitor - RADIO_SelectVfos(); - #ifdef g_power_save_expired + RADIO_select_vfos(); + #ifdef ENABLE_NOAA if (g_rx_vfo->channel_save >= NOAA_CHANNEL_FIRST && g_is_noaa_mode) g_noaa_channel = g_rx_vfo->channel_save - NOAA_CHANNEL_FIRST; #endif - RADIO_SetupRegisters(true); - APP_StartListening(FUNCTION_MONITOR, false); + RADIO_setup_registers(true); + APP_start_listening(FUNCTION_MONITOR, false); return; } @@ -90,9 +90,9 @@ void ACTION_Monitor(void) if (g_scan_state_dir != SCAN_STATE_DIR_OFF) { - g_scan_pause_delay_in_10ms = scan_pause_delay_in_1_10ms; - g_scan_schedule_scan_listen = false; - g_scan_pause_mode = true; + g_scan_pause_delay_in_10ms = scan_pause_delay_in_1_10ms; + g_scan_schedule_scan_listen = false; + g_scan_pause_mode = true; } #ifdef g_power_save_expired @@ -103,7 +103,7 @@ void ACTION_Monitor(void) } #endif - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); #ifdef ENABLE_FMRADIO if (g_fm_radio_mode) @@ -139,19 +139,18 @@ void ACTION_Scan(bool bRestart) #endif } else - { + { // start scanning uint16_t Frequency; if (bRestart) - { // going to scan and auto store what we find + { // scan with auto store FM_EraseChannels(); - g_fm_auto_scan = true; g_fm_channel_position = 0; Frequency = FM_RADIO_BAND.lower; } else - { + { // scan without auto store g_fm_auto_scan = false; g_fm_channel_position = 0; Frequency = g_eeprom.fm_frequency_playing; @@ -172,7 +171,7 @@ void ACTION_Scan(bool bRestart) #endif if (g_screen_to_display != DISPLAY_SEARCH) - { // not scanning + { // not in freq/ctcss/cdcss search mode g_monitor_enabled = false; @@ -181,69 +180,78 @@ void ACTION_Scan(bool bRestart) g_dtmf_rx_live_timeout = 0; memset(g_dtmf_rx_live, 0, sizeof(g_dtmf_rx_live)); - RADIO_SelectVfos(); + RADIO_select_vfos(); - #ifdef g_power_save_expired - if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save)) - #endif + if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save)) { GUI_SelectNextDisplay(DISPLAY_MAIN); if (g_scan_state_dir != SCAN_STATE_DIR_OFF) - { // already scanning + { // currently scanning if (g_scan_next_channel <= USER_CHANNEL_LAST) { // channel mode - // keep scanning but toggle between scan lists - g_eeprom.scan_list_default = (g_eeprom.scan_list_default + 1) % 3; + if (g_eeprom.scan_list_default < 2) + { // keep scanning but toggle between scan lists - // jump to the next channel - CHANNEL_Next(true, g_scan_state_dir); - g_scan_pause_delay_in_10ms = 1; - g_scan_schedule_scan_listen = false; + //g_eeprom.scan_list_default = (g_eeprom.scan_list_default + 1) % 3; + g_eeprom.scan_list_default++; - g_update_status = true; - } - else - { // stop scanning - - SCAN_Stop(); - - #ifdef ENABLE_VOICE - g_another_voice_id = VOICE_ID_SCANNING_STOP; - #endif - } - } - else - { // start scanning + // jump to the next channel + APP_channel_next(true, g_scan_state_dir); + g_scan_pause_delay_in_10ms = 1; + g_scan_schedule_scan_listen = false; - CHANNEL_Next(true, SCAN_STATE_DIR_FORWARD); + g_update_status = true; + return; + } + } + + // stop scanning + + APP_stop_scan(); #ifdef ENABLE_VOICE - AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN); - AUDIO_PlaySingleVoice(true); + g_another_voice_id = VOICE_ID_SCANNING_STOP; #endif - // clear the other vfo's rssi level (to hide the antenna symbol) - g_vfo_rssi_bar_level[(g_eeprom.rx_vfo + 1) & 1u] = 0; - - // let the user see DW is not active - g_dual_watch_active = false; - g_update_status = true; + return; } + + // start scanning + + APP_channel_next(true, SCAN_STATE_DIR_FORWARD); + + #ifdef ENABLE_VOICE + AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN); + AUDIO_PlaySingleVoice(true); + #endif + + // clear the other vfo's rssi level (to hide the antenna symbol) + g_vfo_rssi_bar_level[(g_eeprom.rx_vfo + 1) & 1u] = 0; + + g_update_status = true; } + + return; } - else + + // freq/ctcss/cdcss/search mode + + + // TODO: fixme + + // if (!bRestart) if (!bRestart && g_scan_next_channel <= USER_CHANNEL_LAST) { // channel mode, keep scanning but toggle between scan lists g_eeprom.scan_list_default = (g_eeprom.scan_list_default + 1) % 3; // jump to the next channel - CHANNEL_Next(true, g_scan_state_dir); - g_scan_pause_delay_in_10ms = 1; - g_scan_schedule_scan_listen = false; + APP_channel_next(true, g_scan_state_dir); + g_scan_pause_delay_in_10ms = 1; + g_scan_schedule_scan_listen = false; g_update_status = true; } @@ -251,7 +259,7 @@ void ACTION_Scan(bool bRestart) { // stop scanning g_monitor_enabled = false; - SCAN_Stop(); + APP_stop_scan(); #ifdef ENABLE_VOICE g_another_voice_id = VOICE_ID_SCANNING_STOP; @@ -320,8 +328,8 @@ void ACTION_Scan(bool bRestart) g_monitor_enabled = false; - RADIO_SelectVfos(); - RADIO_SetupRegisters(true); + RADIO_select_vfos(); + RADIO_setup_registers(true); FM_Start(); diff --git a/app/aircopy.c b/app/aircopy.c index 7785dba..c02f716 100644 --- a/app/aircopy.c +++ b/app/aircopy.c @@ -70,7 +70,7 @@ void AIRCOPY_init(void) // turn the backlight ON GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); BK4819_SetupAircopy(AIRCOPY_DATA_PACKET_SIZE); @@ -762,7 +762,7 @@ static void AIRCOPY_Key_MENU(bool key_pressed, bool key_held) } } -void AIRCOPY_ProcessKey(key_code_t Key, bool key_pressed, bool key_held) +void AIRCOPY_process_key(key_code_t Key, bool key_pressed, bool key_held) { switch (Key) { diff --git a/app/aircopy.h b/app/aircopy.h index 26e1d70..beac0ba 100644 --- a/app/aircopy.h +++ b/app/aircopy.h @@ -42,6 +42,6 @@ extern uint16_t g_fsk_tx_timeout_10ms; void AIRCOPY_init(void); void AIRCOPY_process_fsk_tx_10ms(void); void AIRCOPY_process_fsk_rx_10ms(void); -void AIRCOPY_ProcessKey(key_code_t key, bool key_pressed, bool key_held); +void AIRCOPY_process_key(key_code_t key, bool key_pressed, bool key_held); #endif diff --git a/app/app.c b/app/app.c index 3ff5147..bef0779 100644 --- a/app/app.c +++ b/app/app.c @@ -70,9 +70,9 @@ const uint8_t orig_lna = 2; // -14dB const uint8_t orig_mixer = 3; // 0dB const uint8_t orig_pga = 6; // -3dB -static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const bool key_held); +static void APP_process_key(const key_code_t Key, const bool key_pressed, const bool key_held); -static void updateRSSI(const int vfo) +static void APP_update_rssi(const int vfo) { int16_t rssi = BK4819_GetRSSI(); @@ -87,13 +87,13 @@ static void updateRSSI(const int vfo) g_current_rssi[vfo] = rssi; - UI_UpdateRSSI(rssi, vfo); + UI_update_rssi(rssi, vfo); } -static void APP_CheckForIncoming(void) +static void APP_check_for_incoming_rx(void) { if (!g_squelch_lost) - return; // squelch is closed + return; // squelch is open @@ -124,7 +124,7 @@ static void APP_CheckForIncoming(void) FUNCTION_Select(FUNCTION_INCOMING); //g_update_display = true; - updateRSSI(g_eeprom.rx_vfo); + APP_update_rssi(g_eeprom.rx_vfo); g_update_rssi = true; } @@ -140,18 +140,16 @@ static void APP_CheckForIncoming(void) FUNCTION_Select(FUNCTION_INCOMING); //g_update_display = true; - updateRSSI(g_eeprom.rx_vfo); + APP_update_rssi(g_eeprom.rx_vfo); g_update_rssi = true; } return; } g_dual_watch_count_down_10ms = dual_watch_count_after_rx_10ms; - g_schedule_dual_watch = false; + g_schedule_dual_watch = false; - // let the user see DW is not active - g_dual_watch_active = false; - g_update_status = true; + g_update_status = true; } else { // RF scanning @@ -162,7 +160,7 @@ static void APP_CheckForIncoming(void) FUNCTION_Select(FUNCTION_INCOMING); //g_update_display = true; - updateRSSI(g_eeprom.rx_vfo); + APP_update_rssi(g_eeprom.rx_vfo); g_update_rssi = true; } return; @@ -179,12 +177,12 @@ static void APP_CheckForIncoming(void) FUNCTION_Select(FUNCTION_INCOMING); //g_update_display = true; - updateRSSI(g_eeprom.rx_vfo); + APP_update_rssi(g_eeprom.rx_vfo); g_update_rssi = true; } } -static void APP_HandleIncoming(void) +static void APP_process_incoming_rx(void) { bool flag; @@ -214,7 +212,7 @@ static void APP_HandleIncoming(void) if (g_ctcss_lost && g_current_code_type == CODE_TYPE_CONTINUOUS_TONE) { - flag = true; + flag = true; g_found_ctcss = false; } @@ -228,7 +226,8 @@ static void APP_HandleIncoming(void) if (g_scan_state_dir == SCAN_STATE_DIR_OFF && g_css_scan_mode == CSS_SCAN_MODE_OFF) { // not scanning - if (g_rx_vfo->dtmf_decoding_enable || g_setting_killed) + + if (g_rx_vfo->dtmf_decoding_enable || g_setting_radio_disabled) { // DTMF DCD is enabled DTMF_HandleRequest(); @@ -238,31 +237,32 @@ static void APP_HandleIncoming(void) if (g_rx_reception_mode == RX_MODE_DETECTED) { g_dual_watch_count_down_10ms = dual_watch_count_after_1_10ms; - g_schedule_dual_watch = false; + g_schedule_dual_watch = false; g_rx_reception_mode = RX_MODE_LISTENING; - // let the user see DW is not active - g_dual_watch_active = false; - g_update_status = true; - + g_update_status = true; g_update_display = true; + return; } } } } - APP_StartListening(g_monitor_enabled ? FUNCTION_MONITOR : FUNCTION_RECEIVE, false); + APP_start_listening(g_monitor_enabled ? FUNCTION_MONITOR : FUNCTION_RECEIVE, false); } -static void APP_HandleReceive(void) -{ - #define END_OF_RX_MODE_SKIP 0 - #define END_OF_RX_MODE_END 1 - #define END_OF_RX_MODE_TTE 2 +enum end_of_rx_mode_e { + END_OF_RX_MODE_SKIP = 0, + END_OF_RX_MODE_END, + END_OF_RX_MODE_TTE +}; +typedef enum end_of_rx_mode_e end_of_rx_mode_t; - uint8_t Mode = END_OF_RX_MODE_SKIP; +static void APP_process_rx(void) +{ + end_of_rx_mode_t Mode = END_OF_RX_MODE_SKIP; if (g_flag_tail_tone_elimination_complete) { @@ -309,11 +309,7 @@ static void APP_HandleReceive(void) if (g_squelch_lost) { - #ifdef ENABLE_NOAA - if (!g_end_of_rx_detected_maybe && IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save)) - #else - if (!g_end_of_rx_detected_maybe) - #endif + if (!g_end_of_rx_detected_maybe && IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save)) { switch (g_current_code_type) { @@ -396,11 +392,11 @@ Skip: break; case END_OF_RX_MODE_END: - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); #ifdef ENABLE_NOAA if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save)) - g_noaa_count_down_10ms = 300; // 3 sec + g_noaa_count_down_10ms = 3000 / 10; // 3 sec #endif g_update_display = true; @@ -413,12 +409,12 @@ Skip: break; case SCAN_RESUME_CO: - g_scan_pause_delay_in_10ms = scan_pause_delay_in_7_10ms; - g_scan_schedule_scan_listen = false; + g_scan_pause_delay_in_10ms = scan_pause_delay_in_7_10ms; + g_scan_schedule_scan_listen = false; break; case SCAN_RESUME_SE: - SCAN_Stop(); + APP_stop_scan(); break; } } @@ -432,19 +428,19 @@ Skip: g_tail_tone_elimination_count_down_10ms = 20; g_flag_tail_tone_elimination_complete = false; - g_end_of_rx_detected_maybe = true; - g_enable_speaker = false; + g_end_of_rx_detected_maybe = true; + g_enable_speaker = false; } break; } } -static void APP_HandleFunction(void) +static void APP_process_function(void) { switch (g_current_function) { case FUNCTION_FOREGROUND: - APP_CheckForIncoming(); + APP_check_for_incoming_rx(); break; case FUNCTION_TRANSMIT: @@ -454,16 +450,16 @@ static void APP_HandleFunction(void) break; case FUNCTION_INCOMING: - APP_HandleIncoming(); + APP_process_incoming_rx(); break; case FUNCTION_RECEIVE: - APP_HandleReceive(); + APP_process_rx(); break; case FUNCTION_POWER_SAVE: if (!g_rx_idle_mode) - APP_CheckForIncoming(); + APP_check_for_incoming_rx(); break; case FUNCTION_BAND_SCOPE: @@ -471,12 +467,12 @@ static void APP_HandleFunction(void) } } -void APP_StartListening(function_type_t Function, const bool reset_am_fix) +void APP_start_listening(function_type_t Function, const bool reset_am_fix) { const unsigned int chan = g_eeprom.rx_vfo; // const unsigned int chan = g_rx_vfo->channel_save; - if (g_setting_killed) + if (g_setting_radio_disabled) return; #ifdef ENABLE_FMRADIO @@ -495,22 +491,23 @@ void APP_StartListening(function_type_t Function, const bool reset_am_fix) backlight_turn_on(); if (g_scan_state_dir != SCAN_STATE_DIR_OFF) - { + { // we're scanning + switch (g_eeprom.scan_resume_mode) { case SCAN_RESUME_TO: if (!g_scan_pause_mode) { - g_scan_pause_delay_in_10ms = scan_pause_delay_in_1_10ms; - g_scan_schedule_scan_listen = false; - g_scan_pause_mode = true; + g_scan_pause_delay_in_10ms = scan_pause_delay_in_1_10ms; + g_scan_schedule_scan_listen = false; + g_scan_pause_mode = true; } break; case SCAN_RESUME_CO: case SCAN_RESUME_SE: - g_scan_pause_delay_in_10ms = 0; - g_scan_schedule_scan_listen = false; + g_scan_pause_delay_in_10ms = 0; + g_scan_schedule_scan_listen = false; break; } @@ -521,10 +518,10 @@ void APP_StartListening(function_type_t Function, const bool reset_am_fix) if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_is_noaa_mode) { g_rx_vfo->channel_save = g_noaa_channel + NOAA_CHANNEL_FIRST; - g_rx_vfo->p_rx->frequency = NOAA_FREQUENCY_TABLE[g_noaa_channel]; - g_rx_vfo->p_tx->frequency = NOAA_FREQUENCY_TABLE[g_noaa_channel]; + g_rx_vfo->p_rx->frequency = NOAA_FREQUENCY_TABLE[g_noaa_channel]; + g_rx_vfo->p_tx->frequency = NOAA_FREQUENCY_TABLE[g_noaa_channel]; g_eeprom.screen_channel[chan] = g_rx_vfo->channel_save; - g_noaa_count_down_10ms = 500; // 5 sec + g_noaa_count_down_10ms = 5000 / 10; // 5 sec g_schedule_noaa = false; } #endif @@ -535,16 +532,14 @@ void APP_StartListening(function_type_t Function, const bool reset_am_fix) if (g_scan_state_dir == SCAN_STATE_DIR_OFF && g_css_scan_mode == CSS_SCAN_MODE_OFF && g_eeprom.dual_watch != DUAL_WATCH_OFF) - { // not scanning, dual watch is enabled + { // not scanning, but dual watch is enabled g_dual_watch_count_down_10ms = dual_watch_count_after_2_10ms; - g_schedule_dual_watch = false; + g_schedule_dual_watch = false; g_rx_vfo_is_active = true; - // let the user see DW is not active - g_dual_watch_active = false; - g_update_status = true; + g_update_status = true; } { // RF RX front end gain @@ -559,7 +554,7 @@ void APP_StartListening(function_type_t Function, const bool reset_am_fix) if (g_rx_vfo->am_mode && g_setting_am_fix) { // AM RX mode if (reset_am_fix) - AM_fix_reset(chan); // TODO: only reset it when moving channel/frequency + AM_fix_reset(chan); // TODO: only reset it when moving channel/frequency .. or do we ??? AM_fix_10ms(chan); } else @@ -573,8 +568,8 @@ void APP_StartListening(function_type_t Function, const bool reset_am_fix) // AF gain - original QS values BK4819_WriteRegister(BK4819_REG_48, - (11u << 12) | // ??? .. 0 to 15, doesn't seem to make any difference - ( 0u << 10) | // AF Rx Gain-1 + (11u << 12) | // ??? .. 0 to 15, doesn't seem to make any difference + ( 0u << 10) | // AF Rx Gain-1 (g_eeprom.volume_gain << 4) | // AF Rx Gain-2 (g_eeprom.dac_gain << 0)); // AF DAC Gain (after Gain-1 and Gain-2) @@ -606,7 +601,7 @@ void APP_StartListening(function_type_t Function, const bool reset_am_fix) g_update_status = true; } -uint32_t APP_SetFrequencyByStep(vfo_info_t *pInfo, int8_t Step) +uint32_t APP_set_frequency_by_step(vfo_info_t *pInfo, int8_t Step) { uint32_t Frequency = pInfo->freq_config_rx.frequency + (Step * pInfo->step_freq); @@ -632,7 +627,7 @@ uint32_t APP_SetFrequencyByStep(vfo_info_t *pInfo, int8_t Step) return Frequency; } -void SCAN_Stop(void) +void APP_stop_scan(void) { const uint8_t Previous = g_scan_restore_channel; @@ -658,7 +653,7 @@ void SCAN_Stop(void) RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo); } - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); g_update_display = true; return; @@ -677,13 +672,13 @@ void SCAN_Stop(void) g_update_status = true; } -static void FREQ_NextChannel(void) +static void APP_next_freq(void) { - g_rx_vfo->freq_config_rx.frequency = APP_SetFrequencyByStep(g_rx_vfo, g_scan_state_dir); + g_rx_vfo->freq_config_rx.frequency = APP_set_frequency_by_step(g_rx_vfo, g_scan_state_dir); RADIO_ApplyOffset(g_rx_vfo); RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo); - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); #ifdef ENABLE_FASTER_CHANNEL_SCAN g_scan_pause_delay_in_10ms = 9; // 90ms @@ -692,10 +687,10 @@ static void FREQ_NextChannel(void) #endif g_scan_keep_frequency = false; - g_update_display = true; + g_update_display = true; } -static void USER_NextChannel(void) +static void APP_next_channel(void) { static unsigned int prevChannel = 0; const bool enabled = (g_eeprom.scan_list_default < 2) ? g_eeprom.scan_list_enabled[g_eeprom.scan_list_default] : true; @@ -780,7 +775,7 @@ static void USER_NextChannel(void) g_eeprom.screen_channel[g_eeprom.rx_vfo] = g_scan_next_channel; RADIO_ConfigureChannel(g_eeprom.rx_vfo, VFO_CONFIGURE_RELOAD); - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); g_update_display = true; } @@ -799,14 +794,14 @@ static void USER_NextChannel(void) } #ifdef ENABLE_NOAA - static void NOAA_IncreaseChannel(void) + static void APP_next_noaa(void) { if (++g_noaa_channel >= ARRAY_SIZE(NOAA_FREQUENCY_TABLE)) g_noaa_channel = 0; } #endif -static void DUALWATCH_Alternate(void) +static void APP_toggle_dual_watch_vfo(void) { #ifdef ENABLE_NOAA if (g_is_noaa_mode) @@ -819,22 +814,17 @@ static void DUALWATCH_Alternate(void) g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.rx_vfo]; if (g_eeprom.vfo_info[0].channel_save >= NOAA_CHANNEL_FIRST) - NOAA_IncreaseChannel(); + APP_next_noaa(); } else #endif { // toggle between VFO's g_eeprom.rx_vfo = (g_eeprom.rx_vfo + 1) & 1; - g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.rx_vfo]; - - if (!g_dual_watch_active) - { // let the user see DW is active - g_dual_watch_active = true; - g_update_status = true; - } + g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.rx_vfo]; + g_update_status = true; } - RADIO_SetupRegisters(false); + RADIO_setup_registers(false); #ifdef ENABLE_NOAA g_dual_watch_count_down_10ms = g_is_noaa_mode ? dual_watch_count_noaa_10ms : dual_watch_count_toggle_10ms; @@ -843,7 +833,7 @@ static void DUALWATCH_Alternate(void) #endif } -void APP_CheckRadioInterrupts(void) +void APP_process_radio_interrupts(void) { if (g_screen_to_display == DISPLAY_SEARCH) return; @@ -875,7 +865,7 @@ void APP_CheckRadioInterrupts(void) g_update_display = true; } - if (g_rx_vfo->dtmf_decoding_enable || g_setting_killed) + if (g_rx_vfo->dtmf_decoding_enable || g_setting_radio_disabled) { if (g_dtmf_rx_index >= (sizeof(g_dtmf_rx) - 1)) { // make room @@ -931,9 +921,7 @@ void APP_CheckRadioInterrupts(void) g_dual_watch_count_down_10ms = dual_watch_count_after_vox_10ms; g_schedule_dual_watch = false; - // let the user see DW is not active - g_dual_watch_active = false; - g_update_status = true; + g_update_status = true; } } } @@ -959,7 +947,7 @@ void APP_CheckRadioInterrupts(void) } } -void APP_EndTransmission(void) +void APP_end_tx(void) { // back to RX mode RADIO_SendEndOfTransmission(); @@ -982,13 +970,13 @@ void APP_EndTransmission(void) #endif } - RADIO_SetupRegisters(false); + RADIO_setup_registers(false); } #ifdef ENABLE_VOX - static void APP_HandleVox(void) + static void APP_process_vox(void) { - if (g_setting_killed) + if (g_setting_radio_disabled) return; if (g_vox_resume_count_down == 0) @@ -1032,7 +1020,7 @@ void APP_EndTransmission(void) } else { - APP_EndTransmission(); + APP_end_tx(); if (g_eeprom.repeater_tail_tone_elimination == 0) { @@ -1067,25 +1055,24 @@ void APP_EndTransmission(void) } #endif -void APP_Update(void) +void APP_process(void) { #ifdef ENABLE_VOICE if (g_flag_play_queued_voice) { - AUDIO_PlayQueuedVoice(); g_flag_play_queued_voice = false; + AUDIO_PlayQueuedVoice(); } #endif if (g_current_function == FUNCTION_TRANSMIT && (g_tx_timeout_reached || g_serial_config_count_down_500ms > 0)) { // transmitter timed out or must de-key + g_tx_timeout_reached = false; + g_flag_end_tx = true; - g_flag_end_tx = true; - APP_EndTransmission(); - + APP_end_tx(); AUDIO_PlayBeep(BEEP_880HZ_60MS_TRIPLE_BEEP); - RADIO_Setg_vfo_state(VFO_STATE_TIMEOUT); GUI_DisplayScreen(); @@ -1095,7 +1082,7 @@ void APP_Update(void) return; if (g_current_function != FUNCTION_TRANSMIT) - APP_HandleFunction(); + APP_process_function(); #ifdef ENABLE_FMRADIO if (g_fm_radio_mode && g_fm_radio_count_down_500ms > 0) @@ -1115,35 +1102,35 @@ void APP_Update(void) if (IS_FREQ_CHANNEL(g_scan_next_channel)) { if (g_current_function == FUNCTION_INCOMING) - APP_StartListening(g_monitor_enabled ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); + APP_start_listening(g_monitor_enabled ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); else - FREQ_NextChannel(); // switch to next frequency + APP_next_freq(); // switch to next frequency } else { if (g_current_code_type == CODE_TYPE_NONE && g_current_function == FUNCTION_INCOMING) - APP_StartListening(g_monitor_enabled ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); + APP_start_listening(g_monitor_enabled ? FUNCTION_MONITOR : FUNCTION_RECEIVE, true); else - USER_NextChannel(); // switch to next channel + APP_next_channel(); // switch to next channel } - g_scan_pause_mode = false; - g_rx_reception_mode = RX_MODE_NONE; + g_scan_pause_mode = false; + g_rx_reception_mode = RX_MODE_NONE; g_scan_schedule_scan_listen = false; } } #ifdef ENABLE_VOICE - if (g_css_scan_mode == CSS_SCAN_MODE_SCANNING && g_scan_schedule_scan_listen && g_voice_write_index == 0) - #else - if (g_css_scan_mode == CSS_SCAN_MODE_SCANNING && g_scan_schedule_scan_listen) + if (g_voice_write_index == 0) #endif { - MENU_SelectNextCode(); - - g_scan_schedule_scan_listen = false; + if (g_css_scan_mode == CSS_SCAN_MODE_SCANNING && g_scan_schedule_scan_listen) + { + MENU_SelectNextCode(); + g_scan_schedule_scan_listen = false; + } } - + #ifdef ENABLE_NOAA #ifdef ENABLE_VOICE if (g_voice_write_index == 0) @@ -1151,8 +1138,8 @@ void APP_Update(void) { if (g_eeprom.dual_watch == DUAL_WATCH_OFF && g_is_noaa_mode && g_schedule_noaa) { - NOAA_IncreaseChannel(); - RADIO_SetupRegisters(false); + APP_next_noaa(); + RADIO_setup_registers(false); g_noaa_count_down_10ms = 7; // 70ms g_schedule_noaa = false; @@ -1183,12 +1170,12 @@ void APP_Update(void) g_dtmf_call_state == DTMF_CALL_STATE_NONE && g_current_function != FUNCTION_POWER_SAVE) { - DUALWATCH_Alternate(); // toggle between the two VFO's + APP_toggle_dual_watch_vfo(); // toggle between the two VFO's if (g_rx_vfo_is_active && g_screen_to_display == DISPLAY_MAIN) GUI_SelectNextDisplay(DISPLAY_MAIN); - g_rx_vfo_is_active = false; + g_rx_vfo_is_active = false; g_scan_pause_mode = false; g_rx_reception_mode = RX_MODE_NONE; g_schedule_dual_watch = false; @@ -1213,7 +1200,7 @@ void APP_Update(void) #ifdef ENABLE_VOX if (g_eeprom.vox_switch) - APP_HandleVox(); + APP_process_vox(); #endif if (g_schedule_power_save) @@ -1221,14 +1208,14 @@ void APP_Update(void) #ifdef ENABLE_NOAA if ( #ifdef ENABLE_FMRADIO - g_fm_radio_mode || + g_fm_radio_mode || #endif - g_ptt_is_pressed || - g_key_held || - g_eeprom.battery_save == 0 || - g_scan_state_dir != SCAN_STATE_DIR_OFF || - g_css_scan_mode != CSS_SCAN_MODE_OFF || - g_screen_to_display != DISPLAY_MAIN || + g_ptt_is_pressed || + g_key_held || + g_eeprom.battery_save == 0 || + g_scan_state_dir != SCAN_STATE_DIR_OFF || + g_css_scan_mode != CSS_SCAN_MODE_OFF || + g_screen_to_display != DISPLAY_MAIN || g_dtmf_call_state != DTMF_CALL_STATE_NONE) { g_battery_save_count_down_10ms = battery_save_count_10ms; @@ -1247,14 +1234,14 @@ void APP_Update(void) #else if ( #ifdef ENABLE_FMRADIO - g_fm_radio_mode || + g_fm_radio_mode || #endif - g_ptt_is_pressed || - g_key_held || - g_eeprom.battery_save == 0 || - g_scan_state_dir != SCAN_STATE_DIR_OFF || - g_css_scan_mode != CSS_SCAN_MODE_OFF || - g_screen_to_display != DISPLAY_MAIN || + g_ptt_is_pressed || + g_key_held || + g_eeprom.battery_save == 0 || + g_scan_state_dir != SCAN_STATE_DIR_OFF || + g_css_scan_mode != CSS_SCAN_MODE_OFF || + g_screen_to_display != DISPLAY_MAIN || g_dtmf_call_state != DTMF_CALL_STATE_NONE) { g_battery_save_count_down_10ms = battery_save_count_10ms; @@ -1291,7 +1278,7 @@ void APP_Update(void) g_scan_state_dir == SCAN_STATE_DIR_OFF && g_css_scan_mode == CSS_SCAN_MODE_OFF) { // dual watch mode, toggle between the two VFO's - DUALWATCH_Alternate(); + APP_toggle_dual_watch_vfo(); g_update_rssi = false; } @@ -1299,16 +1286,16 @@ void APP_Update(void) FUNCTION_Init(); g_power_save_10ms = power_save1_10ms; // come back here in a bit - g_rx_idle_mode = false; // RX is awake + g_rx_idle_mode = false; // RX is awake } else - if (g_eeprom.dual_watch == DUAL_WATCH_OFF || + if (g_eeprom.dual_watch == DUAL_WATCH_OFF || g_scan_state_dir != SCAN_STATE_DIR_OFF || - g_css_scan_mode != CSS_SCAN_MODE_OFF || + g_css_scan_mode != CSS_SCAN_MODE_OFF || g_update_rssi) { // dual watch mode, go back to sleep - updateRSSI(g_eeprom.rx_vfo); + APP_update_rssi(g_eeprom.rx_vfo); // go back to sleep @@ -1325,7 +1312,7 @@ void APP_Update(void) else { // toggle between the two VFO's - DUALWATCH_Alternate(); + APP_toggle_dual_watch_vfo(); g_update_rssi = true; g_power_save_10ms = power_save1_10ms; @@ -1337,13 +1324,13 @@ void APP_Update(void) } // called every 10ms -void APP_CheckKeys(void) +void APP_check_keys(void) { const bool ptt_pressed = !GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) && (g_serial_config_count_down_500ms == 0) && g_setting_tx_enable; key_code_t key; - if (g_setting_killed) + if (g_setting_radio_disabled) return; // ***************** @@ -1352,9 +1339,9 @@ void APP_CheckKeys(void) if (ptt_pressed) { // PTT pressed #ifdef ENABLE_AIRCOPY - if (!g_setting_killed && !g_ptt_is_pressed && g_screen_to_display != DISPLAY_AIRCOPY) + if (!g_setting_radio_disabled && !g_ptt_is_pressed && g_screen_to_display != DISPLAY_AIRCOPY) #else - if (!g_setting_killed && !g_ptt_is_pressed) + if (!g_setting_radio_disabled && !g_ptt_is_pressed) #endif { if (++g_ptt_debounce >= 3) // 30ms @@ -1365,7 +1352,7 @@ void APP_CheckKeys(void) g_ptt_was_released = false; g_ptt_debounce = 0; - APP_ProcessKey(KEY_PTT, true, false); + APP_process_key(KEY_PTT, true, false); #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); @@ -1386,7 +1373,7 @@ void APP_CheckKeys(void) g_ptt_was_released = true; g_ptt_debounce = 0; - APP_ProcessKey(KEY_PTT, false, false); + APP_process_key(KEY_PTT, false, false); #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); @@ -1430,11 +1417,11 @@ void APP_CheckKeys(void) #ifdef ENABLE_AIRCOPY if (g_screen_to_display != DISPLAY_AIRCOPY) - APP_ProcessKey(g_key_prev, false, g_key_held); + APP_process_key(g_key_prev, false, g_key_held); else - AIRCOPY_ProcessKey(g_key_prev, false, g_key_held); + AIRCOPY_process_key(g_key_prev, false, g_key_held); #else - APP_ProcessKey(g_key_prev, false, g_key_held); + APP_process_key(g_key_prev, false, g_key_held); #endif g_key_debounce_press = 0; @@ -1470,11 +1457,11 @@ void APP_CheckKeys(void) #ifdef ENABLE_AIRCOPY if (g_screen_to_display != DISPLAY_AIRCOPY) - APP_ProcessKey(g_key_prev, true, g_key_held); + APP_process_key(g_key_prev, true, g_key_held); else - AIRCOPY_ProcessKey(g_key_prev, true, g_key_held); + AIRCOPY_process_key(g_key_prev, true, g_key_held); #else - APP_ProcessKey(g_key_prev, true, g_key_held); + APP_process_key(g_key_prev, true, g_key_held); #endif g_update_status = true; @@ -1495,11 +1482,11 @@ void APP_CheckKeys(void) #ifdef ENABLE_AIRCOPY if (g_screen_to_display != DISPLAY_AIRCOPY) - APP_ProcessKey(g_key_prev, true, g_key_held); + APP_process_key(g_key_prev, true, g_key_held); else - AIRCOPY_ProcessKey(g_key_prev, true, g_key_held); + AIRCOPY_process_key(g_key_prev, true, g_key_held); #else - APP_ProcessKey(g_key_prev, true, g_key_held); + APP_process_key(g_key_prev, true, g_key_held); #endif //g_update_status = true; @@ -1519,11 +1506,11 @@ void APP_CheckKeys(void) #ifdef ENABLE_AIRCOPY if (g_screen_to_display != DISPLAY_AIRCOPY) - APP_ProcessKey(g_key_prev, true, g_key_held); + APP_process_key(g_key_prev, true, g_key_held); else - AIRCOPY_ProcessKey(g_key_prev, true, g_key_held); + AIRCOPY_process_key(g_key_prev, true, g_key_held); #else - APP_ProcessKey(g_key_prev, true, g_key_held); + APP_process_key(g_key_prev, true, g_key_held); #endif //g_update_status = true; @@ -1535,7 +1522,7 @@ void APP_CheckKeys(void) // ***************** } -void APP_TimeSlice10ms(void) +void APP_time_slice_10ms(void) { g_flash_light_blink_counter++; @@ -1574,7 +1561,7 @@ void APP_TimeSlice10ms(void) g_flag_save_channel = false; RADIO_ConfigureChannel(g_eeprom.tx_vfo, VFO_CONFIGURE); - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); GUI_SelectNextDisplay(DISPLAY_MAIN); } @@ -1609,7 +1596,7 @@ void APP_TimeSlice10ms(void) AIRCOPY_process_fsk_rx_10ms(); - APP_CheckKeys(); + APP_check_keys(); if (g_update_display) GUI_DisplayScreen(); @@ -1628,7 +1615,7 @@ void APP_TimeSlice10ms(void) #endif if (g_current_function != FUNCTION_POWER_SAVE || !g_rx_idle_mode) - APP_CheckRadioInterrupts(); + APP_process_radio_interrupts(); if (g_current_function == FUNCTION_TRANSMIT) { // transmitting @@ -1751,14 +1738,14 @@ void APP_TimeSlice10ms(void) { if (--g_search_delay_10ms > 0) { - APP_CheckKeys(); + APP_check_keys(); return; } } if (g_search_edit_state != SEARCH_EDIT_STATE_NONE) { // waiting for user input choice - APP_CheckKeys(); + APP_check_keys(); return; } @@ -1950,10 +1937,10 @@ void APP_TimeSlice10ms(void) } } - APP_CheckKeys(); + APP_check_keys(); } -void cancelUserInputModes(void) +void APP_cancel_user_input_modes(void) { if (g_ask_to_save) { @@ -1991,7 +1978,7 @@ void cancelUserInputModes(void) } // this is called once every 500ms -void APP_TimeSlice500ms(void) +void APP_time_slice_500ms(void) { bool exit_menu = false; @@ -2010,7 +1997,7 @@ void APP_TimeSlice500ms(void) { if (--g_key_input_count_down == 0) { - cancelUserInputModes(); + APP_cancel_user_input_modes(); if (g_beep_to_play != BEEP_NONE) { @@ -2115,9 +2102,9 @@ void APP_TimeSlice500ms(void) if (g_screen_to_display != DISPLAY_AIRCOPY) #endif { - if (g_css_scan_mode == CSS_SCAN_MODE_OFF && - g_scan_state_dir == SCAN_STATE_DIR_OFF && - (g_screen_to_display != DISPLAY_SEARCH || + if (g_css_scan_mode == CSS_SCAN_MODE_OFF && + g_scan_state_dir == SCAN_STATE_DIR_OFF && + (g_screen_to_display != DISPLAY_SEARCH || g_search_css_state == SEARCH_CSS_STATE_FOUND || g_search_css_state == SEARCH_CSS_STATE_FAILED || g_search_css_state == SEARCH_CSS_STATE_REPEAT)) @@ -2156,7 +2143,7 @@ void APP_TimeSlice500ms(void) RADIO_ConfigureChannel(0, VFO_CONFIGURE_RELOAD); RADIO_ConfigureChannel(1, VFO_CONFIGURE_RELOAD); - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); } */ DTMF_clear_input_box(); @@ -2200,7 +2187,7 @@ void APP_TimeSlice500ms(void) } if (g_current_function != FUNCTION_POWER_SAVE && g_current_function != FUNCTION_TRANSMIT) - updateRSSI(g_eeprom.rx_vfo); + APP_update_rssi(g_eeprom.rx_vfo); #ifdef ENABLE_FMRADIO if (!g_ptt_is_pressed && g_fm_resume_count_down_500ms > 0) @@ -2322,7 +2309,7 @@ void APP_TimeSlice500ms(void) } #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) - static void ALARM_Off(void) + static void APP_alarm_off(void) { g_alarm_state = ALARM_STATE_OFF; @@ -2341,43 +2328,43 @@ void APP_TimeSlice500ms(void) SYSTEM_DelayMs(5); - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); if (g_screen_to_display != DISPLAY_MENU) // 1of11 .. don't close the menu g_request_display_screen = DISPLAY_MAIN; } #endif -void CHANNEL_Next(const bool flag, const scan_state_dir_t scan_direction) +void APP_channel_next(const bool flag, const scan_state_dir_t scan_direction) { - RADIO_SelectVfos(); + RADIO_select_vfos(); - g_scan_next_channel = g_rx_vfo->channel_save; + g_scan_next_channel = g_rx_vfo->channel_save; g_scan_current_scan_list = SCAN_NEXT_CHAN_SCANLIST1; - g_scan_state_dir = scan_direction; + g_scan_state_dir = scan_direction; if (g_scan_next_channel <= USER_CHANNEL_LAST) { // channel mode if (flag) g_scan_restore_channel = g_scan_next_channel; - USER_NextChannel(); + APP_next_channel(); } else { // frequency mode if (flag) g_scan_restore_frequency = g_rx_vfo->freq_config_rx.frequency; - FREQ_NextChannel(); + APP_next_freq(); } g_scan_pause_delay_in_10ms = scan_pause_delay_in_2_10ms; g_scan_schedule_scan_listen = false; g_scan_pause_mode = false; - g_rx_reception_mode = RX_MODE_NONE; - - g_scan_keep_frequency = false; + g_scan_keep_frequency = false; + + g_rx_reception_mode = RX_MODE_NONE; } -static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const bool key_held) +static void APP_process_key(const key_code_t Key, const bool key_pressed, const bool key_held) { bool flag = false; @@ -2482,7 +2469,7 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b } // cancel user input - cancelUserInputModes(); + APP_cancel_user_input_modes(); } if (key_pressed && g_screen_to_display == DISPLAY_MENU) @@ -2622,7 +2609,7 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b else if ((!key_held && key_pressed) || (g_alarm_state == ALARM_STATE_TX1750 && key_held && !key_pressed)) { - ALARM_Off(); + APP_alarm_off(); if (g_eeprom.repeater_tail_tone_elimination == 0) FUNCTION_Select(FUNCTION_FOREGROUND); @@ -2643,26 +2630,26 @@ static void APP_ProcessKey(const key_code_t Key, const bool key_pressed, const b switch (g_screen_to_display) { case DISPLAY_MAIN: - MAIN_ProcessKeys(Key, key_pressed, key_held); + MAIN_process_key(Key, key_pressed, key_held); break; #ifdef ENABLE_FMRADIO case DISPLAY_FM: - FM_ProcessKeys(Key, key_pressed, key_held); + FM_process_key(Key, key_pressed, key_held); break; #endif case DISPLAY_MENU: - MENU_ProcessKeys(Key, key_pressed, key_held); + MENU_process_key(Key, key_pressed, key_held); break; case DISPLAY_SEARCH: - SEARCH_ProcessKeys(Key, key_pressed, key_held); + SEARCH_process_key(Key, key_pressed, key_held); break; #ifdef ENABLE_AIRCOPY case DISPLAY_AIRCOPY: - AIRCOPY_ProcessKey(Key, key_pressed, key_held); + AIRCOPY_process_key(Key, key_pressed, key_held); break; #endif @@ -2703,8 +2690,8 @@ Skip: MENU_AcceptSetting(); - g_flag_refresh_menu = true; - g_flag_accept_setting = false; + g_flag_refresh_menu = true; + g_flag_accept_setting = false; } if (g_search_flag_stop_scan) @@ -2719,8 +2706,9 @@ Skip: SETTINGS_SaveSettings(); else g_flag_save_settings = 1; + g_request_save_settings = false; - g_update_status = true; + g_update_status = true; } #ifdef ENABLE_FMRADIO @@ -2730,6 +2718,7 @@ Skip: SETTINGS_SaveFM(); else g_flag_save_fm = true; + g_request_save_fm = false; } #endif @@ -2740,6 +2729,7 @@ Skip: SETTINGS_SaveVfoIndices(); else g_flag_save_vfo = true; + g_request_save_vfo = false; } @@ -2750,7 +2740,7 @@ Skip: SETTINGS_SaveChannel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, g_request_save_channel); if (g_screen_to_display != DISPLAY_SEARCH) - if (g_vfo_configure_mode == VFO_CONFIGURE_NONE) // 'if' is so as we don't wipe out previously setting this variable elsewhere + if (g_vfo_configure_mode == VFO_CONFIGURE_NONE) // don't wipe previous variable setting g_vfo_configure_mode = VFO_CONFIGURE; } else @@ -2766,14 +2756,20 @@ Skip: if (g_vfo_configure_mode != VFO_CONFIGURE_NONE) { + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) + UART_printf("audio gap\r\n"); + #endif + if (g_flag_reset_vfos) { RADIO_ConfigureChannel(0, g_vfo_configure_mode); RADIO_ConfigureChannel(1, g_vfo_configure_mode); } else + { RADIO_ConfigureChannel(g_eeprom.tx_vfo, g_vfo_configure_mode); - + } + if (g_request_display_screen == DISPLAY_INVALID) g_request_display_screen = DISPLAY_MAIN; @@ -2784,23 +2780,23 @@ Skip: if (g_flag_reconfigure_vfos) { - RADIO_SelectVfos(); + RADIO_select_vfos(); #ifdef ENABLE_NOAA RADIO_ConfigureNOAA(); #endif - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); - g_dtmf_auto_reset_time_500ms = 0; - g_dtmf_call_state = DTMF_CALL_STATE_NONE; + g_dtmf_auto_reset_time_500ms = 0; + g_dtmf_call_state = DTMF_CALL_STATE_NONE; g_dtmf_tx_stop_count_down_500ms = 0; - g_dtmf_is_tx = false; + g_dtmf_is_tx = false; - g_vfo_rssi_bar_level[0] = 0; - g_vfo_rssi_bar_level[1] = 0; + g_vfo_rssi_bar_level[0] = 0; + g_vfo_rssi_bar_level[1] = 0; - g_flag_reconfigure_vfos = false; + g_flag_reconfigure_vfos= false; if (g_monitor_enabled) ACTION_Monitor(); // 1of11 @@ -2809,7 +2805,7 @@ Skip: if (g_flag_refresh_menu) { g_flag_refresh_menu = false; - g_menu_count_down = menu_timeout_500ms; + g_menu_count_down = menu_timeout_500ms; MENU_ShowCurrentSetting(); } @@ -2817,8 +2813,7 @@ Skip: if (g_search_flag_start_scan) { g_search_flag_start_scan = false; - - g_monitor_enabled = false; + g_monitor_enabled = false; #ifdef ENABLE_VOICE AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN); @@ -2845,7 +2840,7 @@ Skip: #endif GUI_SelectNextDisplay(g_request_display_screen); - g_request_display_screen = DISPLAY_INVALID; - g_update_display = true; + g_request_display_screen = DISPLAY_INVALID; + g_update_display = true; } diff --git a/app/app.h b/app/app.h index dad6636..b922d50 100644 --- a/app/app.h +++ b/app/app.h @@ -28,14 +28,14 @@ extern const uint8_t orig_lna; extern const uint8_t orig_mixer; extern const uint8_t orig_pga; -void APP_EndTransmission(void); -void SCAN_Stop(void); -void CHANNEL_Next(const bool flag, const scan_state_dir_t scan_direction); -void APP_StartListening(function_type_t Function, const bool reset_am_fix); -uint32_t APP_SetFrequencyByStep(vfo_info_t *pInfo, int8_t Step); -void APP_Update(void); -void APP_TimeSlice10ms(void); -void APP_TimeSlice500ms(void); +void APP_end_tx(void); +void APP_stop_scan(void); +void APP_channel_next(const bool flag, const scan_state_dir_t scan_direction); +void APP_start_listening(function_type_t Function, const bool reset_am_fix); +uint32_t APP_set_frequency_by_step(vfo_info_t *pInfo, int8_t Step); +void APP_process(void); +void APP_time_slice_10ms(void); +void APP_time_slice_500ms(void); #endif diff --git a/app/dtmf.c b/app/dtmf.c index bd1d91a..c86240e 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -215,7 +215,7 @@ void DTMF_HandleRequest(void) return; } - if (!g_rx_vfo->dtmf_decoding_enable && !g_setting_killed) + if (!g_rx_vfo->dtmf_decoding_enable && !g_setting_radio_disabled) { // D-DCD is disabled or we're alive DTMF_clear_RX(); return; @@ -235,7 +235,7 @@ void DTMF_HandleRequest(void) if (g_eeprom.permit_remote_kill) { - g_setting_killed = true; // oooerr ! + g_setting_radio_disabled = true; // oooerr ! DTMF_clear_RX(); @@ -274,7 +274,7 @@ void DTMF_HandleRequest(void) if (DTMF_CompareMessage(g_dtmf_rx + Offset, String, strlen(String), true)) { // shit, we're back ! - g_setting_killed = false; + g_setting_radio_disabled = false; DTMF_clear_RX(); @@ -328,8 +328,8 @@ void DTMF_HandleRequest(void) } } - if (g_setting_killed || g_dtmf_call_state != DTMF_CALL_STATE_NONE) - { // we've been killed or expecting a reply + if (g_setting_radio_disabled || g_dtmf_call_state != DTMF_CALL_STATE_NONE) + { // we've been disabled, or expecting a reply return; } diff --git a/app/fm.c b/app/fm.c index 17d1392..f2e802e 100644 --- a/app/fm.c +++ b/app/fm.c @@ -605,7 +605,7 @@ Bail: g_request_display_screen = DISPLAY_FM; } -void FM_ProcessKeys(key_code_t Key, bool key_pressed, bool key_held) +void FM_process_key(key_code_t Key, bool key_pressed, bool key_held) { switch (Key) { diff --git a/app/fm.h b/app/fm.h index 7cc0a40..a7d3628 100644 --- a/app/fm.h +++ b/app/fm.h @@ -50,7 +50,7 @@ void FM_Tune(uint16_t Frequency, int8_t Step, bool bFlag); void FM_PlayAndUpdate(void); int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit); -void FM_ProcessKeys(key_code_t Key, bool bKeyPressed, bool bKeyHeld); +void FM_process_key(key_code_t Key, bool bKeyPressed, bool bKeyHeld); void FM_Play(void); void FM_Start(void); diff --git a/app/generic.c b/app/generic.c index d9bfe9e..df9c7c0 100644 --- a/app/generic.c +++ b/app/generic.c @@ -109,7 +109,7 @@ void GENERIC_Key_PTT(bool key_pressed) } else { - APP_EndTransmission(); + APP_end_tx(); if (g_eeprom.repeater_tail_tone_elimination == 0) FUNCTION_Select(FUNCTION_FOREGROUND); @@ -153,7 +153,7 @@ void GENERIC_Key_PTT(bool key_pressed) else if (g_scan_state_dir != SCAN_STATE_DIR_OFF) { // frequency/channel scanning . .stop - SCAN_Stop(); + APP_stop_scan(); } else if (g_css_scan_mode != CSS_SCAN_MODE_OFF) diff --git a/app/main.c b/app/main.c index c1cbab9..5b91c5f 100644 --- a/app/main.c +++ b/app/main.c @@ -80,7 +80,7 @@ static void processFKeyFunction(const key_code_t Key) switch (Key) { case KEY_0: // FM - + #ifdef ENABLE_FMRADIO ACTION_FM(); #else @@ -93,7 +93,7 @@ static void processFKeyFunction(const key_code_t Key) break; case KEY_1: // BAND - + if (!IS_FREQ_CHANNEL(g_tx_vfo->channel_save)) { g_fkey_pressed = false; @@ -124,7 +124,7 @@ static void processFKeyFunction(const key_code_t Key) break; case KEY_2: // A/B - + if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_CHAN_A) g_eeprom.cross_vfo_rx_tx = CROSS_BAND_CHAN_B; else @@ -148,11 +148,7 @@ static void processFKeyFunction(const key_code_t Key) break; case KEY_3: // VFO/MR - #ifdef ENABLE_NOAA - if (g_eeprom.vfo_open && IS_NOT_NOAA_CHANNEL(g_tx_vfo->channel_save)) - #else - if (g_eeprom.vfo_open) - #endif + if (g_eeprom.vfo_open && IS_NOT_NOAA_CHANNEL(g_tx_vfo->channel_save)) { uint8_t Channel; @@ -195,7 +191,7 @@ static void processFKeyFunction(const key_code_t Key) break; case KEY_4: // FC - + g_fkey_pressed = false; g_search_flag_start_scan = true; g_search_single_frequency = false; @@ -207,7 +203,7 @@ static void processFKeyFunction(const key_code_t Key) break; case KEY_5: // NOAA - + #ifdef ENABLE_NOAA if (IS_NOT_NOAA_CHANNEL(g_tx_vfo->channel_save)) @@ -234,13 +230,13 @@ static void processFKeyFunction(const key_code_t Key) break; case KEY_6: // H/M/L - + ACTION_Power(); // g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; break; case KEY_7: // VOX - + #ifdef ENABLE_VOX ACTION_Vox(); #else @@ -250,14 +246,14 @@ static void processFKeyFunction(const key_code_t Key) break; case KEY_8: // R - + g_tx_vfo->frequency_reverse = g_tx_vfo->frequency_reverse == false; g_request_save_channel = 1; // g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; break; case KEY_9: // CALL - + if (RADIO_CheckValidChannel(g_eeprom.chan_1_call, false, 0)) { g_eeprom.user_channel[Vfo] = g_eeprom.chan_1_call; @@ -461,14 +457,14 @@ static void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) Channel = (g_input_box[0] * 10) + g_input_box[1]; if (Channel >= 1 && Channel <= ARRAY_SIZE(NOAA_FREQUENCY_TABLE)) { - Channel += NOAA_CHANNEL_FIRST; + Channel += NOAA_CHANNEL_FIRST; #ifdef ENABLE_VOICE - g_another_voice_id = (voice_id_t)Key; + g_another_voice_id = (voice_id_t)Key; #endif g_eeprom.noaa_channel[Vfo] = Channel; g_eeprom.screen_channel[Vfo] = Channel; - g_request_save_vfo = true; - g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; + g_request_save_vfo = true; + g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; return; } } @@ -518,7 +514,7 @@ static void MAIN_Key_EXIT(bool key_pressed, bool key_held) } else { - SCAN_Stop(); + APP_stop_scan(); #ifdef ENABLE_VOICE g_another_voice_id = VOICE_ID_SCANNING_STOP; @@ -573,8 +569,8 @@ static void MAIN_Key_MENU(const bool key_pressed, const bool key_held) g_request_display_screen = DISPLAY_MAIN; } - g_fkey_pressed = false; - g_update_status = true; + g_fkey_pressed = false; + g_update_status = true; #ifdef ENABLE_COPY_CHAN_TO_VFO @@ -584,7 +580,7 @@ static void MAIN_Key_MENU(const bool key_pressed, const bool key_held) if (g_scan_state_dir != SCAN_STATE_DIR_OFF) { if (g_current_function != FUNCTION_INCOMING || - g_rx_reception_mode == RX_MODE_NONE || + g_rx_reception_mode == RX_MODE_NONE || g_scan_pause_delay_in_10ms == 0) { // scan is running (not paused) return; @@ -598,14 +594,14 @@ static void MAIN_Key_MENU(const bool key_pressed, const bool key_held) const unsigned int channel = FREQ_CHANNEL_FIRST + g_eeprom.vfo_info[vfo].band; - g_eeprom.screen_channel[vfo] = channel; + g_eeprom.screen_channel[vfo] = channel; g_eeprom.vfo_info[vfo].channel_save = channel; - g_eeprom.tx_vfo = vfo; + g_eeprom.tx_vfo = vfo; - RADIO_SelectVfos(); + RADIO_select_vfos(); RADIO_ApplyOffset(g_rx_vfo); RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo); - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); g_request_save_vfo = true; @@ -629,8 +625,10 @@ static void MAIN_Key_MENU(const bool key_pressed, const bool key_held) if (!key_pressed && !g_dtmf_input_mode) { // menu key released + const bool flag = (g_input_box_index == 0); - g_input_box_index = 0; + + g_input_box_index = 0; if (flag) { @@ -654,15 +652,18 @@ static void MAIN_Key_STAR(bool key_pressed, bool key_held) if (g_input_box_index > 0) { // entering a frequency or DTMF string + if (!key_held && key_pressed) g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + return; } if (key_held && !g_fkey_pressed) { // long press .. toggle scanning + if (!key_pressed) - return; // released + return; // released ACTION_Scan(false); @@ -672,31 +673,23 @@ static void MAIN_Key_STAR(bool key_pressed, bool key_held) if (key_pressed) { // just pressed -// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; - g_beep_to_play = BEEP_880HZ_40MS_OPTIONAL; + g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; return; } - // just released - if (!g_fkey_pressed) { // pressed without the F-key - #ifdef ENABLE_NOAA - if (g_scan_state_dir == SCAN_STATE_DIR_OFF && IS_NOT_NOAA_CHANNEL(g_tx_vfo->channel_save)) - #else - if (g_scan_state_dir == SCAN_STATE_DIR_OFF) - #endif + if (g_scan_state_dir == SCAN_STATE_DIR_OFF && IS_NOT_NOAA_CHANNEL(g_tx_vfo->channel_save)) { // start entering a DTMF string - memmove( - g_dtmf_input_box, - g_dtmf_string, + memmove( g_dtmf_input_box, g_dtmf_string, (sizeof(g_dtmf_input_box) <= (sizeof(g_dtmf_string) - 1)) ? sizeof(g_dtmf_input_box) : sizeof(g_dtmf_string) - 1); + g_dtmf_input_box_index = 0; g_dtmf_input_mode = true; - g_key_input_count_down = key_input_timeout_500ms; + g_key_input_count_down = key_input_timeout_500ms; g_request_display_screen = DISPLAY_MAIN; } @@ -705,30 +698,38 @@ static void MAIN_Key_STAR(bool key_pressed, bool key_held) { // with the F-key g_fkey_pressed = false; - #ifdef ENABLE_NOAA - if (IS_NOAA_CHANNEL(g_tx_vfo->channel_save)) - { - g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; - return; - } - #endif + if (IS_NOAA_CHANNEL(g_tx_vfo->channel_save)) + { + g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + return; + } // scan the CTCSS/DCS code - g_search_flag_start_scan = true; - g_search_single_frequency = true; - g_backup_cross_vfo_rx_tx = g_eeprom.cross_vfo_rx_tx; - g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF; + g_search_flag_start_scan = true; + g_search_single_frequency = true; + g_backup_cross_vfo_rx_tx = g_eeprom.cross_vfo_rx_tx; + g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF; } -// g_ptt_was_released = true; // why is this being set ? + g_ptt_was_released = true; - g_update_status = true; + g_update_status = true; } static void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Direction) { uint8_t Channel = g_eeprom.screen_channel[g_eeprom.tx_vfo]; + // only update eeprom when the key is released (saves wear and tear) + if (!key_pressed && g_scan_state_dir == SCAN_STATE_DIR_OFF && IS_NOT_NOAA_CHANNEL(Channel) && IS_FREQ_CHANNEL(Channel)) + { + SETTINGS_SaveChannel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, 1); + + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) +// UART_printf("save chan\r\n"); + #endif + } + if (key_held || !key_pressed) { // long press @@ -759,20 +760,23 @@ static void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t D return; } - g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; +// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; } if (g_scan_state_dir == SCAN_STATE_DIR_OFF) - { - #ifdef ENABLE_NOAA - if (IS_NOT_NOAA_CHANNEL(Channel)) - #endif + { // not scanning + + if (IS_NOT_NOAA_CHANNEL(Channel)) { uint8_t Next; if (IS_FREQ_CHANNEL(Channel)) { // step/down in frequency - const uint32_t frequency = APP_SetFrequencyByStep(g_tx_vfo, Direction); + + const frequency_band_t old_band = FREQUENCY_GetBand(g_tx_vfo->freq_config_rx.frequency); + frequency_band_t new_band; + + const uint32_t frequency = APP_set_frequency_by_step(g_tx_vfo, Direction); if (RX_freq_check(frequency) < 0) { // frequency not allowed @@ -780,9 +784,20 @@ static void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t D return; } + new_band = FREQUENCY_GetBand(frequency); + g_tx_vfo->freq_config_rx.frequency = frequency; - g_request_save_channel = 1; + if (new_band != old_band) + { + g_request_save_channel = 1; + } + else + { // don't need to go through all the other stuff + BK4819_set_rf_frequency(frequency, true); + //BK4819_PickRXFilterPathBasedOnFrequency(frequency); + } + return; } @@ -815,23 +830,24 @@ static void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t D g_request_save_vfo = true; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; + return; } // jump to the next channel - CHANNEL_Next(false, Direction); - g_scan_pause_delay_in_10ms = 1; - g_scan_schedule_scan_listen = false; + APP_channel_next(false, Direction); + g_scan_pause_delay_in_10ms = 1; + g_scan_schedule_scan_listen = false; -// g_ptt_was_released = true; // why is this being set ? + g_ptt_was_released = true; } -void MAIN_ProcessKeys(key_code_t key, bool key_pressed, bool key_held) +void MAIN_process_key(key_code_t key, bool key_pressed, bool key_held) { #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) - UART_printf(" main 1 key %2u %u %u %u\r\n", key, key_pressed, key_held); +// UART_printf(" main 1 key %2u %u %u %u\r\n", key, key_pressed, key_held); #endif - + #ifdef ENABLE_FMRADIO if (g_fm_radio_mode && key != KEY_PTT && key != KEY_EXIT) { @@ -850,7 +866,7 @@ void MAIN_ProcessKeys(key_code_t key, bool key_pressed, bool key_held) { DTMF_Append(Character); g_key_input_count_down = key_input_timeout_500ms; - //g_ptt_was_released = true; // why is this being set ? + g_ptt_was_released = true; g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; g_request_display_screen = DISPLAY_MAIN; } diff --git a/app/main.h b/app/main.h index b2efa69..04ac80a 100644 --- a/app/main.h +++ b/app/main.h @@ -19,7 +19,7 @@ #include "driver/keyboard.h" -void MAIN_ProcessKeys(key_code_t Key, bool bKeyPressed, bool bKeyHeld); +void MAIN_process_key(key_code_t Key, bool bKeyPressed, bool bKeyHeld); #endif diff --git a/app/menu.c b/app/menu.c index 642e5ba..ffede43 100644 --- a/app/menu.c +++ b/app/menu.c @@ -83,7 +83,7 @@ void MENU_StartCssScan(int8_t Direction) g_menu_scroll_direction = Direction; - RADIO_SelectVfos(); + RADIO_select_vfos(); MENU_SelectNextCode(); @@ -96,7 +96,7 @@ void MENU_StopCssScan(void) g_css_scan_mode = CSS_SCAN_MODE_OFF; g_update_status = true; - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); } int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax) @@ -253,8 +253,8 @@ int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax) case MENU_NOAA_S: #endif case MENU_350TX: - case MENU_200TX: - case MENU_500TX: + case MENU_174TX: + case MENU_470TX: case MENU_350EN: case MENU_SCREN: case MENU_TX_EN: @@ -559,12 +559,10 @@ void MENU_AcceptSetting(void) break; case MENU_XB: - #ifdef ENABLE_NOAA - if (IS_NOAA_CHANNEL(g_eeprom.screen_channel[0])) - return; - if (IS_NOAA_CHANNEL(g_eeprom.screen_channel[1])) - return; - #endif + if (IS_NOAA_CHANNEL(g_eeprom.screen_channel[0])) + return; + if (IS_NOAA_CHANNEL(g_eeprom.screen_channel[1])) + return; g_eeprom.cross_vfo_rx_tx = g_sub_menu_selection; g_flag_reconfigure_vfos = true; @@ -795,12 +793,12 @@ void MENU_AcceptSetting(void) g_setting_freq_lock = g_sub_menu_selection; break; - case MENU_200TX: - g_setting_200_tx_enable = g_sub_menu_selection; + case MENU_174TX: + g_setting_174_tx_enable = g_sub_menu_selection; break; - case MENU_500TX: - g_setting_500_tx_enable = g_sub_menu_selection; + case MENU_470TX: + g_setting_470_tx_enable = g_sub_menu_selection; break; case MENU_350EN: @@ -883,7 +881,7 @@ void MENU_SelectNextCode(void) g_selected_code = g_sub_menu_selection - 1; } - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); g_scan_pause_delay_in_10ms = (g_selected_code_type == CODE_TYPE_CONTINUOUS_TONE) ? scan_pause_delay_in_3_10ms : scan_pause_delay_in_4_10ms; @@ -1229,12 +1227,12 @@ void MENU_ShowCurrentSetting(void) g_sub_menu_selection = g_setting_freq_lock; break; - case MENU_200TX: - g_sub_menu_selection = g_setting_200_tx_enable; + case MENU_174TX: + g_sub_menu_selection = g_setting_174_tx_enable; break; - case MENU_500TX: - g_sub_menu_selection = g_setting_500_tx_enable; + case MENU_470TX: + g_sub_menu_selection = g_setting_470_tx_enable; break; case MENU_350EN: @@ -1663,13 +1661,9 @@ static void MENU_Key_STAR(const bool key_pressed, const bool key_held) return; } - RADIO_SelectVfos(); + RADIO_select_vfos(); - #ifdef ENABLE_NOAA - if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_rx_vfo->am_mode == 0) - #else - if (g_rx_vfo->am_mode == 0) - #endif + if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_rx_vfo->am_mode == 0) { if (g_menu_cursor == MENU_R_CTCS || g_menu_cursor == MENU_R_DCS) { // scan CTCSS or DCS to find the tone/code of the incoming signal @@ -1818,7 +1812,7 @@ static void MENU_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Direction) g_request_display_screen = DISPLAY_MENU; } -void MENU_ProcessKeys(key_code_t Key, bool key_pressed, bool key_held) +void MENU_process_key(key_code_t Key, bool key_pressed, bool key_held) { switch (Key) { diff --git a/app/menu.h b/app/menu.h index a2df065..ec5e185 100644 --- a/app/menu.h +++ b/app/menu.h @@ -30,7 +30,7 @@ void MENU_ShowCurrentSetting(void); void MENU_StartCssScan(int8_t Direction); void MENU_StopCssScan(void); -void MENU_ProcessKeys(key_code_t Key, bool key_pressed, bool key_held); +void MENU_process_key(key_code_t Key, bool key_pressed, bool key_held); #endif diff --git a/app/search.c b/app/search.c index 79c436d..87e0a2b 100644 --- a/app/search.c +++ b/app/search.c @@ -423,7 +423,7 @@ static void SEARCH_Key_UP_DOWN(bool key_pressed, bool pKeyHeld, int8_t Direction g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; } -void SEARCH_ProcessKeys(key_code_t Key, bool key_pressed, bool key_held) +void SEARCH_process_key(key_code_t Key, bool key_pressed, bool key_held) { switch (Key) { @@ -471,7 +471,7 @@ void SEARCH_Start(void) BK4819_StopScan(); - RADIO_SelectVfos(); + RADIO_select_vfos(); #ifdef ENABLE_NOAA if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save)) @@ -486,7 +486,7 @@ void SEARCH_Start(void) g_rx_vfo->step_setting = BackupStep; g_rx_vfo->step_freq = BackupStepFreq; - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); #ifdef ENABLE_NOAA g_is_noaa_mode = false; diff --git a/app/search.h b/app/search.h index 5db8def..922d7bc 100644 --- a/app/search.h +++ b/app/search.h @@ -55,7 +55,7 @@ extern uint8_t g_search_delay_10ms; extern uint8_t g_search_hit_count; extern bool g_search_use_css_result; -void SEARCH_ProcessKeys(key_code_t Key, bool key_pressed, bool key_held); +void SEARCH_process_key(key_code_t Key, bool key_pressed, bool key_held); void SEARCH_Start(void); #endif diff --git a/app/spectrum.c b/app/spectrum.c index e1f7e03..84e0e49 100644 --- a/app/spectrum.c +++ b/app/spectrum.c @@ -202,7 +202,7 @@ static void SetModulation(ModulationType type) static void SetF(uint32_t f) { fMeasure = f; - BK4819_SetFrequency(fMeasure); + BK4819_set_rf_frequency(fMeasure); BK4819_PickRXFilterPathBasedOnFrequency(fMeasure); uint16_t reg = BK4819_ReadRegister(BK4819_REG_30); BK4819_WriteRegister(BK4819_REG_30, 0); @@ -211,7 +211,7 @@ static void SetF(uint32_t f) { static void SetTxF(uint32_t f) { fTx = f; - BK4819_SetFrequency(f); + BK4819_set_rf_frequency(f); BK4819_PickRXFilterPathBasedOnFrequency(f); uint16_t reg = BK4819_ReadRegister(BK4819_REG_30); BK4819_WriteRegister(BK4819_REG_30, 0); diff --git a/board.c b/board.c index bb8b39a..8b011ea 100644 --- a/board.c +++ b/board.c @@ -729,9 +729,9 @@ void BOARD_EEPROM_load(void) g_setting_freq_lock = (Data[0] < 6) ? Data[0] : FREQ_LOCK_NORMAL; #endif g_setting_350_tx_enable = (Data[1] < 2) ? Data[1] : false; // was true - g_setting_killed = (Data[2] < 2) ? Data[2] : false; - g_setting_200_tx_enable = (Data[3] < 2) ? Data[3] : false; - g_setting_500_tx_enable = (Data[4] < 2) ? Data[4] : false; + g_setting_radio_disabled = (Data[2] < 2) ? Data[2] : false; + g_setting_174_tx_enable = (Data[3] < 2) ? Data[3] : false; + g_setting_470_tx_enable = (Data[4] < 2) ? Data[4] : false; g_setting_350_enable = (Data[5] < 2) ? Data[5] : true; g_setting_scramble_enable = (Data[6] < 2) ? Data[6] : true; g_setting_tx_enable = (Data[7] & (1u << 0)) ? true : false; diff --git a/driver/bk4819.c b/driver/bk4819.c index 40e7f93..12e3e76 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -704,10 +704,30 @@ void BK4819_SetupPowerAmplifier(const uint8_t bias, const uint32_t frequency) BK4819_WriteRegister(BK4819_REG_36, ((uint16_t)bias << 8) | ((uint16_t)enable << 7) | ((uint16_t)gain << 0)); } -void BK4819_SetFrequency(uint32_t Frequency) +void BK4819_set_rf_frequency(const uint32_t frequency, const bool trigger_update) { - BK4819_WriteRegister(BK4819_REG_38, (Frequency >> 0) & 0xFFFF); - BK4819_WriteRegister(BK4819_REG_39, (Frequency >> 16) & 0xFFFF); + BK4819_WriteRegister(BK4819_REG_38, (frequency >> 0) & 0xFFFF); + BK4819_WriteRegister(BK4819_REG_39, (frequency >> 16) & 0xFFFF); + + if (trigger_update) + { + // <15> 0 VCO Calibration 1 = enable 0 = disable + // <14> ??? + // <13:10> 0 RX Link 15 = enable 0 = disable + // <9> 0 AF DAC 1 = enable 0 = disable + // <8> 0 DISC Mode 1 = enable 0 = disable + // <7:4> 0 PLL/VCO 15 = enable 0 = disable + // <3> 0 PA Gain 1 = enable 0 = disable + // <2> 0 MIC ADC 1 = enable 0 = disable + // <1> 0 TX DSP 1 = enable 0 = disable + // <0> 0 RX DSP 1 = enable 0 = disable + // + // trigger a PLL/VCO update + // + const uint16_t reg = BK4819_ReadRegister(BK4819_REG_30); + BK4819_WriteRegister(BK4819_REG_30, reg & ~(1u << 15) & (15u << 4)); + BK4819_WriteRegister(BK4819_REG_30, reg); + } } void BK4819_SetupSquelch( @@ -1583,7 +1603,7 @@ void BK4819_EnableFrequencyScan(void) void BK4819_SetScanFrequency(uint32_t Frequency) { - BK4819_SetFrequency(Frequency); + BK4819_set_rf_frequency(Frequency, false); // REG_51 // diff --git a/driver/bk4819.h b/driver/bk4819.h index b894f46..acd2652 100644 --- a/driver/bk4819.h +++ b/driver/bk4819.h @@ -77,7 +77,7 @@ void BK4819_SetTailDetection(const uint32_t freq_10Hz); void BK4819_EnableVox(uint16_t Vox1Threshold, uint16_t Vox0Threshold); void BK4819_SetFilterBandwidth(const BK4819_filter_bandwidth_t Bandwidth, const bool weak_no_different); void BK4819_SetupPowerAmplifier(const uint8_t bias, const uint32_t frequency); -void BK4819_SetFrequency(uint32_t Frequency); +void BK4819_set_rf_frequency(const uint32_t frequency, const bool trigger_update); void BK4819_SetupSquelch( uint8_t SquelchOpenRSSIThresh, uint8_t SquelchCloseRSSIThresh, diff --git a/firmware.bin b/firmware.bin index a27eafb..d62e32a 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 4d9b0ae..ac0b7ef 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/frequencies.c b/frequencies.c index 0939484..7331ca0 100644 --- a/frequencies.c +++ b/frequencies.c @@ -152,7 +152,7 @@ int TX_freq_check(const uint32_t Frequency) if (Frequency >= 13600000 && Frequency < 17400000) return 0; if (Frequency >= 17400000 && Frequency < 35000000) - if (g_setting_200_tx_enable) + if (g_setting_174_tx_enable) return 0; if (Frequency >= 35000000 && Frequency < 40000000) if (g_setting_350_tx_enable && g_setting_350_enable) @@ -160,7 +160,7 @@ int TX_freq_check(const uint32_t Frequency) if (Frequency >= 40000000 && Frequency < 47000000) return 0; if (Frequency >= 47000000 && Frequency <= 60000000) - if (g_setting_500_tx_enable) + if (g_setting_470_tx_enable) return 0; break; diff --git a/functions.c b/functions.c index 1327c07..001337c 100644 --- a/functions.c +++ b/functions.c @@ -43,18 +43,14 @@ function_type_t g_current_function; void FUNCTION_Init(void) { - #ifdef ENABLE_NOAA - if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save)) - #endif + if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save)) { g_current_code_type = g_selected_code_type; if (g_css_scan_mode == CSS_SCAN_MODE_OFF) g_current_code_type = g_rx_vfo->am_mode ? CODE_TYPE_NONE : g_rx_vfo->p_rx->code_type; } - #ifdef ENABLE_NOAA - else - g_current_code_type = CODE_TYPE_CONTINUOUS_TONE; - #endif + else + g_current_code_type = CODE_TYPE_CONTINUOUS_TONE; DTMF_clear_RX(); diff --git a/main.c b/main.c index 81062f7..da60626 100644 --- a/main.c +++ b/main.c @@ -95,9 +95,9 @@ void Main(void) RADIO_ConfigureChannel(0, VFO_CONFIGURE_RELOAD); RADIO_ConfigureChannel(1, VFO_CONFIGURE_RELOAD); - RADIO_SelectVfos(); + RADIO_select_vfos(); - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); for (i = 0; i < ARRAY_SIZE(g_battery_voltages); i++) BOARD_ADC_GetBatteryInfo(&g_battery_voltages[i], &g_usb_current); @@ -216,17 +216,17 @@ void Main(void) while (1) { - APP_Update(); + APP_process(); if (g_next_time_slice) { - APP_TimeSlice10ms(); + APP_time_slice_10ms(); g_next_time_slice = false; } if (g_next_time_slice_500ms) { - APP_TimeSlice500ms(); + APP_time_slice_500ms(); g_next_time_slice_500ms = false; } } diff --git a/misc.c b/misc.c index 2c139ae..3fc55d3 100644 --- a/misc.c +++ b/misc.c @@ -46,7 +46,7 @@ const uint8_t key_lock_timeout_500ms = 30000 / 500; // 30 sec 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 = 80 / 10; // 80ms +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 @@ -89,9 +89,9 @@ const uint32_t g_default_aes_key[4] = {0x4AA5CC60, 0x0312C const uint8_t g_mic_gain_dB_2[5] = {3, 8, 16, 24, 31}; bool g_setting_350_tx_enable; -bool g_setting_killed; -bool g_setting_200_tx_enable; -bool g_setting_500_tx_enable; +bool g_setting_radio_disabled; +bool g_setting_174_tx_enable; +bool g_setting_470_tx_enable; bool g_setting_350_enable; bool g_setting_tx_enable; uint8_t g_setting_freq_lock; @@ -140,7 +140,6 @@ volatile bool g_schedule_dual_watch = true; volatile uint16_t g_dual_watch_count_down_10ms; volatile bool g_dual_watch_count_down_expired = true; -bool g_dual_watch_active; volatile uint8_t g_serial_config_count_down_500ms; @@ -213,6 +212,7 @@ volatile uint16_t g_flash_light_blink_counter; bool g_flag_end_tx; uint16_t g_low_batteryCountdown; + reception_mode_t g_rx_reception_mode; uint8_t g_scan_next_channel; diff --git a/misc.h b/misc.h index 6908660..5084218 100644 --- a/misc.h +++ b/misc.h @@ -170,9 +170,9 @@ extern const uint16_t scan_pause_delay_in_7_10ms; extern const uint8_t g_mic_gain_dB_2[5]; extern bool g_setting_350_tx_enable; -extern bool g_setting_killed; -extern bool g_setting_200_tx_enable; -extern bool g_setting_500_tx_enable; +extern bool g_setting_radio_disabled; +extern bool g_setting_174_tx_enable; +extern bool g_setting_470_tx_enable; extern bool g_setting_350_enable; extern bool g_setting_tx_enable; extern uint8_t g_setting_freq_lock; @@ -223,7 +223,6 @@ extern volatile bool g_schedule_dual_watch; extern volatile uint16_t g_dual_watch_count_down_10ms; extern volatile bool g_dual_watch_count_down_expired; -extern bool g_dual_watch_active; extern volatile uint8_t g_serial_config_count_down_500ms; diff --git a/radio.c b/radio.c index e82c53b..c77fac1 100644 --- a/radio.c +++ b/radio.c @@ -165,12 +165,9 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure if (Channel >= NOAA_CHANNEL_FIRST) { RADIO_InitInfo(pRadio, g_eeprom.screen_channel[VFO], NOAA_FREQUENCY_TABLE[Channel - NOAA_CHANNEL_FIRST]); - if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) return; - g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF; - g_update_status = true; return; } @@ -245,7 +242,7 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure uint8_t Tmp; uint8_t Data[8]; // t_channel channel; - + // EEPROM_ReadBuffer(Base, channel, sizeof(channel)); // *************** @@ -517,7 +514,7 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *pInfo) // my calibration data // - // 1ED0 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 50 MHz + // 1ED0 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 50 MHz // 1EE0 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 108 MHz // 1EF0 5F 5F 5F 69 69 69 91 91 8F FF FF FF FF FF FF FF .. 136 MHz // 1F00 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 174 MHz @@ -545,7 +542,7 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *pInfo) TX_power[2] /= 3; } #endif - + pInfo->txp_calculated_setting = FREQUENCY_CalculateOutputPower( TX_power[0], TX_power[1], @@ -588,7 +585,7 @@ static void RADIO_SelectCurrentVfo(void) g_current_vfo = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_rx_vfo : &g_eeprom.vfo_info[g_eeprom.tx_vfo]; } -void RADIO_SelectVfos(void) +void RADIO_select_vfos(void) { g_eeprom.tx_vfo = get_TX_VFO(); g_eeprom.rx_vfo = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_eeprom.tx_vfo : (g_eeprom.tx_vfo + 1) & 1u; @@ -599,11 +596,11 @@ void RADIO_SelectVfos(void) RADIO_SelectCurrentVfo(); } -void RADIO_SetupRegisters(bool bSwitchToFunction0) +void RADIO_setup_registers(bool switch_to_function_0) { BK4819_filter_bandwidth_t Bandwidth = g_rx_vfo->channel_bandwidth; - uint16_t InterruptMask; - uint32_t Frequency; + uint16_t interrupt_mask; + uint32_t Frequency; GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); @@ -636,7 +633,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0) BK4819_set_GPIO_pin(BK4819_GPIO5_PIN1, false); // ??? while (1) - { // wait for the interrupt to clear ??? + { // wait for the interrupt to clear ? const uint16_t status_bits = BK4819_ReadRegister(BK4819_REG_0C); if ((status_bits & (1u << 0)) == 0) break; @@ -644,20 +641,18 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0) SYSTEM_DelayMs(1); } - BK4819_WriteRegister(BK4819_REG_3F, 0); + BK4819_WriteRegister(BK4819_REG_3F, 0); // disable interrupts // mic gain 0.5dB/step 0 to 31 BK4819_WriteRegister(BK4819_REG_7D, 0xE940 | (g_eeprom.mic_sensitivity_tuning & 0x1f)); #ifdef ENABLE_NOAA - if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save) || !g_is_noaa_mode) - Frequency = g_rx_vfo->p_rx->frequency; - else + if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_is_noaa_mode) Frequency = NOAA_FREQUENCY_TABLE[g_noaa_channel]; - #else - Frequency = g_rx_vfo->p_rx->frequency; + else #endif - BK4819_SetFrequency(Frequency); + Frequency = g_rx_vfo->p_rx->frequency; + BK4819_set_rf_frequency(Frequency, false); BK4819_SetupSquelch( g_rx_vfo->squelch_open_rssi_thresh, g_rx_vfo->squelch_close_rssi_thresh, @@ -672,20 +667,19 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0) // AF RX Gain and DAC BK4819_WriteRegister(BK4819_REG_48, 0xB3A8); // 1011 00 111010 1000 - InterruptMask = BK4819_REG_3F_SQUELCH_FOUND | BK4819_REG_3F_SQUELCH_LOST; + interrupt_mask = BK4819_REG_3F_SQUELCH_FOUND | BK4819_REG_3F_SQUELCH_LOST; - #ifdef ENABLE_NOAA - if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save)) - #endif + if (IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save)) { if (g_rx_vfo->am_mode == 0) { // FM 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) { 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) @@ -700,7 +694,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0) // BK4819_SetTailDetection(670); // 67Hz //#endif - InterruptMask = BK4819_REG_3F_CxCSS_TAIL | BK4819_REG_3F_SQUELCH_FOUND | BK4819_REG_3F_SQUELCH_LOST; + interrupt_mask = BK4819_REG_3F_CxCSS_TAIL | BK4819_REG_3F_SQUELCH_FOUND | BK4819_REG_3F_SQUELCH_LOST; break; case CODE_TYPE_CONTINUOUS_TONE: @@ -712,24 +706,24 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0) // BK4819_SetTailDetection(CTCSS_OPTIONS[Code]); //#endif - InterruptMask = 0 - | BK4819_REG_3F_CxCSS_TAIL - | BK4819_REG_3F_CTCSS_FOUND - | BK4819_REG_3F_CTCSS_LOST - | BK4819_REG_3F_SQUELCH_FOUND - | BK4819_REG_3F_SQUELCH_LOST; + interrupt_mask = + BK4819_REG_3F_CxCSS_TAIL | + BK4819_REG_3F_CTCSS_FOUND | + BK4819_REG_3F_CTCSS_LOST | + BK4819_REG_3F_SQUELCH_FOUND | + BK4819_REG_3F_SQUELCH_LOST; break; case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: BK4819_SetCDCSSCodeWord(DCS_GetGolayCodeWord(code_type, Code)); - InterruptMask = 0 - | BK4819_REG_3F_CxCSS_TAIL - | BK4819_REG_3F_CDCSS_FOUND - | BK4819_REG_3F_CDCSS_LOST - | BK4819_REG_3F_SQUELCH_FOUND - | BK4819_REG_3F_SQUELCH_LOST; + interrupt_mask = + BK4819_REG_3F_CxCSS_TAIL | + BK4819_REG_3F_CDCSS_FOUND | + BK4819_REG_3F_CDCSS_LOST | + BK4819_REG_3F_SQUELCH_FOUND | + BK4819_REG_3F_SQUELCH_LOST; break; } @@ -743,55 +737,50 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0) else { BK4819_SetCTCSSFrequency(2625); - InterruptMask = 0 - | BK4819_REG_3F_CTCSS_FOUND - | BK4819_REG_3F_CTCSS_LOST - | BK4819_REG_3F_SQUELCH_FOUND - | BK4819_REG_3F_SQUELCH_LOST; + interrupt_mask = + BK4819_REG_3F_CTCSS_FOUND | + BK4819_REG_3F_CTCSS_LOST | + BK4819_REG_3F_SQUELCH_FOUND | + BK4819_REG_3F_SQUELCH_LOST; } #endif #ifdef ENABLE_VOX - #ifdef ENABLE_NOAA + if ( #ifdef ENABLE_FMRADIO - if (g_eeprom.vox_switch && !g_fm_radio_mode && IS_NOT_NOAA_CHANNEL(g_current_vfo->channel_save) && g_current_vfo->am_mode == 0) - #else - if (g_eeprom.vox_switch && IS_NOT_NOAA_CHANNEL(g_current_vfo->channel_save) && g_current_vfo->am_mode == 0) + !g_fm_radio_mode && #endif - #else - #ifdef ENABLE_FMRADIO - if (g_eeprom.vox_switch && !g_fm_radio_mode && g_current_vfo->am_mode == 0) - #else - if (g_eeprom.vox_switch && g_current_vfo->am_mode == 0) - #endif - #endif + g_eeprom.vox_switch && + !g_fm_radio_mode && + IS_NOT_NOAA_CHANNEL(g_current_vfo->channel_save) && + g_current_vfo->am_mode == 0) { BK4819_EnableVox(g_eeprom.vox1_threshold, g_eeprom.vox0_threshold); - InterruptMask |= BK4819_REG_3F_VOX_FOUND | BK4819_REG_3F_VOX_LOST; + interrupt_mask |= BK4819_REG_3F_VOX_FOUND | BK4819_REG_3F_VOX_LOST; } else #endif - BK4819_DisableVox(); + BK4819_DisableVox(); // RX expander BK4819_SetCompander((g_rx_vfo->am_mode == 0 && g_rx_vfo->compander >= 2) ? g_rx_vfo->compander : 0); #if 0 - if (!g_rx_vfo->dtmf_decoding_enable && !g_setting_killed) + if (!g_rx_vfo->dtmf_decoding_enable && !g_setting_radio_disabled) { BK4819_DisableDTMF(); } else { BK4819_EnableDTMF(); - InterruptMask |= BK4819_REG_3F_DTMF_5TONE_FOUND; + interrupt_mask |= BK4819_REG_3F_DTMF_5TONE_FOUND; } #else if (g_current_function != FUNCTION_TRANSMIT) { BK4819_DisableDTMF(); BK4819_EnableDTMF(); - InterruptMask |= BK4819_REG_3F_DTMF_5TONE_FOUND; + interrupt_mask |= BK4819_REG_3F_DTMF_5TONE_FOUND; } else { @@ -800,11 +789,11 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0) #endif // enable/disable BK4819 selected interrupts - BK4819_WriteRegister(BK4819_REG_3F, InterruptMask); + BK4819_WriteRegister(BK4819_REG_3F, interrupt_mask); FUNCTION_Init(); - if (bSwitchToFunction0) + if (switch_to_function_0) FUNCTION_Select(FUNCTION_FOREGROUND); } @@ -883,7 +872,7 @@ void RADIO_enableTX(const bool fsk_tx) #pragma GCC diagnostic pop - BK4819_SetFrequency(g_current_vfo->p_tx->frequency); + BK4819_set_rf_frequency(g_current_vfo->p_tx->frequency, false); BK4819_SetCompander((!fsk_tx && g_rx_vfo->am_mode == 0 && (g_rx_vfo->compander == 1 || g_rx_vfo->compander >= 3)) ? g_rx_vfo->compander : 0); BK4819_PrepareTransmit(); BK4819_PickRXFilterPathBasedOnFrequency(g_current_vfo->p_tx->frequency); @@ -906,11 +895,11 @@ void RADIO_enableTX(const bool fsk_tx) case CODE_TYPE_NONE: BK4819_ExitSubAu(); break; - + case CODE_TYPE_CONTINUOUS_TONE: BK4819_SetCTCSSFrequency(CTCSS_OPTIONS[g_current_vfo->p_tx->code]); break; - + case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: BK4819_SetCDCSSCodeWord(DCS_GetGolayCodeWord(g_current_vfo->p_tx->code_type, g_current_vfo->p_tx->code)); @@ -959,29 +948,27 @@ void RADIO_PrepareTX(void) { // dual-RX is enabled g_dual_watch_count_down_10ms = dual_watch_count_after_tx_10ms; - g_schedule_dual_watch = false; + g_schedule_dual_watch = false; #if 0 if (g_rx_vfo_is_active) { // use the TX vfo - g_eeprom.rx_vfo = g_eeprom.tx_vfo; - g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.tx_vfo]; + g_eeprom.rx_vfo = g_eeprom.tx_vfo; + g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.tx_vfo]; g_rx_vfo_is_active = false; } g_current_vfo = g_rx_vfo; #else if (!g_rx_vfo_is_active) { // use the current RX vfo - g_eeprom.rx_vfo = g_eeprom.tx_vfo; - g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.tx_vfo]; + g_eeprom.rx_vfo = g_eeprom.tx_vfo; + g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.tx_vfo]; g_rx_vfo_is_active = true; } g_current_vfo = g_rx_vfo; #endif - - // let the user see that DW is not active '><' symbol - g_dual_watch_active = false; - g_update_status = true; + + g_update_status = true; } RADIO_SelectCurrentVfo(); @@ -1033,8 +1020,8 @@ void RADIO_PrepareTX(void) { if (g_dtmf_call_mode == DTMF_CALL_MODE_DTMF) { - g_dtmf_is_tx = true; - g_dtmf_call_state = DTMF_CALL_STATE_NONE; + g_dtmf_is_tx = true; + g_dtmf_call_state = DTMF_CALL_STATE_NONE; g_dtmf_tx_stop_count_down_500ms = dtmf_txstop_countdown_500ms; } else @@ -1046,7 +1033,7 @@ void RADIO_PrepareTX(void) FUNCTION_Select(FUNCTION_TRANSMIT); - g_tx_timer_count_down_500ms = 0; // no timeout + g_tx_timer_count_down_500ms = 0; // no timeout #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) if (g_alarm_state == ALARM_STATE_OFF) @@ -1060,11 +1047,11 @@ void RADIO_PrepareTX(void) else g_tx_timer_count_down_500ms = 120 * 15; // 15 minutes } - g_tx_timeout_reached = false; - g_flag_end_tx = false; - g_rtte_count_down = 0; - g_dtmf_reply_state = DTMF_REPLY_NONE; + g_tx_timeout_reached = false; + g_flag_end_tx = false; + g_rtte_count_down = 0; + g_dtmf_reply_state = DTMF_REPLY_NONE; } void RADIO_EnableCxCSS(void) @@ -1095,7 +1082,7 @@ void RADIO_PrepareCssTX(void) SYSTEM_DelayMs(200); RADIO_EnableCxCSS(); - RADIO_SetupRegisters(true); + RADIO_setup_registers(true); } void RADIO_SendEndOfTransmission(void) diff --git a/radio.h b/radio.h index a66dd42..c40b4a8 100644 --- a/radio.h +++ b/radio.h @@ -132,8 +132,8 @@ void RADIO_InitInfo(vfo_info_t *pInfo, const uint8_t ChannelSave, const uint void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure); void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *pInfo); void RADIO_ApplyOffset(vfo_info_t *pInfo); -void RADIO_SelectVfos(void); -void RADIO_SetupRegisters(bool bSwitchToFunction0); +void RADIO_select_vfos(void); +void RADIO_setup_registers(bool switch_to_function_0); #ifdef ENABLE_NOAA void RADIO_ConfigureNOAA(void); #endif diff --git a/settings.c b/settings.c index ef4a6bc..5429684 100644 --- a/settings.c +++ b/settings.c @@ -310,9 +310,9 @@ void SETTINGS_SaveSettings(void) memset(State, 0xFF, sizeof(State)); State[0] = g_setting_freq_lock; State[1] = g_setting_350_tx_enable; - State[2] = g_setting_killed; - State[3] = g_setting_200_tx_enable; - State[4] = g_setting_500_tx_enable; + State[2] = g_setting_radio_disabled; + State[3] = g_setting_174_tx_enable; + State[4] = g_setting_470_tx_enable; State[5] = g_setting_350_enable; State[6] = g_setting_scramble_enable; if (!g_setting_tx_enable) State[7] &= ~(1u << 0); @@ -335,10 +335,8 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const vfo_info_t *pVFO, uint16_t OffsetVFO = OffsetMR; uint8_t State[8]; - #ifdef ENABLE_NOAA - if (IS_NOAA_CHANNEL(Channel)) - return; - #endif + if (IS_NOAA_CHANNEL(Channel)) + return; if (IS_FREQ_CHANNEL(Channel)) { // it's a VFO @@ -374,11 +372,11 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const vfo_info_t *pVFO, SETTINGS_UpdateChannel(Channel, pVFO, true); if (Channel > USER_CHANNEL_LAST) - return; // it's not a user channel + return; // it's not a user memory channel #ifndef ENABLE_KEEP_MEM_NAME // clear/reset the channel name - memset(&State, 0x00, sizeof(State)); + memset(&State, 0, sizeof(State)); EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); #else @@ -386,7 +384,7 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const vfo_info_t *pVFO, { // save the channel name memmove(State, pVFO->name + 0, 8); EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); - memset(State, 0x00, sizeof(State)); + memset(State, 0, sizeof(State)); memmove(State, pVFO->name + 8, 2); EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); } @@ -399,10 +397,8 @@ void SETTINGS_UpdateChannel(uint8_t Channel, const vfo_info_t *pVFO, bool keep) uint8_t Attributes = 0xFF; // default attributes uint16_t Offset = 0x0D60 + (Channel & ~7u); - #ifdef ENABLE_NOAA - if (IS_NOAA_CHANNEL(Channel)) - return; - #endif + if (IS_NOAA_CHANNEL(Channel)) + return; Attributes &= (uint8_t)(~USER_CH_COMPAND); // default to '0' = compander disabled @@ -412,7 +408,7 @@ void SETTINGS_UpdateChannel(uint8_t Channel, const vfo_info_t *pVFO, bool keep) { Attributes = (pVFO->scanlist_1_participation << 7) | (pVFO->scanlist_2_participation << 6) | (pVFO->compander << 4) | (pVFO->band << 0); if (State[Channel & 7u] == Attributes) - return; // no change in the attributes + return; // no change in the attributes .. don't place wear on the eeprom } State[Channel & 7u] = Attributes; @@ -423,13 +419,12 @@ void SETTINGS_UpdateChannel(uint8_t Channel, const vfo_info_t *pVFO, bool keep) // #ifndef ENABLE_KEEP_MEM_NAME if (Channel <= USER_CHANNEL_LAST) - { // it's a memory channel + { // user memory channel const uint16_t OffsetMR = Channel * 16; if (!keep) { // clear/reset the channel name - //memset(&State, 0xFF, sizeof(State)); - memset(&State, 0x00, sizeof(State)); // follow the QS way + memset(&State, 0, sizeof(State)); EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); } @@ -437,8 +432,7 @@ void SETTINGS_UpdateChannel(uint8_t Channel, const vfo_info_t *pVFO, bool keep) // { // update the channel name // memmove(State, pVFO->name + 0, 8); // EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); -// //memset(State, 0xFF, sizeof(State)); -// memset(State, 0x00, sizeof(State)); // follow the QS way +// memset(State, 0, sizeof(State)); // memmove(State, pVFO->name + 8, 2); // EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); // } diff --git a/settings.h b/settings.h index ae79ee9..b714b37 100644 --- a/settings.h +++ b/settings.h @@ -178,39 +178,39 @@ typedef struct { // 0x1E00 struct { - uint8_t open_rssi_thresh[10]; - uint8_t unused1[6]; - uint8_t close_rssi_thresh[10]; - uint8_t unused2[6]; - uint8_t open_noise_thresh[10]; - uint8_t unused3[6]; - uint8_t close_noise_thresh[10]; - uint8_t unused4[6]; - uint8_t open_glitch_thresh[10]; - uint8_t unused5[6]; - uint8_t close_glitch_thresh[10]; - uint8_t unused6[6]; - } __attribute__((packed)) squelch_band_4567[6]; + uint8_t open_rssi_thresh[10]; // + uint8_t unused1[6]; // 0xff's + uint8_t close_rssi_thresh[10]; // + uint8_t unused2[6]; // 0xff's + uint8_t open_noise_thresh[10]; // + uint8_t unused3[6]; // 0xff's + uint8_t close_noise_thresh[10]; // + uint8_t unused4[6]; // 0xff's + uint8_t open_glitch_thresh[10]; // + uint8_t unused5[6]; // 0xff's + uint8_t close_glitch_thresh[10]; // + uint8_t unused6[6]; // 0xff's + } __attribute__((packed)) squelch_band_4567[6]; // // 0x1E60 struct { - uint8_t open_rssi_thresh[10]; - uint8_t unused1[6]; - uint8_t close_rssi_thresh[10]; - uint8_t unused2[6]; - uint8_t open_noise_thresh[10]; - uint8_t unused3[6]; - uint8_t close_noise_thresh[10]; - uint8_t unused4[6]; - uint8_t open_glitch_thresh[10]; - uint8_t unused5[6]; - uint8_t close_glitch_thresh[10]; - uint8_t unused6[6]; - } __attribute__((packed)) squelch_band_123[6]; + uint8_t open_rssi_thresh[10]; // + uint8_t unused1[6]; // 0xff's + uint8_t close_rssi_thresh[10]; // + uint8_t unused2[6]; // 0xff's + uint8_t open_noise_thresh[10]; // + uint8_t unused3[6]; // 0xff's + uint8_t close_noise_thresh[10]; // + uint8_t unused4[6]; // 0xff's + uint8_t open_glitch_thresh[10]; // + uint8_t unused5[6]; // 0xff's + uint8_t close_glitch_thresh[10]; // + uint8_t unused6[6]; // 0xff's + } __attribute__((packed)) squelch_band_123[6]; // // 0x1EC0 - uint16_t rssi_band_4567[4]; // - uint16_t rssi_band_123[4]; // + uint16_t rssi_band_4567[4]; // RSSI bargraph thresholds .. (dBm + 160) * 2 + uint16_t rssi_band_123[4]; // RSSI bargraph thresholds .. (dBm + 160) * 2 // 0x1ED0 struct @@ -218,18 +218,18 @@ typedef struct { uint8_t low[3]; // uint8_t mid[3]; // uint8_t high[3]; // - uint8_t unused[7]; // + uint8_t unused[7]; // 0xff's } tx_band_power[7]; // // 0x1F40 uint16_t battery[6]; // - uint8_t unused1[4]; // + uint8_t unused1[4]; // 0xff's // 0x1F50 struct { uint16_t threshold[10]; // - uint8_t unused[4]; // + uint8_t unused[4]; // 0xff's } __attribute__((packed)) vox[2]; // // 0x1F80 @@ -241,7 +241,7 @@ typedef struct { uint8_t volume_gain; // uint8_t dac_gain; // - uint8_t unused5[8 * 10]; // + uint8_t unused5[8 * 10]; // 0xff's } __attribute__((packed)) t_calibration; @@ -267,20 +267,20 @@ typedef struct { // 0x0D60 struct { // these channel attribute settings could have been in the t_channel structure ! uint8_t band:4; // why do QS have these 4 bits ? .. band can/is computed from the frequency - uint8_t unused:2; // + uint8_t unused:2; // 0's ? // uint8_t compander:2; // smoved this to the t_channel structure uint8_t scanlist2:1; // set if is in scan list 2 uint8_t scanlist1:1; // set if is in scan list 1 } __attribute__((packed)) channel_attr[200]; // - uint8_t unused1[8]; // + uint8_t unused1[8]; // 0xff's // 0x0E30 - uint8_t unused2[16]; // + uint8_t unused2[16]; // 0xff's // 0x0E40 uint16_t fm_channel[20]; // - uint8_t unused3[8]; // + uint8_t unused3[8]; // 0xff's // 0x0E70 uint8_t call1; // @@ -291,7 +291,11 @@ typedef struct { uint8_t vox_switch; // uint8_t vox_level; // uint8_t mic_sensitivity; // - uint8_t lcd_contrast; // 1of11 + #if 1 + uint8_t lcd_contrast; // 1of11 + #else + uint8_t unused4; // 0xff's + #endif uint8_t channel_display_mode; // uint8_t cross_vfo; // uint8_t battery_save; // @@ -312,7 +316,7 @@ typedef struct { uint8_t fm_selected_frequency; // uint8_t fm_selected_channel; // uint8_t fm_is_channel_mode; // - uint8_t unused5[5]; // + uint8_t unused5[5]; // 0xff's // 0x0E90 uint8_t beep_control; // @@ -324,11 +328,11 @@ typedef struct { uint8_t auto_key_lock; // uint8_t display_mode; // uint32_t power_on_password; // - uint8_t unused6[4]; // + uint8_t unused6[4]; // 0xff's // 0x0EA0 uint8_t voice_prompt; // - uint8_t unused7[7]; // + uint8_t unused7[7]; // 0xff's uint8_t alarm_mode; // uint8_t roger_mode; // uint8_t repeater_tail_tone_elimination; // rp_ste @@ -336,7 +340,7 @@ typedef struct { #ifdef ENABLE_AIRCOPY uint32_t air_copy_freq; // 1of11 #else - uint8_t unused8[4]; // + uint8_t unused8[4]; // 0xff's #endif // 0x0EB0 @@ -355,7 +359,7 @@ typedef struct { uint8_t dtmf_code_time; // uint8_t dtmf_code_interval; // uint8_t dtmf_permit_kill; // - uint8_t unused9[5]; // + uint8_t unused9[5]; // 0xff's // 0x0EE0 uint8_t dtmf_ani_id[8]; // @@ -372,10 +376,10 @@ typedef struct { uint8_t priority2_enable; // uint8_t priority2_channel1; // uint8_t priority2_channel2; // - uint8_t unused10; // + uint8_t unused10; // 0xff's // 0x0F20 - uint8_t unused11[8]; // + uint8_t unused11[8]; // 0xff's // 0x0F30 uint8_t aes_key[16]; // disabled = all 0xff @@ -383,14 +387,14 @@ typedef struct { // 0x0F40 uint8_t freq_lock; // uint8_t enable_tx_350; // 350MHz ~ 400MHz - uint8_t killed; // - uint8_t enable_tx_200; // - uint8_t enable_tx_500; // - uint8_t enable_350; // - uint8_t enable_scrambler; // + uint8_t radio_disabled; // 0 = not radio is not disabled + uint8_t enable_tx_200; // 174MHz ~ 350MHz + uint8_t enable_tx_470; // >= 470MHz disabled + uint8_t enable_350; // 0 = 350HMz ~ 400MHz RX/TX disabled + uint8_t enable_scrambler; // 0 = scrambler disabled, 1 = enabled #if 0 // QS - uint8_t unused12[9]; // + uint8_t unused12[9]; // 0xff's #else // 1of11 uint8_t tx_enable:1; // 0 = completely disable TX, 1 = allow TX @@ -400,14 +404,17 @@ typedef struct { uint8_t am_fix:1; // 1 = RX AM fix uint8_t backlight_on_tx_rx:2; // 0 = no backlight when TX/RX, 1 = when TX, 2 = when RX, 3 = both RX/TX - uint8_t unused12[8]; // + uint8_t unused12[8]; // 0xff's #endif // 0x0F50 - char channel_name[200][16]; // each channels name text (max 10 chars used per channel) - + struct { + char name[10]; + uint8_t unused[6]; // 0xff's + } __attribute__((packed)) channel_name[200]; + // 0x1BD0 - uint8_t unused13[16 * 3]; // free to use + uint8_t unused13[16 * 3]; // 0xff's .. free to use // 0x1C00 struct { diff --git a/ui/main.c b/ui/main.c index 13f44c7..962d1d0 100644 --- a/ui/main.c +++ b/ui/main.c @@ -283,7 +283,7 @@ void UI_drawBars(uint8_t *p, const unsigned int level) } #endif -void UI_UpdateRSSI(const int16_t rssi, const int vfo) +void UI_update_rssi(const int16_t rssi, const int vfo) { #ifdef ENABLE_RSSI_BAR @@ -809,7 +809,7 @@ void UI_DisplayMain(void) } // show the DTMF decoding symbol - if (g_eeprom.vfo_info[vfo_num].dtmf_decoding_enable || g_setting_killed) + if (g_eeprom.vfo_info[vfo_num].dtmf_decoding_enable || g_setting_radio_disabled) UI_PrintStringSmall("DTMF", LCD_WIDTH + 78, 0, line + 1); // show the audio scramble symbol diff --git a/ui/main.h b/ui/main.h index a32c855..c871fae 100644 --- a/ui/main.h +++ b/ui/main.h @@ -37,7 +37,7 @@ extern center_line_t center_line; #ifdef ENABLE_AUDIO_BAR bool UI_DisplayAudioBar(const bool now); #endif -void UI_UpdateRSSI(const int16_t rssi, const int vfo); +void UI_update_rssi(const int16_t rssi, const int vfo); void UI_DisplayMain(void); #endif diff --git a/ui/menu.c b/ui/menu.c index 05794cc..981f66e 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -130,9 +130,9 @@ const t_menu_item g_menu_list[] = // enabled by pressing both the PTT and upper side button at power-on {"F LOCK", VOICE_ID_INVALID, MENU_FREQ_LOCK }, // country/area specific - {"Tx 200", VOICE_ID_INVALID, MENU_200TX }, // was "200TX" + {"Tx 174", VOICE_ID_INVALID, MENU_174TX }, // was "200TX" {"Tx 350", VOICE_ID_INVALID, MENU_350TX }, // was "350TX" - {"Tx 500", VOICE_ID_INVALID, MENU_500TX }, // was "500TX" + {"Tx 470", VOICE_ID_INVALID, MENU_470TX }, // was "500TX" {"350 EN", VOICE_ID_INVALID, MENU_350EN }, // was "350EN" {"SCR EN", VOICE_ID_INVALID, MENU_SCREN }, // was "SCREN" {"Tx EN", VOICE_ID_INVALID, MENU_TX_EN }, // enable TX @@ -752,10 +752,23 @@ void UI_DisplayMenu(void) #endif case MENU_350TX: - case MENU_200TX: - case MENU_500TX: + strcpy(String, "350 ~ 400\n"); + strcat(String, g_sub_menu_DIS_EN[g_sub_menu_selection]); + break; + + case MENU_174TX: + strcpy(String, "174 ~ 350\n"); + strcat(String, g_sub_menu_DIS_EN[g_sub_menu_selection]); + break; + + case MENU_470TX: + strcpy(String, "470 ~ 600\n"); + strcat(String, g_sub_menu_DIS_EN[g_sub_menu_selection]); + break; + case MENU_350EN: - strcpy(String, g_sub_menu_DIS_EN[g_sub_menu_selection]); + strcpy(String, "350 ~ 400\n"); + strcat(String, g_sub_menu_DIS_EN[g_sub_menu_selection]); break; case MENU_SCREN: diff --git a/ui/menu.h b/ui/menu.h index 1b5bd8c..7f9dd99 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -124,9 +124,9 @@ enum // items after here are normally hidden MENU_FREQ_LOCK, - MENU_200TX, + MENU_174TX, MENU_350TX, - MENU_500TX, + MENU_470TX, MENU_350EN, MENU_SCREN, diff --git a/ui/status.c b/ui/status.c index 0b1cecf..f595333 100644 --- a/ui/status.c +++ b/ui/status.c @@ -79,7 +79,7 @@ void UI_DisplayStatus(const bool test_display) // hmmm, what to put in it's place #endif - if (g_setting_killed) + if (g_setting_radio_disabled) { memset(line + x, 0xFF, 10); x1 = x + 10; @@ -131,10 +131,17 @@ void UI_DisplayStatus(const bool test_display) // DUAL-WATCH indicator if (g_eeprom.dual_watch != DUAL_WATCH_OFF || test_display) { - if (g_dual_watch_active || test_display) - memmove(line + x, BITMAP_TDR1, sizeof(BITMAP_TDR1)); + if (g_scan_state_dir == SCAN_STATE_DIR_OFF || + g_squelch_lost || + g_current_function == FUNCTION_INCOMING || + g_current_function == FUNCTION_MONITOR || + g_screen_to_display == DISPLAY_SEARCH || + test_display) + { + memmove(line + x, BITMAP_TDR1, sizeof(BITMAP_TDR1)); // dual-watch is paused + } else - memmove(line + x, BITMAP_TDR2, sizeof(BITMAP_TDR2)); + memmove(line + x, BITMAP_TDR2, sizeof(BITMAP_TDR2)); // dual-watch is running } x += sizeof(BITMAP_TDR1);