Implement RSSI based squelch control

This commit is contained in:
Niccolò Izzo 2021-01-28 15:13:06 +01:00
parent 0b98f50a12
commit 226d2ccaf7
4 changed files with 23 additions and 15 deletions

View File

@ -21,6 +21,7 @@
#include <stdio.h> #include <stdio.h>
#include <state.h> #include <state.h>
#include <battery.h> #include <battery.h>
#include <hwconfig.h>
#include <interfaces/platform.h> #include <interfaces/platform.h>
state_t state; state_t state;
@ -52,7 +53,11 @@ void state_init()
state.channel.fm.txTone = 2; // 71.9Hz state.channel.fm.txTone = 2; // 71.9Hz
state.rtxStatus = RTX_OFF; state.rtxStatus = RTX_OFF;
#ifdef HAS_ABSOLUTE_KNOB // If the radio has an absolute position knob
state.sqlLevel = platform_getChSelector() - 1;
#else
state.sqlLevel = 3; state.sqlLevel = 3;
#endif
state.voxLevel = 0; state.voxLevel = 0;
state.emergency = false; state.emergency = false;

View File

@ -118,7 +118,7 @@ static void ui_task(void *arg)
rtx_cfg.rxFrequency = state.channel.rx_frequency; rtx_cfg.rxFrequency = state.channel.rx_frequency;
rtx_cfg.txFrequency = state.channel.tx_frequency; rtx_cfg.txFrequency = state.channel.tx_frequency;
rtx_cfg.txPower = state.channel.power; rtx_cfg.txPower = state.channel.power;
rtx_cfg.sqlLevel = state.channel.squelch; rtx_cfg.sqlLevel = state.sqlLevel;
rtx_cfg.rxToneEn = state.channel.fm.rxToneEn; rtx_cfg.rxToneEn = state.channel.fm.rxToneEn;
rtx_cfg.rxTone = ctcss_tone[state.channel.fm.rxTone]; rtx_cfg.rxTone = ctcss_tone[state.channel.fm.rxTone];
rtx_cfg.txToneEn = state.channel.fm.txToneEn; rtx_cfg.txToneEn = state.channel.fm.txToneEn;

View File

@ -537,16 +537,18 @@ void _ui_fsm_menuMacro(kbd_msg_t msg, bool *sync_rtx) {
} }
#ifdef HAS_ABSOLUTE_KNOB // If the radio has an absolute position knob #ifdef HAS_ABSOLUTE_KNOB // If the radio has an absolute position knob
state.sqlLevel = platform_getChSelector(); if(msg.keys & KEY_LEFT || msg.keys & KEY_RIGHT) {
printf("New squelch value: %d\n\r", state.sqlLevel); state.sqlLevel = platform_getChSelector() - 1;
#else // Use left and right buttons or relative position knob *sync_rtx = true;
if(msg.keys && KEY_LEFT) {
state.sqlLevel++;
state.sqlLevel = (state.sqlLevel > 15) 15 : state.sqlLevel;
} }
else if(msg.keys && KEY_RIGHT) { #else // Use left and right buttons or relative position knob
state.sqlLevel--; if(msg.keys & KEY_LEFT) {
state.sqlLevel = (state.sqlLevel < 0) 0 : state.sqlLevel; state.sqlLevel = (state.sqlLevel == 15) 15 : state.sqlLevel++;
*sync_rtx = true;
}
else if(msg.keys & KEY_RIGHT) {
state.sqlLevel = (state.sqlLevel == 0) 0 : state.sqlLevel--;
*sync_rtx = true;
} }
#endif #endif
} }

View File

@ -410,17 +410,18 @@ void rtx_taskFunc()
if(rtxStatus.opStatus == RX) if(rtxStatus.opStatus == RX)
{ {
/* Convert back voltage to ADC counts */ // Unmute speaker if rssi is greater than squelch value
float sqlValue = (adc1_getMeasurement(1) * 4096.0f)/3300.0f; float rssi = rtx_getRssi();
uint16_t sqlLevel = ((uint16_t) sqlValue) >> 6; // sqlValue represents 15 steps from -140dBm to -70dBm
float rssi_squelch = -140.0f + rtxStatus.sqlLevel * 70.0f / 15.0f;
if((gpio_readPin(SPK_MUTE) == 1) && (sqlLevel > sqlOpenTsh)) if((gpio_readPin(SPK_MUTE) == 1) && (rssi > rssi_squelch))
{ {
gpio_clearPin(SPK_MUTE); gpio_clearPin(SPK_MUTE);
platform_ledOn(GREEN); platform_ledOn(GREEN);
} }
if((gpio_readPin(SPK_MUTE) == 0) && (sqlLevel < sqlCloseTsh)) if((gpio_readPin(SPK_MUTE) == 0) && (rssi < rssi_squelch))
{ {
gpio_setPin(SPK_MUTE); gpio_setPin(SPK_MUTE);
platform_ledOff(GREEN); platform_ledOff(GREEN);