Skip to content

Commit

Permalink
Tidy ups, speedier channel scanning, RSSI meter updating fix
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfEleven committed Oct 2, 2023
1 parent e0aa1a8 commit 3c7f496
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 132 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ ENABLE_TX_WHEN_AM := 0
ENABLE_CTCSS_TAIL_PHASE_SHIFT := 1
ENABLE_MAIN_KEY_HOLD := 1
ENABLE_BOOT_BEEPS := 0
ENABLE_COMPANDER := 0
ENABLE_SHOW_CHARGE_LEVEL := 0
ENABLE_COMPANDER := 1
ENABLE_SHOW_CHARGE_LEVEL := 1
ENABLE_REVERSE_BAT_SYMBOL := 1
ENABLE_CODE_SCAN_TIMEOUT := 0
ENABLE_AM_FIX := 1
ENABLE_AM_FIX_SHOW_DATA := 1
ENABLE_SQUELCH_LOWER := 1
ENABLE_RSSI_BAR := 1
ENABLE_AUDIO_BAR := 0
ENABLE_AUDIO_BAR := 1
#ENABLE_COPY_CHAN_TO_VFO := 1
#ENABLE_SINGLE_VFO_CHAN := 1
#ENABLE_BAND_SCOPE := 1
Expand Down
119 changes: 71 additions & 48 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static void APP_CheckForIncoming(void)
if (gCssScanMode != CSS_SCAN_MODE_OFF && gRxReceptionMode == RX_MODE_NONE)
{ // CTCSS/DTS scanning

ScanPauseDelayIn_10ms = 100; // 1 second
ScanPauseDelayIn_10ms = scan_pause_delay_in_5_10ms;
gScheduleScanListen = false;
gRxReceptionMode = RX_MODE_DETECTED;
}
Expand Down Expand Up @@ -160,7 +160,7 @@ static void APP_CheckForIncoming(void)
return;
}

ScanPauseDelayIn_10ms = 20; // 200ms
ScanPauseDelayIn_10ms = scan_pause_delay_in_3_10ms;
gScheduleScanListen = false;
}

Expand Down Expand Up @@ -401,7 +401,7 @@ static void APP_HandleReceive(void)
break;

case SCAN_RESUME_CO:
ScanPauseDelayIn_10ms = 360;
ScanPauseDelayIn_10ms = scan_pause_delay_in_7_10ms;
gScheduleScanListen = false;
break;

Expand Down Expand Up @@ -490,7 +490,7 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix)
case SCAN_RESUME_TO:
if (!gScanPauseMode)
{
ScanPauseDelayIn_10ms = 500;
ScanPauseDelayIn_10ms = scan_pause_delay_in_1_10ms;
gScheduleScanListen = false;
gScanPauseMode = true;
}
Expand Down Expand Up @@ -642,57 +642,76 @@ static void FREQ_NextChannel(void)
RADIO_SetupRegisters(true);

gUpdateDisplay = true;
ScanPauseDelayIn_10ms = 10;
ScanPauseDelayIn_10ms = scan_pause_delay_in_6_10ms;
bScanKeepFrequency = false;
}

