aboutsummaryrefslogtreecommitdiffstats
path: root/sw/deps
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2023-03-13 23:14:32 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2023-03-13 23:14:32 +0100
commite04fec33f079db4c5d42aa412f7b670784ec1b68 (patch)
tree3bed3e90faafcd3967dafae293277ad0b6dddd10 /sw/deps
parentde7b4aa1b04e1fcb226c596c819b5ff996c73238 (diff)
downloadpicardy-e04fec33f079db4c5d42aa412f7b670784ec1b68.tar.gz
picardy-e04fec33f079db4c5d42aa412f7b670784ec1b68.tar.bz2
picardy-e04fec33f079db4c5d42aa412f7b670784ec1b68.zip
Add WSPR TX to eval-clock-cw-tx
Diffstat (limited to 'sw/deps')
-rw-r--r--sw/deps/si5351/src/lib.rs164
1 files changed, 1 insertions, 163 deletions
diff --git a/sw/deps/si5351/src/lib.rs b/sw/deps/si5351/src/lib.rs
index a23d4f9..9f3a2a9 100644
--- a/sw/deps/si5351/src/lib.rs
+++ b/sw/deps/si5351/src/lib.rs
@@ -6,77 +6,6 @@
http://opensource.org/licenses/MIT>, at your option. This file may not be
copied, modified, or distributed except according to those terms.
*/
-/*!
-A platform agnostic Rust driver for the [Si5351], based on the
-[`embedded-hal`] traits.
-
-## The Device
-
-The Silicon Labs [Si5351] is an any-frequency CMOS clock generator.
-
-The device has an I²C interface.
-
-## Usage
-
-Import this crate and an `embedded_hal` implementation:
-
-```
-extern crate stm32f103xx_hal as hal;
-extern crate si5351;
-```
-
-Initialize I²C bus (differs between `embedded_hal` implementations):
-
-```no_run
-# extern crate stm32f103xx_hal as hal;
-use hal::i2c::I2c;
-type I2C = ...;
-
-# fn main() {
-let i2c: I2C = initialize_i2c();
-# }
-```
-
-Then instantiate the device:
-
-```no_run
-# extern crate stm32f103xx_hal as hal;
-# extern crate si5351;
-use si5351;
-use si5351::{Si5351, Si5351Device};
-
-# fn main() {
-let mut clock = Si5351Device<I2C>::new(i2c, false, 25_000_000);
-clock.init(si5351::CrystalLoad::_10)?;
-# }
-```
-
-Or, if you have an [Adafruit module], you can use shortcut functions to initializate it:
-```no_run
-# extern crate stm32f103xx_hal as hal;
-# extern crate si5351;
-use si5351;
-use si5351::{Si5351, Si5351Device};
-
-# fn main() {
-let mut clock = Si5351Device<I2C>::new_adafruit_module(i2c);
-clock.init_adafruit_module()?;
-# }
-```
-
-And set frequency on one of the outputs:
-
-```no_run
-use si5351;
-
-clock.set_frequency(si5351::PLL::A, si5351::ClockOutput::Clk0, 14_175_000)?;
-```
-
-[Si5351]: https://www.silabs.com/documents/public/data-sheets/Si5351-B.pdf
-[`embedded-hal`]: https://github.com/japaric/embedded-hal
-[Adafruit module]: https://www.adafruit.com/product/2045
-*/
-//#![deny(missing_docs)]
#![deny(warnings)]
#![no_std]
@@ -304,33 +233,6 @@ impl OutputDivider {
fn bits(&self) -> u8 {
*self as u8
}
-
- fn min_divider(desired_divider: u16) -> Result<OutputDivider, Error> {
- match 16 - (desired_divider.max(1) - 1).leading_zeros() {
- 0 => Ok(OutputDivider::Div1),
- 1 => Ok(OutputDivider::Div2),
- 2 => Ok(OutputDivider::Div4),
- 3 => Ok(OutputDivider::Div8),
- 4 => Ok(OutputDivider::Div16),
- 5 => Ok(OutputDivider::Div32),
- 6 => Ok(OutputDivider::Div64),
- 7 => Ok(OutputDivider::Div128),
- _ => Err(Error::InvalidParameter)
- }
- }
-
- fn denominator_u8(&self) -> u8 {
- match *self {
- OutputDivider::Div1 => 1,
- OutputDivider::Div2 => 2,
- OutputDivider::Div4 => 4,
- OutputDivider::Div8 => 8,
- OutputDivider::Div16 => 16,
- OutputDivider::Div32 => 32,
- OutputDivider::Div64 => 64,
- OutputDivider::Div128 => 128,
- }
- }
}
fn i2c_error<E>(_: E) -> Error {
@@ -341,7 +243,6 @@ fn i2c_error<E>(_: E) -> Error {
pub struct Si5351Device<I2C> {
i2c: I2C,
address: u8,
- xtal_freq: u32,
clk_enabled_mask: u8,
ms_int_mode_mask: u8,
ms_src_mask: u8,
@@ -352,10 +253,6 @@ pub trait Si5351 {
fn init(&mut self, xtal_load: CrystalLoad) -> Result<(), Error>;
fn read_device_status(&mut self) -> Result<DeviceStatusBits, Error>;
- fn find_int_dividers_for_max_pll_freq(&self, max_pll_freq: u32, freq: u32) -> Result<(u16, OutputDivider), Error>;
- fn find_pll_coeffs_for_dividers(&self, total_div: u32, denom: u32, freq: u32) -> Result<(u8, u32), Error>;
-
- fn set_frequency(&mut self, pll: PLL, clk: ClockOutput, freq: u32) -> Result<(), Error>;
fn set_clock_enabled(&mut self, clk: ClockOutput, enabled: bool);
fn flush_output_enabled(&mut self) -> Result<(), Error>;
@@ -373,11 +270,10 @@ impl<I2C, E> Si5351Device<I2C>
I2C: WriteRead<Error=E> + Write<Error=E>,
{
/// Creates a new driver from a I2C peripheral
- pub fn new(i2c: I2C, address_bit: bool, xtal_freq: u32) -> Self {
+ pub fn new(i2c: I2C, address_bit: bool) -> Self {
let si5351 = Si5351Device {
i2c,
address: ADDRESS | if address_bit { 1 } else { 0 },
- xtal_freq,
clk_enabled_mask: 0,
ms_int_mode_mask: 0,
ms_src_mask: 0,
@@ -386,10 +282,6 @@ impl<I2C, E> Si5351Device<I2C>
si5351
}
- pub fn new_adafruit_module(i2c: I2C) -> Self {
- Si5351Device::new(i2c, false, 25_000_000)
- }
-
fn write_ms_config<MS: FractionalMultisynth + Copy>(&mut self, ms: MS, int: u16, frac_num: u32, frac_denom: u32, r_div: OutputDivider) -> Result<(), Error> {
if frac_denom == 0 {
return Err(Error::InvalidParameter);
@@ -500,60 +392,6 @@ impl<I2C, E> Si5351 for Si5351Device<I2C> where
Ok(DeviceStatusBits::from_bits_truncate(self.read_register(Register::DeviceStatus)?))
}
- fn find_int_dividers_for_max_pll_freq(&self, max_pll_freq: u32, freq: u32) -> Result<(u16, OutputDivider), Error> {
- let total_divider = (max_pll_freq / freq) as u16;
-
- let r_div = OutputDivider::min_divider(total_divider / 900)?;
-
- let ms_div = (total_divider / (2 * r_div.denominator_u8() as u16) * 2).max(6);
- if ms_div > 1800 {
- return Err(Error::InvalidParameter);
- }
-
- Ok((ms_div, r_div))
- }
-
- fn find_pll_coeffs_for_dividers(&self, total_div: u32, denom: u32, freq: u32) -> Result<(u8, u32), Error> {
- if denom == 0 || denom > 0xfffff {
- return Err(Error::InvalidParameter);
- }
-
- let pll_freq = freq * total_div;
-
- let mult = (pll_freq / self.xtal_freq) as u8;
- let f = ((pll_freq % self.xtal_freq) as u64 * denom as u64 / self.xtal_freq as u64) as u32;
-
- Ok((mult, f))
- }
-
- fn set_frequency(&mut self, pll: PLL, clk: ClockOutput, freq: u32) -> Result<(), Error> {
- let denom: u32 = 1048575;
-
- let (ms_divider, r_div) = self.find_int_dividers_for_max_pll_freq(900_000_000, freq)?;
- let total_div = ms_divider as u32 * r_div.denominator_u8() as u32;
- let (mult, num) = self.find_pll_coeffs_for_dividers(total_div, denom, freq)?;
-
- let ms = match clk {
- ClockOutput::Clk0 => Multisynth::MS0,
- ClockOutput::Clk1 => Multisynth::MS1,
- ClockOutput::Clk2 => Multisynth::MS2,
- ClockOutput::Clk3 => Multisynth::MS3,
- ClockOutput::Clk4 => Multisynth::MS4,
- ClockOutput::Clk5 => Multisynth::MS5,
- _ => return Err(Error::InvalidParameter),
- };
-
- self.setup_pll(pll, mult, num, denom)?;
- self.setup_multisynth_int(ms, ms_divider, r_div)?;
- self.select_clock_pll(clk, pll);
- self.set_clock_enabled(clk, true);
- self.flush_clock_control(clk)?;
- self.reset_pll(pll)?;
- self.flush_output_enabled()?;
-
- Ok(())
- }
-
fn set_clock_enabled(&mut self, clk: ClockOutput, enabled: bool) {
let bit = 1u8 << clk.ix();
if enabled {