diff --git a/Makefile b/Makefile index 3cfb685..5c4e8c2 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 := 0 +ENABLE_UART_DEBUG := 1 # AirCopy 2.5 kB ENABLE_AIRCOPY := 0 ENABLE_AIRCOPY_REMEMBER_FREQ := 1 @@ -21,7 +21,7 @@ ENABLE_AIRCOPY_RX_REBOOT := 0 ENABLE_FMRADIO_64_76 := 0 ENABLE_FMRADIO_76_90 := 0 ENABLE_FMRADIO_76_108 := 0 -ENABLE_FMRADIO_875_108 := 0 +ENABLE_FMRADIO_875_108 := 1 ENABLE_FMRADIO_64_108 := 0 # NOAA 1.2 kB ENABLE_NOAA := 0 @@ -36,7 +36,7 @@ ENABLE_REDUCE_LOW_MID_TX_POWER := 1 ENABLE_ALARM := 0 ENABLE_TX1750 := 0 # MDC1200 2.8 kB -ENABLE_MDC1200 := 1 +ENABLE_MDC1200 := 0 ENABLE_MDC1200_SHOW_OP_ARG := 1 ENABLE_PWRON_PASSWORD := 0 ENABLE_RESET_AES_KEY := 0 diff --git a/app/app.c b/app/app.c index fb66119..94a23a5 100644 --- a/app/app.c +++ b/app/app.c @@ -908,16 +908,19 @@ void APP_process_radio_interrupts(void) int_bits = BK4819_ReadRegister(0x02); #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) - { - 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"); - } + #ifdef ENABLE_AIRCOPY + if (g_current_display_screen != DISPLAY_AIRCOPY) + #endif + { + 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) diff --git a/app/menu.c b/app/menu.c index 7c112e2..c037df8 100644 --- a/app/menu.c +++ b/app/menu.c @@ -1433,6 +1433,11 @@ static void MENU_Key_0_to_9(key_code_t Key, bool key_pressed, bool key_held) { uint32_t Frequency; + NUMBER_Get(g_input_box, &Frequency); + + if (g_input_box_index > 0) + g_sub_menu_selection = Frequency; + if (g_input_box_index < 8) { // not yet enough characters #ifdef ENABLE_VOICE @@ -1441,13 +1446,12 @@ static void MENU_Key_0_to_9(key_code_t Key, bool key_pressed, bool key_held) return; } + g_input_box_index = 0; + #ifdef ENABLE_VOICE g_another_voice_id = (voice_id_t)Key; #endif - NUMBER_Get(g_input_box, &Frequency); - g_input_box_index = 0; - #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) UART_printf("offset 3 %u\r\n", Frequency); #endif @@ -1460,7 +1464,7 @@ static void MENU_Key_0_to_9(key_code_t Key, bool key_pressed, bool key_held) #endif #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) - UART_printf("offset 4 %u\r\n", Frequency); +// UART_printf("offset 4 %u\r\n", Frequency); #endif g_sub_menu_selection = Frequency; @@ -1575,9 +1579,9 @@ static void MENU_Key_EXIT(bool key_pressed, bool key_held) g_input_box_index = 0; g_flag_refresh_menu = true; -#ifdef ENABLE_VOICE + #ifdef ENABLE_VOICE g_another_voice_id = VOICE_ID_CANCEL; -#endif + #endif } else g_input_box[--g_input_box_index] = 10; @@ -1588,9 +1592,9 @@ static void MENU_Key_EXIT(bool key_pressed, bool key_held) return; } -#ifdef ENABLE_VOICE + #ifdef ENABLE_VOICE g_another_voice_id = VOICE_ID_CANCEL; -#endif + #endif g_request_display_screen = DISPLAY_MAIN; @@ -1604,9 +1608,9 @@ static void MENU_Key_EXIT(bool key_pressed, bool key_held) { MENU_stop_css_scan(); -#ifdef ENABLE_VOICE + #ifdef ENABLE_VOICE g_another_voice_id = VOICE_ID_SCANNING_STOP; -#endif + #endif g_request_display_screen = DISPLAY_MENU; } diff --git a/firmware.bin b/firmware.bin index f1bbdf2..0720d5b 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 36df625..b367719 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/radio.c b/radio.c index 3e56428..f58ba72 100644 --- a/radio.c +++ b/radio.c @@ -63,7 +63,7 @@ bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO) if (Channel > USER_CHANNEL_LAST) return false; - if (g_user_channel_attributes[Channel].band > BAND7_470MHz) + if (g_eeprom.config.channel_attributes[Channel].band > BAND7_470MHz) return false; if (bCheckScanList) @@ -71,7 +71,7 @@ bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO) switch (VFO) { case 0: - if (g_user_channel_attributes[Channel].scanlist1 == 0) + if (g_eeprom.config.channel_attributes[Channel].scanlist1 == 0) return false; for (i = 0; i < 2; i++) @@ -79,7 +79,7 @@ bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO) break; case 1: - if (g_user_channel_attributes[Channel].scanlist2 == 0) + if (g_eeprom.config.channel_attributes[Channel].scanlist2 == 0) return false; for (i = 0; i < 2; i++) @@ -208,7 +208,7 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur chan = CHANNEL_NUM(channel, VFO); - attributes = g_user_channel_attributes[channel]; + attributes = g_eeprom.config.channel_attributes[channel]; #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) // UART_printf("config chan 1 %u %u %u %u %u\r\n", channel, chan, attributes.band, attributes.scanlist1, attributes.scanlist2); diff --git a/settings.c b/settings.c index d1ac949..b7010ea 100644 --- a/settings.c +++ b/settings.c @@ -41,9 +41,7 @@ static const uint32_t DEFAULT_FREQUENCY_TABLE[] = 43350000 // }; -t_eeprom g_eeprom; - -t_channel_attrib g_user_channel_attributes[FREQ_CHANNEL_LAST + 1]; +t_eeprom g_eeprom; void SETTINGS_write_eeprom_config(void) { // save the entire EEPROM config contents @@ -352,19 +350,21 @@ void SETTINGS_read_eeprom(void) } } +#endif + +#if 1 + { // 0D60 for (index = 0; index < 7; index++) // default VFO attribs g_eeprom.config.channel_attributes[200 + index].attributes = 0xC0 | index; g_eeprom.config.channel_attributes[200 + 7].attributes = 0x00; - SETTINGS_save_attributes(); +// SETTINGS_save_attributes(); } #endif - memcpy(&g_user_channel_attributes, &g_eeprom.config.channel_attributes, sizeof(g_user_channel_attributes)); - // **************************************** memset(&g_eeprom.calib.unused3, 0xff, sizeof(g_eeprom.calib.unused3)); @@ -446,48 +446,51 @@ void SETTINGS_save(void) void SETTINGS_save_channel(const unsigned int channel, const unsigned int vfo, vfo_info_t *p_vfo, const unsigned int mode) { - 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)) + if (!IS_USER_CHANNEL(channel) && !IS_FREQ_CHANNEL(channel)) return; - if (mode < 2 && channel <= USER_CHANNEL_LAST) - return; - - // **************** - if (p_vfo != NULL) { - memset(p_channel, 0, sizeof(t_channel)); - p_vfo->channel.frequency = p_vfo->freq_config_rx.frequency; p_vfo->channel.rx_ctcss_cdcss_code = p_vfo->freq_config_rx.code; p_vfo->channel.tx_ctcss_cdcss_code = p_vfo->freq_config_tx.code; p_vfo->channel.rx_ctcss_cdcss_type = p_vfo->freq_config_rx.code_type; p_vfo->channel.tx_ctcss_cdcss_type = p_vfo->freq_config_tx.code_type; - memcpy(p_channel, &p_vfo->channel, sizeof(t_channel)); + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) + UART_printf("save chan 1 %u %u %u %uHz %uHz\r\n", channel, vfo, mode, p_vfo->channel.frequency * 10, p_vfo->channel.tx_offset * 10); + #endif + } - if (IS_USER_CHANNEL(channel)) - g_eeprom.config.channel_attributes[channel] = g_user_channel_attributes[channel]; + if (mode < 2 && channel <= USER_CHANNEL_LAST) + return; + + { // save the channel to EEPROM + + const unsigned int chan = CHANNEL_NUM(channel, vfo); + const unsigned int addr = sizeof(t_channel) * chan; + t_channel m_channel; + + if (p_vfo != NULL) + memcpy(&m_channel, &p_vfo->channel, sizeof(t_channel)); + else + if (channel <= USER_CHANNEL_LAST) + memset(&m_channel, 0xff, sizeof(t_channel)); + + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) + UART_printf("save chan 2 %04X %3u %3u %u %u %uHz %uHz\r\n", addr, chan, channel, vfo, mode, m_channel.frequency * 10, m_channel.tx_offset * 10); + #endif + + memcpy(&g_eeprom.config.channel[chan], &m_channel, sizeof(t_channel)); + + g_eeprom.config.channel_attributes[channel] = p_vfo->channel_attributes; memset(&g_eeprom.config.channel_name[channel], 0, sizeof(g_eeprom.config.channel_name[channel])); memcpy(g_eeprom.config.channel_name[channel].name, p_vfo->channel_name.name, sizeof(g_eeprom.config.channel_name[channel].name)); - #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) -// UART_printf("save chan %04X %3u %3u %u %u %uHz\r\n", eeprom_addr, chan, channel, vfo, mode, p_channel->frequency * 10); - #endif + EEPROM_WriteBuffer8(addr + 0, ((uint8_t *)&m_channel) + 0); + EEPROM_WriteBuffer8(addr + 8, ((uint8_t *)&m_channel) + 8); } - else - if (channel <= USER_CHANNEL_LAST) - { // user channel - memset(p_channel, 0xff, sizeof(t_channel)); - } - - EEPROM_WriteBuffer8(eeprom_addr + 0, ((uint8_t *)p_channel) + 0); - EEPROM_WriteBuffer8(eeprom_addr + 8, ((uint8_t *)p_channel) + 8); // **************** @@ -525,28 +528,19 @@ void SETTINGS_save_chan_attribs_name(const unsigned int channel, const vfo_info_ { const unsigned int index = channel & ~7u; // eeprom writes are always 8 bytes in length - if (channel >= ARRAY_SIZE(g_user_channel_attributes)) - return; - - if (IS_NOAA_CHANNEL(channel)) + if (!IS_USER_CHANNEL(channel) && !IS_FREQ_CHANNEL(channel)) return; if (p_vfo != NULL) { // channel attributes - - t_channel_attrib attribs = p_vfo->channel_attributes; - g_user_channel_attributes[channel] = attribs; // remember new attributes - g_eeprom.config.channel_attributes[channel] = attribs; - - EEPROM_WriteBuffer8(0x0D60 + index, &g_user_channel_attributes[index]); + g_eeprom.config.channel_attributes[channel] = p_vfo->channel_attributes; + EEPROM_WriteBuffer8(0x0D60 + index, &g_eeprom.config.channel_attributes[index]); } else if (channel <= USER_CHANNEL_LAST) { // user channel - g_user_channel_attributes[channel].attributes = 0xff; g_eeprom.config.channel_attributes[channel].attributes = 0xff; - - EEPROM_WriteBuffer8(0x0D60 + index, &g_user_channel_attributes[index]); + EEPROM_WriteBuffer8(0x0D60 + index, &g_eeprom.config.channel_attributes[index]); } if (channel <= USER_CHANNEL_LAST) @@ -586,12 +580,10 @@ unsigned int SETTINGS_find_channel(const uint32_t frequency) 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) + if (g_eeprom.config.channel_attributes[chan].band > BAND7_470MHz || freq == 0 || freq == 0xffffffff) continue; - if (freq == frequency) - return chan; // found it + return chan; // found it } return 0xffffffff; @@ -606,7 +598,7 @@ uint32_t SETTINGS_fetch_channel_frequency(const int channel) freq = g_eeprom.config.channel[channel].frequency; - if (g_user_channel_attributes[channel].band > BAND7_470MHz || freq == 0 || freq == 0xffffffff) + if (g_eeprom.config.channel_attributes[channel].band > BAND7_470MHz || freq == 0 || freq == 0xffffffff) return 0; return freq; @@ -656,7 +648,7 @@ void SETTINGS_fetch_channel_name(char *s, const int channel) if (channel < 0 || channel > (int)USER_CHANNEL_LAST) return; - if (g_user_channel_attributes[channel].band > BAND7_470MHz) + if (g_eeprom.config.channel_attributes[channel].band > BAND7_470MHz) return; memcpy(s, &g_eeprom.config.channel_name[channel], 10); diff --git a/settings.h b/settings.h index d7115df..a2e29d4 100644 --- a/settings.h +++ b/settings.h @@ -237,6 +237,11 @@ typedef union { uint8_t attributes; } __attribute__((packed)) t_channel_attrib; +typedef struct { + char name[10]; + uint8_t unused[6]; +} __attribute__((packed)) t_channel_name; + // user configuration typedef struct { @@ -409,10 +414,7 @@ typedef struct { } __attribute__((packed)) setting; // 0x0F50 - struct { - char name[10]; - uint8_t unused[6]; // 0xff's - } __attribute__((packed)) channel_name[USER_CHANNEL_LAST - USER_CHANNEL_FIRST + 1]; + t_channel_name channel_name[USER_CHANNEL_LAST - USER_CHANNEL_FIRST + 1]; // 0x1BD0 uint8_t unused13[16 * 3]; // 0xff's .. free to use @@ -516,6 +518,10 @@ typedef struct typedef struct vfo_info_t { + t_channel channel; + t_channel_attrib channel_attributes; + t_channel_name channel_name; + uint8_t channel_save; freq_config_t freq_config_rx; @@ -523,25 +529,18 @@ typedef struct vfo_info_t freq_config_t *p_rx; freq_config_t *p_tx; - t_channel channel; - - t_channel_attrib channel_attributes; - - struct { - char name[10]; - uint8_t unused[6]; - } channel_name; - uint16_t step_freq; - uint8_t freq_in_channel; // channel number where we also found this VFO's frequency + uint8_t freq_in_channel; // first channel number we found this VFO's frequency in + + uint8_t squelch_open_rssi_thresh; + uint8_t squelch_close_rssi_thresh; + + uint8_t squelch_open_noise_thresh; + uint8_t squelch_close_noise_thresh; uint8_t squelch_open_glitch_thresh; - uint8_t squelch_open_rssi_thresh; - uint8_t squelch_open_noise_thresh; uint8_t squelch_close_glitch_thresh; - uint8_t squelch_close_rssi_thresh; - uint8_t squelch_close_noise_thresh; uint8_t txp_calculated_setting; @@ -549,8 +548,7 @@ typedef struct vfo_info_t // ************************************************ -extern t_eeprom g_eeprom; -extern t_channel_attrib g_user_channel_attributes[FREQ_CHANNEL_LAST + 1]; +extern t_eeprom g_eeprom; void SETTINGS_read_eeprom(void); void SETTINGS_write_eeprom_config(void); diff --git a/ui/main.c b/ui/main.c index a17e1fb..d2e23c6 100644 --- a/ui/main.c +++ b/ui/main.c @@ -700,13 +700,11 @@ void UI_DisplayMain(void) unsigned int x = LCD_WIDTH - 1 - sizeof(BITMAP_SCANLIST2) - sizeof(BITMAP_SCANLIST1); - const t_channel_attrib attributes = g_user_channel_attributes[scrn_chan]; - - if (attributes.scanlist1) + if (g_vfo_info[vfo_num].channel_attributes.scanlist1) memcpy(p_line0 + x, BITMAP_SCANLIST1, sizeof(BITMAP_SCANLIST1)); x += sizeof(BITMAP_SCANLIST1); - if (attributes.scanlist2) + if (g_vfo_info[vfo_num].channel_attributes.scanlist2) memcpy(p_line0 + x, BITMAP_SCANLIST2, sizeof(BITMAP_SCANLIST2)); //x += sizeof(BITMAP_SCANLIST2); } diff --git a/ui/menu.c b/ui/menu.c index b25fa47..e592d23 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -672,10 +672,7 @@ void UI_DisplayMenu(void) 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); - #ifdef ENABLE_TRIM_TRAILING_ZEROS - NUMBER_trim_trailing_zeros(str); - #endif + sprintf(str, "%03d.%05u", g_sub_menu_selection / 100000, abs(g_sub_menu_selection) % 100000); UI_PrintString(str, sub_menu_x1, sub_menu_x2, 1, 8); } else