diff --git a/Makefile b/Makefile index dc5c539..288c659 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ ENABLE_OVERLAY := 0 ENABLE_LTO := 1 # UART Programming 2.9 kB ENABLE_UART := 1 -ENABLE_UART_DEBUG := 1 +ENABLE_UART_DEBUG := 0 # AirCopy 2.5 kB ENABLE_AIRCOPY := 0 ENABLE_AIRCOPY_REMEMBER_FREQ := 1 @@ -29,7 +29,7 @@ ENABLE_NOAA := 0 ENABLE_VOICE := 0 ENABLE_MUTE_RADIO_FOR_VOICE := 0 # Tx on Voice 1.0 kB -ENABLE_VOX := 0 +ENABLE_VOX := 1 ENABLE_REDUCE_LOW_MID_TX_POWER := 1 # Tx Alarm 600 B ENABLE_ALARM := 0 @@ -38,14 +38,14 @@ ENABLE_TX1750 := 0 ENABLE_MDC1200 := 0 ENABLE_MDC1200_SHOW_OP_ARG := 1 ENABLE_PWRON_PASSWORD := 0 -ENABLE_RESET_AES_KEY := 1 +ENABLE_RESET_AES_KEY := 0 ENABLE_BIG_FREQ := 0 # smaa bolf 580 B ENABLE_SMALL_BOLD := 1 # smallest font 2 kB ENABLE_SMALLEST_FONT := 0 # trim trailing 44 B -ENABLE_TRIM_TRAILING_ZEROS := 1 +ENABLE_TRIM_TRAILING_ZEROS := 0 ENABLE_KEEP_MEM_NAME := 1 ENABLE_WIDE_RX := 1 ENABLE_TX_WHEN_AM := 0 @@ -56,11 +56,11 @@ ENABLE_CTCSS_TAIL_PHASE_SHIFT := 1 ENABLE_CONTRAST := 0 ENABLE_BOOT_BEEPS := 0 ENABLE_DTMF_CALL_FLASH_LIGHT := 1 -ENABLE_FLASH_LIGHT_SOS_TONE := 1 +ENABLE_FLASH_LIGHT_SOS_TONE := 0 ENABLE_SHOW_CHARGE_LEVEL := 0 ENABLE_REVERSE_BAT_SYMBOL := 1 -ENABLE_FREQ_SEARCH_TIMEOUT := 1 -ENABLE_CODE_SEARCH_TIMEOUT := 1 +ENABLE_FREQ_SEARCH_TIMEOUT := 0 +ENABLE_CODE_SEARCH_TIMEOUT := 0 # Kill and Revive 400 B ENABLE_KILL_REVIVE := 0 # AM Fix 800 B @@ -76,9 +76,9 @@ ENABLE_RX_SIGNAL_BAR := 1 # Tx Timeout Bar 200 B ENABLE_TX_TIMEOUT_BAR := 0 # Tx Audio Bar 300 B -ENABLE_TX_AUDIO_BAR := 1 +ENABLE_TX_AUDIO_BAR := 0 # Side Button Menu 300 B -ENABLE_SIDE_BUTT_MENU := 1 +ENABLE_SIDE_BUTT_MENU := 0 # Key Lock 400 B ENABLE_KEYLOCK := 0 #ENABLE_PANADAPTER := 0 @@ -224,7 +224,6 @@ OBJS += ui/menu.o OBJS += ui/search.o OBJS += ui/status.o OBJS += ui/ui.o -OBJS += ui/welcome.o OBJS += version.o OBJS += main.o diff --git a/am_fix.c b/am_fix.c index 706ecb7..3969bda 100644 --- a/am_fix.c +++ b/am_fix.c @@ -220,7 +220,7 @@ #ifdef ENABLE_AM_FIX_TEST1 // user manually sets the table index .. used to calibrate the desired dB gain table - unsigned int gain_table_index[2] = {1 + g_setting_am_fix_test1, 1 + g_setting_am_fix_test1}; + unsigned int gain_table_index[2] = {1 + g_eeprom.config.setting.am_fix_test1, 1 + g_eeprom.config.setting.am_fix_test1}; #else unsigned int gain_table_index[2] = {original_index, original_index}; #endif @@ -248,7 +248,7 @@ for (vfo = 0; vfo < 2; vfo++) { #ifdef ENABLE_AM_FIX_TEST1 - gain_table_index[vfo] = 1 + g_setting_am_fix_test1; + gain_table_index[vfo] = 1 + g_eeprom.config.setting.am_fix_test1; #else gain_table_index[vfo] = original_index; // re-start with original QS setting #endif @@ -271,7 +271,7 @@ rssi_gain_diff[vfo] = 0; gain_table_index_prev[vfo] = 0; #ifdef ENABLE_AM_FIX_TEST1 -// gain_table_index[vfo] = 1 + g_setting_am_fix_test1; +// gain_table_index[vfo] = 1 + g_eeprom.config.setting.am_fix_test1; #else // gain_table_index[vfo] = original_index; // re-start with original QS setting #endif @@ -347,7 +347,7 @@ // user is manually adjusting a gain register - don't do anything automatically { - int i = 1 + (int)g_setting_am_fix_test1; + int i = 1 + (int)g_eeprom.config.setting.am_fix_test1; i = (i < 1) ? 1 : (i > ((int)ARRAY_SIZE(gain_table) - 1) ? ARRAY_SIZE(gain_table) - 1 : i; if (gain_table_index[vfo] == i) diff --git a/app/action.c b/app/action.c index 0799d57..a939e7b 100644 --- a/app/action.c +++ b/app/action.c @@ -104,8 +104,8 @@ void ACTION_Monitor(void) BK4819_StopTones(g_current_function == FUNCTION_TRANSMIT); #ifdef ENABLE_NOAA -// if (g_rx_vfo->channel_save >= NOAA_CHANNEL_FIRST && g_is_noaa_mode) - if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_is_noaa_mode) +// if (g_rx_vfo->channel_save >= NOAA_CHANNEL_FIRST && g_noaa_mode) + if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_noaa_mode) g_noaa_channel = g_rx_vfo->channel_save - NOAA_CHANNEL_FIRST; #endif @@ -121,10 +121,10 @@ void ACTION_Monitor(void) GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); if (g_scan_state_dir != SCAN_STATE_DIR_OFF) - g_scan_pause_tick_10ms = g_eeprom.scan_hold_time_500ms * 50; + g_scan_pause_tick_10ms = g_eeprom.config.setting.scan_hold_time * 50; #ifdef g_power_save_expired - if (g_eeprom.dual_watch == DUAL_WATCH_OFF && g_is_noaa_mode) + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_OFF && g_noaa_mode) { g_noaa_tick_10ms = noaa_tick_10ms; g_schedule_noaa = false; @@ -177,7 +177,7 @@ void ACTION_Scan(bool bRestart) else { // scan without auto store g_fm_auto_scan = false; - Frequency = g_eeprom.fm_frequency_playing; + Frequency = g_eeprom.config.setting.fm_radio.selected_frequency; } g_fm_channel_position = 0; @@ -218,11 +218,11 @@ void ACTION_Scan(bool bRestart) if (g_scan_next_channel <= USER_CHANNEL_LAST) { // channel mode - if (g_eeprom.scan_list_default < 2) + if (g_eeprom.config.setting.scan_list_default < 2) { // keep scanning but toggle between scan lists - //g_eeprom.scan_list_default = (g_eeprom.scan_list_default + 1) % 3; - g_eeprom.scan_list_default++; + //g_eeprom.config.setting.scan_list_default = (g_eeprom.config.setting.scan_list_default + 1) % 3; + g_eeprom.config.setting.scan_list_default++; // jump to the next channel APP_channel_next(true, g_scan_state_dir); @@ -234,7 +234,7 @@ void ACTION_Scan(bool bRestart) return; } - g_eeprom.scan_list_default = 0; // back to scan list 1 - the next time we start scanning + g_eeprom.config.setting.scan_list_default = 0; // back to scan list 1 - the next time we start scanning } // stop scanning @@ -263,7 +263,7 @@ void ACTION_Scan(bool bRestart) #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_vfo_rssi_bar_level[(g_rx_vfo_num + 1) & 1u] = 0; g_update_status = true; } @@ -280,7 +280,7 @@ void ACTION_Scan(bool bRestart) // 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; + g_eeprom.config.setting.scan_list_default = (g_eeprom.config.setting.scan_list_default + 1) % 3; // jump to the next channel APP_channel_next(true, g_scan_state_dir); @@ -300,13 +300,13 @@ void ACTION_Scan(bool bRestart) #ifdef ENABLE_VOX void ACTION_Vox(void) { - g_eeprom.vox_switch = !g_eeprom.vox_switch; - g_request_save_settings = true; - g_flag_reconfigure_vfos = true; + g_eeprom.config.setting.vox_switch = (g_eeprom.config.setting.vox_switch + 1) & 1u; + g_request_save_settings = true; + g_flag_reconfigure_vfos = true; #ifdef ENABLE_VOICE - g_another_voice_id = VOICE_ID_VOX; + g_another_voice_id = VOICE_ID_VOX; #endif - g_update_status = true; + g_update_status = true; } #endif @@ -378,14 +378,14 @@ void ACTION_process(const key_code_t Key, const bool key_pressed, const bool key if (Key == KEY_SIDE1) { - Short = g_eeprom.key1_short_press_action; - Long = g_eeprom.key1_long_press_action; + Short = g_eeprom.config.setting.key1_short; + Long = g_eeprom.config.setting.key1_long; } else if (Key == KEY_SIDE2) { - Short = g_eeprom.key2_short_press_action; - Long = g_eeprom.key2_long_press_action; + Short = g_eeprom.config.setting.key2_short; + Long = g_eeprom.config.setting.key2_long; } if (!key_held && key_pressed) diff --git a/app/aircopy.c b/app/aircopy.c index 2be708d..2f6eccf 100644 --- a/app/aircopy.c +++ b/app/aircopy.c @@ -114,6 +114,7 @@ void AIRCOPY_start_fsk_tx(const int request_block_num) if (request_block_num < 0) { EEPROM_ReadBuffer(eeprom_addr, &g_fsk_buffer[tx_size], 64); +// memcpy(&g_fsk_buffer[tx_size], ((uint8_t *)&g_eeprom) + eeprom_addr, 64); tx_size += 64 / 2; } @@ -590,6 +591,7 @@ void AIRCOPY_process_fsk_rx_10ms(void) } EEPROM_WriteBuffer8(eeprom_addr, data); // 8 bytes at a time +// memcpy(((uint8_t *)&g_eeprom) + eeprom_addr, data, 8); data += write_size / sizeof(data[0]); eeprom_addr += write_size; diff --git a/app/app.c b/app/app.c index 81f6c23..604da58 100644 --- a/app/app.c +++ b/app/app.c @@ -83,7 +83,7 @@ static void APP_update_rssi(const int vfo) #ifdef ENABLE_AM_FIX // add RF gain adjust compensation - if (g_eeprom.vfo_info[vfo].am_mode > 0 && g_setting_am_fix) + if (g_current_vfo->am_mode > 0 && g_eeprom.config.setting.am_fix) rssi -= rssi_gain_diff[vfo]; #endif @@ -113,11 +113,11 @@ static void APP_check_for_new_receive(void) g_rx_reception_mode = RX_MODE_DETECTED; } - if (g_eeprom.dual_watch == DUAL_WATCH_OFF) + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_OFF) { // dual watch is disabled #ifdef ENABLE_NOAA - if (g_is_noaa_mode) + if (g_noaa_mode) { g_noaa_tick_10ms = noaa_tick_3_10ms; g_schedule_noaa = false; @@ -132,7 +132,7 @@ static void APP_check_for_new_receive(void) if (g_rx_reception_mode != RX_MODE_NONE) goto done; - g_dual_watch_tick_10ms = g_eeprom.scan_hold_time_500ms * 50; + g_dual_watch_tick_10ms = g_eeprom.config.setting.scan_hold_time * 50; g_scan_pause_time_mode = false; g_update_status = true; @@ -162,7 +162,7 @@ done: } #endif } - APP_update_rssi(g_eeprom.rx_vfo); + APP_update_rssi(g_rx_vfo_num); g_update_rssi = true; // } } @@ -214,7 +214,7 @@ static void APP_process_new_receive(void) { // not code scanning #ifdef ENABLE_KILL_REVIVE - if (g_rx_vfo->dtmf_decoding_enable || g_setting_radio_disabled) + if (g_rx_vfo->dtmf_decoding_enable || g_eeprom.config.setting.radio_disabled) #else if (g_rx_vfo->dtmf_decoding_enable) #endif @@ -226,7 +226,7 @@ static void APP_process_new_receive(void) { 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.config.setting.scan_hold_time * 50; g_rx_reception_mode = RX_MODE_LISTENING; g_update_status = true; @@ -262,12 +262,12 @@ static void APP_process_rx(void) { if (g_squelch_open || g_monitor_enabled) { - switch (g_eeprom.scan_resume_mode) + switch (g_eeprom.config.setting.carrier_search_mode) { case SCAN_RESUME_TIME: // stay only for a limited time break; 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.config.setting.scan_hold_time * 50; g_scan_pause_time_mode = false; break; case SCAN_RESUME_STOP: // stop scan once we find any signal @@ -311,7 +311,7 @@ static void APP_process_rx(void) if (g_squelch_open || g_monitor_enabled) { - if (g_setting_backlight_on_tx_rx >= 2) + if (g_eeprom.config.setting.backlight_on_tx_rx >= 2) backlight_turn_on(backlight_tx_rx_time_500ms); // keep the backlight on while we're receiving if (!g_end_of_rx_detected_maybe && IS_NOT_NOAA_CHANNEL(g_rx_vfo->channel_save)) @@ -319,7 +319,7 @@ static void APP_process_rx(void) switch (g_current_code_type) { case CODE_TYPE_NONE: - if (g_eeprom.squelch_level > 0) + if (g_eeprom.config.setting.squelch_level > 0) { if (g_cxcss_tail_found) { @@ -381,7 +381,7 @@ static void APP_process_rx(void) if (!g_end_of_rx_detected_maybe && Mode == END_OF_RX_MODE_NONE && g_next_time_slice_40ms && - g_eeprom.tail_note_elimination && + g_eeprom.config.setting.tail_tone_elimination && (g_current_code_type == CODE_TYPE_DIGITAL || g_current_code_type == CODE_TYPE_REVERSE_DIGITAL) && BK4819_GetCTCType() == 1) { @@ -410,7 +410,7 @@ Skip: break; case END_OF_RX_MODE_TTE: - if (g_eeprom.tail_note_elimination) + if (g_eeprom.config.setting.tail_tone_elimination) { if (!g_monitor_enabled) GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); @@ -426,12 +426,12 @@ Skip: if (g_scan_state_dir != SCAN_STATE_DIR_OFF) { // we're RF scanning - switch (g_eeprom.scan_resume_mode) + switch (g_eeprom.config.setting.carrier_search_mode) { case SCAN_RESUME_TIME: // stay only for a limited time break; 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.config.setting.scan_hold_time * 50; g_scan_pause_time_mode = false; break; case SCAN_RESUME_STOP: // stop scan once we find any signal @@ -443,18 +443,18 @@ Skip: bool APP_start_listening(void) { - const unsigned int chan = g_eeprom.rx_vfo; + const unsigned int chan = g_rx_vfo_num; // const unsigned int chan = g_rx_vfo->channel_save; #ifdef ENABLE_KILL_REVIVE - if (g_setting_radio_disabled) + if (g_eeprom.config.setting.radio_disabled) return false; #endif if (g_squelch_open) BK4819_set_GPIO_pin(BK4819_GPIO6_PIN2_GREEN, true); // LED on - if (g_setting_backlight_on_tx_rx >= 2) + if (g_eeprom.config.setting.backlight_on_tx_rx >= 2) backlight_turn_on(backlight_tx_rx_time_500ms); #ifdef ENABLE_MDC1200 @@ -470,20 +470,20 @@ bool APP_start_listening(void) 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); + g_rx_vfo->freq_in_channel = SETTINGS_find_channel(g_rx_vfo->freq_config_rx.frequency); - switch (g_eeprom.scan_resume_mode) + switch (g_eeprom.config.setting.carrier_search_mode) { case SCAN_RESUME_TIME: if (!g_scan_pause_time_mode) { - g_scan_pause_tick_10ms = g_eeprom.scan_hold_time_500ms * 50; + g_scan_pause_tick_10ms = g_eeprom.config.setting.scan_hold_time * 50; g_scan_pause_time_mode = true; } break; case SCAN_RESUME_CARRIER: - g_scan_pause_tick_10ms = g_eeprom.scan_hold_time_500ms * 50; + g_scan_pause_tick_10ms = g_eeprom.config.setting.scan_hold_time * 50; g_scan_pause_time_mode = false; break; @@ -495,12 +495,12 @@ bool APP_start_listening(void) } #ifdef ENABLE_NOAA - if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_is_noaa_mode) + if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_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_eeprom.screen_channel[chan] = g_rx_vfo->channel_save; + g_eeprom.config.setting.indices.vfo[chan].screen = g_rx_vfo->channel_save; g_noaa_tick_10ms = 5000 / 10; // 5 sec g_schedule_noaa = false; } @@ -511,10 +511,10 @@ bool APP_start_listening(void) if (g_scan_state_dir == SCAN_STATE_DIR_OFF && g_css_scan_mode == CSS_SCAN_MODE_OFF && - g_eeprom.dual_watch != DUAL_WATCH_OFF) + g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF) { // dual watch is active - g_dual_watch_tick_10ms = g_eeprom.scan_hold_time_500ms * 50; + g_dual_watch_tick_10ms = g_eeprom.config.setting.scan_hold_time * 50; g_rx_vfo_is_active = true; g_update_status = true; } @@ -527,10 +527,10 @@ bool APP_start_listening(void) // else { BK4819_WriteRegister(0x48, - (11u << 12) | // ??? .. 0 ~ 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) + (11u << 12) | // ??? .. 0 ~ 15, doesn't seem to make any difference + ( 0u << 10) | // AF Rx Gain-1 + (g_eeprom.calib.volume_gain << 4) | // AF Rx Gain-2 + (g_eeprom.calib.dac_gain << 0)); // AF DAC Gain (after Gain-1 and Gain-2) } FUNCTION_Select(FUNCTION_RECEIVE); @@ -617,10 +617,10 @@ void APP_stop_scan(void) if (g_scan_restore_channel != 0xff) { - g_eeprom.user_channel[g_eeprom.rx_vfo] = g_scan_restore_channel; - g_eeprom.screen_channel[g_eeprom.rx_vfo] = g_scan_restore_channel; + g_eeprom.config.setting.indices.vfo[g_rx_vfo_num].user = g_scan_restore_channel; + g_eeprom.config.setting.indices.vfo[g_rx_vfo_num].screen = g_scan_restore_channel; - RADIO_configure_channel(g_eeprom.rx_vfo, VFO_CONFIGURE_RELOAD); + RADIO_configure_channel(g_rx_vfo_num, VFO_CONFIGURE_RELOAD); RADIO_setup_registers(true); } @@ -632,7 +632,7 @@ void APP_stop_scan(void) 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); + g_rx_vfo->freq_in_channel = SETTINGS_find_channel(g_rx_vfo->freq_config_rx.frequency); RADIO_ApplyOffset(g_rx_vfo, false); RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo); @@ -648,7 +648,7 @@ void APP_stop_scan(void) { // frequency mode RADIO_ApplyOffset(g_rx_vfo, false); RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo); - SETTINGS_save_channel(g_rx_vfo->channel_save, g_eeprom.rx_vfo, g_rx_vfo, 1); + SETTINGS_save_channel(g_rx_vfo->channel_save, g_rx_vfo_num, g_rx_vfo, 1); return; } @@ -716,9 +716,10 @@ static void APP_next_freq(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; - const int chan1 = (g_eeprom.scan_list_default < 2) ? g_eeprom.scan_list_priority_ch1[g_eeprom.scan_list_default] : -1; - const int chan2 = (g_eeprom.scan_list_default < 2) ? g_eeprom.scan_list_priority_ch2[g_eeprom.scan_list_default] : -1; + const unsigned int index = g_eeprom.config.setting.scan_list_default; + const bool enabled = (index < 2) ? !!g_eeprom.config.setting.priority_scan_list[index].enabled : true; + const int chan1 = (index < 2) ? g_eeprom.config.setting.priority_scan_list[index].channel[0] : -1; + const int chan2 = (index < 2) ? g_eeprom.config.setting.priority_scan_list[index].channel[1] : -1; const unsigned int prev_chan = g_scan_next_channel; unsigned int chan = 0; @@ -757,10 +758,10 @@ static void APP_next_channel(void) // this bit doesn't yet work if the other VFO is a frequency case SCAN_NEXT_CHAN_DUAL_WATCH: // dual watch is enabled - include the other VFO in the scan -// if (g_eeprom.dual_watch != DUAL_WATCH_OFF) +// if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF) // { -// chan = (g_eeprom.rx_vfo + 1) & 1u; -// chan = g_eeprom.screen_channel[chan]; +// chan = (g_rx_vfo + 1) & 1u; +// chan = g_eeprom.config.setting.indices.vfo[chan].screen; // if (chan <= USER_CHANNEL_LAST) // { // g_scan_current_scan_list = SCAN_NEXT_CHAN_DUAL_WATCH; @@ -782,7 +783,7 @@ static void APP_next_channel(void) if (!enabled || chan == 0xff) { - chan = RADIO_FindNextChannel(g_scan_next_channel + g_scan_state_dir, g_scan_state_dir, (g_eeprom.scan_list_default < 2) ? true : false, g_eeprom.scan_list_default); + chan = RADIO_FindNextChannel(g_scan_next_channel + g_scan_state_dir, g_scan_state_dir, (index < 2) ? true : false, index); if (chan == 0xFF) { // no valid channel found @@ -799,10 +800,10 @@ static void APP_next_channel(void) // UART_printf("APP_next_channel %u\r\n", g_scan_next_channel); #endif - g_eeprom.user_channel[g_eeprom.rx_vfo] = g_scan_next_channel; - g_eeprom.screen_channel[g_eeprom.rx_vfo] = g_scan_next_channel; + g_eeprom.config.setting.indices.vfo[g_rx_vfo_num].user = g_scan_next_channel; + g_eeprom.config.setting.indices.vfo[g_rx_vfo_num].screen = g_scan_next_channel; - RADIO_configure_channel(g_eeprom.rx_vfo, VFO_CONFIGURE_RELOAD); + RADIO_configure_channel(g_rx_vfo_num, VFO_CONFIGURE_RELOAD); RADIO_setup_registers(true); @@ -830,40 +831,63 @@ static void APP_next_channel(void) } #endif -static void APP_toggle_dual_watch_vfo(void) +static bool APP_toggle_dual_watch_vfo(void) { + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_OFF) + return false; + if (g_current_function == FUNCTION_FOREGROUND && g_current_function == FUNCTION_POWER_SAVE) + return false; + if (g_current_display_screen == DISPLAY_SEARCH) + return false; + if (g_scan_state_dir != SCAN_STATE_DIR_OFF) + return false; + if (g_css_scan_mode != CSS_SCAN_MODE_OFF) + return false; + if (g_ptt_is_pressed) + return false; + if (g_dtmf_call_state != DTMF_CALL_STATE_NONE) + return false; + #ifdef ENABLE_FMRADIO +// if (g_fm_radio_mode) +// return false; + #endif + if (g_dual_watch_tick_10ms > 0) + return false; + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) UART_SendText("dual wot\r\n"); #endif #ifdef ENABLE_NOAA - if (g_is_noaa_mode) + if (g_noaa_mode) { - if (IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[0]) || IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[1])) - g_eeprom.rx_vfo = (g_eeprom.rx_vfo + 1) & 1; + if (IS_NOT_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[0].screen) || IS_NOT_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[1].screen)) + g_rx_vfo_num = (g_rx_vfo_num + 1) & 1u; else - g_eeprom.rx_vfo = 0; + g_rx_vfo_num = 0; - g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.rx_vfo]; + g_rx_vfo = &g_vfo_info[g_rx_vfo_num]; - if (g_eeprom.vfo_info[0].channel_save >= NOAA_CHANNEL_FIRST) + if (g_vfo_info[0].channel_save >= NOAA_CHANNEL_FIRST) 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]; + g_rx_vfo_num = (g_rx_vfo_num + 1) & 1u; + g_rx_vfo = &g_vfo_info[g_rx_vfo_num]; g_update_status = true; } RADIO_setup_registers(false); #ifdef ENABLE_NOAA - g_dual_watch_tick_10ms = g_is_noaa_mode ? dual_watch_delay_noaa_10ms : dual_watch_delay_toggle_10ms; + g_dual_watch_tick_10ms = g_noaa_mode ? dual_watch_delay_noaa_10ms : dual_watch_delay_toggle_10ms; #else g_dual_watch_tick_10ms = dual_watch_delay_toggle_10ms; #endif + + return true; } void APP_process_radio_interrupts(void) @@ -884,7 +908,16 @@ void APP_process_radio_interrupts(void) int_bits = BK4819_ReadRegister(0x02); #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) - UART_printf("reg_c int_bits %04X\r\n", reg_c, int_bits); + { + int i; + UART_printf("int bits %04X %04X ", reg_c, int_bits); + for (i = 15; i >= 0; i--) + UART_printf("%c", (reg_c & (1u << i)) ? '#' : '.'); + UART_SendText(" "); + for (i = 15; i >= 0; i--) + UART_printf("%c", (int_bits & (1u << i)) ? '#' : '.'); + UART_SendText("\r\n"); + } #endif if (int_bits & BK4819_REG_02_DTMF_5TONE_FOUND) @@ -892,7 +925,7 @@ void APP_process_radio_interrupts(void) const char c = DTMF_GetCharacter(BK4819_GetDTMF_5TONE_Code()); if (c != 0xff && g_current_function != FUNCTION_TRANSMIT) { - if (g_setting_live_dtmf_decoder) + if (g_eeprom.config.setting.dtmf_live_decoder) { size_t len = strlen(g_dtmf_rx_live); if (len >= (sizeof(g_dtmf_rx_live) - 1)) @@ -905,9 +938,9 @@ void APP_process_radio_interrupts(void) g_dtmf_rx_live_timeout = dtmf_rx_live_timeout_500ms; // time till we delete it g_update_display = true; } - + #ifdef ENABLE_KILL_REVIVE - if (g_rx_vfo->dtmf_decoding_enable || g_setting_radio_disabled) + if (g_rx_vfo->dtmf_decoding_enable || g_eeprom.config.setting.radio_disabled) #else if (g_rx_vfo->dtmf_decoding_enable) #endif @@ -921,7 +954,7 @@ void APP_process_radio_interrupts(void) 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(); } } @@ -980,7 +1013,7 @@ void APP_process_radio_interrupts(void) g_vox_lost = true; g_vox_pause_tick_10ms = 10; - if (g_eeprom.vox_switch) + if (g_eeprom.config.setting.vox_switch) { if (g_current_function == FUNCTION_POWER_SAVE && !g_rx_idle_mode) { @@ -988,7 +1021,7 @@ void APP_process_radio_interrupts(void) g_power_save_expired = false; } - if (g_eeprom.dual_watch != DUAL_WATCH_OFF && + if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF && (g_dual_watch_tick_10ms == 0 || g_dual_watch_tick_10ms < dual_watch_delay_after_vox_10ms)) { g_dual_watch_tick_10ms = dual_watch_delay_after_vox_10ms; @@ -1017,7 +1050,7 @@ void APP_process_radio_interrupts(void) UART_SendText("sq close\r\n"); #endif - //APP_update_rssi(g_eeprom.rx_vfo); + //APP_update_rssi(g_rx_vfo); g_update_rssi = true; g_update_display = true; @@ -1031,12 +1064,12 @@ void APP_process_radio_interrupts(void) UART_SendText("sq open\r\n"); #endif - //APP_update_rssi(g_eeprom.rx_vfo); + //APP_update_rssi(g_rx_vfo_num); g_update_rssi = true; if (g_monitor_enabled) BK4819_set_GPIO_pin(BK4819_GPIO6_PIN2_GREEN, true); // LED on - + g_update_display = true; } @@ -1054,8 +1087,8 @@ void APP_end_tx(void) if (g_current_vfo->p_tx->code_type != CODE_TYPE_NONE) { // CTCSS/CDCSS is enabled - //if (g_eeprom.tail_note_elimination && g_eeprom.repeater_tail_tone_elimination > 0) - if (g_eeprom.tail_note_elimination) + //if (g_eeprom.config.setting.tail_tone_elimination && g_eeprom.config.setting.repeater_tail_tone_elimination > 0) + if (g_eeprom.config.setting.tail_tone_elimination) { // send the CTCSS/DCS tail tone - allows the receivers to mute the usual FM squelch tail/crash RADIO_enable_CxCSS_tail(); } @@ -1079,7 +1112,7 @@ void APP_end_tx(void) static void APP_process_vox(void) { #ifdef ENABLE_KILL_REVIVE - if (g_setting_radio_disabled) + if (g_eeprom.config.setting.radio_disabled) return; #endif @@ -1126,10 +1159,10 @@ void APP_end_tx(void) { APP_end_tx(); - if (g_eeprom.repeater_tail_tone_elimination == 0) + if (g_eeprom.config.setting.repeater_tail_tone_elimination == 0) FUNCTION_Select(FUNCTION_FOREGROUND); else - g_rtte_count_down = g_eeprom.repeater_tail_tone_elimination * 10; + g_rtte_count_down = g_eeprom.config.setting.repeater_tail_tone_elimination * 10; } g_update_status = true; @@ -1165,7 +1198,7 @@ void APP_check_keys(void) key_code_t key; #ifdef ENABLE_KILL_REVIVE - if (g_setting_radio_disabled) + if (g_eeprom.config.setting.radio_disabled) return; #endif @@ -1176,23 +1209,23 @@ void APP_check_keys(void) { // PTT pressed #ifdef ENABLE_AIRCOPY - if (!g_ptt_is_pressed && g_serial_config_tick_500ms == 0 && g_setting_tx_enable && g_current_function != FUNCTION_TRANSMIT && g_current_display_screen != DISPLAY_AIRCOPY) + if (!g_ptt_is_pressed && g_serial_config_tick_500ms == 0 && g_eeprom.config.setting.tx_enable && g_current_function != FUNCTION_TRANSMIT && g_current_display_screen != DISPLAY_AIRCOPY) #else - if (!g_ptt_is_pressed && g_serial_config_tick_500ms == 0 && g_setting_tx_enable && g_current_function != FUNCTION_TRANSMIT) + if (!g_ptt_is_pressed && g_serial_config_tick_500ms == 0 && g_eeprom.config.setting.tx_enable && g_current_function != FUNCTION_TRANSMIT) #endif { #ifdef ENABLE_KILL_REVIVE - if (!g_setting_radio_disabled) + if (!g_eeprom.config.setting.radio_disabled) #endif { if (++g_ptt_debounce >= 3) // 30ms debounce { // start TX'ing - + g_boot_tick_10ms = 0; // cancel the boot-up screen g_ptt_is_pressed = ptt_pressed; g_ptt_was_released = false; g_ptt_debounce = 3; - + APP_process_key(KEY_PTT, true, false); } } @@ -1202,9 +1235,9 @@ void APP_check_keys(void) { // PTT released #ifdef ENABLE_KILL_REVIVE - if (g_ptt_is_pressed || g_serial_config_tick_500ms > 0 || !g_setting_tx_enable || g_current_function == FUNCTION_TRANSMIT || g_setting_radio_disabled) + if (g_ptt_is_pressed || g_serial_config_tick_500ms > 0 || !g_eeprom.config.setting.tx_enable || g_current_function == FUNCTION_TRANSMIT || g_eeprom.config.setting.radio_disabled) #else - if (g_ptt_is_pressed || g_serial_config_tick_500ms > 0 || !g_setting_tx_enable || g_current_function == FUNCTION_TRANSMIT) + if (g_ptt_is_pressed || g_serial_config_tick_500ms > 0 || !g_eeprom.config.setting.tx_enable || g_current_function == FUNCTION_TRANSMIT) #endif { if (--g_ptt_debounce <= 0) @@ -1319,7 +1352,8 @@ void APP_check_keys(void) { // only the up and down keys are made repeatable // key repeat max 10ms speed if user is moving up/down in freq/channel - const uint8_t repeat_10ms = (g_manual_scanning && g_monitor_enabled && g_current_display_screen == DISPLAY_MAIN) ? 1 : key_repeat_10ms; + const bool freq_chan = IS_FREQ_CHANNEL(g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].screen); + const uint8_t repeat_10ms = (g_manual_scanning && g_monitor_enabled && freq_chan && g_current_display_screen == DISPLAY_MAIN) ? 1 : key_repeat_10ms; if (++g_key_debounce_repeat >= (key_long_press_10ms + repeat_10ms)) { // key repeat @@ -1384,7 +1418,7 @@ void APP_cancel_user_input_modes(void) if (!g_squelch_open && !g_monitor_enabled) GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); - if (g_eeprom.alarm_mode == ALARM_MODE_TONE) + if (g_eeprom.config.setting.alarm_mode == ALARM_MODE_TONE) { RADIO_tx_eot(); RADIO_enable_CxCSS_tail(); @@ -1570,7 +1604,7 @@ void APP_process_scan(void) MENU_SelectNextCode(); #ifdef ENABLE_NOAA - if (g_eeprom.dual_watch == DUAL_WATCH_OFF && g_is_noaa_mode && g_schedule_noaa) + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_OFF && g_noaa_mode && g_schedule_noaa) { APP_next_noaa(); @@ -1580,28 +1614,12 @@ void APP_process_scan(void) g_schedule_noaa = false; } #endif - switch (g_flash_light_state) - case FLASHLIGHT_SOS: - // toggle between the VFO's if dual watch is enabled - if (g_eeprom.dual_watch != DUAL_WATCH_OFF && - g_dual_watch_tick_10ms == 0 && - !g_ptt_is_pressed && - #ifdef ENABLE_FMRADIO - !g_fm_radio_mode && - #endif - g_dtmf_call_state == DTMF_CALL_STATE_NONE && - g_current_display_screen != DISPLAY_SEARCH && - g_scan_state_dir == SCAN_STATE_DIR_OFF && - g_css_scan_mode == CSS_SCAN_MODE_OFF && - g_current_function != FUNCTION_POWER_SAVE && - (g_current_function == FUNCTION_FOREGROUND || g_current_function == FUNCTION_POWER_SAVE)) + if (APP_toggle_dual_watch_vfo()) { - APP_toggle_dual_watch_vfo(); // toggle between the two VFO's - if (g_rx_vfo_is_active && g_current_display_screen == DISPLAY_MAIN) GUI_SelectNextDisplay(DISPLAY_MAIN); - + g_rx_vfo_is_active = false; g_rx_reception_mode = RX_MODE_NONE; } @@ -1658,7 +1676,7 @@ void APP_process_transmit(void) BK4819_SetScrambleFrequencyControlWord((Tone <= 1500) ? Tone : (1500 * 2) - Tone); - if (g_eeprom.alarm_mode == ALARM_MODE_TONE && g_alarm_running_counter_10ms == 512) + if (g_eeprom.config.setting.alarm_mode == ALARM_MODE_TONE && g_alarm_running_counter_10ms == 512) { g_alarm_running_counter_10ms = 0; @@ -1713,7 +1731,7 @@ void APP_process_functions(void) break; case FUNCTION_TRANSMIT: - if (g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3) + if (g_eeprom.config.setting.backlight_on_tx_rx == 1 || g_eeprom.config.setting.backlight_on_tx_rx == 3) backlight_turn_on(backlight_tx_rx_time_500ms); break; @@ -1750,7 +1768,7 @@ void APP_process_power_save(void) g_fkey_pressed || g_key_pressed != KEY_INVALID || g_key_held || - g_eeprom.battery_save == 0 || + g_eeprom.config.setting.battery_save_ratio == 0 || g_scan_state_dir != SCAN_STATE_DIR_OFF || g_css_scan_mode != CSS_SCAN_MODE_OFF || g_current_display_screen != DISPLAY_MAIN || @@ -1761,9 +1779,9 @@ void APP_process_power_save(void) } #ifdef ENABLE_NOAA - if (IS_NOAA_CHANNEL(g_eeprom.screen_channel[0]) || - IS_NOAA_CHANNEL(g_eeprom.screen_channel[1]) || - g_is_noaa_mode) + if (IS_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[0].screen) || + IS_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[1].screen) || + g_noaa_mode) { power_save = false; } @@ -1786,6 +1804,8 @@ void APP_process_power_save(void) g_schedule_power_save = false; + // ************************** + #ifdef ENABLE_VOICE if (g_voice_write_index != 0) return; @@ -1805,17 +1825,12 @@ void APP_process_power_save(void) BK4819_Conditional_RX_TurnOn(); #ifdef ENABLE_VOX - if (g_eeprom.vox_switch) - BK4819_EnableVox(g_eeprom.vox1_threshold, g_eeprom.vox0_threshold); + if (g_eeprom.config.setting.vox_switch) + BK4819_EnableVox(g_vox_threshold[1], g_vox_threshold[0]); #endif - if (g_eeprom.dual_watch != DUAL_WATCH_OFF && - 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 - APP_toggle_dual_watch_vfo(); + if (APP_toggle_dual_watch_vfo()) g_update_rssi = false; - } FUNCTION_Init(); @@ -1823,17 +1838,17 @@ void APP_process_power_save(void) g_rx_idle_mode = false; // RX is awake } else - if (g_eeprom.dual_watch == DUAL_WATCH_OFF || + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_OFF || g_scan_state_dir != SCAN_STATE_DIR_OFF || g_css_scan_mode != CSS_SCAN_MODE_OFF || g_update_rssi) - { // dual watch mode, go back to sleep + { // go back to sleep - APP_update_rssi(g_eeprom.rx_vfo); + APP_update_rssi(g_rx_vfo_num); // go back to sleep - g_power_save_tick_10ms = g_eeprom.battery_save * 10; + g_power_save_tick_10ms = g_eeprom.config.setting.battery_save_ratio * 10; g_rx_idle_mode = true; BK4819_DisableVox(); @@ -1841,11 +1856,9 @@ void APP_process_power_save(void) BK4819_set_GPIO_pin(BK4819_GPIO0_PIN28_RX_ENABLE, false); } else + if (APP_toggle_dual_watch_vfo()) { - // toggle between the two VFO's - APP_toggle_dual_watch_vfo(); - - g_update_rssi = true; + g_update_rssi = true; g_power_save_tick_10ms = power_save1_10ms; } @@ -1945,14 +1958,14 @@ void APP_time_slice_500ms(void) // g_update_display = true; // can't do this if not FM scanning, it causes audio clicks #endif - if (g_backlight_count_down > 0 && + if (g_backlight_tick_500ms > 0 && !g_ask_to_save && g_css_scan_mode == CSS_SCAN_MODE_OFF && g_current_display_screen != DISPLAY_AIRCOPY) { if (g_current_display_screen != DISPLAY_MENU || g_menu_cursor != MENU_AUTO_BACKLITE) // don't turn off backlight if user is in backlight menu option - if (--g_backlight_count_down == 0) - if (g_eeprom.backlight < (ARRAY_SIZE(g_sub_menu_backlight) - 1)) + if (--g_backlight_tick_500ms == 0) + if (g_eeprom.config.setting.backlight_time < (ARRAY_SIZE(g_sub_menu_backlight) - 1)) GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn backlight off } @@ -1960,7 +1973,7 @@ void APP_time_slice_500ms(void) { BOARD_ADC_GetBatteryInfo(&g_usb_current_voltage, &g_usb_current); - if (g_usb_current > 500 || g_battery_calibration[3] < g_usb_current_voltage) + if (g_usb_current > 500 || g_eeprom.calib.battery[3] < g_usb_current_voltage) { #ifdef ENABLE_OVERLAY overlay_FLASH_RebootToBootloader(); @@ -1984,7 +1997,7 @@ void APP_time_slice_500ms(void) // update every 2 sec if ((g_battery_check_counter & 3) == 0) { - if (g_charging_with_type_c || g_setting_battery_text > 0) + if (g_charging_with_type_c || g_eeprom.config.setting.battery_text > 0) g_update_status = true; #ifdef ENABLE_SHOW_CHARGE_LEVEL @@ -2010,7 +2023,7 @@ void APP_time_slice_500ms(void) { #ifdef ENABLE_KEYLOCK - if (g_eeprom.auto_keypad_lock && + if (g_eeprom.config.setting.auto_key_lock != 0 && g_key_lock_tick_500ms > 0 && !g_dtmf_input_mode && g_input_box_index == 0 && @@ -2018,8 +2031,8 @@ void APP_time_slice_500ms(void) { if (--g_key_lock_tick_500ms == 0) { // lock the keyboard - g_eeprom.key_lock = true; - g_update_status = true; + g_eeprom.config.setting.key_lock = true; + g_update_status = true; } } #endif @@ -2028,9 +2041,9 @@ void APP_time_slice_500ms(void) { g_menu_tick_10ms = 0; - if (g_eeprom.backlight == 0) + if (g_eeprom.config.setting.backlight_time == 0) { - g_backlight_count_down = 0; + g_backlight_tick_500ms = 0; GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF } @@ -2088,7 +2101,7 @@ void APP_time_slice_500ms(void) } if (g_current_function != FUNCTION_POWER_SAVE && g_current_function != FUNCTION_TRANSMIT) - APP_update_rssi(g_eeprom.rx_vfo); + APP_update_rssi(g_rx_vfo_num); if (g_low_battery) { @@ -2129,7 +2142,7 @@ void APP_time_slice_500ms(void) ST7565_HardwareReset(); - if (g_eeprom.backlight < (ARRAY_SIZE(g_sub_menu_backlight) - 1)) + if (g_eeprom.config.setting.backlight_time < (ARRAY_SIZE(g_sub_menu_backlight) - 1)) GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight off } #ifdef ENABLE_VOICE @@ -2196,7 +2209,7 @@ void APP_time_slice_500ms(void) { if (--g_dtmf_auto_reset_time_500ms == 0) { - if (g_dtmf_call_state == DTMF_CALL_STATE_RECEIVED && g_eeprom.dtmf_auto_reset_time >= DTMF_HOLD_MAX) + if (g_dtmf_call_state == DTMF_CALL_STATE_RECEIVED && g_eeprom.config.setting.dtmf.auto_reset_time >= DTMF_HOLD_MAX) g_dtmf_call_state = DTMF_CALL_STATE_RECEIVED_STAY; // keep message on-screen till a key is pressed else g_dtmf_call_state = DTMF_CALL_STATE_NONE; @@ -2282,8 +2295,8 @@ void APP_time_slice_10ms(void) #endif #ifdef ENABLE_AM_FIX - if (g_rx_vfo->am_mode > 0 && g_setting_am_fix) - AM_fix_10ms(g_eeprom.rx_vfo); + if (g_rx_vfo->am_mode > 0 && g_eeprom.config.setting.am_fix) + AM_fix_10ms(g_rx_vfo_num); #endif #ifdef ENABLE_FMRADIO @@ -2308,10 +2321,10 @@ void APP_time_slice_10ms(void) if (g_flag_save_channel) { - SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, g_flag_save_channel ? 1 : 0); + SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, g_flag_save_channel ? 1 : 0); g_flag_save_channel = false; - RADIO_configure_channel(g_eeprom.tx_vfo, VFO_CONFIGURE); + RADIO_configure_channel(g_eeprom.config.setting.tx_vfo_num, VFO_CONFIGURE); RADIO_setup_registers(true); @@ -2350,7 +2363,7 @@ void APP_time_slice_10ms(void) if (g_current_function == FUNCTION_TRANSMIT) { // transmitting #ifdef ENABLE_TX_AUDIO_BAR - if (g_setting_mic_bar && (g_flash_light_blink_tick_10ms % (150 / 10)) == 0 && !g_update_display) // once every 150ms + if (g_eeprom.config.setting.mic_bar && (g_flash_light_blink_tick_10ms % (150 / 10)) == 0 && !g_update_display) // once every 150ms UI_DisplayAudioBar(true); #endif } @@ -2383,7 +2396,7 @@ void APP_time_slice_10ms(void) if (g_vox_pause_tick_10ms > 0) g_vox_pause_tick_10ms--; - if (g_eeprom.vox_switch) + if (g_eeprom.config.setting.vox_switch) APP_process_vox(); #endif @@ -2435,7 +2448,7 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const // remember the current backlight state (on / off) const bool backlight_was_on = GPIO_CheckBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); - if (Key == KEY_EXIT && !backlight_was_on && g_eeprom.backlight > 0) + if (Key == KEY_EXIT && !backlight_was_on && g_eeprom.config.setting.backlight_time > 0) { // just turn the back light on for now so the user can see what's what if (!key_pressed && !key_held) { // key has been released @@ -2459,7 +2472,7 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const #ifdef ENABLE_KEYLOCK // keep the auto keylock at bay - if (g_eeprom.auto_keypad_lock) + if (g_eeprom.config.setting.auto_key_lock != 0) g_key_lock_tick_500ms = key_lock_timeout_500ms; #endif @@ -2471,8 +2484,8 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const // ******************** - #ifdef ENABLE_KEYLOCK - if (g_eeprom.key_lock && g_current_function != FUNCTION_TRANSMIT && Key != KEY_PTT) +#ifdef ENABLE_KEYLOCK + if (g_eeprom.config.setting.key_lock && g_current_function != FUNCTION_TRANSMIT && Key != KEY_PTT) { // keyboard is locked if (Key == KEY_F) @@ -2483,7 +2496,7 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const if (key_held) { // unlock the keypad - g_eeprom.key_lock = false; + g_eeprom.config.setting.g_eeprom.key_lock = false; g_request_save_settings = true; g_update_status = true; @@ -2514,7 +2527,7 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const return; } } - #endif +#endif // key beep // if (Key != KEY_PTT && !key_held && key_pressed) @@ -2647,7 +2660,7 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const BK4819_ExitDTMF_TX(false); - if (g_current_vfo->scrambling_type == 0 || !g_setting_scramble_enable) + if (g_current_vfo->scrambling_type == 0 || !g_eeprom.config.setting.enable_scrambler) BK4819_DisableScramble(); else BK4819_EnableScramble(g_current_vfo->scrambling_type - 1); @@ -2655,7 +2668,7 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const } else { - if (g_eeprom.dtmf_side_tone) + if (g_eeprom.config.setting.dtmf.side_tone) { // user will here the DTMF tones in speaker GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); } @@ -2663,9 +2676,9 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const BK4819_DisableScramble(); if (Code == 0xFE) - BK4819_TransmitTone(g_eeprom.dtmf_side_tone, 1750); + BK4819_TransmitTone(g_eeprom.config.setting.dtmf.side_tone, 1750); else - BK4819_PlayDTMFEx(g_eeprom.dtmf_side_tone, Code); + BK4819_PlayDTMFEx(g_eeprom.config.setting.dtmf.side_tone, Code); } } #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) @@ -2674,10 +2687,10 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const { APP_alarm_off(); - if (g_eeprom.repeater_tail_tone_elimination == 0) + if (g_eeprom.config.setting.repeater_tail_tone_elimination == 0) FUNCTION_Select(FUNCTION_FOREGROUND); else - g_rtte_count_down = g_eeprom.repeater_tail_tone_elimination * 10; + g_rtte_count_down = g_eeprom.config.setting.repeater_tail_tone_elimination * 10; if (Key == KEY_PTT) g_ptt_was_pressed = true; @@ -2800,7 +2813,7 @@ Skip: { if (!key_held) { - SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, g_request_save_channel); + SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, g_request_save_channel); if (g_current_display_screen != DISPLAY_SEARCH) if (g_vfo_configure_mode == VFO_CONFIGURE_NONE) // don't wipe previous variable setting @@ -2826,7 +2839,7 @@ Skip: } else { - RADIO_configure_channel(g_eeprom.tx_vfo, g_vfo_configure_mode); + RADIO_configure_channel(g_eeprom.config.setting.tx_vfo_num, g_vfo_configure_mode); } if (g_request_display_screen == DISPLAY_INVALID) @@ -2847,7 +2860,7 @@ Skip: RADIO_setup_registers(true); -// g_tx_vfo->freq_in_channel = BOARD_find_channel(frequency); +// g_tx_vfo->freq_in_channel = SETTINGS_find_channel(frequency); g_dtmf_auto_reset_time_500ms = 0; g_dtmf_call_state = DTMF_CALL_STATE_NONE; diff --git a/app/dtmf.c b/app/dtmf.c index eec0bec..b3389b7 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -93,9 +93,10 @@ bool DTMF_ValidateCodes(char *pCode, const unsigned int size) bool DTMF_GetContact(const int Index, char *pContact) { int i = -1; - if (Index >= 0 && Index < MAX_DTMF_CONTACTS && pContact != NULL) + if (Index >= 0 && Index < (int)ARRAY_SIZE(g_eeprom.config.dtmf_contact)) { - EEPROM_ReadBuffer(0x1C00 + (Index * 16), pContact, 16); + memcpy(pContact, &g_eeprom.config.dtmf_contact[Index], 16); +// EEPROM_ReadBuffer(0x1C00 + (Index * 16), pContact, 16); i = (int)pContact[0] - ' '; } return (i < 0 || i >= 95) ? false : true; @@ -159,7 +160,7 @@ bool DTMF_CompareMessage(const char *pMsg, const char *pTemplate, const unsigned { if (pMsg[i] != pTemplate[i]) { - if (!bCheckGroup || pMsg[i] != g_eeprom.dtmf_group_call_code) + if (!bCheckGroup || pMsg[i] != g_eeprom.config.setting.dtmf.group_call_code) return false; g_dtmf_IsGroupCall = true; } @@ -172,7 +173,7 @@ dtmf_call_mode_t DTMF_CheckGroupCall(const char *pMsg, const unsigned int size) { unsigned int i; for (i = 0; i < size; i++) - if (pMsg[i] == g_eeprom.dtmf_group_call_code) + if (pMsg[i] == g_eeprom.config.setting.dtmf.group_call_code) break; return (i < size) ? DTMF_CALL_MODE_GROUP : DTMF_CALL_MODE_NOT_GROUP; @@ -213,7 +214,7 @@ void DTMF_HandleRequest(void) } #ifdef ENABLE_KILL_REVIVE - if (!g_rx_vfo->dtmf_decoding_enable && !g_setting_radio_disabled) + if (!g_rx_vfo->dtmf_decoding_enable && !g_eeprom.config.setting.radio_disabled) #else if (!g_rx_vfo->dtmf_decoding_enable) #endif @@ -228,16 +229,16 @@ void DTMF_HandleRequest(void) if (g_dtmf_rx_index >= 9) { // look for the RADIO DISABLE code - sprintf(String, "%s%c%s", g_eeprom.ani_dtmf_id, g_eeprom.dtmf_separate_code, g_eeprom.kill_code); + sprintf(String, "%s%c%s", g_eeprom.config.setting.dtmf.ani_id, g_eeprom.config.setting.dtmf.separate_code, g_eeprom.config.setting.dtmf.kill_code); Offset = g_dtmf_rx_index - strlen(String); if (DTMF_CompareMessage(g_dtmf_rx + Offset, String, strlen(String), true)) { // bugger - if (g_eeprom.permit_remote_kill) + if (g_eeprom.config.setting.dtmf.permit_remote_kill != 0) { - g_setting_radio_disabled = true; // :( + g_eeprom.config.setting.radio_disabled = true; // :( DTMF_clear_RX(); @@ -269,14 +270,14 @@ void DTMF_HandleRequest(void) if (g_dtmf_rx_index >= 9) { // look for the REVIVE code - sprintf(String, "%s%c%s", g_eeprom.ani_dtmf_id, g_eeprom.dtmf_separate_code, g_eeprom.revive_code); + sprintf(String, "%s%c%s", g_eeprom.config.setting.dtmf.ani_id, g_eeprom.config.setting.dtmf.separate_code, g_eeprom.config.setting.dtmf.revive_code); Offset = g_dtmf_rx_index - strlen(String); if (DTMF_CompareMessage(g_dtmf_rx + Offset, String, strlen(String), true)) { // shit, we're back ! - g_setting_radio_disabled = false; + g_eeprom.config.setting.radio_disabled = false; DTMF_clear_RX(); @@ -318,7 +319,7 @@ void DTMF_HandleRequest(void) g_dtmf_rx_index >= 9) { // waiting for a reply - sprintf(String, "%s%c%s", g_dtmf_string, g_eeprom.dtmf_separate_code, "AAAAA"); + sprintf(String, "%s%c%s", g_dtmf_string, g_eeprom.config.setting.dtmf.separate_code, "AAAAA"); Offset = g_dtmf_rx_index - strlen(String); @@ -331,7 +332,7 @@ void DTMF_HandleRequest(void) } #ifdef ENABLE_KILL_REVIVE - if (g_setting_radio_disabled) + if (g_eeprom.config.setting.radio_disabled) return; // we've been disabled #endif @@ -340,7 +341,7 @@ void DTMF_HandleRequest(void) g_dtmf_IsGroupCall = false; - sprintf(String, "%s%c", g_eeprom.ani_dtmf_id, g_eeprom.dtmf_separate_code); + sprintf(String, "%s%c", g_eeprom.config.setting.dtmf.ani_id, g_eeprom.config.setting.dtmf.separate_code); Offset = g_dtmf_rx_index - strlen(String) - 3; @@ -358,7 +359,7 @@ void DTMF_HandleRequest(void) g_update_display = true; - switch (g_eeprom.dtmf_decode_response) + switch (g_eeprom.config.setting.dtmf.decode_response) { case DTMF_DEC_RESPONSE_BOTH: g_dtmf_decode_ring_tick_500ms = dtmf_decode_ring_500ms; @@ -386,7 +387,7 @@ void DTMF_HandleRequest(void) bool DTMF_Reply(void) { - const uint16_t Delay = (g_eeprom.dtmf_preload_time < 150) ? 150 : g_eeprom.dtmf_preload_time; + const uint16_t delay_ms = ((g_eeprom.config.setting.dtmf.preload_time < 15) ? 15 : g_eeprom.config.setting.dtmf.preload_time) * 10; const char *pString = NULL; char String[23]; @@ -399,7 +400,7 @@ bool DTMF_Reply(void) } else { // append our ID code onto the end of the DTMF code to send - sprintf(String, "%s%c%s", g_dtmf_string, g_eeprom.dtmf_separate_code, g_eeprom.ani_dtmf_id); + sprintf(String, "%s%c%s", g_dtmf_string, g_eeprom.config.setting.dtmf.separate_code, g_eeprom.config.setting.dtmf.ani_id); pString = String; } break; @@ -409,7 +410,7 @@ bool DTMF_Reply(void) break; case DTMF_REPLY_AAAAA: - sprintf(String, "%s%c%s", g_eeprom.ani_dtmf_id, g_eeprom.dtmf_separate_code, "AAAAA"); + sprintf(String, "%s%c%s", g_eeprom.config.setting.dtmf.ani_id, g_eeprom.config.setting.dtmf.separate_code, "AAAAA"); pString = String; break; @@ -425,7 +426,7 @@ bool DTMF_Reply(void) } // send TX-UP DTMF - pString = g_eeprom.dtmf_key_up_code; + pString = g_eeprom.config.setting.dtmf.key_up_code; break; } @@ -434,22 +435,22 @@ bool DTMF_Reply(void) if (pString == NULL) return false; - if (g_eeprom.dtmf_side_tone) + if (g_eeprom.config.setting.dtmf.side_tone) { // the user will also hear the transmitted tones GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); } - SYSTEM_DelayMs(Delay); + SYSTEM_DelayMs(delay_ms); - BK4819_EnterDTMF_TX(g_eeprom.dtmf_side_tone); + BK4819_EnterDTMF_TX(g_eeprom.config.setting.dtmf.side_tone); BK4819_PlayDTMFString( pString, 1, - g_eeprom.dtmf_first_code_persist_time, - g_eeprom.dtmf_hash_code_persist_time, - g_eeprom.dtmf_code_persist_time, - g_eeprom.dtmf_code_interval_time); + g_eeprom.config.setting.dtmf.first_code_persist_time * 10, + g_eeprom.config.setting.dtmf.hash_code_persist_time * 10, + g_eeprom.config.setting.dtmf.code_persist_time * 10, + g_eeprom.config.setting.dtmf.code_interval_time * 10); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); diff --git a/app/fm.c b/app/fm.c index cbce0be..32ffe82 100644 --- a/app/fm.c +++ b/app/fm.c @@ -37,7 +37,6 @@ #define STATE_USER_MODE 1 #define STATE_SAVE 2 -uint16_t g_fm_channels[20]; bool g_fm_radio_mode; fm_scan_state_dir_t g_fm_scan_state_dir; bool g_fm_auto_scan; @@ -51,19 +50,19 @@ volatile bool g_fm_schedule; bool FM_check_valid_channel(const unsigned int Channel) { - return (Channel < ARRAY_SIZE(g_fm_channels) && (g_fm_channels[Channel] >= BK1080_freq_lower && g_fm_channels[Channel] < BK1080_freq_upper)) ? true : false; + return (Channel < ARRAY_SIZE(g_eeprom.config.setting.fm_channel) && (g_eeprom.config.setting.fm_channel[Channel] >= BK1080_freq_lower && g_eeprom.config.setting.fm_channel[Channel] < BK1080_freq_upper)) ? true : false; } unsigned int FM_find_next_channel(unsigned int Channel, const fm_scan_state_dir_t scan_state_dir) { unsigned int i; - for (i = 0; i < ARRAY_SIZE(g_fm_channels); i++) + for (i = 0; i < ARRAY_SIZE(g_eeprom.config.setting.fm_channel); i++) { - if (Channel > ARRAY_SIZE(g_fm_channels)) - Channel = ARRAY_SIZE(g_fm_channels) - 1; + if (Channel > ARRAY_SIZE(g_eeprom.config.setting.fm_channel)) + Channel = ARRAY_SIZE(g_eeprom.config.setting.fm_channel) - 1; else - if (Channel >= ARRAY_SIZE(g_fm_channels)) + if (Channel >= ARRAY_SIZE(g_eeprom.config.setting.fm_channel)) Channel = 0; if (FM_check_valid_channel(Channel)) @@ -77,19 +76,17 @@ unsigned int FM_find_next_channel(unsigned int Channel, const fm_scan_state_dir_ int FM_configure_channel_state(void) { - g_eeprom.fm_frequency_playing = g_eeprom.fm_selected_frequency; - - if (g_eeprom.fm_channel_mode) + if (g_eeprom.config.setting.fm_radio.channel_mode != 0) { - const uint8_t Channel = FM_find_next_channel(g_eeprom.fm_selected_channel, FM_CHANNEL_UP); + const uint8_t Channel = FM_find_next_channel(g_eeprom.config.setting.fm_radio.selected_channel, FM_CHANNEL_UP); if (Channel == 0xFF) { - g_eeprom.fm_channel_mode = false; + g_eeprom.config.setting.fm_radio.channel_mode = 0; return -1; } - g_eeprom.fm_selected_channel = Channel; - g_eeprom.fm_frequency_playing = g_fm_channels[Channel]; + g_eeprom.config.setting.fm_radio.selected_channel = Channel; + g_eeprom.config.setting.fm_radio.selected_frequency = g_eeprom.config.setting.fm_channel[Channel]; } return 0; @@ -99,12 +96,11 @@ void FM_erase_channels(void) { unsigned int i; uint8_t Template[8]; - memset(Template, 0xFF, sizeof(Template)); for (i = 0; i < 5; i++) EEPROM_WriteBuffer8(0x0E40 + (i * 8), Template); - memset(g_fm_channels, 0xFF, sizeof(g_fm_channels)); + memset(&g_eeprom.config.setting.fm_channel, 0xff, sizeof(g_eeprom.config.setting.fm_channel)); } void FM_tune(uint16_t frequency, const fm_scan_state_dir_t scan_state_dir, const bool flag) @@ -117,7 +113,7 @@ void FM_tune(uint16_t frequency, const fm_scan_state_dir_t scan_state_dir, const g_fm_found_frequency = false; g_ask_to_save = false; g_ask_to_delete = false; - g_eeprom.fm_frequency_playing = frequency; + g_eeprom.config.setting.fm_radio.selected_frequency = frequency; if (!flag) { // wrap-a-around @@ -129,12 +125,12 @@ void FM_tune(uint16_t frequency, const fm_scan_state_dir_t scan_state_dir, const if (frequency >= BK1080_freq_upper) frequency = BK1080_freq_lower; - g_eeprom.fm_frequency_playing = frequency; + g_eeprom.config.setting.fm_radio.selected_frequency = frequency; } g_fm_scan_state_dir = scan_state_dir; - BK1080_SetFrequency(g_eeprom.fm_frequency_playing); + BK1080_SetFrequency(g_eeprom.config.setting.fm_radio.selected_frequency); if (g_fm_resume_tick_500ms < 10) g_fm_resume_tick_500ms = 10; // update display for next 5 seconds @@ -147,18 +143,18 @@ void FM_stop_scan(void) g_fm_scan_state_dir = FM_SCAN_STATE_DIR_OFF; - if (g_fm_auto_scan || g_eeprom.fm_channel_mode) + if (g_fm_auto_scan || g_eeprom.config.setting.fm_radio.channel_mode != 0) { // switch to channel mode - g_eeprom.fm_channel_mode = true; - g_eeprom.fm_selected_channel = 0; + g_eeprom.config.setting.fm_radio.channel_mode = 1; + g_eeprom.config.setting.fm_radio.selected_channel = 0; FM_configure_channel_state(); } else - { - g_eeprom.fm_channel_mode = false; + { // frequency mode + g_eeprom.config.setting.fm_radio.channel_mode = 0; } - BK1080_SetFrequency(g_eeprom.fm_frequency_playing); + BK1080_SetFrequency(g_eeprom.config.setting.fm_radio.selected_frequency); SETTINGS_save_fm(); @@ -209,15 +205,15 @@ Bail: void FM_scan(void) { - if (!FM_check_frequency_lock(g_eeprom.fm_frequency_playing, BK1080_freq_lower)) + if (!FM_check_frequency_lock(g_eeprom.config.setting.fm_radio.selected_frequency, BK1080_freq_lower)) { if (!g_fm_auto_scan) { g_fm_play_tick_10ms = 0; g_fm_found_frequency = true; - if (!g_eeprom.fm_channel_mode) - g_eeprom.fm_selected_frequency = g_eeprom.fm_frequency_playing; +// if (g_eeprom.config.setting.fm_radio.channel_mode == 0) +// g_eeprom.config.setting.fm_radio.selected_frequency = g_eeprom.fm_frequency_playing; GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); @@ -225,10 +221,10 @@ void FM_scan(void) return; } - if (g_fm_channel_position < ARRAY_SIZE(g_fm_channels)) - g_fm_channels[g_fm_channel_position++] = g_eeprom.fm_frequency_playing; + if (g_fm_channel_position < ARRAY_SIZE(g_eeprom.config.setting.fm_channel)) + g_eeprom.config.setting.fm_channel[g_fm_channel_position++] = g_eeprom.config.setting.fm_radio.selected_frequency; - if (g_fm_channel_position >= ARRAY_SIZE(g_fm_channels)) + if (g_fm_channel_position >= ARRAY_SIZE(g_eeprom.config.setting.fm_channel)) { FM_stop_scan(); GUI_SelectNextDisplay(DISPLAY_FM); @@ -236,10 +232,10 @@ void FM_scan(void) } } - if (g_fm_auto_scan && g_eeprom.fm_frequency_playing >= (BK1080_freq_upper - 1u)) + if (g_fm_auto_scan && g_eeprom.config.setting.fm_radio.selected_frequency >= (BK1080_freq_upper - 1u)) FM_stop_scan(); else - FM_tune(g_eeprom.fm_frequency_playing, g_fm_scan_state_dir, false); + FM_tune(g_eeprom.config.setting.fm_radio.selected_frequency, g_fm_scan_state_dir, false); GUI_SelectNextDisplay(DISPLAY_FM); } @@ -255,7 +251,7 @@ void FM_turn_on(void) g_fm_resume_tick_500ms = fm_resume_500ms; // update display again in 'n' seconds // enable the FM radio chip/audio - BK1080_Init(g_eeprom.fm_frequency_playing, true); + BK1080_Init(g_eeprom.config.setting.fm_radio.selected_frequency, true); GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); @@ -285,13 +281,13 @@ void FM_turn_off(void) void FM_toggle_chan_freq_mode(void) { - g_eeprom.fm_channel_mode = !g_eeprom.fm_channel_mode; + g_eeprom.config.setting.fm_radio.channel_mode = (g_eeprom.config.setting.fm_radio.channel_mode + 1) & 1u; FM_stop_scan(); if (!FM_configure_channel_state()) { - BK1080_SetFrequency(g_eeprom.fm_frequency_playing); + BK1080_SetFrequency(g_eeprom.config.setting.fm_radio.selected_frequency); g_request_save_fm = true; } } @@ -344,7 +340,7 @@ static void FM_Key_DIGITS(const key_code_t Key, const bool key_pressed, const bo if (g_fm_scan_state_dir != FM_SCAN_STATE_DIR_OFF) return; - State = g_eeprom.fm_channel_mode ? STATE_USER_MODE : STATE_FREQ_MODE; + State = (g_eeprom.config.setting.fm_radio.channel_mode != 0) ? STATE_USER_MODE : STATE_FREQ_MODE; } INPUTBOX_append(Key); @@ -379,14 +375,14 @@ static void FM_Key_DIGITS(const key_code_t Key, const bool key_pressed, const bo if (Frequency >= BK1080_freq_upper) Frequency = BK1080_freq_upper - 1u; - g_eeprom.fm_selected_frequency = (uint16_t)Frequency; + g_eeprom.config.setting.fm_radio.selected_frequency = (uint16_t)Frequency; #ifdef ENABLE_VOICE g_another_voice_id = (voice_id_t)Key; #endif - g_eeprom.fm_frequency_playing = g_eeprom.fm_selected_frequency; - BK1080_SetFrequency(g_eeprom.fm_frequency_playing); +// g_eeprom.fm_frequency_playing = g_eeprom.config.setting.fm_radio.selected_frequency; + BK1080_SetFrequency(g_eeprom.config.setting.fm_radio.selected_frequency); g_request_save_fm = true; return; @@ -409,17 +405,17 @@ static void FM_Key_DIGITS(const key_code_t Key, const bool key_pressed, const bo g_another_voice_id = (voice_id_t)Key; #endif - g_eeprom.fm_selected_channel = Channel; - g_eeprom.fm_frequency_playing = g_fm_channels[Channel]; + g_eeprom.config.setting.fm_radio.selected_channel = Channel; + g_eeprom.config.setting.fm_radio.selected_frequency = g_eeprom.config.setting.fm_channel[Channel]; - BK1080_SetFrequency(g_eeprom.fm_frequency_playing); + BK1080_SetFrequency(g_eeprom.config.setting.fm_radio.selected_frequency); g_request_save_fm = true; return; } } else - if (Channel < ARRAY_SIZE(g_fm_channels)) + if (Channel < ARRAY_SIZE(g_eeprom.config.setting.fm_channel)) { #ifdef ENABLE_VOICE g_another_voice_id = (voice_id_t)Key; @@ -555,8 +551,8 @@ static void FM_Key_MENU(const bool key_pressed, const bool key_held) return; // key still pressed // see if the frequency is already stored in a channel - for (i = 0; i < ARRAY_SIZE(g_fm_channels) && channel < 0; i++) - if (g_fm_channels[i] == g_eeprom.fm_frequency_playing) + for (i = 0; i < ARRAY_SIZE(g_eeprom.config.setting.fm_channel) && channel < 0; i++) + if (g_eeprom.config.setting.fm_channel[i] == g_eeprom.config.setting.fm_radio.selected_frequency) channel = i; // found it in the channel list g_request_display_screen = DISPLAY_FM; @@ -568,16 +564,16 @@ static void FM_Key_MENU(const bool key_pressed, const bool key_held) if (g_fm_scan_state_dir == FM_SCAN_STATE_DIR_OFF) { // not scanning - if (!g_eeprom.fm_channel_mode) + if (g_eeprom.config.setting.fm_radio.channel_mode == 0) { // frequency mode if (g_ask_to_save) { if (channel < 0) { - g_fm_channels[g_fm_channel_position] = g_eeprom.fm_frequency_playing; - g_ask_to_save = false; - g_request_save_fm = true; + g_eeprom.config.setting.fm_channel[g_fm_channel_position] = g_eeprom.config.setting.fm_radio.selected_frequency; + g_ask_to_save = false; + g_request_save_fm = true; } } else @@ -588,10 +584,10 @@ static void FM_Key_MENU(const bool key_pressed, const bool key_held) { // channel mode if (g_ask_to_delete) { - g_fm_channels[g_eeprom.fm_selected_channel] = 0xFFFF; + g_eeprom.config.setting.fm_channel[g_eeprom.config.setting.fm_radio.selected_channel] = 0xFFFF; FM_configure_channel_state(); - BK1080_SetFrequency(g_eeprom.fm_frequency_playing); + BK1080_SetFrequency(g_eeprom.config.setting.fm_radio.selected_frequency); g_request_save_fm = true; g_ask_to_delete = false; @@ -621,7 +617,7 @@ static void FM_Key_MENU(const bool key_pressed, const bool key_held) if (g_ask_to_save) { - g_fm_channels[g_fm_channel_position] = g_eeprom.fm_frequency_playing; + g_eeprom.config.setting.fm_channel[g_fm_channel_position] = g_eeprom.config.setting.fm_radio.selected_frequency; g_ask_to_save = false; g_request_save_fm = true; return; @@ -664,32 +660,32 @@ static void FM_Key_UP_DOWN(const bool key_pressed, const bool key_held, const fm if (g_fm_auto_scan) return; - FM_tune(g_eeprom.fm_frequency_playing, scan_state_dir, false); + FM_tune(g_eeprom.config.setting.fm_radio.selected_frequency, scan_state_dir, false); g_request_display_screen = DISPLAY_FM; return; } - if (g_eeprom.fm_channel_mode) + if (g_eeprom.config.setting.fm_radio.channel_mode != 0) { // we're in channel mode - const uint8_t Channel = FM_find_next_channel(g_eeprom.fm_selected_channel + scan_state_dir, scan_state_dir); - if (Channel == 0xFF || g_eeprom.fm_selected_channel == Channel) + const uint8_t Channel = FM_find_next_channel(g_eeprom.config.setting.fm_radio.selected_channel + scan_state_dir, scan_state_dir); + if (Channel == 0xFF || g_eeprom.config.setting.fm_radio.selected_channel == Channel) goto Bail; - g_eeprom.fm_selected_channel = Channel; - g_eeprom.fm_frequency_playing = g_fm_channels[Channel]; + g_eeprom.config.setting.fm_radio.selected_channel = Channel; + g_eeprom.config.setting.fm_radio.selected_frequency = g_eeprom.config.setting.fm_channel[Channel]; } else { // no, frequency mode - uint16_t Frequency = g_eeprom.fm_selected_frequency + scan_state_dir; + uint16_t Frequency = g_eeprom.config.setting.fm_radio.selected_frequency + scan_state_dir; if (Frequency < BK1080_freq_lower) Frequency = BK1080_freq_upper - 1u; else if (Frequency >= BK1080_freq_upper) Frequency = BK1080_freq_lower; - g_eeprom.fm_frequency_playing = Frequency; - g_eeprom.fm_selected_frequency = g_eeprom.fm_frequency_playing; + g_eeprom.config.setting.fm_radio.selected_frequency = Frequency; +// g_eeprom.config.setting.fm_radio.selected_frequency = g_eeprom.fm_frequency_playing; } if (g_current_display_screen == DISPLAY_FM && g_fm_scan_state_dir == FM_SCAN_STATE_DIR_OFF) @@ -704,7 +700,7 @@ static void FM_Key_UP_DOWN(const bool key_pressed, const bool key_held, const fm g_request_save_fm = true; Bail: - BK1080_SetFrequency(g_eeprom.fm_frequency_playing); + BK1080_SetFrequency(g_eeprom.config.setting.fm_radio.selected_frequency); g_request_display_screen = DISPLAY_FM; } diff --git a/app/fm.h b/app/fm.h index 9d3f922..62e1771 100644 --- a/app/fm.h +++ b/app/fm.h @@ -29,7 +29,6 @@ enum fm_scan_state_dir_e { }; typedef enum fm_scan_state_dir_e fm_scan_state_dir_t; -extern uint16_t g_fm_channels[20]; extern bool g_fm_radio_mode; extern fm_scan_state_dir_t g_fm_scan_state_dir; extern bool g_fm_auto_scan; diff --git a/app/generic.c b/app/generic.c index aead342..1c9e81a 100644 --- a/app/generic.c +++ b/app/generic.c @@ -56,10 +56,10 @@ void GENERIC_Key_F(bool key_pressed, bool key_held) { // toggle the keyboad lock #ifdef ENABLE_VOICE - g_another_voice_id = g_eeprom.key_lock ? VOICE_ID_UNLOCK : VOICE_ID_LOCK; + g_another_voice_id = g_eeprom.config.setting.key_lock ? VOICE_ID_UNLOCK : VOICE_ID_LOCK; #endif - g_eeprom.key_lock = !g_eeprom.key_lock; + g_eeprom.config.setting.key_lock = (g_eeprom.key_lock + 1) & 1u; g_request_save_settings = true; g_update_status = true; @@ -113,10 +113,10 @@ void GENERIC_Key_PTT(bool key_pressed) { APP_end_tx(); - if (g_eeprom.repeater_tail_tone_elimination == 0) + if (g_eeprom.config.setting.repeater_tail_tone_elimination == 0) FUNCTION_Select(FUNCTION_FOREGROUND); else - g_rtte_count_down = g_eeprom.repeater_tail_tone_elimination * 10; + g_rtte_count_down = g_eeprom.config.setting.repeater_tail_tone_elimination * 10; } g_flag_end_tx = false; @@ -147,7 +147,7 @@ void GENERIC_Key_PTT(bool key_pressed) if (g_current_display_screen == DISPLAY_SEARCH) { // CTCSS/CDCSS scanning .. stop - g_eeprom.cross_vfo_rx_tx = g_backup_cross_vfo_rx_tx; + g_eeprom.config.setting.cross_vfo = g_backup_cross_vfo; g_search_flag_stop_scan = true; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; g_flag_reset_vfos = true; diff --git a/app/main.c b/app/main.c index 0041824..9444a00 100644 --- a/app/main.c +++ b/app/main.c @@ -47,7 +47,7 @@ bool g_manual_scanning; 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.config.setting.dual_watch != DUAL_WATCH_OFF) && g_scan_pause_tick_10ms > 0 && g_scan_pause_tick_10ms <= (200 / 10)) { // scanning isn't paused return false; @@ -105,9 +105,9 @@ void toggle_chan_scanlist(void) void MAIN_copy_mem_vfo_mem(void) { //const unsigned int vfo = get_RX_VFO(); - const unsigned int vfo = g_eeprom.tx_vfo; + const unsigned int vfo = g_eeprom.config.setting.tx_vfo_num; - if (g_css_scan_mode != CSS_SCAN_MODE_OFF || !g_eeprom.vfo_open) + if (g_css_scan_mode != CSS_SCAN_MODE_OFF || g_eeprom.config.setting.vfo_open == 0) { // scanning or VFO disabled g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; return; @@ -119,14 +119,14 @@ void toggle_chan_scanlist(void) return; } - if (IS_USER_CHANNEL(g_eeprom.screen_channel[vfo])) + if (IS_USER_CHANNEL(g_eeprom.config.setting.indices.vfo[vfo].screen)) { // copy channel to VFO, then swap to the VFO - const unsigned int channel = FREQ_CHANNEL_FIRST + g_eeprom.vfo_info[vfo].band; + const unsigned int channel = FREQ_CHANNEL_FIRST + g_vfo_info[vfo].band; - g_eeprom.screen_channel[vfo] = channel; - g_eeprom.vfo_info[vfo].channel_save = channel; - g_eeprom.tx_vfo = vfo; + g_eeprom.config.setting.indices.vfo[vfo].screen = channel; + g_vfo_info[vfo].channel_save = channel; + g_eeprom.config.setting.tx_vfo_num = vfo; RADIO_select_vfos(); RADIO_ApplyOffset(g_tx_vfo, false); @@ -135,9 +135,9 @@ void toggle_chan_scanlist(void) RADIO_setup_registers(true); // find the first channel that contains this frequency - g_tx_vfo->freq_in_channel = BOARD_find_channel(g_tx_vfo->freq_config_tx.frequency); + g_tx_vfo->freq_in_channel = SETTINGS_find_channel(g_tx_vfo->freq_config_tx.frequency); - SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, 1); + SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, 1); #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) UART_printf("chan-vfo %u\r\n", g_tx_vfo->channel_save); @@ -150,14 +150,14 @@ void toggle_chan_scanlist(void) g_update_display = true; } else - if (IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[vfo])) + if (IS_NOT_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[vfo].screen)) { // copy VFO to a channel // search the channels to see if the frequency is already present - unsigned int chan = BOARD_find_channel(g_eeprom.vfo_info[vfo].p_tx->frequency); + unsigned int chan = SETTINGS_find_channel(g_vfo_info[vfo].p_tx->frequency); if (chan > USER_CHANNEL_LAST) { // not found - find next free channel to save too - //for (chan = g_eeprom.screen_channel[vfo]; chan <= USER_CHANNEL_LAST; chan++) + //for (chan = g_eeprom.config.setting.indices.vfo[vfo].screen; chan <= USER_CHANNEL_LAST; chan++) for (chan = 0; chan <= USER_CHANNEL_LAST; chan++) if (!RADIO_CheckValidChannel(chan, false, vfo)) break; @@ -192,7 +192,7 @@ void toggle_chan_scanlist(void) void processFKeyFunction(const key_code_t Key) { uint8_t Band; - uint8_t Vfo = g_eeprom.tx_vfo; + uint8_t vfo = g_eeprom.config.setting.tx_vfo_num; if (g_current_function == FUNCTION_TRANSMIT || g_current_display_screen == DISPLAY_MENU) { @@ -243,7 +243,7 @@ void processFKeyFunction(const key_code_t Key) APP_stop_scan(); Band = g_tx_vfo->band + 1; - if (g_setting_350_enable || Band != BAND5_350MHz) + if (g_eeprom.config.setting.enable_350 || Band != BAND5_350MHz) { if (Band > BAND7_470MHz) Band = BAND1_50MHz; // wrap-a-round @@ -252,8 +252,8 @@ void processFKeyFunction(const key_code_t Key) Band = BAND6_400MHz; // jump to next band g_tx_vfo->band = Band; - g_eeprom.screen_channel[Vfo] = FREQ_CHANNEL_FIRST + Band; - g_eeprom.freq_channel[Vfo] = FREQ_CHANNEL_FIRST + Band; + g_eeprom.config.setting.indices.vfo[vfo].screen = FREQ_CHANNEL_FIRST + Band; + g_eeprom.config.setting.indices.vfo[vfo].frequency = FREQ_CHANNEL_FIRST + Band; g_request_save_vfo = true; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; @@ -265,19 +265,19 @@ void processFKeyFunction(const key_code_t Key) APP_stop_scan(); - if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_CHAN_A) - g_eeprom.cross_vfo_rx_tx = CROSS_BAND_CHAN_B; + if (g_eeprom.config.setting.cross_vfo == CROSS_BAND_CHAN_A) + g_eeprom.config.setting.cross_vfo = CROSS_BAND_CHAN_B; else - if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_CHAN_B) - g_eeprom.cross_vfo_rx_tx = CROSS_BAND_CHAN_A; + if (g_eeprom.config.setting.cross_vfo == CROSS_BAND_CHAN_B) + g_eeprom.config.setting.cross_vfo = CROSS_BAND_CHAN_A; else - if (g_eeprom.dual_watch == DUAL_WATCH_CHAN_A) - g_eeprom.dual_watch = DUAL_WATCH_CHAN_B; + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_CHAN_A) + g_eeprom.config.setting.dual_watch = DUAL_WATCH_CHAN_B; else - if (g_eeprom.dual_watch == DUAL_WATCH_CHAN_B) - g_eeprom.dual_watch = DUAL_WATCH_CHAN_A; + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_CHAN_B) + g_eeprom.config.setting.dual_watch = DUAL_WATCH_CHAN_A; else - g_eeprom.tx_vfo = (Vfo + 1) & 1u; + g_eeprom.config.setting.tx_vfo_num = (vfo + 1) & 1u; g_request_save_settings = 1; g_flag_reconfigure_vfos = true; @@ -289,13 +289,13 @@ void processFKeyFunction(const key_code_t Key) APP_stop_scan(); - if (g_eeprom.vfo_open && IS_NOT_NOAA_CHANNEL(g_tx_vfo->channel_save)) + if (g_eeprom.config.setting.vfo_open > 0 && IS_NOT_NOAA_CHANNEL(g_tx_vfo->channel_save)) { uint8_t Channel; if (IS_USER_CHANNEL(g_tx_vfo->channel_save)) { // swap to frequency mode - g_eeprom.screen_channel[Vfo] = g_eeprom.freq_channel[g_eeprom.tx_vfo]; + g_eeprom.config.setting.indices.vfo[vfo].screen = g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].frequency; #ifdef ENABLE_VOICE g_another_voice_id = VOICE_ID_FREQUENCY_MODE; @@ -306,10 +306,10 @@ void processFKeyFunction(const key_code_t Key) break; } - Channel = RADIO_FindNextChannel(g_eeprom.user_channel[g_eeprom.tx_vfo], 1, false, 0); + Channel = RADIO_FindNextChannel(g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].user, 1, false, 0); if (Channel != 0xFF) { // swap to channel mode - g_eeprom.screen_channel[Vfo] = Channel; + g_eeprom.config.setting.indices.vfo[vfo].screen= Channel; #ifdef ENABLE_VOICE AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE); @@ -333,8 +333,8 @@ void processFKeyFunction(const key_code_t Key) g_search_flag_start_scan = true; g_search_single_frequency = false; - g_backup_cross_vfo_rx_tx = g_eeprom.cross_vfo_rx_tx; - g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF; + g_backup_cross_vfo = g_eeprom.config.setting.cross_vfo; + g_eeprom.config.setting.cross_vfo = CROSS_BAND_OFF; break; case KEY_5: // NOAA @@ -345,11 +345,11 @@ void processFKeyFunction(const key_code_t Key) if (IS_NOT_NOAA_CHANNEL(g_tx_vfo->channel_save)) { - g_eeprom.screen_channel[Vfo] = g_eeprom.noaa_channel[g_eeprom.tx_vfo]; + g_eeprom.config.setting.indices.vfo[vfo].screen = g_eeprom.config.setting.indices.noaa_channel[g_eeprom.config.setting.tx_vfo_num]; } else { - g_eeprom.screen_channel[Vfo] = g_eeprom.freq_channel[g_eeprom.tx_vfo]; + g_eeprom.config.setting.indices.vfo[vfo].screen = g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].frequency; #ifdef ENABLE_VOICE g_another_voice_id = VOICE_ID_FREQUENCY_MODE; @@ -404,7 +404,7 @@ void processFKeyFunction(const key_code_t Key) case KEY_9: // CALL - if (!RADIO_CheckValidChannel(g_eeprom2.config.call1, false, 0)) + if (!RADIO_CheckValidChannel(g_eeprom.config.setting.call1, false, 0)) { g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; return; @@ -414,13 +414,13 @@ void processFKeyFunction(const key_code_t Key) APP_stop_scan(); - g_eeprom.user_channel[Vfo] = g_eeprom2.config.call1; - g_eeprom.screen_channel[Vfo] = g_eeprom2.config.call1; + g_eeprom.config.setting.indices.vfo[vfo].user = g_eeprom.config.setting.call1; + g_eeprom.config.setting.indices.vfo[vfo].screen = g_eeprom.config.setting.call1; #ifdef ENABLE_VOICE AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE); - AUDIO_SetDigitVoice(1, 1 + g_eeprom2.config.call1); - g_another_voice_id = (voice_id_t)0xFE; + AUDIO_SetDigitVoice(1, 1 + g_eeprom.config.setting.call1); + g_another_voice_id = (voice_id_t)0xFE; #endif g_request_save_vfo = true; @@ -436,6 +436,8 @@ void processFKeyFunction(const key_code_t Key) void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) { + const uint8_t vfo = g_eeprom.config.setting.tx_vfo_num; + g_key_input_count_down = key_input_timeout_500ms; if (key_held) @@ -477,8 +479,6 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) return; } - const uint8_t Vfo = g_eeprom.tx_vfo; - if (g_scan_state_dir != SCAN_STATE_DIR_OFF || g_current_function == FUNCTION_TRANSMIT) { g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; @@ -520,8 +520,8 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) g_another_voice_id = (voice_id_t)Key; #endif - g_eeprom.user_channel[Vfo] = (uint8_t)Channel; - g_eeprom.screen_channel[Vfo] = (uint8_t)Channel; + g_eeprom.config.setting.indices.vfo[vfo].user = (uint8_t)Channel; + g_eeprom.config.setting.indices.vfo[vfo].screen = (uint8_t)Channel; g_request_save_vfo = true; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; @@ -568,13 +568,13 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) if (g_tx_vfo->band != band) { - g_tx_vfo->band = band; - g_eeprom.screen_channel[Vfo] = band + FREQ_CHANNEL_FIRST; - g_eeprom.freq_channel[Vfo] = band + FREQ_CHANNEL_FIRST; + g_tx_vfo->band = band; + g_eeprom.config.setting.indices.vfo[vfo].screen = band + FREQ_CHANNEL_FIRST; + g_eeprom.config.setting.indices.vfo[vfo].frequency = band + FREQ_CHANNEL_FIRST; SETTINGS_save_vfo_indices(); - RADIO_configure_channel(Vfo, VFO_CONFIGURE_RELOAD); + RADIO_configure_channel(vfo, VFO_CONFIGURE_RELOAD); } Frequency += g_tx_vfo->step_freq / 2; // for rounding to nearest step size @@ -590,7 +590,7 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) g_tx_vfo->freq_config_tx.frequency = Frequency; // find the first channel that contains this frequency - g_tx_vfo->freq_in_channel = BOARD_find_channel(Frequency); + g_tx_vfo->freq_in_channel = SETTINGS_find_channel(Frequency); g_request_save_channel = 1; g_vfo_configure_mode = VFO_CONFIGURE; @@ -610,7 +610,7 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) if (g_input_box_index != 2) { #ifdef ENABLE_VOICE - g_another_voice_id = (voice_id_t)Key; + g_another_voice_id = (voice_id_t)Key; #endif // g_request_display_screen = DISPLAY_MAIN; return; @@ -621,15 +621,15 @@ 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_update_display = true; + g_eeprom.config.setting.indices.noaa_channel[vfo] = Channel; + g_eeprom.config.setting.indices.vfo[vfo].screen = Channel; + g_request_save_vfo = true; + g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; + g_update_display = true; return; } } @@ -845,8 +845,8 @@ void MAIN_Key_STAR(bool key_pressed, bool key_held) // 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_backup_cross_vfo = g_eeprom.config.setting.cross_vfo; + g_eeprom.config.setting.cross_vfo = CROSS_BAND_OFF; } g_ptt_was_released = true; @@ -860,7 +860,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio static bool monitor_was_enabled = false; #endif - uint8_t Channel = g_eeprom.screen_channel[g_eeprom.tx_vfo]; + uint8_t Channel = g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].screen; if (key_pressed && !key_held) { // key just pressed @@ -886,9 +886,9 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio g_tx_vfo->freq_config_tx.frequency = g_tx_vfo->freq_config_rx.frequency; // find the first channel that contains this frequency - g_tx_vfo->freq_in_channel = BOARD_find_channel(g_tx_vfo->freq_config_rx.frequency); + g_tx_vfo->freq_in_channel = SETTINGS_find_channel(g_tx_vfo->freq_config_rx.frequency); - SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, 1); + SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, 1); RADIO_ApplyOffset(g_tx_vfo, true); @@ -969,7 +969,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio // TODO: include this once we have the entire eeprom loaded // //if (!key_held && key_pressed) - // g_tx_vfo->freq_in_channel = BOARD_find_channel(frequency); + // g_tx_vfo->freq_in_channel = SETTINGS_find_channel(frequency); //else //if (key_held && key_pressed) g_tx_vfo->freq_in_channel = 0xff; @@ -1027,8 +1027,8 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio } #endif - g_eeprom.user_channel[g_eeprom.tx_vfo] = Next; - g_eeprom.screen_channel[g_eeprom.tx_vfo] = Next; + g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].user = Next; + g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].screen = Next; if (!key_held) { @@ -1041,9 +1041,9 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio #ifdef ENABLE_NOAA else { - Channel = NOAA_CHANNEL_FIRST + NUMBER_AddWithWraparound(g_eeprom.screen_channel[g_eeprom.tx_vfo] - NOAA_CHANNEL_FIRST, Direction, 0, 9); - g_eeprom.noaa_channel[g_eeprom.tx_vfo] = Channel; - g_eeprom.screen_channel[g_eeprom.tx_vfo] = Channel; + Channel = NOAA_CHANNEL_FIRST + NUMBER_AddWithWraparound(g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].screen - NOAA_CHANNEL_FIRST, Direction, 0, 9); + g_eeprom.config.setting.indices.noaa_channel[g_eeprom.config.setting.tx_vfo_num] = Channel; + g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].screen = Channel; } #endif diff --git a/app/menu.c b/app/menu.c index 791961b..808edd2 100644 --- a/app/menu.c +++ b/app/menu.c @@ -61,7 +61,7 @@ uint8_t dac_gain; } __attribute__((packed)) misc; - g_eeprom.BK4819_xtal_freq_low = value; + g_eeprom.config.setting.BK4819_xtal_freq_low = value; // radio 1 .. 04 00 46 00 50 00 2C 0E // radio 2 .. 05 00 46 00 50 00 2C 0E @@ -406,7 +406,7 @@ void MENU_AcceptSetting(void) return; case MENU_SQL: - g_eeprom.squelch_level = g_sub_menu_selection; + g_eeprom.config.setting.squelch_level = g_sub_menu_selection; g_vfo_configure_mode = VFO_CONFIGURE; break; @@ -509,7 +509,7 @@ void MENU_AcceptSetting(void) case MENU_SCRAMBLER: g_tx_vfo->scrambling_type = g_sub_menu_selection; #if 0 - if (g_sub_menu_selection > 0 && g_setting_scramble_enable) + if (g_sub_menu_selection > 0 && g_eeprom.config.setting.enable_scrambler) BK4819_EnableScramble(g_sub_menu_selection - 1); else BK4819_DisableScramble(); @@ -525,13 +525,13 @@ void MENU_AcceptSetting(void) case MENU_MEM_SAVE: g_tx_vfo->channel_save = g_sub_menu_selection; #if 0 - g_eeprom.user_channel[0] = g_sub_menu_selection; + g_eeprom.config.setting.indices.vfo[0].user = g_sub_menu_selection; #else - g_eeprom.user_channel[g_eeprom.tx_vfo] = g_sub_menu_selection; + g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].user = g_sub_menu_selection; #endif g_request_save_channel = 2; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; - g_flag_reset_vfos = true; + g_flag_reset_vfos = true; return; case MENU_MEM_NAME: @@ -547,30 +547,30 @@ void MENU_AcceptSetting(void) // save the channel name memset(g_tx_vfo->name, 0, sizeof(g_tx_vfo->name)); memcpy(g_tx_vfo->name, g_edit, 10); - SETTINGS_save_channel(g_sub_menu_selection, g_eeprom.tx_vfo, g_tx_vfo, 3); + SETTINGS_save_channel(g_sub_menu_selection, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, 3); g_flag_reconfigure_vfos = true; return; case MENU_BAT_SAVE: - g_eeprom.battery_save = g_sub_menu_selection; + g_eeprom.config.setting.battery_save_ratio = g_sub_menu_selection; break; #ifdef ENABLE_VOX case MENU_VOX: - g_eeprom.vox_switch = g_sub_menu_selection != 0; - if (g_eeprom.vox_switch) - g_eeprom.vox_level = g_sub_menu_selection - 1; + g_eeprom.config.setting.vox_switch = g_sub_menu_selection != 0; + if (g_eeprom.config.setting.vox_switch) + g_eeprom.config.setting.vox_level = g_sub_menu_selection - 1; g_flag_reconfigure_vfos = true; g_update_status = true; break; #endif case MENU_AUTO_BACKLITE: - g_eeprom.backlight = g_sub_menu_selection; + g_eeprom.config.setting.backlight_time = g_sub_menu_selection; break; case MENU_AUTO_BACKLITE_ON_TX_RX: - g_setting_backlight_on_tx_rx = g_sub_menu_selection; + g_eeprom.config.setting.backlight_on_tx_rx = g_sub_menu_selection; break; #ifdef ENABLE_CONTRAST @@ -581,54 +581,54 @@ void MENU_AcceptSetting(void) #endif case MENU_DUAL_WATCH: -// g_eeprom.dual_watch = g_sub_menu_selection; - g_eeprom.dual_watch = (g_sub_menu_selection > 0) ? 1 + g_eeprom.tx_vfo : DUAL_WATCH_OFF; +// g_eeprom.config.setting.dual_watch = g_sub_menu_selection; + g_eeprom.config.setting.dual_watch = (g_sub_menu_selection > 0) ? 1 + g_eeprom.config.setting.tx_vfo_num : DUAL_WATCH_OFF; g_flag_reconfigure_vfos = true; g_update_status = true; break; case MENU_SCAN_HOLD: - g_eeprom.scan_hold_time_500ms = g_sub_menu_selection; + g_eeprom.config.setting.scan_hold_time = g_sub_menu_selection; break; case MENU_CROSS_VFO: - if (IS_NOAA_CHANNEL(g_eeprom.screen_channel[0])) + if (IS_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[0].screen)) return; - if (IS_NOAA_CHANNEL(g_eeprom.screen_channel[1])) + if (IS_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[1].screen)) return; - g_eeprom.cross_vfo_rx_tx = g_sub_menu_selection; + g_eeprom.config.setting.cross_vfo = g_sub_menu_selection; g_flag_reconfigure_vfos = true; g_update_status = true; break; case MENU_BEEP: - g_eeprom.beep_control = g_sub_menu_selection; + g_eeprom.config.setting.beep_control = g_sub_menu_selection; break; case MENU_TX_TO: - g_eeprom.tx_timeout_timer = g_sub_menu_selection; + g_eeprom.config.setting.tx_timeout = g_sub_menu_selection; break; #ifdef ENABLE_VOICE case MENU_VOICE: - g_eeprom.voice_prompt = g_sub_menu_selection; + g_eeprom.config.setting.voice_prompt = g_sub_menu_selection; g_update_status = true; break; #endif case MENU_SCAN_CAR_RESUME: - g_eeprom.scan_resume_mode = g_sub_menu_selection; + g_eeprom.config.setting.carrier_search_mode = g_sub_menu_selection; break; case MENU_MEM_DISP: - g_eeprom.channel_display_mode = g_sub_menu_selection; + g_eeprom.config.setting.channel_display_mode = g_sub_menu_selection; break; #ifdef ENABLE_KEYLOCK case MENU_AUTO_KEY_LOCK: - g_eeprom.auto_keypad_lock = g_sub_menu_selection; + g_eeprom.config.setting.auto_key_lock = g_sub_menu_selection; g_key_lock_tick_500ms = key_lock_timeout_500ms; break; #endif @@ -648,29 +648,29 @@ void MENU_AcceptSetting(void) return; case MENU_STE: - g_eeprom.tail_note_elimination = g_sub_menu_selection; + g_eeprom.config.setting.tail_tone_elimination = g_sub_menu_selection; break; case MENU_RP_STE: - g_eeprom.repeater_tail_tone_elimination = g_sub_menu_selection; + g_eeprom.config.setting.repeater_tail_tone_elimination = g_sub_menu_selection; break; case MENU_MIC_GAIN: - g_eeprom.mic_sensitivity = g_sub_menu_selection; - g_eeprom.mic_sensitivity_tuning = g_mic_gain_dB_2[g_eeprom.mic_sensitivity]; - BK4819_set_mic_gain(g_eeprom.mic_sensitivity_tuning); + g_eeprom.config.setting.mic_sensitivity = g_sub_menu_selection; + g_mic_sensitivity_tuning = g_mic_gain_dB_2[g_eeprom.config.setting.mic_sensitivity]; + BK4819_set_mic_gain(g_mic_sensitivity_tuning); g_flag_reconfigure_vfos = true; break; #ifdef ENABLE_TX_AUDIO_BAR case MENU_TX_BAR: - g_setting_mic_bar = g_sub_menu_selection; + g_eeprom.config.setting.mic_bar = g_sub_menu_selection; break; #endif #ifdef ENABLE_RX_SIGNAL_BAR case MENU_RX_BAR: - g_setting_rssi_bar = g_sub_menu_selection; + g_eeprom.config.setting.enable_rssi_bar = g_sub_menu_selection; break; #endif @@ -679,39 +679,39 @@ void MENU_AcceptSetting(void) #if 1 g_request_save_channel = 1; #else - SETTINGS_save_channel(g_sub_menu_selection, g_eeprom.tx_vfo, g_tx_vfo, 3); + SETTINGS_save_channel(g_sub_menu_selection, g_eeprom.config.setting.tx_vfo_num, g_tx_vfo, 3); g_flag_reconfigure_vfos = true; #endif return; case MENU_1_CALL: - g_eeprom2.config.call1 = g_sub_menu_selection; + g_eeprom.config.setting.call1 = g_sub_menu_selection; break; case MENU_S_LIST: - g_eeprom.scan_list_default = g_sub_menu_selection; + g_eeprom.config.setting.scan_list_default = g_sub_menu_selection; break; #ifdef ENABLE_ALARM case MENU_ALARM_MODE: - g_eeprom.alarm_mode = g_sub_menu_selection; + g_eeprom.config.setting.alarm_mode = g_sub_menu_selection; break; #endif case MENU_DTMF_ST: - g_eeprom.dtmf_side_tone = g_sub_menu_selection; + g_eeprom.config.setting.dtmf.side_tone = g_sub_menu_selection; break; case MENU_DTMF_RSP: - g_eeprom.dtmf_decode_response = g_sub_menu_selection; + g_eeprom.config.setting.dtmf.decode_response = g_sub_menu_selection; break; case MENU_DTMF_HOLD: - g_eeprom.dtmf_auto_reset_time = g_sub_menu_selection; + g_eeprom.config.setting.dtmf.auto_reset_time = g_sub_menu_selection; break; case MENU_DTMF_PRE: - g_eeprom.dtmf_preload_time = g_sub_menu_selection * 10; + g_eeprom.config.setting.dtmf.preload_time = g_sub_menu_selection; break; #ifdef ENABLE_MDC1200 @@ -721,7 +721,7 @@ void MENU_AcceptSetting(void) break; case MENU_MDC1200_ID: - g_eeprom.mdc1200_id = g_sub_menu_selection; + g_eeprom.config.setting.mdc1200_id = g_sub_menu_selection; break; #endif @@ -731,14 +731,14 @@ void MENU_AcceptSetting(void) g_tx_vfo->dtmf_ptt_id_tx_mode == PTT_ID_BOTH || g_tx_vfo->dtmf_ptt_id_tx_mode == PTT_ID_APOLLO) { - g_eeprom.roger_mode = ROGER_MODE_OFF; + g_eeprom.config.setting.roger_mode = ROGER_MODE_OFF; break; } g_request_save_channel = 1; return; case MENU_BAT_TXT: - g_setting_battery_text = g_sub_menu_selection; + g_eeprom.config.setting.battery_text = g_sub_menu_selection; break; case MENU_DTMF_DCD: @@ -748,10 +748,10 @@ void MENU_AcceptSetting(void) return; case MENU_DTMF_LIVE_DEC: - g_setting_live_dtmf_decoder = g_sub_menu_selection; + g_eeprom.config.setting.dtmf_live_decoder = g_sub_menu_selection; g_dtmf_rx_live_timeout = 0; memset(g_dtmf_rx_live, 0, sizeof(g_dtmf_rx_live)); - if (!g_setting_live_dtmf_decoder) + if (!g_eeprom.config.setting.dtmf_live_decoder) BK4819_DisableDTMF(); g_flag_reconfigure_vfos = true; g_update_status = true; @@ -770,12 +770,12 @@ void MENU_AcceptSetting(void) return; case MENU_PON_MSG: - g_eeprom.pwr_on_display_mode = g_sub_menu_selection; + g_eeprom.config.setting.power_on_display_mode = g_sub_menu_selection; break; case MENU_ROGER_MODE: - g_eeprom.roger_mode = g_sub_menu_selection; - if (g_eeprom.roger_mode != ROGER_MODE_OFF) + g_eeprom.config.setting.roger_mode = g_sub_menu_selection; + if (g_eeprom.config.setting.roger_mode != ROGER_MODE_OFF) { if (g_tx_vfo->dtmf_ptt_id_tx_mode == PTT_ID_TX_DOWN || g_tx_vfo->dtmf_ptt_id_tx_mode == PTT_ID_BOTH || @@ -794,7 +794,7 @@ void MENU_AcceptSetting(void) /* #ifdef ENABLE_AM_FIX case MENU_AM_FIX: - g_setting_am_fix = g_sub_menu_selection; + g_eeprom.config.setting.am_fix = g_sub_menu_selection; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; g_flag_reset_vfos = true; break; @@ -802,7 +802,7 @@ void MENU_AcceptSetting(void) */ #ifdef ENABLE_AM_FIX_TEST1 case MENU_AM_FIX_TEST1: - g_setting_am_fix_test1 = g_sub_menu_selection; + g_eeprom.config.setting.am_fix_test1 = g_sub_menu_selection; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; g_flag_reset_vfos = true; break; @@ -810,7 +810,7 @@ void MENU_AcceptSetting(void) #ifdef ENABLE_NOAA case MENU_NOAA_SCAN: - g_eeprom.noaa_auto_scan = g_sub_menu_selection; + g_eeprom.config.setting.noaa_auto_scan = g_sub_menu_selection; g_flag_reconfigure_vfos = true; break; #endif @@ -823,55 +823,55 @@ void MENU_AcceptSetting(void) #ifdef ENABLE_SIDE_BUTT_MENU case MENU_SIDE1_SHORT: - g_eeprom.key1_short_press_action = g_sub_menu_selection; + g_eeprom.config.setting.key1_short = g_sub_menu_selection; break; case MENU_SIDE1_LONG: - g_eeprom.key1_long_press_action = g_sub_menu_selection; + g_eeprom.config.setting.key1_long = g_sub_menu_selection; break; case MENU_SIDE2_SHORT: - g_eeprom.key2_short_press_action = g_sub_menu_selection; + g_eeprom.config.setting.key2_short = g_sub_menu_selection; break; case MENU_SIDE2_LONG: - g_eeprom.key2_long_press_action = g_sub_menu_selection; + g_eeprom.config.setting.key2_long = g_sub_menu_selection; break; #endif case MENU_RESET: - BOARD_FactoryReset(g_sub_menu_selection); + SETTINGS_factory_reset(g_sub_menu_selection); return; case MENU_350_TX: - g_setting_350_tx_enable = g_sub_menu_selection; + g_eeprom.config.setting.enable_tx_350 = g_sub_menu_selection; break; case MENU_FREQ_LOCK: - g_setting_freq_lock = g_sub_menu_selection; + g_eeprom.config.setting.freq_lock = g_sub_menu_selection; break; case MENU_174_TX: - g_setting_174_tx_enable = g_sub_menu_selection; + g_eeprom.config.setting.enable_tx_200 = g_sub_menu_selection; break; case MENU_470_TX: - g_setting_470_tx_enable = g_sub_menu_selection; + g_eeprom.config.setting.enable_tx_470 = g_sub_menu_selection; break; case MENU_350_EN: - g_setting_350_enable = g_sub_menu_selection; + g_eeprom.config.setting.enable_350 = g_sub_menu_selection; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; g_flag_reset_vfos = true; break; case MENU_SCRAMBLER_EN: - g_setting_scramble_enable = g_sub_menu_selection; + g_eeprom.config.setting.enable_scrambler = g_sub_menu_selection; g_flag_reconfigure_vfos = true; break; case MENU_TX_EN: - g_setting_tx_enable = g_sub_menu_selection; + g_eeprom.config.setting.tx_enable = g_sub_menu_selection; break; #ifdef ENABLE_F_CAL_MENU @@ -882,20 +882,15 @@ void MENU_AcceptSetting(void) case MENU_BAT_CAL: { - uint16_t buf[4]; + g_eeprom.calib.battery[0] = (520ul * g_sub_menu_selection) / 760; // 5.20V empty, blinking above this value, reduced functionality below + g_eeprom.calib.battery[1] = (700ul * g_sub_menu_selection) / 760; // 7.00V, ~5%, 1 bars above this value + g_eeprom.calib.battery[2] = (745ul * g_sub_menu_selection) / 760; // 7.45V, ~17%, 2 bars above this value + g_eeprom.calib.battery[3] = g_sub_menu_selection; // 7.6V, ~29%, 3 bars above this value + g_eeprom.calib.battery[4] = (788ul * g_sub_menu_selection) / 760; // 7.88V, ~65%, 4 bars above this value + g_eeprom.calib.battery[5] = 2300; - g_battery_calibration[0] = (520ul * g_sub_menu_selection) / 760; // 5.20V empty, blinking above this value, reduced functionality below - g_battery_calibration[1] = (700ul * g_sub_menu_selection) / 760; // 7.00V, ~5%, 1 bars above this value - g_battery_calibration[2] = (745ul * g_sub_menu_selection) / 760; // 7.45V, ~17%, 2 bars above this value - g_battery_calibration[3] = g_sub_menu_selection; // 7.6V, ~29%, 3 bars above this value - g_battery_calibration[4] = (788ul * g_sub_menu_selection) / 760; // 7.88V, ~65%, 4 bars above this value - g_battery_calibration[5] = 2300; - EEPROM_WriteBuffer8(0x1F40, g_battery_calibration); - - EEPROM_ReadBuffer( 0x1F48, buf, sizeof(buf)); - buf[0] = g_battery_calibration[4]; - buf[1] = g_battery_calibration[5]; - EEPROM_WriteBuffer8(0x1F48, buf); + EEPROM_WriteBuffer8(0x1F40, &g_eeprom.calib.battery[0]); + EEPROM_WriteBuffer8(0x1F48, &g_eeprom.calib.battery[4]); break; } @@ -966,7 +961,7 @@ void MENU_ShowCurrentSetting(void) switch (g_menu_cursor) { case MENU_SQL: - g_sub_menu_selection = g_eeprom.squelch_level; + g_sub_menu_selection = g_eeprom.config.setting.squelch_level; break; case MENU_CHAN_SQL: @@ -1045,35 +1040,35 @@ void MENU_ShowCurrentSetting(void) case MENU_MEM_SAVE: #if 0 - g_sub_menu_selection = g_eeprom.user_channel[0]; + g_sub_menu_selection = g_eeprom.config.setting.indices.vfo[0].user; #else - g_sub_menu_selection = g_eeprom.user_channel[g_eeprom.tx_vfo]; + g_sub_menu_selection = g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].user; #endif break; case MENU_MEM_NAME: - g_sub_menu_selection = g_eeprom.user_channel[g_eeprom.tx_vfo]; + g_sub_menu_selection = g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].user; break; case MENU_BAT_SAVE: - g_sub_menu_selection = g_eeprom.battery_save; + g_sub_menu_selection = g_eeprom.config.setting.battery_save_ratio; break; #ifdef ENABLE_VOX case MENU_VOX: - g_sub_menu_selection = g_eeprom.vox_switch ? g_eeprom.vox_level + 1 : 0; + g_sub_menu_selection = g_eeprom.config.setting.vox_switch ? g_eeprom.config.setting.vox_level + 1 : 0; break; #endif case MENU_AUTO_BACKLITE: - g_sub_menu_selection = g_eeprom.backlight; + g_sub_menu_selection = g_eeprom.config.setting.backlight_time; - g_backlight_count_down = 0; + g_backlight_tick_500ms = 0; GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight ON while in backlight menu break; case MENU_AUTO_BACKLITE_ON_TX_RX: - g_sub_menu_selection = g_setting_backlight_on_tx_rx; + g_sub_menu_selection = g_eeprom.config.setting.backlight_on_tx_rx; break; #ifdef ENABLE_CONTRAST @@ -1083,43 +1078,43 @@ void MENU_ShowCurrentSetting(void) #endif case MENU_DUAL_WATCH: -// g_sub_menu_selection = g_eeprom.dual_watch; - g_sub_menu_selection = (g_eeprom.dual_watch == DUAL_WATCH_OFF) ? 0 : 1; +// g_sub_menu_selection = g_eeprom.config.setting.dual_watch; + g_sub_menu_selection = (g_eeprom.config.setting.dual_watch == DUAL_WATCH_OFF) ? 0 : 1; break; case MENU_SCAN_HOLD: - g_sub_menu_selection = g_eeprom.scan_hold_time_500ms; + g_sub_menu_selection = g_eeprom.config.setting.scan_hold_time; break; case MENU_CROSS_VFO: - g_sub_menu_selection = g_eeprom.cross_vfo_rx_tx; + g_sub_menu_selection = g_eeprom.config.setting.cross_vfo; break; case MENU_BEEP: - g_sub_menu_selection = g_eeprom.beep_control; + g_sub_menu_selection = g_eeprom.config.setting.beep_control; break; case MENU_TX_TO: - g_sub_menu_selection = g_eeprom.tx_timeout_timer; + g_sub_menu_selection = g_eeprom.config.setting.tx_timeout; break; #ifdef ENABLE_VOICE case MENU_VOICE: - g_sub_menu_selection = g_eeprom.voice_prompt; + g_sub_menu_selection = g_eeprom.config.setting.voice_prompt; break; #endif case MENU_SCAN_CAR_RESUME: - g_sub_menu_selection = g_eeprom.scan_resume_mode; + g_sub_menu_selection = g_eeprom.config.setting.carrier_search_mode; break; case MENU_MEM_DISP: - g_sub_menu_selection = g_eeprom.channel_display_mode; + g_sub_menu_selection = g_eeprom.config.setting.channel_display_mode; break; #ifdef ENABLE_KEYLOCK case MENU_AUTO_KEY_LOCK: - g_sub_menu_selection = g_eeprom.auto_keypad_lock; + g_sub_menu_selection = g_eeprom.config.setting.auto_key_lock; break; #endif @@ -1132,26 +1127,26 @@ void MENU_ShowCurrentSetting(void) break; case MENU_STE: - g_sub_menu_selection = g_eeprom.tail_note_elimination; + g_sub_menu_selection = g_eeprom.config.setting.tail_tone_elimination; break; case MENU_RP_STE: - g_sub_menu_selection = g_eeprom.repeater_tail_tone_elimination; + g_sub_menu_selection = g_eeprom.config.setting.repeater_tail_tone_elimination; break; case MENU_MIC_GAIN: - g_sub_menu_selection = g_eeprom.mic_sensitivity; + g_sub_menu_selection = g_eeprom.config.setting.mic_sensitivity; break; #ifdef ENABLE_TX_AUDIO_BAR case MENU_TX_BAR: - g_sub_menu_selection = g_setting_mic_bar; + g_sub_menu_selection = g_eeprom.config.setting.mic_bar; break; #endif #ifdef ENABLE_RX_SIGNAL_BAR case MENU_RX_BAR: - g_sub_menu_selection = g_setting_rssi_bar; + g_sub_menu_selection = g_eeprom.config.setting.enable_rssi_bar; break; #endif @@ -1160,11 +1155,11 @@ void MENU_ShowCurrentSetting(void) return; case MENU_1_CALL: - g_sub_menu_selection = g_eeprom2.config.call1; + g_sub_menu_selection = g_eeprom.config.setting.call1; break; case MENU_S_LIST: - g_sub_menu_selection = g_eeprom.scan_list_default; + g_sub_menu_selection = g_eeprom.config.setting.scan_list_default; break; case MENU_SLIST1: @@ -1177,20 +1172,20 @@ void MENU_ShowCurrentSetting(void) #ifdef ENABLE_ALARM case MENU_ALARM_MODE: - g_sub_menu_selection = g_eeprom.alarm_mode; + g_sub_menu_selection = g_eeprom.config.setting.alarm_mode; break; #endif case MENU_DTMF_ST: - g_sub_menu_selection = g_eeprom.dtmf_side_tone; + g_sub_menu_selection = g_eeprom.config.setting.dtmf.side_tone; break; case MENU_DTMF_RSP: - g_sub_menu_selection = g_eeprom.dtmf_decode_response; + g_sub_menu_selection = g_eeprom.config.setting.dtmf.decode_response; break; case MENU_DTMF_HOLD: - g_sub_menu_selection = g_eeprom.dtmf_auto_reset_time; + g_sub_menu_selection = g_eeprom.config.setting.dtmf.auto_reset_time; if (g_sub_menu_selection <= DTMF_HOLD_MIN) g_sub_menu_selection = DTMF_HOLD_MIN; @@ -1218,7 +1213,7 @@ void MENU_ShowCurrentSetting(void) break; case MENU_DTMF_PRE: - g_sub_menu_selection = g_eeprom.dtmf_preload_time / 10; + g_sub_menu_selection = g_eeprom.config.setting.dtmf.preload_time; break; #ifdef ENABLE_MDC1200 @@ -1227,7 +1222,7 @@ void MENU_ShowCurrentSetting(void) break; case MENU_MDC1200_ID: - g_sub_menu_selection = g_eeprom.mdc1200_id; + g_sub_menu_selection = g_eeprom.config.setting.mdc1200_id; break; #endif @@ -1236,7 +1231,7 @@ void MENU_ShowCurrentSetting(void) break; case MENU_BAT_TXT: - g_sub_menu_selection = g_setting_battery_text; + g_sub_menu_selection = g_eeprom.config.setting.battery_text; return; case MENU_DTMF_DCD: @@ -1248,15 +1243,15 @@ void MENU_ShowCurrentSetting(void) break; case MENU_DTMF_LIVE_DEC: - g_sub_menu_selection = g_setting_live_dtmf_decoder; + g_sub_menu_selection = g_eeprom.config.setting.dtmf_live_decoder; break; case MENU_PON_MSG: - g_sub_menu_selection = g_eeprom.pwr_on_display_mode; + g_sub_menu_selection = g_eeprom.config.setting.power_on_display_mode; break; case MENU_ROGER_MODE: - g_sub_menu_selection = g_eeprom.roger_mode; + g_sub_menu_selection = g_eeprom.config.setting.roger_mode; break; case MENU_MOD_MODE: @@ -1265,84 +1260,84 @@ void MENU_ShowCurrentSetting(void) /* #ifdef ENABLE_AM_FIX case MENU_AM_FIX: - g_sub_menu_selection = g_setting_am_fix; + g_sub_menu_selection = g_eeprom.config.setting.am_fix; break; #endif */ #ifdef ENABLE_AM_FIX_TEST1 case MENU_AM_FIX_TEST1: - g_sub_menu_selection = g_setting_am_fix_test1; + g_sub_menu_selection = g_eeprom.config.setting.am_fix_test1; break; #endif #ifdef ENABLE_NOAA case MENU_NOAA_SCAN: - g_sub_menu_selection = g_eeprom.noaa_auto_scan; + g_sub_menu_selection = g_eeprom.config.setting.noaa_auto_scan; break; #endif case MENU_MEM_DEL: #if 0 - g_sub_menu_selection = RADIO_FindNextChannel(g_eeprom.user_channel[0], 1, false, 1); + g_sub_menu_selection = RADIO_FindNextChannel(g_eeprom.config.setting.indices.vfo[0].user, 1, false, 1); #else - g_sub_menu_selection = RADIO_FindNextChannel(g_eeprom.user_channel[g_eeprom.tx_vfo], 1, false, 1); + g_sub_menu_selection = RADIO_FindNextChannel(g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].user, 1, false, 1); #endif break; #ifdef ENABLE_SIDE_BUTT_MENU case MENU_SIDE1_SHORT: - g_sub_menu_selection = g_eeprom.key1_short_press_action; + g_sub_menu_selection = g_eeprom.config.setting.key1_short; break; case MENU_SIDE1_LONG: - g_sub_menu_selection = g_eeprom.key1_long_press_action; + g_sub_menu_selection = g_eeprom.config.setting.key1_long; break; case MENU_SIDE2_SHORT: - g_sub_menu_selection = g_eeprom.key2_short_press_action; + g_sub_menu_selection = g_eeprom.config.setting.key2_short; break; case MENU_SIDE2_LONG: - g_sub_menu_selection = g_eeprom.key2_long_press_action; + g_sub_menu_selection = g_eeprom.config.setting.key2_long; break; #endif case MENU_350_TX: - g_sub_menu_selection = g_setting_350_tx_enable; + g_sub_menu_selection = g_eeprom.config.setting.enable_tx_350; break; case MENU_FREQ_LOCK: - g_sub_menu_selection = g_setting_freq_lock; + g_sub_menu_selection = g_eeprom.config.setting.freq_lock; break; case MENU_174_TX: - g_sub_menu_selection = g_setting_174_tx_enable; + g_sub_menu_selection = g_eeprom.config.setting.enable_tx_200; break; case MENU_470_TX: - g_sub_menu_selection = g_setting_470_tx_enable; + g_sub_menu_selection = g_eeprom.config.setting.enable_tx_470; break; case MENU_350_EN: - g_sub_menu_selection = g_setting_350_enable; + g_sub_menu_selection = g_eeprom.config.setting.enable_350; break; case MENU_SCRAMBLER_EN: - g_sub_menu_selection = g_setting_scramble_enable; + g_sub_menu_selection = g_eeprom.config.setting.enable_scrambler; break; case MENU_TX_EN: - g_sub_menu_selection = g_setting_tx_enable; + g_sub_menu_selection = g_eeprom.config.setting.tx_enable; break; #ifdef ENABLE_F_CAL_MENU case MENU_F_CALI: - g_sub_menu_selection = g_eeprom.BK4819_xtal_freq_low; + g_sub_menu_selection = g_eeprom.config.setting.BK4819_xtal_freq_low; break; #endif case MENU_BAT_CAL: - g_sub_menu_selection = g_battery_calibration[3]; + g_sub_menu_selection = g_eeprom.calib.battery[3]; break; default: @@ -1599,9 +1594,9 @@ static void MENU_Key_EXIT(bool key_pressed, bool key_held) g_request_display_screen = DISPLAY_MAIN; - if (g_eeprom.backlight == 0) + if (g_eeprom.config.setting.backlight_time == 0) { - g_backlight_count_down = 0; + g_backlight_tick_500ms = 0; GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF } } @@ -1659,7 +1654,7 @@ static void MENU_Key_MENU(const bool key_pressed, const bool key_held) if (!RADIO_CheckValidChannel(g_sub_menu_selection, false, 0)) return; - BOARD_fetchChannelName(g_edit, g_sub_menu_selection); + SETTINGS_fetch_channel_name(g_edit, g_sub_menu_selection); // pad the channel name out with '_' g_edit_index = strlen(g_edit); @@ -1877,9 +1872,9 @@ static void MENU_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Direction) g_request_display_screen = DISPLAY_MENU; - if (g_menu_cursor != MENU_AUTO_BACKLITE && g_eeprom.backlight == 0) + if (g_menu_cursor != MENU_AUTO_BACKLITE && g_eeprom.config.setting.backlight_time == 0) { - g_backlight_count_down = 0; + g_backlight_tick_500ms = 0; GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF } diff --git a/app/search.c b/app/search.c index 365231e..9f8d1c1 100644 --- a/app/search.c +++ b/app/search.c @@ -112,7 +112,7 @@ static void SEARCH_Key_EXIT(bool key_pressed, bool key_held) switch (g_search_edit_state) { case SEARCH_EDIT_STATE_NONE: - g_eeprom.cross_vfo_rx_tx = g_backup_cross_vfo_rx_tx; + g_eeprom.config.setting.cross_vfo = g_backup_cross_vfo; g_update_status = true; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; g_flag_reset_vfos = true; @@ -184,7 +184,7 @@ static void SEARCH_Key_MENU(bool key_pressed, bool key_held) // determine what the current step size is for the detected frequency // use the 7 VFO channels/bands to determine it const unsigned int band = (unsigned int)FREQUENCY_GetBand(g_search_frequency); - g_search_step_setting = BOARD_fetchFrequencyStepSetting(band, g_eeprom.tx_vfo); + g_search_step_setting = SETTINGS_fetch_frequency_step_setting(band, g_eeprom.config.setting.tx_vfo_num); { // round to nearest step size const uint16_t step_size = STEP_FREQ_TABLE[g_search_step_setting]; g_search_frequency = ((g_search_frequency + (step_size / 2)) / step_size) * step_size; @@ -268,16 +268,16 @@ static void SEARCH_Key_MENU(bool key_pressed, bool key_held) if (g_tx_vfo->channel_save <= USER_CHANNEL_LAST) { Channel = g_search_channel; - g_eeprom.user_channel[g_eeprom.tx_vfo] = Channel; + g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].user = Channel; } else { Channel = FREQ_CHANNEL_FIRST + g_tx_vfo->band; - g_eeprom.freq_channel[g_eeprom.tx_vfo] = Channel; + g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].frequency = Channel; } g_tx_vfo->channel_save = Channel; - g_eeprom.screen_channel[g_eeprom.tx_vfo] = Channel; + g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].screen = Channel; g_request_save_channel = 2; #ifdef ENABLE_VOICE @@ -619,7 +619,7 @@ void SEARCH_Start(void) RADIO_setup_registers(true); #ifdef ENABLE_NOAA - g_is_noaa_mode = false; + g_noaa_mode = false; #endif if (g_search_single_frequency) diff --git a/app/uart.c b/app/uart.c index 73ec176..bdce871 100644 --- a/app/uart.c +++ b/app/uart.c @@ -210,7 +210,7 @@ static void SendVersion(void) reply.Header.ID = 0x0515; reply.Header.Size = sizeof(reply.Data); memcpy(reply.Data.Version, Version_str, slen); - reply.Data.has_custom_aes_key = g_has_custom_aes_key; + reply.Data.has_custom_aes_key = g_has_aes_key; reply.Data.password_locked = g_password_locked; reply.Data.Challenge[0] = g_challenge[0]; reply.Data.Challenge[1] = g_challenge[1]; @@ -285,11 +285,12 @@ static void cmd_051B(const uint8_t *pBuffer) reply.Data.Offset = addr; reply.Data.Size = size; -// if (g_has_custom_aes_key) +// if (g_has_aes_key) // locked = is_locked; // if (!locked) - EEPROM_ReadBuffer(addr, reply.Data.Data, size); +// EEPROM_ReadBuffer(addr, reply.Data.Data, size); + memcpy(reply.Data.Data, ((uint8_t *)&g_eeprom) + addr, size); SendReply(&reply, size + 8); } @@ -303,7 +304,7 @@ static void cmd_051D(const uint8_t *pBuffer) unsigned int size = pCmd->Size; #ifdef INCLUDE_AES bool reload_eeprom = false; - bool locked = g_has_custom_aes_key ? is_locked : g_has_custom_aes_key; + bool locked = g_has_aes_key ? is_locked : g_has_aes_key; #endif reply_051D_t reply; @@ -369,7 +370,7 @@ static void cmd_051D(const uint8_t *pBuffer) #ifdef INCLUDE_AES if (reload_eeprom) - BOARD_eeprom_load(); + SETTINGS_read_eeprom(); #endif } @@ -412,7 +413,7 @@ static void cmd_0529(void) static void cmd_052D(const uint8_t *pBuffer) { cmd_052D_t *pCmd = (cmd_052D_t *)pBuffer; - bool locked = g_has_custom_aes_key; + bool locked = g_has_aes_key; uint32_t response[4]; reply_052D_t reply; @@ -420,8 +421,10 @@ static void cmd_052D(const uint8_t *pBuffer) if (!locked) { + uint32_t aes_key[4]; memcpy((void *)&response, &pCmd->Response, sizeof(response)); // overcome strict compiler warning settings - locked = IsBadChallenge(g_custom_aes_key, g_challenge, response); + memcpy(aes_key, g_eeprom.config.setting.aes_key, sizeof(aes_key)); + locked = IsBadChallenge(aes_key, g_challenge, response); } if (!locked) @@ -459,21 +462,21 @@ static void cmd_052F(const uint8_t *pBuffer) { const cmd_052F_t *pCmd = (const cmd_052F_t *)pBuffer; - g_eeprom.dual_watch = DUAL_WATCH_OFF; - g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF; - g_eeprom.rx_vfo = 0; - g_eeprom.dtmf_side_tone = false; - g_eeprom.vfo_info[0].frequency_reverse = false; - g_eeprom.vfo_info[0].p_rx = &g_eeprom.vfo_info[0].freq_config_rx; - g_eeprom.vfo_info[0].p_tx = &g_eeprom.vfo_info[0].freq_config_tx; - g_eeprom.vfo_info[0].tx_offset_freq_dir = TX_OFFSET_FREQ_DIR_OFF; - g_eeprom.vfo_info[0].dtmf_ptt_id_tx_mode = PTT_ID_OFF; - g_eeprom.vfo_info[0].dtmf_decoding_enable = false; + g_rx_vfo = 0; + g_eeprom.config.setting.dual_watch = DUAL_WATCH_OFF; + g_eeprom.config.setting.cross_vfo = CROSS_BAND_OFF; + g_eeprom.config.setting.dtmf.side_tone = false; + g_vfo_info[0].frequency_reverse = false; + g_vfo_info[0].p_rx = &g_vfo_info[0].freq_config_rx; + g_vfo_info[0].p_tx = &g_vfo_info[0].freq_config_tx; + g_vfo_info[0].tx_offset_freq_dir = TX_OFFSET_FREQ_DIR_OFF; + g_vfo_info[0].dtmf_ptt_id_tx_mode = PTT_ID_OFF; + g_vfo_info[0].dtmf_decoding_enable = false; g_serial_config_tick_500ms = serial_config_tick_500ms; #ifdef ENABLE_NOAA - g_is_noaa_mode = false; + g_noaa_mode = false; #endif if (g_current_function == FUNCTION_POWER_SAVE) diff --git a/audio.c b/audio.c index 4f6cce2..d4279ba 100644 --- a/audio.c +++ b/audio.c @@ -97,7 +97,7 @@ void AUDIO_PlayBeep(beep_type_t Beep) uint16_t ToneFrequency; uint16_t Duration; - if (!g_eeprom.beep_control) + if (g_eeprom.config.setting.beep_control == 0) { // beep not enabled if (Beep != BEEP_880HZ_60MS_TRIPLE_BEEP && Beep != BEEP_500HZ_60MS_DOUBLE_BEEP && @@ -261,7 +261,7 @@ void AUDIO_PlayBeep(beep_type_t Beep) { unsigned int i; - if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF) + if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF) return; GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_VOICE_0); @@ -288,10 +288,10 @@ void AUDIO_PlayBeep(beep_type_t Beep) uint8_t Delay; uint8_t VoiceID = g_voice_id[0]; - if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF || g_voice_write_index == 0) + if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF || g_voice_write_index == 0) goto Bailout; - if (g_eeprom.voice_prompt == VOICE_PROMPT_CHINESE) + if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_CHINESE) { // Chinese if (VoiceID >= ARRAY_SIZE(VoiceClipLengthChinese)) goto Bailout; @@ -371,13 +371,13 @@ void AUDIO_PlayBeep(beep_type_t Beep) void AUDIO_SetVoiceID(uint8_t Index, voice_id_t VoiceID) { - if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF || Index == 0) + if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF || Index == 0) { g_voice_write_index = 0; g_voice_read_index = 0; } - if (g_eeprom.voice_prompt != VOICE_PROMPT_OFF && Index < ARRAY_SIZE(g_voice_id)) + if (g_eeprom.config.setting.voice_prompt != VOICE_PROMPT_OFF && Index < ARRAY_SIZE(g_voice_id)) { g_voice_id[Index] = VoiceID; g_voice_write_index++; @@ -390,13 +390,13 @@ void AUDIO_PlayBeep(beep_type_t Beep) uint8_t Result; uint8_t Count; - if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF || Index == 0) + if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF || Index == 0) { g_voice_write_index = 0; g_voice_read_index = 0; } - if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF) + if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF) return 0; Count = 0; @@ -431,17 +431,17 @@ void AUDIO_PlayBeep(beep_type_t Beep) uint8_t Delay; bool Skip = false; - if (g_eeprom.voice_prompt == VOICE_PROMPT_OFF) + if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_OFF) { g_voice_write_index = 0; g_voice_read_index = 0; return; } - if (g_voice_read_index != g_voice_write_index && g_eeprom.voice_prompt != VOICE_PROMPT_OFF) + if (g_voice_read_index != g_voice_write_index && g_eeprom.config.setting.voice_prompt != VOICE_PROMPT_OFF) { VoiceID = g_voice_id[g_voice_read_index]; - if (g_eeprom.voice_prompt == VOICE_PROMPT_CHINESE) + if (g_eeprom.config.setting.voice_prompt == VOICE_PROMPT_CHINESE) { if (VoiceID < ARRAY_SIZE(VoiceClipLengthChinese)) { diff --git a/bitmaps.c b/bitmaps.c index 6525ec6..9e3b6ec 100644 --- a/bitmaps.c +++ b/bitmaps.c @@ -59,7 +59,7 @@ const uint8_t BITMAP_RX[8] = { __extension__ 0b00000000, __extension__ 0b00111110, - __extension__ 0b01100011, + __extension__ 0b01111111, __extension__ 0b01000001, __extension__ 0b01000001, __extension__ 0b01000001, @@ -94,7 +94,7 @@ const uint8_t BITMAP_RX[8] = __extension__ 0b01000001, __extension__ 0b01000001, __extension__ 0b01000001, - __extension__ 0b01100011, + __extension__ 0b01111111, __extension__ 0b00111110 }; #endif @@ -175,7 +175,7 @@ const uint8_t BITMAP_F_KEY[6] = }; #else // 'XB' (cross-band/cross-VFO) - const uint8_t BITMAP_XB[12] = + const uint8_t BITMAP_XB[11] = { // "XB" __extension__ 0b00000000, __extension__ 0b01100011, @@ -187,18 +187,16 @@ const uint8_t BITMAP_F_KEY[6] = __extension__ 0b01111111, __extension__ 0b01001001, __extension__ 0b01001001, - __extension__ 0b01001001, __extension__ 0b00110110 }; #endif -const uint8_t BITMAP_TDR_RUNNING[12] = +const uint8_t BITMAP_TDR_RUNNING[11] = { // "DW" __extension__ 0b00000000, __extension__ 0b01111111, __extension__ 0b01000001, __extension__ 0b01000001, - __extension__ 0b01000001, __extension__ 0b00111110, __extension__ 0b00000000, __extension__ 0b01111111, @@ -208,14 +206,13 @@ const uint8_t BITMAP_TDR_RUNNING[12] = __extension__ 0b01111111 }; -const uint8_t BITMAP_TDR_HOLDING[12] = +const uint8_t BITMAP_TDR_HOLDING[11] = { // "--" .. DW on hold __extension__ 0b00000000, __extension__ 0b00001000, __extension__ 0b00001000, __extension__ 0b00001000, __extension__ 0b00001000, - __extension__ 0b00001000, __extension__ 0b00000000, __extension__ 0b00001000, __extension__ 0b00001000, @@ -225,14 +222,12 @@ const uint8_t BITMAP_TDR_HOLDING[12] = }; #ifdef ENABLE_VOICE - const uint8_t BITMAP_VOICE_PROMPT[9] = + const uint8_t BITMAP_VOICE_PROMPT[7] = { __extension__ 0b00000000, __extension__ 0b00011000, __extension__ 0b00011000, __extension__ 0b00100100, - __extension__ 0b00100100, - __extension__ 0b01000010, __extension__ 0b01000010, __extension__ 0b11111111, __extension__ 0b00011000 @@ -250,13 +245,12 @@ const uint8_t BITMAP_MONITOR[6] = }; #ifdef ENABLE_FMRADIO - const uint8_t BITMAP_FM[12] = + const uint8_t BITMAP_FM[11] = { // "FM" __extension__ 0b00000000, __extension__ 0b01111111, __extension__ 0b00001001, __extension__ 0b00001001, - __extension__ 0b00001001, __extension__ 0b00000001, __extension__ 0b00000000, __extension__ 0b01111111, @@ -268,7 +262,7 @@ const uint8_t BITMAP_MONITOR[6] = #endif #ifdef ENABLE_NOAA - const uint8_t BITMAP_NOAA[12] = + const uint8_t BITMAP_NOAA[10] = { // "NS" __extension__ 0b00000000, __extension__ 0b01111111, @@ -276,12 +270,9 @@ const uint8_t BITMAP_MONITOR[6] = __extension__ 0b00001000, __extension__ 0b00010000, __extension__ 0b01111111, - __extension__ 0b00000000, __extension__ 0b01000110, __extension__ 0b01001001, - __extension__ 0b01001001, - __extension__ 0b01001001, __extension__ 0b00110001 }; #endif diff --git a/bitmaps.h b/bitmaps.h index 2fb03e2..03a14a0 100644 --- a/bitmaps.h +++ b/bitmaps.h @@ -25,24 +25,24 @@ extern const uint8_t BITMAP_F_KEY[6]; #if 0 extern const uint8_t BITMAP_WX[12]; #else - extern const uint8_t BITMAP_XB[12]; + extern const uint8_t BITMAP_XB[11]; #endif -extern const uint8_t BITMAP_TDR_RUNNING[12]; -extern const uint8_t BITMAP_TDR_HOLDING[12]; +extern const uint8_t BITMAP_TDR_RUNNING[11]; +extern const uint8_t BITMAP_TDR_HOLDING[11]; #ifdef ENABLE_VOICE - extern const uint8_t BITMAP_VOICE_PROMPT[9]; + extern const uint8_t BITMAP_VOICE_PROMPT[7]; #endif extern const uint8_t BITMAP_MONITOR[6]; #ifdef ENABLE_FMRADIO - extern const uint8_t BITMAP_FM[12]; + extern const uint8_t BITMAP_FM[11]; #endif #ifdef ENABLE_NOAA - extern const uint8_t BITMAP_NOAA[12]; + extern const uint8_t BITMAP_NOAA[10]; #endif extern const uint8_t BITMAP_ANTENNA[5]; diff --git a/board.c b/board.c index b86e7f7..5d82198 100644 --- a/board.c +++ b/board.c @@ -44,15 +44,6 @@ #endif #include "ui/menu.h" -static const uint32_t gDefaultFrequencyTable[] = -{ - 14500000, // - 14550000, // - 43300000, // - 43320000, // - 43350000 // -}; - #if defined(ENABLE_OVERLAY) void BOARD_FLASH_Init(void) { @@ -501,499 +492,3 @@ void BOARD_ADC_GetBatteryInfo(uint16_t *pVoltage, uint16_t *pCurrent) *pVoltage = ADC_GetValue(ADC_CH4); *pCurrent = ADC_GetValue(ADC_CH9); } - -void BOARD_Init(void) -{ - BOARD_PORTCON_Init(); - BOARD_GPIO_Init(); - CRC_Init(); - BOARD_ADC_Init(); - ST7565_Init(true); - - #ifdef ENABLE_FMRADIO - BK1080_Init(0, false); - #endif -} - -void BOARD_eeprom_load(void) -{ - unsigned int i; - uint8_t Data[16]; - -// memset(Data, 0, sizeof(Data)); - - // sanity checks - g_eeprom2.config.call1 = IS_USER_CHANNEL(g_eeprom2.config.call1) ? g_eeprom2.config.call1 : USER_CHANNEL_FIRST; - - // 0E70..0E77 - EEPROM_ReadBuffer(0x0E70, Data, 8); -// g_eeprom.chan_1_call = IS_USER_CHANNEL(Data[0]) ? Data[0] : USER_CHANNEL_FIRST; - g_eeprom.squelch_level = (Data[1] < 10) ? Data[1] : 1; - g_eeprom.tx_timeout_timer = (Data[2] < 11) ? Data[2] : 1; - #ifdef ENABLE_NOAA - g_eeprom.noaa_auto_scan = (Data[3] < 2) ? Data[3] : false; - #endif - #ifdef ENABLE_KEYLOCK - g_eeprom.key_lock = (Data[4] < 2) ? Data[4] : false; - #endif - #ifdef ENABLE_VOX - g_eeprom.vox_switch = (Data[5] < 2) ? Data[5] : false; - g_eeprom.vox_level = (Data[6] < 10) ? Data[6] : 1; - #endif - g_eeprom.mic_sensitivity = (Data[7] < 5) ? Data[7] : 4; - - // 0E78..0E7F - EEPROM_ReadBuffer(0x0E78, Data, 8); - #ifdef ENABLE_CONTRAST - g_setting_contrast = (Data[0] > 45) ? 31 : (Data[0] < 26) ? 31 : Data[0]; - #endif - g_eeprom.channel_display_mode = (Data[1] < 4) ? Data[1] : MDF_FREQUENCY; // 4 instead of 3 - extra display mode - g_eeprom.cross_vfo_rx_tx = (Data[2] < 3) ? Data[2] : CROSS_BAND_OFF; - g_eeprom.battery_save = (Data[3] < 5) ? Data[3] : 4; - g_eeprom.dual_watch = (Data[4] < 3) ? Data[4] : DUAL_WATCH_CHAN_A; - g_eeprom.backlight = (Data[5] < ARRAY_SIZE(g_sub_menu_backlight)) ? Data[5] : 3; - g_eeprom.tail_note_elimination = (Data[6] < 2) ? Data[6] : false; - g_eeprom.vfo_open = (Data[7] < 2) ? Data[7] : true; - - // 0E80..0E87 - EEPROM_ReadBuffer(0x0E80, Data, 8); - g_eeprom.screen_channel[0] = IS_VALID_CHANNEL(Data[0]) ? Data[0] : (FREQ_CHANNEL_FIRST + BAND6_400MHz); - g_eeprom.screen_channel[1] = IS_VALID_CHANNEL(Data[3]) ? Data[3] : (FREQ_CHANNEL_FIRST + BAND6_400MHz); - g_eeprom.user_channel[0] = IS_USER_CHANNEL(Data[1]) ? Data[1] : USER_CHANNEL_FIRST; - g_eeprom.user_channel[1] = IS_USER_CHANNEL(Data[4]) ? Data[4] : USER_CHANNEL_FIRST; - g_eeprom.freq_channel[0] = IS_FREQ_CHANNEL(Data[2]) ? Data[2] : (FREQ_CHANNEL_FIRST + BAND6_400MHz); - g_eeprom.freq_channel[1] = IS_FREQ_CHANNEL(Data[5]) ? Data[5] : (FREQ_CHANNEL_FIRST + BAND6_400MHz); - #ifdef ENABLE_NOAA - g_eeprom.noaa_channel[0] = IS_NOAA_CHANNEL(Data[6]) ? Data[6] : NOAA_CHANNEL_FIRST; - g_eeprom.noaa_channel[1] = IS_NOAA_CHANNEL(Data[7]) ? Data[7] : NOAA_CHANNEL_FIRST; - #endif - -#ifdef ENABLE_FMRADIO - { // 0E88..0E8F - struct - { - uint16_t freq; - uint8_t chan; - uint8_t chan_mode; - } __attribute__((packed)) fm; - - EEPROM_ReadBuffer(0x0E88, &fm, sizeof(fm)); - g_eeprom.fm_selected_frequency = (fm.freq >= BK1080_freq_lower && fm.freq < BK1080_freq_upper) ? fm.freq : BK1080_freq_lower; - g_eeprom.fm_selected_channel = fm.chan; - g_eeprom.fm_channel_mode = fm.chan_mode ? true : false; - } - - // 0E40..0E67 - EEPROM_ReadBuffer(0x0E40, g_fm_channels, sizeof(g_fm_channels)); - FM_configure_channel_state(); -#endif - - // 0E90..0E97 - EEPROM_ReadBuffer(0x0E90, Data, 8); - g_eeprom.beep_control = (Data[0] < 2) ? Data[0] : true; - g_eeprom.key1_short_press_action = (Data[1] < ACTION_OPT_LEN) ? Data[1] : ACTION_OPT_MONITOR; - g_eeprom.key1_long_press_action = (Data[2] < ACTION_OPT_LEN) ? Data[2] : ACTION_OPT_FLASHLIGHT; - g_eeprom.key2_short_press_action = (Data[3] < ACTION_OPT_LEN) ? Data[3] : ACTION_OPT_SCAN; - g_eeprom.key2_long_press_action = (Data[4] < ACTION_OPT_LEN) ? Data[4] : ACTION_OPT_NONE; - g_eeprom.scan_resume_mode = (Data[5] < 3) ? Data[5] : SCAN_RESUME_CARRIER; - g_eeprom.auto_keypad_lock = (Data[6] < 2) ? Data[6] : false; - g_eeprom.pwr_on_display_mode = (Data[7] < 4) ? Data[7] : PWR_ON_DISPLAY_MODE_VOLTAGE; - - // 0E98..0E9F - EEPROM_ReadBuffer(0x0E98, Data, 8); - memcpy(&g_eeprom.power_on_password, &Data[0], sizeof(g_eeprom.power_on_password)); - #ifdef ENABLE_MDC1200 - memcpy(&g_eeprom.mdc1200_id, &Data[4], sizeof(g_eeprom.mdc1200_id)); - #endif - - // 0EA0..0EA7 - #ifdef ENABLE_VOICE - EEPROM_ReadBuffer(0x0EA0, Data, 8); - g_eeprom.voice_prompt = (Data[0] < 3) ? Data[0] : VOICE_PROMPT_ENGLISH; - #endif - - { // 0EA8..0EAF - struct { - uint8_t alarm_mode; - uint8_t roger_mode; - uint8_t repeater_tail_tone_elimination; - uint8_t tx_vfo; - uint32_t air_copy_freq; - } __attribute__((packed)) array; - - EEPROM_ReadBuffer(0x0EA8, &array, sizeof(array)); - - #ifdef ENABLE_ALARM - g_eeprom.alarm_mode = (array.alarm_mode < 2) ? array.alarm_mode : true; - #endif - - g_eeprom.roger_mode = (array.roger_mode < 3) ? array.roger_mode : ROGER_MODE_OFF; - g_eeprom.repeater_tail_tone_elimination = (array.repeater_tail_tone_elimination < 11) ? array.repeater_tail_tone_elimination : 0; - g_eeprom.tx_vfo = (array.tx_vfo < 2) ? array.tx_vfo : 0; - - #ifdef ENABLE_AIRCOPY_REMEMBER_FREQ - { - unsigned int i; - for (i = 0; i < ARRAY_SIZE(FREQ_BAND_TABLE); i++) - { - if (array.air_copy_freq >= FREQ_BAND_TABLE[i].lower && array.air_copy_freq < FREQ_BAND_TABLE[i].upper) - { - g_aircopy_freq = array.air_copy_freq; - break; - } - } - } - #endif - } - - // 0ED0..0ED7 - EEPROM_ReadBuffer(0x0ED0, Data, 8); - g_eeprom.dtmf_side_tone = (Data[0] < 2) ? Data[0] : true; - g_eeprom.dtmf_separate_code = DTMF_ValidateCodes((char *)(Data + 1), 1) ? Data[1] : '*'; - g_eeprom.dtmf_group_call_code = DTMF_ValidateCodes((char *)(Data + 2), 1) ? Data[2] : '#'; - g_eeprom.dtmf_decode_response = (Data[3] < 4) ? Data[3] : DTMF_DEC_RESPONSE_RING; - g_eeprom.dtmf_auto_reset_time = (Data[4] <= DTMF_HOLD_MAX) ? Data[4] : (Data[4] >= DTMF_HOLD_MIN) ? Data[4] : DTMF_HOLD_MAX; - g_eeprom.dtmf_preload_time = (Data[5] < 101) ? Data[5] * 10 : 200; - g_eeprom.dtmf_first_code_persist_time = (Data[6] < 101) ? Data[6] * 10 : 70; - g_eeprom.dtmf_hash_code_persist_time = (Data[7] < 101) ? Data[7] * 10 : 70; - - // 0ED8..0EDF - EEPROM_ReadBuffer(0x0ED8, Data, 8); - g_eeprom.dtmf_code_persist_time = (Data[0] < 101) ? Data[0] * 10 : 70; - g_eeprom.dtmf_code_interval_time = (Data[1] < 101) ? Data[1] * 10 : 70; - g_eeprom.permit_remote_kill = (Data[2] < 2) ? Data[2] : false; - - // 0EE0..0EE7 - EEPROM_ReadBuffer(0x0EE0, Data, 8); - if (DTMF_ValidateCodes((char *)Data, 8)) - memcpy(g_eeprom.ani_dtmf_id, Data, sizeof(g_eeprom.power_on_password)); - else - { - memset(g_eeprom.ani_dtmf_id, 0, sizeof(g_eeprom.ani_dtmf_id)); - strcpy(g_eeprom.ani_dtmf_id, "123"); - } - - // 0EE8..0EEF - EEPROM_ReadBuffer(0x0EE8, Data, 8); - if (DTMF_ValidateCodes((char *)Data, 8)) - memcpy(g_eeprom.kill_code, Data, sizeof(g_eeprom.kill_code)); - else - { - memset(g_eeprom.kill_code, 0, sizeof(g_eeprom.kill_code)); - strcpy(g_eeprom.kill_code, "ABCD9"); - } - - // 0EF0..0EF7 - EEPROM_ReadBuffer(0x0EF0, Data, 8); - if (DTMF_ValidateCodes((char *)Data, 8)) - memcpy(g_eeprom.revive_code, Data, sizeof(g_eeprom.revive_code)); - else - { - memset(g_eeprom.revive_code, 0, sizeof(g_eeprom.revive_code)); - strcpy(g_eeprom.revive_code, "9DCBA"); - } - - // 0EF8..0F07 - EEPROM_ReadBuffer(0x0EF8, Data, 16); - if (DTMF_ValidateCodes((char *)Data, 16)) - memcpy(g_eeprom.dtmf_key_up_code, Data, sizeof(g_eeprom.dtmf_key_up_code)); - else - { - memset(g_eeprom.dtmf_key_up_code, 0, sizeof(g_eeprom.dtmf_key_up_code)); - strcpy(g_eeprom.dtmf_key_up_code, "12345"); - } - - // 0F08..0F17 - EEPROM_ReadBuffer(0x0F08, Data, 16); - if (DTMF_ValidateCodes((char *)Data, 16)) - memcpy(g_eeprom.dtmf_key_down_code, Data, sizeof(g_eeprom.dtmf_key_down_code)); - else - { - memset(g_eeprom.dtmf_key_down_code, 0, sizeof(g_eeprom.dtmf_key_down_code)); - strcpy(g_eeprom.dtmf_key_down_code, "54321"); - } - - // 0F18..0F1F - EEPROM_ReadBuffer(0x0F18, Data, 8); -// g_eeprom.scan_list_default = (Data[0] < 2) ? Data[0] : false; - g_eeprom.scan_list_default = (Data[0] < 3) ? Data[0] : false; // we now have 'all' channel scan option - for (i = 0; i < 2; i++) - { - const unsigned int j = 1 + (i * 3); - g_eeprom.scan_list_enabled[i] = (Data[j + 0] < 2) ? Data[j] : false; - g_eeprom.scan_list_priority_ch1[i] = Data[j + 1]; - g_eeprom.scan_list_priority_ch2[i] = Data[j + 2]; - } - - // 0F40..0F47 - EEPROM_ReadBuffer(0x0F40, Data, 8); - g_setting_freq_lock = (Data[0] < FREQ_LOCK_LAST) ? Data[0] : FREQ_LOCK_NORMAL; - g_setting_350_tx_enable = (Data[1] < 2) ? Data[1] : false; // was true - #ifdef ENABLE_KILL_REVIVE - g_setting_radio_disabled = (Data[2] < 2) ? Data[2] : false; - #endif - 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] & (1u << 0)) ? true : false; - #ifdef ENABLE_RX_SIGNAL_BAR - g_setting_rssi_bar = (Data[6] & (1u << 1)) ? true : false; - #endif - g_setting_tx_enable = (Data[7] & (1u << 0)) ? true : false; - g_setting_live_dtmf_decoder = (Data[7] & (1u << 1)) ? true : false; - g_setting_battery_text = (((Data[7] >> 2) & 3u) <= 2) ? (Data[7] >> 2) & 3 : 2; - #ifdef ENABLE_TX_AUDIO_BAR - g_setting_mic_bar = (Data[7] & (1u << 4)) ? true : false; - #endif - #ifdef ENABLE_AM_FIX -// g_setting_am_fix = (Data[7] & (1u << 5)) ? true : false; - #endif - g_setting_backlight_on_tx_rx = (Data[7] >> 6) & 3u; - - // 0F48..0F4F - EEPROM_ReadBuffer(0x0F48, Data, 8); - g_eeprom.scan_hold_time_500ms = (Data[0] > 40) ? 6 : (Data[0] < 2) ? 6 : Data[0]; - - if (!g_eeprom.vfo_open) - { - g_eeprom.screen_channel[0] = g_eeprom.user_channel[0]; - g_eeprom.screen_channel[1] = g_eeprom.user_channel[1]; - } - - // 0D60..0E27 - EEPROM_ReadBuffer(0x0D60, g_user_channel_attributes, sizeof(g_user_channel_attributes)); - - // ***************************** - - // 0F30..0F3F .. AES key - EEPROM_ReadBuffer(0x0F30, g_custom_aes_key, sizeof(g_custom_aes_key)); - g_has_custom_aes_key = false; - for (i = 0; i < ARRAY_SIZE(g_custom_aes_key); i++) - { - if (g_custom_aes_key[i] != 0xFFFFFFFFu) - { - g_has_custom_aes_key = true; - break; - } - } - -#if ENABLE_RESET_AES_KEY - // a fix to wipe the darned AES key - if (g_has_custom_aes_key) - { // ugh :( .. wipe it - uint8_t *p_aes = (uint8_t*)&g_custom_aes_key; - memset(p_aes, 0xff, sizeof(g_custom_aes_key)); - for (i = 0; i < sizeof(g_custom_aes_key); i += 8) - EEPROM_WriteBuffer8(0x0F30 + i, &p_aes[i]); - g_has_custom_aes_key = false; - } -#endif -} - -void BOARD_eeprom_loadCalibration(void) -{ -// uint8_t Mic; - - EEPROM_ReadBuffer(0x1EC0, g_eeprom_rssi_calib[3], 8); - memcpy(g_eeprom_rssi_calib[4], g_eeprom_rssi_calib[3], 8); - memcpy(g_eeprom_rssi_calib[5], g_eeprom_rssi_calib[3], 8); - memcpy(g_eeprom_rssi_calib[6], g_eeprom_rssi_calib[3], 8); - - EEPROM_ReadBuffer(0x1EC8, g_eeprom_rssi_calib[0], 8); - memcpy(g_eeprom_rssi_calib[1], g_eeprom_rssi_calib[0], 8); - memcpy(g_eeprom_rssi_calib[2], g_eeprom_rssi_calib[0], 8); - - EEPROM_ReadBuffer(0x1F40, g_battery_calibration, 12); - if (g_battery_calibration[0] >= 5000) - { - g_battery_calibration[0] = 1900; - g_battery_calibration[1] = 2000; - } - g_battery_calibration[5] = 2300; - - #ifdef ENABLE_VOX - EEPROM_ReadBuffer(0x1F50 + (g_eeprom.vox_level * 2), &g_eeprom.vox1_threshold, 2); - EEPROM_ReadBuffer(0x1F68 + (g_eeprom.vox_level * 2), &g_eeprom.vox0_threshold, 2); - #endif - - //EEPROM_ReadBuffer(0x1F80 + g_eeprom.mic_sensitivity, &Mic, 1); - //g_eeprom.mic_sensitivity_tuning = (Mic < 32) ? Mic : 15; - g_eeprom.mic_sensitivity_tuning = g_mic_gain_dB_2[g_eeprom.mic_sensitivity]; - - { - struct - { - int16_t BK4819_XtalFreqLow; - uint16_t EEPROM_1F8A; - uint16_t EEPROM_1F8C; - uint8_t volume_gain; - uint8_t dac_gain; - } __attribute__((packed)) Misc; - - // radio 1 .. 04 00 46 00 50 00 2C 0E - // radio 2 .. 05 00 46 00 50 00 2C 0E - EEPROM_ReadBuffer(0x1F88, &Misc, 8); - - g_eeprom.BK4819_xtal_freq_low = (Misc.BK4819_XtalFreqLow >= -1000 && Misc.BK4819_XtalFreqLow <= 1000) ? Misc.BK4819_XtalFreqLow : 0; -// g_eeprom_1F8A = Misc.EEPROM_1F8A & 0x01FF; -// g_eeprom_1F8C = Misc.EEPROM_1F8C & 0x01FF; - g_eeprom.volume_gain = (Misc.volume_gain < 64) ? Misc.volume_gain : 58; - g_eeprom.dac_gain = (Misc.dac_gain < 16) ? Misc.dac_gain : 8; - - BK4819_WriteRegister(0x3B, 22656 + g_eeprom.BK4819_xtal_freq_low); -// BK4819_WriteRegister(0x3C, g_eeprom.BK4819_XTAL_FREQ_HIGH); - } -} - -unsigned int BOARD_find_channel(const uint32_t frequency) -{ - unsigned int chan; - - if (frequency == 0 || frequency == 0xffffffff) - return 0xffffffff; - - for (chan = 0; chan <= USER_CHANNEL_LAST; chan++) - { - uint32_t chan_freq; - - if ((g_user_channel_attributes[chan] & USER_CH_BAND_MASK) > BAND7_470MHz) - continue; - - EEPROM_ReadBuffer(chan * 16, &chan_freq, 4); - - if (chan_freq == 0 || chan_freq == 0xffffffff) - continue; - - if (chan_freq == frequency) - return chan; // found it - } - - return 0xffffffff; -} - -uint32_t BOARD_fetchChannelFrequency(const int channel) -{ - uint32_t frequency; - - if (channel < 0 || channel > (int)FREQ_CHANNEL_LAST) - return 0; - - if ((g_user_channel_attributes[channel] & USER_CH_BAND_MASK) > BAND7_470MHz) - return 0; - - EEPROM_ReadBuffer(channel * 16, &frequency, 4); - - return frequency; -} - -unsigned int BOARD_fetchChannelStepSetting(const int channel) -{ - uint8_t data[8]; - unsigned int step_setting = 0; - - if (channel < 0) - return 0; - - if (channel <= USER_CHANNEL_LAST) - { - EEPROM_ReadBuffer(channel * 16, &data, sizeof(data)); - } - else - if (channel <= FREQ_CHANNEL_LAST) - { - EEPROM_ReadBuffer(channel * 16, &data, sizeof(data)); - } - - step_setting = (data[6] >= ARRAY_SIZE(STEP_FREQ_TABLE)) ? STEP_12_5kHz : data[6]; -// step_size = STEP_FREQ_TABLE[step_setting]; - - return step_setting; -} - -unsigned int BOARD_fetchFrequencyStepSetting(const int channel, const int vfo) -{ - uint8_t data[8]; - unsigned int step_setting = 0; - - if (channel < 0 || channel > (FREQ_CHANNEL_LAST - FREQ_CHANNEL_FIRST) || vfo < 0 || vfo >= 2) - return 0; - - EEPROM_ReadBuffer(FREQ_CHANNEL_FIRST + (channel * 16 * 2) + vfo, &data, sizeof(data)); - - step_setting = (data[6] >= ARRAY_SIZE(STEP_FREQ_TABLE)) ? STEP_12_5kHz : data[6]; -// step_size = STEP_FREQ_TABLE[step_setting]; - - return step_setting; -} - -void BOARD_fetchChannelName(char *s, const int channel) -{ - int i; - - if (s == NULL) - return; - - memset(s, 0, 11); // 's' had better be large enough ! - - if (channel < 0 || channel > (int)USER_CHANNEL_LAST) - return; - - if (!RADIO_CheckValidChannel(channel, false, 0)) - return; - - EEPROM_ReadBuffer(0x0F50 + (channel * 16), s, 10); - - for (i = 0; i < 10; i++) - if (s[i] < 32 || s[i] > 127) - break; // invalid char - - s[i--] = 0; // null term - - while (i >= 0 && s[i] == 32) // trim trailing spaces - s[i--] = 0; // null term -} - -void BOARD_FactoryReset(bool bIsAll) -{ - uint16_t i; - uint8_t Template[8]; - - memset(Template, 0xFF, sizeof(Template)); - - for (i = 0x0C80; i < 0x1E00; i += 8) - { - if ( - !(i >= 0x0EE0 && i < 0x0F18) && // ANI ID + DTMF codes - !(i >= 0x0F30 && i < 0x0F50) && // AES KEY + F LOCK + Scramble Enable - !(i >= 0x1C00 && i < 0x1E00) && // DTMF contacts - !(i >= 0x0EB0 && i < 0x0ED0) && // Welcome strings - !(i >= 0x0EA0 && i < 0x0EA8) && // Voice Prompt - (bIsAll || - ( - !(i >= 0x0D60 && i < 0x0E28) && // MR Channel Attributes - !(i >= 0x0F18 && i < 0x0F30) && // Scan List - !(i >= 0x0F50 && i < 0x1C00) && // MR Channel Names - !(i >= 0x0E40 && i < 0x0E70) && // FM Channels - !(i >= 0x0E88 && i < 0x0E90) // FM settings - )) - ) - { - EEPROM_WriteBuffer8(i, Template); - } - } - - if (bIsAll) - { - RADIO_InitInfo(g_rx_vfo, FREQ_CHANNEL_FIRST + BAND6_400MHz, 43350000); - - // set the first few memory channels - for (i = 0; i < ARRAY_SIZE(gDefaultFrequencyTable); i++) - { - const uint32_t Frequency = gDefaultFrequencyTable[i]; - g_rx_vfo->freq_config_rx.frequency = Frequency; - g_rx_vfo->freq_config_tx.frequency = Frequency; - g_rx_vfo->band = FREQUENCY_GetBand(Frequency); - SETTINGS_save_channel(USER_CHANNEL_FIRST + i, 0, g_rx_vfo, 2); - } - } -} diff --git a/board.h b/board.h index 158020c..07e6efe 100644 --- a/board.h +++ b/board.h @@ -24,15 +24,6 @@ void BOARD_GPIO_Init(void); void BOARD_PORTCON_Init(void); void BOARD_ADC_Init(void); void BOARD_ADC_GetBatteryInfo(uint16_t *pVoltage, uint16_t *pCurrent); -void BOARD_Init(void); -void BOARD_eeprom_load(void); -void BOARD_eeprom_loadCalibration(void); -unsigned int BOARD_find_channel(const uint32_t frequency); -uint32_t BOARD_fetchChannelFrequency(const int channel); -unsigned int BOARD_fetchChannelStepSetting(const int channel); -void BOARD_fetchChannelName(char *s, const int channel); -unsigned int BOARD_fetchFrequencyStepSetting(const int channel, const int vfo); -void BOARD_FactoryReset(bool bIsAll); #endif diff --git a/driver/backlight.c b/driver/backlight.c index d563c7d..d1acedd 100644 --- a/driver/backlight.c +++ b/driver/backlight.c @@ -20,11 +20,11 @@ #include "settings.h" // this is decremented once every 500ms -uint16_t g_backlight_count_down = 0; +uint16_t g_backlight_tick_500ms = 0; uint16_t backlight_ticks(void) { - switch (g_eeprom.backlight) + switch (g_eeprom.config.setting.backlight_time) { case 1: return 2 * 5; // 5 sec case 2: return 2 * 10; // 10 sec @@ -41,14 +41,14 @@ void backlight_turn_on(const uint16_t min_ticks) { if (min_ticks > 0) { - if (g_backlight_count_down < min_ticks) - g_backlight_count_down = min_ticks; + if (g_backlight_tick_500ms < min_ticks) + g_backlight_tick_500ms = min_ticks; GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); } else - if (g_eeprom.backlight > 0) + if (g_eeprom.config.setting.backlight_time > 0) { GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); - g_backlight_count_down = backlight_ticks(); + g_backlight_tick_500ms = backlight_ticks(); } } diff --git a/driver/backlight.h b/driver/backlight.h index 1cd24e7..fa35263 100644 --- a/driver/backlight.h +++ b/driver/backlight.h @@ -19,7 +19,7 @@ #include -extern uint16_t g_backlight_count_down; +extern uint16_t g_backlight_tick_500ms; uint16_t backlight_ticks(void); void backlight_turn_on(const uint16_t min_ticks); diff --git a/driver/bk1080.c b/driver/bk1080.c index e9bea4b..939227d 100644 --- a/driver/bk1080.c +++ b/driver/bk1080.c @@ -128,11 +128,7 @@ void BK1080_Init(const uint16_t frequency, const bool initialise) if (BK1080_freq_lower > lower) BK1080_freq_lower = lower; -// if (BK1080_freq_lower > upper) -// BK1080_freq_lower = upper; - -// if (BK1080_freq_upper < lower) -// BK1080_freq_upper = lower; + if (BK1080_freq_upper < upper) BK1080_freq_upper = upper; } @@ -239,7 +235,7 @@ void BK1080_SetFrequency(uint16_t Frequency) BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, (SEEK_THRESHOLD << 8) | (band << 6) | (CHAN_SPACING << 4) | (VOLUME << 0)); BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (uint16_t)channel); - SYSTEM_DelayMs(1); +// SYSTEM_DelayMs(1); BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (uint16_t)channel | (1u << 15)); } diff --git a/driver/st7565.c b/driver/st7565.c index 7d5a08f..c7e4070 100644 --- a/driver/st7565.c +++ b/driver/st7565.c @@ -215,11 +215,11 @@ void ST7565_Init(const bool full) void ST7565_HardwareReset(void) { - GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_ST7565_RES); + GPIO_SetBit( &GPIOB->DATA, GPIOB_PIN_ST7565_RES); SYSTEM_DelayMs(1); GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_ST7565_RES); SYSTEM_DelayMs(20); - GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_ST7565_RES); + GPIO_SetBit( &GPIOB->DATA, GPIOB_PIN_ST7565_RES); SYSTEM_DelayMs(120); } diff --git a/firmware.bin b/firmware.bin index 884f3f4..74acad6 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index e0a1afc..8e1c23e 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/font.c b/font.c index 7152ea1..40a6edf 100644 --- a/font.c +++ b/font.c @@ -477,106 +477,6 @@ const uint8_t g_font_small[95][6] = {0x0C, 0x06, 0x0C, 0x18, 0x0C, 0x00} }; #endif -/* -const uint8_t g_font_small_4x5[95][4] = -{ - {0x00, 0x00, 0x00, 0x00}, // ' ' - {0x00, 0x00, 0x17, 0x00}, // '!' - {0x20, 0x00, 0x03, 0x00}, // '"' - {0x00, 0x00, 0x00, 0x0A}, // '#' - {0x0A, 0x1F, 0x28, 0x00}, // '$' - {0x15, 0x1F, 0x09, 0x70}, // '%' - {0x11, 0x08, 0x04, 0x13}, // '&' - {0x00, 0x1E, 0x15, 0x15}, // ''' - {0x78, 0x00, 0x00, 0x00}, // '(' - {0x07, 0x00, 0x00, 0x0E}, // ')' - {0x00, 0x00, 0x20, 0x00}, // '*' - {0x11, 0x0E, 0x00, 0x20}, // '+' - {0x12, 0x0C, 0x0C, 0x12}, // ',' - {0x00, 0x04, 0x0E, 0x04}, // '-' - {0x00, 0x00, 0x00, 0x10}, // '.' - {0x00, 0x20, 0x00, 0x04}, // '/' - {0x04, 0x00, 0x00, 0x00}, // '0' - {0x10, 0x00, 0x00, 0x20}, // '1' - {0x10, 0x08, 0x04, 0x03}, // '2' - {0x00, 0x0E, 0x11, 0x11}, // '3' - {0x30, 0x00, 0x00, 0x12}, // '4' - {0x10, 0x38, 0x00, 0x19}, // '5' - {0x15, 0x12, 0x78, 0x00}, // '6' - {0x15, 0x15, 0x1F, 0x78}, // '7' - {0x0C, 0x0A, 0x09, 0x1F}, // '8' - {0x00, 0x17, 0x15, 0x15}, // '9' - {0x78, 0x00, 0x1E, 0x15}, // ':' - {0x1D, 0x78, 0x00, 0x01}, // ';' - {0x05, 0x03, 0x20, 0x00}, // '<' - {0x15, 0x15, 0x0A, 0x30}, // '=' - {0x07, 0x05, 0x05, 0x1F}, // '>' - {0x00, 0x00, 0x16, 0x00}, // '?' - {0x20, 0x00, 0x00, 0x10}, // '@' - {0x00, 0x20, 0x00, 0x08}, // 'A' - {0x22, 0x01, 0x20, 0x10}, // 'B' - {0x0A, 0x0A, 0x00, 0x00}, // 'C' - {0x00, 0x01, 0x22, 0x14}, // 'D' - {0x10, 0x02, 0x11, 0x05}, // 'E' - {0x20, 0x00, 0x0E, 0x15}, // 'F' - {0x0E, 0x30, 0x00, 0x1E}, // 'G' - {0x05, 0x1E, 0x48, 0x00}, // 'H' - {0x15, 0x15, 0x0E, 0x70}, // 'I' - {0x1F, 0x11, 0x11, 0x11}, // 'J' - {0x00, 0x1F, 0x11, 0x11}, // 'K' - {0x70, 0x00, 0x1F, 0x15}, // 'L' - {0x11, 0x78, 0x00, 0x1F}, // 'M' - {0x05, 0x01, 0x40, 0x00}, // 'N' - {0x11, 0x15, 0x1D, 0x78}, // 'O' - {0x1F, 0x04, 0x04, 0x1F}, // 'P' - {0x00, 0x11, 0x1F, 0x11}, // 'Q' - {0x70, 0x00, 0x08, 0x11}, // 'R' - {0x1F, 0x38, 0x00, 0x1F}, // 'S' - {0x0A, 0x11, 0x48, 0x00}, // 'T' - {0x10, 0x10, 0x10, 0x78}, // 'U' - {0x1F, 0x02, 0x02, 0x1F}, // 'V' - {0x00, 0x1F, 0x02, 0x04}, // 'W' - {0x48, 0x00, 0x0E, 0x11}, // 'X' - {0x0E, 0x30, 0x00, 0x1F}, // 'Y' - {0x05, 0x02, 0x40, 0x00}, // 'Z' - {0x11, 0x19, 0x1E, 0x38}, // '[' - {0x1F, 0x05, 0x05, 0x1A}, // '\' - {0x00, 0x12, 0x15, 0x15}, // ']' - {0x70, 0x00, 0x01, 0x1F}, // '^' - {0x00, 0x20, 0x00, 0x1F}, // '_' - {0x10, 0x1F, 0x78, 0x00}, // '`' - {0x10, 0x10, 0x0F, 0x30}, // 'a' - {0x1F, 0x08, 0x08, 0x1F}, // 'b' - {0x00, 0x1B, 0x04, 0x04}, // 'c' - {0x48, 0x00, 0x07, 0x1C}, // 'd' - {0x00, 0x20, 0x00, 0x19}, // 'e' - {0x15, 0x13, 0x78, 0x00}, // 'f' - {0x11, 0x00, 0x00, 0x60}, // 'g' - {0x01, 0x02, 0x04, 0x08}, // 'h' - {0x00, 0x00, 0x11, 0x1F}, // 'i' - {0x30, 0x00, 0x02, 0x01}, // 'j' - {0x00, 0x00, 0x00, 0x10}, // 'k' - {0x10, 0x10, 0x78, 0x00}, // 'l' - {0x03, 0x07, 0x06, 0x00}, // 'm' - {0x1D, 0x15, 0x15, 0x1E}, // 'n' - {0x00, 0x1F, 0x14, 0x14}, // 'o' - {0x70, 0x00, 0x0C, 0x12}, // 'p' - {0x12, 0x38, 0x00, 0x08}, // 'q' - {0x14, 0x1F, 0x38, 0x00}, // 'r' - {0x15, 0x15, 0x16, 0x38}, // 's' - {0x1E, 0x05, 0x05, 0x00}, // 't' - {0x00, 0x02, 0x15, 0x15}, // 'u' - {0x38, 0x00, 0x1F, 0x04}, // 'v' - {0x18, 0x48, 0x00, 0x00}, // 'w' - {0x00, 0x00, 0x20, 0x00}, // 'x' - {0x10, 0x1D, 0x00, 0x30}, // 'y' - {0x1F, 0x04, 0x0A, 0x10}, // 'z' - {0x00, 0x00, 0x1F, 0x00}, // '{' - {0x20, 0x00, 0x1E, 0x04}, // '|' - {0x1E, 0x48, 0x00, 0x1E}, // '}' - {0x02, 0x1C, 0x48, 0x00}, // '~' -}; -*/ #ifdef ENABLE_SMALLEST_FONT const uint8_t g_font3x5[160][3] = diff --git a/frequencies.c b/frequencies.c index 8442c8f..0f1be4e 100644 --- a/frequencies.c +++ b/frequencies.c @@ -215,21 +215,22 @@ int FREQUENCY_tx_freq_check(const uint32_t Frequency) if (Frequency < FREQ_BAND_TABLE[0].lower || Frequency > FREQ_BAND_TABLE[ARRAY_SIZE(FREQ_BAND_TABLE) - 1].upper) return -1; // TX not allowed outside this range - switch (g_setting_freq_lock) + switch (g_eeprom.config.setting.freq_lock) { + default: case FREQ_LOCK_NORMAL: if (Frequency >= AIR_BAND.upper && Frequency < 17400000) return 0; if (Frequency >= 17400000 && Frequency < 35000000) - if (g_setting_174_tx_enable) + if (g_eeprom.config.setting.enable_tx_200) return 0; if (Frequency >= 35000000 && Frequency < 40000000) - if (g_setting_350_tx_enable && g_setting_350_enable) + if (g_eeprom.config.setting.enable_tx_350 && g_eeprom.config.setting.enable_350) return 0; if (Frequency >= 40000000 && Frequency < 47000000) return 0; if (Frequency >= 47000000 && Frequency <= 60000000) - if (g_setting_470_tx_enable) + if (g_eeprom.config.setting.enable_tx_470) return 0; break; diff --git a/functions.c b/functions.c index 10e7ffd..850d370 100644 --- a/functions.c +++ b/functions.c @@ -119,14 +119,14 @@ void FUNCTION_Select(function_type_t Function) #ifdef ENABLE_FMRADIO if (g_fm_radio_mode) - g_fm_restore_tick_10ms = g_eeprom.scan_hold_time_500ms * 50; + g_fm_restore_tick_10ms = g_eeprom.config.setting.scan_hold_time * 50; #endif if (g_dtmf_call_state == DTMF_CALL_STATE_CALL_OUT || g_dtmf_call_state == DTMF_CALL_STATE_RECEIVED || g_dtmf_call_state == DTMF_CALL_STATE_RECEIVED_STAY) { - g_dtmf_auto_reset_time_500ms = g_eeprom.dtmf_auto_reset_time * 2; + g_dtmf_auto_reset_time_500ms = g_eeprom.config.setting.dtmf.auto_reset_time * 2; } return; @@ -154,7 +154,7 @@ void FUNCTION_Select(function_type_t Function) GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); } - g_power_save_tick_10ms = g_eeprom.battery_save * 10; + g_power_save_tick_10ms = g_eeprom.config.setting.battery_save_ratio * 10; g_power_save_expired = false; g_rx_idle_mode = true; @@ -174,14 +174,14 @@ void FUNCTION_Select(function_type_t Function) UART_SendText("func transmit\r\n"); #endif - if (g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3) + if (g_eeprom.config.setting.backlight_on_tx_rx == 1 || g_eeprom.config.setting.backlight_on_tx_rx == 3) backlight_turn_on(backlight_tx_rx_time_500ms); - if (g_eeprom.dual_watch != DUAL_WATCH_OFF) + if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF) { // dual-RX is enabled g_dual_watch_tick_10ms = dual_watch_delay_after_tx_10ms; - if (g_dual_watch_tick_10ms < (g_eeprom.scan_hold_time_500ms * 50)) - g_dual_watch_tick_10ms = g_eeprom.scan_hold_time_500ms * 50; + if (g_dual_watch_tick_10ms < (g_eeprom.config.setting.scan_hold_time * 50)) + g_dual_watch_tick_10ms = g_eeprom.config.setting.scan_hold_time * 50; } #ifdef ENABLE_MDC1200 @@ -210,7 +210,7 @@ void FUNCTION_Select(function_type_t Function) GUI_DisplayScreen(); #ifdef ENABLE_ALARM - if (g_alarm_state == ALARM_STATE_TXALARM && g_eeprom.alarm_mode != ALARM_MODE_TONE) + if (g_alarm_state == ALARM_STATE_TXALARM && g_eeprom.config.setting.alarm_mode != ALARM_MODE_TONE) { // enable the alarm tone but not the TX g_alarm_state = ALARM_STATE_ALARM; @@ -233,7 +233,7 @@ void FUNCTION_Select(function_type_t Function) } #endif - if (g_current_vfo->scrambling_type == 0 || !g_setting_scramble_enable) + if (g_current_vfo->scrambling_type == 0 || !g_eeprom.config.setting.enable_scrambler) BK4819_DisableScramble(); RADIO_enableTX(false); @@ -279,7 +279,7 @@ void FUNCTION_Select(function_type_t Function) (1u << 1) | // enable TX DSP (0u << 0)); // disable RX DSP SYSTEM_DelayMs(120); - BK4819_send_MDC1200(MDC1200_OP_CODE_PTT_ID, 0x80, g_eeprom.mdc1200_id); + BK4819_send_MDC1200(MDC1200_OP_CODE_PTT_ID, 0x80, g_eeprom.config.setting.mdc1200_id); } else #endif @@ -301,7 +301,7 @@ void FUNCTION_Select(function_type_t Function) (1u << 1) | // enable TX DSP (0u << 0)); // disable RX DSP */ - if (g_current_vfo->scrambling_type > 0 && g_setting_scramble_enable) + if (g_current_vfo->scrambling_type > 0 && g_eeprom.config.setting.enable_scrambler) { BK4819_EnableScramble(g_current_vfo->scrambling_type - 1); } diff --git a/helper/battery.c b/helper/battery.c index 069ab5a..41e687a 100644 --- a/helper/battery.c +++ b/helper/battery.c @@ -17,11 +17,11 @@ #include "battery.h" #include "driver/backlight.h" #include "misc.h" +#include "settings.h" #include "ui/battery.h" #include "ui/menu.h" #include "ui/ui.h" -uint16_t g_battery_calibration[6]; uint16_t g_usb_current_voltage; uint16_t g_usb_current; uint16_t g_battery_voltages[4]; @@ -86,25 +86,25 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel) g_battery_display_level = 0; - if (g_battery_calibration[5] < Voltage) + if (g_eeprom.calib.battery[5] < Voltage) g_battery_display_level = 6; else - if (g_battery_calibration[4] < Voltage) + if (g_eeprom.calib.battery[4] < Voltage) g_battery_display_level = 5; else - if (g_battery_calibration[3] < Voltage) + if (g_eeprom.calib.battery[3] < Voltage) g_battery_display_level = 4; else - if (g_battery_calibration[2] < Voltage) + if (g_eeprom.calib.battery[2] < Voltage) g_battery_display_level = 3; else - if (g_battery_calibration[1] < Voltage) + if (g_eeprom.calib.battery[1] < Voltage) g_battery_display_level = 2; else - if (g_battery_calibration[0] < Voltage) + if (g_eeprom.calib.battery[0] < Voltage) g_battery_display_level = 1; - g_battery_voltage_average = (Voltage * 760) / g_battery_calibration[3]; + g_battery_voltage_average = (Voltage * 760) / g_eeprom.calib.battery[3]; if ((g_current_display_screen == DISPLAY_MENU) && g_menu_cursor == MENU_VOLTAGE) g_update_display = true; diff --git a/helper/battery.h b/helper/battery.h index 7adf07a..14cf96b 100644 --- a/helper/battery.h +++ b/helper/battery.h @@ -20,7 +20,6 @@ #include #include -extern uint16_t g_battery_calibration[6]; extern uint16_t g_usb_current_voltage; extern uint16_t g_usb_current; extern uint16_t g_battery_voltages[4]; diff --git a/helper/boot.c b/helper/boot.c index 42696fc..112d87a 100644 --- a/helper/boot.c +++ b/helper/boot.c @@ -66,17 +66,17 @@ void BOOT_ProcessMode(boot_mode_t Mode) else if (Mode == BOOT_MODE_AIRCOPY) { - g_eeprom.dual_watch = DUAL_WATCH_OFF; - g_eeprom.battery_save = 0; + g_eeprom.config.setting.dual_watch = DUAL_WATCH_OFF; + g_eeprom.config.setting.battery_save_ratio = 0; #ifdef ENABLE_VOX - g_eeprom.vox_switch = false; + g_eeprom.config.setting.vox_switch = false; #endif - g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF; - g_eeprom.auto_keypad_lock = false; - g_eeprom.key1_short_press_action = ACTION_OPT_NONE; - g_eeprom.key1_long_press_action = ACTION_OPT_NONE; - g_eeprom.key2_short_press_action = ACTION_OPT_NONE; - g_eeprom.key2_long_press_action = ACTION_OPT_NONE; + g_eeprom.config.setting.cross_vfo = CROSS_BAND_OFF; + g_eeprom.config.setting.auto_key_lock = 0; + g_eeprom.config.setting.key1_short = ACTION_OPT_NONE; + g_eeprom.config.setting.key1_long = ACTION_OPT_NONE; + g_eeprom.config.setting.key2_short = ACTION_OPT_NONE; + g_eeprom.config.setting.key2_long = ACTION_OPT_NONE; RADIO_InitInfo(g_rx_vfo, FREQ_CHANNEL_LAST - 1, g_aircopy_freq); diff --git a/main.c b/main.c index 4923baf..213f280 100644 --- a/main.c +++ b/main.c @@ -28,6 +28,8 @@ #include "driver/bk1080.h" #endif #include "driver/bk4819.h" +#include "driver/crc.h" +#include "driver/eeprom.h" #include "driver/gpio.h" #include "driver/st7565.h" #include "driver/system.h" @@ -35,6 +37,7 @@ #if defined(ENABLE_UART) #include "driver/uart.h" #endif +#include "external/printf/printf.h" #include "helper/battery.h" #include "helper/boot.h" #ifdef ENABLE_MDC1200 @@ -43,11 +46,107 @@ #include "misc.h" #include "radio.h" #include "settings.h" +#include "ui/helper.h" #include "ui/lock.h" -#include "ui/welcome.h" #include "ui/menu.h" +#include "ui/status.h" #include "version.h" +void MAIN_DisplayClear(void) +{ + memset(g_status_line, 0, sizeof(g_status_line)); + memset(g_frame_buffer, 0, sizeof(g_frame_buffer)); + + ST7565_BlitStatusLine(); + ST7565_BlitFullScreen(); +} + +void MAIN_DisplayReadingEEPROM(void) +{ + memset(g_status_line, 0, sizeof(g_status_line)); + memset(g_frame_buffer, 0, sizeof(g_frame_buffer)); + + UI_PrintString("READING", 0, LCD_WIDTH, 1, 10); + UI_PrintString("EEPROM", 0, LCD_WIDTH, 3, 10); + + ST7565_BlitStatusLine(); + ST7565_BlitFullScreen(); +} + +void MAIN_DisplayReleaseKeys(void) +{ + memset(g_status_line, 0, sizeof(g_status_line)); + memset(g_frame_buffer, 0, sizeof(g_frame_buffer)); + + UI_PrintString("RELEASE", 0, LCD_WIDTH, 1, 10); + UI_PrintString("ALL KEYS", 0, LCD_WIDTH, 3, 10); + + ST7565_BlitStatusLine(); // blank status line + ST7565_BlitFullScreen(); +} + +void MAIN_DisplayWelcome(void) +{ + char str0[17]; + char str1[17]; + char str2[17]; + + memset(g_status_line, 0, sizeof(g_status_line)); + memset(g_frame_buffer, 0, sizeof(g_frame_buffer)); + + if (g_eeprom.config.setting.power_on_display_mode == PWR_ON_DISPLAY_MODE_NONE) + { + ST7565_FillScreen(0xFF); + } + else + if (g_eeprom.config.setting.power_on_display_mode == PWR_ON_DISPLAY_MODE_FULL_SCREEN) + { + ST7565_FillScreen(0xFF); + } + else + { + unsigned int slen = strlen(Version_str); + if (slen > (sizeof(str2) - 1)) + slen = sizeof(str2) - 1; + + memset(str0, 0, sizeof(str0)); + memset(str1, 0, sizeof(str1)); + memset(str2, 0, sizeof(str2)); + + if (g_eeprom.config.setting.power_on_display_mode == PWR_ON_DISPLAY_MODE_VOLTAGE) + { + strcpy(str0, "VOLTAGE"); + sprintf(str1, "%u.%02uV %u%%", + g_battery_voltage_average / 100, + g_battery_voltage_average % 100, + BATTERY_VoltsToPercent(g_battery_voltage_average)); + } + else + { + //EEPROM_ReadBuffer(0x0EB0, str0, 16); + //sEEPROM_ReadBuffer(0x0EC0, str1, 16); + memcpy(str0, g_eeprom.config.setting.welcome_line[0], 16); + memcpy(str1, g_eeprom.config.setting.welcome_line[1], 16); + } + + memcpy(str2, Version_str, slen); + + UI_PrintString(str0, 0, LCD_WIDTH, 0, 10); + UI_PrintString(str1, 0, LCD_WIDTH, 2, 10); + UI_PrintStringSmall(str2, 0, LCD_WIDTH, 4); + UI_PrintStringSmall(__DATE__, 0, LCD_WIDTH, 5); + UI_PrintStringSmall(__TIME__, 0, LCD_WIDTH, 6); + + #if 1 + ST7565_BlitStatusLine(); // blank status line + #else + UI_DisplayStatus(true); // show all status line symbols (test) + #endif + + ST7565_BlitFullScreen(); + } +} + void Main(void) { unsigned int i; @@ -64,38 +163,48 @@ void Main(void) | SYSCON_DEV_CLK_GATE_CRC_BITS_ENABLE | SYSCON_DEV_CLK_GATE_AES_BITS_ENABLE; - g_monitor_enabled = false; - GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); - SYSTICK_Init(); -#ifdef ENABLE_UART - UART_Init(); -#endif + BOARD_PORTCON_Init(); + BOARD_GPIO_Init(); + CRC_Init(); + #ifdef ENABLE_UART + UART_Init(); + #endif + BOARD_ADC_Init(); + ST7565_Init(true); + #ifdef ENABLE_FMRADIO + BK1080_Init(0, false); + #endif + + // *************************** + + GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); #if defined(ENABLE_UART) UART_SendText(UART_Version_str); UART_SendText("\r\n"); #endif + BootMode = BOOT_GetMode(); + g_unhide_hidden = (BootMode == BOOT_MODE_UNHIDE_HIDDEN); // flag to say include the hidden menu items + // load the entire EEPROM contents into memory + GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // backlight on + MAIN_DisplayReadingEEPROM(); SETTINGS_read_eeprom(); - - BOARD_Init(); - - memset(&g_eeprom, 0, sizeof(g_eeprom)); - - memset(g_dtmf_string, '-', sizeof(g_dtmf_string)); - g_dtmf_string[sizeof(g_dtmf_string) - 1] = 0; + MAIN_DisplayClear(); FREQUENCY_init(); -#if 0 - SETTINGS_restore_calibration(); -#endif - BK4819_Init(); + BOARD_ADC_GetBatteryInfo(&g_usb_current_voltage, &g_usb_current); + + #ifdef ENABLE_CONTRAST + ST7565_SetContrast(g_setting_contrast); + #endif + #if defined(ENABLE_UART) UART_printf("BK4819 id %04X rev %04X\r\n", BK4819_ReadRegister(0x00), BK4819_ReadRegister(0x01)); #ifdef ENABLE_FMRADIO @@ -103,17 +212,18 @@ void Main(void) #endif #endif -#ifdef ENABLE_MDC1200 - MDC1200_init(); -#endif + memset(g_dtmf_string, '-', sizeof(g_dtmf_string)); + g_dtmf_string[sizeof(g_dtmf_string) - 1] = 0; - BOARD_ADC_GetBatteryInfo(&g_usb_current_voltage, &g_usb_current); + #ifdef ENABLE_MDC1200 + MDC1200_init(); + #endif - BOARD_eeprom_load(); + #ifdef ENABLE_AM_FIX + AM_fix_init(); + #endif - BOARD_eeprom_loadCalibration(); - - BK4819_set_mic_gain(g_eeprom.mic_sensitivity_tuning); + BK4819_set_mic_gain(g_mic_sensitivity_tuning); RADIO_configure_channel(0, VFO_CONFIGURE_RELOAD); RADIO_configure_channel(1, VFO_CONFIGURE_RELOAD); @@ -127,18 +237,6 @@ void Main(void) BATTERY_GetReadings(false); - #ifdef ENABLE_CONTRAST - ST7565_SetContrast(g_setting_contrast); - #endif - - #ifdef ENABLE_AM_FIX - AM_fix_init(); - #endif - - BootMode = BOOT_GetMode(); - - g_unhide_hidden = (BootMode == BOOT_MODE_UNHIDE_HIDDEN); // flag to say include the hidden menu items - #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) if (g_unhide_hidden) UART_SendText("boot_unhide_hidden\r\n"); @@ -147,13 +245,13 @@ void Main(void) // sort the menu list UI_SortMenu(!g_unhide_hidden); - // wait for user to release all butts before moving on + // wait for user to release all buttons before moving on if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) || KEYBOARD_Poll() != KEY_INVALID || BootMode != BOOT_MODE_NORMAL) { - backlight_turn_on(0); - UI_DisplayReleaseKeys(); + GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // backlight on + MAIN_DisplayReleaseKeys(); i = 0; while (i < (500 / 10)) // 500ms { @@ -166,7 +264,7 @@ void Main(void) { FUNCTION_Select(FUNCTION_POWER_SAVE); - if (g_eeprom.backlight < (ARRAY_SIZE(g_sub_menu_backlight) - 1)) + if (g_eeprom.config.setting.backlight_time < (ARRAY_SIZE(g_sub_menu_backlight) - 1)) GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF else GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight ON @@ -175,7 +273,7 @@ void Main(void) } else { - UI_DisplayWelcome(); + MAIN_DisplayWelcome(); backlight_turn_on(0); @@ -184,7 +282,7 @@ void Main(void) // AUDIO_PlaySingleVoice(0); #endif - if (g_eeprom.pwr_on_display_mode != PWR_ON_DISPLAY_MODE_NONE) + if (g_eeprom.config.setting.power_on_display_mode != PWR_ON_DISPLAY_MODE_NONE) { // 3 second boot-up screen while (g_boot_tick_10ms > 0) { @@ -201,7 +299,7 @@ void Main(void) } #ifdef ENABLE_PWRON_PASSWORD - if (g_eeprom.power_on_password < 1000000) + if (g_eeprom.config.setting.power_on_password < 1000000) { g_password_locked = true; UI_DisplayLock(); @@ -216,9 +314,9 @@ void Main(void) g_update_status = true; #ifdef ENABLE_VOICE - if (g_eeprom.voice_prompt != VOICE_PROMPT_OFF) + if (g_eeprom.config.setting.voice_prompt != VOICE_PROMPT_OFF) { - const uint8_t Channel = g_eeprom.screen_channel[g_eeprom.tx_vfo]; + const uint8_t Channel = g_eeprom.config.setting.indices.vfo[g_eeprom.config.setting.tx_vfo_num].screen; AUDIO_SetVoiceID(0, VOICE_ID_WELCOME); AUDIO_PlaySingleVoice(0); diff --git a/misc.c b/misc.c index 56c9071..1bfe890 100644 --- a/misc.c +++ b/misc.c @@ -81,38 +81,9 @@ const uint16_t noaa_tick_3_10ms = 200 / 10; // 200ms // *********************************************** -const uint32_t g_default_aes_key[4] = {0x4AA5CC60, 0x0312CC5F, 0xFFD2DABB, 0x6BBA7F92}; +const uint32_t g_default_aes_key[4] = {0x4AA5CC60, 0x0312CC5F, 0xFFD2DABB, 0x6BBA7F92}; -const uint8_t g_mic_gain_dB_2[5] = {3, 8, 16, 24, 31}; - -#ifdef ENABLE_KILL_REVIVE - bool g_setting_radio_disabled; -#endif - -bool g_setting_350_tx_enable; -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; -bool g_setting_scramble_enable; - -uint8_t g_setting_backlight_on_tx_rx; - -#ifdef ENABLE_AM_FIX - bool g_setting_am_fix = true; -#endif -#ifdef ENABLE_AM_FIX_TEST1 - uint8_t g_setting_am_fix_test1 = 0; -#endif -#ifdef ENABLE_TX_AUDIO_BAR - bool g_setting_mic_bar; -#endif -#ifdef ENABLE_RX_SIGNAL_BAR - bool g_setting_rssi_bar; -#endif -bool g_setting_live_dtmf_decoder; -uint8_t g_setting_battery_text; +const uint8_t g_mic_gain_dB_2[5] = {3, 8, 16, 24, 31}; #ifdef ENABLE_CONTRAST uint8_t g_setting_contrast; @@ -125,17 +96,13 @@ uint8_t g_setting_side2_long; bool g_monitor_enabled; -uint32_t g_custom_aes_key[4]; -bool g_has_custom_aes_key; +bool g_has_aes_key; uint32_t g_challenge[4]; +uint16_t g_vox_threshold[2]; + uint16_t g_eeprom_rssi_calib[7][4]; -//uint16_t g_eeprom_1F8A; -//uint16_t g_eeprom_1F8C; - -uint8_t g_user_channel_attributes[FREQ_CHANNEL_LAST + 1]; - volatile uint16_t g_schedule_power_save_tick_10ms = battery_save_count_10ms; volatile bool g_schedule_power_save; @@ -234,16 +201,19 @@ bool g_scan_pause_time_mode; // set if we stopped in SCAN_ volatile uint16_t g_scan_pause_tick_10ms; scan_state_dir_t g_scan_state_dir; +uint8_t g_rx_vfo_num; bool g_rx_vfo_is_active; + #ifdef ENABLE_ALARM uint16_t g_alarm_tone_counter_10ms; uint16_t g_alarm_running_counter_10ms; #endif uint8_t g_menu_list_count; -uint8_t g_backup_cross_vfo_rx_tx; + +uint8_t g_backup_cross_vfo; #ifdef ENABLE_NOAA - bool g_is_noaa_mode; + bool g_noaa_mode; uint8_t g_noaa_channel; #endif @@ -268,36 +238,38 @@ volatile uint16_t g_boot_tick_10ms = 4000 / 10; // 4 seconds int16_t g_current_rssi[2] = {0, 0}; // now one per VFO +uint8_t g_mic_sensitivity_tuning; + unsigned int get_RX_VFO(void) { - unsigned int rx_vfo = g_eeprom.tx_vfo; - if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_CHAN_B) + unsigned int rx_vfo = g_eeprom.config.setting.tx_vfo_num; + if (g_eeprom.config.setting.cross_vfo == CROSS_BAND_CHAN_B) rx_vfo = 0; else - if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_CHAN_A) + if (g_eeprom.config.setting.cross_vfo == CROSS_BAND_CHAN_A) rx_vfo = 1; else - if (g_eeprom.dual_watch == DUAL_WATCH_CHAN_B) + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_CHAN_B) rx_vfo = 1; else - if (g_eeprom.dual_watch == DUAL_WATCH_CHAN_A) + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_CHAN_A) rx_vfo = 0; return rx_vfo; } unsigned int get_TX_VFO(void) { - unsigned int tx_vfo = g_eeprom.tx_vfo; - if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_CHAN_B) + unsigned int tx_vfo = g_eeprom.config.setting.tx_vfo_num; + if (g_eeprom.config.setting.cross_vfo == CROSS_BAND_CHAN_B) tx_vfo = 1; else - if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_CHAN_A) + if (g_eeprom.config.setting.cross_vfo == CROSS_BAND_CHAN_A) tx_vfo = 0; else - if (g_eeprom.dual_watch == DUAL_WATCH_CHAN_B) + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_CHAN_B) tx_vfo = 1; else - if (g_eeprom.dual_watch == DUAL_WATCH_CHAN_A) + if (g_eeprom.config.setting.dual_watch == DUAL_WATCH_CHAN_A) tx_vfo = 0; return tx_vfo; } diff --git a/misc.h b/misc.h index 4e918b9..c999985 100644 --- a/misc.h +++ b/misc.h @@ -22,6 +22,8 @@ #include #include +//#include "settings.h" + #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #endif @@ -43,6 +45,8 @@ //#define IS_NOT_NOAA_CHANNEL(x) ((x) >= USER_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST) #define IS_NOT_NOAA_CHANNEL(x) ((x) <= FREQ_CHANNEL_LAST) +#define CHANNEL_NUM(chaanel, vfo) IS_FREQ_CHANNEL(channel) ? (FREQ_CHANNEL_FIRST + ((channel) - FREQ_CHANNEL_FIRST) * 2) + (vfo) : (channel); + // PTT key-up/key-down audio tone freq's used in NASA's apollo rides to the moon #define APOLLO_TONE_MS 200 // slightly shorter tone length //#define APOLLO_TONE_MS 250 // NASA tone length @@ -173,35 +177,6 @@ extern const uint16_t scan_pause_chan_10ms; extern const uint8_t g_mic_gain_dB_2[5]; -#ifdef ENABLE_KILL_REVIVE - extern bool g_setting_radio_disabled; -#endif - -extern bool g_setting_350_tx_enable; -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; -extern bool g_setting_scramble_enable; - -extern uint8_t g_setting_backlight_on_tx_rx; - -#ifdef ENABLE_AM_FIX - extern bool g_setting_am_fix; -#endif -#ifdef ENABLE_AM_FIX_TEST1 - extern uint8_t g_setting_am_fix_test1; -#endif -#ifdef ENABLE_TX_AUDIO_BAR - extern bool g_setting_mic_bar; -#endif -#ifdef ENABLE_RX_SIGNAL_BAR - extern bool g_setting_rssi_bar; -#endif -extern bool g_setting_live_dtmf_decoder; -extern uint8_t g_setting_battery_text; - #ifdef ENABLE_CONTRAST extern uint8_t g_setting_contrast; #endif @@ -214,17 +189,10 @@ extern uint8_t g_setting_side2_long; extern bool g_monitor_enabled; extern const uint32_t g_default_aes_key[4]; -extern uint32_t g_custom_aes_key[4]; -extern bool g_has_custom_aes_key; +extern bool g_has_aes_key; extern uint32_t g_challenge[4]; extern uint16_t g_eeprom_rssi_calib[7][4]; -//extern uint16_t g_eeprom_rssi_calib[2][4]; - -//extern uint16_t g_eeprom_1F8A; -//extern uint16_t g_eeprom_1F8C; - -extern uint8_t g_user_channel_attributes[207]; extern volatile uint16_t g_schedule_power_save_tick_10ms; extern volatile bool g_schedule_power_save; @@ -325,14 +293,17 @@ extern bool g_scan_pause_time_mode; // set if we stopped in S extern volatile uint16_t g_scan_pause_tick_10ms; // ticks till we move to next channel/frequency extern scan_state_dir_t g_scan_state_dir; // the direction we're scanning in - +extern uint8_t g_rx_vfo_num; extern bool g_rx_vfo_is_active; + +extern uint16_t g_vox_threshold[2]; + extern uint16_t g_alarm_tone_counter_10ms; extern uint16_t g_alarm_running_counter_10ms; extern uint8_t g_menu_list_count; -extern uint8_t g_backup_cross_vfo_rx_tx; +extern uint8_t g_backup_cross_vfo; #ifdef ENABLE_NOAA - extern bool g_is_noaa_mode; + extern bool g_noaa_mode; extern uint8_t g_noaa_channel; #endif extern volatile bool g_next_time_slice; @@ -355,6 +326,8 @@ extern volatile bool g_flag_tail_tone_elimination_complete; extern int16_t g_current_rssi[2]; // now one per VFO extern volatile uint16_t g_boot_tick_10ms; +extern uint8_t g_mic_sensitivity_tuning; + unsigned int get_TX_VFO(void); unsigned int get_RX_VFO(void); void NUMBER_Get(char *pDigits, uint32_t *pInteger); diff --git a/radio.c b/radio.c index 307f90d..0cf9d29 100644 --- a/radio.c +++ b/radio.c @@ -42,6 +42,7 @@ #include "ui/menu.h" #include "ui/ui.h" +vfo_info_t g_vfo_info[2]; vfo_info_t *g_tx_vfo; vfo_info_t *g_rx_vfo; vfo_info_t *g_current_vfo; @@ -53,16 +54,13 @@ vfo_state_t g_vfo_state[2]; bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO) { // return true if the channel appears valid - uint8_t Attributes; - uint8_t PriorityCh1; - uint8_t PriorityCh2; + unsigned int i; + uint8_t priority_channel[2]; if (Channel > USER_CHANNEL_LAST) return false; - Attributes = g_user_channel_attributes[Channel]; - - if ((Attributes & USER_CH_BAND_MASK) > BAND7_470MHz) + if (g_user_channel_attributes[Channel].band > BAND7_470MHz) return false; if (bCheckScanList) @@ -70,29 +68,29 @@ bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO) switch (VFO) { case 0: - if ((Attributes & USER_CH_SCANLIST1) == 0) + if (g_user_channel_attributes[Channel].scanlist1 == 0) return false; - PriorityCh1 = g_eeprom.scan_list_priority_ch1[0]; - PriorityCh2 = g_eeprom.scan_list_priority_ch2[0]; + for (i = 0; i < 2; i++) + priority_channel[i] = g_eeprom.config.setting.priority_scan_list[VFO].channel[i]; break; case 1: - if ((Attributes & USER_CH_SCANLIST2) == 0) + if (g_user_channel_attributes[Channel].scanlist2 == 0) return false; - PriorityCh1 = g_eeprom.scan_list_priority_ch1[1]; - PriorityCh2 = g_eeprom.scan_list_priority_ch2[1]; + for (i = 0; i < 2; i++) + priority_channel[i] = g_eeprom.config.setting.priority_scan_list[VFO].channel[i]; break; default: return true; } - if (PriorityCh1 == Channel) + if (priority_channel[0] == Channel) return false; - if (PriorityCh2 == Channel) + if (priority_channel[1] == Channel) return false; } @@ -151,113 +149,116 @@ void RADIO_InitInfo(vfo_info_t *p_vfo, const uint8_t ChannelSave, const uint32_t void RADIO_configure_channel(const unsigned int VFO, const unsigned int configure) { - uint8_t Channel; - uint8_t Attributes; - uint8_t Band; - uint16_t Base; - uint32_t Frequency; - vfo_info_t *p_vfo = &g_eeprom.vfo_info[VFO]; + unsigned int channel; + t_channel_attrib attributes; +// uint16_t base; + uint32_t frequency; + vfo_info_t *p_vfo = &g_vfo_info[VFO]; - if (!g_setting_350_enable) + if (!g_eeprom.config.setting.enable_350) { - if (g_eeprom.freq_channel[VFO] == (FREQ_CHANNEL_LAST - 2)) - g_eeprom.freq_channel[VFO] = FREQ_CHANNEL_LAST - 1; + if (g_eeprom.config.setting.indices.vfo[VFO].frequency == (FREQ_CHANNEL_LAST - 2)) + g_eeprom.config.setting.indices.vfo[VFO].frequency = FREQ_CHANNEL_LAST - 1; - if (g_eeprom.screen_channel[VFO] == (FREQ_CHANNEL_LAST - 2)) - g_eeprom.screen_channel[VFO] = FREQ_CHANNEL_LAST - 1; + if (g_eeprom.config.setting.indices.vfo[VFO].screen == (FREQ_CHANNEL_LAST - 2)) + g_eeprom.config.setting.indices.vfo[VFO].screen = FREQ_CHANNEL_LAST - 1; } - Channel = g_eeprom.screen_channel[VFO]; + channel = g_eeprom.config.setting.indices.vfo[VFO].screen; p_vfo->freq_in_channel = 0xff; - if (IS_VALID_CHANNEL(Channel)) + if (IS_VALID_CHANNEL(channel)) { #ifdef ENABLE_NOAA - if (Channel >= NOAA_CHANNEL_FIRST) + if (channel >= NOAA_CHANNEL_FIRST) { - RADIO_InitInfo(p_vfo, g_eeprom.screen_channel[VFO], NOAA_FREQUENCY_TABLE[Channel - NOAA_CHANNEL_FIRST]); - if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) + RADIO_InitInfo(p_vfo, g_eeprom.config.setting.indices.vfo[VFO].screen, NOAA_FREQUENCY_TABLE[channel - NOAA_CHANNEL_FIRST]); + if (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) return; - g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF; + g_eeprom.config.setting.cross_vfo = CROSS_BAND_OFF; g_update_status = true; return; } #endif - if (Channel <= USER_CHANNEL_LAST) + if (channel <= USER_CHANNEL_LAST) { - Channel = RADIO_FindNextChannel(Channel, SCAN_STATE_DIR_FORWARD, false, VFO); - if (Channel == 0xFF) + channel = RADIO_FindNextChannel(channel, SCAN_STATE_DIR_FORWARD, false, VFO); + if (channel == 0xFF) { - Channel = g_eeprom.freq_channel[VFO]; - g_eeprom.screen_channel[VFO] = g_eeprom.freq_channel[VFO]; + channel = g_eeprom.config.setting.indices.vfo[VFO].frequency; + g_eeprom.config.setting.indices.vfo[VFO].screen = channel; } else { - g_eeprom.screen_channel[VFO] = Channel; - g_eeprom.user_channel[VFO] = Channel; + g_eeprom.config.setting.indices.vfo[VFO].screen = channel; + g_eeprom.config.setting.indices.vfo[VFO].user = channel; } } } else - Channel = FREQ_CHANNEL_LAST - 1; + { + channel = FREQ_CHANNEL_LAST - 1; + } - Attributes = g_user_channel_attributes[Channel]; - if (Attributes == 0xFF) + attributes = g_user_channel_attributes[channel]; + + if (attributes.band > BAND7_470MHz) { // invalid/unused channel - uint8_t Index; + unsigned int index; - if (Channel <= USER_CHANNEL_LAST) + if (channel <= USER_CHANNEL_LAST) { - Channel = g_eeprom.freq_channel[VFO]; - g_eeprom.screen_channel[VFO] = g_eeprom.freq_channel[VFO]; + channel = g_eeprom.config.setting.indices.vfo[VFO].frequency; + g_eeprom.config.setting.indices.vfo[VFO].screen = channel; } - Index = Channel - FREQ_CHANNEL_FIRST; + index = channel - FREQ_CHANNEL_FIRST; - RADIO_InitInfo(p_vfo, Channel, FREQ_BAND_TABLE[Index].lower); + RADIO_InitInfo(p_vfo, channel, FREQ_BAND_TABLE[index].lower); return; } - Band = Attributes & USER_CH_BAND_MASK; - if (Band > BAND7_470MHz) - Band = BAND6_400MHz; + if (attributes.band > BAND7_470MHz) + attributes.band = BAND6_400MHz; - if (Channel <= USER_CHANNEL_LAST) + if (channel <= USER_CHANNEL_LAST) { // USER channel - p_vfo->band = Band; - p_vfo->scanlist_2_participation = (Attributes & USER_CH_SCANLIST2) ? 1 : 0; - p_vfo->scanlist_1_participation = (Attributes & USER_CH_SCANLIST1) ? 1 : 0; + p_vfo->band = attributes.band; + p_vfo->scanlist_2_participation = attributes.scanlist2; + p_vfo->scanlist_1_participation = attributes.scanlist1; } else - if (IS_FREQ_CHANNEL(Channel)) + if (IS_FREQ_CHANNEL(channel)) { // VFO channel - Band = Channel - FREQ_CHANNEL_FIRST; - g_eeprom.vfo_info[VFO].band = Band; // shouldn't this be "Band / 2" ? .. two VFO's per band + attributes.band = channel - FREQ_CHANNEL_FIRST; // shouldn't this be "Band / 2" ? .. two VFO's per band TODO: + g_vfo_info[VFO].band = attributes.band; #if 0 p_vfo->scanlist_2_participation = 1; p_vfo->scanlist_1_participation = 1; #else // allowing the vfo's to be included in the scanning - p_vfo->scanlist_2_participation = (Attributes & USER_CH_SCANLIST2) ? 1 : 0; - p_vfo->scanlist_1_participation = (Attributes & USER_CH_SCANLIST1) ? 1 : 0; + p_vfo->scanlist_2_participation = attributes.scanlist2; + p_vfo->scanlist_1_participation = attributes.scanlist1; #endif } - p_vfo->channel_save = Channel; + p_vfo->channel_save = channel; - if (Channel <= USER_CHANNEL_LAST) - Base = Channel * 16; - else - Base = 0x0C80 + ((Channel - FREQ_CHANNEL_FIRST) * 16 * 2) + (VFO * 16); // VFO channel +// if (channel <= USER_CHANNEL_LAST) +// base = channel * 16; +// else +// base = 0x0C80 + ((channel - FREQ_CHANNEL_FIRST) * 16 * 2) + (VFO * 16); // VFO channel - if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(Channel)) + if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(channel)) { + const unsigned int chan = CHANNEL_NUM(channel, VFO); t_channel m_channel; - EEPROM_ReadBuffer(Base, &m_channel, sizeof(m_channel)); +// EEPROM_ReadBuffer(Base, &m_channel, sizeof(t_channel)); + memcpy(&m_channel, &g_eeprom.config.channel[chan], sizeof(t_channel)); p_vfo->freq_config_rx.frequency = m_channel.frequency; @@ -321,26 +322,26 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur p_vfo->squelch_level = (m_channel.squelch_level < 10) ? m_channel.squelch_level : 0; } - Frequency = p_vfo->freq_config_rx.frequency; + frequency = p_vfo->freq_config_rx.frequency; - if (Frequency < FREQ_BAND_TABLE[Band].lower) - Frequency = FREQ_BAND_TABLE[Band].lower; + if (frequency < FREQ_BAND_TABLE[attributes.band].lower) + frequency = FREQ_BAND_TABLE[attributes.band].lower; else - if (Frequency >= FREQ_BAND_TABLE[Band].upper) - Frequency = FREQUENCY_floor_to_step(Frequency, p_vfo->step_freq, FREQ_BAND_TABLE[Band].lower, FREQ_BAND_TABLE[Band].upper); + if (frequency >= FREQ_BAND_TABLE[attributes.band].upper) + frequency = FREQUENCY_floor_to_step(frequency, p_vfo->step_freq, FREQ_BAND_TABLE[attributes.band].lower, FREQ_BAND_TABLE[attributes.band].upper); else - if (Channel >= FREQ_CHANNEL_FIRST) - Frequency = FREQUENCY_floor_to_step(Frequency, p_vfo->step_freq, FREQ_BAND_TABLE[Band].lower, FREQ_BAND_TABLE[Band].upper); + if (channel >= FREQ_CHANNEL_FIRST) + frequency = FREQUENCY_floor_to_step(frequency, p_vfo->step_freq, FREQ_BAND_TABLE[attributes.band].lower, FREQ_BAND_TABLE[attributes.band].upper); - if (!g_setting_350_enable && Frequency >= 35000000 && Frequency < 40000000) + if (!g_eeprom.config.setting.enable_350 && frequency >= 35000000 && frequency < 40000000) { // 350~400Mhz not allowed // hop onto the next band up - Frequency = 43350000; - p_vfo->freq_config_rx.frequency = Frequency; - p_vfo->freq_config_tx.frequency = Frequency; - Band = FREQUENCY_GetBand(Frequency); - p_vfo->band = Band; + frequency = 43350000; + p_vfo->freq_config_rx.frequency = frequency; + p_vfo->freq_config_tx.frequency = frequency; + attributes.band = FREQUENCY_GetBand(frequency); + p_vfo->band = attributes.band; p_vfo->frequency_reverse = 0; p_vfo->tx_offset_freq_dir = TX_OFFSET_FREQ_DIR_OFF; p_vfo->tx_offset_freq = 0; @@ -351,15 +352,15 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur } - p_vfo->freq_config_rx.frequency = Frequency; + p_vfo->freq_config_rx.frequency = frequency; - if (Frequency >= AIR_BAND.lower && Frequency < AIR_BAND.upper) + if (frequency >= AIR_BAND.lower && frequency < AIR_BAND.upper) { // air band p_vfo->tx_offset_freq_dir = TX_OFFSET_FREQ_DIR_OFF; p_vfo->tx_offset_freq = 0; } else - if (Channel > USER_CHANNEL_LAST) + if (channel > USER_CHANNEL_LAST) { p_vfo->tx_offset_freq = FREQUENCY_floor_to_step(p_vfo->tx_offset_freq + (p_vfo->step_freq / 2), p_vfo->step_freq, 0, p_vfo->tx_offset_freq + p_vfo->step_freq); } @@ -368,8 +369,9 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur // channel name memset(p_vfo->name, 0, sizeof(p_vfo->name)); - if (Channel <= USER_CHANNEL_LAST) - EEPROM_ReadBuffer(0x0F50 + (Channel * 16), p_vfo->name, 10); // only 10 bytes used + if (channel <= USER_CHANNEL_LAST) +// EEPROM_ReadBuffer(0x0F50 + (Channel * 16), p_vfo->name, 10); // only 10 bytes used + memcpy(p_vfo->name, &g_eeprom.config.channel_name[channel].name, sizeof(g_eeprom.config.channel_name[channel].name)); if (p_vfo->am_mode > 0) { // freq/chan is in AM mode @@ -383,7 +385,7 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur RADIO_ConfigureSquelchAndOutputPower(p_vfo); #ifdef ENABLE_AM_FIX - if (p_vfo->am_mode > 0 && g_setting_am_fix) + if (p_vfo->am_mode > 0 && g_eeprom.config.setting.am_fix) { AM_fix_reset(VFO); AM_fix_10ms(VFO); @@ -405,25 +407,25 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur } #endif -// if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(Channel)) - if (IS_FREQ_CHANNEL(Channel)) - p_vfo->freq_in_channel = BOARD_find_channel(Frequency); // find channel that has this frequency +// if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(channel)) + if (IS_FREQ_CHANNEL(channel)) + p_vfo->freq_in_channel = SETTINGS_find_channel(frequency); // find channel that has this frequency } void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *p_vfo) { - uint8_t TX_power[3]; - uint16_t Base; - frequency_band_t Band; +// uint8_t tx_power[3]; +// uint16_t base; +// frequency_band_t band; uint8_t squelch_level; // ******************************* // squelch - Band = FREQUENCY_GetBand(p_vfo->p_rx->frequency); - Base = (Band < BAND4_174MHz) ? 0x1E60 : 0x1E00; +// band = FREQUENCY_GetBand(p_vfo->p_rx->frequency); +// base = (Band < BAND4_174MHz) ? 0x1E60 : 0x1E00; - squelch_level = (p_vfo->squelch_level > 0) ? p_vfo->squelch_level : g_eeprom.squelch_level; + squelch_level = (p_vfo->squelch_level > 0) ? p_vfo->squelch_level : g_eeprom.config.setting.squelch_level; // note that 'noise' and 'glitch' values are inverted compared to 'rssi' values @@ -435,11 +437,12 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *p_vfo) p_vfo->squelch_open_noise_thresh = 127; // 127 ~ 0 p_vfo->squelch_close_noise_thresh = 127; // 127 ~ 0 - p_vfo->squelch_close_glitch_thresh = 255; // 255 ~ 0 p_vfo->squelch_open_glitch_thresh = 255; // 255 ~ 0 + p_vfo->squelch_close_glitch_thresh = 255; // 255 ~ 0 } else { // squelch >= 1 +#if 0 Base += squelch_level; // my eeprom squelch-1 // VHF UHF EEPROM_ReadBuffer(Base + 0x00, &p_vfo->squelch_open_rssi_thresh, 1); // 50 10 @@ -448,9 +451,21 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *p_vfo) EEPROM_ReadBuffer(Base + 0x20, &p_vfo->squelch_open_noise_thresh, 1); // 65 90 EEPROM_ReadBuffer(Base + 0x30, &p_vfo->squelch_close_noise_thresh, 1); // 70 100 - EEPROM_ReadBuffer(Base + 0x40, &p_vfo->squelch_close_glitch_thresh, 1); // 90 90 - EEPROM_ReadBuffer(Base + 0x50, &p_vfo->squelch_open_glitch_thresh, 1); // 100 100 + EEPROM_ReadBuffer(Base + 0x40, &p_vfo->squelch_close_glitch_thresh, 1); // 90 90 BUG ??? .. these 2 swapped ? + EEPROM_ReadBuffer(Base + 0x50, &p_vfo->squelch_open_glitch_thresh, 1); // 100 100 " " +#else + unsigned int band = (unsigned int)FREQUENCY_GetBand(p_vfo->p_rx->frequency); + band = (band < BAND4_174MHz) ? 1 : 0; + p_vfo->squelch_open_rssi_thresh = g_eeprom.calib.squelch_band[band].open_rssi_thresh[squelch_level]; + p_vfo->squelch_close_rssi_thresh = g_eeprom.calib.squelch_band[band].close_rssi_thresh[squelch_level]; + + p_vfo->squelch_open_noise_thresh = g_eeprom.calib.squelch_band[band].open_noise_thresh[squelch_level]; + p_vfo->squelch_close_noise_thresh = g_eeprom.calib.squelch_band[band].close_noise_thresh[squelch_level]; + + p_vfo->squelch_open_glitch_thresh = g_eeprom.calib.squelch_band[band].open_glitch_thresh[squelch_level]; + p_vfo->squelch_close_glitch_thresh = g_eeprom.calib.squelch_band[band].close_glitch_thresh[squelch_level]; +#endif // ********* // used in AM mode @@ -528,45 +543,49 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *p_vfo) // ******************************* // output power - // my calibration data - // - // 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 .. 137 MHz - // 1F00 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 174 MHz - // 1F10 5A 5A 5A 64 64 64 82 82 82 FF FF FF FF FF FF FF .. 350 MHz - // 1F20 5A 5A 5A 64 64 64 8F 91 8A FF FF FF FF FF FF FF .. 400 MHz - // 1F30 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 470 MHz + { + // my calibration data + // + // 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 .. 137 MHz + // 1F00 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 174 MHz + // 1F10 5A 5A 5A 64 64 64 82 82 82 FF FF FF FF FF FF FF .. 350 MHz + // 1F20 5A 5A 5A 64 64 64 8F 91 8A FF FF FF FF FF FF FF .. 400 MHz + // 1F30 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 470 MHz + + uint8_t tx_power[3]; + const unsigned int band = (unsigned int)FREQUENCY_GetBand(p_vfo->p_tx->frequency); + +// EEPROM_ReadBuffer(0x1ED0 + (band * 16) + (p_vfo->output_power * 3), tx_power, 3); + memcpy(&tx_power, &g_eeprom.calib.tx_band_power[band].level[p_vfo->output_power], 3); - Band = FREQUENCY_GetBand(p_vfo->p_tx->frequency); - - EEPROM_ReadBuffer(0x1ED0 + (Band * 16) + (p_vfo->output_power * 3), TX_power, 3); - - #ifdef ENABLE_REDUCE_LOW_MID_TX_POWER - // make low and mid even lower - if (p_vfo->output_power == OUTPUT_POWER_LOW) - { - TX_power[0] /= 5; //TX_power[0] /= 8; - TX_power[1] /= 5; //TX_power[1] /= 8; - TX_power[2] /= 5; //TX_power[2] /= 8; get more low power - } - else - if (p_vfo->output_power == OUTPUT_POWER_MID) - { - TX_power[0] /= 3; //TX_power[0] /= 5; - TX_power[1] /= 3; //TX_power[1] /= 5; - TX_power[2] /= 3; //TX_power[2] /= 5; get more low power - } - #endif - - p_vfo->txp_calculated_setting = FREQUENCY_CalculateOutputPower( - TX_power[0], - TX_power[1], - TX_power[2], - FREQ_BAND_TABLE[Band].lower, - (FREQ_BAND_TABLE[Band].lower + FREQ_BAND_TABLE[Band].upper) / 2, - FREQ_BAND_TABLE[Band].upper, - p_vfo->p_tx->frequency); + #ifdef ENABLE_REDUCE_LOW_MID_TX_POWER + // make low and mid even lower + if (p_vfo->output_power == OUTPUT_POWER_LOW) + { + tx_power[0] /= 5; //tx_power[0] /= 8; + tx_power[1] /= 5; //tx_power[1] /= 8; + tx_power[2] /= 5; //tx_power[2] /= 8; get more low power + } + else + if (p_vfo->output_power == OUTPUT_POWER_MID) + { + tx_power[0] /= 3; //tx_power[0] /= 5; + tx_power[1] /= 3; //tx_power[1] /= 5; + tx_power[2] /= 3; //tx_power[2] /= 5; get more low power + } + #endif + + p_vfo->txp_calculated_setting = FREQUENCY_CalculateOutputPower( + tx_power[0], + tx_power[1], + tx_power[2], + FREQ_BAND_TABLE[band].lower, + (FREQ_BAND_TABLE[band].lower + FREQ_BAND_TABLE[band].upper) / 2, + FREQ_BAND_TABLE[band].upper, + p_vfo->p_tx->frequency); + } // ******************************* } @@ -612,16 +631,16 @@ void RADIO_ApplyOffset(vfo_info_t *p_vfo, const bool set_pees) 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]; + g_current_vfo = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_rx_vfo : &g_vfo_info[g_eeprom.config.setting.tx_vfo_num]; } 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; + g_eeprom.config.setting.tx_vfo_num = get_TX_VFO(); + g_rx_vfo_num = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_eeprom.config.setting.tx_vfo_num : (g_eeprom.config.setting.tx_vfo_num + 1) & 1u; - g_tx_vfo = &g_eeprom.vfo_info[g_eeprom.tx_vfo]; - g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.rx_vfo]; + g_tx_vfo = &g_vfo_info[g_eeprom.config.setting.tx_vfo_num]; + g_rx_vfo = &g_vfo_info[g_rx_vfo_num]; RADIO_SelectCurrentVfo(); } @@ -649,7 +668,7 @@ void RADIO_setup_registers(bool switch_to_function_foreground) case BK4819_FILTER_BW_NARROW: #ifdef ENABLE_AM_FIX #if 0 -// BK4819_SetFilterBandwidth(Bandwidth, g_rx_vfo->am_mode > 0 && g_setting_am_fix); +// BK4819_SetFilterBandwidth(Bandwidth, g_rx_vfo->am_mode > 0 && g_eeprom.config.setting.am_fix); BK4819_SetFilterBandwidth(Bandwidth, true); #else if (g_rx_vfo->am_mode > 1) @@ -692,7 +711,7 @@ void RADIO_setup_registers(bool switch_to_function_foreground) BK4819_WriteRegister(0x3F, 0); // disable interrupts #ifdef ENABLE_NOAA - if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_is_noaa_mode) + if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_noaa_mode) Frequency = NOAA_FREQUENCY_TABLE[g_noaa_channel]; else #endif @@ -717,10 +736,10 @@ void RADIO_setup_registers(bool switch_to_function_foreground) // else { BK4819_WriteRegister(0x48, - (11u << 12) | // ??? .. 0 ~ 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) + (11u << 12) | // ??? .. 0 ~ 15, doesn't seem to make any difference + ( 0u << 10) | // AF Rx Gain-1 + (g_eeprom.calib.volume_gain << 4) | // AF Rx Gain-2 + (g_eeprom.calib.dac_gain << 0)); // AF DAC Gain (after Gain-1 and Gain-2) } #ifdef ENABLE_VOICE @@ -787,7 +806,7 @@ void RADIO_setup_registers(bool switch_to_function_foreground) break; } - if (g_rx_vfo->scrambling_type > 0 && g_setting_scramble_enable) + if (g_rx_vfo->scrambling_type > 0 && g_eeprom.config.setting.enable_scrambler) BK4819_EnableScramble(g_rx_vfo->scrambling_type - 1); else BK4819_DisableScramble(); @@ -807,11 +826,11 @@ void RADIO_setup_registers(bool switch_to_function_foreground) #ifdef ENABLE_FMRADIO !g_fm_radio_mode && #endif - g_eeprom.vox_switch && + g_eeprom.config.setting.vox_switch && 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); + BK4819_EnableVox(g_vox_threshold[1], g_vox_threshold[0]); interrupt_mask |= BK4819_REG_3F_VOX_FOUND | BK4819_REG_3F_VOX_LOST; } else @@ -848,15 +867,15 @@ void RADIO_setup_registers(bool switch_to_function_foreground) g_update_status = true; - if (g_eeprom.noaa_auto_scan) + if (g_eeprom.config.setting.noaa_auto_scan) { - if (g_eeprom.dual_watch != DUAL_WATCH_OFF) + if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF) { - if (IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[0])) + if (IS_NOT_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[0].screen)) { - if (IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[1])) + if (IS_NOT_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[1].screen)) { - g_is_noaa_mode = false; + g_noaa_mode = false; return; } ChanAB = 1; @@ -864,25 +883,25 @@ void RADIO_setup_registers(bool switch_to_function_foreground) else ChanAB = 0; - if (!g_is_noaa_mode) - g_noaa_channel = g_eeprom.vfo_info[ChanAB].channel_save - NOAA_CHANNEL_FIRST; + if (!g_noaa_mode) + g_noaa_channel = g_vfo_info[ChanAB].channel_save - NOAA_CHANNEL_FIRST; - g_is_noaa_mode = true; + g_noaa_mode = true; return; } if (g_rx_vfo->channel_save >= NOAA_CHANNEL_FIRST) { - g_is_noaa_mode = true; + g_noaa_mode = true; g_noaa_channel = g_rx_vfo->channel_save - NOAA_CHANNEL_FIRST; g_noaa_tick_10ms = noaa_tick_2_10ms; g_schedule_noaa = false; } else - g_is_noaa_mode = false; + g_noaa_mode = false; } else - g_is_noaa_mode = false; + g_noaa_mode = false; } #endif @@ -905,7 +924,7 @@ void RADIO_enableTX(const bool fsk_tx) case BK4819_FILTER_BW_NARROW: #ifdef ENABLE_AM_FIX #if 0 -// BK4819_SetFilterBandwidth(Bandwidth, g_current_vfo->am_mode > 0 && g_setting_am_fix); +// BK4819_SetFilterBandwidth(Bandwidth, g_current_vfo->am_mode > 0 && g_eeprom.config.setting.am_fix); BK4819_SetFilterBandwidth(Bandwidth, true); #else if (g_current_vfo->am_mode > 1) @@ -980,7 +999,7 @@ void RADIO_set_vfo_state(vfo_state_t State) } else { // 1of11 - const unsigned int vfo = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_eeprom.rx_vfo : g_eeprom.tx_vfo; + const unsigned int vfo = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_rx_vfo_num : g_eeprom.config.setting.tx_vfo_num; g_vfo_state[vfo] = State; } @@ -995,21 +1014,21 @@ void RADIO_PrepareTX(void) { vfo_state_t State = VFO_STATE_NORMAL; // default to OK to TX - if (g_eeprom.dual_watch != DUAL_WATCH_OFF) + if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF) { // dual-RX is enabled #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_rx_vfo_num = g_eeprom.config.setting.tx_vfo_num; + g_rx_vfo = &g_vfo_info[g_eeprom.config.setting.tx_vfo_num]; 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_rx_vfo_num = g_eeprom.config.setting.tx_vfo_num; + g_rx_vfo = &g_vfo_info[g_eeprom.config.setting.tx_vfo_num]; g_rx_vfo_is_active = true; } g_current_vfo = g_rx_vfo; @@ -1027,7 +1046,7 @@ void RADIO_PrepareTX(void) } else #endif - if (!g_setting_tx_enable || g_serial_config_tick_500ms > 0) + if (!g_eeprom.config.setting.tx_enable || g_serial_config_tick_500ms > 0) { // TX is disabled or config upload/download in progress State = VFO_STATE_TX_DISABLE; } @@ -1086,11 +1105,11 @@ void RADIO_PrepareTX(void) if (g_alarm_state == ALARM_STATE_OFF) #endif { - if (g_eeprom.tx_timeout_timer == 0) + if (g_eeprom.config.setting.tx_timeout == 0) g_tx_timer_tick_500ms = 60; // 30 sec else - if (g_eeprom.tx_timeout_timer < (ARRAY_SIZE(g_sub_menu_tx_timeout) - 1)) - g_tx_timer_tick_500ms = 120 * g_eeprom.tx_timeout_timer; // minutes + if (g_eeprom.config.setting.tx_timeout < (ARRAY_SIZE(g_sub_menu_tx_timeout) - 1)) + g_tx_timer_tick_500ms = 120 * g_eeprom.config.setting.tx_timeout; // minutes else g_tx_timer_tick_500ms = 120 * 15; // 15 minutes } @@ -1148,35 +1167,35 @@ void RADIO_tx_eot(void) if (g_dtmf_call_state == DTMF_CALL_STATE_NONE && (g_current_vfo->dtmf_ptt_id_tx_mode == PTT_ID_TX_DOWN || g_current_vfo->dtmf_ptt_id_tx_mode == PTT_ID_BOTH)) { // end-of-tx - if (g_eeprom.dtmf_side_tone) + if (g_eeprom.config.setting.dtmf.side_tone) { GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); SYSTEM_DelayMs(60); } - BK4819_EnterDTMF_TX(g_eeprom.dtmf_side_tone); + BK4819_EnterDTMF_TX(g_eeprom.config.setting.dtmf.side_tone); BK4819_PlayDTMFString( - g_eeprom.dtmf_key_down_code, + g_eeprom.config.setting.dtmf.key_down_code, 0, - g_eeprom.dtmf_first_code_persist_time, - g_eeprom.dtmf_hash_code_persist_time, - g_eeprom.dtmf_code_persist_time, - g_eeprom.dtmf_code_interval_time); + g_eeprom.config.setting.dtmf.first_code_persist_time * 10, + g_eeprom.config.setting.dtmf.hash_code_persist_time * 10, + g_eeprom.config.setting.dtmf.code_persist_time * 10, + g_eeprom.config.setting.dtmf.code_interval_time * 10); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER); } else - if (g_eeprom.roger_mode == ROGER_MODE_ROGER) + if (g_eeprom.config.setting.roger_mode == ROGER_MODE_ROGER) { BK4819_PlayRoger(); } else #ifdef ENABLE_MDC1200 -// if (g_eeprom.roger_mode == ROGER_MODE_MDC) +// if (g_eeprom.config.setting.roger_mode == ROGER_MODE_MDC) if (g_current_vfo->mdc1200_mode == MDC1200_MODE_EOT || g_current_vfo->mdc1200_mode == MDC1200_MODE_BOTH) { - BK4819_send_MDC1200(MDC1200_OP_CODE_POST_ID, 0x00, g_eeprom.mdc1200_id); + BK4819_send_MDC1200(MDC1200_OP_CODE_POST_ID, 0x00, g_eeprom.config.setting.mdc1200_id); } else #endif diff --git a/radio.h b/radio.h index 9979861..aaeb7ac 100644 --- a/radio.h +++ b/radio.h @@ -24,12 +24,6 @@ #include "dcs.h" #include "frequencies.h" -enum { - USER_CH_BAND_MASK = 0x0F << 0, - USER_CH_SPARE = 3u << 4, - USER_CH_SCANLIST2 = 1u << 6, - USER_CH_SCANLIST1 = 1u << 7 -}; /* enum { RADIO_CHANNEL_UP = 0x01u, @@ -132,6 +126,8 @@ typedef struct vfo_info_t char name[16]; } vfo_info_t; +extern vfo_info_t g_vfo_info[2]; + extern vfo_info_t *g_tx_vfo; extern vfo_info_t *g_rx_vfo; extern vfo_info_t *g_current_vfo; diff --git a/scheduler.c b/scheduler.c index bb5c5f6..b119627 100644 --- a/scheduler.c +++ b/scheduler.c @@ -78,7 +78,7 @@ void SystickHandler(void) if (g_current_function == FUNCTION_POWER_SAVE) DECREMENT_AND_TRIGGER(g_power_save_tick_10ms, g_power_save_expired); - if (g_eeprom.dual_watch != DUAL_WATCH_OFF && + if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF && g_scan_state_dir == SCAN_STATE_DIR_OFF && g_css_scan_mode == CSS_SCAN_MODE_OFF) { @@ -89,8 +89,8 @@ void SystickHandler(void) #ifdef ENABLE_NOAA if (g_scan_state_dir == SCAN_STATE_DIR_OFF && g_css_scan_mode == CSS_SCAN_MODE_OFF && - g_eeprom.dual_watch == DUAL_WATCH_OFF && - g_is_noaa_mode && + g_eeprom.config.setting.dual_watch == DUAL_WATCH_OFF && + g_noaa_mode && !g_monitor_enabled && g_current_function != FUNCTION_TRANSMIT) { diff --git a/settings.c b/settings.c index e940c92..4c934ad 100644 --- a/settings.c +++ b/settings.c @@ -14,39 +14,304 @@ * limitations under the License. */ +#include "app/dtmf.h" #ifdef ENABLE_FMRADIO #include "app/fm.h" + #include "driver/bk1080.h" #endif +#include "driver/bk4819.h" #include "driver/eeprom.h" #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) #include "driver/uart.h" #endif #include "misc.h" #include "settings.h" +#include "ui/menu.h" -t_eeprom g_eeprom2; +// ****************************************** + + +static const uint32_t DEFAULT_FREQUENCY_TABLE[] = +{ + 14500000, // + 14550000, // + 43300000, // + 43320000, // + 43350000 // +}; + +t_eeprom g_eeprom; +t_channel_attrib g_user_channel_attributes[FREQ_CHANNEL_LAST + 1]; -eeprom_config_t g_eeprom; void SETTINGS_read_eeprom(void) { - EEPROM_ReadBuffer(0, &g_eeprom2, sizeof(g_eeprom2)); + unsigned int index; + + // read the entire EEPROM contents into memory as a whole + for (index = 0; index < sizeof(g_eeprom); index += 128) + EEPROM_ReadBuffer(index, (uint8_t *)(&g_eeprom) + index, 128); #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) UART_printf("config size %04X %u\r\n" + "unused size %04X %u\r\n" "calib size %04X %u\r\n" "eeprom size %04X %u\r\n", - sizeof(g_eeprom2.config), sizeof(g_eeprom2.config), - sizeof(g_eeprom2.calib), sizeof(g_eeprom2.calib), - sizeof(g_eeprom2), sizeof(g_eeprom2)); + sizeof(g_eeprom.config), sizeof(g_eeprom.config), + sizeof(g_eeprom.unused), sizeof(g_eeprom.unused), + sizeof(g_eeprom.calib), sizeof(g_eeprom.calib), + sizeof(g_eeprom), sizeof(g_eeprom)); #endif + + // sanity checks .. + + // 0D60..0E27 + memcpy(&g_user_channel_attributes, &g_eeprom.config.channel_attributes, sizeof(g_user_channel_attributes)); + + g_eeprom.config.setting.call1 = IS_USER_CHANNEL(g_eeprom.config.setting.call1) ? g_eeprom.config.setting.call1 : USER_CHANNEL_FIRST; + g_eeprom.config.setting.squelch_level = (g_eeprom.config.setting.squelch_level < 10) ? g_eeprom.config.setting.squelch_level : 1; + g_eeprom.config.setting.tx_timeout = (g_eeprom.config.setting.tx_timeout < 11) ? g_eeprom.config.setting.tx_timeout : 1; + g_eeprom.config.setting.noaa_auto_scan = (g_eeprom.config.setting.noaa_auto_scan < 2) ? g_eeprom.config.setting.noaa_auto_scan : 0; +#ifdef ENABLE_KEYLOCK + g_eeprom.config.setting.key_lock = (g_eeprom.config.setting.key_lock < 2) ? g_eeprom.config.setting.key_lock : 0; +#endif +#ifdef ENABLE_VOX + g_eeprom.config.setting.vox_switch = (g_eeprom.config.setting.vox_switch < 2) ? g_eeprom.config.setting.vox_switch : 0; + g_eeprom.config.setting.vox_level = (g_eeprom.config.setting.vox_level < 10) ? g_eeprom.config.setting.vox_level : 1; +#endif + g_eeprom.config.setting.mic_sensitivity = (g_eeprom.config.setting.mic_sensitivity < 5) ? g_eeprom.config.setting.mic_sensitivity : 4; + + #ifdef ENABLE_CONTRAST + g_eeprom.config.setting.lcd_contrast = (g_eeprom.config.setting.lcd_contrast > 45) ? 31 : (g_eeprom.config.setting.lcd_contrast < 26) ? 31 : g_eeprom.config.setting.lcd_contrast; + g_setting_contrast = g_eeprom.config.setting.lcd_contrast; + #endif + g_eeprom.config.setting.channel_display_mode = (g_eeprom.config.setting.channel_display_mode < 4) ? g_eeprom.config.setting.channel_display_mode : MDF_FREQUENCY; // 4 instead of 3 - extra display mode + g_eeprom.config.setting.cross_vfo = (g_eeprom.config.setting.cross_vfo < 3) ? g_eeprom.config.setting.cross_vfo : CROSS_BAND_OFF; + g_eeprom.config.setting.battery_save_ratio = (g_eeprom.config.setting.battery_save_ratio < 5) ? g_eeprom.config.setting.battery_save_ratio : 4; + g_eeprom.config.setting.dual_watch = (g_eeprom.config.setting.dual_watch < 3) ? g_eeprom.config.setting.dual_watch : DUAL_WATCH_CHAN_A; + g_eeprom.config.setting.backlight_time = (g_eeprom.config.setting.backlight_time < ARRAY_SIZE(g_sub_menu_backlight)) ? g_eeprom.config.setting.backlight_time : 3; + g_eeprom.config.setting.tail_tone_elimination = (g_eeprom.config.setting.tail_tone_elimination < 2) ? g_eeprom.config.setting.tail_tone_elimination : 0; + g_eeprom.config.setting.vfo_open = (g_eeprom.config.setting.vfo_open < 2) ? g_eeprom.config.setting.vfo_open : 1; + + if (g_eeprom.config.setting.vfo_open == 0) + { + for (index = 0; index < 2; index++) + g_eeprom.config.setting.indices.vfo[index].screen = g_eeprom.config.setting.indices.vfo[index].user; + } + + // 0E80 + for (index = 0; index < ARRAY_SIZE(g_eeprom.config.setting.indices.vfo); index++) + { + g_eeprom.config.setting.indices.vfo[index].screen = IS_VALID_CHANNEL(g_eeprom.config.setting.indices.vfo[index].screen) ? g_eeprom.config.setting.indices.vfo[index].screen : (FREQ_CHANNEL_FIRST + BAND6_400MHz); + g_eeprom.config.setting.indices.vfo[index].user = IS_USER_CHANNEL(g_eeprom.config.setting.indices.vfo[index].user) ? g_eeprom.config.setting.indices.vfo[index].user : USER_CHANNEL_FIRST; + g_eeprom.config.setting.indices.vfo[index].frequency = IS_FREQ_CHANNEL(g_eeprom.config.setting.indices.vfo[index].frequency) ? g_eeprom.config.setting.indices.vfo[index].frequency : (FREQ_CHANNEL_FIRST + BAND6_400MHz); + } +#ifdef ENABLE_NOAA + for (index = 0; index < ARRAY_SIZE(g_eeprom.config.setting.indices.noaa_channel); index++) + g_eeprom.config.setting.indices.noaa_channel[index] = IS_NOAA_CHANNEL(g_eeprom.config.setting.indices.noaa_channel[index]) ? g_eeprom.config.setting.indices.noaa_channel[index] : NOAA_CHANNEL_FIRST; +#endif + +#ifdef ENABLE_FMRADIO + // 0x0E88 + g_eeprom.config.setting.fm_radio.selected_frequency = (g_eeprom.config.setting.fm_radio.selected_frequency >= BK1080_freq_lower && g_eeprom.config.setting.fm_radio.selected_frequency < BK1080_freq_upper) ? g_eeprom.config.setting.fm_radio.selected_frequency : BK1080_freq_lower; + g_eeprom.config.setting.fm_radio.selected_channel = (g_eeprom.config.setting.fm_radio.selected_channel < ARRAY_SIZE(g_eeprom.config.setting.fm_channel)) ? g_eeprom.config.setting.fm_radio.selected_channel : 0; + g_eeprom.config.setting.fm_radio.channel_mode = (g_eeprom.config.setting.fm_radio.channel_mode < 2) ? !!g_eeprom.config.setting.fm_radio.channel_mode : 0; + + // 0E40..0E67 + FM_configure_channel_state(); +#endif + + // 0E90..0E97 + g_eeprom.config.setting.beep_control = (g_eeprom.config.setting.beep_control < 2) ? g_eeprom.config.setting.beep_control : 0; + g_eeprom.config.setting.key1_short = (g_eeprom.config.setting.key1_short < ACTION_OPT_LEN) ? g_eeprom.config.setting.key1_short : ACTION_OPT_MONITOR; + g_eeprom.config.setting.key1_long = (g_eeprom.config.setting.key1_long < ACTION_OPT_LEN) ? g_eeprom.config.setting.key1_long : ACTION_OPT_FLASHLIGHT; + g_eeprom.config.setting.key2_short = (g_eeprom.config.setting.key2_short < ACTION_OPT_LEN) ? g_eeprom.config.setting.key2_short : ACTION_OPT_SCAN; + g_eeprom.config.setting.key2_long = (g_eeprom.config.setting.key2_long < ACTION_OPT_LEN) ? g_eeprom.config.setting.key2_long : ACTION_OPT_NONE; + g_eeprom.config.setting.carrier_search_mode = (g_eeprom.config.setting.carrier_search_mode < 3) ? g_eeprom.config.setting.carrier_search_mode : SCAN_RESUME_CARRIER; + g_eeprom.config.setting.auto_key_lock = (g_eeprom.config.setting.auto_key_lock < 2) ? g_eeprom.config.setting.auto_key_lock : 0; + g_eeprom.config.setting.power_on_display_mode = (g_eeprom.config.setting.power_on_display_mode < 4) ? g_eeprom.config.setting.power_on_display_mode : PWR_ON_DISPLAY_MODE_VOLTAGE; + + // 0EA0..0EA7 + #ifdef ENABLE_VOICE + g_eeprom.config.setting.voice_prompt = (g_eeprom.config.setting.voice_prompt < 3) ? g_eeprom.config.setting.voice_prompt : VOICE_PROMPT_ENGLISH; + #endif + + // 0EA8..0EAF + #ifdef ENABLE_ALARM + g_eeprom.config.setting.alarm_mode = (g_eeprom.config.setting.alarm_mode < 2) ? g_eeprom.config.setting.alarm_mode : 1; + #endif + g_eeprom.config.setting.roger_mode = (g_eeprom.config.setting.roger_mode < 3) ? g_eeprom.config.setting.roger_mode : ROGER_MODE_OFF; + g_eeprom.config.setting.repeater_tail_tone_elimination = (g_eeprom.config.setting.repeater_tail_tone_elimination < 11) ? g_eeprom.config.setting.repeater_tail_tone_elimination : 0; + g_eeprom.config.setting.tx_vfo_num = (g_eeprom.config.setting.tx_vfo_num < 2) ? g_eeprom.config.setting.tx_vfo_num : 0; + #if defined(ENABLE_AIRCOPY) && defined(ENABLE_AIRCOPY_REMEMBER_FREQ) + if (g_eeprom.config.setting.air_copy_freq > 0 && g_eeprom.config.setting.air_copy_freq < 0xffffffff) + { + for (index = 0; index < ARRAY_SIZE(FREQ_BAND_TABLE); index++) + if (g_eeprom.config.setting.air_copy_freq >= FREQ_BAND_TABLE[index].lower && g_eeprom.config.setting.air_copy_freq < FREQ_BAND_TABLE[index].upper) + break; + g_aircopy_freq = (index < ARRAY_SIZE(FREQ_BAND_TABLE)) ? g_eeprom.config.setting.air_copy_freq : 0xffffffff; + } + #endif + + // 0ED0..0ED7 + g_eeprom.config.setting.dtmf.side_tone = (g_eeprom.config.setting.dtmf.side_tone < 2) ? g_eeprom.config.setting.dtmf.side_tone : 1; + g_eeprom.config.setting.dtmf.separate_code = DTMF_ValidateCodes((char *)(&g_eeprom.config.setting.dtmf.separate_code), 1) ? g_eeprom.config.setting.dtmf.separate_code : '*'; + g_eeprom.config.setting.dtmf.group_call_code = DTMF_ValidateCodes((char *)(&g_eeprom.config.setting.dtmf.group_call_code), 1) ? g_eeprom.config.setting.dtmf.group_call_code : '#'; + g_eeprom.config.setting.dtmf.decode_response = (g_eeprom.config.setting.dtmf.decode_response < 4) ? g_eeprom.config.setting.dtmf.decode_response : DTMF_DEC_RESPONSE_RING; + g_eeprom.config.setting.dtmf.auto_reset_time = (g_eeprom.config.setting.dtmf.auto_reset_time <= DTMF_HOLD_MAX) ? g_eeprom.config.setting.dtmf.auto_reset_time : (g_eeprom.config.setting.dtmf.auto_reset_time >= DTMF_HOLD_MIN) ? g_eeprom.config.setting.dtmf.auto_reset_time : DTMF_HOLD_MAX; + g_eeprom.config.setting.dtmf.preload_time = (g_eeprom.config.setting.dtmf.preload_time < 10) ? g_eeprom.config.setting.dtmf.preload_time : 20; + g_eeprom.config.setting.dtmf.first_code_persist_time = (g_eeprom.config.setting.dtmf.first_code_persist_time < 10) ? g_eeprom.config.setting.dtmf.first_code_persist_time : 7; + g_eeprom.config.setting.dtmf.hash_code_persist_time = (g_eeprom.config.setting.dtmf.hash_code_persist_time < 10) ? g_eeprom.config.setting.dtmf.hash_code_persist_time : 7; + g_eeprom.config.setting.dtmf.code_persist_time = (g_eeprom.config.setting.dtmf.code_persist_time < 10) ? g_eeprom.config.setting.dtmf.code_persist_time : 7; + g_eeprom.config.setting.dtmf.code_interval_time = (g_eeprom.config.setting.dtmf.code_interval_time < 10) ? g_eeprom.config.setting.dtmf.code_interval_time : 7; + #ifdef ENABLE_KILL_REVIVE + g_eeprom.config.setting.dtmf.permit_remote_kill = (g_eeprom.config.setting.dtmf.permit_remote_kill < 2) ? g_eeprom.config.setting.dtmf.permit_remote_kill : 0; + #else + g_eeprom.config.setting.dtmf.permit_remote_kill = 0; + #endif + + // 0EE0..0EE7 + if (!DTMF_ValidateCodes(g_eeprom.config.setting.dtmf.ani_id, sizeof(g_eeprom.config.setting.dtmf.ani_id))) + { + memset(g_eeprom.config.setting.dtmf.ani_id, 0, sizeof(g_eeprom.config.setting.dtmf.ani_id)); + strcpy(g_eeprom.config.setting.dtmf.ani_id, "123"); + } + + #ifdef ENABLE_KILL_REVIVE + // 0EE8..0EEF + if (!DTMF_ValidateCodes(g_eeprom.config.setting.dtmf.kill_code, sizeof(g_eeprom.config.setting.dtmf.kill_code))) + { + memset(g_eeprom.config.setting.dtmf.kill_code, 0, sizeof(g_eeprom.config.setting.dtmf.kill_code)); + strcpy(g_eeprom.config.setting.dtmf.kill_code, "ABCD9"); + } + + // 0EF0..0EF7 + if (!DTMF_ValidateCodes(g_eeprom.config.setting.dtmf.revive_code, sizeof(g_eeprom.config.setting.dtmf.revive_code))) + { + memset(g_eeprom.config.setting.dtmf.revive_code, 0, sizeof(g_eeprom.config.setting.dtmf.revive_code)); + strcpy(g_eeprom.config.setting.dtmf.revive_code, "9DCBA"); + } + #else + memset(g_eeprom.config.setting.dtmf.kill_code, 0, sizeof(g_eeprom.config.setting.dtmf.kill_code)); + memset(g_eeprom.config.setting.dtmf.revive_code, 0, sizeof(g_eeprom.config.setting.dtmf.revive_code)); + #endif + + // 0EF8..0F07 + if (!DTMF_ValidateCodes(g_eeprom.config.setting.dtmf.key_up_code, sizeof(g_eeprom.config.setting.dtmf.key_up_code))) + { + memset(g_eeprom.config.setting.dtmf.key_up_code, 0, sizeof(g_eeprom.config.setting.dtmf.key_up_code)); + strcpy(g_eeprom.config.setting.dtmf.key_up_code, "12345"); + } + + // 0F08..0F17 + if (!DTMF_ValidateCodes(g_eeprom.config.setting.dtmf.key_down_code, sizeof(g_eeprom.config.setting.dtmf.key_down_code))) + { + memset(g_eeprom.config.setting.dtmf.key_down_code, 0, sizeof(g_eeprom.config.setting.dtmf.key_down_code)); + strcpy(g_eeprom.config.setting.dtmf.key_down_code, "54321"); + } + + // 0F18..0F1F + g_eeprom.config.setting.scan_list_default = (g_eeprom.config.setting.scan_list_default < 3) ? g_eeprom.config.setting.scan_list_default : 0; // we now have 'all' channel scan option + for (index = 0; index < ARRAY_SIZE(g_eeprom.config.setting.priority_scan_list); index++) + { + unsigned int k; + g_eeprom.config.setting.priority_scan_list[index].enabled = (g_eeprom.config.setting.priority_scan_list[index].enabled < 2) ? g_eeprom.config.setting.priority_scan_list[index].enabled : 0; + for (k = 0; k < ARRAY_SIZE(g_eeprom.config.setting.priority_scan_list[index].channel); k++) + if (!IS_USER_CHANNEL(g_eeprom.config.setting.priority_scan_list[index].channel[k])) + g_eeprom.config.setting.priority_scan_list[index].channel[k] = 0xff; + } + g_eeprom.config.setting.unused10 = 0xff; + + // 0F30..0F3F .. AES key + g_has_aes_key = false; + #if ENABLE_RESET_AES_KEY + // wipe that darned AES key + memset(&g_eeprom.config.setting.aes_key, 0xff, sizeof(g_eeprom.config.setting.aes_key)); + #else + for (index = 0; index < ARRAY_SIZE(g_eeprom.config.setting.aes_key) && !g_has_aes_key; index++) + if (g_eeprom.config.setting.aes_key[index] != 0xffffffff) + g_has_aes_key = true; + #endif + + // 0F40..0F47 + g_eeprom.config.setting.freq_lock = (g_eeprom.config.setting.freq_lock < FREQ_LOCK_LAST) ? g_eeprom.config.setting.freq_lock : FREQ_LOCK_NORMAL; +// g_eeprom.config.setting.enable_tx_350 = (g_eeprom.config.setting.enable_tx_350 < 2) ? g_eeprom.config.setting.enable_tx_350 : false; + #ifdef ENABLE_KILL_REVIVE +// g_eeprom.config.setting.radio_disabled = (g_eeprom.config.setting.radio_disabled < 2) ? g_eeprom.config.setting.radio_disabled : 0; + #else + g_eeprom.config.setting.radio_disabled = 0; + #endif +// g_eeprom.config.setting.enable_tx_200 = (g_eeprom.config.setting.enable_tx_200 < 2) ? g_eeprom.config.setting.enable_tx_200 : 0; +// g_eeprom.config.setting.enable_tx_470 = (g_eeprom.config.setting.enable_tx_470 < 2) ? g_eeprom.config.setting.enable_tx_470 : 0; +// g_eeprom.config.setting.enable_350 = (g_eeprom.config.setting.enable_350 < 2) ? g_eeprom.config.setting.enable_350 : 1; +// g_eeprom.config.setting.enable_scrambler = (g_eeprom.config.setting.enable_scrambler & (1u << 0)) ? 1 : 0; + #ifdef ENABLE_RX_SIGNAL_BAR +// g_eeprom.config.setting.enable_rssi_bar = (Data[6] & (1u << 1)) ? true : false; + #else + g_eeprom.config.setting.enable_rssi_bar = 0; + #endif +// g_eeprom.config.setting.tx_enable = (Data[7] & (1u << 0)) ? true : false; +// g_eeprom.config.setting.dtmf_live_decoder = (Data[7] & (1u << 1)) ? true : false; + g_eeprom.config.setting.battery_text = (g_eeprom.config.setting.battery_text < 3) ? g_eeprom.config.setting.battery_text : 2; + #ifdef ENABLE_TX_AUDIO_BAR +// g_eeprom.config.setting.mic_bar = (Data[7] & (1u << 4)) ? true : false; + #endif + #ifdef ENABLE_AM_FIX +// g_eeprom.config.setting.am_fix = (Data[7] & (1u << 5)) ? true : false; + #endif +// g_eeprom.config.setting.backlight_on_tx_rx = (Data[7] >> 6) & 3u; + + // 0F48..0F4F + g_eeprom.config.setting.scan_hold_time = (g_eeprom.config.setting.scan_hold_time > 40) ? 6 : (g_eeprom.config.setting.scan_hold_time < 2) ? 6 : g_eeprom.config.setting.scan_hold_time; + + memset(&g_eeprom.config.unused13, 0xff, sizeof(g_eeprom.config.unused13)); + + memset(&g_eeprom.unused, 0xff, sizeof(g_eeprom.unused)); + + // **************************************** + + memset(&g_eeprom.calib.unused3, 0xff, sizeof(g_eeprom.calib.unused3)); + + memcpy(&g_eeprom_rssi_calib[0], &g_eeprom.calib.rssi_band_123, 8); + memcpy(&g_eeprom_rssi_calib[1], &g_eeprom_rssi_calib[0], 8); + memcpy(&g_eeprom_rssi_calib[2], &g_eeprom_rssi_calib[0], 8); + memcpy(&g_eeprom_rssi_calib[3], &g_eeprom.calib.rssi_band_4567, 8); + memcpy(&g_eeprom_rssi_calib[4], &g_eeprom_rssi_calib[3], 8); + memcpy(&g_eeprom_rssi_calib[5], &g_eeprom_rssi_calib[3], 8); + memcpy(&g_eeprom_rssi_calib[6], &g_eeprom_rssi_calib[3], 8); + + if (g_eeprom.calib.battery[0] >= 5000) + { + g_eeprom.calib.battery[0] = 1900; + g_eeprom.calib.battery[1] = 2000; + } + g_eeprom.calib.battery[5] = 2300; + + #ifdef ENABLE_VOX + g_vox_threshold[1] = g_eeprom.calib.vox[0].threshold[g_eeprom.config.setting.vox_level]; + g_vox_threshold[0] = g_eeprom.calib.vox[1].threshold[g_eeprom.config.setting.vox_level]; + #endif + + //EEPROM_ReadBuffer(0x1F80 + g_eeprom.config.setting.mic_sensitivity, &Mic, 1); + //g_mic_sensitivity_tuning = (Mic < 32) ? Mic : 15; + g_mic_sensitivity_tuning = g_mic_gain_dB_2[g_eeprom.config.setting.mic_sensitivity]; + + g_eeprom.calib.bk4819_xtal_freq_low = (g_eeprom.calib.bk4819_xtal_freq_low >= -1000 && g_eeprom.calib.bk4819_xtal_freq_low <= 1000) ? g_eeprom.calib.bk4819_xtal_freq_low : 0; + + g_eeprom.calib.volume_gain = (g_eeprom.calib.volume_gain < 64) ? g_eeprom.calib.volume_gain : 58; + g_eeprom.calib.dac_gain = (g_eeprom.calib.dac_gain < 16) ? g_eeprom.calib.dac_gain : 8; + + BK4819_WriteRegister(0x3B, 22656 + g_eeprom.calib.bk4819_xtal_freq_low); +// BK4819_WriteRegister(0x3C, g_eeprom.calib.BK4819_XTAL_FREQ_HIGH); + + // **************************************** } void SETTINGS_write_eeprom_config(void) -{ +{ // save the entire EEPROM contents uint32_t index; - for (index = 0; index < sizeof(g_eeprom2); index += 8) - EEPROM_WriteBuffer8(index, (uint8_t *)(&g_eeprom2) + index); + for (index = 0; index < sizeof(g_eeprom); index += 8) + EEPROM_WriteBuffer8(index, (uint8_t *)(&g_eeprom) + index); } #ifdef ENABLE_FMRADIO @@ -54,219 +319,71 @@ void SETTINGS_write_eeprom_config(void) { unsigned int i; - struct - { - uint16_t frequency; - uint8_t channel; - bool is_channel_selected; - uint8_t padding[4]; - } state; + uint16_t index = (uint16_t)((uint8_t *)&g_eeprom.config.setting.fm_radio - (uint8_t *)&g_eeprom.config); + EEPROM_WriteBuffer8(index, &g_eeprom.config.setting.fm_radio); - memset(&state, 0xFF, sizeof(state)); - state.channel = g_eeprom.fm_selected_channel; - state.frequency = g_eeprom.fm_selected_frequency; - state.is_channel_selected = g_eeprom.fm_channel_mode; - - EEPROM_WriteBuffer8(0x0E88, &state); - - for (i = 0; i < 5; i++) - EEPROM_WriteBuffer8(0x0E40 + (i * 8), &g_fm_channels[i * 4]); + index = (uint16_t)((uint8_t *)&g_eeprom.config.setting.fm_channel - (uint8_t *)&g_eeprom.config); + for (i = 0; i < sizeof(g_eeprom.config.setting.fm_channel); i += 8) + EEPROM_WriteBuffer8(index + i, ((uint8_t *)&g_eeprom.config.setting.fm_channel) + i); } #endif void SETTINGS_save_vfo_indices(void) { - uint8_t State[8]; - - #ifndef ENABLE_NOAA - EEPROM_ReadBuffer(0x0E80, State, sizeof(State)); - #endif - - State[0] = g_eeprom.screen_channel[0]; - State[1] = g_eeprom.user_channel[0]; - State[2] = g_eeprom.freq_channel[0]; - State[3] = g_eeprom.screen_channel[1]; - State[4] = g_eeprom.user_channel[1]; - State[5] = g_eeprom.freq_channel[1]; - #ifdef ENABLE_NOAA - State[6] = g_eeprom.noaa_channel[0]; - State[7] = g_eeprom.noaa_channel[1]; - #endif - - EEPROM_WriteBuffer8(0x0E80, State); + const uint16_t index = (uint16_t)((uint8_t *)&g_eeprom.config.setting.indices - (uint8_t *)&g_eeprom.config); + EEPROM_WriteBuffer8(index, &g_eeprom.config.setting.indices); } void SETTINGS_save(void) { - uint8_t State[8]; + uint32_t index; - State[0] = g_eeprom2.config.call1; - State[1] = g_eeprom.squelch_level; - State[2] = g_eeprom.tx_timeout_timer; - #ifdef ENABLE_NOAA - State[3] = g_eeprom.noaa_auto_scan; - #else - State[3] = false; + #ifndef ENABLE_KEYLOCK + g_eeprom.config.setting.key_lock = 0; #endif - - #ifdef ENABLE_KEYLOCK - State[4] = g_eeprom.key_lock; - #else - State[4] = false; - #endif - #ifdef ENABLE_VOX - State[5] = g_eeprom.vox_switch; - State[6] = g_eeprom.vox_level; - #else - State[5] = false; - State[6] = 0; - #endif - State[7] = g_eeprom.mic_sensitivity; - EEPROM_WriteBuffer8(0x0E70, State); - #ifdef ENABLE_CONTRAST - State[0] = g_setting_contrast; - #else - State[0] = 0xFF; + #ifndef ENABLE_VOX +// g_eeprom.config.setting.vox_switch = 0; +// g_eeprom.config.setting.vox_level = 0; #endif - State[1] = g_eeprom.channel_display_mode; - State[2] = g_eeprom.cross_vfo_rx_tx; - State[3] = g_eeprom.battery_save; - State[4] = g_eeprom.dual_watch; - State[5] = g_eeprom.backlight; - State[6] = g_eeprom.tail_note_elimination; - State[7] = g_eeprom.vfo_open; - EEPROM_WriteBuffer8(0x0E78, State); - State[0] = g_eeprom.beep_control; - State[1] = g_eeprom.key1_short_press_action; - State[2] = g_eeprom.key1_long_press_action; - State[3] = g_eeprom.key2_short_press_action; - State[4] = g_eeprom.key2_long_press_action; - State[5] = g_eeprom.scan_resume_mode; - State[6] = g_eeprom.auto_keypad_lock; - State[7] = g_eeprom.pwr_on_display_mode; - EEPROM_WriteBuffer8(0x0E90, State); + #ifndef ENABLE_CONTRAST +// g_eeprom.config.setting.unused4 = 0xff; + #endif +// memset(&g_eeprom.config.setting.unused6, 0xff, sizeof(g_eeprom.config.setting.unused6)); + + #ifndef ENABLE_PWRON_PASSWORD + memset(&g_eeprom.config.setting.power_on_password, 0xff, sizeof(g_eeprom.config.setting.power_on_password)); + #endif + + #if !defined(ENABLE_ALARM) && !defined(ENABLE_TX1750) + g_eeprom.config.setting.alarm_mode = 0; + #endif + + #if defined(ENABLE_AIRCOPY) && defined(ENABLE_AIRCOPY_REMEMBER_FREQ) + // remember the AIRCOPY frequency + g_eeprom.config.setting.air_copy_freq = g_aircopy_freq; + #else + memset(&g_eeprom.config.setting.unused8, 0xff, sizeof(g_eeprom.config.setting.unused8)); + #endif + + #ifndef ENABLE_KILL_REVIVE + g_eeprom.config.setting.radio_disabled = 0; + #endif + + for (index = 0; index < sizeof(g_eeprom.config.setting); index += 8) { - struct { - uint32_t password; - #ifdef ENABLE_MDC1200 - uint16_t mdc1200_id; // 1of11 - uint8_t spare[2]; - #else - uint8_t spare[4]; - #endif - } __attribute__((packed)) array; - - memset(&array, 0xff, sizeof(array)); - #ifdef ENABLE_PWRON_PASSWORD - array.password = g_eeprom.power_on_password; - #endif - #ifdef ENABLE_MDC1200 - array.mdc1200_id = g_eeprom.mdc1200_id; - #endif - - EEPROM_WriteBuffer8(0x0E98, &array); + const uint16_t offset = (uint16_t)((uint8_t *)&g_eeprom.config.setting - (uint8_t *)&g_eeprom.config); + EEPROM_WriteBuffer8(offset + index, (uint8_t *)(&g_eeprom.config.setting) + index); } - - #ifdef ENABLE_VOICE - memset(State, 0xFF, sizeof(State)); - State[0] = g_eeprom.voice_prompt; - EEPROM_WriteBuffer8(0x0EA0, State); - #endif - - // ***************************** - - { - struct { - uint8_t alarm_mode; - uint8_t roger_mode; - uint8_t repeater_tail_tone_elimination; - uint8_t tx_vfo; - uint32_t air_copy_freq; - } __attribute__((packed)) array; - - memset(&array, 0xff, sizeof(array)); - - #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) - array.alarm_mode = g_eeprom.alarm_mode; - #else - array.alarm_mode = false; - #endif - array.roger_mode = g_eeprom.roger_mode; - array.repeater_tail_tone_elimination = g_eeprom.repeater_tail_tone_elimination; - array.tx_vfo = g_eeprom.tx_vfo; - #ifdef ENABLE_AIRCOPY_REMEMBER_FREQ - // remember the AIRCOPY frequency - array.air_copy_freq = g_aircopy_freq; - #endif - - EEPROM_WriteBuffer8(0x0EA8, &array); - } - - State[0] = g_eeprom.dtmf_side_tone; - State[1] = g_eeprom.dtmf_separate_code; - State[2] = g_eeprom.dtmf_group_call_code; - State[3] = g_eeprom.dtmf_decode_response; - State[4] = g_eeprom.dtmf_auto_reset_time; - State[5] = g_eeprom.dtmf_preload_time / 10U; - State[6] = g_eeprom.dtmf_first_code_persist_time / 10U; - State[7] = g_eeprom.dtmf_hash_code_persist_time / 10U; - EEPROM_WriteBuffer8(0x0ED0, State); - - memset(State, 0xFF, sizeof(State)); - State[0] = g_eeprom.dtmf_code_persist_time / 10U; - State[1] = g_eeprom.dtmf_code_interval_time / 10U; - State[2] = g_eeprom.permit_remote_kill; - EEPROM_WriteBuffer8(0x0ED8, State); - - State[0] = g_eeprom.scan_list_default; - State[1] = g_eeprom.scan_list_enabled[0]; - State[2] = g_eeprom.scan_list_priority_ch1[0]; - State[3] = g_eeprom.scan_list_priority_ch2[0]; - State[4] = g_eeprom.scan_list_enabled[1]; - State[5] = g_eeprom.scan_list_priority_ch1[1]; - State[6] = g_eeprom.scan_list_priority_ch2[1]; - State[7] = 0xFF; - EEPROM_WriteBuffer8(0x0F18, State); - - memset(State, 0xFF, sizeof(State)); - State[0] = g_setting_freq_lock; - State[1] = g_setting_350_tx_enable; - #ifdef ENABLE_KILL_REVIVE - State[2] = g_setting_radio_disabled; - #else - State[2] = false; - #endif - State[3] = g_setting_174_tx_enable; - State[4] = g_setting_470_tx_enable; - State[5] = g_setting_350_enable; - if (!g_setting_scramble_enable) State[6] &= ~(1u << 0); - #ifdef ENABLE_RX_SIGNAL_BAR - if (!g_setting_rssi_bar) State[6] &= ~(1u << 1); - #endif - if (!g_setting_tx_enable) State[7] &= ~(1u << 0); - if (!g_setting_live_dtmf_decoder) State[7] &= ~(1u << 1); - State[7] = (State[7] & ~(3u << 2)) | ((g_setting_battery_text & 3u) << 2); - #ifdef ENABLE_TX_AUDIO_BAR - if (!g_setting_mic_bar) State[7] &= ~(1u << 4); - #endif - #ifdef ENABLE_AM_FIX -// if (!g_setting_am_fix) State[7] &= ~(1u << 5); - #endif - State[7] = (State[7] & ~(3u << 6)) | ((g_setting_backlight_on_tx_rx & 3u) << 6); - EEPROM_WriteBuffer8(0x0F40, State); - - memset(State, 0xFF, sizeof(State)); - State[0] = g_eeprom.scan_hold_time_500ms; - EEPROM_WriteBuffer8(0x0F48, State); } void SETTINGS_save_channel(const unsigned int channel, const unsigned int vfo, const vfo_info_t *p_vfo, const unsigned int mode) { - unsigned int eeprom_addr = channel * 16; - t_channel m_channel; + const unsigned int chan = CHANNEL_NUM(channel, vfo); + t_channel *p_channel = &g_eeprom.config.channel[chan]; + unsigned int eeprom_addr = chan * 16; if (IS_NOAA_CHANNEL(channel)) return; @@ -274,53 +391,50 @@ void SETTINGS_save_channel(const unsigned int channel, const unsigned int vfo, c if (mode < 2 && channel <= USER_CHANNEL_LAST) return; - if (IS_FREQ_CHANNEL(channel)) - eeprom_addr = 0x0C80 + (16 * vfo) + ((channel - FREQ_CHANNEL_FIRST) * 16 * 2); // a VFO - #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) -// UART_printf("sav_chan %04X %3u %u %u\r\n", eeprom_addr, channel, vfo, mode); + UART_printf("sav_chan %04X %3u %3u %u %u\r\n", eeprom_addr, chan, channel, vfo, mode); #endif // **************** if (p_vfo != NULL) { - memset(&m_channel, 0, sizeof(m_channel)); - m_channel.frequency = p_vfo->freq_config_rx.frequency; - m_channel.tx_offset = p_vfo->tx_offset_freq; - m_channel.rx_ctcss_cdcss_code = p_vfo->freq_config_rx.code; - m_channel.tx_ctcss_cdcss_code = p_vfo->freq_config_tx.code; - m_channel.rx_ctcss_cdcss_type = p_vfo->freq_config_rx.code_type; -// m_channel.unused1:2 - m_channel.tx_ctcss_cdcss_type = p_vfo->freq_config_tx.code_type; + memset(p_channel, 0, sizeof(t_channel)); + p_channel->frequency = p_vfo->freq_config_rx.frequency; + p_channel->tx_offset = p_vfo->tx_offset_freq; + p_channel->rx_ctcss_cdcss_code = p_vfo->freq_config_rx.code; + p_channel->tx_ctcss_cdcss_code = p_vfo->freq_config_tx.code; + p_channel->rx_ctcss_cdcss_type = p_vfo->freq_config_rx.code_type; +// p_channel->unused1:2 + p_channel->tx_ctcss_cdcss_type = p_vfo->freq_config_tx.code_type; #ifdef ENABLE_MDC1200 - m_channel.mdc1200_mode = p_vfo->mdc1200_mode; + p_channel->mdc1200_mode = p_vfo->mdc1200_mode; #endif - m_channel.tx_offset_dir = p_vfo->tx_offset_freq_dir; -// m_channel.unused3:2 - m_channel.am_mode = p_vfo->am_mode; -// m_channel.unused4:3 - m_channel.frequency_reverse = p_vfo->frequency_reverse; - m_channel.channel_bandwidth = p_vfo->channel_bandwidth; - m_channel.tx_power = p_vfo->output_power; - m_channel.busy_channel_lock = p_vfo->busy_channel_lock; -// m_channel.unused5:1 - m_channel.compand = p_vfo->compand; - m_channel.dtmf_decoding_enable = p_vfo->dtmf_decoding_enable; - m_channel.dtmf_ptt_id_tx_mode = p_vfo->dtmf_ptt_id_tx_mode; -// m_channel.unused6:4 - m_channel.step_setting = p_vfo->step_setting; - m_channel.scrambler = p_vfo->scrambling_type; - m_channel.squelch_level = p_vfo->squelch_level; + p_channel->tx_offset_dir = p_vfo->tx_offset_freq_dir; +// p_channel->unused3:2 + p_channel->am_mode = p_vfo->am_mode; +// p_channel->unused4:3 + p_channel->frequency_reverse = p_vfo->frequency_reverse; + p_channel->channel_bandwidth = p_vfo->channel_bandwidth; + p_channel->tx_power = p_vfo->output_power; + p_channel->busy_channel_lock = p_vfo->busy_channel_lock; +// p_channel->unused5:1 + p_channel->compand = p_vfo->compand; + p_channel->dtmf_decoding_enable = p_vfo->dtmf_decoding_enable; + p_channel->dtmf_ptt_id_tx_mode = p_vfo->dtmf_ptt_id_tx_mode; +// p_channel->unused6:4 + p_channel->step_setting = p_vfo->step_setting; + p_channel->scrambler = p_vfo->scrambling_type; + p_channel->squelch_level = p_vfo->squelch_level; } else if (channel <= USER_CHANNEL_LAST) { // user channel - memset(&m_channel, 0xff, sizeof(m_channel)); + memset(p_channel, 0xff, sizeof(t_channel)); } - EEPROM_WriteBuffer8(eeprom_addr + 0, (uint8_t *)(&m_channel) + 0); - EEPROM_WriteBuffer8(eeprom_addr + 8, (uint8_t *)(&m_channel) + 8); + EEPROM_WriteBuffer8(eeprom_addr + 0, (uint8_t *)(p_channel) + 0); + EEPROM_WriteBuffer8(eeprom_addr + 8, (uint8_t *)(p_channel) + 8); // **************** @@ -329,28 +443,35 @@ void SETTINGS_save_channel(const unsigned int channel, const unsigned int vfo, c if (channel <= USER_CHANNEL_LAST) { // user channel, it has a channel name const unsigned int eeprom_addr = 0x0F50 + (channel * 16); - uint8_t name[16]; - memset(name, (p_vfo != NULL) ? 0x00 : 0xff, sizeof(name)); + memset(&g_eeprom.config.channel_name[channel], (p_vfo != NULL) ? 0x00 : 0xff, sizeof(g_eeprom.config.channel_name[channel])); #ifndef ENABLE_KEEP_MEM_NAME + // clear/reset the channel name - EEPROM_WriteBuffer8(eeprom_addr + 0, name + 0); - EEPROM_WriteBuffer8(eeprom_addr + 8, name + 8); + EEPROM_WriteBuffer8(eeprom_addr + 0, g_eeprom.config.channel_name[channel] + 0); + EEPROM_WriteBuffer8(eeprom_addr + 8, g_eeprom.config.channel_name[channel] + 8); + #else + if (p_vfo != NULL) - memcpy(name, p_vfo->name, 10); + memcpy(&g_eeprom.config.channel_name[channel], p_vfo->name, 10); + if (mode >= 3 || p_vfo == NULL) { // save the channel name - EEPROM_WriteBuffer8(eeprom_addr + 0, name + 0); - EEPROM_WriteBuffer8(eeprom_addr + 8, name + 8); + + EEPROM_WriteBuffer8(eeprom_addr + 0, &g_eeprom.config.channel_name[channel] + 0); + EEPROM_WriteBuffer8(eeprom_addr + 8, &g_eeprom.config.channel_name[channel] + 8); } + #endif } } void SETTINGS_save_chan_attribs_name(const unsigned int channel, const vfo_info_t *p_vfo) { + const unsigned int index = channel & ~7ul; // eeprom writes are always 8 bytes in length + if (channel >= ARRAY_SIZE(g_user_channel_attributes)) return; @@ -360,40 +481,182 @@ void SETTINGS_save_chan_attribs_name(const unsigned int channel, const vfo_info_ if (p_vfo != NULL) { // channel attributes - const uint8_t attribs = - ((p_vfo->scanlist_1_participation & 1u) << 7) | - ((p_vfo->scanlist_2_participation & 1u) << 6) | - ((3u) << 4) | - ((p_vfo->band & 7u) << 0); + t_channel_attrib attribs; + + attribs.band = p_vfo->band & 7u; + attribs.unused = 3u; + attribs.scanlist2 = p_vfo->scanlist_2_participation; + attribs.scanlist1 = p_vfo->scanlist_1_participation; + + g_user_channel_attributes[channel] = attribs; // remember new attributes + g_eeprom.config.channel_attributes[channel] = attribs; - const unsigned int index = channel & ~7ul; // eeprom writes are always 8 bytes in length - g_user_channel_attributes[channel] = attribs; // remember new attributes EEPROM_WriteBuffer8(0x0D60 + index, g_user_channel_attributes + index); } else if (channel <= USER_CHANNEL_LAST) { // user channel - const unsigned int index = channel & ~7ul; // eeprom writes are always 8 bytes in length - g_user_channel_attributes[channel] = 0xff; + g_user_channel_attributes[channel].attributes = 0xff; + g_eeprom.config.channel_attributes[channel].attributes = 0xff; + EEPROM_WriteBuffer8(0x0D60 + index, g_user_channel_attributes + index); } if (channel <= USER_CHANNEL_LAST) { // user memory channel const unsigned int index = channel * 16; - uint8_t name[16]; if (p_vfo != NULL) { - memset(name, 0, sizeof(name)); - memcpy(name, p_vfo->name, 10); + memset(&g_eeprom.config.channel_name[channel], 0, sizeof(g_eeprom.config.channel_name[channel])); + memcpy(&g_eeprom.config.channel_name[channel], p_vfo->name, 10); } else { - memset(name, 0xff, sizeof(name)); + memset(&g_eeprom.config.channel_name[channel], 0xff, sizeof(g_eeprom.config.channel_name[channel])); } - EEPROM_WriteBuffer8(0x0F50 + 0 + index, name + 0); - EEPROM_WriteBuffer8(0x0F50 + 8 + index, name + 8); + EEPROM_WriteBuffer8(0x0F50 + 0 + index, &g_eeprom.config.channel_name[channel] + 0); + EEPROM_WriteBuffer8(0x0F50 + 8 + index, &g_eeprom.config.channel_name[channel] + 8); + } +} + +unsigned int SETTINGS_find_channel(const uint32_t frequency) +{ + unsigned int chan; + + if (frequency == 0 || frequency == 0xffffffff) + return 0xffffffff; + + for (chan = 0; chan <= USER_CHANNEL_LAST; chan++) + { + const uint32_t freq = g_eeprom.config.channel[chan].frequency; + + if (g_user_channel_attributes[chan].band > BAND7_470MHz || freq == 0 || freq == 0xffffffff) + continue; + + if (freq == frequency) + return chan; // found it + } + + return 0xffffffff; +} + +uint32_t SETTINGS_fetch_channel_frequency(const int channel) +{ + uint32_t freq; + + if (channel < 0 || channel > (int)USER_CHANNEL_LAST) + return 0; + + freq = g_eeprom.config.channel[channel].frequency; + + if (g_user_channel_attributes[channel].band > BAND7_470MHz || freq == 0 || freq == 0xffffffff) + return 0; + + return freq; +} + +unsigned int SETTINGS_fetch_channel_step_setting(const int channel) +{ + unsigned int step_setting; + + if (channel < 0) + return 0; + + if (channel <= USER_CHANNEL_LAST) + step_setting = g_eeprom.config.channel[channel].step_setting; + else + if (channel <= FREQ_CHANNEL_LAST) + step_setting = g_eeprom.config.vfo_channel[(channel - FREQ_CHANNEL_FIRST) * 2].step_setting; + +// step_size = STEP_FREQ_TABLE[step_setting]; + + return (step_setting >= ARRAY_SIZE(STEP_FREQ_TABLE)) ? STEP_12_5kHz : step_setting; +} + +unsigned int SETTINGS_fetch_frequency_step_setting(const int channel, const int vfo) +{ + unsigned int step_setting; + + if (channel < 0 || channel > (FREQ_CHANNEL_LAST - FREQ_CHANNEL_FIRST) || vfo < 0 || vfo >= 2) + return 0; + + step_setting = g_eeprom.config.vfo_channel[(channel * 2) + vfo].step_setting; + +// step_size = STEP_FREQ_TABLE[step_setting]; + + return (step_setting >= ARRAY_SIZE(STEP_FREQ_TABLE)) ? STEP_12_5kHz : step_setting; +} + +void SETTINGS_fetch_channel_name(char *s, const int channel) +{ + int i; + + if (s == NULL) + return; + + memset(s, 0, 11); // 's' had better be large enough ! + + if (channel < 0 || channel > (int)USER_CHANNEL_LAST) + return; + + if (g_user_channel_attributes[channel].band > BAND7_470MHz) + return; + + memcpy(s, &g_eeprom.config.channel_name[channel], 10); + + for (i = 0; i < 10; i++) + if (s[i] < 32 || s[i] > 127) + break; // invalid char + + s[i--] = 0; // null term + + while (i >= 0 && s[i] == 32) // trim trailing spaces + s[i--] = 0; // null term +} + +void SETTINGS_factory_reset(bool bIsAll) +{ + uint16_t i; + uint8_t Template[8]; + + memset(Template, 0xFF, sizeof(Template)); + + for (i = 0x0C80; i < 0x1E00; i += 8) + { + if ( + !(i >= 0x0EE0 && i < 0x0F18) && // ANI ID + DTMF codes + !(i >= 0x0F30 && i < 0x0F50) && // AES KEY + F LOCK + Scramble Enable + !(i >= 0x1C00 && i < 0x1E00) && // DTMF contacts + !(i >= 0x0EB0 && i < 0x0ED0) && // Welcome strings + !(i >= 0x0EA0 && i < 0x0EA8) && // Voice Prompt + (bIsAll || + ( + !(i >= 0x0D60 && i < 0x0E28) && // MR Channel Attributes + !(i >= 0x0F18 && i < 0x0F30) && // Scan List + !(i >= 0x0F50 && i < 0x1C00) && // MR Channel Names + !(i >= 0x0E40 && i < 0x0E70) && // FM Channels + !(i >= 0x0E88 && i < 0x0E90) // FM settings + )) + ) + { + EEPROM_WriteBuffer8(i, Template); + } + } + + if (bIsAll) + { + RADIO_InitInfo(g_rx_vfo, FREQ_CHANNEL_FIRST + BAND6_400MHz, 43350000); + + // set the first few memory channels + for (i = 0; i < ARRAY_SIZE(DEFAULT_FREQUENCY_TABLE); i++) + { + const uint32_t Frequency = DEFAULT_FREQUENCY_TABLE[i]; + g_rx_vfo->freq_config_rx.frequency = Frequency; + g_rx_vfo->freq_config_tx.frequency = Frequency; + g_rx_vfo->band = FREQUENCY_GetBand(Frequency); + SETTINGS_save_channel(USER_CHANNEL_FIRST + i, 0, g_rx_vfo, 2); + } } } diff --git a/settings.h b/settings.h index 421613d..29880c2 100644 --- a/settings.h +++ b/settings.h @@ -123,13 +123,6 @@ typedef enum mdf_display_mode_e mdf_display_mode_t; // ************************************************ // this is the full eeprom structure, both config and calibration areas -// -// am going to use this to replace ALL the currently scattered values -// -// this will also make AIRCOPY safe as we'll first save the incoming transfer -// into this ram area. -// Then, IF the transfer completes withput error, we'll copy it in one go to eeprom - // if channel is used, all unused bits are '0's // if channel not used, all bytes are 0xff @@ -193,184 +186,195 @@ typedef struct { #endif } __attribute__((packed)) t_channel; // -typedef struct { - uint8_t band:4; // why do QS have these bits ? band can/is computed from the frequency - uint8_t unused:2; // - uint8_t scanlist2:1; // set if in scan list 2 - uint8_t scanlist1:1; // set if in scan list 1 -} __attribute__((packed)) t_channel_attr; // +typedef union { + struct { + uint8_t band:4; // why do QS have these bits ? band can/is computed from the frequency + uint8_t unused:2; // + uint8_t scanlist2:1; // set if in scan list 2 + uint8_t scanlist1:1; // set if in scan list 1 + }; + uint8_t attributes; +} __attribute__((packed)) t_channel_attrib; // user configuration typedef struct { - // 0x0000 - t_channel channel[200]; // unused channels are set to all '0xff' + union { - // 0x0C80 - union { // 2 VFO's (upper/lower) per band, 7 frequency bands - t_channel vfo[14]; // - struct { // - t_channel a; // - t_channel b; // - } __attribute__((packed)) vfo_band[7]; // - } __attribute__((packed)); // + struct { + // 0x0000 + t_channel user_channel[200]; // unused channels are set to all '0xff' + // 0x0C80 + t_channel vfo_channel[14]; + }; + + // 0x0000 + t_channel channel[214]; + + } __attribute__((packed)); // 0x0D60 - t_channel_attr channel_attr[200]; // + t_channel_attrib channel_attributes[USER_CHANNEL_LAST - USER_CHANNEL_FIRST + 1]; - uint8_t unused1[8]; // 0xff's + struct { + // 0x0E28 + uint8_t unused1[8]; // 0xff's - // 0x0E30 - uint8_t unused2[16]; // 0xff's + // 0x0E30 + uint8_t unused2[16]; // 0xff's - // 0x0E40 - uint16_t fm_channel[20]; // - uint8_t unused3[8]; // 0xff's + // 0x0E40 + uint16_t fm_channel[20]; // + uint8_t unused3[8]; // 0xff's - // 0x0E70 - uint8_t call1; // - uint8_t squelch_level; // - uint8_t tx_timeout; // - uint8_t noaa_auto_scan; // - uint8_t key_lock; // - uint8_t vox_switch; // - uint8_t vox_level; // - uint8_t mic_sensitivity; // - #ifdef ENABLE_CONTRAST - 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_ratio; // - uint8_t dual_watch; // - uint8_t backlight_time; // - uint8_t tail_tone_elimination; // - uint8_t vfo_open; // + // 0x0E70 + uint8_t call1; // + uint8_t squelch_level; // + uint8_t tx_timeout; // + uint8_t noaa_auto_scan; // + uint8_t key_lock; // + uint8_t vox_switch; // + uint8_t vox_level; // + uint8_t mic_sensitivity; // + #ifdef ENABLE_CONTRAST + 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_ratio; // + uint8_t dual_watch; // + uint8_t backlight_time; // + uint8_t tail_tone_elimination; // + uint8_t vfo_open; // - // 0x0E80 - uint8_t screen_channel_a; // - uint8_t channel_a; // - uint8_t freq_channel_a; // - uint8_t screen_channel_b; // - uint8_t channel_b; // - uint8_t freq_channel_b; // - uint8_t noaa_channel_a; // - uint8_t noaa_channel_b; // - uint8_t fm_selected_frequency; // - uint8_t fm_selected_channel; // - uint8_t fm_channel_mode; // - uint8_t unused5[5]; // 0xff's + // 0x0E80 + struct { + struct { + uint8_t screen; // + uint8_t user; // + uint8_t frequency; // + } __attribute__((packed)) vfo[2]; + uint8_t noaa_channel[2]; // + } __attribute__((packed)) indices; - // 0x0E90 - uint8_t beep_control; // - uint8_t key1_short; // - uint8_t key1_long; // - uint8_t key2_short; // - uint8_t key2_long; // - uint8_t carrier_search_mode; // sc_rev; - uint8_t auto_key_lock; // - uint8_t display_mode; // - uint32_t power_on_password; // - #ifdef ENABLE_MDC1200 - uint16_t mdc1200_id; // 1of11 - uint8_t unused6[2]; // 0xff's - #else - uint8_t unused6[4]; // 0xff's - #endif + // 0x0E88 + struct { + uint16_t selected_frequency; // + uint8_t selected_channel; // + uint8_t channel_mode; // + uint8_t unused[4]; // 0xff's + } __attribute__((packed)) fm_radio; - // 0x0EA0 - uint8_t voice_prompt; // - uint8_t unused7[7]; // 0xff's - uint8_t alarm_mode; // - uint8_t roger_mode; // - uint8_t repeater_tail_tone_elimination; // rp_ste - uint8_t tx_channel; // - #ifdef ENABLE_AIRCOPY - uint32_t air_copy_freq; // 1of11 - #else - uint8_t unused8[4]; // 0xff's - #endif + // 0x0E90 + uint8_t beep_control; // + uint8_t key1_short; // + uint8_t key1_long; // + uint8_t key2_short; // + uint8_t key2_long; // + uint8_t carrier_search_mode; // sc_rev + uint8_t auto_key_lock; // + uint8_t power_on_display_mode; // + uint32_t power_on_password; // + #ifdef ENABLE_MDC1200 + uint16_t mdc1200_id; // 1of11 + uint8_t unused6[2]; // 0xff's + #else + uint8_t unused6[4]; // 0xff's + #endif - // 0x0EB0 - char welcome_line1[16]; // - char welcome_line2[16]; // + // 0x0EA0 + uint8_t voice_prompt; // + uint8_t unused7[7]; // 0xff's + uint8_t alarm_mode; // + uint8_t roger_mode; // + uint8_t repeater_tail_tone_elimination; // rp_ste + uint8_t tx_vfo_num; // + #ifdef ENABLE_AIRCOPY + uint32_t air_copy_freq; // 1of11 + #else + uint8_t unused8[4]; // 0xff's + #endif - // 0x0ED0 - uint8_t dtmf_side_tone; // - uint8_t dtmf_separate_code; // - uint8_t dtmf_group_call_code; // - uint8_t dtmf_rsp; // - uint8_t dtmf_auto_reset_time; // - uint8_t dtmf_preload_time; // - uint8_t dtmf_first_code_time; // - uint8_t dtmf_hash_code_time; // - uint8_t dtmf_code_time; // - uint8_t dtmf_code_interval; // - uint8_t dtmf_permit_kill; // - uint8_t unused9[5]; // 0xff's + // 0x0EB0 + char welcome_line[2][16]; // - // 0x0EE0 - uint8_t dtmf_ani_id[8]; // - uint8_t dtmf_kill_code[8]; // - uint8_t dtmf_revive_code[8]; // - uint8_t dtmf_key_up_code[16]; // - uint8_t dtmf_key_down_code[16]; // + struct { + // 0x0ED0 + uint8_t side_tone; // + uint8_t separate_code; // + uint8_t group_call_code; // + uint8_t decode_response; // + uint8_t auto_reset_time; // + uint8_t preload_time; // + uint8_t first_code_persist_time; // + uint8_t hash_code_persist_time; // + uint8_t code_persist_time; // + uint8_t code_interval_time; // + uint8_t permit_remote_kill; // + uint8_t unused[5]; // 0xff's - // 0x0F18 - uint8_t s_list_default; // - uint8_t priority1_enable; // - uint8_t priority1_channel1; // - uint8_t priority1_channel2; // - uint8_t priority2_enable; // - uint8_t priority2_channel1; // - uint8_t priority2_channel2; // - uint8_t unused10; // 0xff's + // 0x0EE0 + char ani_id[8]; // + char kill_code[8]; // + char revive_code[8]; // + char key_up_code[16]; // + char key_down_code[16]; // + } __attribute__((packed)) dtmf; - // 0x0F20 - uint8_t unused11[16]; // 0xff's + // 0x0F18 + uint8_t scan_list_default; // + struct { + uint8_t enabled; // + uint8_t channel[2]; // + } __attribute__((packed)) priority_scan_list[2]; + uint8_t unused10; // 0xff's - // 0x0F30 - uint8_t aes_key[16]; // disabled = all 0xff + // 0x0F20 + uint8_t unused11[16]; // 0xff's - // 0x0F40 - uint8_t freq_lock; // - uint8_t enable_tx_350:1; // 1 = 350MHz ~ 400MHz TX is enabled - uint8_t unused11a:7; // - uint8_t radio_disabled:1; // 1 = radio is disabled - uint8_t unused11b:7; // - uint8_t enable_tx_200:1; // 1 = 174MHz ~ 350MHz TX enabled - uint8_t unused11c:7; // - uint8_t enable_tx_470:1; // 1 = >= 470MHz TX enabled - uint8_t unused11d:7; // - uint8_t enable_350:1; // 1 = 350HMz ~ 400MHz enabled - uint8_t unused11e:7; // - uint8_t enable_scrambler:1; // - uint8_t enable_rssi_bar:1; // 1of11 - uint8_t unused11f:6; // - #if 0 - // QS - uint8_t unused12[9]; // 0xff's - #else - // 1of11 - uint8_t tx_enable:1; // 0 = completely disable TX, 1 = allow TX - uint8_t dtmf_live_decoder:1; // 1 = enable on-screen live DTMF decoder - uint8_t battery_text:2; // 0 = no battery text, 1 = voltage, 2 = percent .. on the status bar - uint8_t mic_bar:1; // 1 = on-screen TX audio level - uint8_t am_fix:1; // 1 = enable 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 + // 0x0F30 + uint32_t aes_key[4]; // disabled = all 0xff - uint8_t scan_hold_time; // ticks we stay paused for on an RX'ed signal when scanning + // 0x0F40 + uint8_t freq_lock; // + uint8_t enable_tx_350:1; // 1 = 350MHz ~ 400MHz TX is enabled + uint8_t unused11a:7; // + uint8_t radio_disabled:1; // 1 = radio is disabled + uint8_t unused11b:7; // + uint8_t enable_tx_200:1; // 1 = 174MHz ~ 350MHz TX enabled + uint8_t unused11c:7; // + uint8_t enable_tx_470:1; // 1 = >= 470MHz TX enabled + uint8_t unused11d:7; // + uint8_t enable_350:1; // 1 = 350HMz ~ 400MHz enabled + uint8_t unused11e:7; // + uint8_t enable_scrambler:1; // + uint8_t enable_rssi_bar:1; // 1of11 + uint8_t unused11f:6; // + #if 0 + // QS + uint8_t unused12[9]; // 0xff's + #else + // 1of11 + uint8_t tx_enable:1; // 0 = completely disable TX, 1 = allow TX + uint8_t dtmf_live_decoder:1; // 1 = enable on-screen live DTMF decoder + uint8_t battery_text:2; // 0 = no battery text, 1 = voltage, 2 = percent .. on the status bar + uint8_t mic_bar:1; // 1 = on-screen TX audio level + uint8_t am_fix:1; // 1 = enable 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[7]; // 0xff's - #endif + uint8_t scan_hold_time; // ticks we stay paused for on an RX'ed signal when scanning + + uint8_t unused12[7]; // 0xff's + #endif + } __attribute__((packed)) setting; // 0x0F50 struct { char name[10]; uint8_t unused[6]; // 0xff's - } __attribute__((packed)) channel_name[200]; + } __attribute__((packed)) channel_name[USER_CHANNEL_LAST - USER_CHANNEL_FIRST + 1]; // 0x1BD0 uint8_t unused13[16 * 3]; // 0xff's .. free to use @@ -400,23 +404,7 @@ typedef struct { uint8_t unused5[6]; // 0xff's uint8_t close_glitch_thresh[10]; // uint8_t unused6[6]; // 0xff's - } squelch_band_4567[6]; - - // 0x1E60 - struct { - 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 - } squelch_band_123[6]; + } __attribute__((packed)) squelch_band[2]; // 0 = bands 4567, 1 = bands 123 // 0x1EC0 uint16_t rssi_band_4567[4]; // RSSI bargraph thresholds .. (dBm + 160) * 2 @@ -425,11 +413,16 @@ typedef struct { // 0x1ED0 struct { - uint8_t low[3]; // - uint8_t mid[3]; // - uint8_t high[3]; // + union { + struct { + uint8_t low[3]; // + uint8_t mid[3]; // + uint8_t high[3]; // + }; + uint8_t level[3][3]; // + }; uint8_t unused[7]; // 0xff's - } tx_band_power[7]; // + } __attribute__((packed)) tx_band_power[7]; // 0x1F40 uint16_t battery[6]; // @@ -440,11 +433,13 @@ typedef struct { { uint16_t threshold[10]; // uint8_t unused[4]; // 0xff's - } vox[2]; + } __attribute__((packed)) vox[2]; // 0x1F80 uint8_t mic_gain_dB2[5]; // - uint8_t unused4[3]; // + uint8_t unused2[3]; // + + // 0x1F88 int16_t bk4819_xtal_freq_low; // uint16_t unknown2; // uint16_t unknown3; // @@ -452,7 +447,7 @@ typedef struct { uint8_t dac_gain; // // 0x1F90 - uint8_t unused5[16 * 7]; // 0xff's + uint8_t unused3[16 * 7]; // 0xff's // 0x2000 @@ -465,7 +460,7 @@ typedef struct { t_config config; // radios user config // 0x1D00 - uint8_t unused[256]; // does this belong to the config, or the calibration, or neither ? + uint8_t unused[16 * 16]; // does this belong to the config, or the calibration, or neither ? // 0x1E00 t_calibration calib; // calibration settings .. we DO NOT pass this through aircopy, it's radio specific @@ -473,122 +468,9 @@ typedef struct { } __attribute__((packed)) t_eeprom; // 8192 (0x2000) bytes of eeprom // ************************************************ -// this and all the other variables are going to be replaced with the above t_eeprom -typedef struct { - uint8_t screen_channel[2]; - uint8_t freq_channel[2]; - uint8_t user_channel[2]; - #ifdef ENABLE_NOAA - uint8_t noaa_channel[2]; - #endif - uint8_t rx_vfo; - uint8_t tx_vfo; - - uint8_t field7_0xa; - uint8_t field8_0xb; - - #ifdef ENABLE_FMRADIO - uint16_t fm_selected_frequency; - uint8_t fm_selected_channel; - bool fm_channel_mode; - uint16_t fm_frequency_playing; - #endif - - uint8_t squelch_level; - uint8_t tx_timeout_timer; - #ifdef ENABLE_KEYLOCK - bool key_lock; - #endif - bool vox_switch; - uint8_t vox_level; - #ifdef ENABLE_VOICE - voice_prompt_t voice_prompt; - #endif - bool beep_control; - uint8_t channel_display_mode; - bool tail_note_elimination; - bool vfo_open; - uint8_t dual_watch; - uint8_t cross_vfo_rx_tx; - uint8_t battery_save; - uint8_t backlight; - uint8_t scan_resume_mode; - uint8_t scan_list_default; - bool scan_list_enabled[2]; - uint8_t scan_list_priority_ch1[2]; - uint8_t scan_list_priority_ch2[2]; - - #ifdef ENABLE_MDC1200 - uint16_t mdc1200_id; - #endif - - bool auto_keypad_lock; - - #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) - alarm_mode_t alarm_mode; - #endif - pwr_on_display_mode_t pwr_on_display_mode; - roger_mode_t roger_mode; - uint8_t repeater_tail_tone_elimination; - uint8_t key1_short_press_action; - uint8_t key1_long_press_action; - uint8_t key2_short_press_action; - uint8_t key2_long_press_action; - uint8_t mic_sensitivity; - uint8_t mic_sensitivity_tuning; -// uint8_t chan_1_call; - char ani_dtmf_id[8]; - char kill_code[8]; - char revive_code[8]; - char dtmf_key_up_code[16]; - char dtmf_key_down_code[16]; - - char dtmf_separate_code; - char dtmf_group_call_code; - uint8_t dtmf_decode_response; - uint8_t dtmf_auto_reset_time; - uint16_t dtmf_preload_time; - uint16_t dtmf_first_code_persist_time; - uint16_t dtmf_hash_code_persist_time; - uint16_t dtmf_code_persist_time; - uint16_t dtmf_code_interval_time; - bool dtmf_side_tone; - bool permit_remote_kill; - int16_t BK4819_xtal_freq_low; - #ifdef ENABLE_NOAA - bool noaa_auto_scan; - #endif - uint8_t volume_gain; - uint8_t dac_gain; - vfo_info_t vfo_info[2]; - uint32_t power_on_password; - uint16_t vox1_threshold; - uint16_t vox0_threshold; - - uint8_t scan_hold_time_500ms; - -// uint8_t field29_0x26; -// uint8_t field30_0x27; - -// uint8_t field37_0x32; -// uint8_t field38_0x33; - -// uint8_t field57_0x6c; -// uint8_t field58_0x6d; - -// uint8_t field60_0x7e; -// uint8_t field61_0x7f; - -// uint8_t field77_0x95; -// uint8_t field78_0x96; -// uint8_t field79_0x97; - -} eeprom_config_t; - -extern t_eeprom g_eeprom2; - -extern eeprom_config_t g_eeprom; +extern t_eeprom g_eeprom; +extern t_channel_attrib g_user_channel_attributes[FREQ_CHANNEL_LAST + 1]; void SETTINGS_read_eeprom(void); void SETTINGS_write_eeprom_config(void); @@ -597,9 +479,15 @@ void SETTINGS_write_eeprom_config(void); void SETTINGS_save_fm(void); #endif void SETTINGS_save_vfo_indices(void); -//void SETTINGS_restore_calibration(void); void SETTINGS_save(void); void SETTINGS_save_channel(const unsigned int channel, const unsigned int vfo, const vfo_info_t *p_vfo, const unsigned int mode); void SETTINGS_save_chan_attribs_name(const unsigned int channel, const vfo_info_t *p_vfo); +unsigned int SETTINGS_find_channel(const uint32_t frequency); +uint32_t SETTINGS_fetch_channel_frequency(const int channel); +unsigned int SETTINGS_fetch_channel_step_setting(const int channel); +void SETTINGS_fetch_channel_name(char *s, const int channel); +unsigned int SETTINGS_fetch_frequency_step_setting(const int channel, const int vfo); +void SETTINGS_factory_reset(bool bIsAll); + #endif diff --git a/ui/fmradio.c b/ui/fmradio.c index 9cd014c..b428898 100644 --- a/ui/fmradio.c +++ b/ui/fmradio.c @@ -34,7 +34,7 @@ void UI_DisplayFM(void) memset(g_frame_buffer, 0, sizeof(g_frame_buffer)); #ifdef ENABLE_KEYLOCK - if (g_eeprom.key_lock && g_keypad_locked > 0) + if (g_eeprom.config.setting.key_lock && g_keypad_locked > 0) { // tell user how to unlock the keyboard backlight_turn_on(0); UI_PrintString("Long press #", 0, LCD_WIDTH - 1, 1, 8); @@ -54,7 +54,7 @@ void UI_DisplayFM(void) if (g_ask_to_save) { - const unsigned int freq = g_eeprom.fm_frequency_playing; + const unsigned int freq = g_eeprom.config.setting.fm_radio.selected_frequency; sprintf(str, "SAVE %u.%u ?", freq / 10, freq % 10); } else @@ -68,22 +68,22 @@ void UI_DisplayFM(void) if (g_fm_scan_state_dir == FM_SCAN_STATE_DIR_OFF) { - if (!g_eeprom.fm_channel_mode) + if (g_eeprom.config.setting.fm_radio.channel_mode == 0) { - for (i = 0; i < ARRAY_SIZE(g_fm_channels); i++) + for (i = 0; i < ARRAY_SIZE(g_eeprom.config.setting.fm_channel); i++) { - if (g_eeprom.fm_frequency_playing == g_fm_channels[i]) + if (g_eeprom.config.setting.fm_radio.selected_frequency == g_eeprom.config.setting.fm_channel[i]) { sprintf(str, "VFO (CH %u)", 1 + i); break; } } - if (i >= ARRAY_SIZE(g_fm_channels)) + if (i >= ARRAY_SIZE(g_eeprom.config.setting.fm_channel)) strcpy(str, "VFO"); } else - sprintf(str, "CH %u", 1 + g_eeprom.fm_selected_channel); + sprintf(str, "CH %u", 1 + g_eeprom.config.setting.fm_radio.selected_channel); } else if (!g_fm_auto_scan) @@ -102,13 +102,13 @@ void UI_DisplayFM(void) if (g_ask_to_save) { // channel mode const unsigned int chan = g_fm_channel_position; - const uint32_t freq = g_fm_channels[chan]; + const uint32_t freq = g_eeprom.config.setting.fm_channel[chan]; UI_GenerateChannelString(str, chan, ' '); if (FM_check_valid_channel(chan)) sprintf(str + strlen(str), " (%u.%u)", freq / 10, freq % 10); } else - if (g_eeprom.fm_channel_mode && g_input_box_index > 0) + if (g_eeprom.config.setting.fm_radio.channel_mode != 0 && g_input_box_index > 0) { // user is entering a channel number UI_GenerateChannelString(str, g_fm_channel_position, ' '); } @@ -117,7 +117,7 @@ void UI_DisplayFM(void) { if (g_input_box_index == 0) { // frequency mode - const uint32_t freq = g_eeprom.fm_frequency_playing; + const uint32_t freq = g_eeprom.config.setting.fm_radio.selected_frequency; NUMBER_ToDigits(freq * 10000, str); #ifdef ENABLE_TRIM_TRAILING_ZEROS UI_DisplayFrequency(str, 30, 4, false, true); @@ -132,8 +132,8 @@ void UI_DisplayFM(void) } else { // delete channel - const uint32_t chan = g_eeprom.fm_selected_channel; - const uint32_t freq = g_fm_channels[chan]; + const uint32_t chan = g_eeprom.config.setting.fm_radio.selected_channel; + const uint32_t freq = g_eeprom.config.setting.fm_channel[chan]; sprintf(str, "CH %u (%u.%u)", 1 + chan, freq / 10, freq % 10); } diff --git a/ui/lock.c b/ui/lock.c index 7bcb651..7c92ee1 100644 --- a/ui/lock.c +++ b/ui/lock.c @@ -107,7 +107,7 @@ void UI_DisplayLock(void) NUMBER_Get(g_input_box, &Password); - if ((g_eeprom.power_on_password * 100) == Password) + if ((g_eeprom.config.setting.power_on_password * 100) == Password) { AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL); return; diff --git a/ui/main.c b/ui/main.c index 91b685f..b06c658 100644 --- a/ui/main.c +++ b/ui/main.c @@ -85,11 +85,11 @@ void draw_bar(uint8_t *line, const int len, const int max_width) if (g_center_line != CENTER_LINE_NONE && g_center_line != CENTER_LINE_TX_TIMEOUT) return false; - if (g_eeprom.tx_timeout_timer == 0) + if (g_eeprom.config.setting.tx_timeout == 0) timeout_secs = 30; // 30 sec else - if (g_eeprom.tx_timeout_timer < (ARRAY_SIZE(g_sub_menu_tx_timeout) - 1)) - timeout_secs = 60 * g_eeprom.tx_timeout_timer; // minutes + if (g_eeprom.config.setting.tx_timeout < (ARRAY_SIZE(g_sub_menu_tx_timeout) - 1)) + timeout_secs = 60 * g_eeprom.config.setting.tx_timeout; // minutes else timeout_secs = 60 * 15; // 15 minutes @@ -182,7 +182,7 @@ void UI_drawBars(uint8_t *p, const unsigned int level) return false; #endif - if (g_setting_mic_bar) + if (g_eeprom.config.setting.mic_bar) { const unsigned int line = 3; const unsigned int txt_width = 7 * 3; // 3 text chars @@ -230,7 +230,7 @@ void UI_drawBars(uint8_t *p, const unsigned int level) #ifdef ENABLE_RX_SIGNAL_BAR bool UI_DisplayRSSIBar(const int16_t rssi, const bool now) { - if (g_setting_rssi_bar) + if (g_eeprom.config.setting.enable_rssi_bar) { // const int16_t s0_dBm = -127; // S0 .. base level const int16_t s0_dBm = -147; // S0 .. base level @@ -365,7 +365,7 @@ void UI_update_rssi(const int16_t rssi, const int vfo) // ********************************************************** #ifdef ENABLE_KEYLOCK - if (g_eeprom.key_lock && g_keypad_locked > 0) + if (g_eeprom.config.setting.key_lock && g_keypad_locked > 0) return; // display is in use #endif @@ -428,7 +428,7 @@ void UI_DisplayMain(void) g_center_line = CENTER_LINE_NONE; // #ifdef SINGLE_VFO_CHAN -// const bool single_vfo = (g_eeprom.dual_watch == DUAL_WATCH_OFF && g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? true : false; +// const bool single_vfo = (g_eeprom.config.setting.dual_watch == DUAL_WATCH_OFF && g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? true : false; // #else const bool single_vfo = false; // #endif @@ -446,7 +446,7 @@ void UI_DisplayMain(void) } #ifdef ENABLE_KEYLOCK - if (g_eeprom.key_lock && g_keypad_locked > 0) + if (g_eeprom.config.setting.key_lock && g_keypad_locked > 0) { // tell user how to unlock the keyboard backlight_turn_on(10); // 5 seconds UI_PrintString("Long press #", 0, LCD_WIDTH, 1, 8); @@ -458,9 +458,10 @@ void UI_DisplayMain(void) for (vfo_num = 0; vfo_num < 2; vfo_num++) { + const unsigned int scrn_chan = g_eeprom.config.setting.indices.vfo[vfo_num].screen; const unsigned int line = (vfo_num == 0) ? line0 : line1; - unsigned int channel = g_eeprom.tx_vfo; -// unsigned int tx_channel = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_eeprom.rx_vfo : g_eeprom.tx_vfo; + unsigned int channel = g_eeprom.config.setting.tx_vfo_num; +// unsigned int tx_channel = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_rx_vfo_num : g_eeprom.config.setting.tx_vfo_num; const bool same_vfo = (channel == vfo_num) ? true : false; uint8_t *p_line0 = g_frame_buffer[line + 0]; uint8_t *p_line1 = g_frame_buffer[line + 1]; @@ -476,8 +477,8 @@ void UI_DisplayMain(void) } - if (g_eeprom.dual_watch != DUAL_WATCH_OFF && g_rx_vfo_is_active) - channel = g_eeprom.rx_vfo; // we're currently monitoring the other VFO + if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF && g_rx_vfo_is_active) + channel = g_rx_vfo_num; // we're currently monitoring the other VFO if (channel != vfo_num) { @@ -547,7 +548,7 @@ void UI_DisplayMain(void) if (!single_vfo && same_vfo) memcpy(p_line0 + 0, BITMAP_VFO_DEFAULT, sizeof(BITMAP_VFO_DEFAULT)); else - if (g_eeprom.cross_vfo_rx_tx != CROSS_BAND_OFF) + if (g_eeprom.config.setting.cross_vfo != CROSS_BAND_OFF) memcpy(p_line0 + 0, BITMAP_VFO_NOT_DEFAULT, sizeof(BITMAP_VFO_NOT_DEFAULT)); } else @@ -556,7 +557,7 @@ void UI_DisplayMain(void) if (same_vfo) memcpy(p_line0 + 0, BITMAP_VFO_DEFAULT, sizeof(BITMAP_VFO_DEFAULT)); else - //if (g_eeprom.cross_vfo_rx_tx != CROSS_BAND_OFF) + //if (g_eeprom.config.setting.cross_vfo != CROSS_BAND_OFF) memcpy(p_line0 + 0, BITMAP_VFO_NOT_DEFAULT, sizeof(BITMAP_VFO_NOT_DEFAULT)); } @@ -569,7 +570,7 @@ void UI_DisplayMain(void) else #endif { - channel = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_eeprom.rx_vfo : g_eeprom.tx_vfo; + channel = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_rx_vfo_num : g_eeprom.config.setting.tx_vfo_num; if (channel == vfo_num) { // show the TX symbol mode = 1; @@ -584,7 +585,7 @@ void UI_DisplayMain(void) else { // receiving .. show the RX symbol mode = 2; - if ((g_current_function == FUNCTION_RECEIVE && g_squelch_open) && g_eeprom.rx_vfo == vfo_num) + if ((g_current_function == FUNCTION_RECEIVE && g_squelch_open) && g_rx_vfo_num == vfo_num) { #ifdef ENABLE_SMALL_BOLD UI_PrintStringSmallBold("RX", 14, 0, line); @@ -594,32 +595,32 @@ void UI_DisplayMain(void) } } - if (g_eeprom.screen_channel[vfo_num] <= USER_CHANNEL_LAST) + if (scrn_chan <= USER_CHANNEL_LAST) { // channel mode const unsigned int x = 2; - const bool inputting = (g_input_box_index == 0 || g_eeprom.tx_vfo != vfo_num) ? false : true; + const bool inputting = (g_input_box_index == 0 || g_eeprom.config.setting.tx_vfo_num != vfo_num) ? false : true; if (!inputting) - NUMBER_ToDigits(g_eeprom.screen_channel[vfo_num] + 1, str); // show the memory channel number + NUMBER_ToDigits(scrn_chan + 1, str); // show the memory channel number else memcpy(str + 5, g_input_box, 3); // show the input text UI_PrintStringSmall("M", x, 0, line + 1); UI_Displaysmall_digits(3, str + 5, x + 7, line + 1, inputting); } else - if (IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo_num])) + if (IS_FREQ_CHANNEL(scrn_chan)) { // frequency mode // show the frequency band number const unsigned int x = 2; // was 14 -// sprintf(String, "FB%u", 1 + g_eeprom.screen_channel[vfo_num] - FREQ_CHANNEL_FIRST); - sprintf(str, "VFO%u", 1 + g_eeprom.screen_channel[vfo_num] - FREQ_CHANNEL_FIRST); +// sprintf(String, "FB%u", 1 + scrn_chan - FREQ_CHANNEL_FIRST); + sprintf(str, "VFO%u", 1 + scrn_chan - FREQ_CHANNEL_FIRST); UI_PrintStringSmall(str, x, 0, line + 1); } #ifdef ENABLE_NOAA else { - if (g_input_box_index == 0 || g_eeprom.tx_vfo != vfo_num) + if (g_input_box_index == 0 || g_eeprom.config.setting.tx_vfo_num != vfo_num) { // channel number - sprintf(str, "N%u", 1 + g_eeprom.screen_channel[vfo_num] - NOAA_CHANNEL_FIRST); + sprintf(str, "N%u", 1 + scrn_chan - NOAA_CHANNEL_FIRST); } else { // user entering channel number @@ -636,7 +637,7 @@ void UI_DisplayMain(void) #ifdef ENABLE_ALARM if (g_current_function == FUNCTION_TRANSMIT && g_alarm_state == ALARM_STATE_ALARM) { - channel = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_eeprom.rx_vfo : g_eeprom.tx_vfo; + channel = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_rx_vfo_num : g_eeprom.config.setting.tx_vfo_num; if (channel == vfo_num) state = VFO_STATE_ALARM; } @@ -649,7 +650,7 @@ void UI_DisplayMain(void) UI_PrintString(state_list[state], 31, 0, line, 8); } else - if (g_input_box_index > 0 && IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo_num]) && g_eeprom.tx_vfo == vfo_num) + if (g_input_box_index > 0 && IS_FREQ_CHANNEL(scrn_chan) && g_eeprom.config.setting.tx_vfo_num == vfo_num) { // user entering a frequency UI_DisplayFrequency(g_input_box, 32, line, true, false); @@ -659,18 +660,18 @@ void UI_DisplayMain(void) { const unsigned int x = 32; - uint32_t frequency = g_eeprom.vfo_info[vfo_num].p_rx->frequency; + uint32_t frequency = g_vfo_info[vfo_num].p_rx->frequency; if (g_current_function == FUNCTION_TRANSMIT) { // transmitting - channel = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_eeprom.rx_vfo : g_eeprom.tx_vfo; + channel = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_rx_vfo_num : g_eeprom.config.setting.tx_vfo_num; if (channel == vfo_num) - frequency = g_eeprom.vfo_info[vfo_num].p_tx->frequency; + frequency = g_vfo_info[vfo_num].p_tx->frequency; } - if (g_eeprom.screen_channel[vfo_num] <= USER_CHANNEL_LAST) + if (scrn_chan <= USER_CHANNEL_LAST) { // it's a channel - switch (g_eeprom.channel_display_mode) + switch (g_eeprom.config.setting.channel_display_mode) { case MDF_FREQUENCY: // just channel frequency @@ -689,7 +690,7 @@ void UI_DisplayMain(void) case MDF_CHANNEL: // just channel number - sprintf(str, "CH-%03u", g_eeprom.screen_channel[vfo_num] + 1); + sprintf(str, "CH-%03u", scrn_chan + 1); UI_PrintString(str, x, 0, line, 8); break; @@ -697,13 +698,13 @@ void UI_DisplayMain(void) case MDF_NAME: // channel name case MDF_NAME_FREQ: // channel name and frequency - BOARD_fetchChannelName(str, g_eeprom.screen_channel[vfo_num]); + SETTINGS_fetch_channel_name(str, scrn_chan); if (str[0] == 0) { // no channel name available, channel number instead - sprintf(str, "CH-%03u", 1 + g_eeprom.screen_channel[vfo_num]); + sprintf(str, "CH-%03u", 1 + scrn_chan); } - if (g_eeprom.channel_display_mode == MDF_NAME) + if (g_eeprom.config.setting.channel_display_mode == MDF_NAME) { // just the name UI_PrintString(str, x + 4, 0, line, 8); } @@ -729,7 +730,7 @@ void UI_DisplayMain(void) } } else -// if (IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo_num])) +// if (IS_FREQ_CHANNEL(scrn_chan)) { // frequency mode #ifdef ENABLE_BIG_FREQ big_freq(frequency, x, line); @@ -747,19 +748,19 @@ void UI_DisplayMain(void) // show channel symbols - if (g_eeprom.screen_channel[vfo_num] <= USER_CHANNEL_LAST) - //if (IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[vfo_num])) + if (scrn_chan <= USER_CHANNEL_LAST) + //if (IS_NOT_NOAA_CHANNEL(scrn_chan)) { // it's a user channel or VFO unsigned int x = LCD_WIDTH - 1 - sizeof(BITMAP_SCANLIST2) - sizeof(BITMAP_SCANLIST1); - const uint8_t attributes = g_user_channel_attributes[g_eeprom.screen_channel[vfo_num]]; + const t_channel_attrib attributes = g_user_channel_attributes[scrn_chan]; - if (attributes & USER_CH_SCANLIST1) + if (attributes.scanlist1) memcpy(p_line0 + x, BITMAP_SCANLIST1, sizeof(BITMAP_SCANLIST1)); x += sizeof(BITMAP_SCANLIST1); - if (attributes & USER_CH_SCANLIST2) + if (attributes.scanlist2) memcpy(p_line0 + x, BITMAP_SCANLIST2, sizeof(BITMAP_SCANLIST2)); //x += sizeof(BITMAP_SCANLIST2); } @@ -772,35 +773,35 @@ void UI_DisplayMain(void) { unsigned int x = LCD_WIDTH + LCD_WIDTH - 1 - (smallest_char_spacing * 1) - (smallest_char_spacing * 4); - if (IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo_num])) + if (IS_FREQ_CHANNEL(scrn_chan)) { - //g_eeprom.vfo_info[vfo_num].freq_in_channel = BOARD_find_channel(frequency); - if (g_eeprom.vfo_info[vfo_num].freq_in_channel <= USER_CHANNEL_LAST) + //g_vfo_info[vfo_num].freq_in_channel = SETTINGS_find_channel(frequency); + if (g_vfo_info[vfo_num].freq_in_channel <= USER_CHANNEL_LAST) { // the channel number that contains this VFO frequency - sprintf(str, "%03u", 1 + g_eeprom.vfo_info[vfo_num].freq_in_channel); + sprintf(str, "%03u", 1 + g_vfo_info[vfo_num].freq_in_channel); UI_PrintStringSmallest(str, x, (line + 0) * 8, false, true); } } x += smallest_char_spacing * 4; - if (g_eeprom.vfo_info[vfo_num].compand) + if (g_vfo_info[vfo_num].compand) UI_PrintStringSmallest("C", x, (line + 0) * 8, false, true); //x += smallest_char_spacing * 1; } #else { - 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 + const bool is_freq_chan = IS_FREQ_CHANNEL(scrn_chan); + const uint8_t freq_in_channel = g_vfo_info[vfo_num].freq_in_channel; +// const uint8_t freq_in_channel = SETTINGS_find_channel(frequency); // currently way to slow - if (g_eeprom.vfo_info[vfo_num].compand) + if (g_vfo_info[vfo_num].compand) { strcpy(str, " "); if (is_freq_chan && freq_in_channel <= USER_CHANNEL_LAST) str[0] = 'F'; // channel number that contains this VFO frequency - if (g_eeprom.vfo_info[vfo_num].compand) + if (g_vfo_info[vfo_num].compand) str[1] = 'C'; // compander is enabled UI_PrintStringSmall(str, LCD_WIDTH - (7 * 2), 0, line + 1); @@ -844,10 +845,10 @@ void UI_DisplayMain(void) // ************ str[0] = '\0'; - if (g_eeprom.vfo_info[vfo_num].am_mode > 0) + if (g_vfo_info[vfo_num].am_mode > 0) { - //strcpy(str, g_sub_menu_mod_mode[g_eeprom.vfo_info[vfo_num].am_mode]); - switch (g_eeprom.vfo_info[vfo_num].am_mode) + //strcpy(str, g_sub_menu_mod_mode[g_vfo_info[vfo_num].am_mode]); + switch (g_vfo_info[vfo_num].am_mode) { default: case 0: strcpy(str, "FM"); break; @@ -857,7 +858,7 @@ void UI_DisplayMain(void) } else { // or show the CTCSS/DCS symbol - const freq_config_t *pConfig = (mode == 1) ? g_eeprom.vfo_info[vfo_num].p_tx : g_eeprom.vfo_info[vfo_num].p_rx; + const freq_config_t *pConfig = (mode == 1) ? g_vfo_info[vfo_num].p_tx : g_vfo_info[vfo_num].p_rx; const unsigned int code_type = pConfig->code_type; const char *code_list[] = {"", "CT", "DCS", "DCR"}; if (code_type < ARRAY_SIZE(code_list)) @@ -868,22 +869,22 @@ void UI_DisplayMain(void) #ifdef ENABLE_TX_WHEN_AM if (state == VFO_STATE_NORMAL || state == VFO_STATE_ALARM) #else - if ((state == VFO_STATE_NORMAL || state == VFO_STATE_ALARM) && g_eeprom.vfo_info[vfo_num].am_mode == 0) // not allowed to TX if not in FM mode + if ((state == VFO_STATE_NORMAL || state == VFO_STATE_ALARM) && g_vfo_info[vfo_num].am_mode == 0) // not allowed to TX if not in FM mode #endif { - if (FREQUENCY_tx_freq_check(g_eeprom.vfo_info[vfo_num].p_tx->frequency) == 0) + if (FREQUENCY_tx_freq_check(g_vfo_info[vfo_num].p_tx->frequency) == 0) { // show the TX power const char pwr_list[] = "LMH"; - const unsigned int i = g_eeprom.vfo_info[vfo_num].output_power; + const unsigned int i = g_vfo_info[vfo_num].output_power; str[0] = (i < ARRAY_SIZE(pwr_list)) ? pwr_list[i] : '\0'; str[1] = '\0'; UI_PrintStringSmall(str, LCD_WIDTH + 46, 0, line + 1); - if (g_eeprom.vfo_info[vfo_num].freq_config_rx.frequency != g_eeprom.vfo_info[vfo_num].freq_config_tx.frequency) + if (g_vfo_info[vfo_num].freq_config_rx.frequency != g_vfo_info[vfo_num].freq_config_tx.frequency) { // show the TX offset symbol const char dir_list[] = "\0+-"; - const unsigned int i = g_eeprom.vfo_info[vfo_num].tx_offset_freq_dir; + const unsigned int i = g_vfo_info[vfo_num].tx_offset_freq_dir; str[0] = (i < sizeof(dir_list)) ? dir_list[i] : '?'; str[1] = '\0'; UI_PrintStringSmall(str, LCD_WIDTH + 54, 0, line + 1); @@ -892,12 +893,12 @@ void UI_DisplayMain(void) } // show the TX/RX reverse symbol - if (g_eeprom.vfo_info[vfo_num].frequency_reverse) + if (g_vfo_info[vfo_num].frequency_reverse) UI_PrintStringSmall("R", LCD_WIDTH + 62, 0, line + 1); { // show the narrow band symbol str[0] = '\0'; - if (g_eeprom.vfo_info[vfo_num].channel_bandwidth == BANDWIDTH_NARROW) + if (g_vfo_info[vfo_num].channel_bandwidth == BANDWIDTH_NARROW) { str[0] = 'N'; str[1] = '\0'; @@ -907,17 +908,17 @@ void UI_DisplayMain(void) // show the DTMF decoding symbol #ifdef ENABLE_KILL_REVIVE - if (g_eeprom.vfo_info[vfo_num].dtmf_decoding_enable || g_setting_radio_disabled) + if (g_vfo_info[vfo_num].dtmf_decoding_enable || g_eeprom.config.setting.radio_disabled) UI_PrintStringSmall("DTMF", LCD_WIDTH + 78, 0, line + 1); #else - if (g_eeprom.vfo_info[vfo_num].dtmf_decoding_enable) + if (g_vfo_info[vfo_num].dtmf_decoding_enable) UI_PrintStringSmall("DTMF", LCD_WIDTH + 78, 0, line + 1); //UI_PrintStringSmall4x5("DTMF", LCD_WIDTH + 78, 0, line + 1); // font table is currently wrong //UI_PrintStringSmallest("DTMF", LCD_WIDTH + 78, (line + 1) * 8, false, true); #endif // show the audio scramble symbol - if (g_eeprom.vfo_info[vfo_num].scrambling_type > 0 && g_setting_scramble_enable) + if (g_vfo_info[vfo_num].scrambling_type > 0 && g_eeprom.config.setting.enable_scrambler) UI_PrintStringSmall("SCR", LCD_WIDTH + 106, 0, line + 1); } @@ -966,10 +967,10 @@ void UI_DisplayMain(void) #if defined(ENABLE_AM_FIX) && defined(ENABLE_AM_FIX_SHOW_DATA) // show the AM-FIX debug data - if (rx && g_eeprom.vfo_info[g_eeprom.rx_vfo].am_mode > 0 && g_setting_am_fix) + if (rx && g_vfo_info[g_rx_vfo_num].am_mode > 0 && g_eeprom.config.setting.am_fix) { g_center_line = CENTER_LINE_AM_FIX_DATA; - AM_fix_print_data(g_eeprom.rx_vfo, str); + AM_fix_print_data(g_rx_vfo_num, str); UI_PrintStringSmall(str, 2, 0, 3); } else @@ -977,10 +978,10 @@ void UI_DisplayMain(void) #ifdef ENABLE_RX_SIGNAL_BAR // show the RX RSSI dBm, S-point and signal strength bar graph - if (rx && g_setting_rssi_bar) + if (rx && g_eeprom.config.setting.enable_rssi_bar) { g_center_line = CENTER_LINE_RSSI; - UI_DisplayRSSIBar(g_current_rssi[g_eeprom.rx_vfo], false); + UI_DisplayRSSIBar(g_current_rssi[g_rx_vfo_num], false); } else #endif @@ -988,7 +989,7 @@ void UI_DisplayMain(void) if (rx || g_current_function == FUNCTION_FOREGROUND || g_current_function == FUNCTION_POWER_SAVE) { #if 1 - if (g_setting_live_dtmf_decoder && g_dtmf_rx_live[0] != 0) + if (g_eeprom.config.setting.dtmf_live_decoder && g_dtmf_rx_live[0] != 0) { // show live DTMF decode const unsigned int len = strlen(g_dtmf_rx_live); const unsigned int idx = (len > (17 - 5)) ? len - (17 - 5) : 0; // limit to last 'n' chars @@ -1003,7 +1004,7 @@ void UI_DisplayMain(void) UI_PrintStringSmall(str, 2, 0, 3); } #else - if (g_setting_live_dtmf_decoder && g_dtmf_rx_index > 0) + if (g_eeprom.config.setting.dtmf_live_decoder && g_dtmf_rx_index > 0) { // show live DTMF decode const unsigned int len = g_dtmf_rx_index; const unsigned int idx = (len > (17 - 5)) ? len - (17 - 5) : 0; // limit to last 'n' chars diff --git a/ui/menu.c b/ui/menu.c index 2834d00..ab1547f 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -21,7 +21,7 @@ #include "dcs.h" #include "driver/backlight.h" #include "driver/bk4819.h" -#include "driver/eeprom.h" // EEPROM_ReadBuffer() +#include "driver/eeprom.h" #include "driver/st7565.h" #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) #include "driver/uart.h" @@ -283,12 +283,12 @@ const char g_sub_menu_dtmf_rsp[4][9] = "RNG RPLY" }; -const char g_sub_menu_ptt_id[5][15] = +const char g_sub_menu_ptt_id[5][16] = { - "OFF", - "BOT", - "EOT", - "BOT+EOT", + "DTMF ID\nOFF", + "DTMF ID\nBOT", + "DTMF ID\nEOT", + "DTMF ID\nBOT+EOT", "APOLLO\nQUINDAR" }; @@ -469,9 +469,10 @@ void UI_SortMenu(const bool hide_hidden) void UI_DisplayMenu(void) { - const unsigned int menu_list_width = 6; // max no. of characters on the menu list (left side) + const unsigned int menu_list_width = 6; // max no. of characters on the menu list (left side) const unsigned int sub_menu_x1 = (8 * menu_list_width) + 2; // start x corrd const unsigned int sub_menu_x2 = LCD_WIDTH - 1; // end x coord + bool channel_setting = false; // set if the setting is a channel setting unsigned int i; char str[64]; // bigger cuz we can now do multi-line in one string (use '\n' char) @@ -573,6 +574,7 @@ void UI_DisplayMenu(void) sprintf(str, "%d", g_sub_menu_selection); // g_tx_vfo->squelch_level = g_sub_menu_selection; // RADIO_ConfigureSquelchAndOutputPower(g_tx_vfo); + channel_setting = true; break; case MENU_MIC_GAIN: @@ -596,11 +598,13 @@ void UI_DisplayMenu(void) NUMBER_trim_trailing_zeros(str); strcat(str, "kHz"); } + channel_setting = true; break; } case MENU_TX_POWER: strcpy(str, g_sub_menu_tx_power[g_sub_menu_selection]); + channel_setting = true; break; case MENU_RX_CDCSS: @@ -613,11 +617,13 @@ void UI_DisplayMenu(void) sprintf(str + strlen(str), "D%03oN", DCS_CODE_LIST[g_sub_menu_selection - 1]); else sprintf(str + strlen(str), "D%03oI", DCS_CODE_LIST[g_sub_menu_selection - 105]); + channel_setting = true; break; case MENU_RX_CTCSS: case MENU_TX_CTCSS: { + channel_setting = true; strcpy(str, "CTCSS\n"); #if 1 // set CTCSS as the user adjusts it @@ -658,9 +664,11 @@ void UI_DisplayMenu(void) case MENU_SHIFT_DIR: strcpy(str, g_sub_menu_shift_dir[g_sub_menu_selection]); + channel_setting = true; break; case MENU_OFFSET: + channel_setting = true; if (!g_in_sub_menu || g_input_box_index == 0) { sprintf(str, "%d.%05u", g_sub_menu_selection / 100000, abs(g_sub_menu_selection) % 100000); @@ -692,6 +700,7 @@ void UI_DisplayMenu(void) case MENU_BANDWIDTH: strcpy(str, g_sub_menu_bandwidth[g_sub_menu_selection]); + channel_setting = true; break; case MENU_SCRAMBLER: @@ -699,11 +708,12 @@ void UI_DisplayMenu(void) strcat(str, g_sub_menu_scrambler[g_sub_menu_selection]); #if 1 - if (g_sub_menu_selection > 0 && g_setting_scramble_enable) + if (g_sub_menu_selection > 0 && g_eeprom.config.setting.enable_scrambler) BK4819_EnableScramble(g_sub_menu_selection - 1); else BK4819_DisableScramble(); #endif + channel_setting = true; break; #ifdef ENABLE_VOX @@ -728,12 +738,13 @@ void UI_DisplayMenu(void) case MENU_MOD_MODE: // strcpy(str, (g_sub_menu_selection == 0) ? "FM" : "AM"); strcpy(str, g_sub_menu_mod_mode[g_sub_menu_selection]); + channel_setting = true; break; #ifdef ENABLE_AM_FIX_TEST1 case MENU_AM_FIX_TEST1: strcpy(str, g_sub_menu_AM_FIX_test1[g_sub_menu_selection]); -// g_setting_am_fix = g_sub_menu_selection; +// g_eeprom.config.setting.am_fix = g_sub_menu_selection; break; #endif @@ -748,6 +759,7 @@ void UI_DisplayMenu(void) case MENU_COMPAND: strcpy(str, g_sub_menu_rx_tx[g_sub_menu_selection]); + channel_setting = true; break; #ifdef ENABLE_CONTRAST @@ -772,6 +784,7 @@ void UI_DisplayMenu(void) case MENU_S_ADD1: case MENU_S_ADD2: strcpy(str, g_sub_menu_off_on[g_sub_menu_selection]); + channel_setting = true; break; case MENU_BUSY_CHAN_LOCK: @@ -830,6 +843,7 @@ void UI_DisplayMenu(void) case MENU_SCRAMBLER_EN: strcpy(str, "SCRAMBLER\n"); strcat(str, g_sub_menu_dis_en[g_sub_menu_selection]); + channel_setting = true; break; case MENU_TX_EN: @@ -847,13 +861,13 @@ void UI_DisplayMenu(void) UI_GenerateChannelStringEx(str, valid ? "CH-" : "", g_sub_menu_selection); // channel name - BOARD_fetchChannelName(s, g_sub_menu_selection); + SETTINGS_fetch_channel_name(s, g_sub_menu_selection); strcat(str, "\n"); strcat(str, (s[0] == 0) ? "--" : s); if (valid && !g_ask_for_confirmation) { // show the frequency so that the user knows the channels frequency - const uint32_t frequency = BOARD_fetchChannelFrequency(g_sub_menu_selection); + const uint32_t frequency = SETTINGS_fetch_channel_frequency(g_sub_menu_selection); sprintf(str + strlen(str), "\n%u.%05u", frequency / 100000, frequency % 100000); #ifdef ENABLE_TRIM_TRAILING_ZEROS @@ -861,6 +875,7 @@ void UI_DisplayMenu(void) #endif } + channel_setting = (g_menu_cursor != MENU_1_CALL) ? true : false; break; } @@ -874,11 +889,11 @@ void UI_DisplayMenu(void) if (valid) { - const uint32_t frequency = BOARD_fetchChannelFrequency(g_sub_menu_selection); + const uint32_t frequency = SETTINGS_fetch_channel_frequency(g_sub_menu_selection); if (!g_in_sub_menu || g_edit_index < 0) { // show the channel name - BOARD_fetchChannelName(str, g_sub_menu_selection); + SETTINGS_fetch_channel_name(str, g_sub_menu_selection); if (str[0] == 0) strcpy(str, "--"); UI_PrintString(str, sub_menu_x1, sub_menu_x2, y + 2, 8); @@ -901,6 +916,7 @@ void UI_DisplayMenu(void) } already_printed = true; + channel_setting = true; break; } @@ -931,7 +947,7 @@ void UI_DisplayMenu(void) strcpy(str, "SCAN\nRESUME\n"); strcat(str, g_sub_menu_scan_car_resume[g_sub_menu_selection]); if (g_sub_menu_selection == SCAN_RESUME_TIME) - sprintf(str + strlen(str), "%d.%ds", g_eeprom.scan_hold_time_500ms / 2, 5 * (g_eeprom.scan_hold_time_500ms % 2)); + sprintf(str + strlen(str), "%d.%ds", g_eeprom.config.setting.scan_hold_time / 2, 5 * (g_eeprom.config.setting.scan_hold_time % 2)); break; case MENU_SCAN_HOLD: @@ -951,10 +967,11 @@ void UI_DisplayMenu(void) break; case MENU_S_LIST: + strcpy(str, "SCAN LIST\n"); if (g_sub_menu_selection < 2) - sprintf(str, "LIST%u", 1 + g_sub_menu_selection); + sprintf(str + strlen(str), "LIST%u", 1 + g_sub_menu_selection); else - strcpy(str, "ALL"); + strcat(str, "ALL"); break; #ifdef ENABLE_ALARM @@ -966,17 +983,17 @@ void UI_DisplayMenu(void) case MENU_ANI_ID: strcpy(str, "YOUR ID\n"); - strcat(str, g_eeprom.ani_dtmf_id); + strcat(str, g_eeprom.config.setting.dtmf.ani_id); break; case MENU_UP_CODE: - strcpy(str, "PTT DTMF\nBEGIN\n"); - strcat(str, g_eeprom.dtmf_key_up_code); + strcpy(str, "DTMF BOT\n"); + strcat(str, g_eeprom.config.setting.dtmf.key_up_code); break; case MENU_DN_CODE: - strcpy(str, "PTT DTMF\nEND\n"); - strcat(str, g_eeprom.dtmf_key_down_code); + strcpy(str, "DTMF EOT\n"); + strcat(str, g_eeprom.config.setting.dtmf.key_down_code); break; case MENU_DTMF_RSP: @@ -1013,7 +1030,7 @@ void UI_DisplayMenu(void) break; case MENU_DTMF_PRE: - strcpy(str, "TX DTMF\nDELAY\n"); + strcpy(str, "DTMF BOT\nDELAY\n"); // sprintf(String + strlen(String), "%d*10ms", g_sub_menu_selection); sprintf(str + strlen(str), "%dms", 10 * g_sub_menu_selection); break; @@ -1022,6 +1039,7 @@ void UI_DisplayMenu(void) case MENU_MDC1200_MODE: strcpy(str, "MDC1200\nMODE\n"); strcat(str, g_sub_menu_mdc1200_mode[g_sub_menu_selection]); + channel_setting = true; break; case MENU_MDC1200_ID: @@ -1030,8 +1048,8 @@ void UI_DisplayMenu(void) #endif case MENU_PTT_ID: - strcpy(str, (g_sub_menu_selection > 0) ? "TX ID\n" : ""); - strcat(str, g_sub_menu_ptt_id[g_sub_menu_selection]); + strcpy(str, g_sub_menu_ptt_id[g_sub_menu_selection]); + channel_setting = true; break; case MENU_BAT_TXT: @@ -1178,11 +1196,11 @@ void UI_DisplayMenu(void) case MENU_BAT_CAL: { - const uint16_t vol = (uint32_t)g_battery_voltage_average * g_battery_calibration[3] / g_sub_menu_selection; + const uint16_t vol = (uint32_t)g_battery_voltage_average * g_eeprom.calib.battery[3] / g_sub_menu_selection; if (!g_in_sub_menu) sprintf(str, "%u.%02uV\n%d", vol / 100, vol % 100, g_sub_menu_selection); else - sprintf(str, "%u.%02uV\n(%#4d)\n%#4d", vol / 100, vol % 100, g_battery_calibration[3], g_sub_menu_selection); + sprintf(str, "%u.%02uV\n(%#4d)\n%#4d", vol / 100, vol % 100, g_eeprom.calib.battery[3], g_sub_menu_selection); break; } } @@ -1251,14 +1269,14 @@ void UI_DisplayMenu(void) else UI_GenerateChannelStringEx(str, "CH-", g_sub_menu_selection); -// if (g_sub_menu_selection == 0xFF || !g_eeprom.scan_list_enabled[i]) - if (g_sub_menu_selection < 0 || !g_eeprom.scan_list_enabled[i]) +// if (g_sub_menu_selection == 0xFF || g_eeprom.config.setting.priority_scan_list[i].enabled == 0) + if (g_sub_menu_selection < 0 || g_eeprom.config.setting.priority_scan_list[i].enabled == 0) { // channel number UI_PrintString(str, sub_menu_x1, sub_menu_x2, 0, 8); // channel name - BOARD_fetchChannelName(str, g_sub_menu_selection); + SETTINGS_fetch_channel_name(str, g_sub_menu_selection); if (str[0] == 0) strcpy(str, "--"); UI_PrintString(str, sub_menu_x1, sub_menu_x2, 2, 8); @@ -1270,20 +1288,20 @@ void UI_DisplayMenu(void) // channel name memset(str, 0, sizeof(str)); - BOARD_fetchChannelName(str, g_sub_menu_selection); + SETTINGS_fetch_channel_name(str, g_sub_menu_selection); if (str[0] == 0) strcpy(str, "--"); UI_PrintStringSmall(str, sub_menu_x1, sub_menu_x2, 2); - if (IS_USER_CHANNEL(g_eeprom.scan_list_priority_ch1[i])) + if (IS_USER_CHANNEL(g_eeprom.config.setting.priority_scan_list[i].channel[0])) { - sprintf(str, "PRI1:%u", g_eeprom.scan_list_priority_ch1[i] + 1); + sprintf(str, "PRI1:%u", 1 + g_eeprom.config.setting.priority_scan_list[i].channel[0]); UI_PrintString(str, sub_menu_x1, sub_menu_x2, 3, 8); } - if (IS_USER_CHANNEL(g_eeprom.scan_list_priority_ch2[i])) + if (IS_USER_CHANNEL(g_eeprom.config.setting.priority_scan_list[i].channel[1])) { - sprintf(str, "PRI2:%u", g_eeprom.scan_list_priority_ch2[i] + 1); + sprintf(str, "PRI2:%u", 1 + g_eeprom.config.setting.priority_scan_list[i].channel[1]); UI_PrintString(str, sub_menu_x1, sub_menu_x2, 5, 8); } } @@ -1293,12 +1311,12 @@ void UI_DisplayMenu(void) UI_PrintString("SCAN", sub_menu_x1, sub_menu_x2, 4, 8); if (g_menu_cursor == MENU_UP_CODE) - if (strlen(g_eeprom.dtmf_key_up_code) > 8) - UI_PrintString(g_eeprom.dtmf_key_up_code + 8, sub_menu_x1, sub_menu_x2, 4, 8); + if (strlen(g_eeprom.config.setting.dtmf.key_up_code) > 8) + UI_PrintString(g_eeprom.config.setting.dtmf.key_up_code + 8, sub_menu_x1, sub_menu_x2, 4, 8); if (g_menu_cursor == MENU_DN_CODE) - if (strlen(g_eeprom.dtmf_key_down_code) > 8) - UI_PrintString(g_eeprom.dtmf_key_down_code + 8, sub_menu_x1, sub_menu_x2, 4, 8); + if (strlen(g_eeprom.config.setting.dtmf.key_down_code) > 8) + UI_PrintString(g_eeprom.config.setting.dtmf.key_down_code + 8, sub_menu_x1, sub_menu_x2, 4, 8); if (g_menu_cursor == MENU_RX_CTCSS || g_menu_cursor == MENU_TX_CTCSS || @@ -1324,5 +1342,8 @@ void UI_DisplayMenu(void) UI_PrintString(str, sub_menu_x1, sub_menu_x2, 5, 8); } + if (channel_setting) + UI_PrintStringSmall("ch", sub_menu_x1, 0, 0); + ST7565_BlitFullScreen(); } diff --git a/ui/menu.h b/ui/menu.h index 7bd43fd..3debb9d 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -180,7 +180,7 @@ extern const char g_sub_menu_mem_disp[4][15]; extern const char g_sub_menu_alarm_mode[2][5]; #endif extern const char g_sub_menu_dtmf_rsp[4][9]; -extern const char g_sub_menu_ptt_id[5][15]; +extern const char g_sub_menu_ptt_id[5][16]; #ifdef ENABLE_MDC1200 extern const char g_sub_menu_mdc1200_mode[4][8]; #endif diff --git a/ui/search.c b/ui/search.c index 142a825..7954f15 100644 --- a/ui/search.c +++ b/ui/search.c @@ -22,6 +22,7 @@ #include "frequencies.h" #include "misc.h" #include "radio.h" +#include "settings.h" #include "ui/helper.h" #include "ui/search.h" #include "ui/ui.h" @@ -161,7 +162,7 @@ void UI_DisplaySearch(void) strcpy(String, "SAVE "); { char s[11]; - BOARD_fetchChannelName(s, g_search_channel); + SETTINGS_fetch_channel_name(s, g_search_channel); if (s[0] == 0) UI_GenerateChannelStringEx(s, g_search_show_chan_prefix ? "CH-" : "", g_search_channel); strcat(String, s); diff --git a/ui/status.c b/ui/status.c index c498f35..d3ba621 100644 --- a/ui/status.c +++ b/ui/status.c @@ -37,9 +37,9 @@ void UI_DisplayStatus(const bool test_display) uint8_t *line = g_status_line; unsigned int x = 0; unsigned int x1 = 0; - + g_update_status = false; - + memset(g_status_line, 0, sizeof(g_status_line)); // ************** @@ -65,78 +65,79 @@ void UI_DisplayStatus(const bool test_display) x1 = x + sizeof(BITMAP_POWERSAVE); } x += sizeof(BITMAP_POWERSAVE); + x++; #ifdef ENABLE_NOAA - // NOASS SCAN indicator - if (g_is_noaa_mode || test_display) + // NOAA scan indicator + if (g_noaa_mode || test_display) { memcpy(line + x, BITMAP_NOAA, sizeof(BITMAP_NOAA)); x1 = x + sizeof(BITMAP_NOAA); + x += sizeof(BITMAP_NOAA); } - x += sizeof(BITMAP_NOAA); - #else - // hmmm, what to put in it's place + x++; #endif - + #ifdef ENABLE_KILL_REVIVE - if (g_setting_radio_disabled) + if (g_eeprom.config.setting.radio_disabled) { memset(line + x, 0xFF, 10); x1 = x + 10; + x += 10; } - else #endif - { + #ifdef ENABLE_FMRADIO // FM indicator if (g_fm_radio_mode || test_display) { memcpy(line + x, BITMAP_FM, sizeof(BITMAP_FM)); x1 = x + sizeof(BITMAP_FM); + x += sizeof(BITMAP_FM); } - else + x++; #endif - // SCAN indicator - if (g_scan_state_dir != SCAN_STATE_DIR_OFF || test_display) + + // SCAN indicator + if (g_scan_state_dir != SCAN_STATE_DIR_OFF || test_display) + { + // don't display this if in search mode + if (g_current_display_screen != DISPLAY_SEARCH) { - // don't display this if in search mode - if (g_current_display_screen != DISPLAY_SEARCH) - { - if (g_scan_next_channel <= USER_CHANNEL_LAST) - { // channel mode - if (g_eeprom.scan_list_default == 0) - UI_PrintStringSmallBuffer("1", line + x); - else - if (g_eeprom.scan_list_default == 1) - UI_PrintStringSmallBuffer("2", line + x); - else - if (g_eeprom.scan_list_default == 2) - UI_PrintStringSmallBuffer("*", line + x); - } + if (g_scan_next_channel <= USER_CHANNEL_LAST) + { // channel mode + if (g_eeprom.config.setting.scan_list_default == 0) + UI_PrintStringSmallBuffer("1", line + x); else - { // frequency mode - UI_PrintStringSmallBuffer("S", line + x); - } - x1 = x + 7; + if (g_eeprom.config.setting.scan_list_default == 1) + UI_PrintStringSmallBuffer("2", line + x); + else + if (g_eeprom.config.setting.scan_list_default == 2) + UI_PrintStringSmallBuffer("*", line + x); } + else + { // frequency mode + UI_PrintStringSmallBuffer("S", line + x); + } + x1 = x + 7; } + x += 7; // font character width } - x += 7; // font character width + x++; #ifdef ENABLE_VOICE // VOICE indicator - if (g_eeprom.voice_prompt != VOICE_PROMPT_OFF || test_display) + if (g_eeprom.config.setting.voice_prompt != VOICE_PROMPT_OFF || test_display) { memcpy(line + x, BITMAP_VOICE_PROMPT, sizeof(BITMAP_VOICE_PROMPT)); x1 = x + sizeof(BITMAP_VOICE_PROMPT); + x += sizeof(BITMAP_VOICE_PROMPT); } - x += sizeof(BITMAP_VOICE_PROMPT); - #else - // hmmm, what to put in it's place + x++; #endif // DUAL-WATCH indicator - if (g_eeprom.dual_watch != DUAL_WATCH_OFF || test_display) + if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF || test_display) { if (g_dual_watch_tick_10ms > dual_watch_delay_toggle_10ms || g_dtmf_call_state != DTMF_CALL_STATE_NONE || @@ -152,42 +153,47 @@ void UI_DisplayStatus(const bool test_display) memcpy(line + x, BITMAP_TDR_RUNNING, sizeof(BITMAP_TDR_RUNNING)); } x1 = x + sizeof(BITMAP_TDR_RUNNING); + x += sizeof(BITMAP_TDR_RUNNING); } - x += sizeof(BITMAP_TDR_RUNNING); + x++; // monitor if (g_monitor_enabled) { memcpy(line + x, BITMAP_MONITOR, sizeof(BITMAP_MONITOR)); x1 = x + sizeof(BITMAP_MONITOR); + x += sizeof(BITMAP_MONITOR); } - x += sizeof(BITMAP_MONITOR); + x++; // CROSS-VFO indicator - if (g_eeprom.cross_vfo_rx_tx != CROSS_BAND_OFF || test_display) + if (g_eeprom.config.setting.cross_vfo != CROSS_BAND_OFF || test_display) { memcpy(line + x, BITMAP_XB, sizeof(BITMAP_XB)); x1 = x + sizeof(BITMAP_XB); + x += sizeof(BITMAP_XB); } - x += sizeof(BITMAP_XB); - + x++; + #ifdef ENABLE_VOX // VOX indicator - if (g_eeprom.vox_switch || test_display) + if (g_eeprom.config.setting.vox_switch || test_display) { memcpy(line + x, BITMAP_VOX, sizeof(BITMAP_VOX)); x1 = x + sizeof(BITMAP_VOX); + x += sizeof(BITMAP_VOX); } - x += sizeof(BITMAP_VOX); + x++; #endif #ifdef ENABLE_KEYLOCK // KEY-LOCK indicator - if (g_eeprom.key_lock || test_display) + if (g_eeprom.config.setting.key_lock || test_display) { memcpy(line + x, BITMAP_KEYLOCK, sizeof(BITMAP_KEYLOCK)); x += sizeof(BITMAP_KEYLOCK); x1 = x; + x++; } else #endif @@ -197,22 +203,23 @@ void UI_DisplayStatus(const bool test_display) x += sizeof(BITMAP_F_KEY); x1 = x; } + x++; { // battery voltage or percentage text char s[8]; unsigned int space_needed; - + unsigned int x2 = LCD_WIDTH - sizeof(BITMAP_BATTERY_LEVEL) - 3; if (g_charging_with_type_c) x2 -= sizeof(BITMAP_USB_C); // the radio is on USB charge - switch (g_setting_battery_text) + switch (g_eeprom.config.setting.battery_text) { default: case 0: break; - + case 1: // voltage { const uint16_t voltage = (g_battery_voltage_average <= 999) ? g_battery_voltage_average : 999; // limit to 9.99V @@ -222,7 +229,7 @@ void UI_DisplayStatus(const bool test_display) UI_PrintStringSmallBuffer(s, line + x2 - space_needed); break; } - + case 2: // percentage { sprintf(s, "%u%%", BATTERY_VoltsToPercent(g_battery_voltage_average)); @@ -233,10 +240,10 @@ void UI_DisplayStatus(const bool test_display) } } } - + // move to right side of the screen x = LCD_WIDTH - sizeof(BITMAP_BATTERY_LEVEL) - sizeof(BITMAP_USB_C); - + // USB-C charge indicator if (g_charging_with_type_c || test_display) memcpy(line + x, BITMAP_USB_C, sizeof(BITMAP_USB_C)); @@ -244,7 +251,7 @@ void UI_DisplayStatus(const bool test_display) // BATTERY LEVEL indicator UI_DrawBattery(line + x, g_battery_display_level, g_low_battery_blink); - + // ************** ST7565_BlitStatusLine(); diff --git a/ui/welcome.c b/ui/welcome.c deleted file mode 100644 index 8de1153..0000000 --- a/ui/welcome.c +++ /dev/null @@ -1,101 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "driver/eeprom.h" -#include "driver/st7565.h" -#include "external/printf/printf.h" -#include "helper/battery.h" -#include "settings.h" -#include "misc.h" -#include "ui/helper.h" -#include "ui/welcome.h" -#include "ui/status.h" -#include "version.h" - -void UI_DisplayReleaseKeys(void) -{ - memset(g_status_line, 0, sizeof(g_status_line)); - memset(g_frame_buffer, 0, sizeof(g_frame_buffer)); - - UI_PrintString("RELEASE", 0, LCD_WIDTH, 1, 10); - UI_PrintString("ALL KEYS", 0, LCD_WIDTH, 3, 10); - - ST7565_BlitStatusLine(); // blank status line - ST7565_BlitFullScreen(); -} - -void UI_DisplayWelcome(void) -{ - char str0[17]; - char str1[17]; - char str2[17]; - - memset(g_status_line, 0, sizeof(g_status_line)); - memset(g_frame_buffer, 0, sizeof(g_frame_buffer)); - - if (g_eeprom.pwr_on_display_mode == PWR_ON_DISPLAY_MODE_NONE) - { - ST7565_FillScreen(0xFF); - } - else - if (g_eeprom.pwr_on_display_mode == PWR_ON_DISPLAY_MODE_FULL_SCREEN) - { - ST7565_FillScreen(0xFF); - } - else - { - unsigned int slen = strlen(Version_str); - if (slen > (sizeof(str2) - 1)) - slen = sizeof(str2) - 1; - - memset(str0, 0, sizeof(str0)); - memset(str1, 0, sizeof(str1)); - memset(str2, 0, sizeof(str2)); - - if (g_eeprom.pwr_on_display_mode == PWR_ON_DISPLAY_MODE_VOLTAGE) - { - strcpy(str0, "VOLTAGE"); - sprintf(str1, "%u.%02uV %u%%", - g_battery_voltage_average / 100, - g_battery_voltage_average % 100, - BATTERY_VoltsToPercent(g_battery_voltage_average)); - } - else - { - EEPROM_ReadBuffer(0x0EB0, str0, 16); - EEPROM_ReadBuffer(0x0EC0, str1, 16); - } - - memcpy(str2, Version_str, slen); - - UI_PrintString(str0, 0, LCD_WIDTH, 0, 10); - UI_PrintString(str1, 0, LCD_WIDTH, 2, 10); - UI_PrintStringSmall(str2, 0, LCD_WIDTH, 4); - UI_PrintStringSmall(__DATE__, 0, LCD_WIDTH, 5); - UI_PrintStringSmall(__TIME__, 0, LCD_WIDTH, 6); - - #if 1 - ST7565_BlitStatusLine(); // blank status line - #else - UI_DisplayStatus(true); // show all status line symbols (test) - #endif - - ST7565_BlitFullScreen(); - } -} - diff --git a/ui/welcome.h b/ui/welcome.h deleted file mode 100644 index b21a85e..0000000 --- a/ui/welcome.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UI_WELCOME_H -#define UI_WELCOME_H - -void UI_DisplayReleaseKeys(void); -void UI_DisplayWelcome(void); - -#endif -