From 6aa9eca206daf3a37945de57fbd7c476daca4cdb Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Wed, 21 Nov 2018 08:56:35 +0100 Subject: Move i2c construction module outside --- src/construction.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/construction/i2c.rs | 47 ----------------------------------------------- src/construction/mod.rs | 3 --- 3 files changed, 47 insertions(+), 50 deletions(-) create mode 100644 src/construction.rs delete mode 100644 src/construction/i2c.rs delete mode 100644 src/construction/mod.rs diff --git a/src/construction.rs b/src/construction.rs new file mode 100644 index 0000000..ab100fd --- /dev/null +++ b/src/construction.rs @@ -0,0 +1,47 @@ +//! Constructor/destructor functions. + +extern crate embedded_hal as hal; +use hal::blocking; +use core::marker::PhantomData; +use { Ads1x1x, DEVICE_BASE_ADDRESS, SlaveAddr, ic, Config, mode, FullScaleRange }; +use interface::I2cInterface; + + +macro_rules! impl_new_destroy { + ( $IC:ident, $create:ident, $destroy:ident, $conv:ty ) => { + impl Ads1x1x, ic::$IC, $conv, mode::OneShot> + where + I2C: blocking::i2c::Write + blocking::i2c::WriteRead + { + /// Create a new instance of the device in OneShot mode. + pub fn $create(i2c: I2C, address: SlaveAddr) -> Self { + Ads1x1x { + iface: I2cInterface { + i2c, + address: address.addr(DEVICE_BASE_ADDRESS) + }, + config: Config::default(), + fsr: FullScaleRange::default(), + a_conversion_was_started: false, + _conv: PhantomData, + _ic: PhantomData, + _mode: PhantomData + } + } + } + impl Ads1x1x, ic::$IC, CONV, MODE> + { + /// Destroy driver instance, return I²C bus instance. + pub fn $destroy(self) -> I2C { + self.iface.i2c + } + } + } +} + +impl_new_destroy!(Ads1013, new_ads1013, destroy_ads1013, ic::Resolution12Bit); +impl_new_destroy!(Ads1113, new_ads1113, destroy_ads1113, ic::Resolution16Bit); +impl_new_destroy!(Ads1014, new_ads1014, destroy_ads1014, ic::Resolution12Bit); +impl_new_destroy!(Ads1114, new_ads1114, destroy_ads1114, ic::Resolution16Bit); +impl_new_destroy!(Ads1015, new_ads1015, destroy_ads1015, ic::Resolution12Bit); +impl_new_destroy!(Ads1115, new_ads1115, destroy_ads1115, ic::Resolution16Bit); diff --git a/src/construction/i2c.rs b/src/construction/i2c.rs deleted file mode 100644 index 8c63a4b..0000000 --- a/src/construction/i2c.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! Constructor/destructor functions for devices using I2C interface. - -extern crate embedded_hal as hal; -use hal::blocking; -use core::marker::PhantomData; -use { Ads1x1x, DEVICE_BASE_ADDRESS, SlaveAddr, ic, Config, mode, FullScaleRange }; -use interface::I2cInterface; - - -macro_rules! impl_new_destroy { - ( $IC:ident, $create:ident, $destroy:ident, $conv:ty ) => { - impl Ads1x1x, ic::$IC, $conv, mode::OneShot> - where - I2C: blocking::i2c::Write + blocking::i2c::WriteRead - { - /// Create a new instance of the device in OneShot mode. - pub fn $create(i2c: I2C, address: SlaveAddr) -> Self { - Ads1x1x { - iface: I2cInterface { - i2c, - address: address.addr(DEVICE_BASE_ADDRESS) - }, - config: Config::default(), - fsr: FullScaleRange::default(), - a_conversion_was_started: false, - _conv: PhantomData, - _ic: PhantomData, - _mode: PhantomData - } - } - } - impl Ads1x1x, ic::$IC, CONV, MODE> - { - /// Destroy driver instance, return I²C bus instance. - pub fn $destroy(self) -> I2C { - self.iface.i2c - } - } - } -} - -impl_new_destroy!(Ads1013, new_ads1013, destroy_ads1013, ic::Resolution12Bit); -impl_new_destroy!(Ads1113, new_ads1113, destroy_ads1113, ic::Resolution16Bit); -impl_new_destroy!(Ads1014, new_ads1014, destroy_ads1014, ic::Resolution12Bit); -impl_new_destroy!(Ads1114, new_ads1114, destroy_ads1114, ic::Resolution16Bit); -impl_new_destroy!(Ads1015, new_ads1015, destroy_ads1015, ic::Resolution12Bit); -impl_new_destroy!(Ads1115, new_ads1115, destroy_ads1115, ic::Resolution16Bit); diff --git a/src/construction/mod.rs b/src/construction/mod.rs deleted file mode 100644 index 0873d88..0000000 --- a/src/construction/mod.rs +++ /dev/null @@ -1,3 +0,0 @@ -//! Construction / destruction functions - -mod i2c; -- cgit v1.2.3-54-g00ecf