GpioPin

Struct GpioPin 

Source
pub struct GpioPin<P, D> { /* private fields */ }
Expand description

A pin used for general purpose I/O (GPIO).

This struct is a wrapper around the representation of a specific pin P– it enables said pin to be used as a GPIO pin.

You can get access to an instance of this struct by switching a pin to the GPIO state, using Pin::into_input_pin or Pin::into_output_pin.

§embedded-hal traits

Implementations§

Source§

impl<P, D> GpioPin<P, D>
where P: Trait, D: Direction,

Source

pub fn inner(&self) -> &P

Get identifying information about this pin in the form of a pins::Trait

Source§

impl<P> GpioPin<P, Input>
where P: Trait,

Source

pub fn into_output(self, initial: Level) -> GpioPin<P, Output>

Set pin direction to output

This method is only available while the pin is in input mode.

Consumes the pin instance and returns a new instance that is in output mode, making the methods to set the output level available.

Source

pub fn into_dynamic( self, initial_level: Level, initial_direction: DynamicPinDirection, ) -> GpioPin<P, Dynamic>

Set pin direction to dynamic (i.e. changeable at runtime)

This method is only available when the pin is not already in dynamic mode.

Consumes the pin instance and returns a new instance that is in dynamic mode, making the methods to change direction as well as read/set levels (depending on the current diection) available.

Source

pub fn is_high(&self) -> bool

Indicates wether the voltage at the pin is currently HIGH

This method is only available, if two conditions are met:

  • The pin is in the GPIO state.
  • The pin direction is set to input.

See Pin::into_input_pin and into_input. Unless both of these conditions are met, code trying to call this method will not compile.

Source

pub fn is_low(&self) -> bool

Indicates wether the pin input is LOW

This method is only available, if two conditions are met:

  • The pin is in the GPIO state.
  • The pin direction is set to input.

See Pin::into_input_pin and into_input. Unless both of these conditions are met, code trying to call this method will not compile.

Source

pub fn get_level(&self) -> Level

Returns the current voltage level at this pin.

This method is only available, if two conditions are met:

  • The pin is in the GPIO state.
  • The pin direction is set to input.

See Pin::into_input_pin and into_input. Unless both of these conditions are met, code trying to call this method will not compile.

Source§

impl<P> GpioPin<P, Output>
where P: Trait,

Source

pub fn into_input(self) -> GpioPin<P, Input>

Set pin direction to input

This method is only available while the pin is in output mode.

Consumes the pin instance and returns a new instance that is in output mode, making the methods to set the output level available.

Source

pub fn into_dynamic( self, initial_level: Level, initial_direction: DynamicPinDirection, ) -> GpioPin<P, Dynamic>

Set pin direction to dynamic (i.e. changeable at runtime)

This method is only available when the pin is not already in dynamic mode.

Consumes the pin instance and returns a new instance that is in dynamic mode, making the methods to change direction as well as read/set levels (depending on the current diection) available.

Source

pub fn set_high(&mut self)

Set the pin output to HIGH

This method is only available, if two conditions are met:

  • The pin is in the GPIO state.
  • The pin direction is set to output.

See Pin::into_output_pin and into_output. Unless both of these conditions are met, code trying to call this method will not compile.

Source

pub fn set_low(&mut self)

Set the pin output to LOW

This method is only available, if two conditions are met:

  • The pin is in the GPIO state.
  • The pin direction is set to output.

See Pin::into_output_pin and into_output. Unless both of these conditions are met, code trying to call this method will not compile.

Source

pub fn is_set_high(&self) -> bool

Indicates whether the pin output is currently set to HIGH

This method is only available, if two conditions are met:

  • The pin is in the GPIO state.
  • The pin direction is set to output.

See Pin::into_output_pin and into_output. Unless both of these conditions are met, code trying to call this method will not compile.

Source

pub fn is_set_low(&self) -> bool

Indicates whether the pin output is currently set to LOW

This method is only available, if two conditions are met:

  • The pin is in the GPIO state.
  • The pin direction is set to output.

See Pin::into_output_pin and into_output. Unless both of these conditions are met, code trying to call this method will not compile.

Source

pub fn get_set_level(&self) -> Level

Returns the level to which this pin is currently set

This method is only available, if two conditions are met:

  • The pin is in the GPIO state.
  • The pin direction is set to output.

