Fix baseband bandwidth configuration

This commit is contained in:
Michael Ossmann
2026-02-28 19:17:16 -05:00
parent 10f4184cee
commit 30229730b4
3 changed files with 39 additions and 59 deletions

View File

@@ -150,7 +150,7 @@ void max2831_set_mode(max2831_driver_t* const drv, const max2831_mode_t new_mode
}
drv->set_mode(drv, new_mode);
max2831_set_lpf_bandwidth(drv, drv->desired_lpf_bw);
max2831_set_lpf_bandwidth(drv, new_mode, drv->desired_lpf_bw);
}
max2831_mode_t max2831_mode(max2831_driver_t* const drv)
@@ -304,13 +304,13 @@ static const max2831_ft_fine_t max2831_tx_ft_fine[] = {
//clang-format on
uint32_t max2831_set_lpf_bandwidth(max2831_driver_t* const drv, const uint32_t bandwidth_hz) {
uint32_t max2831_set_lpf_bandwidth(max2831_driver_t* const drv, const max2831_mode_t mode, const uint32_t bandwidth_hz) {
const max2831_ft_t* coarse;
const max2831_ft_fine_t* fine;
drv->desired_lpf_bw = bandwidth_hz;
if (drv->mode == MAX2831_MODE_RX) {
if (mode == MAX2831_MODE_RX) {
coarse = max2831_rx_ft;
fine = max2831_rx_ft_fine;
} else {
@@ -343,7 +343,7 @@ uint32_t max2831_set_lpf_bandwidth(max2831_driver_t* const drv, const uint32_t b
/* Program found settings. */
set_MAX2831_LPF_COARSE(drv, coarse->ft);
if (drv->mode == MAX2831_MODE_RX) {
if (mode == MAX2831_MODE_RX) {
set_MAX2831_RX_LPF_FINE_ADJ(drv, f->ft_fine);
} else {
set_MAX2831_TX_LPF_FINE_ADJ(drv, f->ft_fine);

View File

@@ -93,6 +93,7 @@ extern void max2831_stop(max2831_driver_t* const drv);
extern void max2831_set_frequency(max2831_driver_t* const drv, uint32_t freq);
uint32_t max2831_set_lpf_bandwidth(
max2831_driver_t* const drv,
const max2831_mode_t mode,
const uint32_t bandwidth_hz);
bool max2831_set_lna_gain(max2831_driver_t* const drv, const uint32_t gain_db);
bool max2831_set_vga_gain(max2831_driver_t* const drv, const uint32_t gain_db);

View File

@@ -394,7 +394,7 @@ static bool radio_update_frequency(radio_t* const radio, uint64_t* bank)
return true;
}
static uint32_t auto_bandwidth(radio_t* const radio, uint64_t opmode)
static uint32_t auto_bandwidth(radio_t* const radio)
{
uint64_t rotation = radio->config[RADIO_BANK_APPLIED][RADIO_ROTATION];
@@ -413,70 +413,49 @@ static uint32_t auto_bandwidth(radio_t* const radio, uint64_t opmode)
const uint32_t bb_bandwidth = (sample_rate_hz * 3) / 4;
const uint32_t lpf_bandwidth = bb_bandwidth + offset_hz * 2;
switch (opmode) {
case TRANSCEIVER_MODE_TX:
case TRANSCEIVER_MODE_SS:
radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_TX] = bb_bandwidth;
break;
default:
radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_RX] = bb_bandwidth;
}
radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_TX] = bb_bandwidth;
radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_RX] = bb_bandwidth;
return lpf_bandwidth;
}
static bool radio_update_bandwidth(radio_t* const radio, uint64_t* bank)
{
bool new_bw = false;
uint64_t opmode = bank[RADIO_OPMODE];
if (opmode == RADIO_UNSET) {
opmode = radio->config[RADIO_BANK_APPLIED][RADIO_OPMODE];
}
#ifdef PRALINE
/* Praline legacy mode always sets baseband bandwidth automatically. */
(void) bank;
uint32_t lpf_bandwidth = auto_bandwidth(radio, opmode);
uint32_t lpf_bandwidth = auto_bandwidth(radio);
switch (opmode) {
case TRANSCEIVER_MODE_TX:
case TRANSCEIVER_MODE_SS:
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] !=
lpf_bandwidth) {
max2831_set_lpf_bandwidth(&max283x, lpf_bandwidth);
radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] =
lpf_bandwidth;
new_bw = true;
}
break;
default:
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] !=
lpf_bandwidth) {
max2831_set_lpf_bandwidth(&max283x, lpf_bandwidth);
radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] =
lpf_bandwidth;
new_bw = true;
}
bool narrow_lpf_enable = false;
bool applied_narrow_lpf_enable =
radio->config[RADIO_BANK_APPLIED][RADIO_RX_NARROW_LPF];
if (lpf_bandwidth <= 1750000) {
narrow_lpf_enable = true;
}
if (applied_narrow_lpf_enable != narrow_lpf_enable) {
narrowband_filter_set(narrow_lpf_enable);
radio->config[RADIO_BANK_APPLIED][RADIO_RX_NARROW_LPF] =
narrow_lpf_enable;
new_bw = true;
}
/* Always set HPF bandwidth to 30 kHz for now. */
const max2831_rx_hpf_freq_t hpf_bandwidth = MAX2831_RX_HPF_30_KHZ;
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] !=
hpf_bandwidth) {
max2831_set_rx_hpf_frequency(&max283x, hpf_bandwidth);
radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] =
hpf_bandwidth;
new_bw = true;
}
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] != lpf_bandwidth) {
max2831_set_lpf_bandwidth(&max283x, MAX2831_MODE_TX, lpf_bandwidth);
radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] = lpf_bandwidth;
new_bw = true;
}
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] != lpf_bandwidth) {
max2831_set_lpf_bandwidth(&max283x, MAX2831_MODE_RX, lpf_bandwidth);
radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] = lpf_bandwidth;
new_bw = true;
}
bool narrow_lpf_enable = false;
bool applied_narrow_lpf_enable =
radio->config[RADIO_BANK_APPLIED][RADIO_RX_NARROW_LPF];
if (lpf_bandwidth <= 1750000) {
narrow_lpf_enable = true;
}
if (applied_narrow_lpf_enable != narrow_lpf_enable) {
narrowband_filter_set(narrow_lpf_enable);
radio->config[RADIO_BANK_APPLIED][RADIO_RX_NARROW_LPF] =
narrow_lpf_enable;
new_bw = true;
}
/* Always set HPF bandwidth to 30 kHz for now. */
const max2831_rx_hpf_freq_t hpf_bandwidth = MAX2831_RX_HPF_30_KHZ;
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] != hpf_bandwidth) {
max2831_set_rx_hpf_frequency(&max283x, hpf_bandwidth);
radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] = hpf_bandwidth;
new_bw = true;
}
#else
uint64_t lpf_bandwidth;
@@ -494,7 +473,7 @@ static bool radio_update_bandwidth(radio_t* const radio, uint64_t* bank)
lpf_bandwidth = radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF];
}
if (lpf_bandwidth == RADIO_UNSET) {
lpf_bandwidth = auto_bandwidth(radio, opmode);
lpf_bandwidth = auto_bandwidth(radio);
}
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] != lpf_bandwidth) {