Skip to content

Commit

Permalink
Merge pull request #57 from kamilsss655/rc17.4
Browse files Browse the repository at this point in the history
Rc17.4
  • Loading branch information
kamilsss655 authored Jan 10, 2024
2 parents a566155 + e64abf7 commit 57dbd7d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
6 changes: 1 addition & 5 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,11 +916,7 @@ void MENU_ShowCurrentSetting(void)
break;

case MENU_MEM_CH:
#if 0
gSubMenuSelection = gEeprom.MrChannel[0];
#else
gSubMenuSelection = gEeprom.MrChannel[gEeprom.TX_VFO];
#endif
gSubMenuSelection = RADIO_ValidMemoryChannelsCount(false, 0);
break;

case MENU_MEM_NAME:
Expand Down
57 changes: 53 additions & 4 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ struct FrequencyBandInfo {
uint32_t middle;
};

bool gTailFound;

#define F_MAX frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper

#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN
Expand All @@ -47,7 +49,9 @@ struct FrequencyBandInfo {

const uint16_t RSSI_MAX_VALUE = 65535;

static uint16_t R30, R37, R3D, R43, R47, R48, R7E;
#define SQUELCH_OFF_DELAY 10

static uint16_t R30, R37, R3D, R43, R47, R48, R7E, R02, R3F;
static uint32_t initialFreq;
static char String[32];

Expand Down Expand Up @@ -123,6 +127,8 @@ RegisterSpec registerSpecs[] = {
uint16_t statuslineUpdateTimer = 0;

static void RelaunchScan();
static void CheckIfTailFound();
static void ResetInterrupts();

static uint16_t GetRegMenuValue(uint8_t st) {
RegisterSpec s = registerSpecs[st];
Expand Down Expand Up @@ -228,6 +234,8 @@ static void BackupRegisters() {
R47 = BK4819_ReadRegister(BK4819_REG_47);
R48 = BK4819_ReadRegister(BK4819_REG_48);
R7E = BK4819_ReadRegister(BK4819_REG_7E);
R02 = BK4819_ReadRegister(BK4819_REG_02);
R3F = BK4819_ReadRegister(BK4819_REG_3F);
}

static void RestoreRegisters() {
Expand All @@ -238,6 +246,9 @@ static void RestoreRegisters() {
BK4819_WriteRegister(BK4819_REG_47, R47);
BK4819_WriteRegister(BK4819_REG_48, R48);
BK4819_WriteRegister(BK4819_REG_7E, R7E);
BK4819_WriteRegister(BK4819_REG_02, R02);
BK4819_WriteRegister(BK4819_REG_3F, R3F);

}

static void ToggleAFDAC(bool on) {
Expand All @@ -261,6 +272,33 @@ static void SetF(uint32_t f) {

bool IsPeakOverLevel() { return peak.rssi >= settings.rssiTriggerLevel; }

void CheckIfTailFound()
{
uint16_t interrupt_status_bits;
// if interrupt waiting to be handled
if(BK4819_ReadRegister(BK4819_REG_0C) & 1u) {
// reset the interrupt
BK4819_WriteRegister(BK4819_REG_02, 0);
// fetch the interrupt status bits
interrupt_status_bits = BK4819_ReadRegister(BK4819_REG_02);
// if tail found interrupt
if (interrupt_status_bits & BK4819_REG_02_CxCSS_TAIL)
{
gTailFound = true;
listenT = 0;
ResetInterrupts();
}
}
}

static void ResetInterrupts()
{
// disable interupts
BK4819_WriteRegister(BK4819_REG_3F, 0);
// reset the interrupt
BK4819_WriteRegister(BK4819_REG_02, 0);
}

static void ResetPeak() {
peak.t = 0;
peak.rssi = 0;
Expand Down Expand Up @@ -301,6 +339,7 @@ static void TuneToPeak() {
}
#ifdef ENABLE_SPECTRUM_COPY_VFO
static void ExitAndCopyToVfo() {
RestoreRegisters();
if (appMode==CHANNEL_MODE)
// channel mode
{
Expand Down Expand Up @@ -390,8 +429,13 @@ static void ToggleRX(bool on) {
ToggleAFBit(on);

if (on) {
listenT = 1000;
listenT = SQUELCH_OFF_DELAY;
BK4819_SetFilterBandwidth(settings.listenBw, false);

gTailFound=false;

// turn on CSS tail found interrupt
BK4819_WriteRegister(BK4819_REG_3F, BK4819_REG_02_CxCSS_TAIL);
} else {
if(appMode!=CHANNEL_MODE)
BK4819_WriteRegister(0x43, GetBWRegValueForScan());
Expand Down Expand Up @@ -592,6 +636,7 @@ static void ToggleModulation() {
settings.modulationType = MODULATION_FM;
}
RADIO_SetModulation(settings.modulationType);
BK4819_InitAGC(gEeprom.RX_AGC, settings.modulationType);
redrawScreen = true;
}

Expand Down Expand Up @@ -1368,8 +1413,10 @@ static void UpdateListening() {
peak.rssi = scanInfo.rssi;
redrawScreen = true;

if (IsPeakOverLevel() || monitorMode) {
listenT = 1000;
CheckIfTailFound();

if ((IsPeakOverLevel() || monitorMode) && !gTailFound) {
listenT = SQUELCH_OFF_DELAY;
return;
}

Expand Down Expand Up @@ -1457,6 +1504,8 @@ void APP_RunSpectrum() {

BackupRegisters();

ResetInterrupts();

isListening = true; // to turn off RX later
redrawStatus = true;
redrawScreen = true;
Expand Down

0 comments on commit 57dbd7d

Please sign in to comment.