Skip to content

Commit

Permalink
Added menu battery calibration from egzumer (hidden menu option)
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfEleven committed Oct 1, 2023
1 parent a9aa37e commit 4333fde
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 84 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delet
#CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=gnu11 -MMD

ifeq ($(ENABLE_LTO),1)
CFLAGS += -flto
# CFLAGS += -flto
CFLAGS += -flto=2
endif

CFLAGS += -DPRINTF_INCLUDE_CONFIG_H
Expand Down
2 changes: 1 addition & 1 deletion app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2434,8 +2434,8 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)

if (gFlagRefreshSetting)
{
MENU_ShowCurrentSetting();
gFlagRefreshSetting = false;
MENU_ShowCurrentSetting();
}

if (gFlagStartScan)
Expand Down
5 changes: 4 additions & 1 deletion app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,11 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)

if (bFlag)
{
gFlagRefreshSetting = true;
gFlagRefreshSetting = true;
gFlagBackupSetting = true;

gRequestDisplayScreen = DISPLAY_MENU;

#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_MENU;
#endif
Expand Down
116 changes: 86 additions & 30 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "driver/gpio.h"
#include "driver/keyboard.h"
#include "frequencies.h"
#include "helper/battery.h"
#include "misc.h"
#include "settings.h"
#if defined(ENABLE_OVERLAY)
Expand All @@ -46,6 +47,27 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif

void writeXtalFreqCal(const int32_t value)
{
struct
{
int16_t BK4819_XtalFreqLow;
uint16_t EEPROM_1F8A;
uint16_t EEPROM_1F8C;
uint8_t VOLUME_GAIN;
uint8_t DAC_GAIN;
} __attribute__((packed)) Misc;

gEeprom.BK4819_XTAL_FREQ_LOW = value;
BK4819_WriteRegister(BK4819_REG_3B, 22656 + gEeprom.BK4819_XTAL_FREQ_LOW);

// radio 1 .. 04 00 46 00 50 00 2C 0E
// radio 2 .. 05 00 46 00 50 00 2C 0E
EEPROM_ReadBuffer(0x1F88, &Misc, 8);
Misc.BK4819_XtalFreqLow = gEeprom.BK4819_XTAL_FREQ_LOW;
EEPROM_WriteBuffer(0x1F88, &Misc);
}

void MENU_StartCssScan(int8_t Direction)
{
gCssScanMode = CSS_SCAN_MODE_SCANNING;
Expand Down Expand Up @@ -268,6 +290,11 @@ int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax)
*pMax = ARRAY_SIZE(gSubMenu_PTT_ID) - 1;
break;

case MENU_VOL:
*pMin = 1760; // 0
*pMax = 2000; // 2300
break;

case MENU_BAT_TXT:
*pMin = 0;
*pMax = ARRAY_SIZE(gSubMenu_BAT_TXT) - 1;
Expand Down Expand Up @@ -546,7 +573,7 @@ void MENU_AcceptSetting(void)
gSetting_mic_bar = gSubMenuSelection;
break;
#endif

#ifdef ENABLE_COMPANDER
case MENU_COMPAND:
gTxVfo->Compander = gSubMenuSelection;
Expand Down Expand Up @@ -589,6 +616,11 @@ void MENU_AcceptSetting(void)
gRequestSaveChannel = 1;
return;

case MENU_VOL:
if (gF_LOCK)
EEPROM_WriteBuffer(0x1F40, gBatteryCalibration);
break;

case MENU_BAT_TXT:
gSetting_battery_text = gSubMenuSelection;
break;
Expand Down Expand Up @@ -699,24 +731,8 @@ void MENU_AcceptSetting(void)
break;

case MENU_F_CALI:
gEeprom.BK4819_XTAL_FREQ_LOW = gSubMenuSelection;
BK4819_WriteRegister(BK4819_REG_3B, 22656 + gEeprom.BK4819_XTAL_FREQ_LOW);
{
struct
{
int16_t BK4819_XtalFreqLow;
uint16_t EEPROM_1F8A;
uint16_t EEPROM_1F8C;
uint8_t VOLUME_GAIN;
uint8_t DAC_GAIN;
} __attribute__((packed)) Misc;

// radio 1 .. 04 00 46 00 50 00 2C 0E
// radio 2 .. 05 00 46 00 50 00 2C 0E
EEPROM_ReadBuffer(0x1F88, &Misc, 8);
Misc.BK4819_XtalFreqLow = gEeprom.BK4819_XTAL_FREQ_LOW;
EEPROM_WriteBuffer(0x1F88, &Misc);
}
if (gF_LOCK)
writeXtalFreqCal(gSubMenuSelection);
return;
}

