diff --git a/Makefile b/Makefile index 4679904..a4e046b 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ ENABLE_CTCSS_TAIL_PHASE_SHIFT := 1 ENABLE_MAIN_KEY_HOLD := 1 ENABLE_BOOT_BEEPS := 0 ENABLE_COMPANDER := 1 -ENABLE_SHOW_CHARGE_LEVEL := 0 +ENABLE_SHOW_CHARGE_LEVEL := 1 ENABLE_REVERSE_BAT_SYMBOL := 1 ENABLE_NO_SCAN_TIMEOUT := 1 ENABLE_AM_FIX := 1 diff --git a/app/app.c b/app/app.c index 69c7567..20d33f9 100644 --- a/app/app.c +++ b/app/app.c @@ -497,6 +497,8 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) gUpdateStatus = true; } + // ****************************************** + // original setting uint8_t lna_short = orig_lna_short; uint8_t lna = orig_lna; @@ -505,7 +507,7 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) if (gRxVfo->IsAM) { // AM - +/* #ifndef ENABLE_AM_FIX const uint32_t rx_frequency = gRxVfo->pRX->Frequency; @@ -526,7 +528,7 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) pga = 7; // 6 original, 7 increased } #endif - +*/ // what do these 4 other gain settings do ??? //BK4819_WriteRegister(BK4819_REG_12, 0x037B); // 000000 11 011 11 011 //BK4819_WriteRegister(BK4819_REG_11, 0x027B); // 000000 10 011 11 011 @@ -539,6 +541,8 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) // apply the front end gain settings BK4819_WriteRegister(BK4819_REG_13, ((uint16_t)lna_short << 8) | ((uint16_t)lna << 5) | ((uint16_t)mixer << 3) | ((uint16_t)pga << 0)); + // ****************************************** + // AF gain - original BK4819_WriteRegister(BK4819_REG_48, (11u << 12) | // ??? .. 0 to 15, doesn't seem to make any difference @@ -566,7 +570,7 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix) gUpdateDisplay = true; } -void APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step) +uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step) { uint32_t Frequency = pInfo->freq_config_RX.Frequency + (Step * pInfo->StepFrequency); @@ -589,12 +593,12 @@ void APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step) if (Frequency < LowerLimitFrequencyBandTable[pInfo->Band]) Frequency = FREQUENCY_FloorToStep(UpperLimitFrequencyBandTable[pInfo->Band], pInfo->StepFrequency, LowerLimitFrequencyBandTable[pInfo->Band]); - pInfo->freq_config_RX.Frequency = Frequency; + return Frequency; } static void FREQ_NextChannel(void) { - APP_SetFrequencyByStep(gRxVfo, gScanState); + gRxVfo->freq_config_RX.Frequency = APP_SetFrequencyByStep(gRxVfo, gScanState); RADIO_ApplyOffset(gRxVfo); RADIO_ConfigureSquelchAndOutputPower(gRxVfo); @@ -1206,6 +1210,7 @@ void APP_CheckKeys(void) while (i-- > 0) { SYSTEM_DelayMs(1); + if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT)) { // PTT pressed if (count > 0) diff --git a/app/app.h b/app/app.h index 42bd9c8..2e6febd 100644 --- a/app/app.h +++ b/app/app.h @@ -18,17 +18,17 @@ #define APP_APP_H #include + #include "functions.h" #include "radio.h" -void APP_EndTransmission(void); -void CHANNEL_Next(bool bFlag, int8_t Direction); -void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix); -void APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step); - -void APP_Update(void); -void APP_TimeSlice10ms(void); -void APP_TimeSlice500ms(void); +void APP_EndTransmission(void); +void CHANNEL_Next(bool bFlag, int8_t Direction); +void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix); +uint32_t APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step); +void APP_Update(void); +void APP_TimeSlice10ms(void); +void APP_TimeSlice500ms(void); #endif diff --git a/app/main.c b/app/main.c index bd4a400..cbb089c 100644 --- a/app/main.c +++ b/app/main.c @@ -294,7 +294,8 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gRequestDisplayScreen = DISPLAY_MAIN; if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { + { // user is entering channel number + uint16_t Channel; if (gInputBoxIndex != 3) @@ -319,17 +320,20 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) #ifdef ENABLE_VOICE gAnotherVoiceID = (VOICE_ID_t)Key; #endif + gEeprom.MrChannel[Vfo] = (uint8_t)Channel; gEeprom.ScreenChannel[Vfo] = (uint8_t)Channel; gRequestSaveVFO = true; gVfoConfigureMode = VFO_CONFIGURE_RELOAD; + return; } - #ifdef ENABLE_NOAA - if (IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) - #endif - { +// #ifdef ENABLE_NOAA +// if (IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) +// #endif + if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) + { // user is entering frequency uint32_t Frequency; if (gInputBoxIndex < 6) @@ -337,6 +341,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) #ifdef ENABLE_VOICE gAnotherVoiceID = (VOICE_ID_t)Key; #endif + return; } @@ -344,7 +349,16 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) NUMBER_Get(gInputBox, &Frequency); - if (gSetting_350EN || Frequency < 35000000 || Frequency >= 40000000) +// if (Frequency < bx_start1_Hz || Frequency >= bx_stop2_Hz) +// { // the BK4819 chip does not do this frequency range +// } +// else +// if (Frequency >= bx_stop1_Hz && Frequency < bx_start2_Hz) +// { // the BK4819 chip does not do this frequency range +// } +// else +// if (gSetting_350EN || Frequency < 35000000 || Frequency >= 40000000) + if (RX_FREQUENCY_Check(Frequency) == 0) { unsigned int i; for (i = 0; i < 7; i++) @@ -376,10 +390,13 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } } + } #ifdef ENABLE_NOAA else - { + if (IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) + { // user is entering NOAA channel + uint8_t Channel; if (gInputBoxIndex != 2) @@ -648,7 +665,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) if (bKeyHeld || !bKeyPressed) { - if (gInputBoxIndex) + if (gInputBoxIndex > 0) return; if (!bKeyPressed) @@ -669,11 +686,12 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) } else { - if (gInputBoxIndex) + if (gInputBoxIndex > 0) { gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; return; } + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; } @@ -686,8 +704,17 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) uint8_t Next; if (IS_FREQ_CHANNEL(Channel)) - { - APP_SetFrequencyByStep(gTxVfo, Direction); + { // step/down in frequency + const uint32_t frequency = APP_SetFrequencyByStep(gTxVfo, Direction); + + if (RX_FREQUENCY_Check(frequency) < 0) + { // frequency not allowed + gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + return; + } + + gTxVfo->freq_config_RX.Frequency = frequency; + gRequestSaveChannel = 1; return; } diff --git a/driver/bk4819-regs.h b/driver/bk4819-regs.h index 8fe8950..2e44c07 100644 --- a/driver/bk4819-regs.h +++ b/driver/bk4819-regs.h @@ -95,12 +95,12 @@ enum BK4819_REGISTER_t { typedef enum BK4819_REGISTER_t BK4819_REGISTER_t; enum BK4819_GPIO_PIN_t { - BK4819_GPIO6_PIN2 = 0, - BK4819_GPIO5_PIN1 = 1, - BK4819_GPIO4_PIN32 = 2, - BK4819_GPIO3_PIN31 = 3, - BK4819_GPIO2_PIN30 = 4, - BK4819_GPIO1_PIN29_RED = 5, + BK4819_GPIO6_PIN2 = 0, + BK4819_GPIO5_PIN1 = 1, + BK4819_GPIO4_PIN32 = 2, + BK4819_GPIO3_PIN31 = 3, + BK4819_GPIO2_PIN30 = 4, + BK4819_GPIO1_PIN29_RED = 5, BK4819_GPIO0_PIN28_GREEN = 6, }; diff --git a/driver/gpio.h b/driver/gpio.h index a05aa98..a6e6158 100644 --- a/driver/gpio.h +++ b/driver/gpio.h @@ -29,23 +29,23 @@ enum GPIOA_PINS { GPIOA_PIN_KEYBOARD_6 = 12, // Shared with voice chip! GPIOA_PIN_KEYBOARD_7 = 13, // Shared with voice chip! - GPIOA_PIN_I2C_SCL = 10, // Shared with keyboard! - GPIOA_PIN_I2C_SDA = 11, // Shared with keyboard! + GPIOA_PIN_I2C_SCL = 10, // Shared with keyboard! + GPIOA_PIN_I2C_SDA = 11, // Shared with keyboard! - GPIOA_PIN_VOICE_0 = 12, // Shared with keyboard! - GPIOA_PIN_VOICE_1 = 13, // Shared with keyboard! + GPIOA_PIN_VOICE_0 = 12, // Shared with keyboard! + GPIOA_PIN_VOICE_1 = 13 // Shared with keyboard! }; enum GPIOB_PINS { - GPIOB_PIN_BACKLIGHT = 6, + GPIOB_PIN_BACKLIGHT = 6, - GPIOB_PIN_ST7565_A0 = 9, + GPIOB_PIN_ST7565_A0 = 9, GPIOB_PIN_ST7565_RES = 11, // Shared with SWD! - GPIOB_PIN_SWD_IO = 11, // Shared with ST7565! - GPIOB_PIN_SWD_CLK = 14, + GPIOB_PIN_SWD_IO = 11, // Shared with ST7565! + GPIOB_PIN_SWD_CLK = 14, - GPIOB_PIN_BK1080 = 15, + GPIOB_PIN_BK1080 = 15 }; enum GPIOC_PINS { @@ -54,10 +54,8 @@ enum GPIOC_PINS { GPIOC_PIN_BK4819_SDA = 2, GPIOC_PIN_FLASHLIGHT = 3, - GPIOC_PIN_AUDIO_PATH = 4, - - GPIOC_PIN_PTT = 5, + GPIOC_PIN_PTT = 5 }; void GPIO_ClearBit(volatile uint32_t *pReg, uint8_t Bit); diff --git a/firmware.bin b/firmware.bin index e6afad2..b4badb5 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index fa41d1a..af1f3b0 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/frequencies.c b/frequencies.c index 3fb5122..faf71cd 100644 --- a/frequencies.c +++ b/frequencies.c @@ -18,8 +18,13 @@ #include "misc.h" #include "settings.h" -const uint32_t bx_min_Hz = 1800000; // 18MHz -const uint32_t bx_max_Hz = 130000000; // 1300MHz +// the BK4819 has 2 bands it covers, 18MHz ~ 630MHz and 760MHz ~ 1300MHz + +const uint32_t bx_start1_Hz = 1800000; // 18MHz +const uint32_t bx_stop1_Hz = 1800000; // 630MHz + +const uint32_t bx_start2_Hz = 76000000; // 760MHz +const uint32_t bx_stop2_Hz = 130000000; // 1300MHz const uint32_t LowerLimitFrequencyBandTable[7] = { @@ -166,8 +171,8 @@ uint32_t FREQUENCY_FloorToStep(uint32_t Upper, uint32_t Step, uint32_t Lower) return Lower + (Step * Index); } - -int FREQUENCY_Check(VFO_Info_t *pInfo) +/* +int TX_FREQUENCY_Check(VFO_Info_t *pInfo) { // return '0' if TX frequency is allowed // otherwise return '-1' @@ -177,6 +182,15 @@ int FREQUENCY_Check(VFO_Info_t *pInfo) if (pInfo->CHANNEL_SAVE > FREQ_CHANNEL_LAST) return -1; #endif +*/ +int TX_FREQUENCY_Check(const uint32_t Frequency) +{ // return '0' if TX frequency is allowed + // otherwise return '-1' + + if (Frequency < LowerLimitFrequencyBandTable[0] || Frequency > UpperLimitFrequencyBandTable[6]) + return -1; + if (Frequency >= 63000000 && Frequency < 75700000) + return -1; switch (gSetting_F_LOCK) { @@ -233,3 +247,15 @@ int FREQUENCY_Check(VFO_Info_t *pInfo) // dis-allowed TX frequency return -1; } + +int RX_FREQUENCY_Check(const uint32_t Frequency) +{ // return '0' if RX frequency is allowed + // otherwise return '-1' + + if (Frequency < LowerLimitFrequencyBandTable[0] || Frequency > UpperLimitFrequencyBandTable[6]) + return -1; + if (Frequency >= 63000000 && Frequency < 75700000) + return -1; + + return 0; // OK frequency +} diff --git a/frequencies.h b/frequencies.h index c7ee82b..fa8a474 100644 --- a/frequencies.h +++ b/frequencies.h @@ -21,8 +21,11 @@ #include "radio.h" -extern const uint32_t bx_min_Hz; -extern const uint32_t bx_max_Hz; +extern const uint32_t bx_start1_Hz; +extern const uint32_t bx_stop1_Hz; + +extern const uint32_t bx_start2_Hz; +extern const uint32_t bx_stop2_Hz; enum FREQUENCY_Band_t { @@ -50,7 +53,10 @@ extern const uint16_t StepFrequencyTable[7]; FREQUENCY_Band_t FREQUENCY_GetBand(uint32_t Frequency); uint8_t FREQUENCY_CalculateOutputPower(uint8_t TxpLow, uint8_t TxpMid, uint8_t TxpHigh, int32_t LowerLimit, int32_t Middle, int32_t UpperLimit, int32_t Frequency); uint32_t FREQUENCY_FloorToStep(uint32_t Upper, uint32_t Step, uint32_t Lower); -int FREQUENCY_Check(VFO_Info_t *pInfo); + +//int TX_FREQUENCY_Check(VFO_Info_t *pInfo); +int TX_FREQUENCY_Check(const uint32_t Frequency); +int RX_FREQUENCY_Check(const uint32_t Frequency); #endif diff --git a/functions.c b/functions.c index 4aef501..b77ed96 100644 --- a/functions.c +++ b/functions.c @@ -139,6 +139,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function) BK4819_DisableVox(); BK4819_Sleep(); + BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2, false); gUpdateStatus = true; diff --git a/radio.c b/radio.c index fc76f42..53b1d7d 100644 --- a/radio.c +++ b/radio.c @@ -955,13 +955,17 @@ void RADIO_PrepareTX(void) // disable the TX when VFO/Channel is set to AM // the radio does NOT do AM, the adverts are false if (gCurrentVfo->IsAM) + { State = VFO_STATE_TX_DISABLE; + } else #endif if (!gSetting_TX_EN) + { State = VFO_STATE_TX_DISABLE; + } else - if (!FREQUENCY_Check(gCurrentVfo)) + if (TX_FREQUENCY_Check(gCurrentVfo->pTX->Frequency) == 0 && gCurrentVfo->CHANNEL_SAVE <= FREQ_CHANNEL_LAST) { if (gCurrentVfo->BUSY_CHANNEL_LOCK && gCurrentFunction == FUNCTION_RECEIVE) State = VFO_STATE_BUSY; @@ -976,8 +980,10 @@ void RADIO_PrepareTX(void) goto Skip; } else + { State = VFO_STATE_TX_DISABLE; - + } + RADIO_SetVfoState(State); #ifdef ENABLE_ALARM diff --git a/ui/inputbox.c b/ui/inputbox.c index a11cfc2..bc98197 100644 --- a/ui/inputbox.c +++ b/ui/inputbox.c @@ -23,12 +23,12 @@ uint8_t gInputBoxIndex; void INPUTBOX_Append(char Digit) { - if (gInputBoxIndex == 0) - memset(gInputBox, 10, sizeof(gInputBox)); - else if (gInputBoxIndex >= sizeof(gInputBox)) return; + if (gInputBoxIndex == 0) + memset(gInputBox, 10, sizeof(gInputBox)); + gInputBox[gInputBoxIndex++] = Digit; } diff --git a/ui/main.c b/ui/main.c index a405615..ed3b1c1 100644 --- a/ui/main.c +++ b/ui/main.c @@ -293,7 +293,14 @@ void UI_DisplayMain(void) { const char *state_list[] = {"", "BUSY", "BAT LOW", "TX DISABLE", "TIMEOUT", "ALARM", "VOLT HIGH"}; if (State >= 0 && State < ARRAY_SIZE(state_list)) + { UI_PrintString(state_list[State], 31, 0, Line, 8); + } + //else + //{ + // sprintf(String, "State %u ?", State); + // UI_PrintString(String, 31, 0, Line, 8); + //} } else if (gInputBoxIndex > 0 && IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num]) && gEeprom.TX_CHANNEL == vfo_num)