Struct MCP23017

Source
pub struct MCP23017<I2C: Write + WriteRead> {
    pub address: u8,
    /* private fields */
}
Expand description

Struct for an MCP23017. See the crate-level documentation for general info on the device and the operation of this driver.

Fields§

§address: u8

The I2C slave address of this device.

Implementations§

Source§

impl<I2C, E> MCP23017<I2C>
where I2C: WriteRead<Error = E> + Write<Error = E>,

Source

pub fn default(i2c: I2C) -> Result<MCP23017<I2C>, Error<E>>
where I2C: Write<Error = E> + WriteRead<Error = E>,

Creates an expander with the default configuration.

Source

pub fn new(i2c: I2C, address: u8) -> Result<MCP23017<I2C>, Error<E>>
where I2C: Write<Error = E> + WriteRead<Error = E>,

Creates an expander with specific address.

Source

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

Initiates hardware with basic setup.

Source

pub fn pin_mode(&mut self, pin: u8, pin_mode: PinMode) -> Result<(), E>

Sets the mode for a single pin to either Mode::INPUT or Mode::OUTPUT.

Source

pub fn all_pin_mode(&mut self, pin_mode: PinMode) -> Result<(), E>

Sets all pins’ modes to either Mode::INPUT or Mode::OUTPUT.

Source

pub fn read_gpioab(&mut self) -> Result<u16, E>

Reads all 16 pins (port A and B) into a single 16 bit variable.

Source

pub fn read_gpio(&mut self, port: Port) -> Result<u8, E>

Reads a single port, A or B, and returns its current 8 bit value.

Source

pub fn write_gpioab(&mut self, value: u16) -> Result<(), E>

Writes all the pins with the value at the same time.

Source

pub fn write_gpio(&mut self, port: Port, value: u8) -> Result<(), E>

Writes all the pins of one port with the value at the same time.

Source

pub fn digital_write(&mut self, pin: u8, value: bool) -> Result<(), E>

Writes a single bit to a single pin. This function internally reads from the output latch register (OLATA/OLATB) and writes to the GPIO register.

Source

pub fn digital_read(&mut self, pin: u8) -> Result<bool, E>

Reads a single pin.

Source

pub fn pull_up(&mut self, pin: u8, value: bool) -> Result<(), E>

Enables or disables the internal pull-up resistor for a single pin.

Source

pub fn invert_input_polarity(&mut self, pin: u8, value: bool) -> Result<(), E>

Inverts the input polarity for a single pin. This uses the IPOLA or IPOLB registers, see the datasheet for more information.

Source

pub fn setup_interrupts( &mut self, mirroring: bool, open_drain: bool, polarity: Polarity, ) -> Result<(), E>

Configures the interrupt system. both port A and B are assigned the same configuration. mirroring will OR both INTA and INTB pins. open_drain will set the INT pin to value or open drain. polarity will set LOW or HIGH on interrupt. Default values after Power On Reset are: (false, false, LOW)

Source

pub fn setup_interrupt_pin( &mut self, pin: u8, int_mode: InterruptMode, ) -> Result<(), E>

Sets up a pin for interrupt. Note that the interrupt condition finishes when you read the information about the port / value that caused the interrupt or you read the port itself.

Source

pub fn get_last_interrupt_pin(&mut self) -> Result<u8, Error<E>>

Get last interrupt pin

Source

pub fn get_last_interrupt_value(&mut self) -> Result<u8, Error<E>>

Gets last interrupt value

Trait Implementations§

Source§

impl<I2C: Clone + Write + WriteRead> Clone for MCP23017<I2C>

Source§

fn clone(&self) -> MCP23017<I2C>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<I2C: Debug + Write + WriteRead> Debug for MCP23017<I2C>

Source§

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

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

impl<I2C: Copy + Write + WriteRead> Copy for MCP23017<I2C>

Auto Trait Implementations§

§

impl<I2C> Freeze for MCP23017<I2C>
where I2C: Freeze,

§

impl<I2C> RefUnwindSafe for MCP23017<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for MCP23017<I2C>
where I2C: Send,

§

impl<I2C> Sync for MCP23017<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for MCP23017<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for MCP23017<I2C>
where I2C: 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.