Struct 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 Clone for Pin

Source§

fn clone(&self) -> Pin

Returns a duplicate 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 ErrorType for Pin

Source§

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

§

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> CloneToUninit for T
where T: Clone,

Source§

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

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