Struct port_expander::Pin

source ·
pub struct Pin<'a, MODE, MUTEX> { /* private fields */ }
Expand description

Representation of a port-expander pin.

Pin is not constructed directly, this type is created by instanciating a port-expander and then getting access to all its pins using the .split() method.

Implementations§

source§

impl<'a, MODE, MUTEX, PD> Pin<'a, MODE, MUTEX>
where PD: PortDriver, MUTEX: PortMutex<Port = PD>,

source

pub fn pin_mask(&self) -> u32

source

pub fn access_port_driver<F, R>(&self, f: F) -> R
where F: FnOnce(&mut PD) -> R,

source§

impl<'a, MODE, MUTEX, PD> Pin<'a, MODE, MUTEX>
where PD: PortDriver + PortDriverTotemPole, MUTEX: PortMutex<Port = PD>,

source

pub fn into_input(self) -> Result<Pin<'a, Input, MUTEX>, PD::Error>

Configure this pin as an input.

The exact electrical details depend on the port-expander device which is used.

source

pub fn into_output(self) -> Result<Pin<'a, Output, MUTEX>, PD::Error>

Configure this pin as an output with an initial LOW state.

The LOW state is, as long as he port-expander chip allows this, entered without any electrical glitch.

source

pub fn into_output_high(self) -> Result<Pin<'a, Output, MUTEX>, PD::Error>

Configure this pin as an output with an initial HIGH state.

The HIGH state is, as long as he port-expander chip allows this, entered without any electrical glitch.

source§

impl<'a, MODE, MUTEX, PD> Pin<'a, MODE, MUTEX>
where PD: PortDriver + PortDriverPolarity, MUTEX: PortMutex<Port = PD>,

source

pub fn into_inverted(self) -> Result<Self, PD::Error>

Turn on hardware polarity inversion for this pin.

source

pub fn set_inverted(&mut self, inverted: bool) -> Result<(), PD::Error>

Set hardware polarity inversion for this pin.

source§

impl<'a, MODE: HasInput, MUTEX, PD> Pin<'a, MODE, MUTEX>
where PD: PortDriver, MUTEX: PortMutex<Port = PD>,

source

pub fn is_high(&self) -> Result<bool, PD::Error>

Read the pin’s input state and return true if it is HIGH.

source

pub fn is_low(&self) -> Result<bool, PD::Error>

Read the pin’s input state and return true if it is LOW.

source§

impl<'a, MODE: HasInput, MUTEX, PD> Pin<'a, MODE, MUTEX>
where PD: PortDriver + PortDriverPullUp, MUTEX: PortMutex<Port = PD>,

source

pub fn enable_pull_up(&mut self, enable: bool) -> Result<(), PD::Error>

Enable/Disable pull-up resistors for this pin.

If enable is true, the pull-up resistor is enabled, otherwise the pin is configured as floating input.

source§

impl<'a, MODE: HasInput, MUTEX, PD> Pin<'a, MODE, MUTEX>
where PD: PortDriver + PortDriverPullDown, MUTEX: PortMutex<Port = PD>,

source

pub fn enable_pull_down(&mut self, enable: bool) -> Result<(), PD::Error>

Enable/Disable pull-down resistors for this pin.

If enable is true, the pull-down resistor is enabled, otherwise the pin is configured as floating input.

source§

impl<'a, MODE: HasOutput, MUTEX, PD> Pin<'a, MODE, MUTEX>
where PD: PortDriver, MUTEX: PortMutex<Port = PD>,

source

pub fn set_high(&mut self) -> Result<(), PD::Error>

Set the pin’s output state to HIGH.

Note that this can have different electrical meanings depending on the port-expander chip.

source

pub fn set_low(&mut self) -> Result<(), PD::Error>

Set the pin’s output state to LOW.

Note that this can have different electrical meanings depending on the port-expander chip.

source

pub fn is_set_high(&self) -> Result<bool, PD::Error>

Return true if the pin’s output state is HIGH.

This method does not read the pin’s electrical state.

source

pub fn is_set_low(&self) -> Result<bool, PD::Error>

Return true if the pin’s output state is LOW.

This method does not read the pin’s electrical state.

source

pub fn toggle(&mut self) -> Result<(), PD::Error>

Toggle the pin’s output state.

Trait Implementations§

source§

impl<'a, MODE, MUTEX, PD> ErrorType for Pin<'a, MODE, MUTEX>
where PD: PortDriver + PortDriverTotemPole, PD::Error: Error, MUTEX: PortMutex<Port = PD>,

§

type Error = <PD as PortDriver>::Error

Error type
source§

impl<'a, MODE: HasInput, MUTEX, PD> InputPin for Pin<'a, MODE, MUTEX>
where PD: PortDriver + PortDriverTotemPole, <PD as PortDriver>::Error: Error, MUTEX: PortMutex<Port = PD>,

source§

fn is_high(&mut self) -> Result<bool, <PD as PortDriver>::Error>

Is the input pin high?
source§

fn is_low(&mut self) -> Result<bool, <PD as PortDriver>::Error>

Is the input pin low?
source§

impl<'a, MODE: HasOutput, MUTEX, PD> OutputPin for Pin<'a, MODE, MUTEX>
where PD: PortDriver + PortDriverTotemPole, <PD as PortDriver>::Error: Error, MUTEX: PortMutex<Port = PD>,

source§

fn set_low(&mut self) -> Result<(), Self::Error>

Drives the pin low. Read more
source§

fn set_high(&mut self) -> Result<(), Self::Error>

Drives the pin high. Read more
source§

fn set_state(&mut self, state: PinState) -> Result<(), Self::Error>

Drives the pin high or low depending on the provided value. Read more
source§

impl<'a, MODE: HasOutput, MUTEX, PD> StatefulOutputPin for Pin<'a, MODE, MUTEX>
where PD: PortDriver + PortDriverTotemPole, <PD as PortDriver>::Error: Error, MUTEX: PortMutex<Port = PD>,

source§

fn is_set_high(&mut self) -> Result<bool, Self::Error>

Is the pin in drive high mode? Read more
source§

fn is_set_low(&mut self) -> Result<bool, Self::Error>

Is the pin in drive low mode? Read more
source§

fn toggle(&mut self) -> Result<(), Self::Error>

Toggle pin output.

Auto Trait Implementations§

§

impl<'a, MODE, MUTEX> RefUnwindSafe for Pin<'a, MODE, MUTEX>
where MODE: RefUnwindSafe, MUTEX: RefUnwindSafe,

§

impl<'a, MODE, MUTEX> Send for Pin<'a, MODE, MUTEX>
where MODE: Send, MUTEX: Sync,

§

impl<'a, MODE, MUTEX> Sync for Pin<'a, MODE, MUTEX>
where MODE: Sync, MUTEX: Sync,

§

impl<'a, MODE, MUTEX> Unpin for Pin<'a, MODE, MUTEX>
where MODE: Unpin,

§

impl<'a, MODE, MUTEX> UnwindSafe for Pin<'a, MODE, MUTEX>
where MODE: UnwindSafe, MUTEX: RefUnwindSafe,

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.