Expand Down Expand Up @@ -944,7 +960,7 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gSetting_mic_bar;
break;
#endif

#ifdef ENABLE_COMPANDER
case MENU_COMPAND:
gSubMenuSelection = gTxVfo->Compander;
Expand Down Expand Up @@ -993,6 +1009,10 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gTxVfo->DTMF_PTT_ID_TX_MODE;
break;

case MENU_VOL:
gSubMenuSelection = gBatteryCalibration[3];
return;

case MENU_BAT_TXT:
gSubMenuSelection = gSetting_battery_text;
return;
Expand Down Expand Up @@ -1026,7 +1046,7 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gSetting_AM_fix;
break;
#endif

#ifdef ENABLE_AM_FIX_TEST1
case MENU_AM_FIX_TEST1:
gSubMenuSelection = gSetting_AM_fix_test1;
Expand Down Expand Up @@ -1079,6 +1099,12 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gEeprom.BK4819_XTAL_FREQ_LOW;
break;
}

// if (gFlagBackupSetting)
{ // save a copy incase the user wants to back out
// gFlagBackupSetting = false;
gSubMenuSelection_original = gSubMenuSelection;
}
}

static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
Expand Down Expand Up @@ -1127,11 +1153,12 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gInputBoxIndex = 0;

Value = (gInputBox[0] * 10) + gInputBox[1];

if (Value > 0 && Value <= gMenuListCount)
{
gMenuCursor = Value - 1;
gFlagRefreshSetting = true;
gFlagBackupSetting = true;
return;
}

Expand All @@ -1140,13 +1167,14 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)

gInputBox[0] = gInputBox[1];
gInputBoxIndex = 1;

case 1:
Value = gInputBox[0];
if (Value > 0 && Value <= gMenuListCount)
{
gMenuCursor = Value - 1;
gFlagRefreshSetting = true;
gFlagBackupSetting = true;
return;
}
break;
Expand Down Expand Up @@ -1255,6 +1283,29 @@ static void MENU_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
{
if (gIsInSubMenu)
{
// ***********************
// restore original value

if (gMenuCursor == MENU_VOL)
{
if (gF_LOCK)
{
EEPROM_ReadBuffer(0x1F40, gBatteryCalibration, 8);

// gBatteryCalibration[3] = gSubMenuSelection_original;

BATTERY_GetReadings(true);
}
}
else
if (gMenuCursor == MENU_F_CALI)
{
// if (gF_LOCK)
// writeXtalFreqCal(gSubMenuSelection_original);
}

// ***********************

if (gInputBoxIndex == 0 || gMenuCursor != MENU_OFFSET)
{
gAskForConfirmation = 0;
Expand All @@ -1269,6 +1320,8 @@ static void MENU_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
else
gInputBox[--gInputBoxIndex] = 10;

// ***********************

gRequestDisplayScreen = DISPLAY_MENU;
return;
}
Expand All @@ -1278,7 +1331,7 @@ static void MENU_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
#endif

gRequestDisplayScreen = DISPLAY_MAIN;

if (gEeprom.BACKLIGHT == 0)
{
gBacklightCountdown = 0;
Expand Down Expand Up @@ -1322,13 +1375,13 @@ static void MENU_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)

gAskForConfirmation = 0;
gIsInSubMenu = true;

// if (gMenuCursor != MENU_D_LIST)
{
gInputBoxIndex = 0;
edit_index = -1;
}

return;
}

Expand Down Expand Up @@ -1554,16 +1607,19 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)

if (!gIsInSubMenu)
{
gMenuCursor = NUMBER_AddWithWraparound(gMenuCursor, -Direction, 0, gMenuListCount - 1);
gFlagRefreshSetting = true;
gMenuCursor = NUMBER_AddWithWraparound(gMenuCursor, -Direction, 0, gMenuListCount - 1);

gFlagRefreshSetting = true;
gFlagBackupSetting = true;

gRequestDisplayScreen = DISPLAY_MENU;

if (gMenuCursor != MENU_ABR && gEeprom.BACKLIGHT == 0)
{
gBacklightCountdown = 0;
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF
}

return;
}

