0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 22:31:25 +03:00

Squelch and backlight adjustments

This commit is contained in:
OneOfEleven 2023-10-16 18:19:28 +01:00
parent d95adde3a6
commit 613fc482cc
14 changed files with 165 additions and 120 deletions

View File

@ -437,6 +437,9 @@ Skip:
static void APP_process_function(void) static void APP_process_function(void)
{ {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough="
switch (g_current_function) switch (g_current_function)
{ {
case FUNCTION_FOREGROUND: case FUNCTION_FOREGROUND:
@ -444,13 +447,16 @@ static void APP_process_function(void)
break; break;
case FUNCTION_TRANSMIT: case FUNCTION_TRANSMIT:
break; if (g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3)
backlight_turn_on(backlight_tx_rx_time_500ms);
case FUNCTION_MONITOR:
break; break;
case FUNCTION_INCOMING: case FUNCTION_INCOMING:
APP_process_incoming_rx(); APP_process_incoming_rx();
case FUNCTION_MONITOR:
if (g_setting_backlight_on_tx_rx >= 2)
backlight_turn_on(backlight_tx_rx_time_500ms);
break; break;
case FUNCTION_RECEIVE: case FUNCTION_RECEIVE:
@ -465,6 +471,8 @@ static void APP_process_function(void)
case FUNCTION_BAND_SCOPE: case FUNCTION_BAND_SCOPE:
break; break;
} }
#pragma GCC diagnostic pop
} }
void APP_start_listening(function_type_t Function, const bool reset_am_fix) 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; g_enable_speaker = true;
if (g_setting_backlight_on_tx_rx >= 2)
backlight_turn_on();
if (g_scan_state_dir != SCAN_STATE_DIR_OFF) if (g_scan_state_dir != SCAN_STATE_DIR_OFF)
{ // we're scanning { // we're scanning
@ -690,7 +695,7 @@ static void APP_next_freq(void)
RADIO_setup_registers(true); RADIO_setup_registers(true);
#ifdef ENABLE_FASTER_CHANNEL_SCAN #ifdef ENABLE_FASTER_CHANNEL_SCAN
g_scan_pause_delay_in_10ms = 9; // 90ms g_scan_pause_delay_in_10ms = 7; // 70ms
#else #else
g_scan_pause_delay_in_10ms = scan_pause_delay_in_6_10ms; g_scan_pause_delay_in_10ms = scan_pause_delay_in_6_10ms;
#endif #endif
@ -701,7 +706,7 @@ static void APP_next_freq(void)
BK4819_set_rf_frequency(frequency, true); BK4819_set_rf_frequency(frequency, true);
#ifdef ENABLE_FASTER_CHANNEL_SCAN #ifdef ENABLE_FASTER_CHANNEL_SCAN
g_scan_pause_delay_in_10ms = 8; // 80ms g_scan_pause_delay_in_10ms = 10; // 100ms
#else #else
g_scan_pause_delay_in_10ms = scan_pause_delay_in_6_10ms; g_scan_pause_delay_in_10ms = scan_pause_delay_in_6_10ms;
#endif #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) 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 { // 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; g_beep_to_play = BEEP_NONE;
return; return;
} }
*/ */
// turn the backlight on // turn the backlight on
if (key_pressed) if (key_pressed)
if (Key != KEY_PTT || g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3) if (Key != KEY_PTT)
backlight_turn_on(); backlight_turn_on(0);
if (g_current_function == FUNCTION_POWER_SAVE) if (g_current_function == FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_FOREGROUND); FUNCTION_Select(FUNCTION_FOREGROUND);

View File

@ -22,13 +22,21 @@
// this is decremented once every 500ms // this is decremented once every 500ms
uint16_t g_backlight_count_down = 0; 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) if (min_ticks > 0)
return; {
if (g_backlight_count_down < min_ticks)
g_backlight_count_down = min_ticks;
// turn the backlight ON // turn the backlight ON
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); 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) switch (g_eeprom.backlight)
{ {
@ -58,3 +66,4 @@ void backlight_turn_on(void)
g_backlight_count_down *= 2; g_backlight_count_down *= 2;
} }
}

View File

@ -21,7 +21,7 @@
extern uint16_t g_backlight_count_down; extern uint16_t g_backlight_count_down;
void backlight_turn_on(void); void backlight_turn_on(const uint16_t min_ticks);
#endif #endif

