firmware: add MAX2831 support to max283x.c

This commit is contained in:
Antoine van Gelder
2026-03-03 13:40:25 +02:00
parent 5275150bf0
commit bd87a5a1b4
11 changed files with 299 additions and 145 deletions

View File

@@ -185,9 +185,9 @@ bool fpga_if_xcvr_selftest(void)
fpga_set_tx_nco_pstep(&fpga, 64); // NCO phase increment
fpga_set_tx_nco_enable(&fpga, true); // TX enable
rf_path_set_direction(&rf_path, RF_PATH_DIRECTION_RX_CALIBRATION);
max2831_set_lna_gain(&max283x, 16);
max2831_set_vga_gain(&max283x, 36);
max2831_set_frequency(&max283x, 2500000000);
max283x_set_lna_gain(&max283x, 16);
max283x_set_vga_gain(&max283x, 36);
max283x_set_frequency(&max283x, 2500000000);
// Capture 1: 4 Msps, tone at 0.5 MHz, narrowband filter OFF
sample_rate_set(4ULL * FP_ONE_MHZ, true);

View File

@@ -27,8 +27,6 @@
#include "sgpio.h"
#include "si5351c.h"
#include "spi_ssp.h"
#include "max2831.h"
#include "max2831_target.h"
#include "max283x.h"
#include "max5864.h"
#include "max5864_target.h"
@@ -247,21 +245,6 @@ const ssp_config_t ssp_config_max283x = {
.clock_prescale_rate = 2,
.gpio_select = &gpio_max283x_select,
};
static struct gpio gpio_max2831_enable = GPIO(7, 1);
static struct gpio gpio_max2831_rx_enable = GPIO(7, 2);
static struct gpio gpio_max2831_rxhp = GPIO(6, 29);
static struct gpio gpio_max2831_ld = GPIO(4, 11);
max2831_driver_t max283x = {
.bus = &spi_bus_ssp1,
.gpio_enable = &gpio_max2831_enable,
.gpio_rxtx = &gpio_max2831_rx_enable,
.gpio_rxhp = &gpio_max2831_rxhp,
.gpio_ld = &gpio_max2831_ld,
.target_init = max2831_target_init,
.set_mode = max2831_target_set_mode,
};
#else
const ssp_config_t ssp_config_max283x = {
/* FIXME speed up once everything is working reliably */
@@ -276,9 +259,9 @@ const ssp_config_t ssp_config_max283x = {
.clock_prescale_rate = 2,
.gpio_select = &gpio_max283x_select,
};
#endif
max283x_driver_t max283x = {};
#endif
const ssp_config_t ssp_config_max5864 = {
/* FIXME speed up once everything is working reliably */

View File

@@ -34,7 +34,6 @@ extern "C" {
#include "si5351c.h"
#include "spi_ssp.h"
#include "max2831.h"
#include "max283x.h"
#include "max5864.h"
#include "mixer.h"
@@ -396,14 +395,11 @@ extern const ssp_config_t ssp_config_w25q80bv;
extern const ssp_config_t ssp_config_max283x;
extern const ssp_config_t ssp_config_max5864;
#ifndef PRALINE
extern max283x_driver_t max283x;
#else
extern max2831_driver_t max283x;
#ifdef PRALINE
extern ice40_spi_driver_t ice40;
extern fpga_driver_t fpga;
#endif
extern max283x_driver_t max283x;
extern max5864_driver_t max5864;
extern mixer_driver_t mixer;
extern w25q80bv_driver_t spi_flash;
@@ -419,7 +415,6 @@ void clock_gen_shutdown(void);
void ssp1_set_mode_max283x(void);
void ssp1_set_mode_max5864(void);
#ifdef PRALINE
void ssp1_set_mode_max2831(void);
void ssp1_set_mode_ice40(void);
#endif

View File

@@ -37,8 +37,8 @@ typedef enum {
MAX2831_MODE_STANDBY,
MAX2831_MODE_TX,
MAX2831_MODE_RX,
MAX2831_MODE_TX_CALIBRATION,
MAX2831_MODE_RX_CALIBRATION,
MAX2831_MODE_TX_CALIBRATION,
} max2831_mode_t;
typedef enum {

View File

@@ -25,45 +25,60 @@
#include "gpio.h"
#include "gpio_lpc.h"
#include "max2837.h"
#include "max2837_target.h"
#include "max2839.h"
#include "max2839_target.h"
#include "spi_bus.h"
extern spi_bus_t spi_bus_ssp1;
#ifdef PRALINE
static struct gpio gpio_max2837_enable = GPIO(6, 29);
static struct gpio gpio_max2837_rx_enable = GPIO(3, 3);
static struct gpio gpio_max2837_tx_enable = GPIO(3, 2);
static struct gpio gpio_max283x_enable = GPIO(7, 1);
static struct gpio gpio_max283x_rx_enable = GPIO(7, 2);
static struct gpio gpio_max2831_rxhp = GPIO(6, 29);
static struct gpio gpio_max2831_ld = GPIO(4, 11);
#else
static struct gpio gpio_max2837_enable = GPIO(2, 6);
static struct gpio gpio_max2837_rx_enable = GPIO(2, 5);
static struct gpio gpio_max2837_tx_enable = GPIO(2, 4);
static struct gpio gpio_max283x_enable = GPIO(2, 6);
static struct gpio gpio_max283x_rx_enable = GPIO(2, 5);
static struct gpio gpio_max283x_tx_enable = GPIO(2, 4);
#endif
#ifdef PRALINE
max2831_driver_t max2831 = {
.bus = &spi_bus_ssp1,
.gpio_enable = &gpio_max283x_enable,
.gpio_rxtx = &gpio_max283x_rx_enable,
.gpio_rxhp = &gpio_max2831_rxhp,
.gpio_ld = &gpio_max2831_ld,
.target_init = max2831_target_init,
.set_mode = max2831_target_set_mode,
};
#else
max2837_driver_t max2837 = {
.bus = &spi_bus_ssp1,
.gpio_enable = &gpio_max2837_enable,
.gpio_rx_enable = &gpio_max2837_rx_enable,
.gpio_tx_enable = &gpio_max2837_tx_enable,
.gpio_enable = &gpio_max283x_enable,
.gpio_rx_enable = &gpio_max283x_rx_enable,
.gpio_tx_enable = &gpio_max283x_tx_enable,
.target_init = max2837_target_init,
.set_mode = max2837_target_set_mode,
};
max2839_driver_t max2839 = {
.bus = &spi_bus_ssp1,
.gpio_enable = &gpio_max2837_enable,
.gpio_rxtx = &gpio_max2837_rx_enable,
.gpio_enable = &gpio_max283x_enable,
.gpio_rxtx = &gpio_max283x_rx_enable,
.target_init = max2839_target_init,
.set_mode = max2839_target_set_mode,
};
#endif
/* Initialize chip. */
void max283x_setup(max283x_driver_t* const drv, max283x_variant_t type)
{
drv->type = type;
switch (type) {
#ifdef PRALINE
case MAX2831_VARIANT:
memcpy(&drv->drv.max2831, &max2831, sizeof(max2831));
max2831_setup(&drv->drv.max2831);
break;
#else
case MAX2837_VARIANT:
memcpy(&drv->drv.max2837, &max2837, sizeof(max2837));
max2837_setup(&drv->drv.max2837);
@@ -73,14 +88,64 @@ void max283x_setup(max283x_driver_t* const drv, max283x_variant_t type)
memcpy(&drv->drv.max2839, &max2839, sizeof(max2839));
max2839_setup(&drv->drv.max2839);
break;
#endif
}
}
/* Returns the number of registers supported by the driver. */
uint16_t max283x_num_regs(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
return MAX2831_NUM_REGS;
break;
#else
case MAX2837_VARIANT:
return MAX2837_NUM_REGS;
break;
case MAX2839_VARIANT:
return MAX2839_NUM_REGS;
break;
#endif
}
return 0;
}
/* Returns the maximum data register value supported by the driver. */
uint16_t max283x_data_regs_max_value(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
return MAX2831_DATA_REGS_MAX_VALUE;
break;
#else
case MAX2837_VARIANT:
return MAX2837_DATA_REGS_MAX_VALUE;
break;
case MAX2839_VARIANT:
return MAX2839_DATA_REGS_MAX_VALUE;
break;
#endif
}
return 0;
}
/* Read a register via SPI. Save a copy to memory and return
* value. Mark clean. */
uint16_t max283x_reg_read(max283x_driver_t* const drv, uint8_t r)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
return max2831_reg_read(&drv->drv.max2831, r);
break;
#else
case MAX2837_VARIANT:
return max2837_reg_read(&drv->drv.max2837, r);
break;
@@ -88,6 +153,7 @@ uint16_t max283x_reg_read(max283x_driver_t* const drv, uint8_t r)
case MAX2839_VARIANT:
return max2839_reg_read(&drv->drv.max2839, r);
break;
#endif
}
return 0;
@@ -98,6 +164,11 @@ uint16_t max283x_reg_read(max283x_driver_t* const drv, uint8_t r)
void max283x_reg_write(max283x_driver_t* const drv, uint8_t r, uint16_t v)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_reg_write(&drv->drv.max2831, r, v);
break;
#else
case MAX2837_VARIANT:
max2837_reg_write(&drv->drv.max2837, r, v);
break;
@@ -105,6 +176,7 @@ void max283x_reg_write(max283x_driver_t* const drv, uint8_t r, uint16_t v)
case MAX2839_VARIANT:
max2839_reg_write(&drv->drv.max2839, r, v);
break;
#endif
}
}
@@ -114,6 +186,11 @@ void max283x_reg_write(max283x_driver_t* const drv, uint8_t r, uint16_t v)
void max283x_regs_commit(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_regs_commit(&drv->drv.max2831);
break;
#else
case MAX2837_VARIANT:
max2837_regs_commit(&drv->drv.max2837);
break;
@@ -121,12 +198,18 @@ void max283x_regs_commit(max283x_driver_t* const drv)
case MAX2839_VARIANT:
max2839_regs_commit(&drv->drv.max2839);
break;
#endif
}
}
void max283x_set_mode(max283x_driver_t* const drv, const max283x_mode_t new_mode)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_set_mode(&drv->drv.max2831, (max2831_mode_t) new_mode);
break;
#else
case MAX2837_VARIANT:
max2837_set_mode(&drv->drv.max2837, (max2837_mode_t) new_mode);
break;
@@ -134,12 +217,18 @@ void max283x_set_mode(max283x_driver_t* const drv, const max283x_mode_t new_mode
case MAX2839_VARIANT:
max2839_set_mode(&drv->drv.max2839, (max2839_mode_t) new_mode);
break;
#endif
}
}
max283x_mode_t max283x_mode(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
return (max283x_mode_t) max2831_mode(&drv->drv.max2831);
break;
#else
case MAX2837_VARIANT:
return (max283x_mode_t) max2837_mode(&drv->drv.max2837);
break;
@@ -147,18 +236,20 @@ max283x_mode_t max283x_mode(max283x_driver_t* const drv)
case MAX2839_VARIANT:
return (max283x_mode_t) max2839_mode(&drv->drv.max2839);
break;
#endif
}
return 0;
}
//max283x_mode_t max283x_mode(max283x_driver_t* const drv);
//void max283x_set_mode(max283x_driver_t* const drv, const max283x_mode_t new_mode);
/* Turn on/off all chip functions. Does not control oscillator and CLKOUT */
void max283x_start(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_start(&drv->drv.max2831);
break;
#else
case MAX2837_VARIANT:
max2837_start(&drv->drv.max2837);
break;
@@ -166,12 +257,18 @@ void max283x_start(max283x_driver_t* const drv)
case MAX2839_VARIANT:
max2839_start(&drv->drv.max2839);
break;
#endif
}
}
void max283x_stop(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_stop(&drv->drv.max2831);
break;
#else
case MAX2837_VARIANT:
max2837_stop(&drv->drv.max2837);
break;
@@ -179,6 +276,7 @@ void max283x_stop(max283x_driver_t* const drv)
case MAX2839_VARIANT:
max2839_stop(&drv->drv.max2839);
break;
#endif
}
}
@@ -187,6 +285,11 @@ void max283x_stop(max283x_driver_t* const drv)
void max283x_set_frequency(max283x_driver_t* const drv, uint32_t freq)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_set_frequency(&drv->drv.max2831, freq);
break;
#else
case MAX2837_VARIANT:
max2837_set_frequency(&drv->drv.max2837, freq);
break;
@@ -194,14 +297,28 @@ void max283x_set_frequency(max283x_driver_t* const drv, uint32_t freq)
case MAX2839_VARIANT:
max2839_set_frequency(&drv->drv.max2839, freq);
break;
#endif
}
}
uint32_t max283x_set_lpf_bandwidth(
max283x_driver_t* const drv,
const max283x_mode_t mode,
const uint32_t bandwidth_hz)
{
#ifndef PRALINE
(void) mode;
#endif
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
return max2831_set_lpf_bandwidth(
&drv->drv.max2831,
(max2831_mode_t) mode,
bandwidth_hz);
break;
#else
case MAX2837_VARIANT:
return max2837_set_lpf_bandwidth(&drv->drv.max2837, bandwidth_hz);
break;
@@ -209,6 +326,7 @@ uint32_t max283x_set_lpf_bandwidth(
case MAX2839_VARIANT:
return max2839_set_lpf_bandwidth(&drv->drv.max2839, bandwidth_hz);
break;
#endif
}
return 0;
@@ -217,6 +335,11 @@ uint32_t max283x_set_lpf_bandwidth(
bool max283x_set_lna_gain(max283x_driver_t* const drv, const uint32_t gain_db)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
return max2831_set_lna_gain(&drv->drv.max2831, gain_db);
break;
#else
case MAX2837_VARIANT:
return max2837_set_lna_gain(&drv->drv.max2837, gain_db);
break;
@@ -224,6 +347,7 @@ bool max283x_set_lna_gain(max283x_driver_t* const drv, const uint32_t gain_db)
case MAX2839_VARIANT:
return max2839_set_lna_gain(&drv->drv.max2839, gain_db);
break;
#endif
}
return false;
@@ -232,6 +356,11 @@ bool max283x_set_lna_gain(max283x_driver_t* const drv, const uint32_t gain_db)
bool max283x_set_vga_gain(max283x_driver_t* const drv, const uint32_t gain_db)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
return max2831_set_vga_gain(&drv->drv.max2831, gain_db);
break;
#else
case MAX2837_VARIANT:
return max2837_set_vga_gain(&drv->drv.max2837, gain_db);
break;
@@ -239,6 +368,7 @@ bool max283x_set_vga_gain(max283x_driver_t* const drv, const uint32_t gain_db)
case MAX2839_VARIANT:
return max2839_set_vga_gain(&drv->drv.max2839, gain_db);
break;
#endif
}
return false;
@@ -247,6 +377,11 @@ bool max283x_set_vga_gain(max283x_driver_t* const drv, const uint32_t gain_db)
bool max283x_set_txvga_gain(max283x_driver_t* const drv, const uint32_t gain_db)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
return max2831_set_txvga_gain(&drv->drv.max2831, gain_db);
break;
#else
case MAX2837_VARIANT:
return max2837_set_txvga_gain(&drv->drv.max2837, gain_db);
break;
@@ -254,6 +389,7 @@ bool max283x_set_txvga_gain(max283x_driver_t* const drv, const uint32_t gain_db)
case MAX2839_VARIANT:
return max2839_set_txvga_gain(&drv->drv.max2839, gain_db);
break;
#endif
}
return false;
@@ -262,6 +398,11 @@ bool max283x_set_txvga_gain(max283x_driver_t* const drv, const uint32_t gain_db)
void max283x_tx(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_tx(&drv->drv.max2831);
break;
#else
case MAX2837_VARIANT:
max2837_tx(&drv->drv.max2837);
break;
@@ -269,12 +410,18 @@ void max283x_tx(max283x_driver_t* const drv)
case MAX2839_VARIANT:
max2839_tx(&drv->drv.max2839);
break;
#endif
}
}
void max283x_rx(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_rx(&drv->drv.max2831);
break;
#else
case MAX2837_VARIANT:
max2837_rx(&drv->drv.max2837);
break;
@@ -282,5 +429,71 @@ void max283x_rx(max283x_driver_t* const drv)
case MAX2839_VARIANT:
max2839_rx(&drv->drv.max2839);
break;
#endif
}
}
void max283x_set_rx_hpf_frequency(
max283x_driver_t* const drv,
const max283x_rx_hpf_freq_t freq)
{
#ifndef PRALINE
(void) freq;
#endif
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_set_rx_hpf_frequency(
&drv->drv.max2831,
(max2831_rx_hpf_freq_t) freq);
break;
#else
case MAX2837_VARIANT:
// unsupported
break;
case MAX2839_VARIANT:
// unsupported
break;
#endif
}
}
void max283x_tx_calibration(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_tx_calibration(&drv->drv.max2831);
break;
#else
case MAX2837_VARIANT:
// unsupported - use max283x_set_mode instead
break;
case MAX2839_VARIANT:
// unsupported - use max283x_set_mode instead
break;
#endif
}
}
void max283x_rx_calibration(max283x_driver_t* const drv)
{
switch (drv->type) {
#ifdef PRALINE
case MAX2831_VARIANT:
max2831_rx_calibration(&drv->drv.max2831);
break;
#else
case MAX2837_VARIANT:
// unsupported - use max283x_set_mode instead
break;
case MAX2839_VARIANT:
// unsupported - use max283x_set_mode instead
break;
#endif
}
}

