Struct Pin

Source
pub struct Pin<const P: char, const N: u8, MODE = Analog> { /* private fields */ }
Expand description

Generic pin type

  • MODE is one of the pin modes (see Modes section).
  • P is port name: A for GPIOA, B for GPIOB, etc.
  • N is pin number: from 0 to 15.

Implementations§

Source§

impl<const P: char, const N: u8, const A: u8> Pin<P, N, Alternate<A, PushPull>>

Source

pub fn set_open_drain(self) -> Pin<P, N, Alternate<A, OpenDrain>>

Turns pin alternate configuration pin into open drain

Source§

impl<const P: char, const N: u8, MODE: PinMode> Pin<P, N, MODE>

Source

pub fn into_alternate<const A: u8>(self) -> Pin<P, N, Alternate<A, PushPull>>
where Self: IntoAf<A>,

Configures the pin to operate alternate mode

Source

pub fn into_alternate_af0(self) -> Pin<P, N, Alternate<0, PushPull>>
where Self: IntoAf<0>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 0 mode

Source

pub fn into_alternate_af1(self) -> Pin<P, N, Alternate<1, PushPull>>
where Self: IntoAf<1>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 1 mode

Source

pub fn into_alternate_af2(self) -> Pin<P, N, Alternate<2, PushPull>>
where Self: IntoAf<2>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 2 mode

Source

pub fn into_alternate_af3(self) -> Pin<P, N, Alternate<3, PushPull>>
where Self: IntoAf<3>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 3 mode

Source

pub fn into_alternate_af4(self) -> Pin<P, N, Alternate<4, PushPull>>
where Self: IntoAf<4>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 4 mode

Source

pub fn into_alternate_af5(self) -> Pin<P, N, Alternate<5, PushPull>>
where Self: IntoAf<5>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 5 mode

Source

pub fn into_alternate_af6(self) -> Pin<P, N, Alternate<6, PushPull>>
where Self: IntoAf<6>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 6 mode

Source

pub fn into_alternate_af7(self) -> Pin<P, N, Alternate<7, PushPull>>
where Self: IntoAf<7>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 7 mode

Source

pub fn into_alternate_af8(self) -> Pin<P, N, Alternate<8, PushPull>>
where Self: IntoAf<8>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 8 mode

Source

pub fn into_alternate_af9(self) -> Pin<P, N, Alternate<9, PushPull>>
where Self: IntoAf<9>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 9 mode

Source

pub fn into_alternate_af10(self) -> Pin<P, N, Alternate<10, PushPull>>
where Self: IntoAf<10>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 10 mode

Source

pub fn into_alternate_af11(self) -> Pin<P, N, Alternate<11, PushPull>>
where Self: IntoAf<11>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 11 mode

Source

pub fn into_alternate_af12(self) -> Pin<P, N, Alternate<12, PushPull>>
where Self: IntoAf<12>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 12 mode

Source

pub fn into_alternate_af13(self) -> Pin<P, N, Alternate<13, PushPull>>
where Self: IntoAf<13>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 13 mode

Source

pub fn into_alternate_af14(self) -> Pin<P, N, Alternate<14, PushPull>>
where Self: IntoAf<14>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 14 mode

Source

pub fn into_alternate_af15(self) -> Pin<P, N, Alternate<15, PushPull>>
where Self: IntoAf<15>,

👎Deprecated since 0.12.0: Use the .into_alternate() method instead

Configures the pin to operate in alternate function 15 mode

Source

pub fn into_alternate_open_drain<const A: u8>( self, ) -> Pin<P, N, Alternate<A, OpenDrain>>
where Self: IntoAf<A>,

Configures the pin to operate in alternate open drain mode

Source

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

Configures the pin to operate as a input pin

Source

pub fn into_floating_input(self) -> Pin<P, N, Input>

Configures the pin to operate as a floating input pin

Source

pub fn into_pull_down_input(self) -> Pin<P, N, Input>

Configures the pin to operate as a pulled down input pin

Source

pub fn into_pull_up_input(self) -> Pin<P, N, Input>

Configures the pin to operate as a pulled up input pin

Source

pub fn into_open_drain_output(self) -> Pin<P, N, Output<OpenDrain>>

Configures the pin to operate as an open drain output pin Initial state will be low.

Source

pub fn into_open_drain_output_in_state( self, initial_state: PinState, ) -> Pin<P, N, Output<OpenDrain>>