See Pin::into_output_pin and into_output. Unless both of these conditions are met, code trying to call this method will not compile.

Source

pub fn toggle(&mut self)

Toggle the pin output

This method is only available, if two conditions are met:

  • The pin is in the GPIO state.
  • The pin direction is set to output.

See Pin::into_output_pin and into_output. Unless both of these conditions are met, code trying to call this method will not compile.

Source§

impl<P> GpioPin<P, Dynamic>
where P: Trait,

Source

pub fn direction_is_output(&self) -> bool

Tell us whether this pin’s direction is currently set to Output.

Source

pub fn direction_is_input(&self) -> bool

Tell us whether this pin’s direction is currently set to Input.

Source

pub fn switch_to_input(&mut self)

Switch pin direction to input. If the pin is already an input pin, this does nothing.

Source

pub fn switch_to_output(&mut self, level: Level)

Switch pin direction to output with output level set to level. If the pin is already an output pin, this function only switches its level to level.

Source

pub fn set_high(&mut self)

Set the pin level to High. Note that this will be executed regardless of the current pin direction. This enables you to set the initial pin level before switching to output

Source

pub fn set_low(&mut self)

Set the pin level to Low. Note that this will be executed regardless of the current pin direction. This enables you to set the initial pin level before switching to output

Source

pub fn get_level(&self) -> Level

Returns the current voltage level at this pin. This can be used when the pin is in any direction:

If it is currently an Output pin, it indicates to which level the pin is set If it is currently an Input pin, it indicates the level currently present at this pin

This method is only available, if the pin has been set to dynamic mode. See Pin::into_dynamic_pin. Unless this condition is met, code trying to call this method will not compile.

Trait Implementations§

Source§

impl<P> InputPin for GpioPin<P, Dynamic>
where P: Trait,

Source§

type Error = DynamicPinErr

Error type
Source§

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

Is the input pin high?
Source§

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

Is the input pin low?
Source§

impl<P> InputPin for GpioPin<P, Input>
where P: Trait,

Source§

type Error = Void

Error type
Source§

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

Is the input pin high?
Source§

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

Is the input pin low?
Source§

impl<P> InputPin for GpioPin<P, Input>
where P: Trait,

Source§

type Error = Void

Error type
Source§

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

Is the input pin high?
Source§

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

Is the input pin low?
Source§

impl<P> OutputPin for GpioPin<P, Dynamic>
where P: Trait,

Source§

type Error = DynamicPinErr

Error type
Source§

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

Drives the pin high Read more
Source§

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

Drives the pin low 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<P> OutputPin for GpioPin<P, Output>
where P: Trait,

Source§

type Error = Void

Error type
Source§

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

Drives the pin high Read more
Source§

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

Drives the pin low 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<P> OutputPin for GpioPin<P, Output>
where P: Trait,

Source§

type Error = Void

Error type
Source§

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

Drives the pin high Read more
Source§

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

Drives the pin low 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<P> StatefulOutputPin for GpioPin<P, Dynamic>
where P: Trait,

Source§

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

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

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

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

impl<P> StatefulOutputPin for GpioPin<P, Output>
where P: Trait,

Source§

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

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

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

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

impl<P> StatefulOutputPin for GpioPin<P, Output>
where P: Trait,

Source§

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

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

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

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

impl<P> ToggleableOutputPin for GpioPin<P, Output>
where P: Trait,

Source§

type Error = Void

Error type
Source§

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

Toggle pin output.
Source§

impl<P> ToggleableOutputPin for GpioPin<P, Output>
where P: Trait,

Source§

type Error = Void

Error type
Source§

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

Toggle pin output.

Auto Trait Implementations§

§

impl<P, D> Freeze for GpioPin<P, D>
where P: Freeze, D: Freeze,

§

impl<P, D> RefUnwindSafe for GpioPin<P, D>

§

impl<P, D> Send for GpioPin<P, D>
where P: Send, D: Send,

§

impl<P, D> Sync for GpioPin<P, D>
where P: Sync, D: Sync,

§

impl<P, D> Unpin for GpioPin<P, D>
where P: Unpin, D: Unpin,

§

impl<P, D> UnwindSafe for GpioPin<P, D>
where P: UnwindSafe, D: 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.