summaryrefslogtreecommitdiffstats
path: root/src/interface.rs
diff options
context:
space:
mode:
authorMarkus Reiter <me@reitermark.us>2024-01-19 15:09:19 +0100
committerGitHub <noreply@github.com>2024-01-19 15:09:19 +0100
commit5cd361340635aafe8806c82805622bc6afc4c4d7 (patch)
treee71f39a729a95020ca299925b93d0990416666b7 /src/interface.rs
parent6f417d833e2a4041f32a6578332b050d79028910 (diff)
downloadads1x1x-async-5cd361340635aafe8806c82805622bc6afc4c4d7.tar.gz
ads1x1x-async-5cd361340635aafe8806c82805622bc6afc4c4d7.tar.xz
ads1x1x-async-5cd361340635aafe8806c82805622bc6afc4c4d7.zip
Remove `I2cInterface`. (#20)
* Merge `ReadData` and `WriteData` traits. * Remove `I2cInterface`. * Update changelog. * Fix links.
Diffstat (limited to 'src/interface.rs')
-rw-r--r--src/interface.rs53
1 files changed, 0 insertions, 53 deletions
diff --git a/src/interface.rs b/src/interface.rs
deleted file mode 100644
index 0e665a3..0000000
--- a/src/interface.rs
+++ /dev/null
@@ -1,53 +0,0 @@
-//! I2C interface
-
-use crate::{private, Error};
-
-/// I2C interface
-#[derive(Debug, Default)]
-pub struct I2cInterface<I2C> {
- pub(crate) i2c: I2C,
- pub(crate) address: u8,
-}
-
-/// Write data
-pub trait WriteData: private::Sealed {
- /// Error type
- type Error;
-
- /// Write to an u16 register
- fn write_register(&mut self, register: u8, data: u16) -> Result<(), Error<Self::Error>>;
-}
-
-impl<I2C, E> WriteData for I2cInterface<I2C>
-where
- I2C: embedded_hal::i2c::I2c<Error = E>,
-{
- type Error = E;
- fn write_register(&mut self, register: u8, data: u16) -> Result<(), Error<E>> {
- let payload: [u8; 3] = [register, (data >> 8) as u8, data as u8];
- self.i2c.write(self.address, &payload).map_err(Error::I2C)
- }
-}
-
-/// Read data
-pub trait ReadData: private::Sealed {
- /// Error type
- type Error;
-
- /// Read an u16 register
- fn read_register(&mut self, register: u8) -> Result<u16, Error<Self::Error>>;
-}
-
-impl<I2C, E> ReadData for I2cInterface<I2C>
-where
- I2C: embedded_hal::i2c::I2c<Error = E>,
-{
- type Error = E;
- fn read_register(&mut self, register: u8) -> Result<u16, Error<E>> {
- let mut data = [0, 0];
- self.i2c
- .write_read(self.address, &[register], &mut data)
- .map_err(Error::I2C)
- .and(Ok((u16::from(data[0]) << 8) | u16::from(data[1])))
- }
-}