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,

source

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),
        )
    });
source

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));
source

pub unsafe fn steal() -> Self

Steal the output GPIO from whatever is currently using it.

Safety
  1. Ensure that the code stealing the GPIO has exclusive access to the peripheral. Singleton checks are bypassed with this method.
  2. 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() };
source

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();
source

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);
source

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();
source

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();
source

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());

Trait Implementations§

source§

impl<P: Debug> Debug for Output<P>

source§

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

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

impl<P> OutputPin for Output<P>where P: PinOps,

§

type Error = Infallible

Error type
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
§

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<P> StatefulOutputPin for Output<P>where P: PinOps,

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<P: PinOps> Default for Output<P>

Auto Trait Implementations§

§

impl<P> RefUnwindSafe for Output<P>where P: RefUnwindSafe,

§

impl<P> Send for Output<P>where P: Send,

§

impl<P> Sync for Output<P>where P: Sync,

§

impl<P> Unpin for Output<P>where P: Unpin,

§

impl<P> UnwindSafe for Output<P>where P: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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.

§

impl<P> ToggleableOutputPin for Pwhere P: Default,

§

fn toggle(&mut self) -> Result<(), <P as ToggleableOutputPin>::Error>

Toggle pin output

§

type Error = <P as OutputPin>::Error

Error type
source§

impl<T, U> TryFrom<U> for Twhere 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 Twhere 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.