View File

@@ -30,6 +30,8 @@
#include "gpio.h"
#include "gpio_lpc.h"
#include "max2831.h"
#include "max2831_target.h"
#include "max2837.h"
#include "max2837_target.h"
#include "max2839.h"
@@ -47,22 +49,43 @@ typedef enum {
} max283x_mode_t;
typedef enum {
MAX283x_RX_HPF_100_HZ = 0,
MAX283x_RX_HPF_4_KHZ = 1,
MAX283x_RX_HPF_30_KHZ = 2,
MAX283x_RX_HPF_600_KHZ = 3,
} max283x_rx_hpf_freq_t;
typedef enum {
#ifdef PRALINE
MAX2831_VARIANT,
#else
MAX2837_VARIANT,
MAX2839_VARIANT,
#endif
} max283x_variant_t;
typedef struct {
max283x_variant_t type;
union {
#ifdef PRALINE
max2831_driver_t max2831;
#else
max2837_driver_t max2837;
max2839_driver_t max2839;
#endif
} drv;
} max283x_driver_t;
/* Initialize chip. */
void max283x_setup(max283x_driver_t* const drv, max283x_variant_t type);
/* Returns the number of registers supported by the driver. */
uint16_t max283x_num_regs(max283x_driver_t* const drv);
/* Returns the maximum data register value supported by the driver. */
uint16_t max283x_data_regs_max_value(max283x_driver_t* const drv);
/* Read a register via SPI. Save a copy to memory and return
* value. Mark clean. */
uint16_t max283x_reg_read(max283x_driver_t* const drv, uint8_t r);
@@ -88,6 +111,7 @@ void max283x_stop(max283x_driver_t* const drv);
void max283x_set_frequency(max283x_driver_t* const drv, uint32_t freq);
uint32_t max283x_set_lpf_bandwidth(
max283x_driver_t* const drv,
const max283x_mode_t mode,
const uint32_t bandwidth_hz);
bool max283x_set_lna_gain(max283x_driver_t* const drv, const uint32_t gain_db);
@@ -98,4 +122,13 @@ bool max283x_set_txvga_gain(max283x_driver_t* const drv, const uint32_t gain_db)
void max283x_tx(max283x_driver_t* const drv);
void max283x_rx(max283x_driver_t* const drv);
/* Set MAX2831 receiver high-pass filter corner frequency in Hz */
void max283x_set_rx_hpf_frequency(
max283x_driver_t* const drv,
const max283x_rx_hpf_freq_t freq);
/* Perform MAX2831 TX and RX calibration. */
void max283x_tx_calibration(max283x_driver_t* const drv);
void max283x_rx_calibration(max283x_driver_t* const drv);
#endif // __MAX283x_H