Expand Down Expand Up @@ -1599,7 +1655,7 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
bCheckScanList = true;
break;

default:
default:
MENU_ClampSelection(Direction);
gRequestDisplayScreen = DISPLAY_MENU;
return;
Expand Down
Binary file modified firmware.bin
Binary file not shown.
Binary file modified firmware.packed.bin
Binary file not shown.
2 changes: 0 additions & 2 deletions helper/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ BOOT_Mode_t BOOT_GetMode(void)
{
if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT))
return BOOT_MODE_NORMAL; // PTT not pressed

Keys[i] = KEYBOARD_Poll();

SYSTEM_DelayMs(20);
}

Expand Down
33 changes: 16 additions & 17 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,21 @@ void Main(void)
#endif

BootMode = BOOT_GetMode();
if (BootMode == BOOT_MODE_F_LOCK)
{ // enable all the menu items
gMenuListCount = 0;
while (MenuList[gMenuListCount].name[0] != '\0')
gMenuListCount++;

gSubMenuSelection = gSetting_350TX;
gMenuCursor = MENU_350TX;
}
else
{ // hide the hidden menu items
gMenuListCount = 0;
while (MenuList[gMenuListCount].name[0] != '\0')
gMenuListCount++;
gMenuListCount -= 8; // disable the last 'n' items
}
// count the number of menu items
gMenuListCount = 0;
while (MenuList[gMenuListCount].name[0] != '\0')
gMenuListCount++;

// wait for user to release all keys/butts before moving on
if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) || KEYBOARD_Poll() != KEY_INVALID)
if (BootMode == BOOT_MODE_F_LOCK)
gF_LOCK = true; // flag to say use the hidden menu items
else
gMenuListCount -= 8; // hide the last few menu items

// wait for user to release all butts before moving on
if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) ||
KEYBOARD_Poll() != KEY_INVALID ||
BootMode != BOOT_MODE_NORMAL)
{ // keys are pressed
UI_DisplayReleaseKeys();
BACKLIGHT_TurnOn();
Expand All @@ -131,6 +127,9 @@ void Main(void)
i = (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) && KEYBOARD_Poll() == KEY_INVALID) ? i + 1 : 0;
SYSTEM_DelayMs(10);
}
gKeyReading0 = KEY_INVALID;
gKeyReading1 = KEY_INVALID;
gDebounceCounter = 0;
}

if (!gChargingWithTypeC && !gBatteryDisplayLevel)
Expand Down
5 changes: 5 additions & 0 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,11 @@ bool gRequestSaveSettings;
bool gRequestSaveFM;
#endif
bool gFlagPrepareTX;

bool gFlagAcceptSetting;
bool gFlagRefreshSetting;
bool gFlagBackupSetting;

bool gFlagSaveVfo;
bool gFlagSaveSettings;
bool gFlagSaveChannel;
Expand Down Expand Up @@ -217,6 +220,8 @@ uint8_t gNeverUsed;

bool gUpdateDisplay;

bool gF_LOCK = false;

uint8_t gShowChPrefix;

volatile bool gNextTimeslice;
Expand Down
8 changes: 6 additions & 2 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,11 @@ extern bool gRequestSaveSettings;
#endif
extern uint8_t gKeypadLocked;
extern bool gFlagPrepareTX;
extern bool gFlagAcceptSetting;
extern bool gFlagRefreshSetting;

extern bool gFlagAcceptSetting; // accept menu setting
extern bool gFlagRefreshSetting; // refresh menu display
extern bool gFlagBackupSetting; // save a copy of the current menu setting

extern bool gFlagSaveVfo;
extern bool gFlagSaveSettings;
extern bool gFlagSaveChannel;
Expand Down Expand Up @@ -277,6 +280,7 @@ extern uint8_t gNeverUsed;
#endif
extern volatile bool gNextTimeslice;
extern bool gUpdateDisplay;
extern bool gF_LOCK;
#ifdef ENABLE_FMRADIO
extern uint8_t gFM_ChannelPosition;
#endif
Expand Down
Loading

0 comments on commit 4333fde

Please sign in to comment.