diff --git a/Makefile b/Makefile index a8cdc7f..60113a7 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,6 @@ ENABLE_BIG_FREQ := 0 ENABLE_SMALL_BOLD := 1 ENABLE_KEEP_MEM_NAME := 1 ENABLE_WIDE_RX := 1 -ENABLE_1250HZ_STEP := 1 ENABLE_TX_WHEN_AM := 0 ENABLE_F_CAL_MENU := 0 ENABLE_TX_UNLOCK := 0 @@ -304,9 +303,6 @@ endif ifeq ($(ENABLE_WIDE_RX),1) CFLAGS += -DENABLE_WIDE_RX endif -ifeq ($(ENABLE_1250HZ_STEP),1) - CFLAGS += -DENABLE_1250HZ_STEP -endif ifeq ($(ENABLE_TX_WHEN_AM),1) CFLAGS += -DENABLE_TX_WHEN_AM endif diff --git a/README.md b/README.md index 4661b48..f1d5d57 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,6 @@ ENABLE_BIG_FREQ := 0 big font frequencies (like original ENABLE_SMALL_BOLD := 1 bold channel name/no. (when name + freq channel display mode) ENABLE_KEEP_MEM_NAME := 1 maintain channel name when (re)saving memory channel ENABLE_WIDE_RX := 1 full 18MHz to 1300MHz RX (though front-end/PA not designed for full range) -ENABLE_1250HZ_STEP := 1 enable smaller 1.25kHz frequency steps ENABLE_TX_WHEN_AM := 0 allow TX (always FM) when RX is set to AM ENABLE_F_CAL_MENU := 0 enable/disable the radios hidden frequency calibration menu ENABLE_TX_UNLOCK := 0 allow TX everywhere EXCEPT airband (108~136) .. TX harmonic content will cause interference to other services, do so entirely at your own risk ! diff --git a/app/main.c b/app/main.c index dd1e980..32fbf66 100644 --- a/app/main.c +++ b/app/main.c @@ -340,8 +340,8 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) return; } - if (key_pressed) - { // key is pressed + if (key_pressed && !key_held) + { // key just pressed g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; return; // don't use the key till it's released } @@ -519,8 +519,8 @@ void MAIN_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) void MAIN_Key_EXIT(bool key_pressed, bool key_held) { - if (!key_held && key_pressed) - { // exit key pressed + if (key_pressed && !key_held) + { // key just pressed g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; @@ -586,9 +586,10 @@ void MAIN_Key_EXIT(bool key_pressed, bool key_held) void MAIN_Key_MENU(const bool key_pressed, const bool key_held) { if (key_pressed && !key_held) - // menu key pressed + { // key just pressed g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; - + } + if (key_held) { // menu key held down (long press) @@ -685,10 +686,8 @@ void MAIN_Key_STAR(bool key_pressed, bool key_held) { if (g_input_box_index > 0) { // entering a channel, frequency or DTMF string - if (!key_held && key_pressed) g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; - return; } @@ -763,6 +762,11 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio uint8_t Channel = g_eeprom.screen_channel[g_eeprom.tx_vfo]; + if (key_pressed && !key_held) + { // key just pressed + g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; + } + if (!key_pressed && g_scan_state_dir == SCAN_STATE_DIR_OFF && IS_NOT_NOAA_CHANNEL(Channel) && @@ -831,7 +835,7 @@ void MAIN_Key_UP_DOWN(bool key_pressed, bool key_held, scan_state_dir_t Directio const frequency_band_t old_band = FREQUENCY_GetBand(g_tx_vfo->freq_config_rx.frequency); const uint32_t frequency = APP_set_frequency_by_step(g_tx_vfo, Direction); - if (RX_freq_check(frequency) < 0) + if (FREQUENCY_rx_freq_check(frequency) < 0) { // frequency not allowed g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; return; diff --git a/app/menu.c b/app/menu.c index 39d83fc..40ad373 100644 --- a/app/menu.c +++ b/app/menu.c @@ -393,7 +393,7 @@ void MENU_AcceptSetting(void) break; case MENU_STEP: - g_tx_vfo->step_setting = g_sub_menu_selection; + g_tx_vfo->step_setting = step_freq_table_sorted[g_sub_menu_selection]; if (IS_FREQ_CHANNEL(g_tx_vfo->channel_save)) { g_request_save_channel = 1; @@ -935,9 +935,9 @@ void MENU_ShowCurrentSetting(void) break; case MENU_STEP: - g_sub_menu_selection = g_tx_vfo->step_setting; + g_sub_menu_selection = FREQUENCY_get_step_index(STEP_FREQ_TABLE[g_tx_vfo->step_setting]); break; - + case MENU_TX_POWER: g_sub_menu_selection = g_tx_vfo->output_power; break; diff --git a/app/search.c b/app/search.c index 47eceed..d107790 100644 --- a/app/search.c +++ b/app/search.c @@ -180,95 +180,14 @@ static void SEARCH_Key_MENU(bool key_pressed, bool key_held) if (!g_search_single_frequency) { - #if 0 - - uint32_t Freq250 = FREQUENCY_FloorToStep(g_search_frequency, 250, 0); - uint32_t Freq625 = FREQUENCY_FloorToStep(g_search_frequency, 625, 0); - - int16_t Delta250 = (int16_t)g_search_frequency - (int16_t)Freq250; - int16_t Delta625; - - if (125 < Delta250) - { - Delta250 = 250 - Delta250; - Freq250 += 250; - } - - Delta625 = (int16_t)g_search_frequency - (int16_t)Freq625; - - if (312 < Delta625) - { - Delta625 = 625 - Delta625; - Freq625 += 625; - } - - if (Delta625 < Delta250) - { - g_search_step_setting = STEP_6_25kHz; - g_search_frequency = Freq625; - } - else - { - g_search_step_setting = STEP_2_5kHz; - g_search_frequency = Freq250; - } - - #elif 0 - - #ifdef ENABLE_1250HZ_STEP - const step_setting_t small_step = STEP_1_25kHz; - const step_setting_t big_step = STEP_6_25kHz; - #else - const step_setting_t small_step = STEP_2_5kHz; - const step_setting_t big_step = STEP_6_25kHz; - #endif - - const uint32_t small_step_freq = STEP_FREQ_TABLE[small_step]; - const uint32_t big_step_freq = STEP_FREQ_TABLE[big_step]; - - uint32_t freq_small_step = FREQUENCY_FloorToStep(g_search_frequency, small_step_freq, 0); - uint32_t freq_big_step = FREQUENCY_FloorToStep(g_search_frequency, big_step_freq, 0); - - int32_t delta_small_step = (int32_t)g_search_frequency - freq_small_step; - int32_t delta_big_step = (int32_t)g_search_frequency - freq_big_step; - - if (delta_small_step > 125) - { - delta_small_step = STEP_FREQ_TABLE[small_step] - delta_small_step; - freq_big_step += small_step_freq; - } - - delta_big_step = (int32_t)g_search_frequency - freq_big_step; - - if (delta_big_step > 312) - { - delta_big_step = big_step_freq - delta_big_step; - freq_big_step += big_step_freq; - } - - if (delta_small_step >= delta_big_step) - { - g_search_step_setting = small_step; - g_search_frequency = freq_small_step; - } - else - { - g_search_step_setting = big_step; - g_search_frequency = freq_big_step; - } - - #else - - // 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); - { // 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; - } - - #endif + // 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); + { // 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; + } } if (g_tx_vfo->channel_save <= USER_CHANNEL_LAST) diff --git a/firmware.bin b/firmware.bin index b869645..80fe3a6 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 1a266f8..0de14de 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/frequencies.c b/frequencies.c index 8a02dc9..dae752b 100644 --- a/frequencies.c +++ b/frequencies.c @@ -14,15 +14,16 @@ * limitations under the License. */ +#include "driver/uart.h" #include "frequencies.h" #include "misc.h" #include "settings.h" -// the default AIRCOPY frequency to use +// the default AIRCOPY frequency uint32_t g_aircopy_freq = 41002500; // FM broadcast band lower/upper limit -const freq_band_table_t FM_RADIO_BAND = {760, 1080}; +const freq_band_table_t FM_RADIO_BAND = {880, 1080}; // the BK4819 has 2 bands it covers, 18MHz ~ 630MHz and 760MHz ~ 1300MHz const freq_band_table_t BX4819_BAND1 = { 1800000, 63000000}; @@ -45,7 +46,7 @@ const freq_band_table_t FREQ_BAND_TABLE[7] = {10800000, 13600000}, // band 2 {13600000, 17400000}, // band 3 {17400000, 35000000}, // band 4 - {35000000, 40000000}, // band 5 + {35000000, 40000000}, // band 5 {40000000, 47000000}, // band 6 {47000000, 60000000} // band 7 #endif @@ -67,22 +68,63 @@ const freq_band_table_t FREQ_BAND_TABLE[7] = }; #endif -#ifdef ENABLE_1250HZ_STEP - // includes 1.25kHz step - const uint16_t STEP_FREQ_TABLE[7] = {125, 250, 625, 1000, 1250, 2500, 833}; -// const uint16_t STEP_FREQ_TABLE[7] = {125, 250, 625, 1000, 1250, 2500, 833, 10, 50}; -#else - // QS steps (*10 Hz) - const uint16_t STEP_FREQ_TABLE[7] = {250, 500, 625, 1000, 1250, 2500, 833}; -// const uint16_t STEP_FREQ_TABLE[7] = {250, 500, 625, 1000, 1250, 2500, 833, 10, 50}; -#endif +// the first 7 values MUST remain in those same positions (to remain compatible with the QS config windows software) +const uint16_t STEP_FREQ_TABLE[21] = { + 250, 500, 625, 1000, 1250, 2500, 833, + 1, 5, 10, 25, 50, 100, 125, 1500, 3000, 5000, 10000, 12500, 25000, 50000 +}; +uint16_t step_freq_table_sorted[ARRAY_SIZE(STEP_FREQ_TABLE)]; + +unsigned int FREQUENCY_get_step_index(const unsigned int step_size) +{ // return the index into 'STEP_FREQ_TABLE' for the supplied step size + unsigned int i; + for (i = 0; i < ARRAY_SIZE(step_freq_table_sorted); i++) + if (STEP_FREQ_TABLE[step_freq_table_sorted[i]] == step_size) + return i; + // not found, so default to 12.5kHz + return 11; +} + +void FREQUENCY_init(void) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(step_freq_table_sorted); i++) + step_freq_table_sorted[i] = i; + + // sort according to step size + for (i = 0; i < ARRAY_SIZE(step_freq_table_sorted) - 1; i++) + { + uint16_t step1 = STEP_FREQ_TABLE[step_freq_table_sorted[i]]; + unsigned int k; + for (k = i + 1; k < ARRAY_SIZE(step_freq_table_sorted); k++) + { + const uint16_t step2 = STEP_FREQ_TABLE[step_freq_table_sorted[k]]; + if (step2 < step1) + { // swap + const uint16_t temp = step_freq_table_sorted[i]; + step_freq_table_sorted[i] = step_freq_table_sorted[k]; + step_freq_table_sorted[k] = temp; + step1 = STEP_FREQ_TABLE[step_freq_table_sorted[i]]; + } + } + } +/* + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) + UART_SendText("step ..\r\n"); + for (i = 0; i < ARRAY_SIZE(step_freq_table_sorted); i++) + UART_printf("%2u %2u %5u\r\n", i, step_freq_table_sorted[i], STEP_FREQ_TABLE[step_freq_table_sorted[i]]); + UART_SendText("\r\n"); + #endif +*/ +} frequency_band_t FREQUENCY_GetBand(uint32_t Frequency) { int band; for (band = ARRAY_SIZE(FREQ_BAND_TABLE) - 1; band >= 0; band--) - if (Frequency >= FREQ_BAND_TABLE[band].lower) -// if (Frequency < FREQ_BAND_TABLE[band].upper) + if (Frequency >= FREQ_BAND_TABLE[band].lower && Frequency < FREQ_BAND_TABLE[band].upper) +// if (Frequency >= FREQ_BAND_TABLE[band].lower) return (frequency_band_t)band; return BAND1_50MHz; @@ -92,7 +134,7 @@ frequency_band_t FREQUENCY_GetBand(uint32_t Frequency) uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, int32_t LowerLimit, int32_t Middle, int32_t UpperLimit, int32_t Frequency) { uint8_t pwr = TxpMid; - + if (Frequency <= LowerLimit) return TxpLow; @@ -111,28 +153,28 @@ uint32_t FREQUENCY_FloorToStep(uint32_t Upper, uint32_t Step, uint32_t Lower) { #if 1 uint32_t Index; - + if (Step == 833) { const uint32_t Delta = Upper - Lower; uint32_t Base = (Delta / 2500) * 2500; const uint32_t Index = ((Delta - Base) % 2500) / 833; - + if (Index == 2) Base++; - + return Lower + Base + (Index * 833); } - + Index = (Upper - Lower) / Step; - + return Lower + (Step * Index); #else return Lower + (((Upper - Lower) / Step) * Step); #endif } -int TX_freq_check(const uint32_t Frequency) +int FREQUENCY_tx_freq_check(const uint32_t Frequency) { // return '0' if TX frequency is allowed // otherwise return '-1' @@ -200,7 +242,7 @@ int TX_freq_check(const uint32_t Frequency) if (Frequency >= 40000000 && Frequency < 43800000) return 0; break; - + case FREQ_LOCK_446: if (Frequency >= 446.00625 && Frequency <= 446.19375) return 0; @@ -222,7 +264,7 @@ int TX_freq_check(const uint32_t Frequency) return -1; } -int RX_freq_check(const uint32_t Frequency) +int FREQUENCY_rx_freq_check(const uint32_t Frequency) { // return '0' if RX frequency is allowed // otherwise return '-1' diff --git a/frequencies.h b/frequencies.h index d32d513..2f53dde 100644 --- a/frequencies.h +++ b/frequencies.h @@ -20,6 +20,7 @@ #include #include "frequencies.h" +#include "misc.h" enum frequency_band_e { BAND_NONE = -1, @@ -47,47 +48,52 @@ extern const freq_band_table_t BX4819_BAND2; extern const freq_band_table_t FREQ_BAND_TABLE[7]; -#ifdef ENABLE_1250HZ_STEP - // includes 1.25kHz step - enum step_setting_e { - STEP_1_25kHz = 0, - STEP_2_5kHz, - STEP_6_25kHz, - STEP_10_0kHz, - STEP_12_5kHz, - STEP_25_0kHz, - STEP_8_33kHz, -// STEP_100Hz, -// STEP_500Hz - }; -#else - // QS steps - enum step_setting_e { - STEP_2_5kHz = 0, - STEP_5_0kHz, - STEP_6_25kHz, - STEP_10_0kHz, - STEP_12_5kHz, - STEP_25_0kHz, - STEP_8_33kHz, -// STEP_100Hz, -// STEP_500Hz - }; -#endif +// 250, 500, 625, 1000, 1250, 2500, 833, 1, 5, 10, 25, 50, 100, 125, 1500, 3000, 5000, 10000, 12500, 25000, 50000 +enum step_setting_e { + STEP_2_5kHz = 0, + STEP_5_0kHz, + STEP_6_25kHz, + STEP_10_0kHz, + STEP_12_5kHz, + STEP_25_0kHz, + STEP_8_33kHz, + + STEP_10Hz, + STEP_50Hz, + STEP_100Hz, + STEP_250Hz, + STEP_500Hz, + STEP_1kHz, + STEP_1_25kHz, + STEP_15kHz, + STEP_30kHz, + STEP_50kHz, + STEP_100kHz, + STEP_125kHz, + STEP_250kHz, + STEP_500kHz +}; typedef enum step_setting_e step_setting_t; -extern const uint16_t STEP_FREQ_TABLE[7]; -//extern const uint16_t STEP_FREQ_TABLE[9]; +extern const uint16_t STEP_FREQ_TABLE[21]; +extern uint16_t step_freq_table_sorted[ARRAY_SIZE(STEP_FREQ_TABLE)]; #ifdef ENABLE_NOAA extern const uint32_t NOAA_FREQUENCY_TABLE[10]; #endif +// *********** + +unsigned int FREQUENCY_get_step_index(const unsigned int step_size); +void FREQUENCY_init(void); + frequency_band_t FREQUENCY_GetBand(uint32_t Frequency); uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, int32_t LowerLimit, int32_t Middle, int32_t UpperLimit, int32_t Frequency); uint32_t FREQUENCY_FloorToStep(uint32_t Upper, uint32_t Step, uint32_t Lower); -int TX_freq_check(const uint32_t Frequency); -int RX_freq_check(const uint32_t Frequency); +int FREQUENCY_tx_freq_check(const uint32_t Frequency); +int FREQUENCY_rx_freq_check(const uint32_t Frequency); + +// *********** #endif diff --git a/main.c b/main.c index 14abe61..e50386f 100644 --- a/main.c +++ b/main.c @@ -65,8 +65,8 @@ void Main(void) | SYSCON_DEV_CLK_GATE_AES_BITS_ENABLE; SYSTICK_Init(); - BOARD_Init(); UART_Init(); + BOARD_Init(); #if defined(ENABLE_UART) UART_SendText(UART_Version_str); @@ -80,6 +80,8 @@ void Main(void) memset(g_dtmf_string, '-', sizeof(g_dtmf_string)); g_dtmf_string[sizeof(g_dtmf_string) - 1] = 0; + FREQUENCY_init(); + #if 0 SETTINGS_restore_calibration(); #endif diff --git a/radio.c b/radio.c index c2d2195..14220f8 100644 --- a/radio.c +++ b/radio.c @@ -1021,7 +1021,7 @@ void RADIO_PrepareTX(void) State = VFO_STATE_TX_DISABLE; } else - if (TX_freq_check(g_current_vfo->p_tx->frequency) == 0) + if (FREQUENCY_tx_freq_check(g_current_vfo->p_tx->frequency) == 0) { // TX frequency is allowed if (g_current_vfo->busy_channel_lock && g_current_function == FUNCTION_RECEIVE) State = VFO_STATE_BUSY; // busy RX'ing a station diff --git a/ui/menu.c b/ui/menu.c index b1fd1aa..8ffbb55 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -26,6 +26,7 @@ #include "driver/bk4819.h" #include "driver/eeprom.h" // EEPROM_ReadBuffer() #include "driver/st7565.h" +#include "driver/uart.h" #include "external/printf/printf.h" #include "frequencies.h" #include "helper/battery.h" @@ -410,8 +411,6 @@ void UI_SortMenu(const bool hide_hidden) // this means the menu order is entirely determined by the enum list (found in id/menu.h) // it now no longer depends on the order of entries in the above const list (they can be any order) -// unsigned int i; - unsigned int hidden_menu_count = g_hidden_menu_count; #ifndef ENABLE_F_CAL_MENU @@ -420,16 +419,22 @@ void UI_SortMenu(const bool hide_hidden) g_menu_list_count = ARRAY_SIZE(g_menu_list); - // linear index array -// for (i = 0; i < ARRAY_SIZE(g_menu_list_sorted); i++) -// g_menu_list_sorted[i] = i; - // sort non-hidden entries at the beginning sort_list(0, g_menu_list_count - hidden_menu_count); // sort the hidden entries at the end sort_list(g_menu_list_count - hidden_menu_count, hidden_menu_count); - +/* + #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG) + { + unsigned int i; + UART_SendText("menu ..\r\n"); + for (i = 0; i < ARRAY_SIZE(g_menu_list_sorted); i++) + UART_printf("%3u %3u %3u\r\n", i, g_menu_list_sorted[i], g_menu_list[g_menu_list_sorted[i]].menu_id); + UART_SendText("\r\n"); + } + #endif +*/ if (hide_hidden) g_menu_list_count -= hidden_menu_count; // hide the hidden menu items } @@ -544,9 +549,25 @@ void UI_DisplayMenu(void) break; case MENU_STEP: - sprintf(String, "%d.%02ukHz", STEP_FREQ_TABLE[g_sub_menu_selection] / 100, STEP_FREQ_TABLE[g_sub_menu_selection] % 100); + { +// const uint32_t step = (uint32_t)STEP_FREQ_TABLE[g_sub_menu_selection] * 10; + const uint32_t step = (uint32_t)STEP_FREQ_TABLE[step_freq_table_sorted[g_sub_menu_selection]] * 10; + if (step < 1000) + { // Hz + sprintf(String, "%uHz", step); + } + else + { // kHz + int i; + sprintf(String, "%u.%03u", step / 1000, step % 1000); + i = strlen(String) - 1; + while (i > 0 && String[i] == '0' && String[i - 1] != '.') + String[i--] = 0; // trim trailing zeros away + strcat(String, "kHz"); + } break; - + } + case MENU_TX_POWER: strcpy(String, g_sub_MENU_TX_POWER[g_sub_menu_selection]); break;