View File

@@ -395,12 +395,12 @@ static bool radio_update_bandwidth(radio_t* const radio, uint64_t* bank)
uint32_t lpf_bandwidth = auto_bandwidth(radio);
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] != lpf_bandwidth) {
max2831_set_lpf_bandwidth(&max283x, MAX2831_MODE_TX, lpf_bandwidth);
max283x_set_lpf_bandwidth(&max283x, MAX283x_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);
max283x_set_lpf_bandwidth(&max283x, MAX283x_MODE_RX, lpf_bandwidth);
radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] = lpf_bandwidth;
new_bw = true;
}
@@ -417,9 +417,9 @@ static bool radio_update_bandwidth(radio_t* const radio, uint64_t* bank)
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;
const max283x_rx_hpf_freq_t hpf_bandwidth = MAX283x_RX_HPF_30_KHZ;
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] != hpf_bandwidth) {
max2831_set_rx_hpf_frequency(&max283x, hpf_bandwidth);
max283x_set_rx_hpf_frequency(&max283x, hpf_bandwidth);
radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] = hpf_bandwidth;
new_bw = true;
}
@@ -443,7 +443,7 @@ static bool radio_update_bandwidth(radio_t* const radio, uint64_t* bank)
}
if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] != lpf_bandwidth) {
max283x_set_lpf_bandwidth(&max283x, lpf_bandwidth);
max283x_set_lpf_bandwidth(&max283x, MAX283x_MODE_TX, lpf_bandwidth);
radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_RX] = lpf_bandwidth;
radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_TX] = lpf_bandwidth;
radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] = lpf_bandwidth;
@@ -508,19 +508,11 @@ static bool radio_update_gain(radio_t* const radio, uint64_t* bank)
gain = bank[RADIO_GAIN_TX_IF];
if ((gain != RADIO_UNSET) &&
(gain != radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_TX_IF])) {
#ifdef PRALINE
max2831_set_txvga_gain(&max283x, gain);
#else
max283x_set_txvga_gain(&max283x, gain);
#endif
radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_TX_IF] = gain;
new_gain = true;
} else if (radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_TX_IF] == RADIO_UNSET) {
#ifdef PRALINE
max2831_set_txvga_gain(&max283x, DEFAULT_GAIN_IF);
#else
max283x_set_txvga_gain(&max283x, DEFAULT_GAIN_IF);
#endif
radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_TX_IF] = DEFAULT_GAIN_IF;
new_gain = true;
}
@@ -528,19 +520,11 @@ static bool radio_update_gain(radio_t* const radio, uint64_t* bank)
gain = bank[RADIO_GAIN_RX_IF];
if ((gain != RADIO_UNSET) &&
(gain != radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_TX_IF])) {
#ifdef PRALINE
max2831_set_lna_gain(&max283x, gain);
#else
max283x_set_lna_gain(&max283x, gain);
#endif
radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_TX_IF] = gain;
new_gain = true;
} else if (radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_TX_IF] == RADIO_UNSET) {
#ifdef PRALINE
max2831_set_lna_gain(&max283x, DEFAULT_GAIN_IF);
#else
max283x_set_lna_gain(&max283x, DEFAULT_GAIN_IF);
#endif
radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_TX_IF] = DEFAULT_GAIN_IF;
new_gain = true;
}
@@ -548,19 +532,11 @@ static bool radio_update_gain(radio_t* const radio, uint64_t* bank)
gain = bank[RADIO_GAIN_RX_BB];
if ((gain != RADIO_UNSET) &&
(gain != radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_RX_BB])) {
#ifdef PRALINE
max2831_set_vga_gain(&max283x, gain);
#else
max283x_set_vga_gain(&max283x, gain);
#endif
radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_RX_BB] = gain;
new_gain = true;
} else if (radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_RX_BB] == RADIO_UNSET) {
#ifdef PRALINE
max2831_set_vga_gain(&max283x, DEFAULT_GAIN_BB);
#else
max283x_set_vga_gain(&max283x, DEFAULT_GAIN_BB);
#endif
radio->config[RADIO_BANK_APPLIED][RADIO_GAIN_RX_BB] = DEFAULT_GAIN_BB;
new_gain = true;
}

