0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 14:21:25 +03:00

Added menu battery calibration from egzumer (hidden menu option)

This commit is contained in:
OneOfEleven 2023-10-02 00:38:59 +01:00
parent a9aa37e043
commit 4333fdeb3a
12 changed files with 150 additions and 84 deletions

View File

@ -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 #CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=gnu11 -MMD
ifeq ($(ENABLE_LTO),1) ifeq ($(ENABLE_LTO),1)
CFLAGS += -flto # CFLAGS += -flto
CFLAGS += -flto=2
endif endif
CFLAGS += -DPRINTF_INCLUDE_CONFIG_H CFLAGS += -DPRINTF_INCLUDE_CONFIG_H

View File

@ -2434,8 +2434,8 @@ Skip:
if (gFlagRefreshSetting) if (gFlagRefreshSetting)
{ {
MENU_ShowCurrentSetting();
gFlagRefreshSetting = false; gFlagRefreshSetting = false;
MENU_ShowCurrentSetting();
} }
if (gFlagStartScan) if (gFlagStartScan)

View File

@ -597,7 +597,10 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
if (bFlag) if (bFlag)
{ {
gFlagRefreshSetting = true; gFlagRefreshSetting = true;
gFlagBackupSetting = true;
gRequestDisplayScreen = DISPLAY_MENU; gRequestDisplayScreen = DISPLAY_MENU;
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_MENU; gAnotherVoiceID = VOICE_ID_MENU;
#endif #endif

View File

@ -32,6 +32,7 @@
#include "driver/gpio.h" #include "driver/gpio.h"
#include "driver/keyboard.h" #include "driver/keyboard.h"
#include "frequencies.h" #include "frequencies.h"
#include "helper/battery.h"
#include "misc.h" #include "misc.h"
#include "settings.h" #include "settings.h"
#if defined(ENABLE_OVERLAY) #if defined(ENABLE_OVERLAY)
@ -46,6 +47,27 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif #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) void MENU_StartCssScan(int8_t Direction)
{ {
gCssScanMode = CSS_SCAN_MODE_SCANNING; gCssScanMode = CSS_SCAN_MODE_SCANNING;
@ -268,6 +290,11 @@ int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax)
*pMax = ARRAY_SIZE(gSubMenu_PTT_ID) - 1; *pMax = ARRAY_SIZE(gSubMenu_PTT_ID) - 1;
break; break;
case MENU_VOL:
*pMin = 1760; // 0
*pMax = 2000; // 2300
break;
case MENU_BAT_TXT: case MENU_BAT_TXT:
*pMin = 0; *pMin = 0;
*pMax = ARRAY_SIZE(gSubMenu_BAT_TXT) - 1; *pMax = ARRAY_SIZE(gSubMenu_BAT_TXT) - 1;
@ -589,6 +616,11 @@ void MENU_AcceptSetting(void)
gRequestSaveChannel = 1; gRequestSaveChannel = 1;
return; return;
case MENU_VOL:
if (gF_LOCK)
EEPROM_WriteBuffer(0x1F40, gBatteryCalibration);
break;
case MENU_BAT_TXT: case MENU_BAT_TXT:
gSetting_battery_text = gSubMenuSelection; gSetting_battery_text = gSubMenuSelection;
break; break;
@ -699,24 +731,8 @@ void MENU_AcceptSetting(void)
break; break;
case MENU_F_CALI: case MENU_F_CALI:
gEeprom.BK4819_XTAL_FREQ_LOW = gSubMenuSelection; if (gF_LOCK)
BK4819_WriteRegister(BK4819_REG_3B, 22656 + gEeprom.BK4819_XTAL_FREQ_LOW); writeXtalFreqCal(gSubMenuSelection);
{
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);
}
return; return;
} }
@ -993,6 +1009,10 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gTxVfo->DTMF_PTT_ID_TX_MODE; gSubMenuSelection = gTxVfo->DTMF_PTT_ID_TX_MODE;
break; break;
case MENU_VOL:
gSubMenuSelection = gBatteryCalibration[3];
return;
case MENU_BAT_TXT: case MENU_BAT_TXT:
gSubMenuSelection = gSetting_battery_text; gSubMenuSelection = gSetting_battery_text;
return; return;
@ -1079,6 +1099,12 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gEeprom.BK4819_XTAL_FREQ_LOW; gSubMenuSelection = gEeprom.BK4819_XTAL_FREQ_LOW;
break; 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) static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
@ -1132,6 +1158,7 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{ {
gMenuCursor = Value - 1; gMenuCursor = Value - 1;
gFlagRefreshSetting = true; gFlagRefreshSetting = true;
gFlagBackupSetting = true;
return; return;
} }
@ -1147,6 +1174,7 @@ static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{ {
gMenuCursor = Value - 1; gMenuCursor = Value - 1;
gFlagRefreshSetting = true; gFlagRefreshSetting = true;
gFlagBackupSetting = true;
return; return;
} }
break; break;
@ -1255,6 +1283,29 @@ static void MENU_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
{ {
if (gIsInSubMenu) 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) if (gInputBoxIndex == 0 || gMenuCursor != MENU_OFFSET)
{ {
gAskForConfirmation = 0; gAskForConfirmation = 0;
@ -1269,6 +1320,8 @@ static void MENU_Key_EXIT(bool bKeyPressed, bool bKeyHeld)
else else
gInputBox[--gInputBoxIndex] = 10; gInputBox[--gInputBoxIndex] = 10;
// ***********************
gRequestDisplayScreen = DISPLAY_MENU; gRequestDisplayScreen = DISPLAY_MENU;
return; return;
} }
@ -1555,7 +1608,10 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
if (!gIsInSubMenu) if (!gIsInSubMenu)
{ {
gMenuCursor = NUMBER_AddWithWraparound(gMenuCursor, -Direction, 0, gMenuListCount - 1); gMenuCursor = NUMBER_AddWithWraparound(gMenuCursor, -Direction, 0, gMenuListCount - 1);
gFlagRefreshSetting = true; gFlagRefreshSetting = true;
gFlagBackupSetting = true;
gRequestDisplayScreen = DISPLAY_MENU; gRequestDisplayScreen = DISPLAY_MENU;
if (gMenuCursor != MENU_ABR && gEeprom.BACKLIGHT == 0) if (gMenuCursor != MENU_ABR && gEeprom.BACKLIGHT == 0)

Binary file not shown.

Binary file not shown.

View File

@ -40,9 +40,7 @@ BOOT_Mode_t BOOT_GetMode(void)
{ {
if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT)) if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT))
return BOOT_MODE_NORMAL; // PTT not pressed return BOOT_MODE_NORMAL; // PTT not pressed
Keys[i] = KEYBOARD_Poll(); Keys[i] = KEYBOARD_Poll();
SYSTEM_DelayMs(20); SYSTEM_DelayMs(20);
} }

