diff --git a/app/app.c b/app/app.c index 1907ee5..aceeec5 100644 --- a/app/app.c +++ b/app/app.c @@ -437,6 +437,9 @@ Skip: static void APP_process_function(void) { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wimplicit-fallthrough=" + switch (g_current_function) { case FUNCTION_FOREGROUND: @@ -444,13 +447,16 @@ static void APP_process_function(void) break; case FUNCTION_TRANSMIT: - break; - - case FUNCTION_MONITOR: + if (g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3) + backlight_turn_on(backlight_tx_rx_time_500ms); break; case FUNCTION_INCOMING: APP_process_incoming_rx(); + + case FUNCTION_MONITOR: + if (g_setting_backlight_on_tx_rx >= 2) + backlight_turn_on(backlight_tx_rx_time_500ms); break; case FUNCTION_RECEIVE: @@ -465,6 +471,8 @@ static void APP_process_function(void) case FUNCTION_BAND_SCOPE: break; } + + #pragma GCC diagnostic pop } void APP_start_listening(function_type_t Function, const bool reset_am_fix) @@ -487,9 +495,6 @@ void APP_start_listening(function_type_t Function, const bool reset_am_fix) g_enable_speaker = true; - if (g_setting_backlight_on_tx_rx >= 2) - backlight_turn_on(); - if (g_scan_state_dir != SCAN_STATE_DIR_OFF) { // we're scanning @@ -690,7 +695,7 @@ static void APP_next_freq(void) RADIO_setup_registers(true); #ifdef ENABLE_FASTER_CHANNEL_SCAN - g_scan_pause_delay_in_10ms = 9; // 90ms + g_scan_pause_delay_in_10ms = 7; // 70ms #else g_scan_pause_delay_in_10ms = scan_pause_delay_in_6_10ms; #endif @@ -701,7 +706,7 @@ static void APP_next_freq(void) BK4819_set_rf_frequency(frequency, true); #ifdef ENABLE_FASTER_CHANNEL_SCAN - g_scan_pause_delay_in_10ms = 8; // 80ms + g_scan_pause_delay_in_10ms = 10; // 100ms #else g_scan_pause_delay_in_10ms = scan_pause_delay_in_6_10ms; #endif @@ -2401,15 +2406,15 @@ static void APP_process_key(const key_code_t Key, const bool key_pressed, const if (Key == KEY_EXIT && !backlight_was_on && g_eeprom.backlight > 0) { // just turn the light on for now so the user can see what's what - backlight_turn_on(); + backlight_turn_on(0); g_beep_to_play = BEEP_NONE; return; } */ // turn the backlight on if (key_pressed) - if (Key != KEY_PTT || g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3) - backlight_turn_on(); + if (Key != KEY_PTT) + backlight_turn_on(0); if (g_current_function == FUNCTION_POWER_SAVE) FUNCTION_Select(FUNCTION_FOREGROUND); diff --git a/driver/backlight.c b/driver/backlight.c index aa77597..ae36d43 100644 --- a/driver/backlight.c +++ b/driver/backlight.c @@ -22,39 +22,48 @@ // this is decremented once every 500ms uint16_t g_backlight_count_down = 0; -void backlight_turn_on(void) +void backlight_turn_on(const uint16_t min_ticks) { - if (g_eeprom.backlight == 0) - return; - - // turn the backlight ON - GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); - - switch (g_eeprom.backlight) + if (min_ticks > 0) { - default: - case 1: // 5 sec - g_backlight_count_down = 5; - break; - case 2: // 10 sec - g_backlight_count_down = 10; - break; - case 3: // 20 sec - g_backlight_count_down = 20; - break; - case 4: // 1 min - g_backlight_count_down = 60; - break; - case 5: // 2 min - g_backlight_count_down = 60 * 2; - break; - case 6: // 4 min - g_backlight_count_down = 60 * 4; - break; - case 7: // always on - g_backlight_count_down = 0; - break; - } + if (g_backlight_count_down < min_ticks) + g_backlight_count_down = min_ticks; - g_backlight_count_down *= 2; + // turn the backlight ON + GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); + } + else + if (g_eeprom.backlight > 0) + { + // turn the backlight ON + GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); + + switch (g_eeprom.backlight) + { + default: + case 1: // 5 sec + g_backlight_count_down = 5; + break; + case 2: // 10 sec + g_backlight_count_down = 10; + break; + case 3: // 20 sec + g_backlight_count_down = 20; + break; + case 4: // 1 min + g_backlight_count_down = 60; + break; + case 5: // 2 min + g_backlight_count_down = 60 * 2; + break; + case 6: // 4 min + g_backlight_count_down = 60 * 4; + break; + case 7: // always on + g_backlight_count_down = 0; + break; + } + + g_backlight_count_down *= 2; + } } diff --git a/driver/backlight.h b/driver/backlight.h index da1b02c..7649bbd 100644 --- a/driver/backlight.h +++ b/driver/backlight.h @@ -21,7 +21,7 @@ extern uint16_t g_backlight_count_down; -void backlight_turn_on(void); +void backlight_turn_on(const uint16_t min_ticks); #endif diff --git a/driver/bk4819.c b/driver/bk4819.c index adc986f..4372efc 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -787,7 +787,9 @@ void BK4819_SetupSquelch( #else // faster (but twitchier) (1u << 14) | // 1 ??? - (2u << 11) | // *5 squelch = open delay .. 0 ~ 7 +// (2u << 11) | // *5 squelch = open delay .. 0 ~ 7 +// (1u << 9) | // *3 squelch = close delay .. 0 ~ 3 + (1u << 11) | // *5 squelch = open delay .. 0 ~ 7 (1u << 9) | // *3 squelch = close delay .. 0 ~ 3 squelch_open_glitch_thresh); // 0 ~ 255 #endif diff --git a/firmware.bin b/firmware.bin index 9366d7f..6d24f12 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index a489e37..cda9cd9 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/functions.c b/functions.c index 94d0498..75a8ede 100644 --- a/functions.c +++ b/functions.c @@ -256,7 +256,7 @@ void FUNCTION_Select(function_type_t Function) BK4819_DisableScramble(); if (g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3) - backlight_turn_on(); + backlight_turn_on(backlight_tx_rx_time_500ms); break; diff --git a/helper/battery.c b/helper/battery.c index 9cfb054..cb35210 100644 --- a/helper/battery.c +++ b/helper/battery.c @@ -125,7 +125,7 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel) { g_update_status = true; g_update_display = true; - backlight_turn_on(); + backlight_turn_on(0); } g_charging_with_type_c = true; diff --git a/main.c b/main.c index da60626..3e3ba76 100644 --- a/main.c +++ b/main.c @@ -127,7 +127,7 @@ void Main(void) KEYBOARD_Poll() != KEY_INVALID || BootMode != BOOT_MODE_NORMAL) { - backlight_turn_on(); + backlight_turn_on(0); UI_DisplayReleaseKeys(); i = 0; while (i < (500 / 10)) // 500ms @@ -152,7 +152,7 @@ void Main(void) { UI_DisplayWelcome(); - backlight_turn_on(); + backlight_turn_on(0); #ifdef ENABLE_VOICE // AUDIO_SetVoiceID(0, VOICE_ID_WELCOME); diff --git a/misc.c b/misc.c index 3fc55d3..59c318c 100644 --- a/misc.c +++ b/misc.c @@ -25,57 +25,59 @@ const uint8_t obfuscate_array[16] = { // *********************************************** -const uint8_t fm_resume_countdown_500ms = 2500 / 500; // 2.5 seconds -const uint8_t fm_radio_countdown_500ms = 2000 / 500; // 2 seconds -const uint16_t fm_play_countdown_scan_10ms = 100 / 10; // 100ms -const uint16_t fm_play_countdown_noscan_10ms = 1200 / 10; // 1.2 seconds -const uint16_t fm_restore_countdown_10ms = 5000 / 10; // 5 seconds +const uint8_t fm_resume_countdown_500ms = 2500 / 500; // 2.5 seconds +const uint8_t fm_radio_countdown_500ms = 2000 / 500; // 2 seconds +const uint16_t fm_play_countdown_scan_10ms = 100 / 10; // 100ms +const uint16_t fm_play_countdown_noscan_10ms = 1200 / 10; // 1.2 seconds +const uint16_t fm_restore_countdown_10ms = 5000 / 10; // 5 seconds const uint8_t menu_timeout_500ms = 30000 / 500; // 30 seconds const uint16_t menu_timeout_long_500ms = 120000 / 500; // 2 minutes -const uint8_t dtmf_rx_live_timeout_500ms = 6000 / 500; // 6 seconds live decoder on screen -const uint8_t dtmf_rx_timeout_500ms = 10000 / 500; // 10 seconds till we wipe the DTMF receiver -const uint8_t dtmf_decode_ring_countdown_500ms = 15000 / 500; // 15 seconds .. time we sound the ringing for -const uint8_t dtmf_txstop_countdown_500ms = 3000 / 500; // 6 seconds +const uint16_t backlight_tx_rx_time_500ms = 10000 / 500; // 10 seconds -const uint8_t serial_config_count_down_500ms = 3000 / 500; // 3 seconds +const uint8_t dtmf_rx_live_timeout_500ms = 6000 / 500; // 6 seconds live decoder on screen +const uint8_t dtmf_rx_timeout_500ms = 10000 / 500; // 10 seconds till we wipe the DTMF receiver +const uint8_t dtmf_decode_ring_countdown_500ms = 15000 / 500; // 15 seconds .. time we sound the ringing for +const uint8_t dtmf_txstop_countdown_500ms = 3000 / 500; // 6 seconds -const uint8_t key_input_timeout_500ms = 6000 / 500; // 6 seconds -const uint8_t key_lock_timeout_500ms = 30000 / 500; // 30 seconds +const uint8_t serial_config_count_down_500ms = 3000 / 500; // 3 seconds -const uint8_t key_debounce_10ms = 30 / 10; // 30ms -const uint8_t key_long_press_10ms = 300 / 10; // 300ms -const uint8_t key_repeat_10ms = 50 / 10; // 50ms +const uint8_t key_input_timeout_500ms = 6000 / 500; // 6 seconds +const uint8_t key_lock_timeout_500ms = 30000 / 500; // 30 seconds -const uint16_t scan_freq_css_timeout_10ms = 10000 / 10; // 10 seconds -const uint8_t scan_freq_css_delay_10ms = 210 / 10; // 210ms .. don't reduce this +const uint8_t key_debounce_10ms = 30 / 10; // 30ms +const uint8_t key_long_press_10ms = 300 / 10; // 300ms +const uint8_t key_repeat_10ms = 50 / 10; // 50ms -const uint16_t dual_watch_count_after_tx_10ms = 3600 / 10; // 3.6 sec after TX ends -const uint16_t dual_watch_count_after_rx_10ms = 1000 / 10; // 1 sec after RX ends ? -const uint16_t dual_watch_count_after_1_10ms = 5000 / 10; // 5 sec -const uint16_t dual_watch_count_after_2_10ms = 3600 / 10; // 3.6 sec -const uint16_t dual_watch_count_noaa_10ms = 70 / 10; // 70ms +const uint16_t scan_freq_css_timeout_10ms = 10000 / 10; // 10 seconds +const uint8_t scan_freq_css_delay_10ms = 210 / 10; // 210ms .. don't reduce this + +const uint16_t dual_watch_count_after_tx_10ms = 3600 / 10; // 3.6 sec after TX ends +const uint16_t dual_watch_count_after_rx_10ms = 1000 / 10; // 1 sec after RX ends ? +const uint16_t dual_watch_count_after_1_10ms = 5000 / 10; // 5 sec +const uint16_t dual_watch_count_after_2_10ms = 3600 / 10; // 3.6 sec +const uint16_t dual_watch_count_noaa_10ms = 70 / 10; // 70ms #ifdef ENABLE_VOX - const uint16_t dual_watch_count_after_vox_10ms = 200 / 10; // 200ms + const uint16_t dual_watch_count_after_vox_10ms = 200 / 10; // 200ms #endif -const uint16_t dual_watch_count_toggle_10ms = 100 / 10; // 100ms between VFO toggles +const uint16_t dual_watch_count_toggle_10ms = 100 / 10; // 100ms between VFO toggles -const uint16_t scan_pause_delay_in_1_10ms = 5000 / 10; // 5 seconds -const uint16_t scan_pause_delay_in_2_10ms = 500 / 10; // 500ms -const uint16_t scan_pause_delay_in_3_10ms = 200 / 10; // 200ms -const uint16_t scan_pause_delay_in_4_10ms = 300 / 10; // 300ms -const uint16_t scan_pause_delay_in_5_10ms = 1000 / 10; // 1 sec -const uint16_t scan_pause_delay_in_6_10ms = 100 / 10; // 100ms -const uint16_t scan_pause_delay_in_7_10ms = 3600 / 10; // 3.6 seconds +const uint16_t scan_pause_delay_in_1_10ms = 5000 / 10; // 5 seconds +const uint16_t scan_pause_delay_in_2_10ms = 500 / 10; // 500ms +const uint16_t scan_pause_delay_in_3_10ms = 200 / 10; // 200ms +const uint16_t scan_pause_delay_in_4_10ms = 300 / 10; // 300ms +const uint16_t scan_pause_delay_in_5_10ms = 1000 / 10; // 1 sec +const uint16_t scan_pause_delay_in_6_10ms = 100 / 10; // 100ms +const uint16_t scan_pause_delay_in_7_10ms = 3600 / 10; // 3.6 seconds -const uint16_t battery_save_count_10ms = 10000 / 10; // 10 seconds +const uint16_t battery_save_count_10ms = 10000 / 10; // 10 seconds -const uint16_t power_save1_10ms = 100 / 10; // 100ms -const uint16_t power_save2_10ms = 200 / 10; // 200ms +const uint16_t power_save1_10ms = 100 / 10; // 100ms +const uint16_t power_save2_10ms = 200 / 10; // 200ms #ifdef ENABLE_VOX - const uint16_t vox_stop_count_down_10ms = 1000 / 10; // 1 second + const uint16_t vox_stop_count_down_10ms = 1000 / 10; // 1 second #endif const uint16_t noaa_count_down_10ms = 5000 / 10; // 5 seconds diff --git a/misc.h b/misc.h index 5084218..ecbd6e9 100644 --- a/misc.h +++ b/misc.h @@ -119,6 +119,8 @@ extern const uint16_t fm_restore_countdown_10ms; extern const uint8_t menu_timeout_500ms; extern const uint16_t menu_timeout_long_500ms; +extern const uint16_t backlight_tx_rx_time_500ms; + extern const uint8_t dtmf_rx_live_timeout_500ms; extern const uint8_t dtmf_rx_timeout_500ms; extern const uint8_t dtmf_decode_ring_countdown_500ms; diff --git a/radio.c b/radio.c index 280d410..6777e46 100644 --- a/radio.c +++ b/radio.c @@ -434,20 +434,23 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *pInfo) Band = FREQUENCY_GetBand(pInfo->p_rx->frequency); uint16_t Base = (Band < BAND4_174MHz) ? 0x1E60 : 0x1E00; + // note that 'noise' and 'glitch' values are inverted compared to 'rssi' values + if (g_eeprom.squelch_level == 0) { // squelch == 0 (off) pInfo->squelch_open_rssi_thresh = 0; // 0 ~ 255 - pInfo->squelch_open_noise_thresh = 127; // 127 ~ 0 - pInfo->squelch_close_glitch_thresh = 255; // 255 ~ 0 - pInfo->squelch_close_rssi_thresh = 0; // 0 ~ 255 + + pInfo->squelch_open_noise_thresh = 127; // 127 ~ 0 pInfo->squelch_close_noise_thresh = 127; // 127 ~ 0 + + pInfo->squelch_close_glitch_thresh = 255; // 255 ~ 0 pInfo->squelch_open_glitch_thresh = 255; // 255 ~ 0 } else { // squelch >= 1 - Base += g_eeprom.squelch_level; // my eeprom squelch-1 - // VHF UHF + Base += g_eeprom.squelch_level; // my eeprom squelch-1 + // VHF UHF EEPROM_ReadBuffer(Base + 0x00, &pInfo->squelch_open_rssi_thresh, 1); // 50 10 EEPROM_ReadBuffer(Base + 0x10, &pInfo->squelch_close_rssi_thresh, 1); // 40 5 @@ -457,56 +460,78 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *pInfo) EEPROM_ReadBuffer(Base + 0x40, &pInfo->squelch_close_glitch_thresh, 1); // 90 90 EEPROM_ReadBuffer(Base + 0x50, &pInfo->squelch_open_glitch_thresh, 1); // 100 100 - uint16_t rssi_open = pInfo->squelch_open_rssi_thresh; - uint16_t rssi_close = pInfo->squelch_close_rssi_thresh; - uint16_t noise_open = pInfo->squelch_open_noise_thresh; - uint16_t noise_close = pInfo->squelch_close_noise_thresh; - uint16_t glitch_open = pInfo->squelch_open_glitch_thresh; - uint16_t glitch_close = pInfo->squelch_close_glitch_thresh; + // ********* + + // used in AM mode + int16_t rssi_open = pInfo->squelch_open_rssi_thresh; // 0 ~ 255 + int16_t rssi_close = pInfo->squelch_close_rssi_thresh; // 0 ~ 255 + + // used in FM mode + int16_t noise_open = pInfo->squelch_open_noise_thresh; // 127 ~ 0 + int16_t noise_close = pInfo->squelch_close_noise_thresh; // 127 ~ 0 + + // used in both modes ? + int16_t glitch_open = pInfo->squelch_open_glitch_thresh; // 255 ~ 0 + int16_t glitch_close = pInfo->squelch_close_glitch_thresh; // 255 ~ 0 + + // ********* #if ENABLE_SQUELCH_MORE_SENSITIVE // make squelch a little more sensitive // - // getting the best setting here is still experimental, bare with me - // - // note that 'noise' and 'glitch' values are inverted compared to 'rssi' values + // getting the best general settings here is experimental, bare with me #if 0 - rssi_open = (rssi_open * 8) / 9; +// rssi_open = (rssi_open * 8) / 9; noise_open = (noise_open * 9) / 8; glitch_open = (glitch_open * 9) / 8; #else // even more sensitive .. use when RX bandwidths are fixed (no weak signal auto adjust) - rssi_open = (rssi_open * 1) / 2; +// rssi_open = (rssi_open * 1) / 2; noise_open = (noise_open * 2) / 1; glitch_open = (glitch_open * 2) / 1; #endif #else // more sensitive .. use when RX bandwidths are fixed (no weak signal auto adjust) - rssi_open = (rssi_open * 3) / 4; +// rssi_open = (rssi_open * 3) / 4; noise_open = (noise_open * 4) / 3; glitch_open = (glitch_open * 4) / 3; #endif - rssi_close = (rssi_open * 9) / 10; - noise_close = (noise_open * 10) / 9; - glitch_close = (glitch_open * 10) / 9; - + // ********* // ensure the 'close' threshold is lower than the 'open' threshold - if (rssi_close == rssi_open && rssi_close >= 2) - rssi_close -= 2; - if (noise_close == noise_open && noise_close <= 125) - noise_close += 2; - if (glitch_close == glitch_open && glitch_close <= 253) - glitch_close += 2; + // ie, maintain a minimum level of hysteresis - pInfo->squelch_open_rssi_thresh = (rssi_open > 255) ? 255 : rssi_open; - pInfo->squelch_close_rssi_thresh = (rssi_close > 255) ? 255 : rssi_close; - pInfo->squelch_open_noise_thresh = (noise_open > 127) ? 127 : noise_open; - pInfo->squelch_close_noise_thresh = (noise_close > 127) ? 127 : noise_close; - pInfo->squelch_open_glitch_thresh = (glitch_open > 255) ? 255 : glitch_open; - pInfo->squelch_close_glitch_thresh = (glitch_close > 255) ? 255 : glitch_close; +// rssi_close = (rssi_open * 4) / 6; + noise_close = (noise_open * 6) / 4; + glitch_close = (glitch_open * 6) / 4; + +// if (rssi_open < 8) +// rssi_open = 8; +// if (rssi_close > (rssi_open - 8)) +// rssi_close = rssi_open - 8; + + if (noise_open > (127 - 4)) + noise_open = 127 - 4; + if (noise_close < (noise_open + 4)) + noise_close = noise_open + 4; + + if (glitch_open > (255 - 8)) + glitch_open = 255 - 8; + if (glitch_close < (glitch_open + 8)) + glitch_close = glitch_open + 8; + + // ********* + + pInfo->squelch_open_rssi_thresh = (rssi_open > 255) ? 255 : (rssi_open < 0) ? 0 : rssi_open; + pInfo->squelch_close_rssi_thresh = (rssi_close > 255) ? 255 : (rssi_close < 0) ? 0 : rssi_close; + + pInfo->squelch_open_noise_thresh = (noise_open > 127) ? 127 : (noise_open < 0) ? 0 : noise_open; + pInfo->squelch_close_noise_thresh = (noise_close > 127) ? 127 : (noise_close < 0) ? 0 : noise_close; + + pInfo->squelch_open_glitch_thresh = (glitch_open > 255) ? 255 : (glitch_open < 0) ? 0 : glitch_open; + pInfo->squelch_close_glitch_thresh = (glitch_close > 255) ? 255 : (glitch_close < 0) ? 0 : glitch_close; } // ******************************* diff --git a/ui/fmradio.c b/ui/fmradio.c index fad2203..6dfee76 100644 --- a/ui/fmradio.c +++ b/ui/fmradio.c @@ -36,7 +36,7 @@ void UI_DisplayFM(void) if (g_eeprom.key_lock && g_keypad_locked > 0) { // tell user how to unlock the keyboard - backlight_turn_on(); + backlight_turn_on(0); UI_PrintString("Long press #", 0, LCD_WIDTH, 1, 8); UI_PrintString("to unlock", 0, LCD_WIDTH, 3, 8); ST7565_BlitFullScreen(); diff --git a/ui/main.c b/ui/main.c index b13cabd..d5d982f 100644 --- a/ui/main.c +++ b/ui/main.c @@ -399,7 +399,7 @@ void UI_DisplayMain(void) if (g_serial_config_count_down_500ms > 0) { - backlight_turn_on(); + backlight_turn_on(10); // 5 seconds UI_PrintString("UART", 0, LCD_WIDTH, 1, 8); UI_PrintString("CONFIG COMMS", 0, LCD_WIDTH, 3, 8); ST7565_BlitFullScreen(); @@ -408,7 +408,7 @@ void UI_DisplayMain(void) if (g_eeprom.key_lock && g_keypad_locked > 0) { // tell user how to unlock the keyboard - backlight_turn_on(); + backlight_turn_on(10); // 5 seconds UI_PrintString("Long press #", 0, LCD_WIDTH, 1, 8); UI_PrintString("to unlock", 0, LCD_WIDTH, 3, 8); ST7565_BlitFullScreen();