Struct stm32wlxx_hal::gpio::Output
source · pub struct Output<P> { /* private fields */ }
Expand description
Output pin.
Implementations§
source§impl<P> Output<P>where
P: PinOps,
impl<P> Output<P>where P: PinOps,
sourcepub fn new(pin: P, args: &OutputArgs, cs: &CriticalSection) -> Self
pub fn new(pin: P, args: &OutputArgs, cs: &CriticalSection) -> Self
Create a new output pin from a GPIO.
Example
Configure GPIO port C3, C4, C5 as outputs. These are the GPIOs for the RF switch on the NUCLEO-WL55JC2.
use stm32wlxx_hal::{
gpio::{self, pins, Output, PortC},
pac,
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
const OUTPUT_ARGS: gpio::OutputArgs = gpio::OutputArgs {
level: gpio::PinState::Low,
speed: gpio::Speed::High,
ot: gpio::OutputType::PushPull,
pull: gpio::Pull::None,
};
let gpioc: PortC = PortC::split(dp.GPIOC, &mut dp.RCC);
let (c2, c4, c5): (Output<pins::C3>, Output<pins::C4>, Output<pins::C5>) =
cortex_m::interrupt::free(|cs| {
(
Output::new(gpioc.c3, &OUTPUT_ARGS, cs),
Output::new(gpioc.c4, &OUTPUT_ARGS, cs),
Output::new(gpioc.c5, &OUTPUT_ARGS, cs),
)
});
sourcepub fn default(pin: P, cs: &CriticalSection) -> Self
pub fn default(pin: P, cs: &CriticalSection) -> Self
Create a new output pin from a GPIO using the default settings.
Example
Configure GPIO C0 as an output.
use stm32wlxx_hal::{
gpio::{pins, Output, OutputArgs, PortC},
pac,
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
let gpioc: PortC = PortC::split(dp.GPIOC, &mut dp.RCC);
let mut c0: Output<pins::C0> = cortex_m::interrupt::free(|cs| Output::default(gpioc.c0, cs));
sourcepub unsafe fn steal() -> Self
pub unsafe fn steal() -> Self
Steal the output GPIO from whatever is currently using it.
Safety
- Ensure that the code stealing the GPIO has exclusive access to the peripheral. Singleton checks are bypassed with this method.
- You are responsible for setting up the GPIO correctly. No setup will occur when using this method.
Example
use stm32wlxx_hal::gpio::{pins, Output};
// ... setup occurs here
let b11: Output<pins::B11> = unsafe { Output::steal() };
sourcepub fn free(self) -> P
pub fn free(self) -> P
Free the GPIO pin.
Example
Configure a GPIO as an output, then free it.
use stm32wlxx_hal::{
gpio::{pins, Output, PortC},
pac,
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
let gpioc: PortC = PortC::split(dp.GPIOC, &mut dp.RCC);
let c0: Output<pins::C0> = cortex_m::interrupt::free(|cs| Output::default(gpioc.c0, cs));
let c0: pins::C0 = c0.free();
sourcepub fn set_level(&mut self, level: PinState)
pub fn set_level(&mut self, level: PinState)
Set the GPIO output level.
This is the same as the OutputPin
trait from the embedded hal, but
without the Infallible
result types.
Example
Pulse a GPIO pin.
use stm32wlxx_hal::{
gpio::{pins, Output, PinState, PortC},
pac,
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
let gpioc: PortC = PortC::split(dp.GPIOC, &mut dp.RCC);
let mut c0: Output<pins::C0> = cortex_m::interrupt::free(|cs| Output::default(gpioc.c0, cs));
c0.set_level(PinState::High);
c0.set_level(PinState::Low);
sourcepub fn set_level_high(&mut self)
pub fn set_level_high(&mut self)
Set the GPIO output level high.
This is the same as the OutputPin
trait from the embedded hal, but
without the Infallible
result types.
Example
Set GPIO C0 high.
use stm32wlxx_hal::{
gpio::{pins, Output, PortC},
pac,
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
let gpioc: PortC = PortC::split(dp.GPIOC, &mut dp.RCC);
let mut c0: Output<pins::C0> = cortex_m::interrupt::free(|cs| Output::default(gpioc.c0, cs));
c0.set_level_high();
sourcepub fn set_level_low(&mut self)
pub fn set_level_low(&mut self)
Set the GPIO output level high.
This is the same as the OutputPin
trait from the embedded hal, but
without the Infallible
result types.
Example
Set GPIO C0 low.
use stm32wlxx_hal::{
gpio::{pins, Output, PortC},
pac,
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
let gpioc: PortC = PortC::split(dp.GPIOC, &mut dp.RCC);
let mut c0: Output<pins::C0> = cortex_m::interrupt::free(|cs| Output::default(gpioc.c0, cs));
c0.set_level_low();
sourcepub fn level(&self) -> PinState
pub fn level(&self) -> PinState
Get the current GPIO output level.
Example
Toggle a GPIO pin.
use core::ops::Not;
use stm32wlxx_hal::{
gpio::{pins, Output, PinState, PortC},
pac,
};
let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();
let gpioc: PortC = PortC::split(dp.GPIOC, &mut dp.RCC);
let mut c0: Output<pins::C0> = cortex_m::interrupt::free(|cs| Output::default(gpioc.c0, cs));
c0.set_level(c0.level().not());