Skip to content

Commit

Permalink
Refactor, merge #186
Browse files Browse the repository at this point in the history
  • Loading branch information
JuantAldea authored and egzumer committed Dec 5, 2023
1 parent ed395ab commit 52bdd40
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 224 deletions.
25 changes: 7 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,15 @@ else # unix
endif

AS = arm-none-eabi-gcc

CC =
LD = arm-none-eabi-gcc

ifeq ($(ENABLE_CLANG),0)
CC += arm-none-eabi-gcc
CC = arm-none-eabi-gcc
# Use GCC's linker to avoid undefined symbol errors
# LD += arm-none-eabi-gcc
else
# May need to adjust this to match your system
CC += clang --sysroot=/usr/arm-none-eabi --target=arm-none-eabi
CC = clang --sysroot=/usr/arm-none-eabi --target=arm-none-eabi
# Bloats binaries to 512MB
# LD = ld.lld
endif
Expand All @@ -221,17 +219,18 @@ endif

CFLAGS =
ifeq ($(ENABLE_CLANG),0)
CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD
CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c2x -MMD
#CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD
#CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c99 -MMD
#CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=gnu99 -MMD
#CFLAGS += -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=gnu11 -MMD
else
# Oz needed to make it fit on flash
CFLAGS += -Oz -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD
CFLAGS += -Oz -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c2x -MMD
endif

ifeq ($(ENABLE_LTO),1)
CFLAGS += -flto=2
CFLAGS += -flto=auto
else
# We get most of the space savings if LTO creates problems
CFLAGS += -ffunction-sections -fdata-sections
Expand Down Expand Up @@ -366,21 +365,11 @@ ifeq ($(ENABLE_AGC_SHOW_DATA),1)
endif

LDFLAGS =
ifeq ($(ENABLE_CLANG),0)
LDFLAGS += -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld
else
# Fix warning about implied executable stack
LDFLAGS += -z noexecstack -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld
endif
LDFLAGS += -z noexecstack -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld -Wl,--gc-sections

# Use newlib-nano instead of newlib
LDFLAGS += --specs=nano.specs

ifeq ($(ENABLE_LTO),0)
# Throw away unneeded func/data sections like LTO does
LDFLAGS += -Wl,--gc-sections
endif

