Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save bytes, 24 FM broadcast channels, Global channel skip #9

Merged
merged 12 commits into from
Jul 25, 2024
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ OBJS += external/printf/printf.o

# Drivers
OBJS += driver/adc.o
ifeq ($(ENABLE_PWRON_PASSWORD),1)
ifeq ($(ENABLE_UART),1)
OBJS += driver/aes.o
endif
endif
OBJS += driver/backlight.o
ifeq ($(ENABLE_FMRADIO),1)
OBJS += driver/bk1080.o
Expand Down Expand Up @@ -213,7 +215,7 @@ ifeq ($(ENABLE_FEAT_F4HWN),1)
VERSION_STRING_1 ?= v2.8.1

AUTHOR_STRING_2 ?= Voxless
VERSION_STRING_2 ?= v1.0.2
VERSION_STRING_2 ?= v1.0.3

AUTHOR_STRING ?= $(AUTHOR_STRING_1)+$(AUTHOR_STRING_2)
VERSION_STRING ?= $(VERSION_STRING_2)
Expand Down
2 changes: 1 addition & 1 deletion app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ void APP_Update(void)
gRxIdleMode = true;
goToSleep = false;

BK4819_DisableVox();
//BK4819_DisableVox();
BK4819_Sleep();
BK4819_ToggleGpioOut(BK4819_GPIO0_PIN28_RX_ENABLE, false);

Expand Down
6 changes: 3 additions & 3 deletions app/chFrScanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ void CHFRSCANNER_Start(const bool storeBackupSettings, const int8_t scan_directi

if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) {
dwchan = (gEeprom.RX_VFO + 1) & 1u;
dwchan = gEeprom.ScreenChannel[dwchan];
dwchan = gEeprom.ScreenChannel[dwchan]+1;
if (!IS_MR_CHANNEL(dwchan))
dwchan = 0;

}

if (IS_MR_CHANNEL(gNextMrChannel))
Expand Down Expand Up @@ -265,7 +264,8 @@ static void NextMemChannel(void)
if (++dualscan%4==0) {
dualscan=0;
currentScanList = SCAN_NEXT_CHAN_DUAL_WATCH;
gNextMrChannel = dwchan;
if (!gMR_ChannelExclude[dwchan-1])
gNextMrChannel = dwchan-1;
break;
}
}
Expand Down
8 changes: 4 additions & 4 deletions app/fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif

