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>
impl<I2C, E> MCP23017<I2C>
Sourcepub fn default(i2c: I2C) -> Result<MCP23017<I2C>, Error<E>>
pub fn default(i2c: I2C) -> Result<MCP23017<I2C>, Error<E>>
Creates an expander with the default configuration.
Sourcepub fn new(i2c: I2C, address: u8) -> Result<MCP23017<I2C>, Error<E>>
pub fn new(i2c: I2C, address: u8) -> Result<MCP23017<I2C>, Error<E>>
Creates an expander with specific address.
Sourcepub fn init_hardware(&mut self) -> Result<(), Error<E>>
pub fn init_hardware(&mut self) -> Result<(), Error<E>>
Initiates hardware with basic setup.
Sourcepub fn pin_mode(&mut self, pin: u8, pin_mode: PinMode) -> Result<(), E>
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
.
Sourcepub fn all_pin_mode(&mut self, pin_mode: PinMode) -> Result<(), E>
pub fn all_pin_mode(&mut self, pin_mode: PinMode) -> Result<(), E>
Sets all pins’ modes to either Mode::INPUT
or Mode::OUTPUT
.
Sourcepub fn read_gpioab(&mut self) -> Result<u16, E>
pub fn read_gpioab(&mut self) -> Result<u16, E>
Reads all 16 pins (port A and B) into a single 16 bit variable.
Sourcepub fn read_gpio(&mut self, port: Port) -> Result<u8, E>
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.
Sourcepub fn write_gpioab(&mut self, value: u16) -> Result<(), E>
pub fn write_gpioab(&mut self, value: u16) -> Result<(), E>
Writes all the pins with the value at the same time.
Sourcepub fn write_gpio(&mut self, port: Port, value: u8) -> Result<(), E>
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.
Sourcepub fn digital_write(&mut self, pin: u8, value: bool) -> Result<(), E>
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.
Sourcepub fn digital_read(&mut self, pin: u8) -> Result<bool, E>
pub fn digital_read(&mut self, pin: u8) -> Result<bool, E>
Reads a single pin.
Sourcepub fn pull_up(&mut self, pin: u8, value: bool) -> Result<(), E>
pub fn pull_up(&mut self, pin: u8, value: bool) -> Result<(), E>
Enables or disables the internal pull-up resistor for a single pin.
Sourcepub fn invert_input_polarity(&mut self, pin: u8, value: bool) -> Result<(), E>
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.
Sourcepub fn setup_interrupts(
&mut self,
mirroring: bool,
open_drain: bool,
polarity: Polarity,
) -> Result<(), E>
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)
Sourcepub fn setup_interrupt_pin(
&mut self,
pin: u8,
int_mode: InterruptMode,
) -> Result<(), E>
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.
Sourcepub fn get_last_interrupt_pin(&mut self) -> Result<u8, Error<E>>
pub fn get_last_interrupt_pin(&mut self) -> Result<u8, Error<E>>
Get last interrupt pin
Sourcepub fn get_last_interrupt_value(&mut self) -> Result<u8, Error<E>>
pub fn get_last_interrupt_value(&mut self) -> Result<u8, Error<E>>
Gets last interrupt value