Skip to content

Commit

Permalink
Merge pull request #29 from kamilsss655/rc17
Browse files Browse the repository at this point in the history
Rc17
  • Loading branch information
kamilsss655 authored Jan 2, 2024
2 parents 04752f8 + 3056ca8 commit 17c055a
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 26 deletions.
2 changes: 1 addition & 1 deletion am_fix.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ int16_t rssi_gain_diff[2] = {0, 0};
unsigned int max_index = ARRAY_SIZE(gain_table) - 1;

// -110dBm, any higher and the AM demodulator starts to saturate/clip/distort
const int16_t desired_rssi = (-110 + 165) * 2;
const int16_t desired_rssi = (-110 + 180) * 2;

void AM_fix_init(void)
{ // called at boot-up
Expand Down
15 changes: 9 additions & 6 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,10 @@ static void ToggleRX(bool on) {

if (on) {
listenT = 1000;
BK4819_WriteRegister(0x43, listenBWRegValues[settings.listenBw]);
BK4819_SetFilterBandwidth(settings.listenBw, false);
} else {
BK4819_WriteRegister(0x43, GetBWRegValueForScan());
if(appMode!=CHANNEL_MODE)
BK4819_WriteRegister(0x43, GetBWRegValueForScan());
}
}

Expand Down Expand Up @@ -605,6 +606,7 @@ static void ToggleListeningBW() {
} else {
settings.listenBw++;
}
BK4819_SetFilterBandwidth(settings.listenBw, false);
redrawScreen = true;
}

Expand Down Expand Up @@ -1365,9 +1367,10 @@ static void UpdateListening() {
}

if (currentState == SPECTRUM) {
BK4819_WriteRegister(0x43, GetBWRegValueForScan());
if(appMode!=CHANNEL_MODE)
BK4819_WriteRegister(0x43, GetBWRegValueForScan());
Measure();
BK4819_WriteRegister(0x43, listenBWRegValues[settings.listenBw]);
BK4819_SetFilterBandwidth(settings.listenBw, false);
} else {
Measure();
}
Expand Down Expand Up @@ -1473,11 +1476,11 @@ void APP_RunSpectrum() {
ToggleRX(true), ToggleRX(false); // hack to prevent noise when squelch off
#ifdef ENABLE_SPECTRUM_COPY_VFO
RADIO_SetModulation(settings.modulationType = gTxVfo->Modulation);
BK4819_SetFilterBandwidth(settings.listenBw = gTxVfo->CHANNEL_BANDWIDTH);
BK4819_SetFilterBandwidth(settings.listenBw = gTxVfo->CHANNEL_BANDWIDTH, false);
settings.scanStepIndex = GetScanStepFromStepFrequency(gTxVfo->StepFrequency);
#elif
RADIO_SetModulation(settings.modulationType = MODULATION_FM);
BK4819_SetFilterBandwidth(settings.listenBw = BK4819_FILTER_BW_WIDE);
BK4819_SetFilterBandwidth(settings.listenBw = BK4819_FILTER_BW_WIDE, false);
#endif

RelaunchScan();
Expand Down
10 changes: 5 additions & 5 deletions app/spectrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ static const uint16_t scanStepBWRegValues[] = {
0b0011011000101000, // 25
};

static const uint16_t listenBWRegValues[] = {
0b0011011000101000, // 25
0b0111111100001000, // 12.5
0b0100100001011000, // 6.25
};
// static const uint16_t listenBWRegValues[] = {
// 0b0011011000101000, // 25
// 0b0111111100001000, // 12.5
// 0b0100100001011000, // 6.25
// };

typedef enum State {
SPECTRUM,
Expand Down
55 changes: 44 additions & 11 deletions driver/bk4819.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,17 +516,50 @@ void BK4819_EnableVox(uint16_t VoxEnableThreshold, uint16_t VoxDisableThreshold,
BK4819_WriteRegister(BK4819_REG_31, REG_31_Value | (1u << 2)); // VOX Enable
}

const uint16_t listenBWRegValues[5] = {
0x3028, // 25
0x4048, // 12.5
0x0349, // 8.33
0x205C, // 6.25
0x01F4 // 5
};

void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth)
{
BK4819_WriteRegister(BK4819_REG_43, listenBWRegValues[Bandwidth]);
/*
Sets filter bandwidth
dynamic: if set to true, it will use dynamic filters that lower bandwidth when signal is low
*/
void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth, const bool dynamic)
{
//1o11
// // filter bandwidth lowers when signal is low
// const uint16_t listenBWRegDynamicValues[5] = {
// 0x45a8, // 25
// 0x4408, // 12.5
// 0x1148, // 8.33
// 0x4458, // 6.25
// 0x0058 // 5
// };

// // filter bandwidth stays the same when signal is low
// const uint16_t listenBWRegValues[5] = {
// 0x49a8, // 25
// 0x4808, // 12.5
// 0x1348, // 8.33
// 0x4858, // 6.25
// 0x0058 // 5
// };
//fagci (narrower 25, 12.5)
// filter bandwidth lowers when signal is low
const uint16_t listenBWRegDynamicValues[5] = {
0x3428, // 25
0x7B08, // 12.5
0x1148, // 8.33
0x4458, // 6.25
0x0058 // 5
};

// filter bandwidth stays the same when signal is low
const uint16_t listenBWRegValues[5] = {
0x3628, // 25
0x7F08, // 12.5
0x1348, // 8.33
0x4858, // 6.25
0x0058 // 5
};

BK4819_WriteRegister(BK4819_REG_43, dynamic==true ? listenBWRegDynamicValues[Bandwidth] : listenBWRegValues[Bandwidth]);
}

void BK4819_SetupPowerAmplifier(uint8_t Bias, uint32_t Frequency) {
Expand Down
2 changes: 1 addition & 1 deletion driver/bk4819.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void BK4819_SetCDCSSCodeWord(uint32_t CodeWord);
void BK4819_SetCTCSSFrequency(uint32_t BaudRate);
void BK4819_SetTailDetection(const uint32_t freq_10Hz);
void BK4819_EnableVox(uint16_t Vox1Threshold, uint16_t Vox0Threshold, uint8_t VoxDelay);
void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth);
void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth, const bool dynamic);
void BK4819_SetupPowerAmplifier(const uint8_t bias, const uint32_t frequency);
void BK4819_SetDefaultAmplifierSettings();
void BK4819_SetFrequency(uint32_t Frequency);
Expand Down
4 changes: 2 additions & 2 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ void RADIO_SetupRegisters(bool switchToForeground)

BK4819_FilterBandwidth_t Bandwidth = gRxVfo->CHANNEL_BANDWIDTH;

BK4819_SetFilterBandwidth(Bandwidth);
BK4819_SetFilterBandwidth(Bandwidth, gRxVfo->Modulation != MODULATION_AM);

BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1_RED, false);

Expand Down Expand Up @@ -824,7 +824,7 @@ void RADIO_SetTxParameters(void)

BK4819_FilterBandwidth_t Bandwidth = gCurrentVfo->CHANNEL_BANDWIDTH;

BK4819_SetFilterBandwidth(Bandwidth);
BK4819_SetFilterBandwidth(Bandwidth, gRxVfo->Modulation != MODULATION_AM);


BK4819_SetFrequency(gCurrentVfo->pTX->Frequency);
Expand Down

0 comments on commit 17c055a

Please sign in to comment.