Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion firmware/common/clock_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include <stdint.h>

#include "hackrf_core.h"
#include "drivers.h"
#include "hackrf_ui.h"
#include "i2c_bus.h"
#include "platform_detect.h"
Expand Down
2 changes: 1 addition & 1 deletion firmware/common/clock_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#include <libopencm3/lpc43xx/gpdma.h>
#include <libopencm3/lpc43xx/creg.h>

#include "drivers.h"
#include "gpdma.h"
#include "gpio.h"
#include "hackrf_core.h"
#ifdef IS_PRALINE
#include "fpga.h"
#include "platform_gpio.h"
Expand Down
2 changes: 1 addition & 1 deletion firmware/common/cpu_clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#endif

#include "delay.h"
#include "hackrf_core.h"
#include "drivers.h"
#include "i2c_bus.h"
#ifdef IS_NOT_RAD1O
#include "platform_detect.h"
Expand Down
2 changes: 1 addition & 1 deletion firmware/common/da7219.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <stdint.h>

#include "da7219.h"
#include "hackrf_core.h"
#include "drivers.h"
#include "i2c_bus.h"

#define DA7219_REG_CHIP_ID1 0x81
Expand Down
178 changes: 178 additions & 0 deletions firmware/common/drivers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
* Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
*
* 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 "drivers.h"

#include <stdbool.h>

#include <libopencm3/lpc43xx/memorymap.h>
#include <libopencm3/lpc43xx/ssp.h>

#include "clock_gen.h"
#include "i2c_lpc.h"
#include "max283x.h"
#include "max5864_target.h"
#include "spi_bus.h"
#include "w25q80bv_target.h"
#if defined(IS_PRALINE)
#include "fpga.h"
#include "ice40_spi.h"
#endif

i2c_bus_t i2c0 = {
.obj = (void*) I2C0_BASE,
.start = i2c_lpc_start,
.stop = i2c_lpc_stop,
.transfer = i2c_lpc_transfer,
};

i2c_bus_t i2c1 = {
.obj = (void*) I2C1_BASE,
.start = i2c_lpc_start,
.stop = i2c_lpc_stop,
.transfer = i2c_lpc_transfer,
};

// const i2c_lpc_config_t i2c_config_si5351c_slow_clock = {
// .duty_cycle_count = 15,
// };

const i2c_lpc_config_t i2c_config_si5351c_fast_clock = {
.duty_cycle_count = 255,
};

si5351c_driver_t clock_gen = {
.bus = &i2c0,
.i2c_address = 0x60,
};

ssp_config_t ssp_config_max283x = {
/* FIXME speed up once everything is working reliably */
/*
// Freq About 0.0498MHz / 49.8KHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
const uint8_t serial_clock_rate = 32;
const uint8_t clock_prescale_rate = 128;
*/
// Freq About 4.857MHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
.serial_clock_rate = 21,
.clock_prescale_rate = 2,
};

max283x_driver_t max283x = {};

ssp_config_t ssp_config_max5864 = {
/* FIXME speed up once everything is working reliably */
/*
// Freq About 0.0498MHz / 49.8KHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
const uint8_t serial_clock_rate = 32;
const uint8_t clock_prescale_rate = 128;
*/
// Freq About 4.857MHz => Freq = PCLK / (CPSDVSR * [SCR+1]) with PCLK=PLL1=204MHz
.data_bits = SSP_DATA_8BITS,
.serial_clock_rate = 21,
.clock_prescale_rate = 2,
};

spi_bus_t spi_bus_ssp1 = {
.obj = (void*) SSP1_BASE,
.config = &ssp_config_max5864,
.start = spi_ssp_start,
.stop = spi_ssp_stop,
.transfer = spi_ssp_transfer,
.transfer_gather = spi_ssp_transfer_gather,
};

max5864_driver_t max5864 = {
.bus = &spi_bus_ssp1,
.target_init = max5864_target_init,
};

ssp_config_t ssp_config_w25q80bv = {
.data_bits = SSP_DATA_8BITS,
.serial_clock_rate = 2,
.clock_prescale_rate = 2,
};

