diff --git a/Makefile b/Makefile index 17fec9b..68d04b8 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ ENABLE_COMPANDER := 1 ENABLE_SHOW_CHARGE_LEVEL := 0 ENABLE_REVERSE_BAT_SYMBOL := 1 ENABLE_AM_FIX := 1 +ENABLE_SQUELCH1_LOWER := 1 ENABLE_AUDIO_BAR := 0 #ENABLE_SINGLE_VFO_CHAN := 1 #ENABLE_BAND_SCOPE := 1 @@ -200,6 +201,9 @@ endif ifeq ($(ENABLE_AM_FIX),1) CFLAGS += -DENABLE_AM_FIX endif +ifeq ($(ENABLE_SQUELCH1_LOWER),1) + CFLAGS += -DENABLE_SQUELCH1_LOWER +endif ifeq ($(ENABLE_AUDIO_BAR),1) CFLAGS += -DENABLE_AUDIO_BAR endif diff --git a/app/main.c b/app/main.c index c496a77..fde510d 100644 --- a/app/main.c +++ b/app/main.c @@ -199,7 +199,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) gRequestSaveVFO = true; gVfoConfigureMode = VFO_CONFIGURE_RELOAD; } - BK4819_SetFilterBandwidth(gTxVfo->CHANNEL_BANDWIDTH); + BK4819_SetFilterBandwidth(gTxVfo->CHANNEL_BANDWIDTH, ); gUpdateDisplay = true; gRequestDisplayScreen = gScreenToDisplay; #else diff --git a/driver/bk4819.c b/driver/bk4819.c index 0e986ea..cd9c746 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -515,7 +515,7 @@ void BK4819_EnableVox(uint16_t VoxEnableThreshold, uint16_t VoxDisableThreshold) BK4819_WriteRegister(BK4819_REG_31, REG_31_Value | (1u << 2)); // VOX Enable } -void BK4819_SetFilterBandwidth(BK4819_FilterBandwidth_t Bandwidth, const bool weak_no_different) +void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth, const bool weak_no_different) { // REG_43 <14:12> 4 RF filter bandwidth // 0 = 1.7 kHz @@ -557,11 +557,12 @@ void BK4819_SetFilterBandwidth(BK4819_FilterBandwidth_t Bandwidth, const bool we // REG_43 <2> 0 Gain after FM Demodulation // 0 = 0dB // 1 = 6dB - // + if (Bandwidth == BK4819_FILTER_BW_WIDE) { if (weak_no_different) - { + { // make the bandwidth the same with weak signals (sounds much better) + BK4819_WriteRegister(BK4819_REG_43, (0u << 15) | // 0 (3u << 12) | // 3 RF filter bandwidth @@ -618,10 +619,10 @@ void BK4819_SetFilterBandwidth(BK4819_FilterBandwidth_t Bandwidth, const bool we { if (weak_no_different) { - BK4819_WriteRegister(BK4819_REG_43, // 0 100 000 001 01 1 0 00 + BK4819_WriteRegister(BK4819_REG_43, (0u << 15) | // 0 - (4u << 12) | // 4 RF filter bandwidth - (4u << 9) | // 0 RF filter bandwidth when signal is weak + (2u << 12) | // 4 RF filter bandwidth + (2u << 9) | // 0 RF filter bandwidth when signal is weak (1u << 6) | // 1 AFTxLPF2 filter Band Width (1u << 4) | // 1 BW Mode Selection (1u << 3) | // 1 @@ -630,9 +631,9 @@ void BK4819_SetFilterBandwidth(BK4819_FilterBandwidth_t Bandwidth, const bool we } else { - BK4819_WriteRegister(BK4819_REG_43, // 0 100 000 001 01 1 0 00 + BK4819_WriteRegister(BK4819_REG_43, (0u << 15) | // 0 - (4u << 12) | // 4 RF filter bandwidth + (2u << 12) | // 4 RF filter bandwidth (0u << 9) | // 0 RF filter bandwidth when signal is weak (1u << 6) | // 1 AFTxLPF2 filter Band Width (1u << 4) | // 1 BW Mode Selection @@ -643,28 +644,28 @@ void BK4819_SetFilterBandwidth(BK4819_FilterBandwidth_t Bandwidth, const bool we } } -void BK4819_SetupPowerAmplifier(uint16_t Bias, uint32_t Frequency) +void BK4819_SetupPowerAmplifier(const uint8_t bias, const uint32_t frequency) { - uint8_t Gain; - - if (Bias > 255) - Bias = 255; - - if (Frequency < 28000000) - { - // Gain 1 = 1 - // Gain 2 = 0 - Gain = 0x08U; - } - else - { - // Gain 1 = 4 - // Gain 2 = 2 - Gain = 0x22U; - } - - // Enable PACTLoutput - BK4819_WriteRegister(BK4819_REG_36, (Bias << 8) | 0x80U | Gain); + // REG_36 <15:8> 0 PA Bias output 0 ~ 3.2V + // 255 = 3.2V + // 0 = 0V + // + // REG_36 <7> 0 + // 1 = Enable PA-CTL output + // 0 = Disable (Output 0 V) + // + // REG_36 <5:3> 7 PA gain 1 tuning + // 7 = max + // 0 = min + // + // REG_36 <2:0> 7 PA gain 2 tuning + // 7 = max + // 0 = min + // + // 280MHz gain 1 = 1 gain 2 = 0 gain 1 = 4 gain 2 = 2 + const uint8_t gain = (frequency < 28000000) ? (1u << 3) | (0u << 0) : (4u << 3) | (2u << 0); + const uint8_t enable = 1; + BK4819_WriteRegister(BK4819_REG_36, (bias << 8) | (enable << 7) | (gain << 0)); } void BK4819_SetFrequency(uint32_t Frequency) @@ -684,35 +685,63 @@ void BK4819_SetupSquelch( // REG_70 <15> 0 Enable TONE1 // 1 = Enable // 0 = Disable + // // REG_70 <14:8> 0 TONE1 tuning gain + // 0 ~ 127 + // // REG_70 <7> 0 Enable TONE2 // 1 = Enable // 0 = Disable + // // REG_70 <6:0> 0 TONE2/FSK tuning gain + // 0 ~ 127 // BK4819_WriteRegister(BK4819_REG_70, 0); // Glitch threshold for Squelch // + // 0 ~ 255 + // BK4819_WriteRegister(BK4819_REG_4D, 0xA000 | SquelchCloseGlitchThresh); - // REG_4E <13:11> 5 Squelch = 1 Delay Setting - // REG_4E <10: 9> 7 Squelch = 0 Delay Setting - // REG_4E < 7: 0> 8 Glitch threshold for Squelch = 1 + // REG_4E <15:14> 1 ??? // - #if 1 - BK4819_WriteRegister(BK4819_REG_4E, 0x6F00 | SquelchOpenGlitchThresh); + // REG_4E <13:11> 5 Squelch = 1 Delay Setting + // 0 ~ 7 + // + // REG_4E <10: 9> 7 Squelch = 0 Delay Setting + // 0 ~ 3 + // + // REG_4E < 8> 0 ??? + // + // REG_4E < 7: 0> 8 Glitch threshold for Squelch = 1 + // 0 ~ 255 + // + BK4819_WriteRegister(BK4819_REG_4E, // 01 101 11 1 00000000 + #if 0 + (1u << 14) // 1 ??? + | (5u << 11) // 5 squelch = 1 delay .. 0 ~ 7 + | (3u << 9) // 3 squelch = 0 delay .. 0 ~ 3 + | SquelchOpenGlitchThresh); // 0 ~ 255 #else - // https://github.com/fagci/uv-k5-firmware-fagci-mod - BK4819_WriteRegister(BK4819_REG_4E, 0x0040 | SquelchOpenGlitchThresh); + (1u << 14) // 1 ??? + | (2u << 11) // squelch = 1 delay .. 0 ~ 7 + | (1u << 9) // squelch = 0 delay .. 0 ~ 3 + | SquelchOpenGlitchThresh); // 0 ~ 255 #endif - + // REG_4F <14:8> 47 Ex-noise threshold for Squelch = 0 - // REG_4F <6:0> 46 Ex-noise threshold for Squelch = 1 + // 0 ~ 127 + // + // REG_4F < 7> ??? + // + // REG_4F < 6:0> 46 Ex-noise threshold for Squelch = 1 + // 0 ~ 127 BK4819_WriteRegister(BK4819_REG_4F, ((uint16_t)SquelchCloseNoiseThresh << 8) | SquelchOpenNoiseThresh); // REG_78 <15:8> 72 RSSI threshold for Squelch = 1 0.5dB/step - // REG_78 <7:0> 70 RSSI threshold for Squelch = 0 0.5dB/step + // REG_78 < 7:0> 70 RSSI threshold for Squelch = 0 0.5dB/step + // BK4819_WriteRegister(BK4819_REG_78, ((uint16_t)SquelchOpenRSSIThresh << 8) | SquelchCloseRSSIThresh); BK4819_SetAF(BK4819_AF_MUTE); @@ -881,9 +910,9 @@ void BK4819_PlayTone(uint16_t Frequency, bool bTuningGainSwitch) BK4819_SetAF(BK4819_AF_BEEP); if (bTuningGainSwitch == 0) - ToneConfig = BK4819_REG_70_ENABLE_TONE1 | (96U << BK4819_REG_70_SHIFT_TONE1_TUNING_GAIN); + ToneConfig = BK4819_REG_70_ENABLE_TONE1 | (96u << BK4819_REG_70_SHIFT_TONE1_TUNING_GAIN); else - ToneConfig = BK4819_REG_70_ENABLE_TONE1 | (28U << BK4819_REG_70_SHIFT_TONE1_TUNING_GAIN); + ToneConfig = BK4819_REG_70_ENABLE_TONE1 | (28u << BK4819_REG_70_SHIFT_TONE1_TUNING_GAIN); BK4819_WriteRegister(BK4819_REG_70, ToneConfig); BK4819_WriteRegister(BK4819_REG_30, 0); diff --git a/driver/bk4819.h b/driver/bk4819.h index 37ead18..6d44e7a 100644 --- a/driver/bk4819.h +++ b/driver/bk4819.h @@ -78,8 +78,8 @@ void BK4819_SetCDCSSCodeWord(uint32_t CodeWord); void BK4819_SetCTCSSFrequency(uint32_t BaudRate); void BK4819_SetTailDetection(const uint32_t freq_10Hz); void BK4819_EnableVox(uint16_t Vox1Threshold, uint16_t Vox0Threshold); -void BK4819_SetFilterBandwidth(BK4819_FilterBandwidth_t Bandwidth, const bool weak_no_different); -void BK4819_SetupPowerAmplifier(uint16_t Bias, uint32_t Frequency); +void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth, const bool weak_no_different); +void BK4819_SetupPowerAmplifier(const uint8_t bias, const uint32_t frequency); void BK4819_SetFrequency(uint32_t Frequency); void BK4819_SetupSquelch( uint8_t SquelchOpenRSSIThresh, diff --git a/firmware b/firmware index 2cf65b4..df13c57 100644 Binary files a/firmware and b/firmware differ diff --git a/firmware.bin b/firmware.bin index 72c83e9..503327c 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index cef35c3..03bf6a1 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/radio.c b/radio.c index 6cc5faa..ed45d55 100644 --- a/radio.c +++ b/radio.c @@ -440,30 +440,59 @@ void RADIO_ConfigureSquelchAndOutputPower(VFO_Info_t *pInfo) if (gEeprom.SQUELCH_LEVEL == 0) { - pInfo->SquelchOpenRSSIThresh = 0x00; - pInfo->SquelchOpenNoiseThresh = 0x7F; - pInfo->SquelchCloseGlitchThresh = 0xFF; + pInfo->SquelchOpenRSSIThresh = 0; + pInfo->SquelchOpenNoiseThresh = 127; + pInfo->SquelchCloseGlitchThresh = 255; - pInfo->SquelchCloseRSSIThresh = 0x00; - pInfo->SquelchCloseNoiseThresh = 0x7F; - pInfo->SquelchOpenGlitchThresh = 0xFF; + pInfo->SquelchCloseRSSIThresh = 0; + pInfo->SquelchCloseNoiseThresh = 127; + pInfo->SquelchOpenGlitchThresh = 255; } else { Base += gEeprom.SQUELCH_LEVEL; + // my squelch-1 + // VHF UHF + EEPROM_ReadBuffer(Base + 0x00, &pInfo->SquelchOpenRSSIThresh, 1); // 50 10 + EEPROM_ReadBuffer(Base + 0x10, &pInfo->SquelchCloseRSSIThresh, 1); // 40 5 - EEPROM_ReadBuffer(Base + 0x00, &pInfo->SquelchOpenRSSIThresh, 1); - EEPROM_ReadBuffer(Base + 0x10, &pInfo->SquelchCloseRSSIThresh, 1); + EEPROM_ReadBuffer(Base + 0x20, &pInfo->SquelchOpenNoiseThresh, 1); // 65 90 + EEPROM_ReadBuffer(Base + 0x30, &pInfo->SquelchCloseNoiseThresh, 1); // 70 100 - EEPROM_ReadBuffer(Base + 0x20, &pInfo->SquelchOpenNoiseThresh, 1); - EEPROM_ReadBuffer(Base + 0x30, &pInfo->SquelchCloseNoiseThresh, 1); - - EEPROM_ReadBuffer(Base + 0x40, &pInfo->SquelchCloseGlitchThresh, 1); - EEPROM_ReadBuffer(Base + 0x50, &pInfo->SquelchOpenGlitchThresh, 1); + EEPROM_ReadBuffer(Base + 0x40, &pInfo->SquelchCloseGlitchThresh, 1); // 90 90 + EEPROM_ReadBuffer(Base + 0x50, &pInfo->SquelchOpenGlitchThresh, 1); // 100 100 + #if ENABLE_SQUELCH1_LOWER + // make squelch-1 more sensitive + if (gEeprom.SQUELCH_LEVEL == 1) + { + if (Band < BAND4_174MHz) + { + pInfo->SquelchOpenRSSIThresh = ((uint16_t)pInfo->SquelchOpenRSSIThresh * 11) / 12; + pInfo->SquelchCloseRSSIThresh = ((uint16_t)pInfo->SquelchOpenRSSIThresh * 9) / 10; + + pInfo->SquelchOpenNoiseThresh = ((uint16_t)pInfo->SquelchOpenNoiseThresh * 9) / 8; + pInfo->SquelchCloseNoiseThresh = ((uint16_t)pInfo->SquelchOpenNoiseThresh * 10) / 9; + + pInfo->SquelchOpenGlitchThresh = ((uint16_t)pInfo->SquelchOpenGlitchThresh * 9) / 8; + pInfo->SquelchCloseGlitchThresh = ((uint16_t)pInfo->SquelchOpenGlitchThresh * 10) / 9; + } + else + { + pInfo->SquelchOpenRSSIThresh = ((uint16_t)pInfo->SquelchOpenRSSIThresh * 3) / 4; + pInfo->SquelchCloseRSSIThresh = ((uint16_t)pInfo->SquelchOpenRSSIThresh * 9) / 10; + + pInfo->SquelchOpenNoiseThresh = ((uint16_t)pInfo->SquelchOpenNoiseThresh * 4) / 3; + pInfo->SquelchCloseNoiseThresh = ((uint16_t)pInfo->SquelchOpenNoiseThresh * 10) / 9; + + pInfo->SquelchOpenGlitchThresh = ((uint16_t)pInfo->SquelchOpenGlitchThresh * 4) / 3; + pInfo->SquelchCloseGlitchThresh = ((uint16_t)pInfo->SquelchOpenGlitchThresh * 10) / 9; + } + } + #endif + if (pInfo->SquelchOpenNoiseThresh > 127) pInfo->SquelchOpenNoiseThresh = 127; - if (pInfo->SquelchCloseNoiseThresh > 127) pInfo->SquelchCloseNoiseThresh = 127; }