Expander

Struct Expander 

Source
pub struct Expander<EI: ExpanderInterface> { /* private fields */ }
Expand description

The port expander device itself.

Implementations§

Source§

impl<EI: ExpanderInterface + Send> Expander<EI>

Source

pub fn new(iface: EI) -> Self

Create a new Expander.

Takes ownership of the ExpanderInterface which it should use to communicate with the MAX7301.

Source

pub fn configure<'e>(&'e mut self) -> Configurator<'e, EI>

Begin (re)configuring the port expander hardware by returning a Configurator.

The Configurator is a builder-like interface that can be used to alter port modes and device configuration bits.

Source

pub fn into_immediate<M: IOMutex<Self>>(self) -> ImmediateIO<M, EI>

Convert this expander into an immediate-mode I/O adapter.

The I/O adapter can be used to generate individual PortPins that allow embedded-hal-compatible access to the GPIOs on the expander directly, with every operation immediately triggering a bus operation.

See ImmediateIO for detail.

Source

pub fn into_transactional<M: IOMutex<Self>>(self) -> TransactionalIO<M, EI>

Convert this expander into a transactional I/O adapter.

The I/O adapter can be used to generate individual PortPins that allow embedded-hal-compatible access to the GPIOs on the expander. Unlike immediate mode, the operations on PortPin trait methods are buffered in a write-back cache.

See TransactionalIO for detail.

Source

pub fn read_port(&mut self, port: u8) -> Result<bool, EI::Error>

Perform a read of the current value of a single I/O port on the expander.

Source

pub fn read_ports(&mut self, start_port: u8) -> Result<u8, EI::Error>

Perform a read of the current value of 8 consecutive I/O ports on the expander in a single bus transaction.

There is no alignment requirement; the start_port may be any valid port, and that port along with up to 7 following ports will be read in one transaction. The return value is a u8 where the LSB is the value read from start_port, and each higher bit is the 7 ports following it in ascending order. If any of the bits would correspond to a port higher than 31, then those bits will be unset.

Source

pub fn write_port(&mut self, port: u8, bit: bool) -> Result<(), EI::Error>

Write a value to a single I/O port on the expander.

Source

pub fn write_ports(&mut self, start_port: u8, bits: u8) -> Result<(), EI::Error>

Write a value to 8 consecutive I/O ports on the expander in a single bus transaction.

There is no alignment requirement; the start_port may be any valid port, and that port along with up to 7 following ports will be written in one transaction. bits is a u8 where the LSB is the value to write to start_port, and each higher bit is the 7 ports following it in ascending order. If any of the bits would correspond to a port higher than 31, then those bits will be ignored.

Auto Trait Implementations§

§

impl<EI> Freeze for Expander<EI>
where EI: Freeze,

§

impl<EI> RefUnwindSafe for Expander<EI>
where EI: RefUnwindSafe,

§

impl<EI> Send for Expander<EI>
where EI: Send,

§

impl<EI> Sync for Expander<EI>
where EI: Sync,

§

impl<EI> Unpin for Expander<EI>
where EI: Unpin,

§

impl<EI> UnwindSafe for Expander<EI>
where EI: 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>,

Source§

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>,

Source§

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.