max170xx/common.rs
1//! Common methods
2
3macro_rules! impl_common {
4 ($ic:ident) => {
5 /// Device driver
6 #[derive(Debug)]
7 pub struct $ic<I2C> {
8 i2c: I2C,
9 }
10
11 impl<I2C, E> $ic<I2C>
12 where
13 I2C: i2c::I2c<Error = E>,
14 {
15 /// Create new instance of the device.
16 pub fn new(i2c: I2C) -> Self {
17 $ic { i2c }
18 }
19
20 /// Destroy driver instance, return I2C bus.
21 pub fn destroy(self) -> I2C {
22 self.i2c
23 }
24
25 /// Quick start
26 ///
27 /// Restarts fuel-gauge calculations in the same manner as initial power-up
28 /// of the IC. This is useful if an application's power-up sequence
29 /// is exceedingly noisy
30 pub fn quickstart(&mut self) -> Result<(), Error<E>> {
31 self.write_register(Register::MODE, Command::QSTRT)
32 }
33
34 /// Get IC version
35 pub fn version(&mut self) -> Result<u16, Error<E>> {
36 self.read_register(Register::VERSION)
37 }
38 }
39 impl_register_access!($ic);
40 };
41}