View File

@ -787,7 +787,9 @@ void BK4819_SetupSquelch(
#else #else
// faster (but twitchier) // faster (but twitchier)
(1u << 14) | // 1 ??? (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 (1u << 9) | // *3 squelch = close delay .. 0 ~ 3
squelch_open_glitch_thresh); // 0 ~ 255 squelch_open_glitch_thresh); // 0 ~ 255
#endif #endif

Binary file not shown.

Binary file not shown.

View File

@ -256,7 +256,7 @@ void FUNCTION_Select(function_type_t Function)
BK4819_DisableScramble(); BK4819_DisableScramble();
if (g_setting_backlight_on_tx_rx == 1 || g_setting_backlight_on_tx_rx == 3) 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; break;

View File

@ -125,7 +125,7 @@ void BATTERY_GetReadings(const bool bDisplayBatteryLevel)
{ {
g_update_status = true; g_update_status = true;
g_update_display = true; g_update_display = true;
backlight_turn_on(); backlight_turn_on(0);
} }
g_charging_with_type_c = true; g_charging_with_type_c = true;

4
main.c
View File

@ -127,7 +127,7 @@ void Main(void)
KEYBOARD_Poll() != KEY_INVALID || KEYBOARD_Poll() != KEY_INVALID ||
BootMode != BOOT_MODE_NORMAL) BootMode != BOOT_MODE_NORMAL)
{ {
backlight_turn_on(); backlight_turn_on(0);
UI_DisplayReleaseKeys(); UI_DisplayReleaseKeys();
i = 0; i = 0;
while (i < (500 / 10)) // 500ms while (i < (500 / 10)) // 500ms
@ -152,7 +152,7 @@ void Main(void)
{ {
UI_DisplayWelcome(); UI_DisplayWelcome();
backlight_turn_on(); backlight_turn_on(0);
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
// AUDIO_SetVoiceID(0, VOICE_ID_WELCOME); // AUDIO_SetVoiceID(0, VOICE_ID_WELCOME);

2
misc.c
View File

@ -34,6 +34,8 @@ const uint16_t fm_restore_countdown_10ms = 5000 / 10; // 5 seco
const uint8_t menu_timeout_500ms = 30000 / 500; // 30 seconds const uint8_t menu_timeout_500ms = 30000 / 500; // 30 seconds
const uint16_t menu_timeout_long_500ms = 120000 / 500; // 2 minutes const uint16_t menu_timeout_long_500ms = 120000 / 500; // 2 minutes
const uint16_t backlight_tx_rx_time_500ms = 10000 / 500; // 10 seconds
const uint8_t dtmf_rx_live_timeout_500ms = 6000 / 500; // 6 seconds live decoder on screen 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_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_decode_ring_countdown_500ms = 15000 / 500; // 15 seconds .. time we sound the ringing for

2
misc.h
View File

@ -119,6 +119,8 @@ extern const uint16_t fm_restore_countdown_10ms;
extern const uint8_t menu_timeout_500ms; extern const uint8_t menu_timeout_500ms;
extern const uint16_t menu_timeout_long_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_live_timeout_500ms;
extern const uint8_t dtmf_rx_timeout_500ms; extern const uint8_t dtmf_rx_timeout_500ms;
extern const uint8_t dtmf_decode_ring_countdown_500ms; extern const uint8_t dtmf_decode_ring_countdown_500ms;

87
radio.c
View File

@ -434,14 +434,17 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *pInfo)
Band = FREQUENCY_GetBand(pInfo->p_rx->frequency); Band = FREQUENCY_GetBand(pInfo->p_rx->frequency);
uint16_t Base = (Band < BAND4_174MHz) ? 0x1E60 : 0x1E00; 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) if (g_eeprom.squelch_level == 0)
{ // squelch == 0 (off) { // squelch == 0 (off)
pInfo->squelch_open_rssi_thresh = 0; // 0 ~ 255 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_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_noise_thresh = 127; // 127 ~ 0
pInfo->squelch_close_glitch_thresh = 255; // 255 ~ 0
pInfo->squelch_open_glitch_thresh = 255; // 255 ~ 0 pInfo->squelch_open_glitch_thresh = 255; // 255 ~ 0
} }
else else
@ -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 + 0x40, &pInfo->squelch_close_glitch_thresh, 1); // 90 90
EEPROM_ReadBuffer(Base + 0x50, &pInfo->squelch_open_glitch_thresh, 1); // 100 100 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; // used in AM mode
uint16_t noise_close = pInfo->squelch_close_noise_thresh; int16_t rssi_open = pInfo->squelch_open_rssi_thresh; // 0 ~ 255
uint16_t glitch_open = pInfo->squelch_open_glitch_thresh; int16_t rssi_close = pInfo->squelch_close_rssi_thresh; // 0 ~ 255
uint16_t glitch_close = pInfo->squelch_close_glitch_thresh;
// 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 #if ENABLE_SQUELCH_MORE_SENSITIVE
// make squelch a little more sensitive // make squelch a little more sensitive
// //
// getting the best setting here is still experimental, bare with me // getting the best general settings here is experimental, bare with me
//
// note that 'noise' and 'glitch' values are inverted compared to 'rssi' values
#if 0 #if 0
rssi_open = (rssi_open * 8) / 9; // rssi_open = (rssi_open * 8) / 9;
noise_open = (noise_open * 9) / 8; noise_open = (noise_open * 9) / 8;
glitch_open = (glitch_open * 9) / 8; glitch_open = (glitch_open * 9) / 8;
#else #else
// even more sensitive .. use when RX bandwidths are fixed (no weak signal auto adjust) // 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; noise_open = (noise_open * 2) / 1;
glitch_open = (glitch_open * 2) / 1; glitch_open = (glitch_open * 2) / 1;
#endif #endif
#else #else
// more sensitive .. use when RX bandwidths are fixed (no weak signal auto adjust) // 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; noise_open = (noise_open * 4) / 3;
glitch_open = (glitch_open * 4) / 3; glitch_open = (glitch_open * 4) / 3;
#endif #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 // ensure the 'close' threshold is lower than the 'open' threshold
if (rssi_close == rssi_open && rssi_close >= 2) // ie, maintain a minimum level of hysteresis
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;
pInfo->squelch_open_rssi_thresh = (rssi_open > 255) ? 255 : rssi_open; // rssi_close = (rssi_open * 4) / 6;
pInfo->squelch_close_rssi_thresh = (rssi_close > 255) ? 255 : rssi_close; noise_close = (noise_open * 6) / 4;
pInfo->squelch_open_noise_thresh = (noise_open > 127) ? 127 : noise_open; glitch_close = (glitch_open * 6) / 4;
pInfo->squelch_close_noise_thresh = (noise_close > 127) ? 127 : noise_close;
pInfo->squelch_open_glitch_thresh = (glitch_open > 255) ? 255 : glitch_open; // if (rssi_open < 8)
pInfo->squelch_close_glitch_thresh = (glitch_close > 255) ? 255 : glitch_close; // 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;
} }
// ******************************* // *******************************

