diff --git a/app/action.c b/app/action.c index 19f937f..d46fc58 100644 --- a/app/action.c +++ b/app/action.c @@ -148,7 +148,7 @@ void ACTION_Scan(bool bRestart) g_fm_auto_scan = true; g_fm_channel_position = 0; - Frequency = g_eeprom.fm_lower_limit; + Frequency = FM_RADIO_BAND.lower; } else { diff --git a/app/dtmf.c b/app/dtmf.c index d2ecc3e..c6e160e 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -425,7 +425,7 @@ void DTMF_Reply(void) } // send TX-UP DTMF - pString = g_eeprom.dtmf_up_code; + pString = g_eeprom.dtmf_key_up_code; break; } diff --git a/app/fm.c b/app/fm.c index eba2a4b..17d1392 100644 --- a/app/fm.c +++ b/app/fm.c @@ -137,11 +137,11 @@ void FM_Tune(uint16_t Frequency, int8_t Step, bool flag) if (!flag) { Frequency += Step; - if (Frequency < g_eeprom.fm_lower_limit) - Frequency = g_eeprom.fm_upper_limit; + if (Frequency < FM_RADIO_BAND.lower) + Frequency = FM_RADIO_BAND.upper; else - if (Frequency > g_eeprom.fm_upper_limit) - Frequency = g_eeprom.fm_lower_limit; + if (Frequency > FM_RADIO_BAND.upper) + Frequency = FM_RADIO_BAND.lower; g_eeprom.fm_frequency_playing = Frequency; } @@ -288,7 +288,7 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) Frequency /= 10000; - if (Frequency < g_eeprom.fm_lower_limit || g_eeprom.fm_upper_limit < Frequency) + if (Frequency < FM_RADIO_BAND.lower || Frequency > FM_RADIO_BAND.upper) { g_request_display_screen = DISPLAY_FM; return; @@ -587,11 +587,11 @@ static void FM_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Step) else { // no, frequency mode uint16_t Frequency = g_eeprom.fm_selected_frequency + Step; - if (Frequency < g_eeprom.fm_lower_limit) - Frequency = g_eeprom.fm_upper_limit; + if (Frequency < FM_RADIO_BAND.lower) + Frequency = FM_RADIO_BAND.upper; else - if (Frequency > g_eeprom.fm_upper_limit) - Frequency = g_eeprom.fm_lower_limit; + if (Frequency > FM_RADIO_BAND.upper) + Frequency = FM_RADIO_BAND.lower; g_eeprom.fm_frequency_playing = Frequency; g_eeprom.fm_selected_frequency = g_eeprom.fm_frequency_playing; @@ -649,7 +649,7 @@ void FM_ProcessKeys(key_code_t Key, bool key_pressed, bool key_held) void FM_Play(void) { - if (!FM_CheckFrequencyLock(g_eeprom.fm_frequency_playing, g_eeprom.fm_lower_limit)) + if (!FM_CheckFrequencyLock(g_eeprom.fm_frequency_playing, FM_RADIO_BAND.lower)) { if (!g_fm_auto_scan) { @@ -677,7 +677,7 @@ void FM_Play(void) } } - if (g_fm_auto_scan && g_eeprom.fm_frequency_playing >= g_eeprom.fm_upper_limit) + if (g_fm_auto_scan && g_eeprom.fm_frequency_playing >= FM_RADIO_BAND.upper) FM_PlayAndUpdate(); else FM_Tune(g_eeprom.fm_frequency_playing, g_fm_scan_state, false); diff --git a/app/uart.c b/app/uart.c index ecc2f18..a9b48fa 100644 --- a/app/uart.c +++ b/app/uart.c @@ -351,11 +351,11 @@ static void cmd_051D(const uint8_t *pBuffer) #endif #ifdef ENABLE_PWRON_PASSWORD - if ((Offset < 0x0E98 || Offset >= 0x0EA0) || !g_password_locked || pCmd->allow_password) + if ((Offset < 0x0E98 || Offset >= 0x0E9C) || !g_password_locked || pCmd->allow_password) EEPROM_WriteBuffer(Offset, data); #else - if (Offset == 0x0E90) - memset(data + 8, 0xff, 4); // wipe the password + if (Offset == 0x0E98) + memset(data, 0xff, 4); // wipe the password EEPROM_WriteBuffer(Offset, data); #endif } diff --git a/board.c b/board.c index d157733..35ecb8a 100644 --- a/board.c +++ b/board.c @@ -573,9 +573,7 @@ void BOARD_EEPROM_load(void) } __attribute__((packed)) FM; EEPROM_ReadBuffer(0x0E88, &FM, 8); - g_eeprom.fm_lower_limit = 760; - g_eeprom.fm_upper_limit = 1080; - if (FM.SelectedFrequency < g_eeprom.fm_lower_limit || FM.SelectedFrequency > g_eeprom.fm_upper_limit) + if (FM.SelectedFrequency < FM_RADIO_BAND.lower || FM.SelectedFrequency > FM_RADIO_BAND.upper) g_eeprom.fm_selected_frequency = 960; else g_eeprom.fm_selected_frequency = FM.SelectedFrequency; @@ -624,9 +622,11 @@ void BOARD_EEPROM_load(void) #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_FREQ { unsigned int i; @@ -637,11 +637,11 @@ void BOARD_EEPROM_load(void) 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; @@ -692,21 +692,21 @@ void BOARD_EEPROM_load(void) // 0EF8..0F07 EEPROM_ReadBuffer(0x0EF8, Data, 16); if (DTMF_ValidateCodes((char *)Data, 16)) - memmove(g_eeprom.dtmf_up_code, Data, 16); + memmove(g_eeprom.dtmf_key_up_code, Data, 16); else { - memset(g_eeprom.dtmf_up_code, 0, sizeof(g_eeprom.dtmf_up_code)); - strcpy(g_eeprom.dtmf_up_code, "12345"); + 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)) - memmove(g_eeprom.dtmf_down_code, Data, 16); + memmove(g_eeprom.dtmf_key_down_code, Data, 16); else { - memset(g_eeprom.dtmf_down_code, 0, sizeof(g_eeprom.dtmf_down_code)); - strcpy(g_eeprom.dtmf_down_code, "54321"); + 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 @@ -751,7 +751,7 @@ void BOARD_EEPROM_load(void) 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; @@ -763,7 +763,7 @@ void BOARD_EEPROM_load(void) break; } } - + #if ENABLE_RESET_AES_KEY // a fix to wipe the darned AES key if (g_has_custom_aes_key) @@ -855,7 +855,7 @@ unsigned int BOARD_fetchChannelStepSetting(const int channel) { uint8_t data[8]; unsigned int step_setting = 0; - + if (channel < 0) return 0; @@ -868,10 +868,10 @@ unsigned int BOARD_fetchChannelStepSetting(const int channel) { 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; } @@ -879,7 +879,7 @@ 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; @@ -887,7 +887,7 @@ unsigned int BOARD_fetchFrequencyStepSetting(const int channel, const int vfo) step_setting = (data[6] >= ARRAY_SIZE(STEP_FREQ_TABLE)) ? STEP_12_5kHz : data[6]; // step_size = STEP_FREQ_TABLE[step_setting]; - + return step_setting; } diff --git a/firmware.bin b/firmware.bin index ddacead..3cac966 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index affa766..fc0916f 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/frequencies.c b/frequencies.c index ff9f01e..2756578 100644 --- a/frequencies.c +++ b/frequencies.c @@ -21,6 +21,9 @@ // the default AIRCOPY frequency to use uint32_t g_aircopy_freq = 41002500; +// FM broadcast band lower/upper limit +const freq_band_table_t FM_RADIO_BAND = {760, 1080}; + // the BK4819 has 2 bands it covers, 18MHz ~ 630MHz and 760MHz ~ 1300MHz const freq_band_table_t BX4819_BAND1 = { 1800000, 63000000}; const freq_band_table_t BX4819_BAND2 = {84000000, 130000000}; diff --git a/frequencies.h b/frequencies.h index fbea414..7ca4b40 100644 --- a/frequencies.h +++ b/frequencies.h @@ -40,6 +40,8 @@ typedef struct { extern uint32_t g_aircopy_freq; +extern const freq_band_table_t FM_RADIO_BAND; + extern const freq_band_table_t BX4819_BAND1; extern const freq_band_table_t BX4819_BAND2; diff --git a/radio.c b/radio.c index 1ec4ccb..38f0153 100644 --- a/radio.c +++ b/radio.c @@ -248,6 +248,9 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure EEPROM_ReadBuffer(Base + 8, Data, sizeof(Data)); + g_eeprom.vfo_info[VFO].freq_config_rx.code_type = (Data[2] >> 0) & 0x0F; + g_eeprom.vfo_info[VFO].freq_config_tx.code_type = (Data[2] >> 4) & 0x0F; + Tmp = Data[3] & 0x0F; if (Tmp > TX_OFFSET_FREQ_DIR_SUB) Tmp = 0; @@ -265,9 +268,6 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure Tmp = 0; g_eeprom.vfo_info[VFO].scrambling_type = Tmp; - g_eeprom.vfo_info[VFO].freq_config_rx.code_type = (Data[2] >> 0) & 0x0F; - g_eeprom.vfo_info[VFO].freq_config_tx.code_type = (Data[2] >> 4) & 0x0F; - Tmp = Data[0]; switch (g_eeprom.vfo_info[VFO].freq_config_rx.code_type) { @@ -1104,7 +1104,7 @@ void RADIO_SendEndOfTransmission(void) BK4819_EnterDTMF_TX(g_eeprom.dtmf_side_tone); BK4819_PlayDTMFString( - g_eeprom.dtmf_down_code, + g_eeprom.dtmf_key_down_code, 0, g_eeprom.dtmf_first_code_persist_time, g_eeprom.dtmf_hash_code_persist_time, diff --git a/settings.h b/settings.h index 009a9ac..2fd7fb2 100644 --- a/settings.h +++ b/settings.h @@ -114,6 +114,282 @@ enum mdf_display_mode_e { }; typedef enum mdf_display_mode_e mdf_display_mode_t; +// ************************************************ + +typedef struct { + // [0] + uint8_t rx_ctcss_cdcss_code; + // [1] + uint8_t tx_ctcss_cdcss_code; + // [2] + uint8_t rx_code_type:4; + uint8_t tx_code_type:4; + // [3] + uint8_t tx_offset_dir:4; + uint8_t unused1:4; + // [4] + uint8_t frequency_reverse:1; + uint8_t channel_bandwidth:1; + uint8_t tx_power:2; + uint8_t busy_channel_lockout:1; + uint8_t unused2:3; + // [5] + uint8_t dtmf_decoding_enable:1; + uint8_t dtmf_ptt_id_tx_mode:3; + uint8_t unused3:4; + // [6] + uint8_t step_setting; + // [7] + uint8_t scrambler; + // [8] + uint32_t frequency; + // [12] + uint32_t offset; +} __attribute__((packed)) t_channel; + +// 512 bytes +typedef struct { + + // 0x1E00 + struct { + uint8_t open_rssi_thresh[10]; + uint8_t unused1[6]; + + uint8_t close_rssi_thresh[10]; + uint8_t unused2[6]; + + uint8_t open_noise_thresh[10]; + uint8_t unused3[6]; + + uint8_t close_noise_thresh[10]; + uint8_t unused4[6]; + + uint8_t open_glitch_thresh[10]; + uint8_t unused5[6]; + + uint8_t close_glitch_thresh[10]; + uint8_t unused6[6]; + } __attribute__((packed)) uhf_squelch[6]; + + // 0x1E60 + struct { + uint8_t open_rssi_thresh[10]; + uint8_t unused1[6]; + + uint8_t close_rssi_thresh[10]; + uint8_t unused2[6]; + + uint8_t open_noise_thresh[10]; + uint8_t unused3[6]; + + uint8_t close_noise_thresh[10]; + uint8_t unused4[6]; + + uint8_t open_glitch_thresh[10]; + uint8_t unused5[6]; + + uint8_t close_glitch_thresh[10]; + uint8_t unused6[6]; + } __attribute__((packed)) vhf_squelch[6]; + + // 0x1EC0 + uint16_t unknown1[4]; + uint16_t rssi[4]; + + // 0x1ED0 + struct + { + uint8_t low_tx_pwr[3]; + uint8_t mid_tx_pwr[3]; + uint8_t high_tx_pwr[3]; + uint8_t unused[7]; + } band_setting[7]; + + // 0x1F40 + uint16_t battery[6]; + uint8_t unused1[4]; + + // 0x1F50 + struct + { + uint16_t threshold[10]; + uint8_t unused[4]; + } __attribute__((packed)) vox[2]; + + // 0x1F80 + uint8_t mic_gain_dB2[5]; + uint8_t unused4[3]; + + // 0x1F88 + int16_t bk4819_xtal_freq_low; + uint16_t unknown2; + uint16_t unknown3; + uint8_t volume_gain; + uint8_t dac_gain; + + uint8_t unused5[8 * 10]; + +} __attribute__((packed)) t_calibration; + +typedef struct { + + // 0x0000 + t_channel channel[200]; + + // 0xC80 + t_channel vfo[14]; + + // 0x0D60 + struct { + uint8_t band:4; + uint8_t compander:2; + uint8_t scanlist2:1; + uint8_t scanlist1:1; + } __attribute__((packed)) channel_attr[200]; + + uint8_t unused1[8]; + uint8_t unused2[16]; + + // 0x0E40 + uint16_t fm_channel[20]; + uint8_t unused3[8]; + + // 0x0E70 + uint8_t call1; + uint8_t squelch; + uint8_t tot; + uint8_t noaa_auto_scan; + uint8_t key_lock; + uint8_t vox_switch; + uint8_t vox_level; + uint8_t mic_sensitivity; + uint8_t unused4; + uint8_t mdf; + uint8_t wx; + uint8_t battery_save; + uint8_t tdr; + uint8_t backlight; + uint8_t site; + 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_is_channel_mode; + uint8_t unused5[5]; + + // 0x0E90 + uint8_t beep_control; + uint8_t key1_short; + uint8_t key1_long; + uint8_t key2_short; + uint8_t key2_long; + uint8_t sc_rev; + uint8_t auto_lock; + uint8_t display_mode; + uint32_t power_on_password; + uint8_t unused6[4]; + + // 0x0EA0 + uint8_t voice_prompt; + uint8_t unused7[7]; + uint8_t alarm_mode; + uint8_t roger_mode; + uint8_t rp_ste; + uint8_t tx_channel; + uint8_t unused8[4]; + + // 0x0EB0 + uint8_t welcome_line1[16]; + uint8_t welcome_line2[16]; + + // 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]; + + // 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]; + uint8_t s_list_default; + uint8_t scanlist1_enable; + uint8_t scanlist1_channel1; + uint8_t scanlist1_channel2; + uint8_t scanlist2_enable; + uint8_t scanlist2_channel1; + uint8_t scanlist2_channel2; + uint8_t unused10; + + // 0x0F20 + uint8_t unused11[8]; + + // 0x0F30 + uint8_t aes_key[16]; + + // 0x0F40 + uint8_t f_lock; + uint8_t enable_tx_350; + uint8_t killed; + uint8_t enable_tx_200; + uint8_t enable_tx_500; + uint8_t enable_350; + uint8_t enable_scrambler; + #if 0 + // QS + uint8_t unused12[9]; + #else + // 1of11 + uint8_t tx_enable:1; + uint8_t dtmf_live_decoder:1; + uint8_t battery_text:2; + uint8_t mic_bar:1; + uint8_t am_fix:1; + uint8_t backlight_on_tx_rx:2; + + uint8_t unused12[8]; + #endif + + // 0x0F50 + char channel_name[200][16]; + + // 0x1BD0 + uint8_t unused13[16]; + uint8_t unused14[16]; + uint8_t unused15[16]; + + // 0x1C00 + uint8_t dtmf_contact[16][16]; + + // 0x1D00 + uint8_t unused16[16 * 16]; + + // 0x1E00 + t_calibration calibration; + +} __attribute__((packed)) t_eeprom; + +// ************************************************ + typedef struct { uint8_t screen_channel[2]; uint8_t freq_channel[2]; @@ -132,8 +408,6 @@ typedef struct { uint8_t fm_selected_channel; bool fm_is_channel_mode; uint16_t fm_frequency_playing; - uint16_t fm_lower_limit; - uint16_t fm_upper_limit; #endif uint8_t squelch_level; @@ -160,12 +434,12 @@ typedef struct { uint8_t field29_0x26; uint8_t field30_0x27; - + uint8_t field37_0x32; uint8_t field38_0x33; bool auto_keypad_lock; - + #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) alarm_mode_t alarm_mode; #endif @@ -182,8 +456,8 @@ typedef struct { char ani_dtmf_id[8]; char kill_code[8]; char revive_code[8]; - char dtmf_up_code[16]; - char dtmf_down_code[16]; + char dtmf_key_up_code[16]; + char dtmf_key_down_code[16]; uint8_t field57_0x6c; uint8_t field58_0x6d; diff --git a/ui/menu.c b/ui/menu.c index cdbeb71..f7423f6 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -878,12 +878,12 @@ void UI_DisplayMenu(void) case MENU_UPCODE: strcpy(String, "PTT DTMF\nBEGIN\n"); - strcat(String, g_eeprom.dtmf_up_code); + strcat(String, g_eeprom.dtmf_key_up_code); break; case MENU_DWCODE: strcpy(String, "PTT DTMF\nEND\n"); - strcat(String, g_eeprom.dtmf_down_code); + strcat(String, g_eeprom.dtmf_key_down_code); break; case MENU_D_RSP: @@ -1148,12 +1148,12 @@ void UI_DisplayMenu(void) UI_PrintString("SCAN", menu_item_x1, menu_item_x2, 4, 8); if (g_menu_cursor == MENU_UPCODE) - if (strlen(g_eeprom.dtmf_up_code) > 8) - UI_PrintString(g_eeprom.dtmf_up_code + 8, menu_item_x1, menu_item_x2, 4, 8); + if (strlen(g_eeprom.dtmf_key_up_code) > 8) + UI_PrintString(g_eeprom.dtmf_key_up_code + 8, menu_item_x1, menu_item_x2, 4, 8); if (g_menu_cursor == MENU_DWCODE) - if (strlen(g_eeprom.dtmf_down_code) > 8) - UI_PrintString(g_eeprom.dtmf_down_code + 8, menu_item_x1, menu_item_x2, 4, 8); + if (strlen(g_eeprom.dtmf_key_down_code) > 8) + UI_PrintString(g_eeprom.dtmf_key_down_code + 8, menu_item_x1, menu_item_x2, 4, 8); if (g_menu_cursor == MENU_R_CTCS || g_menu_cursor == MENU_T_CTCS ||