Skip to content

Commit

Permalink
Bug fixes if FM radio enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfEleven committed Sep 25, 2023
1 parent ed32177 commit bcfe977
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 54 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@

# compile options (see Readme.md)
# '0' = disable
# '1' = enable
# compile options (see README.md for descriptions)
# 0 = disable
# 1 = enable
#
ENABLE_SWD := 0
ENABLE_OVERLAY := 1
ENABLE_UART := 1
ENABLE_AIRCOPY := 0
ENABLE_FMRADIO := 0
ENABLE_FMRADIO := 1
ENABLE_NOAA := 0
ENABLE_VOICE := 0
ENABLE_ALARM := 0
Expand Down Expand Up @@ -137,7 +137,10 @@ OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size

# the user might not have/want git installed
# can set own version string here (max 7 chars here)
GIT_HASH := $(shell git rev-parse --short HEAD)
#GIT_HASH := 230925b

$(info GIT_HASH = $(GIT_HASH))

ASFLAGS = -c -mcpu=cortex-m0
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@ ENABLE_SWD := 0 only needed if using CPU's SWD port (de
ENABLE_OVERLAY := 1 cpu FLASH stuff
ENABLE_UART := 1 without this you can't configure radio via PC
ENABLE_AIRCOPY := 0 easier to just enter frequency
ENABLE_FMRADIO := 0 WBFM VHF band 2 RX
ENABLE_NOAA := 0 Everything NOAA
ENABLE_FMRADIO := 1 WBFM VHF band 2 RX
ENABLE_NOAA := 0 everything NOAA
ENABLE_VOICE := 0 want to hear voices ?
ENABLE_ALARM := 0 TX alarms
ENABLE_BIG_FREQ := 0 big font frequencies
ENABLE_SMALL_BOLD := 1 bold channel name/no. (name + freq channel display mode)
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 frontend not tuned over full range)
ENABLE_TX_WHEN_AM := 0 allow TX (always FM) when RX is set to AM
ENABLE_CTCSS_TAIL_PHASE_SHIFT := 1 standard CTCSS tail phase shift rather than QS's own 55Hz tone method
ENABLE_MAIN_KEY_HOLD := 1 initial F-key press not needed, instead hold down keys 0-9 to access the functions
ENABLE_BOOT_BEEPS := 0 give user audio feedback on volume knob position at boot-up
ENABLE_COMPANDER := 1 compander option (per channel)
ENABLE_SHOW_CHARGE_LEVEL := 1 show the charge level when the radio is on charge
ENABLE_SHOW_CHARGE_LEVEL := 0 show the charge level when the radio is on charge
ENABLE_REVERSE_BAT_SYMBOL := 1 mirror the battery symbol on the status bar (+ pole on the right)
ENABLE_NO_SCAN_TIMEOUT := 1 remove the 32 sec timeout from the CTCSS/DCS scan (press exit butt to end scan)
ENABLE_AM_FIX := 1 dynamically adjust the front end gains when in AM mode to helo prevent AM demodulator saturation - ignore the on-screen RSSI (for now)
ENABLE_AM_FIX_SHOW_DATA := 1 show debug data for the AM fix
ENABLE_SQUELCH1_LOWER := 1 adjusts squelch setting '1' to be more sensitive - I plan to let user adjust it in the menu
ENABLE_SQUELCH1_LOWER := 0 adjusts squelch setting '1' to be more sensitive - I plan to let user adjust it in the menu
ENABLE_AUDIO_BAR := 0 experimental, display an audo bar level when TX'ing
#ENABLE_SINGLE_VFO_CHAN := 1 not yet implemented - single VFO on display when possible
#ENABLE_BAND_SCOPE := 1 not yet implemented - spectrum/pan-adapter
Expand All @@ -45,7 +46,7 @@ ENABLE_AUDIO_BAR := 0 experimental, display an audo bar level
* Added new bugs
* Mic menu includes max gain possible
* AM RX everywhere (left the TX as is)
* An attempt to improve the AM RX audio (demodulator getting saturated/overloaded)
* An attempt to improve the AM RX audio (demodulator getting saturated/overloaded in Quansheng firmware)
* keypad-5/NOAA button now toggles scanlist-1 on/off for current channel when held down - IF NOAA not used
* Better backlight times (inc always on)
* Live DTMF decoder option, though the decoder needs some coeff tuning changes to decode other radios it seems
Expand Down
2 changes: 1 addition & 1 deletion am_fix.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ const uint8_t orig_pga = 6; // -3dB
return;

