max283x: Move platform switch inside max283x_setup().

This commit is contained in:
Martin Ling 2026-04-06 21:21:01 +01:00
parent 02f5e6347f
commit 05d3ef58d0
3 changed files with 24 additions and 47 deletions

View file

@ -25,6 +25,7 @@
#include "max283x.h"
#include "platform_detect.h"
#include "platform_gpio.h"
#include "spi_bus.h"
@ -65,49 +66,41 @@ max2839_driver_t max2839 = {
#endif
/* Initialize chip. */
void max283x_setup(max283x_driver_t* const drv, max283x_variant_t type)
void max283x_setup(max283x_driver_t* const drv)
{
drv->type = type;
const platform_gpio_t* gpio = platform_gpio();
/* MAX283x GPIO PinMux */
switch (detected_platform()) {
case BOARD_ID_PRALINE:
#if defined(PRALINE) || defined(UNIVERSAL)
max2831.gpio_enable = gpio->max283x_enable;
max2831.gpio_rxtx = gpio->max283x_rx_enable;
max2831.gpio_rxhp = gpio->max2831_rxhp;
max2831.gpio_ld = gpio->max2831_ld;
#endif
#if !defined(PRALINE) || defined(UNIVERSAL)
max2837.gpio_enable = gpio->max283x_enable;
max2837.gpio_rx_enable = gpio->max283x_rx_enable;
max2837.gpio_tx_enable = gpio->max283x_tx_enable;
#endif
#if defined(HACKRF_ONE) || defined(UNIVERSAL)
max2839.gpio_enable = gpio->max283x_enable;
max2839.gpio_rxtx = gpio->max283x_rx_enable;
#endif
switch (drv->type) {
#if defined(PRALINE) || defined(UNIVERSAL)
case MAX2831_VARIANT:
drv->type = MAX2831_VARIANT;
max2831.gpio_enable = gpio->max283x_enable;
max2831.gpio_rxtx = gpio->max283x_rx_enable;
max2831.gpio_rxhp = gpio->max2831_rxhp;
max2831.gpio_ld = gpio->max2831_ld;
memcpy(&drv->drv.max2831, &max2831, sizeof(max2831));
max2831_setup(&drv->drv.max2831);
break;
#endif
#if !defined(PRALINE) || defined(UNIVERSAL)
case MAX2837_VARIANT:
memcpy(&drv->drv.max2837, &max2837, sizeof(max2837));
max2837_setup(&drv->drv.max2837);
break;
#endif
case BOARD_ID_HACKRF1_R9:
#if defined(HACKRF_ONE) || defined(UNIVERSAL)
case MAX2839_VARIANT:
drv->type = MAX2839_VARIANT;
max2839.gpio_enable = gpio->max283x_enable;
max2839.gpio_rxtx = gpio->max283x_rx_enable;
memcpy(&drv->drv.max2839, &max2839, sizeof(max2839));
max2839_setup(&drv->drv.max2839);
break;
#endif
break;
default:
#if !defined(PRALINE) || defined(UNIVERSAL)
drv->type = MAX2837_VARIANT;
max2837.gpio_enable = gpio->max283x_enable;
max2837.gpio_rx_enable = gpio->max283x_rx_enable;
max2837.gpio_tx_enable = gpio->max283x_tx_enable;
memcpy(&drv->drv.max2837, &max2837, sizeof(max2837));
max2837_setup(&drv->drv.max2837);
#endif
break;
}
}

View file

@ -82,7 +82,7 @@ typedef struct {
} max283x_driver_t;
/* Initialize chip. */
void max283x_setup(max283x_driver_t* const drv, max283x_variant_t type);
void max283x_setup(max283x_driver_t* const drv);
/* Returns the number of registers supported by the driver. */
uint16_t max283x_num_regs(max283x_driver_t* const drv);

View file

@ -484,23 +484,7 @@ void rf_path_init(rf_path_t* const rf_path)
max5864_shutdown(&max5864);
ssp1_set_mode_max283x();
switch (board_id) {
case BOARD_ID_PRALINE:
#if defined(PRALINE) || defined(UNIVERSAL)
max283x_setup(&max283x, MAX2831_VARIANT);
#endif
break;
case BOARD_ID_HACKRF1_R9:
#if defined(HACKRF_ONE) || defined(UNIVERSAL)
max283x_setup(&max283x, MAX2839_VARIANT);
#endif
break;
default:
#if !defined(PRALINE) || defined(UNIVERSAL)
max283x_setup(&max283x, MAX2837_VARIANT);
#endif
break;
}
max283x_setup(&max283x);
max283x_start(&max283x);
switch (board_id) {