diff --git a/app/aircopy.c b/app/aircopy.c index 2437df8..3d7cfca 100644 --- a/app/aircopy.c +++ b/app/aircopy.c @@ -650,7 +650,7 @@ static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) g_aircopy_freq = Frequency; #ifdef ENABLE_AIRCOPY_REMEMBER_FREQ - SETTINGS_SaveSettings(); // remeber the frequency for the next time + SETTINGS_save(); // remeber the frequency for the next time #endif g_rx_vfo->freq_config_rx.frequency = Frequency; diff --git a/app/app.c b/app/app.c index f2c6568..cf0d308 100644 --- a/app/app.c +++ b/app/app.c @@ -652,11 +652,11 @@ void APP_stop_scan(void) { // frequency mode RADIO_ApplyOffset(g_rx_vfo); RADIO_ConfigureSquelchAndOutputPower(g_rx_vfo); - SETTINGS_SaveChannel(g_rx_vfo->channel_save, g_eeprom.rx_vfo, g_rx_vfo, 1); + SETTINGS_save_channel(g_rx_vfo->channel_save, g_eeprom.rx_vfo, g_rx_vfo, 1); return; } - SETTINGS_SaveVfoIndices(); + SETTINGS_save_vfo_indices(); } #ifdef ENABLE_VOICE @@ -1549,27 +1549,27 @@ void APP_time_slice_10ms(void) if (g_flag_save_vfo) { - SETTINGS_SaveVfoIndices(); + SETTINGS_save_vfo_indices(); g_flag_save_vfo = false; } if (g_flag_save_settings) { - SETTINGS_SaveSettings(); + SETTINGS_save(); g_flag_save_settings = false; } #ifdef ENABLE_FMRADIO if (g_flag_save_fm) { - SETTINGS_SaveFM(); + SETTINGS_save_fm(); g_flag_save_fm = false; } #endif if (g_flag_save_channel) { - SETTINGS_SaveChannel(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.tx_vfo, g_tx_vfo, g_flag_save_channel ? 1 : 0); g_flag_save_channel = false; RADIO_configure_channel(g_eeprom.tx_vfo, VFO_CONFIGURE); @@ -2734,7 +2734,7 @@ Skip: if (g_request_save_settings) { if (!key_held) - SETTINGS_SaveSettings(); + SETTINGS_save(); else g_flag_save_settings = 1; @@ -2746,7 +2746,7 @@ Skip: if (g_request_save_fm) { if (!key_held) - SETTINGS_SaveFM(); + SETTINGS_save_fm(); else g_flag_save_fm = true; @@ -2757,7 +2757,7 @@ Skip: if (g_request_save_vfo) { if (!key_held) - SETTINGS_SaveVfoIndices(); + SETTINGS_save_vfo_indices(); else g_flag_save_vfo = true; @@ -2768,7 +2768,7 @@ Skip: { if (!key_held) { - SETTINGS_SaveChannel(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.tx_vfo, g_tx_vfo, g_request_save_channel); if (g_screen_to_display != DISPLAY_SEARCH) if (g_vfo_configure_mode == VFO_CONFIGURE_NONE) // don't wipe previous variable setting @@ -2787,10 +2787,6 @@ Skip: if (g_vfo_configure_mode != VFO_CONFIGURE_NONE) { - #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) - UART_printf("audio gap\r\n"); - #endif - if (g_flag_reset_vfos) { RADIO_configure_channel(0, g_vfo_configure_mode); @@ -2819,6 +2815,8 @@ Skip: RADIO_setup_registers(true); +// g_tx_vfo->frequency_channel = BOARD_find_channel(frequency); + g_dtmf_auto_reset_time_500ms = 0; g_dtmf_call_state = DTMF_CALL_STATE_NONE; g_dtmf_tx_stop_count_down_500ms = 0; diff --git a/app/dtmf.c b/app/dtmf.c index d29492d..2a702b6 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -244,7 +244,7 @@ void DTMF_HandleRequest(void) DTMF_clear_RX(); - SETTINGS_SaveSettings(); + SETTINGS_save(); g_dtmf_reply_state = DTMF_REPLY_AB; @@ -283,7 +283,7 @@ void DTMF_HandleRequest(void) DTMF_clear_RX(); - SETTINGS_SaveSettings(); + SETTINGS_save(); g_dtmf_reply_state = DTMF_REPLY_AB; g_dtmf_call_state = DTMF_CALL_STATE_NONE; diff --git a/app/fm.c b/app/fm.c index 3d11290..1892e24 100644 --- a/app/fm.c +++ b/app/fm.c @@ -163,7 +163,7 @@ void FM_PlayAndUpdate(void) FM_ConfigureChannelState(); BK1080_SetFrequency(g_eeprom.fm_frequency_playing); - SETTINGS_SaveFM(); + SETTINGS_save_fm(); g_fm_play_count_down_10ms = 0; g_schedule_fm = false; diff --git a/app/main.c b/app/main.c index ce4b9d1..4dc64c4 100644 --- a/app/main.c +++ b/app/main.c @@ -43,8 +43,14 @@ void toggle_chan_scanlist(void) { // toggle the selected channels scanlist setting +// if (IS_FREQ_CHANNEL(g_tx_vfo->channel_save)) + if (IS_NOAA_CHANNEL(g_tx_vfo->channel_save)) + { + g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + return; + } + if (g_screen_to_display != DISPLAY_MAIN || - !IS_USER_CHANNEL(g_tx_vfo->channel_save) || g_current_function == FUNCTION_TRANSMIT || g_current_function == FUNCTION_PANADAPTER) { @@ -76,7 +82,7 @@ void toggle_chan_scanlist(void) g_tx_vfo->scanlist_1_participation = 1; } - SETTINGS_UpdateChannel(g_tx_vfo->channel_save, g_tx_vfo, true); + SETTINGS_save_chan_attribs_name(g_tx_vfo->channel_save, g_tx_vfo); g_vfo_configure_mode = VFO_CONFIGURE; g_flag_reset_vfos = true; @@ -406,9 +412,6 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) return; } -// #ifdef ENABLE_NOAA -// if (IS_NOT_NOAA_CHANNEL(g_tx_vfo->channel_save)) -// #endif if (IS_FREQ_CHANNEL(g_tx_vfo->channel_save)) { // user is entering a frequency @@ -457,13 +460,13 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) g_eeprom.screen_channel[Vfo] = band + FREQ_CHANNEL_FIRST; g_eeprom.freq_channel[Vfo] = band + FREQ_CHANNEL_FIRST; - SETTINGS_SaveVfoIndices(); + SETTINGS_save_vfo_indices(); RADIO_configure_channel(Vfo, VFO_CONFIGURE_RELOAD); } // Frequency += 75; // is this meant to be rounding ? - Frequency += g_tx_vfo->step_freq / 2; // no idea, but this is + Frequency += g_tx_vfo->step_freq / 2; // no idea, but this is Frequency = FREQUENCY_FloorToStep(Frequency, g_tx_vfo->step_freq, FREQ_BAND_TABLE[g_tx_vfo->band].lower); @@ -474,10 +477,18 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) } g_tx_vfo->freq_config_rx.frequency = Frequency; - // 1of11 .. test to prevent the monitor being turned off -// g_request_save_channel = 1; - SETTINGS_SaveChannel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, 1); - RADIO_setup_registers(true); + + // find the first channel that contains this frequency + g_tx_vfo->frequency_channel = BOARD_find_channel(Frequency); + + // 1of11 .. test to prevent monitor mode being turned off + #if 0 + // this currently also turns monitor mode off :( + g_request_save_channel = 1; + #else + SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, 1); + RADIO_setup_registers(true); + #endif return; } @@ -615,9 +626,9 @@ void MAIN_Key_MENU(const bool key_pressed, const bool key_held) #ifdef ENABLE_COPY_CHAN_TO_VFO_TO_CHAN - if (g_scan_state_dir == SCAN_STATE_DIR_OFF && - g_css_scan_mode == CSS_SCAN_MODE_OFF && - g_eeprom.dual_watch == DUAL_WATCH_OFF && + 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.vfo_open) { // not scanning @@ -647,28 +658,36 @@ void MAIN_Key_MENU(const bool key_pressed, const bool key_held) g_update_display = true; } else - if (IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo])) - { // copy VFO to channel + if (IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[vfo])) + { // copy VFO to a channel // search the channels to see if the frequency is already present - const unsigned int chan = BOARD_find_channel(g_eeprom.vfo_info[vfo].p_tx->frequency); + unsigned int chan = BOARD_find_channel(g_eeprom.vfo_info[vfo].p_tx->frequency); + if (chan > USER_CHANNEL_LAST) + { // find next next free channel + //for (chan = g_eeprom.screen_channel[vfo]; chan <= USER_CHANNEL_LAST; chan++) + for (chan = 0; chan <= USER_CHANNEL_LAST; chan++) + if (!RADIO_CheckValidChannel(chan, false, vfo)) + break; + } g_screen_to_display = DISPLAY_INVALID; GUI_SelectNextDisplay(DISPLAY_MENU); - - g_flag_refresh_menu = false; g_menu_cursor = MENU_MEM_SAVE; g_is_in_sub_menu = true; - if (chan <= USER_CHANNEL_LAST) - { // go straight to the channel that holds the same frequency + { + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) + UART_printf("vfo to mem %u\r\n", chan); + #endif + g_sub_menu_selection = chan; + g_flag_refresh_menu = false; + g_screen_to_display = DISPLAY_MENU; + g_update_display = false; + UI_DisplayMenu(); } - g_screen_to_display = DISPLAY_MENU; - g_update_display = false; - UI_DisplayMenu(); - #ifdef ENABLE_VOICE g_another_voice_id = VOICE_ID_MENU; #endif @@ -796,27 +815,31 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; } - if (!key_pressed && - g_scan_state_dir == SCAN_STATE_DIR_OFF && - IS_NOT_NOAA_CHANNEL(Channel) && - IS_FREQ_CHANNEL(Channel)) - { // key released in frequency mode - #ifdef ENABLE_SQ_OPEN_WITH_UP_DN_BUTTS - if (key_held && !monitor_was_enabled && g_current_function == FUNCTION_MONITOR) - { // re-enable the squelch - APP_start_listening(FUNCTION_RECEIVE, false); - g_monitor_enabled = false; - } - #endif + if (!key_pressed) + { + if (g_scan_state_dir == SCAN_STATE_DIR_OFF && IS_FREQ_CHANNEL(Channel)) + { // key released in frequency mode - // only update eeprom when the key is released - saves a LOT of wear and tear on the little eeprom - SETTINGS_SaveChannel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, 1); + #ifdef ENABLE_SQ_OPEN_WITH_UP_DN_BUTTS + if (key_held && !monitor_was_enabled && g_current_function == FUNCTION_MONITOR) + { // re-enable the squelch + APP_start_listening(FUNCTION_RECEIVE, false); + g_monitor_enabled = false; + } + #endif - #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) -// UART_printf("save chan\r\n"); - #endif + // find the first channel that contains this frequency + g_tx_vfo->frequency_channel = BOARD_find_channel(g_tx_vfo->freq_config_rx.frequency); + + // only update eeprom when the key is released - saves a LOT of wear and tear on the little eeprom + SETTINGS_save_channel(g_tx_vfo->channel_save, g_eeprom.tx_vfo, g_tx_vfo, 1); + + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) +// UART_printf("save chan\r\n"); + #endif + } } - + if (key_held || !key_pressed) { // long press @@ -874,6 +897,13 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio g_tx_vfo->freq_config_rx.frequency = frequency; + // find the first channel that contains this frequency + // currently takes to long to scan all the channels + // + // TODO: include this once we have the entire eeprom loaded + // + //g_tx_vfo->frequency_channel = BOARD_find_channel(frequency); + if (new_band != old_band) { // original slow method g_request_save_channel = 1; diff --git a/app/menu.c b/app/menu.c index 40ad373..9da091e 100644 --- a/app/menu.c +++ b/app/menu.c @@ -527,7 +527,7 @@ void MENU_AcceptSetting(void) // save the channel name memset(g_tx_vfo->name, 0, sizeof(g_tx_vfo->name)); memmove(g_tx_vfo->name, g_edit, 10); - SETTINGS_SaveChannel(g_sub_menu_selection, g_eeprom.tx_vfo, g_tx_vfo, 3); + SETTINGS_save_channel(g_sub_menu_selection, g_eeprom.tx_vfo, g_tx_vfo, 3); g_flag_reconfigure_vfos = true; return; @@ -614,14 +614,14 @@ void MENU_AcceptSetting(void) case MENU_S_ADD1: g_tx_vfo->scanlist_1_participation = g_sub_menu_selection; - SETTINGS_UpdateChannel(g_tx_vfo->channel_save, g_tx_vfo, true); + SETTINGS_save_chan_attribs_name(g_tx_vfo->channel_save, g_tx_vfo); g_vfo_configure_mode = VFO_CONFIGURE; g_flag_reset_vfos = true; return; case MENU_S_ADD2: g_tx_vfo->scanlist_2_participation = g_sub_menu_selection; - SETTINGS_UpdateChannel(g_tx_vfo->channel_save, g_tx_vfo, true); + SETTINGS_save_chan_attribs_name(g_tx_vfo->channel_save, g_tx_vfo); g_vfo_configure_mode = VFO_CONFIGURE; g_flag_reset_vfos = true; return; @@ -657,7 +657,7 @@ void MENU_AcceptSetting(void) #if 1 g_request_save_channel = 1; #else - SETTINGS_SaveChannel(g_sub_menu_selection, g_eeprom.tx_vfo, g_tx_vfo, 3); + SETTINGS_save_channel(g_sub_menu_selection, g_eeprom.tx_vfo, g_tx_vfo, 3); g_flag_reconfigure_vfos = true; #endif return; @@ -783,7 +783,7 @@ void MENU_AcceptSetting(void) #endif case MENU_MEM_DEL: - SETTINGS_UpdateChannel(g_sub_menu_selection, NULL, false); + SETTINGS_save_chan_attribs_name(g_sub_menu_selection, NULL); g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; g_flag_reset_vfos = true; return; diff --git a/bitmaps.c b/bitmaps.c index 538c9cf..ee64868 100644 --- a/bitmaps.c +++ b/bitmaps.c @@ -400,3 +400,13 @@ const uint8_t BITMAP_COMPAND[6] = __extension__ 0b01000010, __extension__ 0b00100100 }; + +const uint8_t BITMAP_FREQ_CHAN[6] = +{ + __extension__ 0b00000000, + __extension__ 0b01111110, + __extension__ 0b00010010, + __extension__ 0b00010010, + __extension__ 0b00000010, + __extension__ 0b00000010 +}; diff --git a/bitmaps.h b/bitmaps.h index 7ccb581..c2a8def 100644 --- a/bitmaps.h +++ b/bitmaps.h @@ -61,5 +61,7 @@ extern const uint8_t BITMAP_SCANLIST2[6]; extern const uint8_t BITMAP_COMPAND[6]; +extern const uint8_t BITMAP_FREQ_CHAN[6]; + #endif diff --git a/board.c b/board.c index 0ee4af2..cad5503 100644 --- a/board.c +++ b/board.c @@ -992,7 +992,7 @@ void BOARD_FactoryReset(bool bIsAll) g_rx_vfo->freq_config_rx.frequency = Frequency; g_rx_vfo->freq_config_tx.frequency = Frequency; g_rx_vfo->band = FREQUENCY_GetBand(Frequency); - SETTINGS_SaveChannel(USER_CHANNEL_FIRST + i, 0, g_rx_vfo, 2); + SETTINGS_save_channel(USER_CHANNEL_FIRST + i, 0, g_rx_vfo, 2); } } } diff --git a/driver/eeprom.c b/driver/eeprom.c index 606e4c6..3bff947 100644 --- a/driver/eeprom.c +++ b/driver/eeprom.c @@ -14,40 +14,60 @@ * limitations under the License. */ +#include // NULL and memcmp + #include "driver/eeprom.h" #include "driver/i2c.h" #include "driver/system.h" -void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size) +void EEPROM_ReadBuffer(const uint16_t address, void *p_buffer, const unsigned int size) { - I2C_Start(); + if (p_buffer == NULL || address >= 0x2000 || size == 0) + return; + I2C_Start(); I2C_Write(0xA0); - - I2C_Write((Address >> 8) & 0xFF); - I2C_Write((Address >> 0) & 0xFF); - + I2C_Write((address >> 8) & 0xFF); + I2C_Write((address >> 0) & 0xFF); I2C_Start(); - I2C_Write(0xA1); - - I2C_ReadBuffer(pBuffer, Size); - + I2C_ReadBuffer(p_buffer, size); I2C_Stop(); } -void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer) +void EEPROM_WriteBuffer(const uint16_t address, const void *p_buffer) { + if (p_buffer == NULL || address >= 0x2000) + return; + +#if 0 + // normal way + I2C_Start(); - I2C_Write(0xA0); - - I2C_Write((Address >> 8) & 0xFF); - I2C_Write((Address >> 0) & 0xFF); - - I2C_WriteBuffer(pBuffer, 8); - + I2C_Write((address >> 8) & 0xFF); + I2C_Write((address >> 0) & 0xFF); + I2C_WriteBuffer(p_buffer, 8); I2C_Stop(); - SYSTEM_DelayMs(10); +#else + // eeprom wear reduction + // only write the data IF it's different to what's already in eeprom + + uint8_t buffer[8]; + EEPROM_ReadBuffer(address, buffer, 8); + if (memcmp(p_buffer, buffer, 8) != 0) + { + I2C_Start(); + I2C_Write(0xA0); + I2C_Write((address >> 8) & 0xFF); + I2C_Write((address >> 0) & 0xFF); + I2C_WriteBuffer(p_buffer, 8); + I2C_Stop(); + } + +#endif + + // give the EEPROM time to burn the data in (apparently takes 5ms) + SYSTEM_DelayMs(8); } diff --git a/driver/eeprom.h b/driver/eeprom.h index 545c48c..32c5656 100644 --- a/driver/eeprom.h +++ b/driver/eeprom.h @@ -19,8 +19,8 @@ #include -void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size); -void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer); +void EEPROM_ReadBuffer(const uint16_t address, void *p_buffer, const unsigned int size); +void EEPROM_WriteBuffer(const uint16_t address, const void *p_buffer); #endif diff --git a/firmware.bin b/firmware.bin index eba2262..5ddc618 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index a88c502..867b58d 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/radio.c b/radio.c index da82f97..81864d0 100644 --- a/radio.c +++ b/radio.c @@ -22,6 +22,7 @@ #include "app/fm.h" #endif #include "audio.h" +#include "board.h" #include "bsp/dp32g030/gpio.h" #include "dcs.h" #include "driver/bk4819.h" @@ -120,8 +121,8 @@ void RADIO_InitInfo(vfo_info_t *pInfo, const uint8_t ChannelSave, const uint32_t memset(pInfo, 0, sizeof(*pInfo)); pInfo->band = FREQUENCY_GetBand(Frequency); - pInfo->scanlist_1_participation = true; - pInfo->scanlist_2_participation = true; + pInfo->scanlist_1_participation = 1; + pInfo->scanlist_2_participation = 1; pInfo->step_setting = STEP_12_5kHz; pInfo->step_freq = STEP_FREQ_TABLE[pInfo->step_setting]; pInfo->channel_save = ChannelSave; @@ -132,6 +133,7 @@ void RADIO_InitInfo(vfo_info_t *pInfo, const uint8_t ChannelSave, const uint32_t pInfo->p_rx = &pInfo->freq_config_rx; pInfo->p_tx = &pInfo->freq_config_tx; pInfo->compand = 0; // off + pInfo->frequency_channel = 0xff; if (ChannelSave == (FREQ_CHANNEL_FIRST + BAND2_108MHz)) pInfo->am_mode = 1; @@ -144,10 +146,8 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur uint8_t Channel; uint8_t Attributes; uint8_t Band; - bool bParticipation2; uint16_t Base; uint32_t Frequency; - vfo_info_t *pRadio = &g_eeprom.vfo_info[VFO]; if (!g_setting_350_enable) { @@ -160,12 +160,14 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur Channel = g_eeprom.screen_channel[VFO]; + g_eeprom.vfo_info[VFO].frequency_channel = 0xff; + if (IS_VALID_CHANNEL(Channel)) { #ifdef ENABLE_NOAA if (Channel >= NOAA_CHANNEL_FIRST) { - RADIO_InitInfo(pRadio, g_eeprom.screen_channel[VFO], NOAA_FREQUENCY_TABLE[Channel - NOAA_CHANNEL_FIRST]); + RADIO_InitInfo(&g_eeprom.vfo_info[VFO], g_eeprom.screen_channel[VFO], NOAA_FREQUENCY_TABLE[Channel - NOAA_CHANNEL_FIRST]); if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) return; g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF; @@ -206,32 +208,36 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur Index = Channel - FREQ_CHANNEL_FIRST; - RADIO_InitInfo(pRadio, Channel, FREQ_BAND_TABLE[Index].lower); + RADIO_InitInfo(&g_eeprom.vfo_info[VFO], Channel, FREQ_BAND_TABLE[Index].lower); return; } Band = Attributes & USER_CH_BAND_MASK; if (Band > BAND7_470MHz) - { Band = BAND6_400MHz; - } if (Channel <= USER_CHANNEL_LAST) - { + { // user channel g_eeprom.vfo_info[VFO].band = Band; - g_eeprom.vfo_info[VFO].scanlist_1_participation = (Attributes & USER_CH_SCANLIST1) ? true : false; - bParticipation2 = (Attributes & USER_CH_SCANLIST2) ? true : false; + g_eeprom.vfo_info[VFO].scanlist_2_participation = (Attributes & USER_CH_SCANLIST2) ? 1 : 0; + g_eeprom.vfo_info[VFO].scanlist_1_participation = (Attributes & USER_CH_SCANLIST1) ? 1 : 0; } else - { + if (IS_FREQ_CHANNEL(Channel)) + { // VFO channel Band = Channel - FREQ_CHANNEL_FIRST; - g_eeprom.vfo_info[VFO].band = Band; - bParticipation2 = true; - g_eeprom.vfo_info[VFO].scanlist_1_participation = true; + g_eeprom.vfo_info[VFO].band = Band; // shouldn't this be "Band / 2" ? .. two VFO's per band + #if 0 + g_eeprom.vfo_info[VFO].scanlist_2_participation = 1; + g_eeprom.vfo_info[VFO].scanlist_1_participation = 1; + #else + // allowing the vfo's to be included in the scanning + g_eeprom.vfo_info[VFO].scanlist_2_participation = (Attributes & USER_CH_SCANLIST2) ? 1 : 0; + g_eeprom.vfo_info[VFO].scanlist_1_participation = (Attributes & USER_CH_SCANLIST1) ? 1 : 0; + #endif } - g_eeprom.vfo_info[VFO].scanlist_2_participation = bParticipation2; - g_eeprom.vfo_info[VFO].channel_save = Channel; + g_eeprom.vfo_info[VFO].channel_save = Channel; if (Channel <= USER_CHANNEL_LAST) Base = Channel * 16; @@ -353,7 +359,7 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur EEPROM_ReadBuffer(Base, &info, sizeof(info)); - pRadio->freq_config_rx.frequency = info.frequency; + g_eeprom.vfo_info[VFO].freq_config_rx.frequency = info.frequency; if (info.offset >= 100000000) info.offset = 1000000; @@ -362,11 +368,14 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur // *************** } - Frequency = pRadio->freq_config_rx.frequency; + Frequency = g_eeprom.vfo_info[VFO].freq_config_rx.frequency; #if 1 - // fix previously set incorrect band + // fix previously maybe incorrect set band + Band = FREQUENCY_GetBand(Frequency); + g_eeprom.vfo_info[VFO].band = Band; + #endif if (Frequency < FREQ_BAND_TABLE[Band].lower) @@ -378,21 +387,23 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur if (Channel >= FREQ_CHANNEL_FIRST) Frequency = FREQUENCY_FloorToStep(Frequency, g_eeprom.vfo_info[VFO].step_freq, FREQ_BAND_TABLE[Band].lower); - pRadio->freq_config_rx.frequency = Frequency; + g_eeprom.vfo_info[VFO].freq_config_rx.frequency = Frequency; if (Frequency >= 10800000 && Frequency < 13600000) - g_eeprom.vfo_info[VFO].tx_offset_freq_dir = TX_OFFSET_FREQ_DIR_OFF; + g_eeprom.vfo_info[VFO].tx_offset_freq_dir = TX_OFFSET_FREQ_DIR_OFF; // air band else if (Channel > USER_CHANNEL_LAST) g_eeprom.vfo_info[VFO].tx_offset_freq = FREQUENCY_FloorToStep(g_eeprom.vfo_info[VFO].tx_offset_freq, g_eeprom.vfo_info[VFO].step_freq, 0); - RADIO_ApplyOffset(pRadio); + if (IS_FREQ_CHANNEL(Channel)) + g_eeprom.vfo_info[VFO].frequency_channel = BOARD_find_channel(Frequency); // remember if a channel has this frequency + + RADIO_ApplyOffset(&g_eeprom.vfo_info[VFO]); memset(g_eeprom.vfo_info[VFO].name, 0, sizeof(g_eeprom.vfo_info[VFO].name)); - if (Channel < USER_CHANNEL_LAST) - { // 16 bytes allocated to the channel name but only 10 used, the rest are 0's - EEPROM_ReadBuffer(0x0F50 + (Channel * 16), g_eeprom.vfo_info[VFO].name + 0, 8); - EEPROM_ReadBuffer(0x0F58 + (Channel * 16), g_eeprom.vfo_info[VFO].name + 8, 2); + if (Channel <= USER_CHANNEL_LAST) + { // only 10 bytes used + EEPROM_ReadBuffer(0x0F50 + (Channel * 16), g_eeprom.vfo_info[VFO].name, 10); } if (!g_eeprom.vfo_info[VFO].frequency_reverse) @@ -421,7 +432,7 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur g_eeprom.vfo_info[VFO].freq_config_tx.code_type = CODE_TYPE_NONE; } - RADIO_ConfigureSquelchAndOutputPower(pRadio); + RADIO_ConfigureSquelchAndOutputPower(&g_eeprom.vfo_info[VFO]); } void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *pInfo) diff --git a/radio.h b/radio.h index b2181c3..7e4cd18 100644 --- a/radio.h +++ b/radio.h @@ -113,6 +113,8 @@ typedef struct vfo_info_t uint8_t compand; + uint8_t frequency_channel; // channel number if a channel is set to this vfo's frequency + char name[16]; } vfo_info_t; diff --git a/settings.c b/settings.c index 6ca8c53..2d40019 100644 --- a/settings.c +++ b/settings.c @@ -27,7 +27,7 @@ eeprom_config_t g_eeprom; #ifdef ENABLE_FMRADIO - void SETTINGS_SaveFM(void) + void SETTINGS_save_fm(void) { unsigned int i; @@ -51,7 +51,7 @@ eeprom_config_t g_eeprom; } #endif -void SETTINGS_SaveVfoIndices(void) +void SETTINGS_save_vfo_indices(void) { uint8_t State[8]; @@ -188,10 +188,10 @@ void SETTINGS_restore_calibration(void) // ************************************************* -void SETTINGS_SaveSettings(void) +void SETTINGS_save(void) { uint8_t State[8]; - + State[0] = g_eeprom.chan_1_call; State[1] = g_eeprom.squelch_level; State[2] = g_eeprom.tx_timeout_timer; @@ -336,118 +336,107 @@ void SETTINGS_SaveSettings(void) #endif State[7] = (State[7] & ~(3u << 6)) | ((g_setting_backlight_on_tx_rx & 3u) << 6); EEPROM_WriteBuffer(0x0F40, State); - + memset(State, 0xFF, sizeof(State)); State[0] = g_eeprom.scan_hold_time_500ms; EEPROM_WriteBuffer(0x0F48, State); } -void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const vfo_info_t *pVFO, uint8_t Mode) +void SETTINGS_save_channel(const uint8_t channel, const uint8_t vfo, const vfo_info_t *p_vfo, const uint8_t mode) { - const uint16_t OffsetMR = Channel * 16; - uint16_t OffsetVFO = OffsetMR; - uint8_t State[8]; + const uint16_t offset_mem = channel * 16; + uint16_t offset_vfo = offset_mem; + uint8_t state[16]; +// t_channel channel_data; - if (IS_NOAA_CHANNEL(Channel)) + if (p_vfo == NULL || IS_NOAA_CHANNEL(channel)) return; - if (IS_FREQ_CHANNEL(Channel)) + if (IS_FREQ_CHANNEL(channel)) { // it's a VFO - OffsetVFO = (VFO == 0) ? 0x0C80 : 0x0C90; - OffsetVFO += (Channel - FREQ_CHANNEL_FIRST) * 32; + offset_vfo = (vfo == 0) ? 0x0C80 : 0x0C90; + offset_vfo += (channel - FREQ_CHANNEL_FIRST) * 16 * 2; } - if (Mode < 2 && Channel <= USER_CHANNEL_LAST) + if (mode < 2 && channel <= USER_CHANNEL_LAST) return; #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) -// UART_printf("sav_chan %u %u %u\r\n", Channel, VFO, Mode); +// UART_printf("sav_chan %u %u %u\r\n", channel, vfo, mode); #endif - ((uint32_t *)State)[0] = pVFO->freq_config_rx.frequency; - ((uint32_t *)State)[1] = pVFO->tx_offset_freq; - EEPROM_WriteBuffer(OffsetVFO + 0, State); + ((uint32_t *)state)[0] = p_vfo->freq_config_rx.frequency; + ((uint32_t *)state)[1] = p_vfo->tx_offset_freq; + EEPROM_WriteBuffer(offset_vfo, state); - State[0] = pVFO->freq_config_rx.code; - State[1] = pVFO->freq_config_tx.code; - State[2] = (pVFO->freq_config_tx.code_type << 4) | pVFO->freq_config_rx.code_type; - State[3] = ((pVFO->am_mode & 1u) << 4) | pVFO->tx_offset_freq_dir; - State[4] = - (pVFO->compand << 6) | - (pVFO->busy_channel_lock << 4) | - (pVFO->output_power << 2) | - (pVFO->channel_bandwidth << 1) | - (pVFO->frequency_reverse << 0); - State[5] = ((pVFO->dtmf_ptt_id_tx_mode & 7u) << 1) | ((pVFO->dtmf_decoding_enable & 1u) << 0); - State[6] = pVFO->step_setting; - State[7] = pVFO->scrambling_type; - EEPROM_WriteBuffer(OffsetVFO + 8, State); + state[0] = p_vfo->freq_config_rx.code; + state[1] = p_vfo->freq_config_tx.code; + state[2] = (p_vfo->freq_config_tx.code_type << 4) | p_vfo->freq_config_rx.code_type; + state[3] = ((p_vfo->am_mode & 1u) << 4) | p_vfo->tx_offset_freq_dir; + state[4] = + ((p_vfo->compand & 3u) << 6) | + ((p_vfo->busy_channel_lock & 3u) << 4) | + ((p_vfo->output_power & 1u) << 2) | + ((p_vfo->channel_bandwidth & 1u) << 1) | + ((p_vfo->frequency_reverse & 1u) << 0); + state[5] = ((p_vfo->dtmf_ptt_id_tx_mode & 7u) << 1) | ((p_vfo->dtmf_decoding_enable & 1u) << 0); + state[6] = p_vfo->step_setting; + state[7] = p_vfo->scrambling_type; + EEPROM_WriteBuffer(offset_vfo + 8, state); - SETTINGS_UpdateChannel(Channel, pVFO, true); + SETTINGS_save_chan_attribs_name(channel, p_vfo); - if (Channel > USER_CHANNEL_LAST) + if (channel > USER_CHANNEL_LAST) return; // it's not a user memory channel #ifndef ENABLE_KEEP_MEM_NAME - // clear/reset the channel name - memset(&State, 0, sizeof(State)); - EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); - EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); + { // clear/reset the channel name + memset(&state, 0, sizeof(state)); + EEPROM_WriteBuffer(0x0F50 + 0 + offset_mem, state + 0); + EEPROM_WriteBuffer(0x0F50 + 8 + offset_mem, state + 8); + } #else - if (Mode >= 3) + if (mode >= 3) { // save the channel name - memmove(State, pVFO->name + 0, 8); - EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); - memset(State, 0, sizeof(State)); - memmove(State, pVFO->name + 8, 2); - EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); + memset(state, 0, sizeof(state)); + memmove(state, p_vfo->name, 10); + + EEPROM_WriteBuffer(0x0F50 + 0 + offset_mem, state + 0); + EEPROM_WriteBuffer(0x0F50 + 8 + offset_mem, state + 8); } #endif } -void SETTINGS_UpdateChannel(uint8_t Channel, const vfo_info_t *pVFO, bool keep) +void SETTINGS_save_chan_attribs_name(const uint8_t channel, const vfo_info_t *p_vfo) { - uint8_t State[8]; - uint8_t Attributes = 0xFF; // default attributes - uint16_t Offset = 0x0D60 + (Channel & ~7u); - - if (IS_NOAA_CHANNEL(Channel)) + if (p_vfo == NULL || channel >= ARRAY_SIZE(g_user_channel_attributes)) return; - EEPROM_ReadBuffer(Offset, State, sizeof(State)); + if (IS_NOAA_CHANNEL(channel)) + return; - if (keep) - { - Attributes = (pVFO->scanlist_1_participation << 7) | (pVFO->scanlist_2_participation << 6) | (pVFO->band << 0); - if (State[Channel & 7u] == Attributes) - return; // no change in the attributes .. don't place wear on the eeprom + { // 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); + + const unsigned int index = channel & ~7u; // eeprom writes are always 8 bytes in length + g_user_channel_attributes[channel] = attribs; // remember new attributes + EEPROM_WriteBuffer(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]; - State[Channel & 7u] = Attributes; + memset(name, 0, sizeof(name)); + memmove(name, p_vfo->name, 10); - EEPROM_WriteBuffer(Offset, State); - - g_user_channel_attributes[Channel] = Attributes; - -// #ifndef ENABLE_KEEP_MEM_NAME - if (Channel <= USER_CHANNEL_LAST) - { // user memory channel - - const uint16_t OffsetMR = Channel * 16; - if (!keep) - { // clear/reset the channel name - memset(&State, 0, sizeof(State)); - EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); - EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); - } -// else -// { // update the channel name -// memmove(State, pVFO->name + 0, 8); -// EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); -// memset(State, 0, sizeof(State)); -// memmove(State, pVFO->name + 8, 2); -// EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); -// } - } -// #endif + EEPROM_WriteBuffer(0x0F50 + 0 + index, name + 0); + EEPROM_WriteBuffer(0x0F50 + 8 + index, name + 8); + } } diff --git a/settings.h b/settings.h index 3988e57..25b39f3 100644 --- a/settings.h +++ b/settings.h @@ -268,8 +268,8 @@ typedef struct { // 0x0D60 struct { // these channel attribute settings could have been in the t_channel structure ! - uint8_t band:4; // why do QS have these 4 bits ? .. band can/is computed from the frequency - uint8_t unused:2; // 0's + 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 is in scan list 2 uint8_t scanlist1:1; // set if is in scan list 1 } __attribute__((packed)) channel_attr[200]; // @@ -559,12 +559,12 @@ typedef struct { extern eeprom_config_t g_eeprom; #ifdef ENABLE_FMRADIO - void SETTINGS_SaveFM(void); + void SETTINGS_save_fm(void); #endif -void SETTINGS_SaveVfoIndices(void); +void SETTINGS_save_vfo_indices(void); //void SETTINGS_restore_calibration(void); -void SETTINGS_SaveSettings(void); -void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const vfo_info_t *pVFO, uint8_t Mode); -void SETTINGS_UpdateChannel(uint8_t Channel, const vfo_info_t *pVFO, bool keep); +void SETTINGS_save(void); +void SETTINGS_save_channel(const uint8_t channel, const uint8_t vfo, const vfo_info_t *p_vfo, const uint8_t mode); +void SETTINGS_save_chan_attribs_name(const uint8_t channel, const vfo_info_t *p_vfo); #endif diff --git a/ui/main.c b/ui/main.c index d60b578..9e0c757 100644 --- a/ui/main.c +++ b/ui/main.c @@ -240,39 +240,39 @@ void UI_drawBars(uint8_t *p, const unsigned int level) { // const int16_t s0_dBm = -127; // S0 .. base level const int16_t s0_dBm = -147; // S0 .. base level - + const int16_t s9_dBm = s0_dBm + (6 * 9); // S9 .. 6dB/S-Point const int16_t bar_max_dBm = s9_dBm + 30; // S9+30dB // const int16_t bar_min_dBm = s0_dBm + (6 * 0); // S0 const int16_t bar_min_dBm = s0_dBm + (6 * 4); // S4 - + // ************ - + const unsigned int txt_width = 7 * 8; // 8 text chars const unsigned int bar_x = 2 + txt_width + 4; // X coord of bar graph const unsigned int bar_width = LCD_WIDTH - 1 - bar_x; - + const int16_t rssi_dBm = (rssi / 2) - 160; const int16_t clamped_dBm = (rssi_dBm <= bar_min_dBm) ? bar_min_dBm : (rssi_dBm >= bar_max_dBm) ? bar_max_dBm : rssi_dBm; const unsigned int bar_range_dB = bar_max_dBm - bar_min_dBm; const unsigned int len = ((clamped_dBm - bar_min_dBm) * bar_width) / bar_range_dB; - + const unsigned int line = 3; uint8_t *p_line = g_frame_buffer[line]; - + char s[16]; - + if (g_eeprom.key_lock && g_keypad_locked > 0) return false; // display is in use - + if (g_current_function == FUNCTION_TRANSMIT || g_screen_to_display != DISPLAY_MAIN || g_dtmf_call_state != DTMF_CALL_STATE_NONE) return false; // display is in use - + if (now) memset(p_line, 0, LCD_WIDTH); - + if (rssi_dBm >= (s9_dBm + 6)) { // S9+XXdB, 1dB increment const char *fmt[] = {"%3d 9+%u ", "%3d 9+%2u "}; @@ -285,12 +285,12 @@ void UI_drawBars(uint8_t *p, const unsigned int level) sprintf(s, "%4d S%u ", rssi_dBm, s_level); } UI_PrintStringSmall(s, 2, 0, line); - + draw_bar(p_line + bar_x, len, bar_width); - + if (now) ST7565_BlitFullScreen(); - + return true; } @@ -643,28 +643,13 @@ void UI_DisplayMain(void) if (g_eeprom.screen_channel[vfo_num] <= USER_CHANNEL_LAST) { // it's a channel - - // show the channel symbols - const uint8_t attributes = g_user_channel_attributes[g_eeprom.screen_channel[vfo_num]]; - if (attributes & USER_CH_SCANLIST1) - memmove(p_line0 + 113, BITMAP_SCANLIST1, sizeof(BITMAP_SCANLIST1)); - if (attributes & USER_CH_SCANLIST2) - memmove(p_line0 + 120, BITMAP_SCANLIST2, sizeof(BITMAP_SCANLIST2)); - #ifndef ENABLE_BIG_FREQ - if (g_eeprom.vfo_info[vfo_num].compand) - memmove(p_line0 + 120 + LCD_WIDTH, BITMAP_COMPAND, sizeof(BITMAP_COMPAND)); - #else - - // TODO: // find somewhere else to put the symbol - - #endif - #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wimplicit-fallthrough=" switch (g_eeprom.channel_display_mode) { - case MDF_FREQUENCY: // show the channel frequency + case MDF_FREQUENCY: // just channel frequency + #ifdef ENABLE_BIG_FREQ NUMBER_ToDigits(frequency, String); // show the main large frequency digits @@ -676,35 +661,41 @@ void UI_DisplayMain(void) sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000); UI_PrintString(String, 32, 0, line, 8); #endif + break; - case MDF_CHANNEL: // show the channel number + case MDF_CHANNEL: // just channel number + sprintf(String, "CH-%03u", g_eeprom.screen_channel[vfo_num] + 1); UI_PrintString(String, 32, 0, line, 8); + break; - case MDF_NAME: // show the channel name - case MDF_NAME_FREQ: // show the channel name and frequency + case MDF_NAME: // channel name + case MDF_NAME_FREQ: // channel name and frequency BOARD_fetchChannelName(String, g_eeprom.screen_channel[vfo_num]); + if (String[0] == 0) - { // no channel name, show the channel number instead + { // no channel name available, channel number instead sprintf(String, "CH-%03u", g_eeprom.screen_channel[vfo_num] + 1); } if (g_eeprom.channel_display_mode == MDF_NAME) - { + { // just the name UI_PrintString(String, 32, 0, line, 8); } else - { + { // name & frequency + + // name #ifdef ENABLE_SMALL_BOLD UI_PrintStringSmallBold(String, 32 + 4, 0, line); #else UI_PrintStringSmall(String, 32 + 4, 0, line); #endif - // show the channel frequency below the channel number/name + // frequency sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000); UI_PrintStringSmall(String, 32 + 4, 0, line + 1); } @@ -715,6 +706,7 @@ void UI_DisplayMain(void) #pragma GCC diagnostic pop } else +// if (IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo_num])) { // frequency mode #ifdef ENABLE_BIG_FREQ NUMBER_ToDigits(frequency, String); // 8 digits @@ -727,16 +719,48 @@ void UI_DisplayMain(void) sprintf(String, "%03u.%05u", frequency / 100000, frequency % 100000); UI_PrintString(String, 32, 0, line, 8); #endif - - // show the channel symbols - //const uint8_t attributes = g_user_channel_attributes[g_eeprom.screen_channel[vfo_num]]; - if (g_eeprom.vfo_info[vfo_num].compand) - #ifdef ENABLE_BIG_FREQ - memmove(p_line0 + 120, BITMAP_COMPAND, sizeof(BITMAP_COMPAND)); - #else - memmove(p_line0 + 120 + LCD_WIDTH, BITMAP_COMPAND, sizeof(BITMAP_COMPAND)); - #endif } + + // show channel symbols + + //if (g_eeprom.screen_channel[vfo_num] <= USER_CHANNEL_LAST) + if (IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[vfo_num])) + { // 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]]; + + if (attributes & USER_CH_SCANLIST1) + memmove(p_line0 + x, BITMAP_SCANLIST1, sizeof(BITMAP_SCANLIST1)); + x += sizeof(BITMAP_SCANLIST1); + + if (attributes & USER_CH_SCANLIST2) + memmove(p_line0 + x, BITMAP_SCANLIST2, sizeof(BITMAP_SCANLIST2)); + //x += sizeof(BITMAP_SCANLIST2); + } + + #ifdef ENABLE_BIG_FREQ + + // no room for these symbols + + #else + { + unsigned int x = LCD_WIDTH + LCD_WIDTH - 1 - sizeof(BITMAP_FREQ_CHAN) - sizeof(BITMAP_COMPAND); + + if (g_eeprom.vfo_info[vfo_num].compand) + memmove(p_line0 + x, BITMAP_COMPAND, sizeof(BITMAP_COMPAND)); + x += sizeof(BITMAP_COMPAND); + + if (IS_FREQ_CHANNEL(g_eeprom.screen_channel[vfo_num])) + { + //g_eeprom.vfo_info[vfo_num].frequency_channel = BOARD_find_channel(frequency); + if (g_eeprom.vfo_info[vfo_num].frequency_channel <= USER_CHANNEL_LAST) + memmove(p_line0 + x, BITMAP_FREQ_CHAN, sizeof(BITMAP_FREQ_CHAN)); + //x += sizeof(BITMAP_FREQ_CHAN); + } + } + #endif } // ************