Compare commits
No commits in common. "e509c36df9b7521ffb253079e3226d6b870f0b4d" and "629d265d12195ea7151d3af13594045d26ab4fd1" have entirely different histories.
e509c36df9
...
629d265d12
14
Cargo.toml
14
Cargo.toml
@ -1,19 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "si5351"
|
name = "si5351"
|
||||||
version = "0.2.0"
|
version = "0.1.2"
|
||||||
keywords = ["embedded", "no-std", "embedded-hal-driver", "clock", "ham-radio"]
|
categories = ["embedded-hal-driver", "ham-radio", "clock", "pll" ]
|
||||||
categories = ["embedded", "no-std"]
|
|
||||||
authors = ["Ilya Epifanov <elijah.epifanov@gmail.com>"]
|
authors = ["Ilya Epifanov <elijah.epifanov@gmail.com>"]
|
||||||
description = "A platform agnostic driver for the Si5351 clock generator"
|
description = "A platform agnostic driver for the Si5351 clock generator"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
exclude = [".travis.yml", ".gitignore"]
|
|
||||||
repository = "https://github.com/ilya-epifanov/si5351"
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[badges.travis-ci]
|
|
||||||
branch = "master"
|
|
||||||
repository = "jamwaffles/ssd1306"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embedded-hal = "0.2.2"
|
embedded-hal = "0.1"
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
|
|||||||
@ -186,7 +186,7 @@
|
|||||||
same "printed page" as the copyright notice for easier
|
same "printed page" as the copyright notice for easier
|
||||||
identification within third-party archives.
|
identification within third-party archives.
|
||||||
|
|
||||||
Copyright 2018 Ilya Epifanov
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
25
LICENSE-MIT
25
LICENSE-MIT
@ -1,25 +0,0 @@
|
|||||||
Copyright (c) 2018 Ilya Epifanov
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any
|
|
||||||
person obtaining a copy of this software and associated
|
|
||||||
documentation files (the "Software"), to deal in the
|
|
||||||
Software without restriction, including without
|
|
||||||
limitation the rights to use, copy, modify, merge,
|
|
||||||
publish, distribute, sublicense, and/or sell copies of
|
|
||||||
the Software, and to permit persons to whom the Software
|
|
||||||
is furnished to do so, subject to the following
|
|
||||||
conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice
|
|
||||||
shall be included in all copies or substantial portions
|
|
||||||
of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
||||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
||||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
||||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
||||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
||||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
||||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
||||||
DEALINGS IN THE SOFTWARE.
|
|
||||||
25
README.md
25
README.md
@ -1,24 +1 @@
|
|||||||
# si5351
|
# si5351
|
||||||
|
|
||||||
[](https://docs.rs/si5351)
|
|
||||||
[](https://crates.io/crates/si5351)
|
|
||||||
[](https://travis-ci.org/ilya-epifanov/si5351)
|
|
||||||
|
|
||||||
## Documentation
|
|
||||||
|
|
||||||
On [docs.rs](https://docs.rs/si5351)
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
Licensed under either of
|
|
||||||
|
|
||||||
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
||||||
* MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
||||||
|
|
||||||
at your option.
|
|
||||||
|
|
||||||
### Contribution
|
|
||||||
|
|
||||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
|
||||||
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
|
|
||||||
additional terms or conditions.
|
|
||||||
7
Xargo.toml
Normal file
7
Xargo.toml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
[dependencies.core]
|
||||||
|
stage = 0
|
||||||
|
|
||||||
|
[dependencies.compiler_builtins]
|
||||||
|
git = "https://github.com/rust-lang-nursery/compiler-builtins"
|
||||||
|
features = ["mem"]
|
||||||
|
stage = 1
|
||||||
97
src/lib.rs
97
src/lib.rs
@ -1,91 +1,14 @@
|
|||||||
/*
|
|
||||||
Copyright 2018 Ilya Epifanov
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
|
|
||||||
http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
|
||||||
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(missing_docs)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
|
#![feature(unsize)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bitflags;
|
extern crate bitflags;
|
||||||
use embedded_hal as hal;
|
extern crate embedded_hal as hal;
|
||||||
|
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use crate::hal::blocking::i2c::{Write, WriteRead};
|
use hal::blocking::i2c::{Write, WriteRead};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
@ -339,8 +262,8 @@ fn i2c_error<E>(_: E) -> Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Si5351 driver
|
/// Si5351 driver
|
||||||
pub struct Si5351Device<I2C> {
|
pub struct Si5351Device<'a, I2C: 'a> {
|
||||||
i2c: I2C,
|
i2c: &'a mut I2C,
|
||||||
address: u8,
|
address: u8,
|
||||||
xtal_freq: u32,
|
xtal_freq: u32,
|
||||||
clk_enabled_mask: u8,
|
clk_enabled_mask: u8,
|
||||||
@ -348,7 +271,7 @@ pub struct Si5351Device<I2C> {
|
|||||||
ms_src_mask: u8,
|
ms_src_mask: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Si5351 {
|
pub trait Si5351<'a> {
|
||||||
fn init_adafruit_module(&mut self) -> Result<(), Error>;
|
fn init_adafruit_module(&mut self) -> Result<(), Error>;
|
||||||
fn init(&mut self, xtal_load: CrystalLoad) -> Result<(), Error>;
|
fn init(&mut self, xtal_load: CrystalLoad) -> Result<(), Error>;
|
||||||
fn read_device_status(&mut self) -> Result<DeviceStatusBits, Error>;
|
fn read_device_status(&mut self) -> Result<DeviceStatusBits, Error>;
|
||||||
@ -369,12 +292,12 @@ pub trait Si5351 {
|
|||||||
fn select_clock_pll(&mut self, clocl: ClockOutput, pll: PLL);
|
fn select_clock_pll(&mut self, clocl: ClockOutput, pll: PLL);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I2C, E> Si5351Device<I2C>
|
impl<'a, I2C, E> Si5351Device<'a, I2C>
|
||||||
where
|
where
|
||||||
I2C: WriteRead<Error=E> + Write<Error=E>,
|
I2C: WriteRead<Error=E> + Write<Error=E>,
|
||||||
{
|
{
|
||||||
/// Creates a new driver from a I2C peripheral
|
/// Creates a new driver from a I2C peripheral
|
||||||
pub fn new(i2c: I2C, address_bit: bool, xtal_freq: u32) -> Self {
|
pub fn new(i2c: &'a mut I2C, address_bit: bool, xtal_freq: u32) -> Self {
|
||||||
let si5351 = Si5351Device {
|
let si5351 = Si5351Device {
|
||||||
i2c,
|
i2c,
|
||||||
address: ADDRESS | if address_bit { 1 } else { 0 },
|
address: ADDRESS | if address_bit { 1 } else { 0 },
|
||||||
@ -387,7 +310,7 @@ impl<I2C, E> Si5351Device<I2C>
|
|||||||
si5351
|
si5351
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_adafruit_module(i2c: I2C) -> Self {
|
pub fn new_adafruit_module(i2c: &'a mut I2C) -> Self {
|
||||||
Si5351Device::new(i2c, false, 25_000_000)
|
Si5351Device::new(i2c, false, 25_000_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,7 +387,7 @@ impl<I2C, E> Si5351Device<I2C>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<I2C, E> Si5351 for Si5351Device<I2C> where
|
impl<'a, I2C, E> Si5351<'a> for Si5351Device<'a, I2C> where
|
||||||
I2C: WriteRead<Error=E> + Write<Error=E>
|
I2C: WriteRead<Error=E> + Write<Error=E>
|
||||||
{
|
{
|
||||||
fn init_adafruit_module(&mut self) -> Result<(), Error> {
|
fn init_adafruit_module(&mut self) -> Result<(), Error> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user