View File

@@ -31,7 +31,6 @@
#include "gpio_lpc.h"
#include "platform_detect.h"
#include "mixer.h"
#include "max2831.h"
#include "max283x.h"
#include "max5864.h"
#include "sgpio.h"
@@ -443,16 +442,15 @@ void rf_path_init(rf_path_t* const rf_path)
ssp1_set_mode_max283x();
#ifdef PRALINE
max2831_setup(&max283x);
max2831_start(&max283x);
max283x_setup(&max283x, MAX2831_VARIANT);
#else
if (detected_platform() == BOARD_ID_HACKRF1_R9) {
max283x_setup(&max283x, MAX2839_VARIANT);
} else {
max283x_setup(&max283x, MAX2837_VARIANT);
}
max283x_start(&max283x);
#endif
max283x_start(&max283x);
// On HackRF One, the mixer is now set up earlier in boot.
#ifndef HACKRF_ONE
@@ -481,11 +479,7 @@ void rf_path_set_direction(rf_path_t* const rf_path, const rf_path_direction_t d
ssp1_set_mode_max5864();
max5864_tx(&max5864);
ssp1_set_mode_max283x();
#ifdef PRALINE
max2831_tx(&max283x);
#else
max283x_tx(&max283x);
#endif
sgpio_configure(&sgpio_config, SGPIO_DIRECTION_TX);
break;
@@ -503,11 +497,7 @@ void rf_path_set_direction(rf_path_t* const rf_path, const rf_path_direction_t d
ssp1_set_mode_max5864();
max5864_rx(&max5864);
ssp1_set_mode_max283x();
#ifdef PRALINE
max2831_rx(&max283x);
#else
max283x_rx(&max283x);
#endif
sgpio_configure(&sgpio_config, SGPIO_DIRECTION_RX);
break;
@@ -520,9 +510,9 @@ void rf_path_set_direction(rf_path_t* const rf_path, const rf_path_direction_t d
max5864_xcvr(&max5864);
ssp1_set_mode_max283x();
if (direction == RF_PATH_DIRECTION_TX_CALIBRATION) {
max2831_tx_calibration(&max283x);
max283x_tx_calibration(&max283x);
} else {
max2831_rx_calibration(&max283x);
max283x_rx_calibration(&max283x);
}
sgpio_configure(&sgpio_config, SGPIO_DIRECTION_RX);
break;
@@ -537,11 +527,7 @@ void rf_path_set_direction(rf_path_t* const rf_path, const rf_path_direction_t d
ssp1_set_mode_max5864();
max5864_standby(&max5864);
ssp1_set_mode_max283x();
#ifdef PRALINE
max2831_set_mode(&max283x, MAX2831_MODE_STANDBY);
#else
max283x_set_mode(&max283x, MAX283x_MODE_STANDBY);
#endif
sgpio_configure(&sgpio_config, SGPIO_DIRECTION_RX);
break;
}

View File

@@ -25,9 +25,6 @@
#include "hackrf_ui.h"
#include "hackrf_core.h"
#include "mixer.h"
#include "max2831.h"
#include "max2837.h"
#include "max2839.h"
#include "sgpio.h"
#include "operacake.h"
#include "platform_detect.h"
@@ -168,35 +165,35 @@ bool tuning_set_frequency(
rf = rf + offset;
}
max2831_mode_t prior_max2831_mode = max2831_mode(&max283x);
max2831_set_mode(&max283x, MAX2831_MODE_STANDBY);
max283x_mode_t prior_max283x_mode = max283x_mode(&max283x);
max283x_set_mode(&max283x, MAX283x_MODE_STANDBY);
if (cfg->if_mhz == 0) {
rf_path_set_filter(&rf_path, RF_PATH_FILTER_BYPASS);
max2831_set_frequency(&max283x, rf);
max283x_set_frequency(&max283x, rf);
sgpio_cpld_set_mixer_invert(&sgpio_config, 0);
} else if (cfg->if_mhz > freq_mhz) {
rf_path_set_filter(&rf_path, RF_PATH_FILTER_LOW_PASS);
if (cfg->high_lo) {
mixer_freq_hz = FREQ_ONE_MHZ * cfg->if_mhz + rf;
real_mixer_freq_hz = mixer_set_frequency(&mixer, mixer_freq_hz);
max2831_set_frequency(&max283x, real_mixer_freq_hz - rf);
max283x_set_frequency(&max283x, real_mixer_freq_hz - rf);
sgpio_cpld_set_mixer_invert(&sgpio_config, 1);
} else {
mixer_freq_hz = FREQ_ONE_MHZ * cfg->if_mhz - rf;
real_mixer_freq_hz = mixer_set_frequency(&mixer, mixer_freq_hz);
max2831_set_frequency(&max283x, real_mixer_freq_hz + rf);
max283x_set_frequency(&max283x, real_mixer_freq_hz + rf);
sgpio_cpld_set_mixer_invert(&sgpio_config, 0);
}
} else {
rf_path_set_filter(&rf_path, RF_PATH_FILTER_HIGH_PASS);
mixer_freq_hz = rf - FREQ_ONE_MHZ * cfg->if_mhz;
real_mixer_freq_hz = mixer_set_frequency(&mixer, mixer_freq_hz);
max2831_set_frequency(&max283x, rf - real_mixer_freq_hz);
max283x_set_frequency(&max283x, rf - real_mixer_freq_hz);
sgpio_cpld_set_mixer_invert(&sgpio_config, 0);
}
max2831_set_mode(&max283x, prior_max2831_mode);
max283x_set_mode(&max283x, prior_max283x_mode);
hackrf_ui()->set_frequency(freq);
operacake_set_range(freq_mhz);
return true;
@@ -223,11 +220,8 @@ bool set_freq_explicit(
}
rf_path_set_filter(&rf_path, path);
#ifdef PRALINE
max2831_set_frequency(&max283x, if_freq_hz);
#else
max283x_set_frequency(&max283x, if_freq_hz);
#endif
if (lo_freq_hz > if_freq_hz) {
sgpio_cpld_set_mixer_invert(&sgpio_config, 1);
} else {

View File

@@ -213,6 +213,7 @@ macro(DeclareTargets)
${SRC_M4}
${PATH_HACKRF_FIRMWARE_COMMON}/fpga.c
${PATH_HACKRF_FIRMWARE_COMMON}/ice40_spi.c
${PATH_HACKRF_FIRMWARE_COMMON}/max283x.c
${PATH_HACKRF_FIRMWARE_COMMON}/max2831.c
${PATH_HACKRF_FIRMWARE_COMMON}/max2831_target.c
)
@@ -247,9 +248,9 @@ macro(DeclareTargets)
set_target_properties(${PROJECT_NAME}_m0.elf PROPERTIES COMPILE_FLAGS "${CFLAGS_M0}")
set_target_properties(${PROJECT_NAME}_m0.elf PROPERTIES LINK_FLAGS "${LDFLAGS_M0}")
DeclareTarget("${PROJECT_NAME}" "" "${CFLAGS_M4}" "${LDFLAGS_M4}")
DeclareTarget("${PROJECT_NAME}" "_ram" "${CFLAGS_M4_RAM} -DRAM_MODE" "${LDFLAGS_M4_RAM}")
DeclareTarget("${PROJECT_NAME}" "_dfu" "${CFLAGS_M4_RAM} -DDFU_MODE" "${LDFLAGS_M4_RAM}")
DeclareTarget("${PROJECT_NAME}" "" "${CFLAGS_M4}" "${LDFLAGS_M4}")
DeclareTarget("${PROJECT_NAME}" "_ram" "${CFLAGS_M4_RAM} -DRAM_MODE" "${LDFLAGS_M4_RAM}")
DeclareTarget("${PROJECT_NAME}" "_dfu" "${CFLAGS_M4_RAM} -DDFU_MODE" "${LDFLAGS_M4_RAM}")
add_custom_target(
${PROJECT_NAME}.dfu ${DFU_ALL}

View File

@@ -40,9 +40,10 @@ usb_request_status_t usb_vendor_request_write_max283x(
const usb_transfer_stage_t stage)
{
if (stage == USB_TRANSFER_STAGE_SETUP) {
#ifndef PRALINE
if (endpoint->setup.index < MAX2837_NUM_REGS) {
if (endpoint->setup.value < MAX2837_DATA_REGS_MAX_VALUE) {
uint16_t num_regs = max283x_num_regs(&max283x);
uint16_t data_regs_max_value = max283x_data_regs_max_value(&max283x);
if (endpoint->setup.index < num_regs) {
if (endpoint->setup.value < data_regs_max_value) {
max283x_reg_write(
&max283x,
endpoint->setup.index,
@@ -51,18 +52,6 @@ usb_request_status_t usb_vendor_request_write_max283x(
return USB_REQUEST_STATUS_OK;
}
}
#else
if (endpoint->setup.index < MAX2831_NUM_REGS) {
if (endpoint->setup.value < MAX2831_DATA_REGS_MAX_VALUE) {
max2831_reg_write(
&max283x,
endpoint->setup.index,
endpoint->setup.value);
usb_transfer_schedule_ack(endpoint->in);
return USB_REQUEST_STATUS_OK;
}
}
#endif
return USB_REQUEST_STATUS_STALL;
} else {
return USB_REQUEST_STATUS_OK;
@@ -74,8 +63,8 @@ usb_request_status_t usb_vendor_request_read_max283x(
const usb_transfer_stage_t stage)
{
if (stage == USB_TRANSFER_STAGE_SETUP) {
#ifndef PRALINE
if (endpoint->setup.index < MAX2837_NUM_REGS) {
uint16_t num_regs = max283x_num_regs(&max283x);
if (endpoint->setup.index < num_regs) {
const uint16_t value =
max283x_reg_read(&max283x, endpoint->setup.index);
endpoint->buffer[0] = value & 0xff;
@@ -89,22 +78,6 @@ usb_request_status_t usb_vendor_request_read_max283x(
usb_transfer_schedule_ack(endpoint->out);
return USB_REQUEST_STATUS_OK;
}
#else
if (endpoint->setup.index < MAX2831_NUM_REGS) {
const uint16_t value =
max2831_reg_read(&max283x, endpoint->setup.index);
endpoint->buffer[0] = value & 0xff;
endpoint->buffer[1] = value >> 8;
usb_transfer_schedule_block(
endpoint->in,
&endpoint->buffer,
2,
NULL,
NULL);
usb_transfer_schedule_ack(endpoint->out);
return USB_REQUEST_STATUS_OK;
}
#endif
return USB_REQUEST_STATUS_STALL;
} else {
return USB_REQUEST_STATUS_OK;