static void MR_NextChannel(void)
{
const uint8_t Ch1 = gEeprom.SCANLIST_PRIORITY_CH1[gEeprom.SCAN_LIST_DEFAULT];
const uint8_t Ch2 = gEeprom.SCANLIST_PRIORITY_CH2[gEeprom.SCAN_LIST_DEFAULT];
const bool bEnabled = gEeprom.SCAN_LIST_ENABLED[gEeprom.SCAN_LIST_DEFAULT];
uint8_t PreviousCh = gNextMrChannel;
uint8_t Ch;

if (bEnabled)
static unsigned int prev_mr_chan = 0;
const bool enabled = gEeprom.SCAN_LIST_ENABLED[gEeprom.SCAN_LIST_DEFAULT];
const unsigned int chan1 = gEeprom.SCANLIST_PRIORITY_CH1[gEeprom.SCAN_LIST_DEFAULT];
const unsigned int chan2 = gEeprom.SCANLIST_PRIORITY_CH2[gEeprom.SCAN_LIST_DEFAULT];
const unsigned int prev_chan = gNextMrChannel;
unsigned int chan = 0;

if (enabled)
{
if (gCurrentScanList == 0)
switch (gCurrentScanList)
{
gPreviousMrChannel = gNextMrChannel;
if (RADIO_CheckValidChannel(Ch1, false, 0))
gNextMrChannel = Ch1;
else
gCurrentScanList = 1;
}
case SCAN_NEXT_CHAN_SCANLIST1:
prev_mr_chan = gNextMrChannel;
if (RADIO_CheckValidChannel(chan1, false, 0))
{
//gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1;
gNextMrChannel = chan1;
break;
}

if (gCurrentScanList == 1)
{
if (RADIO_CheckValidChannel(Ch2, false, 0))
gNextMrChannel = Ch2;
else
gCurrentScanList = 2;
}
case SCAN_NEXT_CHAN_SCANLIST2:
if (RADIO_CheckValidChannel(chan2, false, 0))
{
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST2;
gNextMrChannel = chan2;
break;
}

if (gCurrentScanList == 2)
{
gNextMrChannel = gPreviousMrChannel;
Ch = RADIO_FindNextChannel(gNextMrChannel + gScanState, gScanState, true, gEeprom.SCAN_LIST_DEFAULT);
if (Ch == 0xFF)
return;
// this bit doesn't work at all :(
case SCAN_NEXT_CHAN_DUAL_WATCH:
// if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF)
{
// chan = (gEeprom.RX_CHANNEL + 1) & 1u;
// chan = gEeprom.MrChannel[chan];
// chan = gEeprom.ScreenChannel[chan];
// chan = gEeprom.VfoInfo[chan].CHANNEL_SAVE;
// chan = 14;
// if (RADIO_CheckValidChannel(chan, false, 0))
// {
// gCurrentScanList = SCAN_NEXT_CHAN_DUAL_WATCH;
// gNextMrChannel = chan;
// break;
// }
}

gNextMrChannel = Ch;
default:
case SCAN_NEXT_CHAN_MR:
gCurrentScanList = SCAN_NEXT_CHAN_MR;
gNextMrChannel = prev_mr_chan;
chan = 0xffffffff;
break;
}
}
else

if (!enabled || chan == 0xffffffff)
{
Ch = RADIO_FindNextChannel(gNextMrChannel + gScanState, gScanState, true, gEeprom.SCAN_LIST_DEFAULT);
if (Ch == 0xFF)
chan = RADIO_FindNextChannel(gNextMrChannel + gScanState, gScanState, true, gEeprom.SCAN_LIST_DEFAULT);
if (chan == 0xFF)
return;

gNextMrChannel = Ch;
gNextMrChannel = chan;
}

if (PreviousCh != gNextMrChannel)
if (prev_chan != gNextMrChannel)
{
gEeprom.MrChannel[gEeprom.RX_CHANNEL] = gNextMrChannel;
gEeprom.ScreenChannel[gEeprom.RX_CHANNEL] = gNextMrChannel;
Expand All @@ -703,12 +722,14 @@ static void MR_NextChannel(void)
gUpdateDisplay = true;
}

ScanPauseDelayIn_10ms = scan_pause_delay_in_3_10ms;
bScanKeepFrequency = false;
// ScanPauseDelayIn_10ms = scan_pause_delay_in_3_10ms;
ScanPauseDelayIn_10ms = 8; // 100ms .. <= ~60ms it misses signals (squelch response and/or PLL lock time) ?

bScanKeepFrequency = false;

if (bEnabled)
if (++gCurrentScanList > 2)
gCurrentScanList = 0;
if (enabled)
if (++gCurrentScanList >= SCAN_NEXT_NUM)
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1; // back round we go
}

#ifdef ENABLE_NOAA
Expand Down Expand Up @@ -1450,7 +1471,6 @@ void APP_TimeSlice10ms(void)
// Skipping authentic device checks

#ifdef ENABLE_FMRADIO
// if (gFmRadioCountdown_500ms > 0)
if (gFmRadioMode && gFmRadioCountdown_500ms > 0) // 1of11
return;
#endif
Expand Down Expand Up @@ -1561,6 +1581,9 @@ void APP_TimeSlice10ms(void)
switch (gScanCssState)
{
case SCAN_CSS_STATE_OFF:

// must be RF frequency scanning if we're here ?

if (!BK4819_GetFrequencyScanResult(&Result))
break;

Expand Down Expand Up @@ -1593,8 +1616,8 @@ void APP_TimeSlice10ms(void)
gUpdateStatus = true;
}