ifeq ($(DEBUG),1)
ASFLAGS += -g
CFLAGS += -g
Expand Down
165 changes: 68 additions & 97 deletions app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
void toggle_chan_scanlist(void)
{ // toggle the selected channels scanlist setting

if ( SCANNER_IsScanning())
if (SCANNER_IsScanning())
return;

if(!IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) {
Expand All @@ -55,20 +55,11 @@ void toggle_chan_scanlist(void)
#endif
return;
}

if (gTxVfo->SCANLIST1_PARTICIPATION)
{
if (gTxVfo->SCANLIST2_PARTICIPATION)
gTxVfo->SCANLIST1_PARTICIPATION = 0;
else
gTxVfo->SCANLIST2_PARTICIPATION = 1;
}
else
{
if (gTxVfo->SCANLIST2_PARTICIPATION)
gTxVfo->SCANLIST2_PARTICIPATION = 0;
else
gTxVfo->SCANLIST1_PARTICIPATION = 1;

if (gTxVfo->SCANLIST1_PARTICIPATION ^ gTxVfo->SCANLIST2_PARTICIPATION){
gTxVfo->SCANLIST2_PARTICIPATION = gTxVfo->SCANLIST1_PARTICIPATION;
} else {
gTxVfo->SCANLIST1_PARTICIPATION = !gTxVfo->SCANLIST1_PARTICIPATION;
}

SETTINGS_UpdateChannel(gTxVfo->CHANNEL_SAVE, gTxVfo, true);
Expand All @@ -79,7 +70,6 @@ void toggle_chan_scanlist(void)

static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
{
uint8_t Band;
uint8_t Vfo = gEeprom.TX_VFO;

if (gScreenToDisplay == DISPLAY_MENU)
Expand Down Expand Up @@ -113,69 +103,63 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;

#ifdef ENABLE_COPY_CHAN_TO_VFO
if (gEeprom.VFO_OPEN && !gCssBackgroundScan)
if (!gEeprom.VFO_OPEN || gCssBackgroundScan)
{
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}

if (gScanStateDir != SCAN_OFF)
{
if (gCurrentFunction != FUNCTION_INCOMING ||
gRxReceptionMode == RX_MODE_NONE ||
gScanPauseDelayIn_10ms == 0)
{ // scan is running (not paused)
return;
}
if (gScanStateDir != SCAN_OFF)
{
if (gCurrentFunction != FUNCTION_INCOMING ||
gRxReceptionMode == RX_MODE_NONE ||
gScanPauseDelayIn_10ms == 0)
{ // scan is running (not paused)
return;
}
}

const uint8_t vfo = gEeprom.TX_VFO;

if (IS_MR_CHANNEL(gEeprom.ScreenChannel[vfo]))
{ // copy channel to VFO, then swap to the VFO
const uint8_t vfo = gEeprom.TX_VFO;

const unsigned int channel = FREQ_CHANNEL_FIRST + gEeprom.VfoInfo[vfo].Band;
if (IS_MR_CHANNEL(gEeprom.ScreenChannel[vfo]))
{ // copy channel to VFO, then swap to the VFO

gEeprom.ScreenChannel[vfo] = channel;
gEeprom.VfoInfo[vfo].CHANNEL_SAVE = channel;
gEeprom.ScreenChannel[vfo] = FREQ_CHANNEL_FIRST + gEeprom.VfoInfo[vfo].Band;
gEeprom.VfoInfo[vfo].CHANNEL_SAVE = gEeprom.ScreenChannel[vfo];

RADIO_SelectVfos();
RADIO_ApplyOffset(gRxVfo);
RADIO_ConfigureSquelchAndOutputPower(gRxVfo);
RADIO_SetupRegisters(true);
RADIO_SelectVfos();
RADIO_ApplyOffset(gRxVfo);
RADIO_ConfigureSquelchAndOutputPower(gRxVfo);
RADIO_SetupRegisters(true);

//SETTINGS_SaveChannel(channel, gEeprom.RX_VFO, gRxVfo, 1);
//SETTINGS_SaveChannel(channel, gEeprom.RX_VFO, gRxVfo, 1);

gUpdateDisplay = true;
}
}
else
{
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
gUpdateDisplay = true;
}
#endif
return;
}

#ifdef ENABLE_WIDE_RX
if(gTxVfo->Band == 6 && gTxVfo->pRX->Frequency < 100000000) {
gTxVfo->pRX->Frequency = 100000000;
if(gTxVfo->Band == BAND7_470MHz && gTxVfo->pRX->Frequency < _1GHz_in_KHz) {
gTxVfo->pRX->Frequency = _1GHz_in_KHz;
return;
}
else
#endif
{
Band = gTxVfo->Band + 1;
if (gSetting_350EN || Band != BAND5_350MHz) {
if (Band > BAND7_470MHz)
Band = BAND1_50MHz;
}
else
Band = BAND6_400MHz;
#endif

gTxVfo->Band = Band;
gTxVfo->Band += 1;

gEeprom.ScreenChannel[Vfo] = FREQ_CHANNEL_FIRST + Band;
gEeprom.FreqChannel[Vfo] = FREQ_CHANNEL_FIRST + Band;
if (gTxVfo->Band == BAND5_350MHz && !gSetting_350EN) {
// skip if not enabled
gTxVfo->Band += 1;
} else if (gTxVfo->Band >= BAND_LAST_ELEMENT){
// go arround if overflowed
gTxVfo->Band = BAND1_50MHz;
}

gEeprom.ScreenChannel[Vfo] = FREQ_CHANNEL_FIRST + gTxVfo->Band;
gEeprom.FreqChannel[Vfo] = FREQ_CHANNEL_FIRST + gTxVfo->Band;

gRequestSaveVFO = true;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD;

Expand Down Expand Up @@ -335,8 +319,6 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // user is entering channel number

uint16_t Channel;

if (gInputBoxIndex != 3)
{
#ifdef ENABLE_VOICE
Expand All @@ -348,7 +330,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)

gInputBoxIndex = 0;

Channel = ((gInputBox[0] * 100) + (gInputBox[1] * 10) + gInputBox[2]) - 1;
const uint16_t Channel = ((gInputBox[0] * 100) + (gInputBox[1] * 10) + gInputBox[2]) - 1;

if (!RADIO_CheckValidChannel(Channel, false, 0))
{
Expand All @@ -374,19 +356,17 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // user is entering a frequency

uint32_t Frequency;
bool isGigaF = gTxVfo->pRX->Frequency >= 100000000;
#ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif
bool isGigaF = gTxVfo->pRX->Frequency >= _1GHz_in_KHz;
if (gInputBoxIndex < 6 + isGigaF)
{
#ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif

return;
}

gInputBoxIndex = 0;
Frequency = StrToUL(INPUTBOX_GetAscii()) * 100;
uint32_t Frequency = StrToUL(INPUTBOX_GetAscii()) * 100;

// clamp the frequency entered to some valid value
if (Frequency < frequencyBandTable[0].lower)
Expand All @@ -405,46 +385,37 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
Frequency = frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper;
}

{
const FREQUENCY_Band_t band = FREQUENCY_GetBand(Frequency);

#ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif
const FREQUENCY_Band_t band = FREQUENCY_GetBand(Frequency);

if (gTxVfo->Band != band)
{
gTxVfo->Band = band;
gEeprom.ScreenChannel[Vfo] = band + FREQ_CHANNEL_FIRST;
gEeprom.FreqChannel[Vfo] = band + FREQ_CHANNEL_FIRST;
if (gTxVfo->Band != band)
{
gTxVfo->Band = band;
gEeprom.ScreenChannel[Vfo] = band + FREQ_CHANNEL_FIRST;
gEeprom.FreqChannel[Vfo] = band + FREQ_CHANNEL_FIRST;

SETTINGS_SaveVfoIndices();
SETTINGS_SaveVfoIndices();

RADIO_ConfigureChannel(Vfo, VFO_CONFIGURE_RELOAD);
}
RADIO_ConfigureChannel(Vfo, VFO_CONFIGURE_RELOAD);
}

Frequency = FREQUENCY_RoundToStep(Frequency, gTxVfo->StepFrequency);
Frequency = FREQUENCY_RoundToStep(Frequency, gTxVfo->StepFrequency);

if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
{ // clamp the frequency to the limit
const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2;
Frequency = (Frequency < center) ? BX4819_band1.upper - gTxVfo->StepFrequency : BX4819_band2.lower;
}
if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
{ // clamp the frequency to the limit
const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2;
Frequency = (Frequency < center) ? BX4819_band1.upper - gTxVfo->StepFrequency : BX4819_band2.lower;
}

gTxVfo->freq_config_RX.Frequency = Frequency;
gTxVfo->freq_config_RX.Frequency = Frequency;

gRequestSaveChannel = 1;
return;
}
gRequestSaveChannel = 1;
return;

}
#ifdef ENABLE_NOAA
else
if (IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // user is entering NOAA channel

uint8_t Channel;

if (gInputBoxIndex != 2)
{
#ifdef ENABLE_VOICE
Expand All @@ -456,7 +427,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)

gInputBoxIndex = 0;

Channel = (gInputBox[0] * 10) + gInputBox[1];
uint8_t Channel = (gInputBox[0] * 10) + gInputBox[1];
if (Channel >= 1 && Channel <= ARRAY_SIZE(NoaaFrequencyTable))
{
Channel += NOAA_CHANNEL_FIRST;
Expand Down Expand Up @@ -586,7 +557,7 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)

if (!bKeyPressed && !gDTMF_InputMode)
{ // menu key released
const bool bFlag = (gInputBoxIndex == 0);
const bool bFlag = !gInputBoxIndex;
gInputBoxIndex = 0;

if (bFlag)
Expand Down
Loading

0 comments on commit 52bdd40

Please sign in to comment.