uint16_t gFM_Channels[20];
uint16_t gFM_Channels[24];
bool gFmRadioMode;
uint8_t gFmRadioCountdown_500ms;
volatile uint16_t gFmPlayCountdown_10ms;
Expand Down Expand Up @@ -297,7 +297,7 @@ static void Key_DIGITS(KEY_Code_t Key, uint8_t state)
return;
}
}
else if (Channel < 20) {
else if (Channel < ARRAY_SIZE(gFM_Channels)) {
#ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif
Expand Down Expand Up @@ -569,10 +569,10 @@ void FM_Play(void)
return;
}

if (gFM_ChannelPosition < 20)
if (gFM_ChannelPosition < ARRAY_SIZE(gFM_Channels))
gFM_Channels[gFM_ChannelPosition++] = gEeprom.FM_FrequencyPlaying;

if (gFM_ChannelPosition >= 20) {
if (gFM_ChannelPosition >= ARRAY_SIZE(gFM_Channels)) {
FM_PlayAndUpdate();
GUI_SelectNextDisplay(DISPLAY_FM);
return;
Expand Down
2 changes: 1 addition & 1 deletion app/fm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum {
FM_SCAN_OFF = 0U,
};

extern uint16_t gFM_Channels[20];
extern uint16_t gFM_Channels[24];
extern bool gFmRadioMode;
extern uint8_t gFmRadioCountdown_500ms;
extern volatile uint16_t gFmPlayCountdown_10ms;
Expand Down
18 changes: 9 additions & 9 deletions app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,13 +362,9 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
if (gScanStateDir != SCAN_OFF){
switch(Key){
case KEY_1:
gEeprom.SCAN_LIST_DEFAULT=0;
break;
case KEY_2:
gEeprom.SCAN_LIST_DEFAULT=1;
break;
case KEY_3:
gEeprom.SCAN_LIST_DEFAULT=2;
gEeprom.SCAN_LIST_DEFAULT=Key-1;
break;
case KEY_0:
gEeprom.SCAN_LIST_DEFAULT=3;
Expand Down Expand Up @@ -579,6 +575,11 @@ static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
gInputBoxIndex = 0;
gRequestDisplayScreen = DISPLAY_MAIN;
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
} else {
if (gMR_ChannelExclude[gTxVfo->CHANNEL_SAVE]) {
gMR_ChannelExclude[gTxVfo->CHANNEL_SAVE] = false;
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
}
}
}
}
Expand All @@ -594,14 +595,13 @@ static void MAIN_Key_MENU(bool bKeyPressed, bool bKeyHeld)
if (bKeyPressed) { // long press MENU key

#ifdef ENABLE_FEAT_F4HWN
if(gScanStateDir != SCAN_OFF && gEeprom.SCAN_LIST_DEFAULT < 5)
if(gScanStateDir != SCAN_OFF)
{
if(FUNCTION_IsRx())
{
gTxVfo->SCANLIST_PARTICIPATION = 0;

SETTINGS_UpdateChannel(gTxVfo->CHANNEL_SAVE, gTxVfo, true, true, false);

gMR_ChannelExclude[gTxVfo->CHANNEL_SAVE] = true;

gVfoConfigureMode = VFO_CONFIGURE;
gFlagResetVfos = true;

Expand Down
22 changes: 14 additions & 8 deletions app/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include "board.h"
#include "bsp/dp32g030/dma.h"
#include "bsp/dp32g030/gpio.h"
#include "driver/aes.h"
#ifdef ENABLE_PWRON_PASSWORD
#include "driver/aes.h"
#endif
#include "driver/backlight.h"
#include "driver/bk4819.h"
#include "driver/crc.h"
Expand Down Expand Up @@ -208,7 +210,7 @@ static void SendVersion(void)

SendReply(&Reply, sizeof(Reply));
}

#ifdef ENABLE_PWRON_PASSWORD
static bool IsBadChallenge(const uint32_t *pKey, const uint32_t *pIn, const uint32_t *pResponse)
{
unsigned int i;
Expand All @@ -227,7 +229,7 @@ static bool IsBadChallenge(const uint32_t *pKey, const uint32_t *pIn, const uint

return false;
}

#endif
// session init, sends back version info and state
// timestamp is a session id really
static void CMD_0514(const uint8_t *pBuffer)
Expand Down Expand Up @@ -269,10 +271,10 @@ static void CMD_051B(const uint8_t *pBuffer)
Reply.Header.Size = pCmd->Size + 4;
Reply.Data.Offset = pCmd->Offset;
Reply.Data.Size = pCmd->Size;

#ifdef ENABLE_PWRON_PASSWORD
if (bHasCustomAesKey)
bLocked = gIsLocked;

#endif
if (!bLocked)
EEPROM_ReadBuffer(pCmd->Offset, Reply.Data.Data, pCmd->Size);

Expand Down Expand Up @@ -301,9 +303,9 @@ static void CMD_051D(const uint8_t *pBuffer)
Reply.Header.ID = 0x051E;
Reply.Header.Size = sizeof(Reply.Data);
Reply.Data.Offset = pCmd->Offset;

#ifdef ENABLE_PWRON_PASSWORD
bIsLocked = bHasCustomAesKey ? gIsLocked : bHasCustomAesKey;

#endif
if (!bIsLocked)
{
unsigned int i;
Expand Down Expand Up @@ -357,6 +359,7 @@ static void CMD_0529(void)
static void CMD_052D(const uint8_t *pBuffer)
{
const CMD_052D_t *pCmd = (const CMD_052D_t *)pBuffer;

REPLY_052D_t Reply;
bool bIsLocked;

Expand All @@ -366,6 +369,7 @@ static void CMD_052D(const uint8_t *pBuffer)
Reply.Header.ID = 0x052E;
Reply.Header.Size = sizeof(Reply.Data);

#ifdef ENABLE_PWRON_PASSWORD
bIsLocked = bHasCustomAesKey;

if (!bIsLocked)
Expand All @@ -388,7 +392,9 @@ static void CMD_052D(const uint8_t *pBuffer)
gTryCount = 3;
bIsLocked = true;
}

#else
bIsLocked = pCmd->Response[0];
#endif
gIsLocked = bIsLocked;
Reply.Data.bIsLocked = bIsLocked;

Expand Down
4 changes: 2 additions & 2 deletions driver/bk4819.c
Original file line number Diff line number Diff line change
Expand Up @@ -924,11 +924,11 @@ void BK4819_SetCompander(const unsigned int mode)
BK4819_WriteRegister(BK4819_REG_31, r31 | (1u << 3));
}

void BK4819_DisableVox(void)
/* void BK4819_DisableVox(void)
{
const uint16_t Value = BK4819_ReadRegister(BK4819_REG_31);
BK4819_WriteRegister(BK4819_REG_31, Value & 0xFFFB);
}
} */

void BK4819_DisableDTMF(void)
{
Expand Down
2 changes: 1 addition & 1 deletion driver/bk4819.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void BK4819_EnableScramble(uint8_t Type);
bool BK4819_CompanderEnabled(void);
void BK4819_SetCompander(const unsigned int mode);

void BK4819_DisableVox(void);
//void BK4819_DisableVox(void);
void BK4819_DisableDTMF(void);
void BK4819_EnableDTMF(void);
void BK4819_PlayTone(uint16_t Frequency, bool bTuningGainSwitch);
Expand Down
2 changes: 1 addition & 1 deletion functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void FUNCTION_PowerSave() {

gMonitor = false;

BK4819_DisableVox();
// BK4819_DisableVox();
BK4819_Sleep();

BK4819_ToggleGpioOut(BK4819_GPIO0_PIN28_RX_ENABLE, false);
Expand Down
1 change: 1 addition & 0 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ uint16_t gEEPROM_1F8A;
uint16_t gEEPROM_1F8C;

ChannelAttributes_t gMR_ChannelAttributes[FREQ_CHANNEL_LAST + 1];
bool gMR_ChannelExclude[FREQ_CHANNEL_LAST + 1];

volatile uint16_t gBatterySaveCountdown_10ms = battery_save_count_10ms;

Expand Down
1 change: 1 addition & 0 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ typedef union {
} ChannelAttributes_t;

extern ChannelAttributes_t gMR_ChannelAttributes[207];
extern bool gMR_ChannelExclude[207];

extern volatile uint16_t gBatterySaveCountdown_10ms;

Expand Down
5 changes: 4 additions & 1 deletion radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ bool RADIO_CheckValidChannel(uint16_t channel, bool checkScanList, uint8_t scanL

const ChannelAttributes_t att = gMR_ChannelAttributes[channel];

if (checkScanList && gMR_ChannelExclude[channel] == true)
return false;

if (att.band > BAND7_470MHz)
return false;

Expand Down Expand Up @@ -843,7 +846,7 @@ void RADIO_SetupRegisters(bool switchToForeground)
else
#endif
{
BK4819_DisableVox();
//BK4819_DisableVox();
}

// RX expander
Expand Down
17 changes: 9 additions & 8 deletions scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,21 @@ void SystickHandler(void)
if (gCurrentFunction == FUNCTION_POWER_SAVE)
DECREMENT_AND_TRIGGER(gPowerSave_10ms, gPowerSaveCountdownExpired);

if (gScanStateDir == SCAN_OFF && !gCssBackgroundScan && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF)
if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE)
DECREMENT_AND_TRIGGER(gDualWatchCountdown_10ms, gScheduleDualWatch);
if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT){
if (gScanStateDir == SCAN_OFF && !gCssBackgroundScan && gCurrentFunction != FUNCTION_RECEIVE){
if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF)
DECREMENT_AND_TRIGGER(gDualWatchCountdown_10ms, gScheduleDualWatch);

#ifdef ENABLE_NOAA
if (gScanStateDir == SCAN_OFF && !gCssBackgroundScan && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF)
if (gIsNoaaMode && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT)
if (gCurrentFunction != FUNCTION_RECEIVE)

if (gIsNoaaMode && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF)
DECREMENT_AND_TRIGGER(gNOAA_Countdown_10ms, gScheduleNOAA);
#endif
}

if (gScanStateDir != SCAN_OFF)
if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT)
if (gScanStateDir != SCAN_OFF)
DECREMENT_AND_TRIGGER(gScanPauseDelayIn_10ms, gScheduleScanListen);
}

DECREMENT_AND_TRIGGER(gTailNoteEliminationCountdown_10ms, gFlagTailNoteEliminationComplete);

Expand Down
29 changes: 12 additions & 17 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "settings.h"
#include "ui/menu.h"

/*
static const uint32_t gDefaultFrequencyTable[] =
{
14500000, //
Expand All @@ -35,6 +36,7 @@ static const uint32_t gDefaultFrequencyTable[] =
43320000, //
43350000 //
};
*/

EEPROM_Config_t gEeprom = { 0 };

Expand Down Expand Up @@ -106,7 +108,7 @@ void SETTINGS_InitEEPROM(void)
gEeprom.FM_IsMrMode = fmCfg.isMrMode;
}

// 0E40..0E67
// 0E40..0E67 -> 0E40..0E6F
EEPROM_ReadBuffer(0x0E40, gFM_Channels, sizeof(gFM_Channels));
FM_ConfigureChannelState();
#endif
Expand Down Expand Up @@ -441,6 +443,7 @@ void SETTINGS_FactoryReset(bool bIsAll)
RADIO_InitInfo(gRxVfo, FREQ_CHANNEL_FIRST + BAND6_400MHz, 43350000);

// set the first few memory channels
/* don't need this
for (i = 0; i < ARRAY_SIZE(gDefaultFrequencyTable); i++)
{
const uint32_t Frequency = gDefaultFrequencyTable[i];
Expand All @@ -449,6 +452,7 @@ void SETTINGS_FactoryReset(bool bIsAll)
gRxVfo->Band = FREQUENCY_GetBand(Frequency);
SETTINGS_SaveChannel(MR_CHANNEL_FIRST + i, 0, gRxVfo, 2);
}
*/
}
}

Expand Down Expand Up @@ -618,12 +622,9 @@ void SETTINGS_SaveSettings(void)

State[0] = gEeprom.SCAN_LIST_DEFAULT;
//State[1] = gEeprom.SCAN_LIST_ENABLED[0];
if (gEeprom.SCAN_LIST_ENABLED[0] == 1)
tmp = tmp | (1 << 0);
if (gEeprom.SCAN_LIST_ENABLED[1] == 1)
tmp = tmp | (1 << 1);
if (gEeprom.SCAN_LIST_ENABLED[2] == 1)
tmp = tmp | (1 << 2);
if (gEeprom.SCAN_LIST_ENABLED[0] == 1) tmp |= 1 << 0;
if (gEeprom.SCAN_LIST_ENABLED[1] == 1) tmp |= 1 << 1;
if (gEeprom.SCAN_LIST_ENABLED[2] == 1) tmp |= 1 << 2;
State[2] = gEeprom.SCANLIST_PRIORITY_CH1[0];
State[3] = gEeprom.SCANLIST_PRIORITY_CH2[0];
State[4] = gEeprom.SCANLIST_PRIORITY_CH1[1];
Expand Down Expand Up @@ -665,16 +666,10 @@ void SETTINGS_SaveSettings(void)
memset(State, 0xFF, sizeof(State));

tmp = 0;

if(gSetting_set_inv == 1)
tmp = tmp | (1 << 0);
if (gSetting_set_lck == 1)
tmp = tmp | (1 << 1);
if (gSetting_set_met == 1)
tmp = tmp | (1 << 2);
if (gSetting_set_gui == 1)
tmp = tmp | (1 << 3);

if (gSetting_set_inv) tmp |= 1 << 0;
if (gSetting_set_lck) tmp |= 1 << 1;
if (gSetting_set_met) tmp |= 1 << 2;
if (gSetting_set_gui) tmp |= 1 << 3;
State[5] = ((tmp << 4) | (gSetting_set_ctr & 0x0F));
State[6] = ((gSetting_set_tot << 4) | (gSetting_set_eot & 0x0F));
State[7] = ((gSetting_set_low << 4) | (gSetting_set_ptt & 0x0F));
Expand Down
Loading
Loading