31
main.c
View File

@ -103,25 +103,21 @@ void Main(void)
#endif #endif
BootMode = BOOT_GetMode(); BootMode = BOOT_GetMode();
// count the number of menu items
gMenuListCount = 0;
while (MenuList[gMenuListCount].name[0] != '\0')
gMenuListCount++;
if (BootMode == BOOT_MODE_F_LOCK) if (BootMode == BOOT_MODE_F_LOCK)
{ // enable all the menu items gF_LOCK = true; // flag to say use the hidden menu items
gMenuListCount = 0;
while (MenuList[gMenuListCount].name[0] != '\0')
gMenuListCount++;
gSubMenuSelection = gSetting_350TX;
gMenuCursor = MENU_350TX;
}
else else
{ // hide the hidden menu items gMenuListCount -= 8; // hide the last few menu items
gMenuListCount = 0;
while (MenuList[gMenuListCount].name[0] != '\0')
gMenuListCount++;
gMenuListCount -= 8; // disable the last 'n' items
}
// wait for user to release all keys/butts before moving on // wait for user to release all butts before moving on
if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) || KEYBOARD_Poll() != KEY_INVALID) if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) ||
KEYBOARD_Poll() != KEY_INVALID ||
BootMode != BOOT_MODE_NORMAL)
{ // keys are pressed { // keys are pressed
UI_DisplayReleaseKeys(); UI_DisplayReleaseKeys();
BACKLIGHT_TurnOn(); BACKLIGHT_TurnOn();
@ -131,6 +127,9 @@ void Main(void)
i = (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) && KEYBOARD_Poll() == KEY_INVALID) ? i + 1 : 0; i = (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT) && KEYBOARD_Poll() == KEY_INVALID) ? i + 1 : 0;
SYSTEM_DelayMs(10); SYSTEM_DelayMs(10);
} }
gKeyReading0 = KEY_INVALID;
gKeyReading1 = KEY_INVALID;
gDebounceCounter = 0;
} }
if (!gChargingWithTypeC && !gBatteryDisplayLevel) if (!gChargingWithTypeC && !gBatteryDisplayLevel)

