summaryrefslogtreecommitdiffstats
path: root/src/devices/construction
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-07 20:19:06 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-07 20:19:06 +0100
commit28b16cc364cc4f4112aca2195df389ea6f007048 (patch)
treeaa14b2c5d06ee56acea022dfdbe67a6af7ab901c /src/devices/construction
parenta502e4c40952777f0ac5f1fc759fe4f669d8500e (diff)
downloadads1x1x-async-28b16cc364cc4f4112aca2195df389ea6f007048.tar.gz
ads1x1x-async-28b16cc364cc4f4112aca2195df389ea6f007048.tar.xz
ads1x1x-async-28b16cc364cc4f4112aca2195df389ea6f007048.zip
Convert between modes through transformation of the struct
Diffstat (limited to 'src/devices/construction')
-rw-r--r--src/devices/construction/i2c.rs41
-rw-r--r--src/devices/construction/mod.rs3
2 files changed, 44 insertions, 0 deletions
diff --git a/src/devices/construction/i2c.rs b/src/devices/construction/i2c.rs
new file mode 100644
index 0000000..900a5fe
--- /dev/null
+++ b/src/devices/construction/i2c.rs
@@ -0,0 +1,41 @@
+//! Functions exclusive of ADS1013
+
+extern crate embedded_hal as hal;
+use hal::blocking;
+use core::marker::PhantomData;
+use { Ads1x1x, DEVICE_BASE_ADDRESS, SlaveAddr, ic, Config, mode };
+use interface::I2cInterface;
+
+
+macro_rules! impl_new_destroy {
+ ( $IC:ident, $create:ident, $destroy:ident ) => {
+ impl<I2C, E> Ads1x1x<I2cInterface<I2C>, ic::$IC, mode::OneShot>
+ where
+ I2C: blocking::i2c::Write<Error = E> + blocking::i2c::WriteRead<Error = E>
+ {
+ /// 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(),
+ a_conversion_was_started: false,
+ _ic: PhantomData,
+ _mode: PhantomData
+ }
+ }
+ }
+ impl<I2C, MODE> Ads1x1x<I2cInterface<I2C>, ic::$IC, 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);
+impl_new_destroy!(Ads1113, new_ads1113, destroy_ads1113); \ No newline at end of file
diff --git a/src/devices/construction/mod.rs b/src/devices/construction/mod.rs
new file mode 100644
index 0000000..0873d88
--- /dev/null
+++ b/src/devices/construction/mod.rs
@@ -0,0 +1,3 @@
+//! Construction / destruction functions
+
+mod i2c;