Skip to content

Commit

Permalink
Enabled TX for all modulations, Created SSB and TX envelope by modify…
Browse files Browse the repository at this point in the history
…ing power when on TX, added support to modify deviation for FM, AM and SSB modulation from menu. TODO, keep deviation settings in EPROM.
  • Loading branch information
sfotis authored and JuantAldea committed Dec 26, 2023
1 parent a0cacb2 commit 7047ca7
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 21 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,6 +46,7 @@ ENABLE_BYP_RAW_DEMODULATORS ?= 0
ENABLE_BLMIN_TMP_OFF ?= 0
ENABLE_SCAN_RANGES ?= 1
ENABLE_ORIGINAL_MENU_LAYOUT ?= 0
ENABLE_DEVIATION ?= 1

# ---- DEBUGGING ----
ENABLE_AM_FIX_SHOW_DATA ?= 0
Expand Down Expand Up @@ -377,6 +378,9 @@ endif
ifeq ($(ENABLE_ORIGINAL_MENU_LAYOUT),1)
CFLAGS += -DENABLE_ORIGINAL_MENU_LAYOUT
endif
ifeq ($(ENABLE_DEVIATION),1)
CFLAGS += -DENABLE_DEVIATION
endif

LDFLAGS =
LDFLAGS += -z noexecstack -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld -Wl,--gc-sections
Expand Down
33 changes: 31 additions & 2 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,34 @@ static void HandleReceive(void)
}
}

#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
void HandleTransmit()
{
#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
}

static void HandlePowerSave()
{
if (!gRxIdleMode) {
Expand All @@ -398,7 +426,7 @@ static void HandlePowerSave()

static void (*HandleFunction_fn_table[])(void) = {
[FUNCTION_FOREGROUND] = &CheckForIncoming,
[FUNCTION_TRANSMIT] = &FUNCTION_NOP,
[FUNCTION_TRANSMIT] = &HandleTransmit,
[FUNCTION_MONITOR] = &FUNCTION_NOP,
[FUNCTION_INCOMING] = &HandleIncoming,
[FUNCTION_RECEIVE] = &HandleReceive,
Expand Down Expand Up @@ -807,8 +835,9 @@ void APP_Update(void)

if (gReducedService)
return;

#ifndef ENABLE_TX_WHEN_AM
if (gCurrentFunction != FUNCTION_TRANSMIT)
#endif
HandleFunction();

#ifdef ENABLE_FMRADIO
Expand Down
33 changes: 31 additions & 2 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions driver/bk4819-regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,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,
Expand Down
6 changes: 6 additions & 0 deletions driver/bk4819.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,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
Expand Down
1 change: 1 addition & 0 deletions driver/bk4819.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
51 changes: 36 additions & 15 deletions radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,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)
{
Expand Down Expand Up @@ -829,7 +833,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();

Expand All @@ -845,22 +849,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)
Expand Down
4 changes: 4 additions & 0 deletions radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion ui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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 },
Expand Down Expand Up @@ -541,7 +546,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;
Expand Down
5 changes: 5 additions & 0 deletions ui/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7047ca7

Please sign in to comment.