Skip to content

Commit

Permalink
Modulation, filtering, keys, UI (see description)
Browse files Browse the repository at this point in the history
1) Added support for modulation
2) Added options to change bandwidth and filters
3) Reorganized UI
4) Changed keys to match UI layout
  • Loading branch information
xawen committed Nov 25, 2023
1 parent a868bde commit b950689
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 19 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ Menu => DTMF decoder
Exit => Single/dual VFO display
```

### Spectrum Key Mappings
```
Up => Increase frequency range by frequency +/- (number in middle of bottom row)
Down => Decrease frequency range by frequency +/- (number in middle of bottom row)
1 => Change number of scan steps (16, 32, 64 or 128)
2 =>
3 => Change modulation (AM, FM or SSB)
4 => Change step size (0.25k - 50k)
5 =>
6 => Inrease squelch level
7 =>
8 =>
9 => Decrease squelch level
0 => Toggle filter (U = unfiltered, F = filtered)
* => Change scan delay (0 - 40ms)
# => Toggle bandwidth (W = wide, N = narrow)
Menu =>
Exit => Exit spectrum
```

### Build & Flash
See __Compiler__, __Building__ and __Flashing__ sections below.

Expand Down
116 changes: 98 additions & 18 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/

#include "misc.h"
#include "app/spectrum.h"
#include "app/radio.h"
#include "driver/bk4819.h"
Expand Down Expand Up @@ -50,6 +51,8 @@ uint16_t RssiValue[128] = {0};
uint16_t SquelchLevel;
uint8_t bExit;
uint8_t bRXMode;
uint8_t bFilterEnabled;
uint8_t bNarrow;
uint16_t RssiLow;
uint16_t RssiHigh;
uint16_t BarScale;
Expand Down Expand Up @@ -77,13 +80,21 @@ const char* StepStrings[] = {
};

void DrawCurrentFreq(uint16_t Color){
static const char Mode[3][2] = {
"FM",
"AM",
"SB",
};

gColorForeground = Color;
Int2Ascii(CurrentFreq, 8);
for (uint8_t i = 6; i > 2; i--){
gShortString[i+1] = gShortString[i];
}
gShortString[3] = '.';
UI_DrawString(50, 80, gShortString, 8);
UI_DrawString(40, 92, gShortString, 8);

UI_DrawSmallString(108, 82, Mode[CurrentModulation], 2);
}

void DrawLabels(void){
Expand All @@ -106,15 +117,22 @@ void DrawLabels(void){

gShortString[2] = ' ';
Int2Ascii(CurrentStepCount, (CurrentStepCount < 100) ? 2 : 3);
UI_DrawSmallString(2, 76, gShortString, 3);
UI_DrawSmallString(2, 82, gShortString, 3);

UI_DrawSmallString(2, 64, StepStrings[CurrentFreqStepIndex], 5);
UI_DrawSmallString(2, 70, StepStrings[CurrentFreqStepIndex], 5);

gShortString[1] = ' ';
Int2Ascii(CurrentScanDelay, (CurrentScanDelay < 10) ? 1 : 2);
UI_DrawSmallString(142, 76, gShortString, 2);
if (CurrentScanDelay < 10) {
gShortString[1] = gShortString[0];
gShortString[0] = ' ';
}
UI_DrawSmallString(146, 72, gShortString, 2);

UI_DrawSmallString(152, 60, (bFilterEnabled) ? "F" : "U", 1);

UI_DrawSmallString(152, 48, (bNarrow) ? "N" : "W", 1);

gColorForeground = COLOR_BLUE;
gColorForeground = COLOR_GREY;

Int2Ascii(CurrentFreqChangeStep / 10, 5);
for (uint8_t i = 4; i > 0; i--){
Expand All @@ -128,6 +146,8 @@ void SetFreqMinMax(void){
CurrentFreqChangeStep = CurrentFreqStep*(CurrentStepCount >> 1);
FreqMin = FreqCenter - CurrentFreqChangeStep;
FreqMax = FreqCenter + CurrentFreqChangeStep;
FREQUENCY_SelectBand(FreqCenter);
BK4819_EnableFilter(bFilterEnabled);
RssiValue[CurrentFreqIndex] = 0; // Force a rescan
}

Expand Down Expand Up @@ -173,6 +193,27 @@ void ChangeSquelchLevel(uint8_t Up) {
}
}

void ToggleFilter(void) {
bFilterEnabled ^= 1;
BK4819_EnableFilter(bFilterEnabled);
DrawLabels();
}

void ToggleNarrowWide(void) {
bNarrow ^= 1;
if (bNarrow) {
BK4819_WriteRegister(0x43, 0x4048);
} else {
BK4819_WriteRegister(0x43, 0x3028);
}
DrawLabels();
}

void IncrementModulation(void) {
CurrentModulation = (CurrentModulation + 1) % 3;
DrawCurrentFreq((bRXMode) ? COLOR_GREEN : COLOR_BLUE);
}

uint16_t GetAdjustedLevel(uint16_t Level, uint16_t Low, uint16_t High, uint16_t Scale) {
uint16_t Value = 0;

Expand Down Expand Up @@ -220,15 +261,15 @@ void DrawSpectrum(uint16_t ActiveBarColor){
Power = GetAdjustedLevel(SquelchLevel, BarLow, BarHigh, BarScale);
DISPLAY_DrawRectangle1(16, BarY + Power, 1, 128, COLOR_RED);

gColorForeground = COLOR_RED;
gShortString[2] = ' ';
Int2Ascii(SquelchLevel, (SquelchLevel < 100) ? 2 : 3);
UI_DrawSmallString(142, 64, gShortString, 3);

gColorForeground = ActiveBarColor;
gShortString[2] = ' ';
Int2Ascii(RssiValue[CurrentFreqIndex], (RssiValue[CurrentFreqIndex] < 100) ? 2 : 3);
UI_DrawSmallString(142, 54, gShortString, 3);
UI_DrawSmallString(56, 62, gShortString, 3);

gColorForeground = COLOR_RED;
gShortString[2] = ' ';
Int2Ascii(SquelchLevel, (SquelchLevel < 100) ? 2 : 3);
UI_DrawSmallString(80, 62, gShortString, 3);

}

Expand Down Expand Up @@ -283,30 +324,31 @@ void CheckKeys(void){
case KEY_2:
break;
case KEY_3:
IncrementScanDelay();
IncrementModulation();
break;
case KEY_4:
IncrementFreqStepIndex();
break;
case KEY_5:
break;
case KEY_6:
ChangeSquelchLevel(TRUE);
break;
case KEY_7:
break;
case KEY_8:
BK4819_ToggleAGCMode(FALSE);
break;
case KEY_9:
BK4819_ToggleAGCMode(TRUE);
ChangeSquelchLevel(FALSE);
break;
case KEY_0:
ToggleFilter();
break;
case KEY_HASH:
ChangeSquelchLevel(FALSE);
ToggleNarrowWide();
break;
case KEY_STAR:
ChangeSquelchLevel(TRUE);
IncrementScanDelay();
break;
default:
break;
Expand All @@ -315,9 +357,45 @@ void CheckKeys(void){
}
}

void Spectrum_StartAudio(void)
{
gReceivingAudio = true;

gpio_bits_set(GPIOA, BOARD_GPIOA_LED_GREEN);
gRadioMode = RADIO_MODE_RX;
OpenAudio(bNarrow, CurrentModulation);
if (gMainVfo->gModulationType == 0) {
BK4819_WriteRegister(0x4D, 0xA080);
BK4819_WriteRegister(0x4E, 0x6F7C);
}

if (CurrentModulation > 0) {
// AM, SSB
BK4819_EnableScramble(false);
BK4819_EnableCompander(false);
// Set bit 4 of register 73 (Auto Frequency Control Disable)
uint16_t reg_73 = BK4819_ReadRegister(0x73);
BK4819_WriteRegister(0x73, reg_73 | 0x10U);
if (CurrentModulation > 1) { // if SSB
BK4819_WriteRegister(0x43, 0b0010000001011000); // Filter 6.25KHz
BK4819_WriteRegister(0x37, 0b0001011000001111);
BK4819_WriteRegister(0x3D, 0b0010101101000101);
BK4819_WriteRegister(0x48, 0b0000001110101000);
}
} else {
// FM
BK4819_EnableCompander(true);
uint16_t reg_73 = BK4819_ReadRegister(0x73);
BK4819_WriteRegister(0x73, reg_73 & ~0x10U);
BK4819_SetAFResponseCoefficients(false, true, gCalibration.RX_3000Hz_Coefficient);
}
SPEAKER_TurnOn(SPEAKER_OWNER_RX);
}

void RunRX(void) {
bRXMode = TRUE;
RADIO_StartAudio();
//RADIO_StartAudio();
Spectrum_StartAudio();

while(RssiValue[CurrentFreqIndex] > SquelchLevel) {
RssiValue[CurrentFreqIndex] = BK4819_GetRSSI();
Expand Down Expand Up @@ -399,11 +477,13 @@ void APP_Spectrum(void){
RegisterBackup[0] = BK4819_ReadRegister(0x7E);

FreqCenter = gVfoState[gSettings.CurrentVfo].RX.Frequency;
bNarrow = gVfoState[gSettings.CurrentVfo].bIsNarrow;
CurrentModulation = gVfoState[gSettings.CurrentVfo].gModulationType;
CurrentFreqStepIndex = gSettings.FrequencyStep;
CurrentFreqStep = FREQUENCY_GetStep(CurrentFreqStepIndex);
CurrentStepCountIndex = STEPS_64;
CurrentScanDelay = 5;
bFilterEnabled = TRUE;
SquelchLevel = 0;
BarScale = 40;
BarY = 15;
Expand Down
2 changes: 1 addition & 1 deletion driver/bk4819.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static void DisableAGC(uint32_t Unknown)
}
#endif

static void OpenAudio(bool bIsNarrow, uint8_t gModulationType)
void OpenAudio(bool bIsNarrow, uint8_t gModulationType)
{
switch(gModulationType) {
case 0:
Expand Down
1 change: 1 addition & 0 deletions driver/bk4819.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum BK4819_AF_Type_t {

typedef enum BK4819_AF_Type_t BK4819_AF_Type_t;

void OpenAudio(bool bIsNarrow, uint8_t gModulationType);
uint16_t BK4819_ReadRegister(uint8_t Reg);
uint16_t BK4819_GetRSSI();
void BK4819_WriteRegister(uint8_t Reg, uint16_t Data);
Expand Down

0 comments on commit b950689

Please sign in to comment.