summaryrefslogtreecommitdiffstats
path: root/src/devices/mode/continuous.rs
blob: 6bf52016ce727211d7dd4af7fe741c2c27f5f99e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//! Common functions

use core::marker::PhantomData;
use { Ads1x1x, mode, Error, interface };
use super::super::OperatingMode;

impl<DI, IC, CONV, E> Ads1x1x<DI, IC, CONV, mode::Continuous>
where
    DI: interface::WriteData<Error = E>,
{
    /// Change operating mode to OneShot
    pub fn into_one_shot(mut self) -> Result<Ads1x1x<DI, IC, CONV, mode::OneShot>, Error<E>> {
        self.set_operating_mode(OperatingMode::OneShot)?;
        Ok(Ads1x1x {
            iface: self.iface,
            config: self.config,
            fsr: self.fsr,
            a_conversion_was_started: self.a_conversion_was_started,
            _conv: PhantomData,
            _ic: PhantomData,
            _mode: PhantomData
        })
    }

    /// Start continuous conversions
    pub fn start(&mut self) -> Result<(), Error<E>> {
        self.set_operating_mode(OperatingMode::Continuous)?;
        self.a_conversion_was_started = true;
        Ok(())
    }
}