View File

@ -36,7 +36,7 @@ void UI_DisplayFM(void)
if (g_eeprom.key_lock && g_keypad_locked > 0) if (g_eeprom.key_lock && g_keypad_locked > 0)
{ // tell user how to unlock the keyboard { // 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("Long press #", 0, LCD_WIDTH, 1, 8);
UI_PrintString("to unlock", 0, LCD_WIDTH, 3, 8); UI_PrintString("to unlock", 0, LCD_WIDTH, 3, 8);
ST7565_BlitFullScreen(); ST7565_BlitFullScreen();

View File

@ -399,7 +399,7 @@ void UI_DisplayMain(void)
if (g_serial_config_count_down_500ms > 0) 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("UART", 0, LCD_WIDTH, 1, 8);
UI_PrintString("CONFIG COMMS", 0, LCD_WIDTH, 3, 8); UI_PrintString("CONFIG COMMS", 0, LCD_WIDTH, 3, 8);
ST7565_BlitFullScreen(); ST7565_BlitFullScreen();
@ -408,7 +408,7 @@ void UI_DisplayMain(void)
if (g_eeprom.key_lock && g_keypad_locked > 0) if (g_eeprom.key_lock && g_keypad_locked > 0)
{ // tell user how to unlock the keyboard { // 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("Long press #", 0, LCD_WIDTH, 1, 8);
UI_PrintString("to unlock", 0, LCD_WIDTH, 3, 8); UI_PrintString("to unlock", 0, LCD_WIDTH, 3, 8);
ST7565_BlitFullScreen(); ST7565_BlitFullScreen();