RFFC5071: Further work abstracting SPI details out of driver.
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
#include "si5351c.h"
|
||||
#include "max2837.h"
|
||||
#include "rffc5071.h"
|
||||
#include "rffc5071_spi.h"
|
||||
#include "sgpio.h"
|
||||
#include "rf_path.h"
|
||||
#include <libopencm3/lpc43xx/i2c.h>
|
||||
@ -37,9 +38,17 @@
|
||||
|
||||
max2837_driver_t max2837;
|
||||
|
||||
rffc5071_driver_t rffc5072;
|
||||
spi_t rffc5071_spi = {
|
||||
.init = rffc5071_spi_init,
|
||||
.transfer = rffc5071_spi_transfer,
|
||||
.transfer_gather = rffc5071_spi_transfer_gather,
|
||||
};
|
||||
|
||||
w25q80bv_driver_t spi_flash;
|
||||
rffc5071_driver_t rffc5072 = {
|
||||
.spi = &rffc5071_spi,
|
||||
};
|
||||
|
||||
|
||||
void delay(uint32_t duration)
|
||||
{
|
||||
|
@ -34,7 +34,6 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "rffc5071.h"
|
||||
#include "rffc5071_spi.h"
|
||||
#include "rffc5071_regs.def" // private register def macros
|
||||
|
||||
#include "hackrf_core.h"
|
||||
@ -91,7 +90,7 @@ void rffc5071_setup(rffc5071_driver_t* const drv)
|
||||
{
|
||||
rffc5071_init(drv);
|
||||
|
||||
rffc5071_spi_init(drv->spi);
|
||||
spi_init(drv->spi);
|
||||
|
||||
/* initial setup */
|
||||
/* put zeros in freq contol registers */
|
||||
@ -124,7 +123,7 @@ static uint16_t rffc5071_spi_read(rffc5071_driver_t* const drv, uint8_t r) {
|
||||
(void)drv;
|
||||
|
||||
uint16_t data[] = { 0x80 | (r & 0x7f), 0xffff };
|
||||
rffc5071_spi_transfer(drv->spi, data, 2);
|
||||
spi_transfer(drv->spi, data, 2);
|
||||
return data[1];
|
||||
}
|
||||
|
||||
@ -132,7 +131,7 @@ static void rffc5071_spi_write(rffc5071_driver_t* const drv, uint8_t r, uint16_t
|
||||
(void)drv;
|
||||
|
||||
uint16_t data[] = { 0x00 | (r & 0x7f), v };
|
||||
rffc5071_spi_transfer(drv->spi, data, 2);
|
||||
spi_transfer(drv->spi, data, 2);
|
||||
}
|
||||
|
||||
uint16_t rffc5071_reg_read(rffc5071_driver_t* const drv, uint8_t r)
|
||||
|
@ -25,7 +25,16 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "rffc5071_spi.h"
|
||||
#include "spi.h"
|
||||
|
||||
/* 31 registers, each containing 16 bits of data. */
|
||||
#define RFFC5071_NUM_REGS 31
|
||||
|
||||
typedef struct {
|
||||
spi_t* const spi;
|
||||
uint16_t regs[RFFC5071_NUM_REGS];
|
||||
uint32_t regs_dirty;
|
||||
} rffc5071_driver_t;
|
||||
|
||||
/* Initialize chip. Call _setup() externally, as it calls _init(). */
|
||||
extern void rffc5071_init(rffc5071_driver_t* const drv);
|
||||
|
@ -138,11 +138,13 @@ static uint32_t rffc5071_spi_exchange_word(spi_t* const spi, const uint32_t data
|
||||
* next 7 bits are register address,
|
||||
* next 16 bits are register value.
|
||||
*/
|
||||
void rffc5071_spi_transfer(spi_t* const spi, uint16_t* const data, const size_t count) {
|
||||
void rffc5071_spi_transfer(spi_t* const spi, void* const _data, const size_t count) {
|
||||
if( count != 2 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t* const data = _data;
|
||||
|
||||
const bool direction_read = (data[0] >> 7) & 1;
|
||||
|
||||
/*
|
||||
@ -171,3 +173,9 @@ void rffc5071_spi_transfer(spi_t* const spi, uint16_t* const data, const size_t
|
||||
*/
|
||||
rffc5071_spi_sck(spi);
|
||||
}
|
||||
|
||||
void rffc5071_spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfer, const size_t count) {
|
||||
if( count == 1 ) {
|
||||
rffc5071_spi_transfer(spi, transfer[0].data, transfer[0].count);
|
||||
}
|
||||
}
|
||||
|
@ -25,16 +25,8 @@
|
||||
|
||||
#include "spi.h"
|
||||
|
||||
/* 31 registers, each containing 16 bits of data. */
|
||||
#define RFFC5071_NUM_REGS 31
|
||||
|
||||
typedef struct {
|
||||
spi_t* const spi;
|
||||
uint16_t regs[RFFC5071_NUM_REGS];
|
||||
uint32_t regs_dirty;
|
||||
} rffc5071_driver_t;
|
||||
|
||||
void rffc5071_spi_init(spi_t* const spi);
|
||||
void rffc5071_spi_transfer(spi_t* const spi, uint16_t* const data, const size_t count);
|
||||
void rffc5071_spi_transfer(spi_t* const spi, void* const data, const size_t count);
|
||||
void rffc5071_spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfer, const size_t count);
|
||||
|
||||
#endif // __RFFC5071_SPI_H
|
||||
|
34
firmware/common/spi.c
Normal file
34
firmware/common/spi.c
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
*
|
||||
* 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 "spi.h"
|
||||
|
||||
void spi_init(spi_t* const spi) {
|
||||
spi->init(spi);
|
||||
}
|
||||
|
||||
void spi_transfer(spi_t* const spi, void* const data, const size_t count) {
|
||||
spi->transfer(spi, data, count);
|
||||
}
|
||||
|
||||
void spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count) {
|
||||
spi->transfer_gather(spi, transfers, count);
|
||||
}
|
45
firmware/common/spi.h
Normal file
45
firmware/common/spi.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __SPI_H__
|
||||
#define __SPI_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
void* const data;
|
||||
const size_t count;
|
||||
} spi_transfer_t;
|
||||
|
||||
struct spi_t;
|
||||
typedef struct spi_t spi_t;
|
||||
|
||||
struct spi_t {
|
||||
void (*init)(spi_t* const spi);
|
||||
void (*transfer)(spi_t* const spi, void* const data, const size_t count);
|
||||
void (*transfer_gather)(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count);
|
||||
};
|
||||
|
||||
void spi_init(spi_t* const spi);
|
||||
void spi_transfer(spi_t* const spi, void* const data, const size_t count);
|
||||
void spi_transfer_gather(spi_t* const spi, const spi_transfer_t* const transfers, const size_t count);
|
||||
|
||||
#endif/*__SPI_H__*/
|
@ -139,6 +139,7 @@ macro(DeclareTargets)
|
||||
${PATH_HACKRF_FIRMWARE_COMMON}/max5864.c
|
||||
${PATH_HACKRF_FIRMWARE_COMMON}/rffc5071.c
|
||||
${PATH_HACKRF_FIRMWARE_COMMON}/rffc5071_spi.c
|
||||
${PATH_HACKRF_FIRMWARE_COMMON}/spi.c
|
||||
m0_bin.s
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user