//gScanDelay_10ms = scan_delay_10ms;
gScanDelay_10ms = 20 / 10; // 20ms
gScanDelay_10ms = scan_delay_10ms;
//gScanDelay_10ms = 1; // 10ms
break;

case SCAN_CSS_STATE_SCANNING:
Expand Down Expand Up @@ -1943,7 +1966,7 @@ void APP_TimeSlice500ms(void)
}
else
gDTMF_DecodeRingCountdown_500ms = 0;

if (gDTMF_CallState != DTMF_CALL_STATE_NONE &&
gCurrentFunction != FUNCTION_TRANSMIT &&
gCurrentFunction != FUNCTION_RECEIVE)
Expand Down Expand Up @@ -1996,7 +2019,7 @@ void CHANNEL_Next(bool bFlag, int8_t Direction)
RADIO_SelectVfos();

gNextMrChannel = gRxVfo->CHANNEL_SAVE;
gCurrentScanList = 0;
gCurrentScanList = SCAN_NEXT_CHAN_SCANLIST1;
gScanState = Direction;

if (IS_MR_CHANNEL(gNextMrChannel))
Expand Down
19 changes: 12 additions & 7 deletions driver/bk4819.c
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,14 @@ void BK4819_SetupSquelch(
//
BK4819_WriteRegister(BK4819_REG_4E, // 01 101 11 1 00000000
#if 0
// original
(1u << 14) // 1 ???
| (5u << 11) // 5 squelch = 1 delay .. 0 ~ 7
| (3u << 9) // 3 squelch = 0 delay .. 0 ~ 3
| SquelchOpenGlitchThresh); // 0 ~ 255
#else
// supposedly fast
(1u << 14) // 1 ???
| (2u << 11) // squelch = 1 delay .. 0 ~ 7
| (1u << 9) // squelch = 0 delay .. 0 ~ 3
| SquelchOpenGlitchThresh); // 0 ~ 255
#endif

Expand Down Expand Up @@ -1487,10 +1487,15 @@ void BK4819_PlayRogerMDC(void)
unsigned int i;

BK4819_SetAF(BK4819_AF_MUTE);
BK4819_WriteRegister(BK4819_REG_58, 0x37C3); // FSK Enable, RX Bandwidth FFSK1200/1800, 0xAA or 0x55 Preamble, 11 RX Gain,
// 101 RX Mode, FFSK1200/1800 TX
BK4819_WriteRegister(BK4819_REG_72, 0x3065); // Set Tone2 to 1200Hz
BK4819_WriteRegister(BK4819_REG_70, 0x00E0); // Enable Tone2 and Set Tone2 Gain

BK4819_WriteRegister(BK4819_REG_58, 0x37C3); // FSK Enable,
// RX Bandwidth FFSK 1200/1800
// 0xAA or 0x55 Preamble
// 11 RX Gain,
// 101 RX Mode
// TX FFSK 1200/1800
BK4819_WriteRegister(BK4819_REG_72, 0x3065); // Set Tone-2 to 1200Hz
BK4819_WriteRegister(BK4819_REG_70, 0x00E0); // Enable Tone-2 and Set Tone2 Gain
BK4819_WriteRegister(BK4819_REG_5D, 0x0D00); // Set FSK data length to 13 bytes
BK4819_WriteRegister(BK4819_REG_59, 0x8068); // 4 byte sync length, 6 byte preamble, clear TX FIFO
BK4819_WriteRegister(BK4819_REG_59, 0x0068); // Same, but clear TX FIFO is now unset (clearing done)
Expand All @@ -1509,7 +1514,7 @@ void BK4819_PlayRogerMDC(void)

SYSTEM_DelayMs(180);

// Stop FSK TX, reset Tone2, disable FSK
// Stop FSK TX, reset Tone-2, disable FSK
BK4819_WriteRegister(BK4819_REG_59, 0x0068);
BK4819_WriteRegister(BK4819_REG_70, 0x0000);
BK4819_WriteRegister(BK4819_REG_58, 0x0000);
Expand Down
Binary file modified firmware.bin
Binary file not shown.
Binary file modified firmware.packed.bin
Binary file not shown.
16 changes: 3 additions & 13 deletions frequencies.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,16 @@ uint32_t FREQUENCY_FloorToStep(uint32_t Upper, uint32_t Step, uint32_t Lower)