Configures the pin to operate as an open-drain output pin. initial_state specifies whether the pin should be initially high or low.

Source

pub fn into_push_pull_output(self) -> Pin<P, N, Output<PushPull>>

Configures the pin to operate as an push pull output pin Initial state will be low.

Source

pub fn into_push_pull_output_in_state( self, initial_state: PinState, ) -> Pin<P, N, Output<PushPull>>

Configures the pin to operate as an push-pull output pin. initial_state specifies whether the pin should be initially high or low.

Source

pub fn into_analog(self) -> Pin<P, N, Analog>

Configures the pin to operate as an analog input pin

Source

pub fn into_dynamic(self) -> DynamicPin<P, N>

Configures the pin as a pin that can change between input and output without changing the type. It starts out as a floating input

Source

pub fn into_mode<M: PinMode>(self) -> Pin<P, N, M>

Converts pin into specified mode

Source§

impl<const P: char, const N: u8, MODE> Pin<P, N, MODE>
where MODE: PinMode,

Source

pub fn with_input<R>(&mut self, f: impl FnOnce(&mut Pin<P, N, Input>) -> R) -> R

Temporarily configures this pin as a input.

The closure f is called with the reconfigured pin. After it returns, the pin will be configured back.

Source

pub fn with_analog<R>( &mut self, f: impl FnOnce(&mut Pin<P, N, Analog>) -> R, ) -> R

Temporarily configures this pin as an analog pin.

The closure f is called with the reconfigured pin. After it returns, the pin will be configured back.

Source

pub fn with_open_drain_output<R>( &mut self, f: impl FnOnce(&mut Pin<P, N, Output<OpenDrain>>) -> R, ) -> R

Temporarily configures this pin as an open drain output.

The closure f is called with the reconfigured pin. After it returns, the pin will be configured back. The value of the pin after conversion is undefined. If you want to control it, use with_open_drain_output_in_state

Source

pub fn with_open_drain_output_in_state<R>( &mut self, state: PinState, f: impl FnOnce(&mut Pin<P, N, Output<OpenDrain>>) -> R, ) -> R

Temporarily configures this pin as an open drain output .

The closure f is called with the reconfigured pin. After it returns, the pin will be configured back. Note that the new state is set slightly before conversion happens. This can cause a short output glitch if switching between output modes

Source

pub fn with_push_pull_output<R>( &mut self, f: impl FnOnce(&mut Pin<P, N, Output<PushPull>>) -> R, ) -> R

Temporarily configures this pin as a push-pull output.

The closure f is called with the reconfigured pin. After it returns, the pin will be configured back. The value of the pin after conversion is undefined. If you want to control it, use with_push_pull_output_in_state

Source

pub fn with_push_pull_output_in_state<R>( &mut self, state: PinState, f: impl FnOnce(&mut Pin<P, N, Output<PushPull>>) -> R, ) -> R

Temporarily configures this pin as a push-pull output.

The closure f is called with the reconfigured pin. After it returns, the pin will be configured back. Note that the new state is set slightly before conversion happens. This can cause a short output glitch if switching between output modes

Source§

impl<const P: char, const N: u8, MODE> Pin<P, N, MODE>

Source

pub const fn interrupt(&self) -> Interrupt

NVIC interrupt number of interrupt from this pin

Used to unmask / enable the interrupt with cortex_m::peripheral::NVIC::unmask(). This is also useful for all other cortex_m::peripheral::NVIC functions.

Source§

impl<const P: char, const N: u8, MODE> Pin<P, N, MODE>
where MODE: OutputSpeed,

Source

pub fn set_speed(&mut self, speed: Speed)

Set pin speed

Source

pub fn speed(self, speed: Speed) -> Self

Set pin speed

Source§

impl<const P: char, const N: u8, MODE> Pin<P, N, MODE>
where MODE: Active,

Source

pub fn set_internal_resistor(&mut self, resistor: Pull)

Set the internal pull-up and pull-down resistor

Source

pub fn internal_resistor(self, resistor: Pull) -> Self

Set the internal pull-up and pull-down resistor

Source

pub fn internal_pull_up(self, on: bool) -> Self

Enables / disables the internal pull up

Source

pub fn internal_pull_down(self, on: bool) -> Self

Enables / disables the internal pull down

Source§

