diff --git a/firmware/common/hackrf_core.c b/firmware/common/hackrf_core.c index b862ba4f..cd1c8005 100644 --- a/firmware/common/hackrf_core.c +++ b/firmware/common/hackrf_core.c @@ -23,6 +23,7 @@ #include "hackrf_core.h" #include "si5351c.h" +#include "si5351c_drv.h" #include "max2837.h" #include "rffc5071.h" #include "sgpio.h" diff --git a/firmware/common/si5351c.c b/firmware/common/si5351c.c index 58b614dc..3be5041a 100644 --- a/firmware/common/si5351c.c +++ b/firmware/common/si5351c.c @@ -21,57 +21,11 @@ */ #include "si5351c.h" -#include + +#include "si5351c_drv.h" enum pll_sources active_clock_source; -/* FIXME return i2c0 status from each function */ - -/* write to single register */ -void si5351c_write_single(uint8_t reg, uint8_t val) -{ - i2c0_tx_start(); - i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE); - i2c0_tx_byte(reg); - i2c0_tx_byte(val); - i2c0_stop(); -} - -/* read single register */ -uint8_t si5351c_read_single(uint8_t reg) -{ - uint8_t val; - - /* set register address with write */ - i2c0_tx_start(); - i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE); - i2c0_tx_byte(reg); - - /* read the value */ - i2c0_tx_start(); - i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_READ); - val = i2c0_rx_byte(); - i2c0_stop(); - - return val; -} - -/* - * Write to one or more contiguous registers. data[0] should be the first - * register number, one or more values follow. - */ -void si5351c_write(uint8_t* const data, const uint_fast8_t data_count) -{ - uint_fast8_t i; - - i2c0_tx_start(); - i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE); - - for (i = 0; i < data_count; i++) - i2c0_tx_byte(data[i]); - i2c0_stop(); -} - /* Disable all CLKx outputs. */ void si5351c_disable_all_outputs() { diff --git a/firmware/common/si5351c.h b/firmware/common/si5351c.h index b62279d7..fcc2d2b8 100644 --- a/firmware/common/si5351c.h +++ b/firmware/common/si5351c.h @@ -31,7 +31,6 @@ extern "C" #include #define SI_INTDIV(x) (x*128-512) -#define SI5351C_I2C_ADDR (0x60 << 1) #define SI5351C_CLK_POWERDOWN (1<<7) #define SI5351C_CLK_INT_MODE (1<<6) @@ -76,10 +75,6 @@ void si5351c_configure_multisynth(const uint_fast8_t ms_number, void si5351c_configure_clock_control(const enum pll_sources source); void si5351c_enable_clock_outputs(); void si5351c_set_int_mode(const uint_fast8_t ms_number, const uint_fast8_t on); - -void si5351c_write_single(uint8_t reg, uint8_t val); -uint8_t si5351c_read_single(uint8_t reg); -void si5351c_write(uint8_t* const data, const uint_fast8_t data_count); void si5351c_set_clock_source(const enum pll_sources source); void si5351c_activate_best_clock_source(void); diff --git a/firmware/common/si5351c_drv.c b/firmware/common/si5351c_drv.c new file mode 100644 index 00000000..e63912c1 --- /dev/null +++ b/firmware/common/si5351c_drv.c @@ -0,0 +1,74 @@ +/* + * Copyright 2012 Michael Ossmann + * Copyright 2012 Jared Boone + * + * 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 "si5351c_drv.h" + +#include + +#define SI5351C_I2C_ADDR (0x60 << 1) + +/* FIXME return i2c0 status from each function */ + +/* write to single register */ +void si5351c_write_single(uint8_t reg, uint8_t val) +{ + i2c0_tx_start(); + i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE); + i2c0_tx_byte(reg); + i2c0_tx_byte(val); + i2c0_stop(); +} + +/* read single register */ +uint8_t si5351c_read_single(uint8_t reg) +{ + uint8_t val; + + /* set register address with write */ + i2c0_tx_start(); + i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE); + i2c0_tx_byte(reg); + + /* read the value */ + i2c0_tx_start(); + i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_READ); + val = i2c0_rx_byte(); + i2c0_stop(); + + return val; +} + +/* + * Write to one or more contiguous registers. data[0] should be the first + * register number, one or more values follow. + */ +void si5351c_write(uint8_t* const data, const uint_fast8_t data_count) +{ + uint_fast8_t i; + + i2c0_tx_start(); + i2c0_tx_byte(SI5351C_I2C_ADDR | I2C_WRITE); + + for (i = 0; i < data_count; i++) + i2c0_tx_byte(data[i]); + i2c0_stop(); +} diff --git a/firmware/common/si5351c_drv.h b/firmware/common/si5351c_drv.h new file mode 100644 index 00000000..501b221e --- /dev/null +++ b/firmware/common/si5351c_drv.h @@ -0,0 +1,41 @@ +/* + * Copyright 2012 Michael Ossmann + * Copyright 2012 Jared Boone + * + * 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 __SI5351C_DRV_H +#define __SI5351C_DRV_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include + +void si5351c_write_single(uint8_t reg, uint8_t val); +uint8_t si5351c_read_single(uint8_t reg); +void si5351c_write(uint8_t* const data, const uint_fast8_t data_count); + +#ifdef __cplusplus +} +#endif + +#endif /* __SI5351C_DRV_H */ diff --git a/firmware/hackrf-common.cmake b/firmware/hackrf-common.cmake index df5d5c96..9b4fb9a9 100644 --- a/firmware/hackrf-common.cmake +++ b/firmware/hackrf-common.cmake @@ -134,6 +134,7 @@ macro(DeclareTargets) ${PATH_HACKRF_FIRMWARE_COMMON}/sgpio.c ${PATH_HACKRF_FIRMWARE_COMMON}/rf_path.c ${PATH_HACKRF_FIRMWARE_COMMON}/si5351c.c + ${PATH_HACKRF_FIRMWARE_COMMON}/si5351c_drv.c ${PATH_HACKRF_FIRMWARE_COMMON}/max2837.c ${PATH_HACKRF_FIRMWARE_COMMON}/max5864.c ${PATH_HACKRF_FIRMWARE_COMMON}/rffc5071.c diff --git a/firmware/hackrf_usb/usb_api_register.c b/firmware/hackrf_usb/usb_api_register.c index d822c924..9478e7c1 100644 --- a/firmware/hackrf_usb/usb_api_register.c +++ b/firmware/hackrf_usb/usb_api_register.c @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include