return Lower + (Step * Index);
}
/*
int TX_freq_check(VFO_Info_t *pInfo)
{ // return '0' if TX frequency is allowed
// otherwise return '-1'
const uint32_t Frequency = pInfo->pTX->Frequency;

#ifdef ENABLE_NOAA
if (pInfo->CHANNEL_SAVE > FREQ_CHANNEL_LAST)
return -1;
#endif
*/
int TX_freq_check(const uint32_t Frequency)
{ // return '0' if TX frequency is allowed
// otherwise return '-1'

if (Frequency < LowerLimitFrequencyBandTable[0] || Frequency > UpperLimitFrequencyBandTable[6])
return -1;
return -1; // not allowed outside this range

if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz)
return -1;
return -1; // BX chip does not work in this range

switch (gSetting_F_LOCK)
{
Expand Down
12 changes: 8 additions & 4 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ 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

Expand Down Expand Up @@ -192,10 +195,11 @@ bool gFlagEndTransmission;
uint16_t gLowBatteryCountdown;
uint8_t gNextMrChannel;
ReceptionMode_t gRxReceptionMode;
uint8_t gRestoreMrChannel;
uint8_t gCurrentScanList;
uint8_t gPreviousMrChannel;
uint32_t gRestoreFrequency;

uint8_t gRestoreMrChannel;
enum scan_next_chan_t gCurrentScanList;
uint32_t gRestoreFrequency;

bool gRxVfoIsActive;
#ifdef ENABLE_ALARM
uint8_t gAlarmToneCounter;
Expand Down
18 changes: 14 additions & 4 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ enum AlarmState_t {
ALARM_STATE_ALARM,
ALARM_STATE_TX1750
};

typedef enum AlarmState_t AlarmState_t;

enum ReceptionMode_t {
RX_MODE_NONE = 0, // squelch close ?
RX_MODE_DETECTED, // signal detected
RX_MODE_LISTENING //
};

typedef enum ReceptionMode_t ReceptionMode_t;

enum CssScanMode_t
Expand All @@ -80,9 +78,17 @@ enum CssScanMode_t
CSS_SCAN_MODE_SCANNING,
CSS_SCAN_MODE_FOUND,
};

typedef enum CssScanMode_t CssScanMode_t;

enum scan_next_chan_t {
SCAN_NEXT_CHAN_SCANLIST1 = 0,
SCAN_NEXT_CHAN_SCANLIST2,
SCAN_NEXT_CHAN_DUAL_WATCH,
SCAN_NEXT_CHAN_MR,
SCAN_NEXT_NUM
};
typedef enum scan_next_chan_t scan_next_chan_t;

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;
Expand Down Expand Up @@ -127,6 +133,9 @@ extern const uint16_t scan_pause_delay_in_1_10ms;
extern const uint16_t scan_pause_delay_in_2_10ms;
extern const uint16_t scan_pause_delay_in_3_10ms;
extern const uint16_t scan_pause_delay_in_4_10ms;
extern const uint16_t scan_pause_delay_in_5_10ms;
extern const uint16_t scan_pause_delay_in_6_10ms;
extern const uint16_t scan_pause_delay_in_7_10ms;

//extern const uint16_t gMax_bat_v;
//extern const uint16_t gMin_bat_v;
Expand Down Expand Up @@ -256,10 +265,11 @@ extern bool gFlagEndTransmission;
extern uint16_t gLowBatteryCountdown;
extern uint8_t gNextMrChannel;
extern ReceptionMode_t gRxReceptionMode;

extern uint8_t gRestoreMrChannel;
extern uint8_t gCurrentScanList;
extern uint8_t gPreviousMrChannel;
extern uint32_t gRestoreFrequency;

extern bool gRxVfoIsActive;
extern uint8_t gAlarmToneCounter;
extern uint16_t gAlarmRunningCounter;
Expand Down
Loading

0 comments on commit 3c7f496

Please sign in to comment.