Skip to content

Commit

Permalink
Merge pull request #85 from kamilsss655/rc19.7
Browse files Browse the repository at this point in the history
Rc19.7
  • Loading branch information
kamilsss655 authored Jan 19, 2024
2 parents 3942f6d + 0ce83e8 commit 07f191e
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 12 deletions.
5 changes: 4 additions & 1 deletion app/fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include "settings.h"
#include "ui/ui.h"

const uint16_t FM_RADIO_MAX_FREQ = 1080; // 108 Mhz
const uint16_t FM_RADIO_MIN_FREQ = 875; // 87.5 Mhz

bool gFmRadioMode;
uint8_t gFmRadioCountdown_500ms;
volatile uint16_t gFmPlayCountdown_10ms;
Expand Down Expand Up @@ -59,7 +62,7 @@ static void Key_EXIT()

static void Key_UP_DOWN(bool direction)
{
BK1080_TuneNext(direction);
BK1080_TuneNext(direction);
gEeprom.FM_FrequencyPlaying = BK1080_GetFrequency();
// save
gRequestSaveSettings = true;
Expand Down
3 changes: 3 additions & 0 deletions app/fm.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

#include "driver/keyboard.h"

extern const uint16_t FM_RADIO_MAX_FREQ;
extern const uint16_t FM_RADIO_MIN_FREQ;

enum {
FM_SCAN_OFF = 0U,
};
Expand Down
68 changes: 59 additions & 9 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ bool gTailFound;
Mode appMode;
//Idea - make this user adjustable to compensate for different antennas, frontends, conditions
#define UHF_NOISE_FLOOR 40
bool scanPassComplete;
uint16_t rssiNormalization[128];
uint8_t scanChannel[MR_CHANNEL_LAST+3];
uint8_t scanChannelsCount;
void ToggleScanList();
void AutoAdjustResolution();
void ToggleNormalizeRssi();
#endif

const uint16_t RSSI_MAX_VALUE = 65535;
Expand Down Expand Up @@ -305,22 +308,26 @@ static void TuneToPeak() {
#ifdef ENABLE_SPECTRUM_COPY_VFO
static void ExitAndCopyToVfo() {
RestoreRegisters();
gTxVfo->Modulation = settings.modulationType;
gTxVfo->CHANNEL_BANDWIDTH = settings.listenBw;
gTxVfo->Band = FREQUENCY_GetBand(peak.f);

if (appMode==CHANNEL_MODE)
// channel mode
{
gEeprom.MrChannel[gEeprom.TX_VFO] = scanChannel[peak.i-1];
gEeprom.ScreenChannel[gEeprom.TX_VFO] = scanChannel[peak.i-1];

gRequestSaveVFO = true;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
}
else // frequency mode
else
// frequency mode
{
gTxVfo->STEP_SETTING = FREQUENCY_GetStepIdxFromStepFrequency(GetScanStep());
}
gTxVfo->Modulation = settings.modulationType;
gTxVfo->CHANNEL_BANDWIDTH = settings.listenBw;

SETTINGS_SetVfoFrequency(peak.f);
gRequestSaveChannel = 1;
SETTINGS_SetVfoFrequency(peak.f);

gRequestSaveChannel = 1;
}

// Additional delay to debounce keys
SYSTEM_DelayMs(200);
Expand Down Expand Up @@ -382,6 +389,9 @@ uint16_t GetRssi() {
rssi+=UHF_NOISE_FLOOR;
}

if (appMode==CHANNEL_MODE)
rssi+=rssiNormalization[scanInfo.i];

#endif
return rssi;
}
Expand Down Expand Up @@ -457,6 +467,7 @@ static void ResetBlacklist() {
if(appMode==CHANNEL_MODE){
LoadValidMemoryChannels();
AutoAdjustResolution();
memset(rssiNormalization, 0, sizeof(rssiNormalization));
}

RelaunchScan();
Expand Down Expand Up @@ -1018,7 +1029,16 @@ static void OnKeyDown(uint8_t key) {
}
break;
case KEY_SIDE2:
ToggleBacklight();
#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN
if(appMode==CHANNEL_MODE){
ToggleNormalizeRssi();
}
else {
ToggleBacklight();
}
#elif
ToggleBacklight();
#endif
break;
case KEY_PTT:
#ifdef ENABLE_SPECTRUM_COPY_VFO
Expand Down Expand Up @@ -1343,6 +1363,12 @@ static void UpdateScan() {
NextScanStep();
return;
}
#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN
else {
if(scanPassComplete == false)
scanPassComplete = true;
}
#endif

if(scanInfo.measurementsCount < 128)
memset(&rssiHistory[scanInfo.measurementsCount], 0,
Expand Down Expand Up @@ -1570,4 +1596,28 @@ void APP_RunSpectrum() {
settings.stepsCount = STEPS_128;
}
}
// 2024 by kamilsss655 -> https://github.com/kamilsss655
// flattens spectrum by bringing all the rssi readings to the peak value
void ToggleNormalizeRssi()
{
// we don't want to normalize when there is already active signal RX
if(IsPeakOverLevel())
return;

memset(rssiNormalization, 0, sizeof(rssiNormalization));

// we should do a full scan without correction, and only then apply correction
if(scanPassComplete == false){
newScanStart = true;
return;
}
else
{
for(uint8_t i = 0; i < ARRAY_SIZE(rssiHistory); i++)
{
rssiNormalization[i] = peak.rssi - rssiHistory[i];
}
scanPassComplete = false;
}
}
#endif
4 changes: 4 additions & 0 deletions board.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@ void BOARD_EEPROM_Init(void)
#ifdef ENABLE_FMRADIO
EEPROM_ReadBuffer(0x0E88, Data, 8);
memmove(&gEeprom.FM_FrequencyPlaying, Data, 2);
// validate that its within the supported range
if(gEeprom.FM_FrequencyPlaying < FM_RADIO_MIN_FREQ || gEeprom.FM_FrequencyPlaying > FM_RADIO_MAX_FREQ)
gEeprom.FM_FrequencyPlaying = FM_RADIO_MIN_FREQ;

#endif

// 0E90..0E97
Expand Down
6 changes: 5 additions & 1 deletion driver/bk1080.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ void BK1080_TuneNext(bool direction)
{
uint16_t reg_11;
uint16_t reg_02;
uint8_t scanCounter_100ms = 100; // timeouts after 10s

reg_02 = BK1080_ReadRegister(BK1080_REG_02_POWER_CONFIGURATION);
reg_11 = BK1080_ReadRegister(BK1080_REG_11);
Expand All @@ -128,7 +129,10 @@ void BK1080_TuneNext(bool direction)

// wait until we find the channel
while((BK1080_ReadRegister(BK1080_REG_10) >> 14) == 0){
SYSTEM_DelayMs(5);
if(scanCounter_100ms-- == 0)
break;

SYSTEM_DelayMs(100);
}

//read found freq
Expand Down
2 changes: 1 addition & 1 deletion driver/bk4819.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ void BK4819_InitAGC(const uint8_t agcType, ModulationMode_t modulation)
BK4819_WriteRegister(BK4819_REG_49, (0 << 14) | (50 << 7) | (15 << 0));
break;
case RX_AGC_FAST:
BK4819_WriteRegister(BK4819_REG_49, (0 << 14) | (47 << 7) | (22 << 0));
BK4819_WriteRegister(BK4819_REG_49, (0 << 14) | (50 << 7) | (25 << 0));
break;
default:
return;
Expand Down

0 comments on commit 07f191e

Please sign in to comment.