taking an i2c bus by value
This commit is contained in:
parent
ec33c2de17
commit
bf425b8b6c
14
Cargo.toml
14
Cargo.toml
@ -1,12 +1,18 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "si5351"
|
name = "si5351"
|
||||||
version = "0.1.5"
|
version = "0.2.0"
|
||||||
keywords = ["embedded-hal-driver", "clock", "ham-radio"]
|
keywords = ["embedded", "no-std", "embedded-hal-driver", "clock", "ham-radio"]
|
||||||
categories = ["embedded", "no-std", "hardware-support"]
|
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"
|
||||||
|
|
||||||
|
[badges.travis-ci]
|
||||||
|
branch = "master"
|
||||||
|
repository = "jamwaffles/ssd1306"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
embedded-hal = "0.1"
|
embedded-hal = "0.2.2"
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
[dependencies.core]
|
|
||||||
stage = 0
|
|
||||||
|
|
||||||
[dependencies.compiler_builtins]
|
|
||||||
git = "https://github.com/rust-lang-nursery/compiler-builtins"
|
|
||||||
features = ["mem"]
|
|
||||||
stage = 1
|
|
||||||
19
src/lib.rs
19
src/lib.rs
@ -46,7 +46,7 @@ use si5351;
|
|||||||
use si5351::{Si5351, Si5351Device};
|
use si5351::{Si5351, Si5351Device};
|
||||||
|
|
||||||
# fn main() {
|
# fn main() {
|
||||||
let mut clock = Si5351Device<I2C>::new(&mut i2c, false, 25_000_000);
|
let mut clock = Si5351Device<I2C>::new(i2c, false, 25_000_000);
|
||||||
clock.init(si5351::CrystalLoad::_10)?;
|
clock.init(si5351::CrystalLoad::_10)?;
|
||||||
# }
|
# }
|
||||||
```
|
```
|
||||||
@ -59,7 +59,7 @@ use si5351;
|
|||||||
use si5351::{Si5351, Si5351Device};
|
use si5351::{Si5351, Si5351Device};
|
||||||
|
|
||||||
# fn main() {
|
# fn main() {
|
||||||
let mut clock = Si5351Device<I2C>::new_adafruit_module(&mut i2c);
|
let mut clock = Si5351Device<I2C>::new_adafruit_module(i2c);
|
||||||
clock.init_adafruit_module()?;
|
clock.init_adafruit_module()?;
|
||||||
# }
|
# }
|
||||||
```
|
```
|
||||||
@ -78,7 +78,6 @@ clock.set_frequency(si5351::PLL::A, si5351::ClockOutput::Clk0, 14_175_000)?;
|
|||||||
*/
|
*/
|
||||||
//#![deny(missing_docs)]
|
//#![deny(missing_docs)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![feature(unsize)]
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -340,8 +339,8 @@ fn i2c_error<E>(_: E) -> Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Si5351 driver
|
/// Si5351 driver
|
||||||
pub struct Si5351Device<'a, I2C: 'a> {
|
pub struct Si5351Device<I2C> {
|
||||||
i2c: &'a mut I2C,
|
i2c: I2C,
|
||||||
address: u8,
|
address: u8,
|
||||||
xtal_freq: u32,
|
xtal_freq: u32,
|
||||||
clk_enabled_mask: u8,
|
clk_enabled_mask: u8,
|
||||||
@ -349,7 +348,7 @@ pub struct Si5351Device<'a, I2C: 'a> {
|
|||||||
ms_src_mask: u8,
|
ms_src_mask: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Si5351<'a> {
|
pub trait Si5351 {
|
||||||
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>;
|
||||||
@ -370,12 +369,12 @@ pub trait Si5351<'a> {
|
|||||||
fn select_clock_pll(&mut self, clocl: ClockOutput, pll: PLL);
|
fn select_clock_pll(&mut self, clocl: ClockOutput, pll: PLL);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, I2C, E> Si5351Device<'a, I2C>
|
impl<I2C, E> Si5351Device<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: &'a mut I2C, address_bit: bool, xtal_freq: u32) -> Self {
|
pub fn new(i2c: 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 },
|
||||||
@ -388,7 +387,7 @@ impl<'a, I2C, E> Si5351Device<'a, I2C>
|
|||||||
si5351
|
si5351
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_adafruit_module(i2c: &'a mut I2C) -> Self {
|
pub fn new_adafruit_module(i2c: I2C) -> Self {
|
||||||
Si5351Device::new(i2c, false, 25_000_000)
|
Si5351Device::new(i2c, false, 25_000_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +464,7 @@ impl<'a, I2C, E> Si5351Device<'a, I2C>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, I2C, E> Si5351<'a> for Si5351Device<'a, I2C> where
|
impl<I2C, E> Si5351 for Si5351Device<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