5
misc.c
View File

@ -166,8 +166,11 @@ bool gRequestSaveSettings;
bool gRequestSaveFM; bool gRequestSaveFM;
#endif #endif
bool gFlagPrepareTX; bool gFlagPrepareTX;
bool gFlagAcceptSetting; bool gFlagAcceptSetting;
bool gFlagRefreshSetting; bool gFlagRefreshSetting;
bool gFlagBackupSetting;
bool gFlagSaveVfo; bool gFlagSaveVfo;
bool gFlagSaveSettings; bool gFlagSaveSettings;
bool gFlagSaveChannel; bool gFlagSaveChannel;
@ -217,6 +220,8 @@ uint8_t gNeverUsed;
bool gUpdateDisplay; bool gUpdateDisplay;
bool gF_LOCK = false;
uint8_t gShowChPrefix; uint8_t gShowChPrefix;
volatile bool gNextTimeslice; volatile bool gNextTimeslice;

8
misc.h
View File

@ -230,8 +230,11 @@ extern bool gRequestSaveSettings;
#endif #endif
extern uint8_t gKeypadLocked; extern uint8_t gKeypadLocked;
extern bool gFlagPrepareTX; 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 gFlagSaveVfo;
extern bool gFlagSaveSettings; extern bool gFlagSaveSettings;
extern bool gFlagSaveChannel; extern bool gFlagSaveChannel;
@ -277,6 +280,7 @@ extern uint8_t gNeverUsed;
#endif #endif
extern volatile bool gNextTimeslice; extern volatile bool gNextTimeslice;
extern bool gUpdateDisplay; extern bool gUpdateDisplay;
extern bool gF_LOCK;
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
extern uint8_t gFM_ChannelPosition; extern uint8_t gFM_ChannelPosition;
#endif #endif

View File

