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

ENABLE_ALT_CHANNELS option #471

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ ENABLE_REDUCE_LOW_MID_TX_POWER?= 0
ENABLE_BYP_RAW_DEMODULATORS ?= 0
ENABLE_BLMIN_TMP_OFF ?= 0
ENABLE_SCAN_RANGES ?= 1
ENABLE_ALT_CHANNELS ?= 0

# ---- DEBUGGING ----
ENABLE_AM_FIX_SHOW_DATA ?= 0
Expand Down Expand Up @@ -377,6 +378,9 @@ endif
ifeq ($(ENABLE_CUSTOM_MENU_LAYOUT),1)
CFLAGS += -DENABLE_CUSTOM_MENU_LAYOUT
endif
ifeq ($(ENABLE_ALT_CHANNELS),1)
CFLAGS += -DENABLE_ALT_CHANNELS
endif

LDFLAGS =
LDFLAGS += -z noexecstack -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld -Wl,--gc-sections
Expand Down
2 changes: 1 addition & 1 deletion app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ static void HandleReceive(void)
goto Skip;
}

if (gScanStateDir != SCAN_OFF && IS_FREQ_CHANNEL(gNextMrChannel)) { // we are scanning in the frequency mode
if (gScanStateDir != SCAN_OFF && IS_VFO_CHANNEL(gNextMrChannel)) { // we are scanning in the frequency mode
if (g_SquelchLost)
return;

Expand Down
2 changes: 1 addition & 1 deletion app/chFrScanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void CHFRSCANNER_Start(const bool storeBackupSettings, const int8_t scan_directi

void CHFRSCANNER_ContinueScanning(void)
{
if (IS_FREQ_CHANNEL(gNextMrChannel))
if (IS_VFO_CHANNEL(gNextMrChannel))
{
if (gCurrentFunction == FUNCTION_INCOMING)
APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE);
Expand Down
2 changes: 1 addition & 1 deletion app/dtmf.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ bool DTMF_GetContact(const int Index, char *pContact)
return false;
}

EEPROM_ReadBuffer(0x1C00 + (Index * 16), pContact, 16);
EEPROM_ReadBuffer(EEPROM_DTMF_CONTACT_OFF + (Index * 16), pContact, 16);

// check whether the first character is printable or not
return (pContact[0] >= ' ' && pContact[0] < 127);
Expand Down
24 changes: 12 additions & 12 deletions app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
break;

case KEY_1:
if (!IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) {
if (!IS_VFO_CHANNEL(gTxVfo->CHANNEL_SAVE)) {
gWasFKeyPressed = false;
gUpdateStatus = true;
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
Expand All @@ -115,7 +115,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
if (IS_MR_CHANNEL(gEeprom.ScreenChannel[vfo]))
{ // copy channel to VFO, then swap to the VFO

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

RADIO_SelectVfos();
Expand Down Expand Up @@ -147,8 +147,8 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
gTxVfo->Band = BAND1_50MHz;
}

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

gRequestSaveVFO = true;
gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
Expand Down Expand Up @@ -325,7 +325,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
// #ifdef ENABLE_NOAA
// if (!IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE))
// #endif
if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE))
if (IS_VFO_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // user is entering a frequency

#ifdef ENABLE_VOICE
Expand Down Expand Up @@ -355,8 +355,8 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)

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

SETTINGS_SaveVfoIndices();

Expand Down Expand Up @@ -600,14 +600,14 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld)

static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
{
uint8_t Channel = gEeprom.ScreenChannel[gEeprom.TX_VFO];
channel_t Channel = gEeprom.ScreenChannel[gEeprom.TX_VFO];

if (bKeyHeld || !bKeyPressed) { // key held or released
if (gInputBoxIndex > 0)
return; // leave if input box active

if (!bKeyPressed) {
if (!bKeyHeld || IS_FREQ_CHANNEL(Channel))
if (!bKeyHeld || IS_VFO_CHANNEL(Channel))
return;
// if released long button press and not in freq mode
#ifdef ENABLE_VOICE
Expand All @@ -630,8 +630,8 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
if (!IS_NOAA_CHANNEL(Channel))
#endif
{
uint8_t Next;
if (IS_FREQ_CHANNEL(Channel)) { // step/down in frequency
channel_t Next;
if (IS_VFO_CHANNEL(Channel)) { // step/down in frequency
const uint32_t frequency = APP_SetFrequencyByStep(gTxVfo, Direction);

if (RX_freq_check(frequency) < 0) { // frequency not allowed
Expand All @@ -646,7 +646,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
}

Next = RADIO_FindNextChannel(Channel + Direction, Direction, false, 0);
if (Next == 0xFF)
if (Next == MAX_CHANNEL)
return;
if (Channel == Next)
return;
Expand Down
4 changes: 2 additions & 2 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void MENU_AcceptSetting(void)

case MENU_STEP:
gTxVfo->STEP_SETTING = FREQUENCY_GetStepIdxFromSortedIdx(gSubMenuSelection);
if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE))
if (IS_VFO_CHANNEL(gTxVfo->CHANNEL_SAVE))
{
gRequestSaveChannel = 1;
return;
Expand Down Expand Up @@ -1166,7 +1166,7 @@ void MENU_ShowCurrentSetting(void)

static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{
uint8_t Offset;
channel_t Offset;
int32_t Min;
int32_t Max;
uint16_t Value = 0;
Expand Down
4 changes: 2 additions & 2 deletions app/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ static void SCANNER_Key_MENU(bool bKeyPressed, bool bKeyHeld)
gEeprom.MrChannel[gEeprom.TX_VFO] = chan;
}
else {
chan = gTxVfo->Band + FREQ_CHANNEL_FIRST;
chan = gTxVfo->Band + VFO_CHANNEL_FIRST;
gEeprom.FreqChannel[gEeprom.TX_VFO] = chan;
}

Expand Down Expand Up @@ -310,7 +310,7 @@ void SCANNER_Start(bool singleFreq)

#ifdef ENABLE_NOAA
if (IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE))
gRxVfo->CHANNEL_SAVE = FREQ_CHANNEL_FIRST + BAND6_400MHz;
gRxVfo->CHANNEL_SAVE = VFO_CHANNEL_FIRST + BAND6_400MHz;
#endif

uint8_t backupStep = gRxVfo->STEP_SETTING;
Expand Down
3 changes: 2 additions & 1 deletion driver/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "driver/eeprom.h"
#include "driver/i2c.h"
#include "driver/system.h"
#include "misc.h"

void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size)
{
Expand All @@ -41,7 +42,7 @@ void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size)

void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer)
{
if (pBuffer == NULL || Address >= 0x2000)
if (pBuffer == NULL || Address >= EEPROM_SIZE)
return;


Expand Down
2 changes: 1 addition & 1 deletion helper/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void BOOT_ProcessMode(BOOT_Mode_t Mode)
gEeprom.KEY_2_LONG_PRESS_ACTION = ACTION_OPT_NONE;
gEeprom.KEY_M_LONG_PRESS_ACTION = ACTION_OPT_NONE;

RADIO_InitInfo(gRxVfo, FREQ_CHANNEL_LAST - 1, 41002500);
RADIO_InitInfo(gRxVfo, VFO_CHANNEL_LAST - 1, 41002500);

gRxVfo->CHANNEL_BANDWIDTH = BANDWIDTH_WIDE;
gRxVfo->OUTPUT_POWER = OUTPUT_POWER_LOW;
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void Main(void)
AUDIO_SetVoiceID(1, VOICE_ID_CHANNEL_MODE);
AUDIO_SetDigitVoice(2, Channel + 1);
}
else if (IS_FREQ_CHANNEL(Channel))
else if (IS_VFO_CHANNEL(Channel))
AUDIO_SetVoiceID(1, VOICE_ID_FREQUENCY_MODE);

AUDIO_PlaySingleVoice(0);
Expand Down
2 changes: 1 addition & 1 deletion misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ uint16_t gEEPROM_RSSI_CALIB[7][4];
uint16_t gEEPROM_1F8A;
uint16_t gEEPROM_1F8C;

ChannelAttributes_t gMR_ChannelAttributes[FREQ_CHANNEL_LAST + 1];
ChannelAttributes_t gMR_ChannelAttributes[ALL_CHANNELS_COUNT];

volatile uint16_t gBatterySaveCountdown_10ms = battery_save_count_10ms;

Expand Down
103 changes: 99 additions & 4 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,114 @@
#endif

#define IS_MR_CHANNEL(x) ((x) <= MR_CHANNEL_LAST)
#define IS_FREQ_CHANNEL(x) ((x) >= FREQ_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 (emulated) VFOs (variable frequency oscillator) in this radio.

There is a memory mode, and frequency mode, so MR_CHANNEL or FREQ_CHANNEL

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!
Will revert to FREQ in the next commit. Just need to finish the chirp driver to be sure everything is in sync and working as expected.

#define IS_VFO_CHANNEL(x) ((x) >= VFO_CHANNEL_FIRST && (x) <= VFO_CHANNEL_LAST)
#define IS_VALID_CHANNEL(x) ((x) < LAST_CHANNEL)
#define IS_NOAA_CHANNEL(x) ((x) >= NOAA_CHANNEL_FIRST && (x) <= NOAA_CHANNEL_LAST)

#ifdef ENABLE_ALT_CHANNELS
typedef uint16_t channel_t;

#define EEPROM_SIZE 0xFFFF //Exact size is 0x10000 but the ckecs are "gret or equal" so a bit off to fit in 2 bytes looks like ok
#define VFO_CHANNELS_COUNT 7 // VFO in each freq band is like a "system channel"
#define FM_CHANNELS_COUNT 20 // are these NOAA? no clue, but let's define them in a constant here
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are not NOAA, these are FM broadcast radio channels. You don't need that for your modification.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Entire NOAA is confusing me, but I think with hints from the chirp driver more pieces fit in place.

#define MR_CHANNELS_COUNT 999
#define MAX_CHANNEL 0xffff // a mask defining ceil of two bytes
#define ALL_CHANNELS_COUNT (VFO_CHANNELS_COUNT + FM_CHANNELS_COUNT + MR_CHANNELS_COUNT)

#define EEPROM_MR_FREQ_OFF 0x2000 // Start of the channel relocation
#define EEPROM_MR_FREQ_LEN (MR_CHANNELS_COUNT * 16)

#define EEPROM_MR_ATTR_OFF (EEPROM_MR_FREQ_OFF + EEPROM_MR_FREQ_LEN)
#define EEPROM_MR_ATTR_LEN (MR_CHANNELS_COUNT)

#define EEPROM_VFO_ATTR_OFF (EEPROM_MR_ATTR_OFF + EEPROM_MR_ATTR_LEN)
#define EEPROM_VFO_ATTR_LEN (VFO_CHANNELS_COUNT)

#define EEPROM_MR_SETTINGS_OFF (EEPROM_VFO_ATTR_OFF + EEPROM_VFO_ATTR_LEN) // Screen CH A, MR CH A, Freq CH A, Screen CH B, MR CH B, Freq CH B, NOAA CH A, NOAA CH B
#define EEPROM_MR_SETTINGS_LEN 0x0010

#define EEPROM_MR_NAME_OFF (EEPROM_MR_SETTINGS_OFF + EEPROM_MR_SETTINGS_LEN)
#define EEPROM_MR_NAME_LEN (EEPROM_MR_FREQ_LEN)
#define EEPROM_LAST (EEPROM_MR_NAME_OFF + EEPROM_MR_NAME_LEN)
static const uint16_t MR_CHANNEL_FIRST = 0;
static const uint16_t MR_CHANNEL_LAST = (MR_CHANNELS_COUNT - 1);
static const uint16_t VFO_CHANNEL_FIRST = MR_CHANNELS_COUNT;
static const uint16_t VFO_CHANNEL_LAST = (MR_CHANNELS_COUNT + VFO_CHANNELS_COUNT - 1);
static const uint16_t NOAA_CHANNEL_FIRST = (MR_CHANNELS_COUNT + VFO_CHANNELS_COUNT);
static const uint16_t NOAA_CHANNEL_LAST = (MR_CHANNELS_COUNT + VFO_CHANNELS_COUNT + FM_CHANNELS_COUNT -1);
static const uint16_t LAST_CHANNEL = (MR_CHANNELS_COUNT + VFO_CHANNELS_COUNT + FM_CHANNELS_COUNT);
#else
typedef uint8_t channel_t;

#define EEPROM_SIZE 0x2000
#define VFO_CHANNELS_COUNT 7
#define FM_CHANNELS_COUNT 20
#define MR_CHANNELS_COUNT 200
#define MAX_CHANNEL 0xff
#define ALL_CHANNELS_COUNT (VFO_CHANNELS_COUNT + FM_CHANNELS_COUNT + MR_CHANNELS_COUNT)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong, you add FM channels, together you get 227, should be 207

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!
The FM channels are counted elsewhere.


#define EEPROM_MR_FREQ_OFF 0x0000
#define EEPROM_MR_FREQ_LEN 0x0C80

#define EEPROM_MR_ATTR_OFF 0x0D60
#define EEPROM_MR_ATTR_LEN 0x00C8

#define EEPROM_VFO_ATTR_OFF 0x0E28
#define EEPROM_VFO_ATTR_LEN 0x0007

#define EEPROM_MR_SETTINGS_OFF 0x0E80
#define EEPROM_MR_SETTINGS_LEN 0x0008

#define EEPROM_MR_NAME_OFF 0x0F50
#define EEPROM_MR_NAME_LEN 0x0C80
#endif // ENABLE_ALT_CHANNELS

#define EEPROM_VFO_FREQ_OFF 0x0C80
#define EEPROM_VFO_FREQ_LEN 0x00E0

#define EEPROM_FM_CHANNELS_OFF 0x0E40
#define EEPROM_FM_CHANNELS_LEN 0x0028

#define EEPROM_OPTIONS_0E70_OFF 0x0E70
#define EEPROM_OPTIONS_0E70_LEN 0x0008

#define EEPROM_OPTIONS_0E78_OFF 0x0E78
#define EEPROM_OPTIONS_0E78_LEN 0x0008

#define EEPROM_FM_CH_SETTINGS_OFF 0x0E88
#define EEPROM_FM_CH_SETTINGS_LEN 0x0003

#define EEPROM_WELCOME_STR1_OFF 0x0EB0
#define EEPROM_WELCOME_STR1_LEN 0x0010
#define EEPROM_WELCOME_STR2_OFF 0x0EC0
#define EEPROM_WELCOME_STR2_LEN 0x0010

#define EEPROM_CODE_OPTIONS_OFF 0x0ED0
#define EEPROM_CODE_OPTIONS_LEN 0x000B
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lengths in this section are not needed, they are not use anywhere

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My intentions is to have hints for the expected size, even not used in the code...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitions are seen everywhere in the code and shown in IDE hints, it doesn't help.


#define EEPROM_DTMF_ANI_ID_OFF 0x0EE0
#define EEPROM_DTMF_ANI_ID_LEN 0x0038

#define EEPROM_SCAN_LIST_OFF 0x0F18
#define EEPROM_SCAN_LIST_LEN 0x0018

#define EEPROM_AES_KEY_OFF 0x0F30
#define EEPROM_AES_KEY_LEN 0x0010

#define EEPROM_DTMF_CONTACT_OFF 0x1C00
#define EEPROM_DTMF_CONTACT_LEN 0x0100

#ifndef ENABLE_ALT_CHANNELS
enum {
MR_CHANNEL_FIRST = 0,
MR_CHANNEL_LAST = 199u,
FREQ_CHANNEL_FIRST = 200u,
FREQ_CHANNEL_LAST = 206u,
VFO_CHANNEL_FIRST = 200u,
VFO_CHANNEL_LAST = 206u,
NOAA_CHANNEL_FIRST = 207u,
NOAA_CHANNEL_LAST = 216u,
LAST_CHANNEL
};
#endif

enum {
VFO_CONFIGURE_NONE = 0,
Expand Down Expand Up @@ -186,7 +281,7 @@ typedef union {
uint8_t __val;
} ChannelAttributes_t;

extern ChannelAttributes_t gMR_ChannelAttributes[207];
extern ChannelAttributes_t gMR_ChannelAttributes[ALL_CHANNELS_COUNT];

extern volatile uint16_t gBatterySaveCountdown_10ms;

Expand Down
Loading