impl<const P: char, const N: u8, MODE> Pin<P, N, MODE>

Source

pub fn erase_number(self) -> PartiallyErasedPin<P, MODE>

Erases the pin number from the type

This is useful when you want to collect the pins into an array where you need all the elements to have the same type

Source

pub fn erase(self) -> ErasedPin<MODE>

Erases the pin number and the port from the type

This is useful when you want to collect the pins into an array where you need all the elements to have the same type

Source§

impl<const P: char, const N: u8, MODE> Pin<P, N, Output<MODE>>

Source

pub fn set_high(&mut self)

Drives the pin high

Source

pub fn set_low(&mut self)

Drives the pin low

Source

pub fn get_state(&self) -> PinState

Is the pin in drive high or low mode?

Source

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

Drives the pin high or low depending on the provided value

Source

pub fn is_set_high(&self) -> bool

Is the pin in drive high mode?

Source

pub fn is_set_low(&self) -> bool

Is the pin in drive low mode?

Source

pub fn toggle(&mut self)

Toggle pin output

Source§

impl<const P: char, const N: u8, MODE> Pin<P, N, MODE>
where MODE: Readable,

Source

pub fn is_high(&self) -> bool

Is the input pin high?

Source

pub fn is_low(&self) -> bool

Is the input pin low?

Trait Implementations§

Source§

impl<const P: char, const N: u8, MODE> Debug for Pin<P, N, MODE>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const P: char, const N: u8, MODE> Format for Pin<P, N, MODE>

Source§