@ -206,9 +206,12 @@ const char gSubMenu_XB[3][10] =
const char gSubMenu_SC_REV[3][13] = const char gSubMenu_SC_REV[3][13] =
{ {
"TIME\nOPER", // "TIME\nOPER",
"CARRIER\nOPER", // "CARRIER\nOPER",
"SEARCH\nOPER" // "SEARCH\nOPER"
"TIME",
"CARRIER",
"SEARCH"
}; };
const char gSubMenu_MDF[4][15] = const char gSubMenu_MDF[4][15] =
@ -332,9 +335,10 @@ bool gIsInSubMenu;
uint8_t gMenuCursor; uint8_t gMenuCursor;
int8_t gMenuScrollDirection; int8_t gMenuScrollDirection;
int32_t gSubMenuSelection; int32_t gSubMenuSelection;
int32_t gSubMenuSelection_original = 0; // copy of the original value
// edit box // edit box
char edit_original[17]; // a copy of the text before editing so that we can easily test for changes/difference char edit_original[17] = {0}; // a copy of the text before editing so that we can easily test for changes/difference
char edit[17]; char edit[17];
int edit_index; int edit_index;
@ -344,7 +348,7 @@ void UI_DisplayMenu(void)
const unsigned int menu_item_x1 = (8 * menu_list_width) + 2; const unsigned int menu_item_x1 = (8 * menu_list_width) + 2;
const unsigned int menu_item_x2 = LCD_WIDTH - 1; const unsigned int menu_item_x2 = LCD_WIDTH - 1;
unsigned int i; unsigned int i;
char String[16]; char String[64];
char Contact[16]; char Contact[16];
// clear the screen // clear the screen
@ -728,21 +732,21 @@ void UI_DisplayMenu(void)
break; break;
case MENU_VOL: case MENU_VOL:
// 1st text line if (gF_LOCK)
sprintf(String, "%u.%02uV", gBatteryVoltageAverage / 100, gBatteryVoltageAverage % 100); {
UI_PrintString(String, menu_item_x1, menu_item_x2, 1, 8); gBatteryCalibration[3] = gSubMenuSelection;
BATTERY_GetReadings(true);
{ // 2nd text line .. percentage sprintf(String, "%u.%02uV\n%u%%\n%u",
UI_PrintString(String, menu_item_x1, menu_item_x2, 1, 8); gBatteryVoltageAverage / 100, gBatteryVoltageAverage % 100,
sprintf(String, "%u%%", BATTERY_VoltsToPercent(gBatteryVoltageAverage)); BATTERY_VoltsToPercent(gBatteryVoltageAverage),
UI_PrintString(String, menu_item_x1, menu_item_x2, 3, 8); gSubMenuSelection);
#if 0 }
sprintf(String, "Curr %u", gBatteryCurrent); // needs scaling into mA else
UI_PrintString(String, menu_item_x1, menu_item_x2, 5, 8); {
#endif sprintf(String, "%u.%02uV\n%u%%",
gBatteryVoltageAverage / 100, gBatteryVoltageAverage % 100,
BATTERY_VoltsToPercent(gBatteryVoltageAverage));
} }
already_printed = true;
break; break;
case MENU_RESET: case MENU_RESET:
@ -756,19 +760,14 @@ void UI_DisplayMenu(void)
case MENU_F_CALI: case MENU_F_CALI:
{ {
const uint32_t value = 22656 + gSubMenuSelection; const uint32_t value = 22656 + gSubMenuSelection;
const uint32_t xtal_Hz = (0x4f0000u + value) * 5;
//gEeprom.BK4819_XTAL_FREQ_LOW = gSubMenuSelection; // already set when the user was adjusting the value //gEeprom.BK4819_XTAL_FREQ_LOW = gSubMenuSelection; // already set when the user was adjusting the value
BK4819_WriteRegister(BK4819_REG_3B, value); BK4819_WriteRegister(BK4819_REG_3B, value);
sprintf(String, "%d", gSubMenuSelection); sprintf(String, "%d\n%u.%06u\nMHz",
UI_PrintString(String, menu_item_x1, menu_item_x2, 0, 8); gSubMenuSelection,
xtal_Hz / 1000000, xtal_Hz % 1000000);
const uint32_t xtal_Hz = (0x4f0000u + value) * 5;
sprintf(String, "%u.%06u", xtal_Hz / 1000000, xtal_Hz % 1000000);
UI_PrintString(String, menu_item_x1, menu_item_x2, 2, 8);
UI_PrintString("MHz", menu_item_x1, menu_item_x2, 4, 8);
already_printed = true;
} }
break; break;
} }

View File

@ -156,6 +156,7 @@ extern bool gIsInSubMenu;
extern uint8_t gMenuCursor; extern uint8_t gMenuCursor;
extern int8_t gMenuScrollDirection; extern int8_t gMenuScrollDirection;
extern int32_t gSubMenuSelection; extern int32_t gSubMenuSelection;
extern int32_t gSubMenuSelection_original;
extern char edit_original[17]; extern char edit_original[17];
extern char edit[17]; extern char edit[17];