spi_bus_t spi_bus_ssp0 = {
.obj = (void*) SSP0_BASE,
.config = &ssp_config_w25q80bv,
.start = spi_ssp_start,
.stop = spi_ssp_stop,
.transfer = spi_ssp_transfer,
.transfer_gather = spi_ssp_transfer_gather,
};

w25q80bv_driver_t spi_flash = {
.bus = &spi_bus_ssp0,
.target_init = w25q80bv_target_init,
};

sgpio_config_t sgpio_config = {
.slice_mode_multislice = true,
};

#ifdef IS_PRALINE
ssp_config_t ssp_config_ice40_fpga = {
.data_bits = SSP_DATA_8BITS,
.spi_mode = SSP_CPOL_1_CPHA_1,
.serial_clock_rate = 21,
.clock_prescale_rate = 2,
};

ice40_spi_driver_t ice40 = {
.bus = &spi_bus_ssp1,
};

fpga_driver_t fpga = {
.bus = &ice40,
};
#endif

radio_t radio = {
.sample_rate_cb = sample_rate_set,
};

rf_path_t rf_path = {
.switchctrl = 0,
};

jtag_gpio_t jtag_gpio_cpld = {};

jtag_t jtag_cpld = {
.gpio = &jtag_gpio_cpld,
};

void ssp1_set_mode_max283x(void)
{
spi_bus_start(&spi_bus_ssp1, &ssp_config_max283x);
}

void ssp1_set_mode_max5864(void)
{
spi_bus_start(max5864.bus, &ssp_config_max5864);
}

#ifdef IS_PRALINE
void ssp1_set_mode_ice40(void)
{
spi_bus_start(&spi_bus_ssp1, &ssp_config_ice40_fpga);
}
#endif
77 changes: 77 additions & 0 deletions firmware/common/drivers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
*
* 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.
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include "cpld_jtag.h"
#include "i2c_bus.h"
#include "i2c_lpc.h"
#include "max283x.h"
#include "max5864.h"
#include "mixer.h"
#include "platform_detect.h" // IWYU pragma: keep
#include "radio.h"
#include "rf_path.h"
#include "sgpio.h"
#include "si5351c.h"
#include "spi_ssp.h"
#include "w25q80bv.h"
#if defined(IS_PRALINE)
#include "fpga.h"
#include "ice40_spi.h"
#endif

/* TODO: Hide these configurations */
extern const i2c_lpc_config_t i2c_config_si5351c_fast_clock;
extern si5351c_driver_t clock_gen;
extern ssp_config_t ssp_config_max283x;
extern ssp_config_t ssp_config_max5864;
extern ssp_config_t ssp_config_w25q80bv;

#if defined(IS_PRALINE)
extern ssp_config_t ssp_config_ice40_fpga;
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;
extern sgpio_config_t sgpio_config;
extern radio_t radio;
extern rf_path_t rf_path;
extern jtag_gpio_t jtag_gpio_cpld;
extern jtag_t jtag_cpld;
extern i2c_bus_t i2c0;

void ssp1_set_mode_max283x(void);
void ssp1_set_mode_max5864(void);
#if defined(IS_PRALINE)
void ssp1_set_mode_ice40(void);
#endif

#ifdef __cplusplus
}
#endif
4 changes: 2 additions & 2 deletions firmware/common/fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
*/

#include "fpga.h"
#include "fpga_regs.def"

#include <stdbool.h>

#include "fpga_regs.def"
#include "hackrf_core.h"
#include "drivers.h"
#include "ice40_spi.h"

/* Set up all registers according to the loaded bitstream's defaults. */
Expand Down
2 changes: 1 addition & 1 deletion firmware/common/fpga_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <stddef.h>
#include <stdint.h>

#include "drivers.h"
#include "fpga.h"
#include "hackrf_core.h"
#include "ice40_spi.h"
#include "lz4_blk.h"
#include "selftest.h"
Expand Down
2 changes: 1 addition & 1 deletion firmware/common/fpga_selftest.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

#include "clock_gen.h"
#include "delay.h"
#include "drivers.h"
#include "fixed_point.h"
#include "fpga.h"
#include "hackrf_core.h"
#include "ice40_spi.h"
#include "m0_state.h"
#include "max283x.h"
Expand Down
Loading
Loading