diff --git a/app/app.c b/app/app.c index 92376b3..8dac70a 100644 --- a/app/app.c +++ b/app/app.c @@ -475,15 +475,30 @@ void APP_StartListening(FUNCTION_Type_t Function) void APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step) { - uint32_t Frequency = pInfo->ConfigRX.Frequency + (Step * pInfo->StepFrequency); + uint32_t Frequency; + + Frequency = pInfo->ConfigRX.Frequency + (Step * pInfo->StepFrequency); + + if (pInfo->StepFrequency == 833) + { + const uint32_t Lower = LowerLimitFrequencyBandTable[pInfo->Band]; + const uint32_t Delta = Frequency - Lower; + uint32_t Base = (Delta / 2500) * 2500; + const uint32_t Index = ((Delta - Base) % 2500) / 833; + + if (Index == 2) + Base++; + + Frequency = Lower + Base + (Index * 833); + } - if (Frequency < LowerLimitFrequencyBandTable[pInfo->Band]) - Frequency = FREQUENCY_FloorToStep(UpperLimitFrequencyBandTable[pInfo->Band], pInfo->StepFrequency, LowerLimitFrequencyBandTable[pInfo->Band]); - else if (Frequency > UpperLimitFrequencyBandTable[pInfo->Band]) - Frequency = LowerLimitFrequencyBandTable[pInfo->Band]; - - pInfo->ConfigRX.Frequency = Frequency; + pInfo->ConfigRX.Frequency = LowerLimitFrequencyBandTable[pInfo->Band]; + else + if (Frequency < LowerLimitFrequencyBandTable[pInfo->Band]) + pInfo->ConfigRX.Frequency = FREQUENCY_FloorToStep(UpperLimitFrequencyBandTable[pInfo->Band], pInfo->StepFrequency, LowerLimitFrequencyBandTable[pInfo->Band]); + else + pInfo->ConfigRX.Frequency = Frequency; } static void FREQ_NextChannel(void) @@ -614,6 +629,14 @@ void APP_CheckRadioInterrupts(void) // fetch the interrupt status bits interrupt_status_bits = BK4819_ReadRegister(BK4819_REG_02); + // 0 = no phase shift + // 1 = 120deg phase shift + // 2 = 180deg phase shift + // 3 = 240deg phase shift +// const uint8_t ctcss_shift = BK4819_GetCTCShift(); +// if (ctcss_shift > 0) +// g_CTCSS_Lost = true; + if (interrupt_status_bits & BK4819_REG_02_DTMF_5TONE_FOUND) { gDTMF_RequestPending = true; diff --git a/app/menu.c b/app/menu.c index 7dc0b84..5f82114 100644 --- a/app/menu.c +++ b/app/menu.c @@ -24,6 +24,8 @@ #include "board.h" #include "bsp/dp32g030/gpio.h" #include "driver/backlight.h" +#include "driver/bk4819.h" +#include "driver/eeprom.h" #include "driver/gpio.h" #include "driver/keyboard.h" #include "frequencies.h" @@ -61,9 +63,9 @@ VOICE_ID_INVALID, VOICE_ID_BEEP_PROMPT, VOICE_ID_TRANSMIT_OVER_TIME, -// #ifdef ENABLE_VOICE + #ifdef ENABLE_VOICE VOICE_ID_VOICE_PROMPT, -// #endif + #endif VOICE_ID_INVALID, VOICE_ID_INVALID, VOICE_ID_INVALID, @@ -72,6 +74,9 @@ VOICE_ID_INVALID, VOICE_ID_INVALID, VOICE_ID_INVALID, + #ifdef ENABLE_COMPANDER + VOICE_ID_INVALID, + #endif VOICE_ID_INVALID, VOICE_ID_INVALID, VOICE_ID_INVALID, @@ -98,11 +103,16 @@ #endif VOICE_ID_DELETE_CHANNEL, VOICE_ID_INITIALISATION, + + // hidden items + VOICE_ID_INVALID, VOICE_ID_INVALID, VOICE_ID_INVALID, VOICE_ID_INVALID, VOICE_ID_INVALID, + VOICE_ID_INVALID, + VOICE_ID_INVALID }; #endif @@ -127,7 +137,7 @@ void MENU_StopCssScan(void) RADIO_SetupRegisters(true); } -int MENU_GetLimits(uint8_t Cursor, uint8_t *pMin, uint8_t *pMax) +int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax) { switch (Cursor) { @@ -304,7 +314,12 @@ int MENU_GetLimits(uint8_t Cursor, uint8_t *pMin, uint8_t *pMax) *pMin = 1; *pMax = 16; break; - + + case MENU_F_CALI: + *pMin = -1000; + *pMax = +1000; + break; + default: return -1; } @@ -314,8 +329,8 @@ int MENU_GetLimits(uint8_t Cursor, uint8_t *pMin, uint8_t *pMax) void MENU_AcceptSetting(void) { - uint8_t Min; - uint8_t Max; + int32_t Min; + int32_t Max; uint8_t Code; FREQ_Config_t *pConfig = &gTxVfo->ConfigRX; @@ -656,7 +671,28 @@ void MENU_AcceptSetting(void) gRequestSaveSettings = true; gFlagReconfigureVfos = true; return; - + + 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); + } + return; + default: return; } @@ -666,13 +702,14 @@ void MENU_AcceptSetting(void) void MENU_SelectNextCode(void) { - uint8_t UpperLimit; + int32_t UpperLimit; if (gMenuCursor == MENU_R_DCS) UpperLimit = 208; + //UpperLimit = ARRAY_SIZE(DCS_Options); else if (gMenuCursor == MENU_R_CTCS) - UpperLimit = 50; + UpperLimit = ARRAY_SIZE(CTCSS_Options) - 1; else return; @@ -707,11 +744,11 @@ void MENU_SelectNextCode(void) static void MENU_ClampSelection(int8_t Direction) { - uint8_t Min; - uint8_t Max; + int32_t Min; + int32_t Max; if (!MENU_GetLimits(gMenuCursor, &Min, &Max)) { - uint8_t Selection = gSubMenuSelection; + int32_t Selection = gSubMenuSelection; if (Selection < Min) Selection = Min; else if (Selection > Max) Selection = Max; @@ -976,6 +1013,10 @@ void MENU_ShowCurrentSetting(void) case MENU_SCREN: gSubMenuSelection = gSetting_ScrambleEnable; break; + + case MENU_F_CALI: + gSubMenuSelection = gEeprom.BK4819_XTAL_FREQ_LOW; + break; } } @@ -1073,8 +1114,8 @@ static void MENU_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } else { - uint8_t Min; - uint8_t Max; + int32_t Min; + int32_t Max; if (!MENU_GetLimits(gMenuCursor, &Min, &Max)) { @@ -1322,12 +1363,16 @@ static void MENU_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) case MENU_1_CALL: bCheckScanList = false; break; + case MENU_SLIST2: VFO = 1; + // Fallthrough + case MENU_SLIST1: bCheckScanList = true; break; + default: MENU_ClampSelection(Direction); gRequestDisplayScreen = DISPLAY_MENU; @@ -1361,7 +1406,7 @@ void MENU_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) MENU_Key_MENU(bKeyPressed, bKeyHeld); break; case KEY_UP: - MENU_Key_UP_DOWN(bKeyPressed, bKeyHeld, 1); + MENU_Key_UP_DOWN(bKeyPressed, bKeyHeld, 1); break; case KEY_DOWN: MENU_Key_UP_DOWN(bKeyPressed, bKeyHeld, -1); diff --git a/app/menu.h b/app/menu.h index a4fbe61..644be8d 100644 --- a/app/menu.h +++ b/app/menu.h @@ -19,7 +19,7 @@ #include "driver/keyboard.h" -int MENU_GetLimits(uint8_t Cursor, uint8_t *pMin, uint8_t *pMax); +int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax); void MENU_AcceptSetting(void); void MENU_SelectNextCode(void); void MENU_ShowCurrentSetting(void); diff --git a/board.c b/board.c index d4cd54a..d697913 100644 --- a/board.c +++ b/board.c @@ -52,8 +52,8 @@ static const uint32_t gDefaultFrequencyTable[] = 14500000, // 14550000, // 43300000, // - 43320000, // - 43350000 // + 43320000, // + 43350000 // }; // BAND1_50MHz @@ -69,10 +69,10 @@ void BOARD_FLASH_Init(void) FLASH_Init(FLASH_READ_MODE_1_CYCLE); FLASH_ConfigureTrimValues(); SYSTEM_ConfigureClocks(); - + overlay_FLASH_MainClock = 48000000; overlay_FLASH_ClockMultiplier = 48; - + FLASH_Init(FLASH_READ_MODE_2_CYCLE); } @@ -379,7 +379,7 @@ void BOARD_EEPROM_Init(void) gEeprom.NoaaChannel[0] = IS_NOAA_CHANNEL(Data[6]) ? Data[6] : NOAA_CHANNEL_FIRST; gEeprom.NoaaChannel[1] = IS_NOAA_CHANNEL(Data[7]) ? Data[7] : NOAA_CHANNEL_FIRST; #endif - + #ifdef ENABLE_FMRADIO { // 0E88..0E8F struct @@ -389,7 +389,7 @@ void BOARD_EEPROM_Init(void) uint8_t IsMrMode; uint8_t Padding[8]; } __attribute__((packed)) FM; - + EEPROM_ReadBuffer(0x0E88, &FM, 8); gEeprom.FM_LowerLimit = 760; gEeprom.FM_UpperLimit = 1080; @@ -401,7 +401,7 @@ void BOARD_EEPROM_Init(void) gEeprom.FM_SelectedChannel = FM.SelectedChannel; gEeprom.FM_IsMrMode = (FM.IsMrMode < 2) ? FM.IsMrMode : false; } - + // 0E40..0E67 EEPROM_ReadBuffer(0x0E40, gFM_Channels, sizeof(gFM_Channels)); FM_ConfigureChannelState(); @@ -430,7 +430,7 @@ void BOARD_EEPROM_Init(void) EEPROM_ReadBuffer(0x0EA0, Data, 8); gEeprom.VOICE_PROMPT = (Data[0] < 3) ? Data[0] : VOICE_PROMPT_ENGLISH; #endif - + // 0EA8..0EAF EEPROM_ReadBuffer(0x0EA8, Data, 8); #ifdef ENABLE_ALARM @@ -568,25 +568,29 @@ void BOARD_EEPROM_LoadMoreSettings(void) //gEeprom.MIC_SENSITIVITY_TUNING = (Mic < 32) ? Mic : 15; gEeprom.MIC_SENSITIVITY_TUNING = gMicGain_dB2[gEeprom.MIC_SENSITIVITY]; - struct { - int16_t BK4819_XtalFreqLow; - uint16_t EEPROM_1F8A; - uint16_t EEPROM_1F8C; - uint8_t VOLUME_GAIN; - uint8_t DAC_GAIN; - } Misc; + struct + { + int16_t BK4819_XtalFreqLow; + uint16_t EEPROM_1F8A; + uint16_t EEPROM_1F8C; + uint8_t VOLUME_GAIN; + uint8_t DAC_GAIN; + } __attribute__((packed)) Misc; - EEPROM_ReadBuffer(0x1F88, &Misc, 8); - gEeprom.BK4819_XTAL_FREQ_LOW = ((Misc.BK4819_XtalFreqLow + 1000) < 2000) ? Misc.BK4819_XtalFreqLow : 0; + // 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); - gEEPROM_1F8A = Misc.EEPROM_1F8A & 0x01FF; - gEEPROM_1F8C = Misc.EEPROM_1F8C & 0x01FF; + gEeprom.BK4819_XTAL_FREQ_LOW = (Misc.BK4819_XtalFreqLow >= -1000 && Misc.BK4819_XtalFreqLow <= 1000) ? Misc.BK4819_XtalFreqLow : 0; + gEEPROM_1F8A = Misc.EEPROM_1F8A & 0x01FF; + gEEPROM_1F8C = Misc.EEPROM_1F8C & 0x01FF; + gEeprom.VOLUME_GAIN = (Misc.VOLUME_GAIN < 64) ? Misc.VOLUME_GAIN : 58; + gEeprom.DAC_GAIN = (Misc.DAC_GAIN < 16) ? Misc.DAC_GAIN : 8; - gEeprom.VOLUME_GAIN = (Misc.VOLUME_GAIN < 64) ? Misc.VOLUME_GAIN : 58; - gEeprom.DAC_GAIN = (Misc.DAC_GAIN < 16) ? Misc.DAC_GAIN : 8; - - BK4819_WriteRegister(BK4819_REG_3B, gEeprom.BK4819_XTAL_FREQ_LOW + 22656); + BK4819_WriteRegister(BK4819_REG_3B, 22656 + gEeprom.BK4819_XTAL_FREQ_LOW); +// BK4819_WriteRegister(BK4819_REG_3C, gEeprom.BK4819_XTAL_FREQ_HIGH); + } } void BOARD_FactoryReset(bool bIsAll) diff --git a/driver/bk4819.c b/driver/bk4819.c index a323a42..66fbbde 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -1028,12 +1028,17 @@ uint8_t BK4819_GetDTMF_5TONE_Code(void) uint8_t BK4819_GetCDCSSCodeType(void) { - return (BK4819_ReadRegister(BK4819_REG_0C) >> 14) & 3; + return (BK4819_ReadRegister(BK4819_REG_0C) >> 14) & 3u; +} + +uint8_t BK4819_GetCTCShift(void) +{ + return (BK4819_ReadRegister(BK4819_REG_0C) >> 12) & 3u; } uint8_t BK4819_GetCTCType(void) { - return (BK4819_ReadRegister(BK4819_REG_0C) >> 10) & 3; + return (BK4819_ReadRegister(BK4819_REG_0C) >> 10) & 3u; } void BK4819_SendFSKData(uint16_t *pData) diff --git a/driver/bk4819.h b/driver/bk4819.h index 178afa2..77950c9 100644 --- a/driver/bk4819.h +++ b/driver/bk4819.h @@ -137,6 +137,7 @@ void BK4819_StopScan(void); uint8_t BK4819_GetDTMF_5TONE_Code(void); uint8_t BK4819_GetCDCSSCodeType(void); +uint8_t BK4819_GetCTCShift(void); uint8_t BK4819_GetCTCType(void); void BK4819_SendFSKData(uint16_t *pData); diff --git a/firmware b/firmware index 25d58d6..4753dc1 100644 Binary files a/firmware and b/firmware differ diff --git a/firmware.bin b/firmware.bin index dc4502e..b9c9e66 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index a051c48..70275fc 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/frequencies.c b/frequencies.c index 6277aff..d2baa1a 100644 --- a/frequencies.c +++ b/frequencies.c @@ -148,7 +148,22 @@ uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t T uint32_t FREQUENCY_FloorToStep(uint32_t Upper, uint32_t Step, uint32_t Lower) { - const uint32_t Index = (Upper - Lower) / Step; + uint32_t Index; + + if (Step == 833) + { + const uint32_t Delta = Upper - Lower; + uint32_t Base = (Delta / 2500) * 2500; + const uint32_t Index = ((Delta - Base) % 2500) / 833; + + if (Index == 2) + Base++; + + return Lower + Base + (Index * 833); + } + + Index = (Upper - Lower) / Step; + return Lower + (Step * Index); } diff --git a/helper/boot.c b/helper/boot.c index d8a4879..a8c06ab 100644 --- a/helper/boot.c +++ b/helper/boot.c @@ -66,7 +66,8 @@ void BOOT_ProcessMode(BOOT_Mode_t Mode) { if (Mode == BOOT_MODE_F_LOCK) { - gMenuListCount += 6; // enable the last 6 menu items + //gMenuListCount += 6; // enable the last 6 menu items + gMenuListCount += 7; // enable the last 7 menu items gMenuCursor = MENU_350TX; gSubMenuSelection = gSetting_350TX; GUI_SelectNextDisplay(DISPLAY_MENU); diff --git a/main.c b/main.c index 5bae662..adc1018 100644 --- a/main.c +++ b/main.c @@ -116,7 +116,8 @@ void Main(void) // count the number of menu list items while (MenuList[gMenuListCount][0] != 0) gMenuListCount++; - gMenuListCount -= 6; + //gMenuListCount -= 6; + gMenuListCount -= 7; UI_DisplayWelcome(); BACKLIGHT_TurnOn(); diff --git a/misc.c b/misc.c index b6c9993..e08a2dc 100644 --- a/misc.c +++ b/misc.c @@ -216,12 +216,15 @@ void NUMBER_ToDigits(uint32_t Value, char *pDigits) pDigits[8] = 0; } -uint8_t NUMBER_AddWithWraparound(uint8_t Base, int8_t Add, uint8_t LowerLimit, uint8_t UpperLimit) +int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit) { Base += Add; - if (Base == 0xFF || Base < LowerLimit) + + if (Base == 0x7fffffff || Base < LowerLimit) return UpperLimit; + if (Base > UpperLimit) return LowerLimit; + return Base; } diff --git a/misc.h b/misc.h index fe3ea64..fd09a2a 100644 --- a/misc.h +++ b/misc.h @@ -239,7 +239,7 @@ extern uint8_t gIsLocked; void NUMBER_Get(char *pDigits, uint32_t *pInteger); void NUMBER_ToDigits(uint32_t Value, char *pDigits); -uint8_t NUMBER_AddWithWraparound(uint8_t Base, int8_t Add, uint8_t LowerLimit, uint8_t UpperLimit); +int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit); #endif diff --git a/ui/menu.c b/ui/menu.c index c1d4b58..b442397 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -15,10 +15,12 @@ */ #include +#include // abs() #include "app/dtmf.h" #include "bitmaps.h" #include "dcs.h" +#include "driver/bk4819.h" #include "driver/eeprom.h" // EEPROM_ReadBuffer() #include "driver/st7565.h" #include "external/printf/printf.h" @@ -107,7 +109,9 @@ const char MenuList[][7] = "500-TX", // was "500TX" "350-EN", // was "350EN" "SCR-EN", // was "SCREN" - + + "F-CALI", // reference xtal calibration + "" // end of list }; @@ -241,10 +245,10 @@ const char gSubMenu_F_LOCK[6][4] = "438" }; -bool gIsInSubMenu; -uint8_t gMenuCursor; -int8_t gMenuScrollDirection; -uint32_t gSubMenuSelection; +bool gIsInSubMenu; +uint8_t gMenuCursor; +int8_t gMenuScrollDirection; +int32_t gSubMenuSelection; void UI_DisplayMenu(void) { @@ -255,7 +259,7 @@ void UI_DisplayMenu(void) memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); for (i = 0; i < 3; i++) - if (gMenuCursor || i) + if (gMenuCursor > 0 || i > 0) if ((gMenuListCount - 1) != gMenuCursor || i != 2) UI_PrintString(MenuList[gMenuCursor + i - 1], 0, 0, i * 2, 8); @@ -274,7 +278,7 @@ void UI_DisplayMenu(void) gFrameBuffer[i][49] = 0xFF; } #else - // a nicer less intense thinner dotted line + // a less intense thinner dotted line for (i = 0; i < 6; i++) gFrameBuffer[i][49] = 0xAA; #endif @@ -283,7 +287,7 @@ void UI_DisplayMenu(void) NUMBER_ToDigits(1 + gMenuCursor, String); UI_DisplaySmallDigits(2, String + 6, 33, 6, false); #else - sprintf(String, "%2u.%u", 1u + gMenuCursor, gMenuListCount); + sprintf(String, "%2u.%u", 1 + gMenuCursor, gMenuListCount); UI_PrintStringSmall(String, 8, 0, 6); #endif @@ -295,7 +299,7 @@ void UI_DisplayMenu(void) switch (gMenuCursor) { case MENU_SQL: - sprintf(String, "%u", gSubMenuSelection); + sprintf(String, "%d", gSubMenuSelection); break; case MENU_MIC: @@ -306,13 +310,13 @@ void UI_DisplayMenu(void) break; case MENU_STEP: - sprintf(String, "%u.%02uKHz", StepFrequencyTable[gSubMenuSelection] / 100, StepFrequencyTable[gSubMenuSelection] % 100); + sprintf(String, "%d.%02uKHz", StepFrequencyTable[gSubMenuSelection] / 100, abs(StepFrequencyTable[gSubMenuSelection]) % 100); break; - + case MENU_TXP: strcpy(String, gSubMenu_TXP[gSubMenuSelection]); break; - + case MENU_R_DCS: case MENU_T_DCS: if (gSubMenuSelection == 0) @@ -323,7 +327,7 @@ void UI_DisplayMenu(void) else sprintf(String, "D%03oI", DCS_Options[gSubMenuSelection - 105]); break; - + case MENU_R_CTCS: case MENU_T_CTCS: if (gSubMenuSelection == 0) @@ -331,15 +335,15 @@ void UI_DisplayMenu(void) else sprintf(String, "%u.%uHz", CTCSS_Options[gSubMenuSelection - 1] / 10, CTCSS_Options[gSubMenuSelection - 1] % 10); break; - + case MENU_SFT_D: strcpy(String, gSubMenu_SFT_D[gSubMenuSelection]); break; - + case MENU_OFFSET: if (!gIsInSubMenu || gInputBoxIndex == 0) { - sprintf(String, "%u.%05u", gSubMenuSelection / 100000, gSubMenuSelection % 100000); + sprintf(String, "%d.%05u", gSubMenuSelection / 100000, abs(gSubMenuSelection) % 100000); break; } @@ -355,26 +359,26 @@ void UI_DisplayMenu(void) String[11] = 0; break; - + case MENU_W_N: strcpy(String, gSubMenu_W_N[gSubMenuSelection]); break; - + case MENU_SCR: case MENU_VOX: if (gSubMenuSelection == 0) strcpy(String, "OFF"); else - sprintf(String, "%u", gSubMenuSelection); + sprintf(String, "%d", gSubMenuSelection); break; - + case MENU_ABR: #if 0 if (gSubMenuSelection == 0) strcpy(String, "OFF"); else if (gSubMenuSelection < 5) - sprintf(String, "%u sec", gSubMenuSelection * 10); + sprintf(String, "%d sec", gSubMenuSelection * 10); else strcpy(String, "ON"); #else @@ -390,11 +394,11 @@ void UI_DisplayMenu(void) } #endif break; - + case MENU_AM: strcpy(String, (gSubMenuSelection == 0) ? "FM" : "AM"); break; - + case MENU_AUTOLK: strcpy(String, (gSubMenuSelection == 0) ? "OFF" : "AUTO"); break; @@ -419,91 +423,88 @@ void UI_DisplayMenu(void) case MENU_SCREN: strcpy(String, gSubMenu_OFF_ON[gSubMenuSelection]); break; - + case MENU_MEM_CH: case MENU_1_CALL: case MENU_DEL_CH: - UI_GenerateChannelStringEx( - String, - RADIO_CheckValidChannel((uint16_t)gSubMenuSelection, false, 0), - (uint8_t)gSubMenuSelection); + UI_GenerateChannelStringEx(String, RADIO_CheckValidChannel(gSubMenuSelection, false, 0), gSubMenuSelection); break; - + case MENU_SAVE: strcpy(String, gSubMenu_SAVE[gSubMenuSelection]); break; - + case MENU_TDR: case MENU_XB: strcpy(String, gSubMenu_CHAN[gSubMenuSelection]); break; - + case MENU_TOT: if (gSubMenuSelection == 0) strcpy(String, "OFF"); else - sprintf(String, "%umin", gSubMenuSelection); + sprintf(String, "%dmin", gSubMenuSelection); break; - + #ifdef ENABLE_VOICE case MENU_VOICE: strcpy(String, gSubMenu_VOICE[gSubMenuSelection]); break; #endif - + case MENU_SC_REV: strcpy(String, gSubMenu_SC_REV[gSubMenuSelection]); break; - + case MENU_MDF: strcpy(String, gSubMenu_MDF[gSubMenuSelection]); break; - + case MENU_RP_STE: if (gSubMenuSelection == 0) strcpy(String, "OFF"); else - sprintf(String, "%u*100ms", gSubMenuSelection); + sprintf(String, "%d*100ms", gSubMenuSelection); break; - + case MENU_S_LIST: sprintf(String, "LIST%u", gSubMenuSelection); break; - + #ifdef ENABLE_ALARM case MENU_AL_MOD: sprintf(String, gSubMenu_AL_MOD[gSubMenuSelection]); break; #endif - + case MENU_ANI_ID: strcpy(String, gEeprom.ANI_DTMF_ID); break; - + case MENU_UPCODE: strcpy(String, gEeprom.DTMF_UP_CODE); break; - + case MENU_DWCODE: strcpy(String, gEeprom.DTMF_DOWN_CODE); break; - + case MENU_D_RSP: strcpy(String, gSubMenu_D_RSP[gSubMenuSelection]); break; - + case MENU_D_HOLD: - sprintf(String, "%us", gSubMenuSelection); + sprintf(String, "%ds", gSubMenuSelection); break; - + case MENU_D_PRE: - sprintf(String, "%u*10ms", gSubMenuSelection); + sprintf(String, "%d*10ms", gSubMenuSelection); break; - + case MENU_PTT_ID: strcpy(String, gSubMenu_PTT_ID[gSubMenuSelection]); break; - + case MENU_D_LIST: gIsDtmfContactValid = DTMF_GetContact((int)gSubMenuSelection - 1, Contact); if (!gIsDtmfContactValid) @@ -511,26 +512,42 @@ void UI_DisplayMenu(void) else memcpy(String, Contact, 8); break; - + case MENU_PONMSG: strcpy(String, gSubMenu_PONMSG[gSubMenuSelection]); break; - + case MENU_ROGER: strcpy(String, gSubMenu_ROGER[gSubMenuSelection]); break; - + case MENU_VOL: sprintf(String, "%u.%02uV", gBatteryVoltageAverage / 100, gBatteryVoltageAverage % 100); break; - + case MENU_RESET: strcpy(String, gSubMenu_RESET[gSubMenuSelection]); break; - + case MENU_F_LOCK: strcpy(String, gSubMenu_F_LOCK[gSubMenuSelection]); break; + + case MENU_F_CALI: + { + sprintf(String, "%d", gSubMenuSelection); + UI_PrintString(String, 50, 127, 1, 8); + + const uint32_t value = 22656 + gSubMenuSelection; + //gEeprom.BK4819_XTAL_FREQ_LOW = gSubMenuSelection; + BK4819_WriteRegister(BK4819_REG_3B, value); + + const uint32_t xtal_Hz = (0x4f0000u + value) * 5; + sprintf(String, "%u.%06u", xtal_Hz / 1000000, xtal_Hz % 1000000); + UI_PrintString(String, 50, 127, 3, 8); + UI_PrintString("MHz", 50, 127, 5, 8); + } + break; } if (gMenuCursor == MENU_AM) @@ -565,6 +582,7 @@ void UI_DisplayMenu(void) UI_PrintString("MHz", 50, 127, 3, 8); } else + if (gMenuCursor != MENU_F_CALI) { UI_PrintString(String, 50, 127, 2, 8); } @@ -631,7 +649,7 @@ void UI_DisplayMenu(void) gMenuCursor == MENU_D_LIST) { unsigned int Offset; - NUMBER_ToDigits((uint8_t)gSubMenuSelection, String); + NUMBER_ToDigits(gSubMenuSelection, String); Offset = (gMenuCursor == MENU_D_LIST) ? 2 : 3; UI_DisplaySmallDigits(Offset, String + (8 - Offset), 105, 0, false); } @@ -643,7 +661,7 @@ void UI_DisplayMenu(void) if (gSubMenuSelection == 0xFF) strcpy(String, "NULL"); else - UI_GenerateChannelStringEx(String, true, (uint8_t)gSubMenuSelection); + UI_GenerateChannelStringEx(String, true, gSubMenuSelection); if (gSubMenuSelection == 0xFF || !gEeprom.SCAN_LIST_ENABLED[i]) { diff --git a/ui/menu.h b/ui/menu.h index eebcefb..fdf17a3 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -82,12 +82,17 @@ enum #endif MENU_DEL_CH, MENU_RESET, + + // items after here are normally hidden + MENU_350TX, MENU_F_LOCK, MENU_200TX, MENU_500TX, MENU_350EN, - MENU_SCREN + MENU_SCREN, + + MENU_F_CALI // reference xtal calibration }; extern const char MenuList[][7]; @@ -121,9 +126,8 @@ extern bool gIsInSubMenu; extern uint8_t gMenuCursor; extern int8_t gMenuScrollDirection; -extern uint32_t gSubMenuSelection; +extern int32_t gSubMenuSelection; void UI_DisplayMenu(void); #endif -