Struct stm32_hal2::gpio::Pin
source · [−]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
sourceimpl Pin
impl Pin
sourcepub fn new(port: Port, pin: u8, mode: PinMode) -> Self
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);
sourcepub fn mode(&mut self, value: PinMode)
pub fn mode(&mut self, value: PinMode)
Set pin mode. Eg, Output, Input, Analog, or Alt. Sets the MODER
register.
sourcepub fn output_type(&mut self, value: OutputType)
pub fn output_type(&mut self, value: OutputType)
Set output type. Sets the OTYPER
register.
sourcepub fn output_speed(&mut self, value: OutputSpeed)
pub fn output_speed(&mut self, value: OutputSpeed)
Set output speed to Low, Medium, or High. Sets the OSPEEDR
register.
sourcepub fn pull(&mut self, value: Pull)
pub fn pull(&mut self, value: Pull)
Set internal pull resistor: Pull up, pull down, or floating. Sets the PUPDR
register.
sourcepub fn cfg_lock(&mut self, value: CfgLock)
pub fn cfg_lock(&mut self, value: CfgLock)
Lock or unlock a port configuration. Sets the LCKR
register.
sourcepub fn get_state(&mut self) -> PinState
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.
sourcepub fn set_state(&mut self, value: PinState)
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.
sourcepub fn enable_interrupt(&mut self, edge: Edge)
pub fn enable_interrupt(&mut self, edge: Edge)
Configure this pin as an interrupt source. Set the edge as Rising or Falling.
sourcepub fn is_high(&self) -> bool
pub fn is_high(&self) -> bool
Check if the pin’s input voltage is high. Reads from the IDR
register.
sourcepub fn is_low(&self) -> bool
pub fn is_low(&self) -> bool
Check if the pin’s input voltage is low. Reads from the IDR
register.
Trait Implementations
sourceimpl OutputPin for Pin
impl OutputPin for Pin
type Error = Infallible
type Error = Infallible
Error type
sourceimpl ToggleableOutputPin for Pin
impl ToggleableOutputPin for Pin
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more