Struct mcp3425::MCP3425

source ·
pub struct MCP3425<I2C, D, M> { /* private fields */ }
Expand description

Driver for the MCP3425 ADC

Implementations§

source§

impl<I2C, D, E, M> MCP3425<I2C, D, M>
where I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>, D: DelayMs<u8>, M: ConversionMode,

source

pub fn new(i2c: I2C, address: u8, delay: D, mode: M) -> Self

Initialize the MCP3425 driver.

This constructor is side-effect free, so it will not write any configuration to the device until a first measurement is triggered.

source

pub fn destroy(self) -> I2C

Destroy the driver instance and return the I2C device.

source§

impl<I2C, D, E> MCP3425<I2C, D, OneShotMode>
where I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>, D: DelayMs<u8>,

source

pub fn oneshot(i2c: I2C, address: u8, delay: D) -> Self

Initialize the MCP3425 driver in One-Shot mode.

This constructor is side-effect free, so it will not write any configuration to the device until a first measurement is triggered.

source

pub fn into_continuous(self) -> MCP3425<I2C, D, ContinuousMode>

Change the conversion mode to continuous.

This conversion is side-effect free, so it will not write any configuration to the device until set_config is called.

source

pub fn measure(&mut self, config: &Config) -> Result<Voltage, Error<E>>

Do a one-shot voltage measurement.

Return the result in millivolts.

source§

impl<I2C, D, E> MCP3425<I2C, D, ContinuousMode>
where I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>, D: DelayMs<u8>,

source

pub fn continuous(i2c: I2C, address: u8, delay: D) -> Self

Initialize the MCP3425 driver in Continuous Measurement mode.

This constructor is side-effect free, so it will not write any configuration to the device until a first measurement is triggered.

source

pub fn into_oneshot(self) -> MCP3425<I2C, D, OneShotMode>

Change the conversion mode to one-shot.

This conversion is side-effect free, so it will not write any configuration to the device until a first one-shot measurement is triggered.

source

pub fn set_config(&mut self, config: &Config) -> Result<(), Error<E>>

Write the specified configuration to the device and block until the first measurement is ready.

The wait-for-measurement logic is implemented with polling, since there are no non-blocking embedded_hal traits yet.

Note: Since the wait-until-ready logic needs to read the data register, when reading the measurement immediately after setting the configuration, that measurement will be returned as NotFresh.

source

pub fn read_measurement(&mut self) -> Result<Voltage, Error<E>>

Read a measurement from the device.

Note that the set_config method MUST have been called before, otherwise Error::NotInitialized will be returned.

If you poll faster than the sample rate, Error::NotReady will be returned.

Trait Implementations§

source§

impl<I2C: Debug, D: Debug, M: Debug> Debug for MCP3425<I2C, D, M>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<I2C: Default, D: Default, M: Default> Default for MCP3425<I2C, D, M>

source§

fn default() -> MCP3425<I2C, D, M>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<I2C, D, M> RefUnwindSafe for MCP3425<I2C, D, M>

§

impl<I2C, D, M> Send for MCP3425<I2C, D, M>
where D: Send, I2C: Send, M: Send,

§

impl<I2C, D, M> Sync for MCP3425<I2C, D, M>
where D: Sync, I2C: Sync, M: Sync,

§

impl<I2C, D, M> Unpin for MCP3425<I2C, D, M>
where D: Unpin, I2C: Unpin, M: Unpin,

§

impl<I2C, D, M> UnwindSafe for MCP3425<I2C, D, M>
where D: UnwindSafe, I2C: UnwindSafe, M: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.