
Conflicts: firmware/common/hackrf_core.c firmware/common/hackrf_core.h firmware/common/tuning.c
71 lines
2.2 KiB
C
71 lines
2.2 KiB
C
/*
|
|
* Copyright 2012 Will Code? (TODO: Proper attribution)
|
|
* 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 "max2837_spi.h"
|
|
|
|
#include <libopencm3/lpc43xx/gpio.h>
|
|
#include <libopencm3/lpc43xx/scu.h>
|
|
#include <libopencm3/lpc43xx/ssp.h>
|
|
|
|
#include "hackrf_core.h"
|
|
|
|
void max2837_spi_init(spi_t* const spi) {
|
|
(void)spi;
|
|
|
|
/* 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
|
|
const uint8_t serial_clock_rate = 21;
|
|
const uint8_t clock_prescale_rate = 2;
|
|
|
|
ssp_init(SSP1_NUM,
|
|
SSP_DATA_16BITS,
|
|
SSP_FRAME_SPI,
|
|
SSP_CPOL_0_CPHA_0,
|
|
serial_clock_rate,
|
|
clock_prescale_rate,
|
|
SSP_MODE_NORMAL,
|
|
SSP_MASTER,
|
|
SSP_SLAVE_OUT_ENABLE);
|
|
|
|
/* Configure SSP1 Peripheral (to be moved later in SSP driver) */
|
|
scu_pinmux(SCU_SSP1_MISO, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
|
|
scu_pinmux(SCU_SSP1_MOSI, (SCU_SSP_IO | SCU_CONF_FUNCTION5));
|
|
scu_pinmux(SCU_SSP1_SCK, (SCU_SSP_IO | SCU_CONF_FUNCTION1));
|
|
}
|
|
|
|
void max2837_spi_transfer(spi_t* const spi, void* const _data, const size_t count) {
|
|
(void)spi;
|
|
|
|
uint16_t* const data = _data;
|
|
|
|
gpio_clear(PORT_XCVR_CS, PIN_XCVR_CS);
|
|
for(size_t i=0; i<count; i++) {
|
|
data[i] = ssp_transfer(SSP1_NUM, data[i]);
|
|
}
|
|
gpio_set(PORT_XCVR_CS, PIN_XCVR_CS);
|
|
}
|