Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
c3e03945dThis file is pinned to the selected release. Download the original to open it in your design tool.
/*
* Copyright 2012-2026 Great Scott Gadgets <info@greatscottgadgets.com>
* Copyright 2012 Jared Boone
* Copyright 2013 Benjamin Vernoux
*
* This file is part of HackRF.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "rf_path.h"
#include "max283x.h"
#include "max5864.h"
#include "mixer.h"
#include "platform_detect.h"
#ifdef IS_NOT_JAWBREAKER
#include <libopencm3/lpc43xx/scu.h>
#include "platform_scu.h"
#include "platform_gpio.h"
#endif
/* RF Path instance. */
rf_path_t rf_path = {
.switchctrl = 0,
};
/*
* RF switches on Jawbreaker are controlled by General Purpose Outputs (GPO) on
* the RFFC5072.
*
* On HackRF One, the same signals are controlled by GPIO on the LPC.
* SWITCHCTRL_NO_TX_AMP_PWR and SWITCHCTRL_NO_RX_AMP_PWR are not normally used
* on HackRF One as the amplifier power is instead controlled only by
* SWITCHCTRL_AMP_BYPASS.
*
* The rad1o also uses GPIO pins to control the different switches. The amplifiers
* are also connected to the LPC.
*
* On Praline, a subset of control signals is managed by GPIO pins on the LPC, while
* the remaining signals are generated through combinatorial logic in hardware.
*/
#define SWITCHCTRL_NO_TX_AMP_PWR (1 << 0) /* GPO1 turn off TX amp power */
#define SWITCHCTRL_AMP_BYPASS (1 << 1) /* GPO2 bypass amp section */
#define SWITCHCTRL_TX (1 << 2) /* GPO3 1 for TX mode, 0 for RX mode */
#define SWITCHCTRL_MIX_BYPASS (1 << 3) /* GPO4 bypass RFFC5072 mixer section */
#define SWITCHCTRL_HP (1 << 4) /* GPO5 1 for high-pass, 0 for low-pass */
#define SWITCHCTRL_NO_RX_AMP_PWR (1 << 5) /* GPO6 turn off RX amp power */
/*
* GPO6 GPO5 GPO4 GPO3 GPO2 GPO1
* !RXAMP HP MIXBP TX AMPBP !TXAMP Mix mode Amp mode
* 1 X 1 1 1 1 TX bypass Bypass
* 1 X 1 1 0 0 TX bypass TX amplified
* 1 1 0 1 1 1 TX high Bypass
* 1 1 0 1 0 0 TX high TX amplified
* 1 0 0 1 1 1 TX low Bypass
* 1 0 0 1 0 0 TX low TX amplified
* 1 X 1 0 1 1 RX bypass Bypass
* 0 X 1 0 0 1 RX bypass RX amplified
* 1 1 0 0 1 1 RX high Bypass
* 0 1 0 0 0 1 RX high RX amplified
* 1 0 0 0 1 1 RX low Bypass
* 0 0 0 0 0 1 RX low RX amplified
*/
/*
* Safe (initial) switch settings turn off both amplifiers and enable both amp
* bypass and mixer bypass.
*/
#define SWITCHCTRL_SAFE \
(SWITCHCTRL_NO_TX_AMP_PWR | SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_TX | \
SWITCHCTRL_MIX_BYPASS | SWITCHCTRL_HP | SWITCHCTRL_NO_RX_AMP_PWR)
/*
* Antenna port power on HackRF One (except r9) is controlled by GPO1 on the
* RFFC5072. This is the only thing we use RFFC5072 GPO for on HackRF One.
* The value of SWITCHCTRL_NO_ANT_PWR does not correspond to the GPO1 bit in
* the gpo register.
*/
#define SWITCHCTRL_ANT_PWR (1 << 6) /* turn on antenna port power */
#ifdef IS_HACKRF_ONE
static void switchctrl_set_hackrf_one(rf_path_t* const rf_path, uint8_t ctrl)
{
board_id_t board_id = detected_platform();
if (ctrl & SWITCHCTRL_TX) {
if (board_id != BOARD_ID_HACKRF1_R9) {
gpio_set(rf_path->gpio_tx);
}
gpio_clear(rf_path->gpio_rx);
} else {
if (board_id != BOARD_ID_HACKRF1_R9) {
gpio_clear(rf_path->gpio_tx);
}
gpio_set(rf_path->gpio_rx);
}
if (ctrl & SWITCHCTRL_MIX_BYPASS) {
gpio_set(rf_path->gpio_mix_bypass);
gpio_clear(rf_path->gpio_no_mix_bypass);
if (ctrl & SWITCHCTRL_TX) {
gpio_set(rf_path->gpio_tx_mix_bp);
gpio_clear(rf_path->gpio_rx_mix_bp);
} else {
gpio_clear(rf_path->gpio_tx_mix_bp);
gpio_set(rf_path->gpio_rx_mix_bp);
}
} else {
gpio_clear(rf_path->gpio_mix_bypass);
gpio_set(rf_path->gpio_no_mix_bypass);
gpio_clear(rf_path->gpio_tx_mix_bp);
gpio_clear(rf_path->gpio_rx_mix_bp);
}
if (ctrl & SWITCHCTRL_HP) {
gpio_set(rf_path->gpio_hp);
gpio_clear(rf_path->gpio_lp);
} else {
gpio_clear(rf_path->gpio_hp);
gpio_set(rf_path->gpio_lp);
}
if (ctrl & SWITCHCTRL_AMP_BYPASS) {
gpio_set(rf_path->gpio_amp_bypass);
gpio_clear(rf_path->gpio_tx_amp);
gpio_set(rf_path->gpio_no_tx_amp_pwr);
gpio_clear(rf_path->gpio_rx_amp);
gpio_set(rf_path->gpio_no_rx_amp_pwr);
} else if (ctrl & SWITCHCTRL_TX) {
gpio_clear(rf_path->gpio_amp_bypass);
gpio_set(rf_path->gpio_tx_amp);
gpio_clear(rf_path->gpio_no_tx_amp_pwr);
gpio_clear(rf_path->gpio_rx_amp);
gpio_set(rf_path->gpio_no_rx_amp_pwr);
} else {
gpio_clear(rf_path->gpio_amp_bypass);
gpio_clear(rf_path->gpio_tx_amp);
gpio_set(rf_path->gpio_no_tx_amp_pwr);
gpio_set(rf_path->gpio_rx_amp);
gpio_clear(rf_path->gpio_no_rx_amp_pwr);
}
/*
* These normally shouldn't be set post-Jawbreaker, but they can be
* used to explicitly turn off power to the amplifiers while AMP_BYPASS
* is unset:
*/
if (ctrl & SWITCHCTRL_NO_TX_AMP_PWR) {
gpio_set(rf_path->gpio_no_tx_amp_pwr);
}
if (ctrl & SWITCHCTRL_NO_RX_AMP_PWR) {
gpio_set(rf_path->gpio_no_rx_amp_pwr);
}
if (board_id == BOARD_ID_HACKRF1_R9) {
if (ctrl & SWITCHCTRL_ANT_PWR) {
gpio_clear(rf_path->gpio_h1r9_no_ant_pwr);
} else {
gpio_set(rf_path->gpio_h1r9_no_ant_pwr);
}
} else {
if (ctrl & SWITCHCTRL_ANT_PWR) {
mixer_set_gpo(
&mixer,
0x00); /* turn on antenna power by clearing GPO1 */
} else {
mixer_set_gpo(
&mixer,
0x01); /* turn off antenna power by setting GPO1 */
}
}
}
#endif
#ifdef IS_PRALINE
static void switchctrl_set_praline(rf_path_t* const rf_path, uint8_t ctrl)
{
if (ctrl & SWITCHCTRL_TX) {
gpio_set(rf_path->gpio_tx_en);
if (ctrl & SWITCHCTRL_NO_TX_AMP_PWR) {
ctrl |= SWITCHCTRL_AMP_BYPASS;
}
} else {
gpio_clear(rf_path->gpio_tx_en);
if (ctrl & SWITCHCTRL_NO_RX_AMP_PWR) {
ctrl |= SWITCHCTRL_AMP_BYPASS;
}
}
if (ctrl & SWITCHCTRL_MIX_BYPASS) {
gpio_set(rf_path->gpio_mix_en_n);
} else {
gpio_clear(rf_path->gpio_mix_en_n);
}
if (ctrl & SWITCHCTRL_HP) {
gpio_clear(rf_path->gpio_lpf_en);
} else {
gpio_set(rf_path->gpio_lpf_en);
}
if (ctrl & SWITCHCTRL_AMP_BYPASS) {
gpio_clear(rf_path->gpio_rf_amp_en);
} else {
gpio_set(rf_path->gpio_rf_amp_en);
}
if (ctrl & SWITCHCTRL_ANT_PWR) {
gpio_clear(rf_path->gpio_ant_bias_en_n);
} else {
gpio_set(rf_path->gpio_ant_bias_en_n);
}
}
#endif
#ifdef IS_RAD1O
static void switchctrl_set_rad1o(rf_path_t* const rf_path, uint8_t ctrl)
{
if (ctrl & SWITCHCTRL_TX) {
gpio_set(rf_path->gpio_tx_rx_n);
gpio_clear(rf_path->gpio_tx_rx);
} else {
gpio_clear(rf_path->gpio_tx_rx_n);
gpio_set(rf_path->gpio_tx_rx);
}
if (ctrl & SWITCHCTRL_MIX_BYPASS) {
gpio_clear(rf_path->gpio_by_mix);
gpio_set(rf_path->gpio_by_mix_n);
gpio_clear(rf_path->gpio_mixer_en);
} else {
gpio_set(rf_path->gpio_by_mix);
gpio_clear(rf_path->gpio_by_mix_n);
gpio_set(rf_path->gpio_mixer_en);
}
if (ctrl & SWITCHCTRL_HP) {
gpio_set(rf_path->gpio_low_high_filt);
gpio_clear(rf_path->gpio_low_high_filt_n);
} else {
gpio_clear(rf_path->gpio_low_high_filt);
gpio_set(rf_path->gpio_low_high_filt_n);
}
if (ctrl & SWITCHCTRL_AMP_BYPASS) {
gpio_clear(rf_path->gpio_by_amp);
gpio_set(rf_path->gpio_by_amp_n);
gpio_clear(rf_path->gpio_tx_amp);
gpio_clear(rf_path->gpio_rx_lna);
} else if (ctrl & SWITCHCTRL_TX) {
gpio_set(rf_path->gpio_by_amp);
gpio_clear(rf_path->gpio_by_amp_n);
gpio_set(rf_path->gpio_tx_amp);
gpio_clear(rf_path->gpio_rx_lna);
} else {
gpio_set(rf_path->gpio_by_amp);
gpio_clear(rf_path->gpio_by_amp_n);
gpio_clear(rf_path->gpio_tx_amp);
gpio_set(rf_path->gpio_rx_lna);
}
/*
* These normally shouldn't be set post-Jawbreaker, but they can be
* used to explicitly turn off power to the amplifiers while AMP_BYPASS
* is unset:
*/
if (ctrl & SWITCHCTRL_NO_TX_AMP_PWR) {
gpio_clear(rf_path->gpio_tx_amp);
}
if (ctrl & SWITCHCTRL_NO_RX_AMP_PWR) {
gpio_clear(rf_path->gpio_rx_lna);
}
}
#endif
static void switchctrl_set(rf_path_t* const rf_path, const uint8_t gpo)
{
#ifdef IS_JAWBREAKER
if (IS_JAWBREAKER) {
(void) rf_path;
mixer_set_gpo(&mixer, gpo);
}
#endif
#ifdef IS_HACKRF_ONE
if (IS_HACKRF_ONE) {
switchctrl_set_hackrf_one(rf_path, gpo);
}
#endif
#ifdef IS_PRALINE
if (IS_PRALINE) {
switchctrl_set_praline(rf_path, gpo);
}
#endif
#ifdef IS_RAD1O
if (IS_RAD1O) {
switchctrl_set_rad1o(rf_path, gpo);
}
#endif
}
void rf_path_pin_shutdown(void)
{
#ifdef IS_PRALINE
if (IS_PRALINE) {
const platform_scu_t* scu = platform_scu();
/* Configure RF switch control signals */
scu_pinmux(scu->TX_EN, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
board_rev_t rev = detected_revision();
if ((rev == BOARD_REV_PRALINE_R1_0) ||
(rev == BOARD_REV_GSG_PRALINE_R1_0)) {
scu_pinmux(scu->MIX_EN_N_R1_0, SCU_GPIO_PDN | SCU_CONF_FUNCTION4);
} else {
scu_pinmux(scu->MIX_EN_N, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
}
scu_pinmux(scu->LPF_EN, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
scu_pinmux(scu->RF_AMP_EN, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
/* Configure antenna port power control signal */
scu_pinmux(scu->ANT_BIAS_EN_N, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
/* Configure RF power supply (VAA) switch */
scu_pinmux(scu->NO_VAA_ENABLE, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
/* Disable narrowband filter. */
narrowband_filter_set(0);
gpio_output(platform_gpio()->aa_en);
}
#endif
}
void rf_path_pin_setup(rf_path_t* const rf_path)
{
#ifdef IS_JAWBREAKER
(void) rf_path;
#else
const platform_gpio_t* gpio = platform_gpio();
const platform_scu_t* scu = platform_scu();
#endif
// initialize rf_path struct and assign gpio's
#ifdef IS_HACKRF_ONE
if (IS_HACKRF_ONE) {
*rf_path = (rf_path_t){
.switchctrl = 0,
.gpio_hp = gpio->hp,
.gpio_lp = gpio->lp,
.gpio_tx_mix_bp = gpio->tx_mix_bp,
.gpio_no_mix_bypass = gpio->no_mix_bypass,
.gpio_rx_mix_bp = gpio->rx_mix_bp,
.gpio_tx_amp = gpio->tx_amp,
.gpio_tx = gpio->tx,
.gpio_mix_bypass = gpio->mix_bypass,
.gpio_rx = gpio->rx,
.gpio_no_tx_amp_pwr = gpio->no_tx_amp_pwr,
.gpio_amp_bypass = gpio->amp_bypass,
.gpio_rx_amp = gpio->rx_amp,
.gpio_no_rx_amp_pwr = gpio->no_rx_amp_pwr,
};
#ifdef IS_H1_R9
if (IS_H1_R9) {
rf_path->gpio_rx = gpio->h1r9_rx;
rf_path->gpio_h1r9_no_ant_pwr = gpio->h1r9_no_ant_pwr;
}
#endif
}
#endif
#ifdef IS_RAD1O
if (IS_RAD1O) {
*rf_path = (rf_path_t){
.switchctrl = 0,
.gpio_tx_rx_n = gpio->tx_rx_n,
.gpio_tx_rx = gpio->tx_rx,
.gpio_by_mix = gpio->by_mix,
.gpio_by_mix_n = gpio->by_mix_n,
.gpio_by_amp = gpio->by_amp,
.gpio_by_amp_n = gpio->by_amp_n,
.gpio_mixer_en = gpio->mixer_en,
.gpio_low_high_filt = gpio->low_high_filt,
.gpio_low_high_filt_n = gpio->low_high_filt_n,
.gpio_tx_amp = gpio->tx_amp,
.gpio_rx_lna = gpio->rx_lna,
};
}
#endif
#ifdef IS_PRALINE
if (IS_PRALINE) {
*rf_path = (rf_path_t){
.switchctrl = 0,
.gpio_tx_en = gpio->tx_en,
.gpio_mix_en_n = gpio->mix_en_n,
.gpio_lpf_en = gpio->lpf_en,
.gpio_rf_amp_en = gpio->rf_amp_en,
.gpio_ant_bias_en_n = gpio->ant_bias_en_n,
};
if ((detected_revision() == BOARD_REV_PRALINE_R1_0) ||
(detected_revision() == BOARD_REV_GSG_PRALINE_R1_0)) {
rf_path->gpio_mix_en_n = gpio->mix_en_n_r1_0;
}
scu_pinmux(scu->PINMUX_FPGA_CRESET, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
scu_pinmux(scu->PINMUX_FPGA_CDONE, SCU_GPIO_PUP | SCU_CONF_FUNCTION4);
scu_pinmux(scu->PINMUX_FPGA_SPI_CS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
}
#endif
#ifdef IS_HACKRF_ONE
if (IS_HACKRF_ONE) {
/* Configure RF switch control signals */
// clang-format off
scu_pinmux(scu->HP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->LP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->TX_MIX_BP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->NO_MIX_BYPASS, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->RX_MIX_BP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->TX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->MIX_BYPASS, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
scu_pinmux(scu->NO_TX_AMP_PWR, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->AMP_BYPASS, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->RX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->NO_RX_AMP_PWR, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
// clang-format on
#ifdef IS_H1_R9
if (IS_H1_R9) {
scu_pinmux(scu->H1R9_RX, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(
scu->H1R9_NO_ANT_PWR,
SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
gpio_clear(rf_path->gpio_h1r9_no_ant_pwr);
gpio_output(rf_path->gpio_h1r9_no_ant_pwr);
scu_pinmux(
scu->H1R9_NO_VAA_EN,
SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
}
#endif
#ifdef IS_NOT_H1_R9
if (IS_NOT_H1_R9) {
scu_pinmux(scu->TX, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
scu_pinmux(scu->RX, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
gpio_output(rf_path->gpio_tx);
scu_pinmux(scu->NO_VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
}
#endif
/*
* Safe (initial) switch settings turn off both amplifiers and antenna port
* power and enable both amp bypass and mixer bypass.
*/
switchctrl_set(rf_path, SWITCHCTRL_SAFE);
/* Configure RF switch control signals as outputs */
gpio_output(rf_path->gpio_amp_bypass);
gpio_output(rf_path->gpio_no_mix_bypass);
gpio_output(rf_path->gpio_rx_amp);
gpio_output(rf_path->gpio_no_rx_amp_pwr);
gpio_output(rf_path->gpio_hp);
gpio_output(rf_path->gpio_lp);
gpio_output(rf_path->gpio_tx_mix_bp);
gpio_output(rf_path->gpio_rx_mix_bp);
gpio_output(rf_path->gpio_tx_amp);
gpio_output(rf_path->gpio_no_tx_amp_pwr);
gpio_output(rf_path->gpio_mix_bypass);
gpio_output(rf_path->gpio_rx);
}
#endif
#ifdef IS_RAD1O
if (IS_RAD1O) {
/* Configure RF switch control signals */
// clang-format off
scu_pinmux(scu->BY_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->BY_AMP_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
scu_pinmux(scu->TX_RX, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->TX_RX_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->BY_MIX, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->BY_MIX_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->LOW_HIGH_FILT, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->LOW_HIGH_FILT_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->TX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->RX_LNA, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
scu_pinmux(scu->MIXER_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
// clang-format on
/* Configure RF power supply (VAA) switch */
scu_pinmux(scu->VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
/*
* Safe (initial) switch settings turn off both amplifiers and antenna port
* power and enable both amp bypass and mixer bypass.
*/
switchctrl_set(rf_path, SWITCHCTRL_SAFE);
/* Configure RF switch control signals as outputs */
gpio_output(rf_path->gpio_tx_rx_n);
gpio_output(rf_path->gpio_tx_rx);
gpio_output(rf_path->gpio_by_mix);
gpio_output(rf_path->gpio_by_mix_n);
gpio_output(rf_path->gpio_by_amp);
gpio_output(rf_path->gpio_by_amp_n);
gpio_output(rf_path->gpio_mixer_en);
gpio_output(rf_path->gpio_low_high_filt);
gpio_output(rf_path->gpio_low_high_filt_n);
gpio_output(rf_path->gpio_tx_amp);
gpio_output(rf_path->gpio_rx_lna);
}
#endif
#ifdef IS_PRALINE
if (IS_PRALINE) {
/* Configure RF switch control signals */
scu_pinmux(scu->TX_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
board_rev_t rev = detected_revision();
if ((rev == BOARD_REV_PRALINE_R1_0) ||
(rev == BOARD_REV_GSG_PRALINE_R1_0)) {
scu_pinmux(scu->MIX_EN_N_R1_0, SCU_GPIO_FAST | SCU_CONF_FUNCTION4);
} else {
scu_pinmux(scu->MIX_EN_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
}
scu_pinmux(scu->LPF_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
scu_pinmux(scu->RF_AMP_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
/* Configure antenna port power control signal */
scu_pinmux(scu->ANT_BIAS_EN_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
/* Configure RF power supply (VAA) switch */
scu_pinmux(scu->NO_VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0);
/*
* Safe (initial) switch settings turn off both amplifiers and antenna port
* power and enable both amp bypass and mixer bypass.
*/
switchctrl_set(rf_path, SWITCHCTRL_SAFE);
/* Configure RF switch control signals as outputs */
gpio_output(rf_path->gpio_ant_bias_en_n);
gpio_output(rf_path->gpio_tx_en);
gpio_output(rf_path->gpio_mix_en_n);
gpio_output(rf_path->gpio_lpf_en);
gpio_output(rf_path->gpio_rf_amp_en);
}
#endif
}
void rf_path_init(rf_path_t* const rf_path)
{
max5864_setup(&max5864);
max5864_shutdown(&max5864);
max283x_setup(&max283x);
max283x_start(&max283x);
#ifdef IS_RAD1O
if (IS_RAD1O) {
mixer_setup(&mixer, MAX2871_VARIANT);
}
#endif
#ifdef IS_NOT_RAD1O
if (IS_NOT_RAD1O) {
#ifdef IS_NOT_HACKRF_ONE
if (IS_NOT_HACKRF_ONE) {
mixer_setup(&mixer, RFFC5071_VARIANT);
}
#endif
}
#endif
rf_path->switchctrl = SWITCHCTRL_SAFE;
}
void rf_path_set_direction(rf_path_t* const rf_path, const rf_path_direction_t direction)
{
/* Turn off TX and RX amplifiers, then enable based on direction and bypass state. */
rf_path->switchctrl |= SWITCHCTRL_NO_TX_AMP_PWR | SWITCHCTRL_NO_RX_AMP_PWR;
switch (direction) {
case RF_PATH_DIRECTION_TX:
rf_path->switchctrl |= SWITCHCTRL_TX;
if ((rf_path->switchctrl & SWITCHCTRL_AMP_BYPASS) == 0) {
/* TX amplifier is in path, be sure to enable TX amplifier. */
rf_path->switchctrl &= ~SWITCHCTRL_NO_TX_AMP_PWR;
}
if (rf_path->switchctrl & SWITCHCTRL_MIX_BYPASS) {
mixer_disable(&mixer);
} else {
mixer_enable(&mixer);
}
max5864_tx(&max5864);
max283x_tx(&max283x);
break;
case RF_PATH_DIRECTION_RX:
rf_path->switchctrl &= ~SWITCHCTRL_TX;
if ((rf_path->switchctrl & SWITCHCTRL_AMP_BYPASS) == 0) {
/* RX amplifier is in path, be sure to enable RX amplifier. */
rf_path->switchctrl &= ~SWITCHCTRL_NO_RX_AMP_PWR;
}
if (rf_path->switchctrl & SWITCHCTRL_MIX_BYPASS) {
mixer_disable(&mixer);
} else {
mixer_enable(&mixer);
}
max5864_rx(&max5864);
max283x_rx(&max283x);
break;
#ifdef IS_PRALINE
case RF_PATH_DIRECTION_TX_CALIBRATION:
case RF_PATH_DIRECTION_RX_CALIBRATION:
rf_path->switchctrl &= ~SWITCHCTRL_TX;
mixer_disable(&mixer);
max5864_xcvr(&max5864);
if (direction == RF_PATH_DIRECTION_TX_CALIBRATION) {
max283x_tx_calibration(&max283x);
} else {
max283x_rx_calibration(&max283x);
}
break;
#endif
case RF_PATH_DIRECTION_OFF:
default:
rf_path_set_lna(rf_path, 0);
/* Set RF path to receive direction when "off" */
rf_path->switchctrl &= ~SWITCHCTRL_TX;
mixer_disable(&mixer);
max5864_standby(&max5864);
max283x_set_mode(&max283x, MAX283x_MODE_STANDBY);
break;
}
switchctrl_set(rf_path, rf_path->switchctrl);
}
void rf_path_set_filter(rf_path_t* const rf_path, const rf_path_filter_t filter)
{
switch (filter) {
default:
case RF_PATH_FILTER_BYPASS:
rf_path->switchctrl |= SWITCHCTRL_MIX_BYPASS;
mixer_disable(&mixer);
break;
case RF_PATH_FILTER_LOW_PASS:
rf_path->switchctrl &= ~(SWITCHCTRL_HP | SWITCHCTRL_MIX_BYPASS);
mixer_enable(&mixer);
break;
case RF_PATH_FILTER_HIGH_PASS:
rf_path->switchctrl &= ~SWITCHCTRL_MIX_BYPASS;
rf_path->switchctrl |= SWITCHCTRL_HP;
mixer_enable(&mixer);
break;
}
switchctrl_set(rf_path, rf_path->switchctrl);
}
void rf_path_set_lna(rf_path_t* const rf_path, const uint_fast8_t enable)
{
if (enable) {
if (rf_path->switchctrl & SWITCHCTRL_TX) {
/* AMP_BYPASS=0, NO_RX_AMP_PWR=1, NO_TX_AMP_PWR=0 */
rf_path->switchctrl |= SWITCHCTRL_NO_RX_AMP_PWR;
rf_path->switchctrl &=
~(SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_NO_TX_AMP_PWR);
} else {
/* AMP_BYPASS=0, NO_RX_AMP_PWR=0, NO_TX_AMP_PWR=1 */
rf_path->switchctrl |= SWITCHCTRL_NO_TX_AMP_PWR;
rf_path->switchctrl &=
~(SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_NO_RX_AMP_PWR);
}
} else {
/* AMP_BYPASS=1, NO_RX_AMP_PWR=1, NO_TX_AMP_PWR=1 */
rf_path->switchctrl |= SWITCHCTRL_AMP_BYPASS | SWITCHCTRL_NO_TX_AMP_PWR |
SWITCHCTRL_NO_RX_AMP_PWR;
}
switchctrl_set(rf_path, rf_path->switchctrl);
}
/* antenna port power control */
void rf_path_set_antenna(rf_path_t* const rf_path, const uint_fast8_t enable)
{
if (enable) {
rf_path->switchctrl |= SWITCHCTRL_ANT_PWR;
} else {
rf_path->switchctrl &= ~(SWITCHCTRL_ANT_PWR);
}
switchctrl_set(rf_path, rf_path->switchctrl);
}
#ifdef IS_PRALINE
void narrowband_filter_set(const uint8_t value)
{
gpio_write(platform_gpio()->aa_en, value & 1);
}
#endif