case FUNCTION_FOREGROUND:
return;
// return;

// only adjust stuff if we're in one of these modes
case FUNCTION_RECEIVE:
Expand Down
3 changes: 2 additions & 1 deletion app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static void ACTION_Monitor(void)
#ifdef ENABLE_NOAA
if (gEeprom.DUAL_WATCH == DUAL_WATCH_OFF && gIsNoaaMode)
{
gNOAA_Countdown_10ms = 500; // 5 sec
gNOAA_Countdown_10ms = NOAA_countdown_10ms;
gScheduleNOAA = false;
}
#endif
Expand Down Expand Up @@ -155,6 +155,7 @@ void ACTION_Scan(bool bRestart)
#endif
}
}

return;
}
#endif
Expand Down
28 changes: 15 additions & 13 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static void APP_CheckForIncoming(void)
#ifdef ENABLE_NOAA
if (gIsNoaaMode)
{
gNOAA_Countdown_10ms = 20; // 200ms
gNOAA_Countdown_10ms = NOAA_countdown_3_10ms;
gScheduleNOAA = false;
}
#endif
Expand Down Expand Up @@ -965,7 +965,8 @@ void APP_Update(void)
APP_HandleFunction();

#ifdef ENABLE_FMRADIO
if (gFmRadioCountdown_500ms > 0)
// if (gFmRadioCountdown_500ms > 0)
if (gFmRadioMode && gFmRadioCountdown_500ms > 0) // 1of11
return;
#endif

