From 354580f8159448de8f14861adc546c9ef5f93787 Mon Sep 17 00:00:00 2001 From: Fotios Sioutis Date: Sun, 17 Dec 2023 21:12:18 +0200 Subject: [PATCH] Enabled TX for all modulations, Created SSB and TX envelope by modifying power when on TX, added support to modify deviation for FM, AM and SSB modulation from menu. TODO, keep deviation settings in EPROM. --- Makefile | 14 ++++++------ app/app.c | 27 +++++++++++++++++++++-- app/menu.c | 33 ++++++++++++++++++++++++++-- driver/bk4819-regs.h | 1 + driver/bk4819.c | 6 ++++++ driver/bk4819.h | 1 + radio.c | 51 +++++++++++++++++++++++++++++++------------- radio.h | 4 ++++ ui/menu.c | 18 +++++++++++++++- ui/menu.h | 5 +++++ 10 files changed, 132 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index 58d7c8480..50fa37992 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ ENABLE_BIG_FREQ ?= 1 ENABLE_SMALL_BOLD ?= 1 ENABLE_KEEP_MEM_NAME ?= 1 ENABLE_WIDE_RX ?= 1 -ENABLE_TX_WHEN_AM ?= 0 +ENABLE_TX_WHEN_AM ?= 1 ENABLE_F_CAL_MENU ?= 0 ENABLE_CTCSS_TAIL_PHASE_SHIFT ?= 0 ENABLE_BOOT_BEEPS ?= 0 @@ -45,6 +45,7 @@ ENABLE_REDUCE_LOW_MID_TX_POWER?= 0 ENABLE_BYP_RAW_DEMODULATORS ?= 0 ENABLE_BLMIN_TMP_OFF ?= 0 ENABLE_SCAN_RANGES ?= 1 +ENABLE_DEVIATION ?= 1 # ---- DEBUGGING ---- ENABLE_AM_FIX_SHOW_DATA ?= 0 @@ -201,13 +202,7 @@ SIZE = arm-none-eabi-size AUTHOR_STRING ?= EGZUMER # the user might not have/want git installed # can set own version string here (max 7 chars) -ifneq (, $(shell $(WHERE) git)) - VERSION_STRING ?= $(shell git describe --tags --exact-match 2>$(NULL_OUTPUT)) - ifeq (, $(VERSION_STRING)) - VERSION_STRING := $(shell git rev-parse --short HEAD) - endif -endif -#VERSION_STRING := 230930b +VERSION_STRING := SV2RSR_MOD ASFLAGS = -c -mcpu=cortex-m0 @@ -364,6 +359,9 @@ endif ifeq ($(ENABLE_FLASHLIGHT),1) CFLAGS += -DENABLE_FLASHLIGHT endif +ifeq ($(ENABLE_DEVIATION),1) + CFLAGS += -DENABLE_DEVIATION +endif LDFLAGS = LDFLAGS += -z noexecstack -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld -Wl,--gc-sections diff --git a/app/app.c b/app/app.c index 604d73f4f..56384e44d 100644 --- a/app/app.c +++ b/app/app.c @@ -408,7 +408,17 @@ static void HandleReceive(void) break; } } - +#ifdef ENABLE_TX_WHEN_AM +uint8_t calculateRFSignalPower(uint8_t amplitude, uint8_t maxPower, uint8_t carrierPercentage) +{ + if (carrierPercentage == 0) { + return (uint8_t)((amplitude * maxPower) / 255); + } + uint8_t carrierAmplitude = (carrierPercentage * maxPower) / 100; + uint8_t modulationDepth = maxPower - carrierAmplitude; + return carrierAmplitude + (modulationDepth * amplitude / 255); +} +#endif static void HandleFunction(void) { switch (gCurrentFunction) @@ -418,6 +428,18 @@ static void HandleFunction(void) break; case FUNCTION_TRANSMIT: +#ifdef ENABLE_TX_WHEN_AM + if (gCurrentVfo->Modulation == MODULATION_USB || gCurrentVfo->Modulation == MODULATION_AM) { + uint8_t val = BK4819_GetVoiceAmplitudeOut() >> 7; + if (gCurrentVfo->Modulation == MODULATION_USB) { + val = calculateRFSignalPower(val, gCurrentVfo->TXP_CalculatedSetting, 0); + } + else { + val = calculateRFSignalPower(val, gCurrentVfo->TXP_CalculatedSetting, 50); + } + BK4819_SetupPowerAmplifier(val, gCurrentVfo->pTX->Frequency); + } +#endif break; case FUNCTION_MONITOR: @@ -849,8 +871,9 @@ void APP_Update(void) if (gReducedService) return; - +#ifndef ENABLE_TX_WHEN_AM if (gCurrentFunction != FUNCTION_TRANSMIT) +#endif HandleFunction(); #ifdef ENABLE_FMRADIO diff --git a/app/menu.c b/app/menu.c index 2f8c877c4..5c377a800 100644 --- a/app/menu.c +++ b/app/menu.c @@ -199,7 +199,15 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) *pMin = 0; *pMax = ARRAY_SIZE(CTCSS_Options); break; - + +#ifdef ENABLE_DEVIATION + case MENU_DEV_FM: + case MENU_DEV_AM: + case MENU_DEV_SSB: + *pMin = 0; + *pMax = 45; + break; +#endif case MENU_W_N: *pMin = 0; *pMax = ARRAY_SIZE(gSubMenu_W_N) - 1; @@ -451,6 +459,17 @@ void MENU_AcceptSetting(void) gRequestSaveChannel = 1; return; } +#ifdef ENABLE_DEVIATION + case MENU_DEV_FM: + gTxVfo->DeviationFM = gSubMenuSelection; + return; + case MENU_DEV_AM: + gTxVfo->DeviationAM = gSubMenuSelection; + return; + case MENU_DEV_SSB: + gTxVfo->DeviationSSB = gSubMenuSelection; + return; +#endif case MENU_SFT_D: gTxVfo->TX_OFFSET_FREQUENCY_DIRECTION = gSubMenuSelection; gRequestSaveChannel = 1; @@ -887,7 +906,17 @@ void MENU_ShowCurrentSetting(void) case MENU_T_CTCS: gSubMenuSelection = (gTxVfo->freq_config_TX.CodeType == CODE_TYPE_CONTINUOUS_TONE) ? gTxVfo->freq_config_TX.Code + 1 : 0; break; - +#ifdef ENABLE_DEVIATION + case MENU_DEV_FM: + gSubMenuSelection = gTxVfo->DeviationFM; + break; + case MENU_DEV_AM: + gSubMenuSelection = gTxVfo->DeviationAM; + break; + case MENU_DEV_SSB: + gSubMenuSelection = gTxVfo->DeviationSSB; + break; +#endif case MENU_SFT_D: gSubMenuSelection = gTxVfo->TX_OFFSET_FREQUENCY_DIRECTION; break; diff --git a/driver/bk4819-regs.h b/driver/bk4819-regs.h index 93025b9b5..f7fc30791 100644 --- a/driver/bk4819-regs.h +++ b/driver/bk4819-regs.h @@ -73,6 +73,7 @@ enum BK4819_REGISTER_t { BK4819_REG_3D = 0x3DU, BK4819_REG_3E = 0x3EU, BK4819_REG_3F = 0x3FU, + BK4819_REG_40 = 0x40U, BK4819_REG_43 = 0x43U, BK4819_REG_46 = 0x46U, BK4819_REG_47 = 0x47U, diff --git a/driver/bk4819.c b/driver/bk4819.c index f7ac28a52..af0f3b034 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -695,6 +695,12 @@ void BK4819_SetFilterBandwidth(const BK4819_FilterBandwidth_t Bandwidth, const b BK4819_WriteRegister(BK4819_REG_43, val); } +void BK4819_SetupDeviation(const uint16_t dev) +{ + uint16_t hw_dev = ((dev > 0 ? 1 : 0) << 12) | (dev << 0);; + BK4819_WriteRegister(BK4819_REG_40, hw_dev); +} + void BK4819_SetupPowerAmplifier(const uint8_t bias, const uint32_t frequency) { // REG_36 <15:8> 0 PA Bias output 0 ~ 3.2V diff --git a/driver/bk4819.h b/driver/bk4819.h index 5f3798189..5835aa504 100644 --- a/driver/bk4819.h +++ b/driver/bk4819.h @@ -82,6 +82,7 @@ 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(const BK4819_FilterBandwidth_t Bandwidth, const bool weak_no_different); +void BK4819_SetupDeviation(const uint16_t dev); void BK4819_SetupPowerAmplifier(const uint8_t bias, const uint32_t frequency); void BK4819_SetFrequency(uint32_t Frequency); void BK4819_SetupSquelch( diff --git a/radio.c b/radio.c index f325ec1f6..869fe6e48 100644 --- a/radio.c +++ b/radio.c @@ -265,7 +265,11 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure pVfo->freq_config_RX.CodeType = (data[2] >> 0) & 0x0F; pVfo->freq_config_TX.CodeType = (data[2] >> 4) & 0x0F; - +#ifdef ENABLE_DEVIATION + pVfo->DeviationFM = 13; + pVfo->DeviationAM = 14; + pVfo->DeviationSSB = 8; +#endif tmp = data[0]; switch (pVfo->freq_config_RX.CodeType) { @@ -848,7 +852,7 @@ void RADIO_SetTxParameters(void) BK4819_SetFrequency(gCurrentVfo->pTX->Frequency); // TX compressor - BK4819_SetCompander((gRxVfo->Modulation == MODULATION_FM && (gRxVfo->Compander == 1 || gRxVfo->Compander >= 3)) ? gRxVfo->Compander : 0); + BK4819_SetCompander(gRxVfo->Compander == 1 || gRxVfo->Compander >= 3/*))*/ ? gRxVfo->Compander : 0); BK4819_PrepareTransmit(); @@ -864,22 +868,39 @@ void RADIO_SetTxParameters(void) SYSTEM_DelayMs(10); - switch (gCurrentVfo->pTX->CodeType) - { - default: - case CODE_TYPE_OFF: - BK4819_ExitSubAu(); - break; + if (gCurrentVfo->Modulation == MODULATION_FM) { + switch (gCurrentVfo->pTX->CodeType) + { + default: + case CODE_TYPE_OFF: + BK4819_ExitSubAu(); + break; - case CODE_TYPE_CONTINUOUS_TONE: - BK4819_SetCTCSSFrequency(CTCSS_Options[gCurrentVfo->pTX->Code]); - break; + case CODE_TYPE_CONTINUOUS_TONE: + BK4819_SetCTCSSFrequency(CTCSS_Options[gCurrentVfo->pTX->Code]); + break; - case CODE_TYPE_DIGITAL: - case CODE_TYPE_REVERSE_DIGITAL: - BK4819_SetCDCSSCodeWord(DCS_GetGolayCodeWord(gCurrentVfo->pTX->CodeType, gCurrentVfo->pTX->Code)); - break; + case CODE_TYPE_DIGITAL: + case CODE_TYPE_REVERSE_DIGITAL: + BK4819_SetCDCSSCodeWord(DCS_GetGolayCodeWord(gCurrentVfo->pTX->CodeType, gCurrentVfo->pTX->Code)); + break; + } + } + else { + BK4819_ExitSubAu(); } +#ifdef ENABLE_DEVIATION + if (gCurrentVfo->Modulation == MODULATION_USB) { + BK4819_SetupDeviation(gCurrentVfo->DeviationSSB * 0x5B); + } + else if (gCurrentVfo->Modulation == MODULATION_AM) { + BK4819_SetupDeviation(gCurrentVfo->DeviationAM * 0x5B); + } + else { + BK4819_SetupDeviation(gCurrentVfo->DeviationFM * 0x5B); + } +#endif + SYSTEM_DelayMs(10); } void RADIO_SetModulation(ModulationMode_t modulation) diff --git a/radio.h b/radio.h index 3c62c941e..e5db44ac6 100644 --- a/radio.h +++ b/radio.h @@ -128,6 +128,10 @@ typedef struct VFO_Info_t ModulationMode_t Modulation; uint8_t Compander; + + uint8_t DeviationFM; + uint8_t DeviationAM; + uint8_t DeviationSSB; char Name[16]; } VFO_Info_t; diff --git a/ui/menu.c b/ui/menu.c index 62ce8e56e..2f582939e 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -45,6 +45,11 @@ const t_menu_item MenuList[] = {"RxCTCS", VOICE_ID_CTCSS, MENU_R_CTCS }, // was "R_CTCS" {"TxDCS", VOICE_ID_DCS, MENU_T_DCS }, // was "T_DCS" {"TxCTCS", VOICE_ID_CTCSS, MENU_T_CTCS }, // was "T_CTCS" +#ifdef ENABLE_DEVIATION + {"DevFM", VOICE_ID_INVALID, MENU_DEV_FM }, + {"DevAM", VOICE_ID_INVALID, MENU_DEV_AM }, + {"DevSSB", VOICE_ID_INVALID, MENU_DEV_SSB }, +#endif {"TxODir", VOICE_ID_TX_OFFSET_FREQUENCY_DIRECTION, MENU_SFT_D }, // was "SFT_D" {"TxOffs", VOICE_ID_TX_OFFSET_FREQUENCY, MENU_OFFSET }, // was "OFFSET" {"W/N", VOICE_ID_CHANNEL_BANDWIDTH, MENU_W_N }, @@ -542,7 +547,18 @@ void UI_DisplayMenu(void) sprintf(String, "%u.%uHz", CTCSS_Options[gSubMenuSelection - 1] / 10, CTCSS_Options[gSubMenuSelection - 1] % 10); break; } - +#ifdef ENABLE_DEVIATION + case MENU_DEV_FM: + case MENU_DEV_AM: + case MENU_DEV_SSB: + { + if (gSubMenuSelection == 0) + strcpy(String, "OFF"); + else + sprintf(String, "%d", gSubMenuSelection); + break; + } +#endif case MENU_SFT_D: strcpy(String, gSubMenu_SFT_D[gSubMenuSelection]); break; diff --git a/ui/menu.h b/ui/menu.h index ba4361945..60a2ad086 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -38,6 +38,11 @@ enum MENU_R_CTCS, MENU_T_DCS, MENU_T_CTCS, +#ifdef ENABLE_DEVIATION + MENU_DEV_FM, + MENU_DEV_AM, + MENU_DEV_SSB, +#endif MENU_SFT_D, MENU_OFFSET, MENU_TOT,