fn format(&self, f: Formatter<'_>)

Writes the defmt representation of self to fmt.
Source§

impl From<Pin<'C', 2, Alternate<10>>> for Usb1UlpiDirPin

Available on crate feature usb_hs only.
Source§

fn from(v: PC2<Alternate<10>>) -> Self

Converts to this type from the input type.
Source§

impl From<Pin<'C', 3, Alternate<10>>> for Usb1UlpiNxtPin

Available on crate feature usb_hs only.
Source§

fn from(v: PC3<Alternate<10>>) -> Self

Converts to this type from the input type.
Source§

impl From<Pin<'H', 4, Alternate<10>>> for Usb1UlpiNxtPin

Available on crate feature usb_hs only.
Source§

fn from(v: PH4<Alternate<10>>) -> Self

Converts to this type from the input type.
Source§

impl From<Pin<'I', 11, Alternate<10>>> for Usb1UlpiDirPin

Available on crate feature usb_hs only.
Source§

fn from(v: PI11<Alternate<10>>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8> From<Pin<P, N>> for Pin<P, N, Input>

Source§

fn from(f: Pin<P, N, Analog>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8, Otype> From<Pin<P, N>> for Pin<P, N, Output<Otype>>
where Output<Otype>: PinMode,

Source§

fn from(f: Pin<P, N, Analog>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8, const A: u8, Otype, MODE> From<Pin<P, N, Alternate<A, Otype>>> for Pin<P, N, MODE>
where Alternate<A, Otype>: PinMode, MODE: PinMode + NotAlt,

Source§

fn from(f: Pin<P, N, Alternate<A, Otype>>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8, const A: u8, const B: u8> From<Pin<P, N, Alternate<B>>> for Pin<P, N, Alternate<A, OpenDrain>>
where Self: IntoAf<A>,

Source§

fn from(f: Pin<P, N, Alternate<B, PushPull>>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8> From<Pin<P, N, Input>> for Pin<P, N, Analog>

Source§

fn from(f: Pin<P, N, Input>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8, Otype> From<Pin<P, N, Input>> for Pin<P, N, Output<Otype>>
where Output<Otype>: PinMode,

Source§

fn from(f: Pin<P, N, Input>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8, MODE> From<Pin<P, N, MODE>> for ErasedPin<MODE>

Source§

fn from(p: Pin<P, N, MODE>) -> Self

Pin-to-erased pin conversion using the From trait.

Note that From is the reciprocal of Into.

Source§

impl<const P: char, const N: u8, MODE> From<Pin<P, N, MODE>> for PartiallyErasedPin<P, MODE>

Source§

fn from(p: Pin<P, N, MODE>) -> Self

Pin-to-partially erased pin conversion using the From trait.

Note that From is the reciprocal of Into.

Source§

impl<const P: char, const N: u8, MODE: PinMode + NotAlt, const A: u8, Otype> From<Pin<P, N, MODE>> for Pin<P, N, Alternate<A, Otype>>
where Alternate<A, Otype>: PinMode, Self: IntoAf<A>,

Source§

fn from(f: Pin<P, N, MODE>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8> From<Pin<P, N, Output<OpenDrain>>> for Pin<P, N, Output<PushPull>>

Source§

fn from(f: Pin<P, N, Output<OpenDrain>>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8, Otype> From<Pin<P, N, Output<Otype>>> for Pin<P, N, Analog>
where Output<Otype>: PinMode,

Source§

fn from(f: Pin<P, N, Output<Otype>>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8, Otype> From<Pin<P, N, Output<Otype>>> for Pin<P, N, Input>
where Output<Otype>: PinMode,

Source§

fn from(f: Pin<P, N, Output<Otype>>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8> From<Pin<P, N, Output>> for Pin<P, N, Output<OpenDrain>>

Source§

fn from(f: Pin<P, N, Output<PushPull>>) -> Self

Converts to this type from the input type.
Source§

impl<const P: char, const N: u8, MODE> InputPin for Pin<P, N, MODE>
where MODE: Readable,

Source§

type Error = Infallible

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<const P: char, const N: u8, Otype> IoPin<Pin<P, N, Input>, Pin<P, N, Output<Otype>>> for Pin<P, N, Input>
where Output<Otype>: PinMode,

Source§

type Error = Infallible

Error type.
Source§

fn into_input_pin(self) -> Result<Self, Self::Error>

Tries to convert this pin to input mode. Read more
Source§

fn into_output_pin( self, state: PinState, ) -> Result<Pin<P, N, Output<Otype>>, Self::Error>

Tries to convert this pin to output mode with the given initial state. Read more
Source§

impl<const P: char, const N: u8, Otype> IoPin<Pin<P, N, Input>, Pin<P, N, Output<Otype>>> for Pin<P, N, Output<Otype>>
where Output<Otype>: PinMode,

Source§

type Error = Infallible

Error type.
Source§

fn into_input_pin(self) -> Result<Pin<P, N, Input>, Self::Error>

Tries to convert this pin to input mode. Read more
Source§

fn into_output_pin(self, state: PinState) -> Result<Self, Self::Error>

Tries to convert this pin to output mode with the given initial state. Read more
Source§

impl<const P: char, const N: u8> IoPin<Pin<P, N, Output<OpenDrain>>, Pin<P, N, Output<OpenDrain>>> for Pin<P, N, Output<OpenDrain>>

Source§

type Error = Infallible

Error type.
Source§

fn into_input_pin(self) -> Result<Self, Self::Error>

Tries to convert this pin to input mode. Read more
Source§

fn into_output_pin(self, state: PinState) -> Result<Self, Self::Error>

Tries to convert this pin to output mode with the given initial state. Read more
Source§

impl<const P: char, const N: u8, MODE> OutputPin for Pin<P, N, Output<MODE>>

Source§

type Error = Infallible

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<const P: char, const N: u8, MODE> PinExt for Pin<P, N, MODE>

Source§

type Mode = MODE

Current pin mode
Source§

fn pin_id(&self) -> u8

Pin number
Source§

fn port_id(&self) -> u8

Port number starting from 0
Source§

impl<const P: char, const N: u8, MODE> StatefulOutputPin for Pin<P, N, Output<MODE>>

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<const P: char, const N: u8, MODE> ToggleableOutputPin for Pin<P, N, Output<MODE>>

Source§

type Error = Infallible

Error type
Source§

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

Toggle pin output.

Auto Trait Implementations§

§

impl<const P: char, const N: u8, MODE> Freeze for Pin<P, N, MODE>

§

impl<const P: char, const N: u8, MODE> RefUnwindSafe for Pin<P, N, MODE>
where MODE: RefUnwindSafe,

§

impl<const P: char, const N: u8, MODE> Send for Pin<P, N, MODE>
where MODE: Send,

§

impl<const P: char, const N: u8, MODE> Sync for Pin<P, N, MODE>
where MODE: Sync,

§

impl<const P: char, const N: u8, MODE> Unpin for Pin<P, N, MODE>
where MODE: Unpin,

§

impl<const P: char, const N: u8, MODE> UnwindSafe for Pin<P, N, MODE>
where MODE: 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.