Struct stm32_hal2::gpio::Pin

source ·
pub struct Pin {
    pub port: Port,
    pub pin: u8,
}
Expand description

Represents a single GPIO pin. Allows configuration, and reading/setting state.

Fields§

§port: Port

The GPIO Port letter. Eg A, B, C.

§pin: u8

The pin number: 1 - 15.

Implementations§

source§

impl Pin

source

pub fn new(port: Port, pin: u8, mode: PinMode) -> Self

Create a new pin, with a specific mode. Enables the RCC peripheral clock to the port, if not already enabled. Example: let pa1 = Pin::new(Port::A, 1, PinMode::Output); Leaves settings other than mode and alternate function (if applicable) at their hardware defaults.

source

pub fn mode(&mut self, value: PinMode)

Set pin mode. Eg, Output, Input, Analog, or Alt. Sets the MODER register.

source

pub fn output_type(&mut self, value: OutputType)

Set output type. Sets the OTYPER register.

source

pub fn output_speed(&mut self, value: OutputSpeed)

Set output speed to Low, Medium, or High. Sets the OSPEEDR register.

source

pub fn pull(&mut self, value: Pull)

Set internal pull resistor: Pull up, pull down, or floating. Sets the PUPDR register.

source

pub fn cfg_lock(&mut self, value: CfgLock)

Lock or unlock a port configuration. Sets the LCKR register.

source

pub fn get_state(&mut self) -> PinState

Read the input data register. Eg determine if the pin is high or low. See also is_high() and is_low(). Reads from the IDR register.

source

pub fn set_state(&mut self, value: PinState)

Set a pin state (ie set high or low output voltage level). See also set_high() and set_low(). Sets the BSRR register. Atomic.

source

pub fn enable_interrupt(&mut self, edge: Edge)

Configure this pin as an interrupt source. Set the edge as Rising or Falling.

source

pub fn is_high(&self) -> bool

Check if the pin’s input voltage is high. Reads from the IDR register.

source

pub fn is_low(&self) -> bool

Check if the pin’s input voltage is low. Reads from the IDR register.

source

pub fn set_high(&mut self)

Set the pin’s output voltage to high. Sets the BSRR register. Atomic.

source

pub fn set_low(&mut self)

Set the pin’s output voltage to low. Sets the BSRR register. Atomic.

source

pub fn toggle(&mut self)

Toggle output voltage between low and high. Sets the BSRR register. Atomic.

Trait Implementations§

source§

impl ErrorType for Pin

§

type Error = Infallible

Error type
source§

impl InputPin for Pin

source§

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

Is the input pin high?
source§

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

Is the input pin low?
source§

impl OutputPin for Pin

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 StatefulOutputPin for Pin

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 RefUnwindSafe for Pin

§

impl Send for Pin

§

impl Sync for Pin

§

impl Unpin for Pin

§

impl UnwindSafe for Pin

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.