Expand Down Expand Up @@ -1058,7 +1059,7 @@ void APP_Update(void)
gCurrentFunction != FUNCTION_MONITOR &&
gCurrentFunction != FUNCTION_RECEIVE &&
gCurrentFunction != FUNCTION_TRANSMIT)
{
{ // switch to FM radio mode
FM_Play();
gScheduleFM = false;
}
Expand Down Expand Up @@ -1091,7 +1092,7 @@ void APP_Update(void)
}
else
{
gBatterySaveCountdown_10ms = battery_save_count_10ms;
gBatterySaveCountdown_10ms = battery_save_count_10ms;
}
#else
if (
Expand All @@ -1106,7 +1107,7 @@ void APP_Update(void)
gScreenToDisplay != DISPLAY_MAIN ||
gDTMF_CallState != DTMF_CALL_STATE_NONE)
{
gBatterySaveCountdown_10ms = battery_save_count_10ms;
gBatterySaveCountdown_10ms = battery_save_count_10ms;
}
else
{
Expand Down Expand Up @@ -1362,9 +1363,8 @@ void APP_TimeSlice10ms(void)
else
{ // transmitting
#ifdef ENABLE_AUDIO_BAR
if (gSetting_mic_bar && (gFlashLightBlinkCounter % (100 / 10)) == 0) // once every 100ms
if (gSetting_mic_bar && (gFlashLightBlinkCounter % (150 / 10)) == 0) // once every 150ms
UI_DisplayAudioBar();
//gUpdateDisplay = true;
#endif

if (gUpdateDisplay)
Expand All @@ -1380,7 +1380,8 @@ void APP_TimeSlice10ms(void)
// Skipping authentic device checks

#ifdef ENABLE_FMRADIO
if (gFmRadioCountdown_500ms > 0)
// if (gFmRadioCountdown_500ms > 0)
if (gFmRadioMode && gFmRadioCountdown_500ms > 0) // 1of11
return;
#endif

Expand Down Expand Up @@ -1454,10 +1455,10 @@ void APP_TimeSlice10ms(void)
}

#ifdef ENABLE_FMRADIO
if (gFmRadioMode && gFM_RestoreCountdown > 0)
if (gFmRadioMode && gFM_RestoreCountdown_10ms > 0)
{
if (--gFM_RestoreCountdown == 0)
{
if (--gFM_RestoreCountdown_10ms == 0)
{ // switch back to FM radio mode
FM_Start();
GUI_SelectNextDisplay(DISPLAY_FM);
}
Expand Down Expand Up @@ -1630,7 +1631,8 @@ void APP_TimeSlice500ms(void)
if (gFmRadioCountdown_500ms > 0)
{
gFmRadioCountdown_500ms--;
return;
if (gFmRadioMode) // 1of11
return;
}
#endif

Expand Down Expand Up @@ -1743,7 +1745,7 @@ void APP_TimeSlice500ms(void)
{
RADIO_SetVfoState(VFO_STATE_NORMAL);
if (gCurrentFunction != FUNCTION_RECEIVE && gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_MONITOR && gFmRadioMode)
{
{ // switch back to FM radio mode
FM_Start();
GUI_SelectNextDisplay(DISPLAY_FM);
}
Expand Down
14 changes: 7 additions & 7 deletions app/fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ uint8_t gFM_ChannelPosition;
bool gFM_FoundFrequency;
bool gFM_AutoScan;
uint8_t gFM_ResumeCountdown_500ms;
uint16_t gFM_RestoreCountdown;
uint16_t gFM_RestoreCountdown_10ms;

bool FM_CheckValidChannel(uint8_t Channel)
{
Expand Down Expand Up @@ -93,9 +93,9 @@ int FM_ConfigureChannelState(void)

void FM_TurnOff(void)
{
gFmRadioMode = false;
gFM_ScanState = FM_SCAN_OFF;
gFM_RestoreCountdown = 0;
gFmRadioMode = false;
gFM_ScanState = FM_SCAN_OFF;
gFM_RestoreCountdown_10ms = 0;

GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);

Expand Down Expand Up @@ -655,9 +655,9 @@ void FM_Play(void)

void FM_Start(void)
{
gFmRadioMode = true;
gFM_ScanState = FM_SCAN_OFF;
gFM_RestoreCountdown = 0;
gFmRadioMode = true;
gFM_ScanState = FM_SCAN_OFF;
gFM_RestoreCountdown_10ms = 0;

BK1080_Init(gEeprom.FM_FrequencyPlaying, true);

Expand Down
2 changes: 1 addition & 1 deletion app/fm.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern uint16_t gFM_FrequencyDeviation;
extern bool gFM_FoundFrequency;
extern bool gFM_AutoScan;
extern uint8_t gFM_ResumeCountdown_500ms;
extern uint16_t gFM_RestoreCountdown;
extern uint16_t gFM_RestoreCountdown_10ms;

bool FM_CheckValidChannel(uint8_t Channel);
uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction);
Expand Down
6 changes: 6 additions & 0 deletions app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
case KEY_0:
#ifdef ENABLE_FMRADIO
ACTION_FM();
#else


// TODO: do something useful with the key


#endif
break;

Expand Down
Binary file modified firmware.bin
Binary file not shown.
Binary file modified firmware.packed.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function)

#if defined(ENABLE_FMRADIO)
if (gFmRadioMode)
gFM_RestoreCountdown = 500;
gFM_RestoreCountdown_10ms = fm_restore_countdown_10ms;
#endif

if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT || gDTMF_CallState == DTMF_CALL_STATE_RECEIVED)
Expand Down Expand Up @@ -201,6 +201,6 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
gSchedulePowerSave = false;

#if defined(ENABLE_FMRADIO)
gFM_RestoreCountdown = 0;
gFM_RestoreCountdown_10ms = 0;
#endif
}
6 changes: 5 additions & 1 deletion misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const uint8_t fm_resume_countdown_500ms = 2500 / 500; // 2.5 second
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 = 20000 / 500; // 20 seconds

Expand All @@ -38,7 +39,6 @@ const uint16_t key_debounce_10ms = 20 / 10; // 20ms

const uint8_t scan_delay_10ms = 210 / 10; // 210ms

// 10ms count down resolution
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
Expand All @@ -52,6 +52,10 @@ 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 NOAA_countdown_10ms = 5000 / 10; // 5 seconds
const uint16_t NOAA_countdown_2_10ms = 500 / 10; // 500ms
const uint16_t NOAA_countdown_3_10ms = 200 / 10; // 200ms

const uint16_t gMax_bat_v = 840; // 8.4V
const uint16_t gMin_bat_v = 660; // 6.6V

Expand Down
5 changes: 5 additions & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern const uint8_t fm_resume_countdown_500ms;
extern const uint8_t fm_radio_countdown_500ms;
extern const uint16_t fm_play_countdown_scan_10ms;
extern const uint16_t fm_play_countdown_noscan_10ms;
extern const uint16_t fm_restore_countdown_10ms;

extern const uint8_t menu_timeout_500ms;

Expand All @@ -108,6 +109,10 @@ extern const uint16_t battery_save_count_10ms;
extern const uint16_t power_save1_10ms;
extern const uint16_t power_save2_10ms;

extern const uint16_t NOAA_countdown_10ms;
extern const uint16_t NOAA_countdown_2_10ms;
extern const uint16_t NOAA_countdown_3_10ms;

extern const uint16_t dual_watch_count_after_tx_10ms;
extern const uint16_t dual_watch_count_after_rx_10ms;
extern const uint16_t dual_watch_count_after_1_10ms;
Expand Down
10 changes: 5 additions & 5 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
case BK4819_FILTER_BW_WIDE:
case BK4819_FILTER_BW_NARROW:
#ifdef ENABLE_AM_FIX
// BK4819_SetFilterBandwidth(Bandwidth, gRxVfo->IsAM && gSetting_AM_fix);
BK4819_SetFilterBandwidth(Bandwidth, false);
BK4819_SetFilterBandwidth(Bandwidth, gRxVfo->IsAM && gSetting_AM_fix);
// BK4819_SetFilterBandwidth(Bandwidth, false);
#else
BK4819_SetFilterBandwidth(Bandwidth, false);
#endif
Expand Down Expand Up @@ -815,7 +815,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
{
gIsNoaaMode = true;
gNoaaChannel = gRxVfo->CHANNEL_SAVE - NOAA_CHANNEL_FIRST;
gNOAA_Countdown_10ms = 50; // 500ms
gNOAA_Countdown_10ms = NOAA_countdown_2_10ms;
gScheduleNOAA = false;
}
else
Expand Down Expand Up @@ -844,8 +844,8 @@ void RADIO_SetTxParameters(void)
case BK4819_FILTER_BW_WIDE:
case BK4819_FILTER_BW_NARROW:
#ifdef ENABLE_AM_FIX
// BK4819_SetFilterBandwidth(Bandwidth, gCurrentVfo->IsAM && gSetting_AM_fix);
BK4819_SetFilterBandwidth(Bandwidth, false);
BK4819_SetFilterBandwidth(Bandwidth, gCurrentVfo->IsAM && gSetting_AM_fix);
// BK4819_SetFilterBandwidth(Bandwidth, false);
#else
BK4819_SetFilterBandwidth(Bandwidth, false);
#endif
Expand Down
6 changes: 4 additions & 2 deletions ui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
#ifdef ENABLE_AUDIO_BAR
void UI_DisplayAudioBar(void)
{
// if (gCurrentFunction == FUNCTION_TRANSMIT && gSetting_mic_bar)
if (gSetting_mic_bar)
{
const unsigned int line = 3;
Expand All @@ -51,6 +50,8 @@
#if 1
// TX audio level

if (gCurrentFunction != FUNCTION_TRANSMIT)
return;

// TODO: logify this to make the bar visible with the mostly small value

Expand All @@ -76,7 +77,8 @@
pLine[i] = 0x3e;
#endif

ST7565_BlitFullScreen();
if (gCurrentFunction == FUNCTION_TRANSMIT)
ST7565_BlitFullScreen();
}
}
#endif
Expand Down
Loading

0 comments on commit bcfe977

Please sign in to comment.