Struct GpioDriver

Source
pub struct GpioDriver<'a> {
    callbacks: [Option<Box<dyn FnMut(u32, EventType) + 'a>>; 16],
    configs: [GpioConfig; 16],
}
Expand description

A GPIO driver for STM32F407

Fields§

§callbacks: [Option<Box<dyn FnMut(u32, EventType) + 'a>>; 16]

Callbacks for each pin (indexed by pin number)

§configs: [GpioConfig; 16]

Configuration for each pin

Implementations§

Source§

impl<'a> GpioDriver<'a>

Source

pub fn new() -> Self

Source

pub fn new_gpioa() -> Self

Create a new GPIOA driver instance

Source

pub fn new_gpiob() -> Self

Create a new GPIOB driver instance

Source

pub fn new_gpioc() -> Self

Create a new GPIOC driver instance

Source

pub fn new_gpiod() -> Self

Create a new GPIOD driver instance

Source

pub fn new_gpioe() -> Self

Create a new GPIOE driver instance

Source

fn get_gpio_regs(port: u8) -> *mut RegisterBlock

Get GPIO register block for a given port

Source

fn get_rcc_regs() -> *mut RegisterBlock

Get RCC register block

Source

fn enable_gpio_clock(port: u8)

Enable GPIO port clock

Source

fn decode_pin(pin: u32) -> (u8, u8)

Extract port and pin from Pin identifier Pin format: (port << 4) | pin_number where port: 0=GPIOA, 1=GPIOB, 2=GPIOC, 3=GPIOD, 4=GPIOE and pin_number: 0-15

Source

fn encode_pin(port: u8, pin_num: u8) -> u32

Encode port and pin into Pin identifier

Source

fn configure_pin(&mut self, pin: u32, config: GpioConfig) -> Result<(), i32>

Configure a GPIO pin

Trait Implementations§

Source§

impl<'a> Gpio<'a> for GpioDriver<'a>

Source§

fn setup( &mut self, pin: u32, callback: impl FnMut(u32, EventType) + 'a, ) -> Result<(), i32>

Initializes a GPIO pin and registers a callback for events.
Source§

fn set_direction(&mut self, pin: u32, direction: Direction) -> Result<(), i32>

Sets the direction of a GPIO pin.
Source§

fn set_output_mode(&mut self, pin: u32, mode: OutputMode) -> Result<(), i32>

Sets the output mode of a GPIO pin.
Source§

fn set_pull_resistor( &mut self, pin: u32, resistor: PullResistor, ) -> Result<(), i32>

Sets the internal pull-up or pull-down resistor for a GPIO pin.
Source§

fn set_event_trigger( &mut self, pin: u32, trigger: EventTrigger, ) -> Result<(), i32>

Sets the event trigger for a GPIO pin.
Source§

fn set_output(&mut self, pin: u32, value: bool)

Sets the output level of a GPIO pin. value is true for high, false for low.
Source§

fn get_input(&self, pin: u32) -> bool

Gets the input level of a GPIO pin. Returns true for high, false for low.

Auto Trait Implementations§

§

impl<'a> Freeze for GpioDriver<'a>

§

impl<'a> !RefUnwindSafe for GpioDriver<'a>

§

impl<'a> !Send for GpioDriver<'a>

§

impl<'a> !Sync for GpioDriver<'a>

§

impl<'a> Unpin for GpioDriver<'a>

§

impl<'a> !UnwindSafe for GpioDriver<'a>

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.