#[cfg(feature = "device-selected")] pub mod gpio { //! General Purpose Input / Output use core::convert::Infallible; use core::marker::PhantomData; use crate::rcc::Rcc; /// Extension trait to split a GPIO peripheral in independent pins and registers pub trait GpioExt { /// The parts to split the GPIO into type Parts; /// Splits the GPIO block into independent pins and registers fn split(self, rcc: &mut Rcc) -> Self::Parts; } trait GpioRegExt { fn is_low(&self, pos: u8) -> bool; fn is_set_low(&self, pos: u8) -> bool; fn set_high(&self, pos: u8); fn set_low(&self, pos: u8); } /// Alternate function 0 pub struct AF0; /// Alternate function 1 pub struct AF1; /// Alternate function 2 pub struct AF2; /// Alternate function 3 pub struct AF3; /// Alternate function 4 pub struct AF4; /// Alternate function 5 pub struct AF5; /// Alternate function 6 pub struct AF6; /// Alternate function 7 pub struct AF7; /// Alternate function mode (type state) pub struct Alternate { _mode: PhantomData, } /// Input mode (type state) pub struct Input { _mode: PhantomData, } /// Floating input (type state) pub struct Floating; /// Pulled down input (type state) pub struct PullDown; /// Pulled up input (type state) pub struct PullUp; /// Open drain input or output (type state) pub struct OpenDrain; /// Analog mode (type state) pub struct Analog; /// Output mode (type state) pub struct Output { _mode: PhantomData, } /// Push pull output (type state) pub struct PushPull; use embedded_hal::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin}; /// Fully erased pin pub struct Pin { i: u8, port: *const dyn GpioRegExt, _mode: PhantomData, } unsafe impl Sync for Pin {} unsafe impl Send for Pin {} impl StatefulOutputPin for Pin> { #[inline(always)] fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } #[inline(always)] fn is_set_low(&self) -> Result { Ok(unsafe { (*self.port).is_set_low(self.i) }) } } impl OutputPin for Pin> { type Error = Infallible; #[inline(always)] fn set_high(&mut self) -> Result<(), Self::Error> { unsafe { (*self.port).set_high(self.i) }; Ok(()) } #[inline(always)] fn set_low(&mut self) -> Result<(), Self::Error> { unsafe { (*self.port).set_low(self.i) } Ok(()) } } impl toggleable::Default for Pin> {} impl InputPin for Pin> { type Error = Infallible; #[inline(always)] fn is_high(&self) -> Result { self.is_low().map(|v| !v) } #[inline(always)] fn is_low(&self) -> Result { Ok(unsafe { (*self.port).is_low(self.i) }) } } impl InputPin for Pin> { type Error = Infallible; #[inline(always)] fn is_high(&self) -> Result { self.is_low().map(|v| !v) } #[inline(always)] fn is_low(&self) -> Result { Ok(unsafe { (*self.port).is_low(self.i) }) } } impl GpioRegExt for crate::pac::gpioa::RegisterBlock { fn is_low(&self, pos: u8) -> bool { self.idr.read().bits() & (1 << pos) == 0 } fn is_set_low(&self, pos: u8) -> bool { self.odr.read().bits() & (1 << pos) == 0 } fn set_high(&self, pos: u8) { unsafe { self.bsrr.write(|w| w.bits(1 << pos)) } } fn set_low(&self, pos: u8) { unsafe { self.bsrr.write(|w| w.bits(1 << (pos + 16))) } } } impl GpioRegExt for crate::pac::gpiof::RegisterBlock { fn is_low(&self, pos: u8) -> bool { self.idr.read().bits() & (1 << pos) == 0 } fn is_set_low(&self, pos: u8) -> bool { self.odr.read().bits() & (1 << pos) == 0 } fn set_high(&self, pos: u8) { unsafe { self.bsrr.write(|w| w.bits(1 << pos)) } } fn set_low(&self, pos: u8) { unsafe { self.bsrr.write(|w| w.bits(1 << (pos + 16))) } } } /// GPIO #[cfg(any(feature = "device-selected"))] pub mod gpioa { use core::marker::PhantomData; use core::convert::Infallible; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, toggleable}; use crate::{rcc::Rcc, pac::GPIOA}; use cortex_m::interrupt::CriticalSection; use super::{ Alternate, Analog, Floating, GpioExt, Input, OpenDrain, Output, PullDown, PullUp, PushPull, AF0, AF1, AF2, AF3, AF4, AF5, AF6, AF7, Pin, GpioRegExt, }; /// GPIO parts pub struct Parts { /// Pin pub pa0: PA0>, /// Pin pub pa1: PA1>, /// Pin pub pa2: PA2>, /// Pin pub pa3: PA3>, /// Pin pub pa4: PA4>, /// Pin pub pa5: PA5>, /// Pin pub pa6: PA6>, /// Pin pub pa7: PA7>, /// Pin pub pa8: PA8>, /// Pin pub pa9: PA9>, /// Pin pub pa10: PA10>, /// Pin pub pa11: PA11>, /// Pin pub pa12: PA12>, /// Pin pub pa13: PA13>, /// Pin pub pa14: PA14>, /// Pin pub pa15: PA15>, } impl GpioExt for GPIOA { type Parts = Parts; fn split(self, rcc: &mut Rcc) -> Parts { rcc.regs.ahbenr.modify(|_, w| w.iopaen().set_bit()); Parts { pa0: PA0 { _mode: PhantomData }, pa1: PA1 { _mode: PhantomData }, pa2: PA2 { _mode: PhantomData }, pa3: PA3 { _mode: PhantomData }, pa4: PA4 { _mode: PhantomData }, pa5: PA5 { _mode: PhantomData }, pa6: PA6 { _mode: PhantomData }, pa7: PA7 { _mode: PhantomData }, pa8: PA8 { _mode: PhantomData }, pa9: PA9 { _mode: PhantomData }, pa10: PA10 { _mode: PhantomData }, pa11: PA11 { _mode: PhantomData }, pa12: PA12 { _mode: PhantomData }, pa13: PA13 { _mode: PhantomData }, pa14: PA14 { _mode: PhantomData }, pa15: PA15 { _mode: PhantomData }, } } } fn _set_alternate_mode(index: usize, mode: u32) { let offset = 2 * index; let offset2 = 4 * index; unsafe { let reg = &(*GPIOA::ptr()); if offset2 < 32 { reg.afrl.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } else { let offset2 = offset2 - 32; reg.afrh.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); } } /// Pin pub struct PA0 { _mode: PhantomData, } impl PA0 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA0> { _set_alternate_mode(0, 0); PA0 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA0> { _set_alternate_mode(0, 1); PA0 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA0> { _set_alternate_mode(0, 2); PA0 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA0> { _set_alternate_mode(0, 3); PA0 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA0> { _set_alternate_mode(0, 4); PA0 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA0> { _set_alternate_mode(0, 5); PA0 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA0> { _set_alternate_mode(0, 6); PA0 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA0> { _set_alternate_mode(0, 7); PA0 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA0 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA0 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA0 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA0 { let offset = 2 * 0; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA0 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA0 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA0 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA0 { _mode: PhantomData } } } impl PA0> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 0; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA0> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 0; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA0> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 0; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA0> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 0, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA0> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(0) }) } } impl OutputPin for PA0> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(0) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(0) }) } } impl toggleable::Default for PA0> {} impl InputPin for PA0> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(0) }) } } impl PA0> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 0, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA0> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(0) }) } } /// Pin pub struct PA1 { _mode: PhantomData, } impl PA1 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA1> { _set_alternate_mode(1, 0); PA1 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA1> { _set_alternate_mode(1, 1); PA1 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA1> { _set_alternate_mode(1, 2); PA1 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA1> { _set_alternate_mode(1, 3); PA1 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA1> { _set_alternate_mode(1, 4); PA1 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA1> { _set_alternate_mode(1, 5); PA1 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA1> { _set_alternate_mode(1, 6); PA1 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA1> { _set_alternate_mode(1, 7); PA1 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA1 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA1 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA1 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA1 { let offset = 2 * 1; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA1 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA1 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA1 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA1 { _mode: PhantomData } } } impl PA1> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 1; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA1> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 1; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA1> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 1; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA1> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 1, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA1> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(1) }) } } impl OutputPin for PA1> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(1) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(1) }) } } impl toggleable::Default for PA1> {} impl InputPin for PA1> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(1) }) } } impl PA1> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 1, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA1> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(1) }) } } /// Pin pub struct PA2 { _mode: PhantomData, } impl PA2 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA2> { _set_alternate_mode(2, 0); PA2 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA2> { _set_alternate_mode(2, 1); PA2 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA2> { _set_alternate_mode(2, 2); PA2 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA2> { _set_alternate_mode(2, 3); PA2 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA2> { _set_alternate_mode(2, 4); PA2 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA2> { _set_alternate_mode(2, 5); PA2 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA2> { _set_alternate_mode(2, 6); PA2 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA2> { _set_alternate_mode(2, 7); PA2 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA2 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA2 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA2 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA2 { let offset = 2 * 2; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA2 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA2 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA2 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA2 { _mode: PhantomData } } } impl PA2> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 2; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA2> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 2; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA2> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 2; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA2> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 2, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA2> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(2) }) } } impl OutputPin for PA2> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(2) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(2) }) } } impl toggleable::Default for PA2> {} impl InputPin for PA2> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(2) }) } } impl PA2> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 2, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA2> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(2) }) } } /// Pin pub struct PA3 { _mode: PhantomData, } impl PA3 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA3> { _set_alternate_mode(3, 0); PA3 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA3> { _set_alternate_mode(3, 1); PA3 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA3> { _set_alternate_mode(3, 2); PA3 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA3> { _set_alternate_mode(3, 3); PA3 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA3> { _set_alternate_mode(3, 4); PA3 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA3> { _set_alternate_mode(3, 5); PA3 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA3> { _set_alternate_mode(3, 6); PA3 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA3> { _set_alternate_mode(3, 7); PA3 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA3 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA3 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA3 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA3 { let offset = 2 * 3; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA3 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 3))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA3 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 3))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA3 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 3))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 3))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA3 { _mode: PhantomData } } } impl PA3> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 3; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA3> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 3; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA3> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 3; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA3> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 3, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA3> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(3) }) } } impl OutputPin for PA3> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(3) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(3) }) } } impl toggleable::Default for PA3> {} impl InputPin for PA3> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(3) }) } } impl PA3> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 3, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA3> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(3) }) } } /// Pin pub struct PA4 { _mode: PhantomData, } impl PA4 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA4> { _set_alternate_mode(4, 0); PA4 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA4> { _set_alternate_mode(4, 1); PA4 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA4> { _set_alternate_mode(4, 2); PA4 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA4> { _set_alternate_mode(4, 3); PA4 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA4> { _set_alternate_mode(4, 4); PA4 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA4> { _set_alternate_mode(4, 5); PA4 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA4> { _set_alternate_mode(4, 6); PA4 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA4> { _set_alternate_mode(4, 7); PA4 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA4 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA4 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA4 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA4 { let offset = 2 * 4; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA4 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 4))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA4 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 4))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA4 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 4))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 4))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA4 { _mode: PhantomData } } } impl PA4> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 4; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA4> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 4; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA4> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 4; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA4> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 4, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA4> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(4) }) } } impl OutputPin for PA4> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(4) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(4) }) } } impl toggleable::Default for PA4> {} impl InputPin for PA4> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(4) }) } } impl PA4> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 4, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA4> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(4) }) } } /// Pin pub struct PA5 { _mode: PhantomData, } impl PA5 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA5> { _set_alternate_mode(5, 0); PA5 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA5> { _set_alternate_mode(5, 1); PA5 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA5> { _set_alternate_mode(5, 2); PA5 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA5> { _set_alternate_mode(5, 3); PA5 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA5> { _set_alternate_mode(5, 4); PA5 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA5> { _set_alternate_mode(5, 5); PA5 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA5> { _set_alternate_mode(5, 6); PA5 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA5> { _set_alternate_mode(5, 7); PA5 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA5 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA5 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA5 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA5 { let offset = 2 * 5; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA5 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 5))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA5 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 5))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA5 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 5))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 5))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA5 { _mode: PhantomData } } } impl PA5> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 5; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA5> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 5; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA5> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 5; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA5> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 5, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA5> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(5) }) } } impl OutputPin for PA5> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(5) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(5) }) } } impl toggleable::Default for PA5> {} impl InputPin for PA5> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(5) }) } } impl PA5> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 5, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA5> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(5) }) } } /// Pin pub struct PA6 { _mode: PhantomData, } impl PA6 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA6> { _set_alternate_mode(6, 0); PA6 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA6> { _set_alternate_mode(6, 1); PA6 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA6> { _set_alternate_mode(6, 2); PA6 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA6> { _set_alternate_mode(6, 3); PA6 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA6> { _set_alternate_mode(6, 4); PA6 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA6> { _set_alternate_mode(6, 5); PA6 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA6> { _set_alternate_mode(6, 6); PA6 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA6> { _set_alternate_mode(6, 7); PA6 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA6 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA6 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA6 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA6 { let offset = 2 * 6; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA6 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 6))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA6 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 6))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA6 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 6))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 6))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA6 { _mode: PhantomData } } } impl PA6> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 6; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA6> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 6; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA6> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 6; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA6> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 6, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA6> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(6) }) } } impl OutputPin for PA6> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(6) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(6) }) } } impl toggleable::Default for PA6> {} impl InputPin for PA6> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(6) }) } } impl PA6> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 6, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA6> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(6) }) } } /// Pin pub struct PA7 { _mode: PhantomData, } impl PA7 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA7> { _set_alternate_mode(7, 0); PA7 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA7> { _set_alternate_mode(7, 1); PA7 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA7> { _set_alternate_mode(7, 2); PA7 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA7> { _set_alternate_mode(7, 3); PA7 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA7> { _set_alternate_mode(7, 4); PA7 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA7> { _set_alternate_mode(7, 5); PA7 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA7> { _set_alternate_mode(7, 6); PA7 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA7> { _set_alternate_mode(7, 7); PA7 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA7 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA7 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA7 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA7 { let offset = 2 * 7; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA7 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 7))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA7 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 7))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA7 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 7))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 7))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA7 { _mode: PhantomData } } } impl PA7> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 7; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA7> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 7; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA7> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 7; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA7> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 7, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA7> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(7) }) } } impl OutputPin for PA7> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(7) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(7) }) } } impl toggleable::Default for PA7> {} impl InputPin for PA7> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(7) }) } } impl PA7> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 7, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA7> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(7) }) } } /// Pin pub struct PA8 { _mode: PhantomData, } impl PA8 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA8> { _set_alternate_mode(8, 0); PA8 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA8> { _set_alternate_mode(8, 1); PA8 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA8> { _set_alternate_mode(8, 2); PA8 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA8> { _set_alternate_mode(8, 3); PA8 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA8> { _set_alternate_mode(8, 4); PA8 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA8> { _set_alternate_mode(8, 5); PA8 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA8> { _set_alternate_mode(8, 6); PA8 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA8> { _set_alternate_mode(8, 7); PA8 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA8 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA8 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA8 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA8 { let offset = 2 * 8; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA8 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 8))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA8 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 8))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA8 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 8))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 8))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA8 { _mode: PhantomData } } } impl PA8> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 8; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA8> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 8; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA8> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 8; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA8> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 8, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA8> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(8) }) } } impl OutputPin for PA8> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(8) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(8) }) } } impl toggleable::Default for PA8> {} impl InputPin for PA8> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(8) }) } } impl PA8> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 8, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA8> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(8) }) } } /// Pin pub struct PA9 { _mode: PhantomData, } impl PA9 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA9> { _set_alternate_mode(9, 0); PA9 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA9> { _set_alternate_mode(9, 1); PA9 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA9> { _set_alternate_mode(9, 2); PA9 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA9> { _set_alternate_mode(9, 3); PA9 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA9> { _set_alternate_mode(9, 4); PA9 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA9> { _set_alternate_mode(9, 5); PA9 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA9> { _set_alternate_mode(9, 6); PA9 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA9> { _set_alternate_mode(9, 7); PA9 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA9 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA9 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA9 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA9 { let offset = 2 * 9; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA9 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 9))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA9 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 9))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA9 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 9))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 9))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA9 { _mode: PhantomData } } } impl PA9> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 9; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA9> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 9; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA9> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 9; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA9> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 9, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA9> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(9) }) } } impl OutputPin for PA9> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(9) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(9) }) } } impl toggleable::Default for PA9> {} impl InputPin for PA9> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(9) }) } } impl PA9> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 9, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA9> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(9) }) } } /// Pin pub struct PA10 { _mode: PhantomData, } impl PA10 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA10> { _set_alternate_mode(10, 0); PA10 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA10> { _set_alternate_mode(10, 1); PA10 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA10> { _set_alternate_mode(10, 2); PA10 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA10> { _set_alternate_mode(10, 3); PA10 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA10> { _set_alternate_mode(10, 4); PA10 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA10> { _set_alternate_mode(10, 5); PA10 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA10> { _set_alternate_mode(10, 6); PA10 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA10> { _set_alternate_mode(10, 7); PA10 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA10 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA10 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA10 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA10 { let offset = 2 * 10; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA10 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 10))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA10 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 10))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA10 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 10))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 10))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA10 { _mode: PhantomData } } } impl PA10> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 10; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA10> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 10; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA10> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 10; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA10> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 10, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA10> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(10) }) } } impl OutputPin for PA10> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(10) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(10) }) } } impl toggleable::Default for PA10> {} impl InputPin for PA10> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(10) }) } } impl PA10> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 10, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA10> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(10) }) } } /// Pin pub struct PA11 { _mode: PhantomData, } impl PA11 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA11> { _set_alternate_mode(11, 0); PA11 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA11> { _set_alternate_mode(11, 1); PA11 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA11> { _set_alternate_mode(11, 2); PA11 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA11> { _set_alternate_mode(11, 3); PA11 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA11> { _set_alternate_mode(11, 4); PA11 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA11> { _set_alternate_mode(11, 5); PA11 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA11> { _set_alternate_mode(11, 6); PA11 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA11> { _set_alternate_mode(11, 7); PA11 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA11 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA11 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA11 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA11 { let offset = 2 * 11; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA11 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 11))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA11 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 11))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA11 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 11))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 11))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA11 { _mode: PhantomData } } } impl PA11> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 11; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA11> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 11; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA11> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 11; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA11> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 11, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA11> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(11) }) } } impl OutputPin for PA11> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(11) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(11) }) } } impl toggleable::Default for PA11> {} impl InputPin for PA11> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(11) }) } } impl PA11> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 11, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA11> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(11) }) } } /// Pin pub struct PA12 { _mode: PhantomData, } impl PA12 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA12> { _set_alternate_mode(12, 0); PA12 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA12> { _set_alternate_mode(12, 1); PA12 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA12> { _set_alternate_mode(12, 2); PA12 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA12> { _set_alternate_mode(12, 3); PA12 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA12> { _set_alternate_mode(12, 4); PA12 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA12> { _set_alternate_mode(12, 5); PA12 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA12> { _set_alternate_mode(12, 6); PA12 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA12> { _set_alternate_mode(12, 7); PA12 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA12 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA12 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA12 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA12 { let offset = 2 * 12; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA12 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 12))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA12 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 12))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA12 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 12))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 12))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA12 { _mode: PhantomData } } } impl PA12> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 12; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA12> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 12; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA12> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 12; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA12> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 12, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA12> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(12) }) } } impl OutputPin for PA12> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(12) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(12) }) } } impl toggleable::Default for PA12> {} impl InputPin for PA12> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(12) }) } } impl PA12> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 12, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA12> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(12) }) } } /// Pin pub struct PA13 { _mode: PhantomData, } impl PA13 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA13> { _set_alternate_mode(13, 0); PA13 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA13> { _set_alternate_mode(13, 1); PA13 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA13> { _set_alternate_mode(13, 2); PA13 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA13> { _set_alternate_mode(13, 3); PA13 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA13> { _set_alternate_mode(13, 4); PA13 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA13> { _set_alternate_mode(13, 5); PA13 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA13> { _set_alternate_mode(13, 6); PA13 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA13> { _set_alternate_mode(13, 7); PA13 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA13 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA13 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA13 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA13 { let offset = 2 * 13; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA13 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 13))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA13 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 13))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA13 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 13))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 13))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA13 { _mode: PhantomData } } } impl PA13> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 13; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA13> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 13; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA13> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 13; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA13> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 13, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA13> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(13) }) } } impl OutputPin for PA13> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(13) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(13) }) } } impl toggleable::Default for PA13> {} impl InputPin for PA13> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(13) }) } } impl PA13> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 13, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA13> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(13) }) } } /// Pin pub struct PA14 { _mode: PhantomData, } impl PA14 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA14> { _set_alternate_mode(14, 0); PA14 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA14> { _set_alternate_mode(14, 1); PA14 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA14> { _set_alternate_mode(14, 2); PA14 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA14> { _set_alternate_mode(14, 3); PA14 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA14> { _set_alternate_mode(14, 4); PA14 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA14> { _set_alternate_mode(14, 5); PA14 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA14> { _set_alternate_mode(14, 6); PA14 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA14> { _set_alternate_mode(14, 7); PA14 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA14 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA14 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA14 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA14 { let offset = 2 * 14; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA14 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 14))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA14 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 14))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA14 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 14))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 14))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA14 { _mode: PhantomData } } } impl PA14> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 14; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA14> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 14; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA14> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 14; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA14> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 14, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA14> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(14) }) } } impl OutputPin for PA14> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(14) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(14) }) } } impl toggleable::Default for PA14> {} impl InputPin for PA14> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(14) }) } } impl PA14> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 14, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA14> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(14) }) } } /// Pin pub struct PA15 { _mode: PhantomData, } impl PA15 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PA15> { _set_alternate_mode(15, 0); PA15 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PA15> { _set_alternate_mode(15, 1); PA15 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PA15> { _set_alternate_mode(15, 2); PA15 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PA15> { _set_alternate_mode(15, 3); PA15 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PA15> { _set_alternate_mode(15, 4); PA15 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PA15> { _set_alternate_mode(15, 5); PA15 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PA15> { _set_alternate_mode(15, 6); PA15 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PA15> { _set_alternate_mode(15, 7); PA15 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PA15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA15 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PA15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA15 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PA15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PA15 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PA15 { let offset = 2 * 15; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PA15 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PA15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 15))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA15 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PA15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 15))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA15 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PA15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 15))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 15))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PA15 { _mode: PhantomData } } } impl PA15> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 15; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PA15> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 15; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOA::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PA15> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 15; unsafe { let reg = &(*GPIOA::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PA15> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 15, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PA15> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_set_low(15) }) } } impl OutputPin for PA15> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_high(15) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOA::ptr()).set_low(15) }) } } impl toggleable::Default for PA15> {} impl InputPin for PA15> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(15) }) } } impl PA15> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 15, port: GPIOA::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PA15> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOA::ptr()).is_low(15) }) } } } /// GPIO #[cfg(any(feature = "device-selected"))] pub mod gpiob { use core::marker::PhantomData; use core::convert::Infallible; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, toggleable}; use crate::{rcc::Rcc, pac::GPIOB}; use cortex_m::interrupt::CriticalSection; use super::{ Alternate, Analog, Floating, GpioExt, Input, OpenDrain, Output, PullDown, PullUp, PushPull, AF0, AF1, AF2, AF3, AF4, AF5, AF6, AF7, Pin, GpioRegExt, }; /// GPIO parts pub struct Parts { /// Pin pub pb0: PB0>, /// Pin pub pb1: PB1>, /// Pin pub pb2: PB2>, /// Pin pub pb3: PB3>, /// Pin pub pb4: PB4>, /// Pin pub pb5: PB5>, /// Pin pub pb6: PB6>, /// Pin pub pb7: PB7>, /// Pin pub pb8: PB8>, /// Pin pub pb9: PB9>, /// Pin pub pb10: PB10>, /// Pin pub pb11: PB11>, /// Pin pub pb12: PB12>, /// Pin pub pb13: PB13>, /// Pin pub pb14: PB14>, /// Pin pub pb15: PB15>, } impl GpioExt for GPIOB { type Parts = Parts; fn split(self, rcc: &mut Rcc) -> Parts { rcc.regs.ahbenr.modify(|_, w| w.iopben().set_bit()); Parts { pb0: PB0 { _mode: PhantomData }, pb1: PB1 { _mode: PhantomData }, pb2: PB2 { _mode: PhantomData }, pb3: PB3 { _mode: PhantomData }, pb4: PB4 { _mode: PhantomData }, pb5: PB5 { _mode: PhantomData }, pb6: PB6 { _mode: PhantomData }, pb7: PB7 { _mode: PhantomData }, pb8: PB8 { _mode: PhantomData }, pb9: PB9 { _mode: PhantomData }, pb10: PB10 { _mode: PhantomData }, pb11: PB11 { _mode: PhantomData }, pb12: PB12 { _mode: PhantomData }, pb13: PB13 { _mode: PhantomData }, pb14: PB14 { _mode: PhantomData }, pb15: PB15 { _mode: PhantomData }, } } } fn _set_alternate_mode(index: usize, mode: u32) { let offset = 2 * index; let offset2 = 4 * index; unsafe { let reg = &(*GPIOB::ptr()); if offset2 < 32 { reg.afrl.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } else { let offset2 = offset2 - 32; reg.afrh.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); } } /// Pin pub struct PB0 { _mode: PhantomData, } impl PB0 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB0> { _set_alternate_mode(0, 0); PB0 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB0> { _set_alternate_mode(0, 1); PB0 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB0> { _set_alternate_mode(0, 2); PB0 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB0> { _set_alternate_mode(0, 3); PB0 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB0> { _set_alternate_mode(0, 4); PB0 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB0> { _set_alternate_mode(0, 5); PB0 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB0> { _set_alternate_mode(0, 6); PB0 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB0> { _set_alternate_mode(0, 7); PB0 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB0 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB0 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB0 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB0 { let offset = 2 * 0; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB0 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB0 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB0 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB0 { _mode: PhantomData } } } impl PB0> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 0; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB0> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 0; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB0> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 0; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB0> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 0, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB0> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(0) }) } } impl OutputPin for PB0> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(0) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(0) }) } } impl toggleable::Default for PB0> {} impl InputPin for PB0> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(0) }) } } impl PB0> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 0, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB0> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(0) }) } } /// Pin pub struct PB1 { _mode: PhantomData, } impl PB1 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB1> { _set_alternate_mode(1, 0); PB1 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB1> { _set_alternate_mode(1, 1); PB1 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB1> { _set_alternate_mode(1, 2); PB1 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB1> { _set_alternate_mode(1, 3); PB1 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB1> { _set_alternate_mode(1, 4); PB1 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB1> { _set_alternate_mode(1, 5); PB1 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB1> { _set_alternate_mode(1, 6); PB1 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB1> { _set_alternate_mode(1, 7); PB1 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB1 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB1 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB1 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB1 { let offset = 2 * 1; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB1 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB1 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB1 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB1 { _mode: PhantomData } } } impl PB1> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 1; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB1> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 1; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB1> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 1; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB1> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 1, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB1> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(1) }) } } impl OutputPin for PB1> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(1) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(1) }) } } impl toggleable::Default for PB1> {} impl InputPin for PB1> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(1) }) } } impl PB1> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 1, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB1> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(1) }) } } /// Pin pub struct PB2 { _mode: PhantomData, } impl PB2 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB2> { _set_alternate_mode(2, 0); PB2 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB2> { _set_alternate_mode(2, 1); PB2 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB2> { _set_alternate_mode(2, 2); PB2 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB2> { _set_alternate_mode(2, 3); PB2 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB2> { _set_alternate_mode(2, 4); PB2 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB2> { _set_alternate_mode(2, 5); PB2 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB2> { _set_alternate_mode(2, 6); PB2 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB2> { _set_alternate_mode(2, 7); PB2 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB2 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB2 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB2 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB2 { let offset = 2 * 2; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB2 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB2 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB2 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB2 { _mode: PhantomData } } } impl PB2> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 2; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB2> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 2; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB2> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 2; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB2> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 2, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB2> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(2) }) } } impl OutputPin for PB2> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(2) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(2) }) } } impl toggleable::Default for PB2> {} impl InputPin for PB2> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(2) }) } } impl PB2> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 2, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB2> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(2) }) } } /// Pin pub struct PB3 { _mode: PhantomData, } impl PB3 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB3> { _set_alternate_mode(3, 0); PB3 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB3> { _set_alternate_mode(3, 1); PB3 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB3> { _set_alternate_mode(3, 2); PB3 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB3> { _set_alternate_mode(3, 3); PB3 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB3> { _set_alternate_mode(3, 4); PB3 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB3> { _set_alternate_mode(3, 5); PB3 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB3> { _set_alternate_mode(3, 6); PB3 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB3> { _set_alternate_mode(3, 7); PB3 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB3 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB3 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB3 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB3 { let offset = 2 * 3; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB3 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 3))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB3 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 3))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB3 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 3))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 3))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB3 { _mode: PhantomData } } } impl PB3> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 3; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB3> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 3; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB3> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 3; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB3> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 3, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB3> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(3) }) } } impl OutputPin for PB3> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(3) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(3) }) } } impl toggleable::Default for PB3> {} impl InputPin for PB3> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(3) }) } } impl PB3> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 3, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB3> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(3) }) } } /// Pin pub struct PB4 { _mode: PhantomData, } impl PB4 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB4> { _set_alternate_mode(4, 0); PB4 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB4> { _set_alternate_mode(4, 1); PB4 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB4> { _set_alternate_mode(4, 2); PB4 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB4> { _set_alternate_mode(4, 3); PB4 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB4> { _set_alternate_mode(4, 4); PB4 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB4> { _set_alternate_mode(4, 5); PB4 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB4> { _set_alternate_mode(4, 6); PB4 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB4> { _set_alternate_mode(4, 7); PB4 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB4 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB4 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB4 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB4 { let offset = 2 * 4; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB4 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 4))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB4 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 4))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB4 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 4))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 4))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB4 { _mode: PhantomData } } } impl PB4> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 4; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB4> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 4; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB4> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 4; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB4> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 4, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB4> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(4) }) } } impl OutputPin for PB4> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(4) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(4) }) } } impl toggleable::Default for PB4> {} impl InputPin for PB4> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(4) }) } } impl PB4> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 4, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB4> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(4) }) } } /// Pin pub struct PB5 { _mode: PhantomData, } impl PB5 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB5> { _set_alternate_mode(5, 0); PB5 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB5> { _set_alternate_mode(5, 1); PB5 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB5> { _set_alternate_mode(5, 2); PB5 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB5> { _set_alternate_mode(5, 3); PB5 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB5> { _set_alternate_mode(5, 4); PB5 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB5> { _set_alternate_mode(5, 5); PB5 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB5> { _set_alternate_mode(5, 6); PB5 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB5> { _set_alternate_mode(5, 7); PB5 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB5 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB5 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB5 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB5 { let offset = 2 * 5; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB5 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 5))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB5 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 5))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB5 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 5))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 5))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB5 { _mode: PhantomData } } } impl PB5> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 5; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB5> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 5; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB5> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 5; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB5> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 5, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB5> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(5) }) } } impl OutputPin for PB5> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(5) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(5) }) } } impl toggleable::Default for PB5> {} impl InputPin for PB5> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(5) }) } } impl PB5> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 5, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB5> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(5) }) } } /// Pin pub struct PB6 { _mode: PhantomData, } impl PB6 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB6> { _set_alternate_mode(6, 0); PB6 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB6> { _set_alternate_mode(6, 1); PB6 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB6> { _set_alternate_mode(6, 2); PB6 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB6> { _set_alternate_mode(6, 3); PB6 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB6> { _set_alternate_mode(6, 4); PB6 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB6> { _set_alternate_mode(6, 5); PB6 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB6> { _set_alternate_mode(6, 6); PB6 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB6> { _set_alternate_mode(6, 7); PB6 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB6 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB6 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB6 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB6 { let offset = 2 * 6; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB6 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 6))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB6 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 6))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB6 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 6))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 6))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB6 { _mode: PhantomData } } } impl PB6> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 6; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB6> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 6; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB6> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 6; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB6> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 6, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB6> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(6) }) } } impl OutputPin for PB6> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(6) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(6) }) } } impl toggleable::Default for PB6> {} impl InputPin for PB6> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(6) }) } } impl PB6> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 6, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB6> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(6) }) } } /// Pin pub struct PB7 { _mode: PhantomData, } impl PB7 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB7> { _set_alternate_mode(7, 0); PB7 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB7> { _set_alternate_mode(7, 1); PB7 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB7> { _set_alternate_mode(7, 2); PB7 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB7> { _set_alternate_mode(7, 3); PB7 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB7> { _set_alternate_mode(7, 4); PB7 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB7> { _set_alternate_mode(7, 5); PB7 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB7> { _set_alternate_mode(7, 6); PB7 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB7> { _set_alternate_mode(7, 7); PB7 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB7 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB7 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB7 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB7 { let offset = 2 * 7; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB7 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 7))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB7 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 7))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB7 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 7))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 7))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB7 { _mode: PhantomData } } } impl PB7> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 7; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB7> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 7; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB7> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 7; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB7> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 7, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB7> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(7) }) } } impl OutputPin for PB7> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(7) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(7) }) } } impl toggleable::Default for PB7> {} impl InputPin for PB7> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(7) }) } } impl PB7> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 7, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB7> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(7) }) } } /// Pin pub struct PB8 { _mode: PhantomData, } impl PB8 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB8> { _set_alternate_mode(8, 0); PB8 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB8> { _set_alternate_mode(8, 1); PB8 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB8> { _set_alternate_mode(8, 2); PB8 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB8> { _set_alternate_mode(8, 3); PB8 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB8> { _set_alternate_mode(8, 4); PB8 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB8> { _set_alternate_mode(8, 5); PB8 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB8> { _set_alternate_mode(8, 6); PB8 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB8> { _set_alternate_mode(8, 7); PB8 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB8 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB8 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB8 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB8 { let offset = 2 * 8; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB8 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 8))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB8 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 8))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB8 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 8))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 8))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB8 { _mode: PhantomData } } } impl PB8> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 8; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB8> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 8; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB8> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 8; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB8> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 8, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB8> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(8) }) } } impl OutputPin for PB8> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(8) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(8) }) } } impl toggleable::Default for PB8> {} impl InputPin for PB8> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(8) }) } } impl PB8> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 8, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB8> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(8) }) } } /// Pin pub struct PB9 { _mode: PhantomData, } impl PB9 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB9> { _set_alternate_mode(9, 0); PB9 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB9> { _set_alternate_mode(9, 1); PB9 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB9> { _set_alternate_mode(9, 2); PB9 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB9> { _set_alternate_mode(9, 3); PB9 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB9> { _set_alternate_mode(9, 4); PB9 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB9> { _set_alternate_mode(9, 5); PB9 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB9> { _set_alternate_mode(9, 6); PB9 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB9> { _set_alternate_mode(9, 7); PB9 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB9 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB9 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB9 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB9 { let offset = 2 * 9; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB9 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 9))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB9 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 9))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB9 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 9))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 9))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB9 { _mode: PhantomData } } } impl PB9> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 9; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB9> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 9; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB9> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 9; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB9> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 9, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB9> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(9) }) } } impl OutputPin for PB9> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(9) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(9) }) } } impl toggleable::Default for PB9> {} impl InputPin for PB9> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(9) }) } } impl PB9> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 9, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB9> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(9) }) } } /// Pin pub struct PB10 { _mode: PhantomData, } impl PB10 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB10> { _set_alternate_mode(10, 0); PB10 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB10> { _set_alternate_mode(10, 1); PB10 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB10> { _set_alternate_mode(10, 2); PB10 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB10> { _set_alternate_mode(10, 3); PB10 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB10> { _set_alternate_mode(10, 4); PB10 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB10> { _set_alternate_mode(10, 5); PB10 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB10> { _set_alternate_mode(10, 6); PB10 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB10> { _set_alternate_mode(10, 7); PB10 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB10 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB10 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB10 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB10 { let offset = 2 * 10; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB10 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 10))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB10 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 10))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB10 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 10))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 10))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB10 { _mode: PhantomData } } } impl PB10> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 10; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB10> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 10; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB10> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 10; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB10> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 10, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB10> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(10) }) } } impl OutputPin for PB10> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(10) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(10) }) } } impl toggleable::Default for PB10> {} impl InputPin for PB10> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(10) }) } } impl PB10> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 10, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB10> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(10) }) } } /// Pin pub struct PB11 { _mode: PhantomData, } impl PB11 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB11> { _set_alternate_mode(11, 0); PB11 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB11> { _set_alternate_mode(11, 1); PB11 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB11> { _set_alternate_mode(11, 2); PB11 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB11> { _set_alternate_mode(11, 3); PB11 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB11> { _set_alternate_mode(11, 4); PB11 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB11> { _set_alternate_mode(11, 5); PB11 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB11> { _set_alternate_mode(11, 6); PB11 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB11> { _set_alternate_mode(11, 7); PB11 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB11 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB11 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB11 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB11 { let offset = 2 * 11; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB11 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 11))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB11 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 11))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB11 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 11))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 11))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB11 { _mode: PhantomData } } } impl PB11> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 11; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB11> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 11; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB11> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 11; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB11> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 11, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB11> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(11) }) } } impl OutputPin for PB11> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(11) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(11) }) } } impl toggleable::Default for PB11> {} impl InputPin for PB11> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(11) }) } } impl PB11> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 11, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB11> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(11) }) } } /// Pin pub struct PB12 { _mode: PhantomData, } impl PB12 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB12> { _set_alternate_mode(12, 0); PB12 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB12> { _set_alternate_mode(12, 1); PB12 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB12> { _set_alternate_mode(12, 2); PB12 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB12> { _set_alternate_mode(12, 3); PB12 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB12> { _set_alternate_mode(12, 4); PB12 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB12> { _set_alternate_mode(12, 5); PB12 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB12> { _set_alternate_mode(12, 6); PB12 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB12> { _set_alternate_mode(12, 7); PB12 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB12 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB12 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB12 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB12 { let offset = 2 * 12; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB12 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 12))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB12 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 12))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB12 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 12))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 12))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB12 { _mode: PhantomData } } } impl PB12> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 12; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB12> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 12; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB12> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 12; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB12> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 12, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB12> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(12) }) } } impl OutputPin for PB12> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(12) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(12) }) } } impl toggleable::Default for PB12> {} impl InputPin for PB12> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(12) }) } } impl PB12> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 12, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB12> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(12) }) } } /// Pin pub struct PB13 { _mode: PhantomData, } impl PB13 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB13> { _set_alternate_mode(13, 0); PB13 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB13> { _set_alternate_mode(13, 1); PB13 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB13> { _set_alternate_mode(13, 2); PB13 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB13> { _set_alternate_mode(13, 3); PB13 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB13> { _set_alternate_mode(13, 4); PB13 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB13> { _set_alternate_mode(13, 5); PB13 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB13> { _set_alternate_mode(13, 6); PB13 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB13> { _set_alternate_mode(13, 7); PB13 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB13 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB13 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB13 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB13 { let offset = 2 * 13; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB13 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 13))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB13 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 13))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB13 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 13))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 13))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB13 { _mode: PhantomData } } } impl PB13> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 13; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB13> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 13; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB13> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 13; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB13> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 13, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB13> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(13) }) } } impl OutputPin for PB13> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(13) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(13) }) } } impl toggleable::Default for PB13> {} impl InputPin for PB13> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(13) }) } } impl PB13> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 13, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB13> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(13) }) } } /// Pin pub struct PB14 { _mode: PhantomData, } impl PB14 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB14> { _set_alternate_mode(14, 0); PB14 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB14> { _set_alternate_mode(14, 1); PB14 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB14> { _set_alternate_mode(14, 2); PB14 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB14> { _set_alternate_mode(14, 3); PB14 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB14> { _set_alternate_mode(14, 4); PB14 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB14> { _set_alternate_mode(14, 5); PB14 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB14> { _set_alternate_mode(14, 6); PB14 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB14> { _set_alternate_mode(14, 7); PB14 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB14 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB14 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB14 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB14 { let offset = 2 * 14; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB14 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 14))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB14 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 14))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB14 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 14))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 14))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB14 { _mode: PhantomData } } } impl PB14> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 14; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB14> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 14; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB14> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 14; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB14> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 14, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB14> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(14) }) } } impl OutputPin for PB14> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(14) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(14) }) } } impl toggleable::Default for PB14> {} impl InputPin for PB14> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(14) }) } } impl PB14> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 14, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB14> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(14) }) } } /// Pin pub struct PB15 { _mode: PhantomData, } impl PB15 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PB15> { _set_alternate_mode(15, 0); PB15 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PB15> { _set_alternate_mode(15, 1); PB15 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PB15> { _set_alternate_mode(15, 2); PB15 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PB15> { _set_alternate_mode(15, 3); PB15 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PB15> { _set_alternate_mode(15, 4); PB15 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PB15> { _set_alternate_mode(15, 5); PB15 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PB15> { _set_alternate_mode(15, 6); PB15 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PB15> { _set_alternate_mode(15, 7); PB15 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PB15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB15 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PB15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB15 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PB15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PB15 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PB15 { let offset = 2 * 15; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PB15 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PB15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 15))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB15 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PB15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 15))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB15 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PB15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 15))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 15))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PB15 { _mode: PhantomData } } } impl PB15> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 15; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PB15> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 15; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOB::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PB15> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 15; unsafe { let reg = &(*GPIOB::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PB15> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 15, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PB15> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_set_low(15) }) } } impl OutputPin for PB15> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_high(15) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOB::ptr()).set_low(15) }) } } impl toggleable::Default for PB15> {} impl InputPin for PB15> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(15) }) } } impl PB15> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 15, port: GPIOB::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PB15> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOB::ptr()).is_low(15) }) } } } /// GPIO #[cfg(any( feature = "stm32f030", feature = "stm32f051", feature = "stm32f058", feature = "stm32f070", feature = "stm32f071", feature = "stm32f072", feature = "stm32f078", feature = "stm32f091", feature = "stm32f098" ))] pub mod gpioc { use core::marker::PhantomData; use core::convert::Infallible; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, toggleable}; use crate::{rcc::Rcc, pac::GPIOC}; use cortex_m::interrupt::CriticalSection; use super::{ Alternate, Analog, Floating, GpioExt, Input, OpenDrain, Output, PullDown, PullUp, PushPull, AF0, AF1, AF2, AF3, AF4, AF5, AF6, AF7, Pin, GpioRegExt, }; /// GPIO parts pub struct Parts { /// Pin pub pc0: PC0>, /// Pin pub pc1: PC1>, /// Pin pub pc2: PC2>, /// Pin pub pc3: PC3>, /// Pin pub pc4: PC4>, /// Pin pub pc5: PC5>, /// Pin pub pc6: PC6>, /// Pin pub pc7: PC7>, /// Pin pub pc8: PC8>, /// Pin pub pc9: PC9>, /// Pin pub pc10: PC10>, /// Pin pub pc11: PC11>, /// Pin pub pc12: PC12>, /// Pin pub pc13: PC13>, /// Pin pub pc14: PC14>, /// Pin pub pc15: PC15>, } impl GpioExt for GPIOC { type Parts = Parts; fn split(self, rcc: &mut Rcc) -> Parts { rcc.regs.ahbenr.modify(|_, w| w.iopcen().set_bit()); Parts { pc0: PC0 { _mode: PhantomData }, pc1: PC1 { _mode: PhantomData }, pc2: PC2 { _mode: PhantomData }, pc3: PC3 { _mode: PhantomData }, pc4: PC4 { _mode: PhantomData }, pc5: PC5 { _mode: PhantomData }, pc6: PC6 { _mode: PhantomData }, pc7: PC7 { _mode: PhantomData }, pc8: PC8 { _mode: PhantomData }, pc9: PC9 { _mode: PhantomData }, pc10: PC10 { _mode: PhantomData }, pc11: PC11 { _mode: PhantomData }, pc12: PC12 { _mode: PhantomData }, pc13: PC13 { _mode: PhantomData }, pc14: PC14 { _mode: PhantomData }, pc15: PC15 { _mode: PhantomData }, } } } fn _set_alternate_mode(index: usize, mode: u32) { let offset = 2 * index; let offset2 = 4 * index; unsafe { let reg = &(*GPIOC::ptr()); if offset2 < 32 { reg.afrl.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } else { let offset2 = offset2 - 32; reg.afrh.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); } } /// Pin pub struct PC0 { _mode: PhantomData, } impl PC0 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC0> { _set_alternate_mode(0, 0); PC0 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC0> { _set_alternate_mode(0, 1); PC0 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC0> { _set_alternate_mode(0, 2); PC0 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC0> { _set_alternate_mode(0, 3); PC0 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC0> { _set_alternate_mode(0, 4); PC0 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC0> { _set_alternate_mode(0, 5); PC0 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC0> { _set_alternate_mode(0, 6); PC0 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC0> { _set_alternate_mode(0, 7); PC0 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC0 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC0 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC0 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC0 { let offset = 2 * 0; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC0 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC0 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC0 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC0 { _mode: PhantomData } } } impl PC0> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 0; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC0> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 0; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC0> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 0; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC0> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 0, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC0> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(0) }) } } impl OutputPin for PC0> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(0) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(0) }) } } impl toggleable::Default for PC0> {} impl InputPin for PC0> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(0) }) } } impl PC0> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 0, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC0> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(0) }) } } /// Pin pub struct PC1 { _mode: PhantomData, } impl PC1 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC1> { _set_alternate_mode(1, 0); PC1 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC1> { _set_alternate_mode(1, 1); PC1 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC1> { _set_alternate_mode(1, 2); PC1 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC1> { _set_alternate_mode(1, 3); PC1 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC1> { _set_alternate_mode(1, 4); PC1 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC1> { _set_alternate_mode(1, 5); PC1 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC1> { _set_alternate_mode(1, 6); PC1 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC1> { _set_alternate_mode(1, 7); PC1 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC1 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC1 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC1 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC1 { let offset = 2 * 1; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC1 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC1 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC1 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC1 { _mode: PhantomData } } } impl PC1> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 1; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC1> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 1; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC1> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 1; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC1> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 1, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC1> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(1) }) } } impl OutputPin for PC1> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(1) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(1) }) } } impl toggleable::Default for PC1> {} impl InputPin for PC1> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(1) }) } } impl PC1> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 1, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC1> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(1) }) } } /// Pin pub struct PC2 { _mode: PhantomData, } impl PC2 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC2> { _set_alternate_mode(2, 0); PC2 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC2> { _set_alternate_mode(2, 1); PC2 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC2> { _set_alternate_mode(2, 2); PC2 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC2> { _set_alternate_mode(2, 3); PC2 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC2> { _set_alternate_mode(2, 4); PC2 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC2> { _set_alternate_mode(2, 5); PC2 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC2> { _set_alternate_mode(2, 6); PC2 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC2> { _set_alternate_mode(2, 7); PC2 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC2 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC2 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC2 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC2 { let offset = 2 * 2; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC2 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC2 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC2 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC2 { _mode: PhantomData } } } impl PC2> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 2; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC2> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 2; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC2> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 2; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC2> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 2, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC2> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(2) }) } } impl OutputPin for PC2> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(2) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(2) }) } } impl toggleable::Default for PC2> {} impl InputPin for PC2> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(2) }) } } impl PC2> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 2, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC2> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(2) }) } } /// Pin pub struct PC3 { _mode: PhantomData, } impl PC3 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC3> { _set_alternate_mode(3, 0); PC3 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC3> { _set_alternate_mode(3, 1); PC3 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC3> { _set_alternate_mode(3, 2); PC3 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC3> { _set_alternate_mode(3, 3); PC3 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC3> { _set_alternate_mode(3, 4); PC3 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC3> { _set_alternate_mode(3, 5); PC3 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC3> { _set_alternate_mode(3, 6); PC3 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC3> { _set_alternate_mode(3, 7); PC3 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC3 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC3 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC3 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC3 { let offset = 2 * 3; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC3 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 3))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC3 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 3))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC3 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC3> { let offset = 2 * 3; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 3))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 3))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC3 { _mode: PhantomData } } } impl PC3> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 3; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC3> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 3; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC3> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 3; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC3> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 3, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC3> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(3) }) } } impl OutputPin for PC3> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(3) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(3) }) } } impl toggleable::Default for PC3> {} impl InputPin for PC3> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(3) }) } } impl PC3> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 3, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC3> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(3) }) } } /// Pin pub struct PC4 { _mode: PhantomData, } impl PC4 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC4> { _set_alternate_mode(4, 0); PC4 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC4> { _set_alternate_mode(4, 1); PC4 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC4> { _set_alternate_mode(4, 2); PC4 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC4> { _set_alternate_mode(4, 3); PC4 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC4> { _set_alternate_mode(4, 4); PC4 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC4> { _set_alternate_mode(4, 5); PC4 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC4> { _set_alternate_mode(4, 6); PC4 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC4> { _set_alternate_mode(4, 7); PC4 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC4 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC4 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC4 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC4 { let offset = 2 * 4; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC4 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 4))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC4 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 4))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC4 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC4> { let offset = 2 * 4; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 4))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 4))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC4 { _mode: PhantomData } } } impl PC4> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 4; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC4> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 4; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC4> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 4; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC4> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 4, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC4> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(4) }) } } impl OutputPin for PC4> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(4) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(4) }) } } impl toggleable::Default for PC4> {} impl InputPin for PC4> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(4) }) } } impl PC4> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 4, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC4> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(4) }) } } /// Pin pub struct PC5 { _mode: PhantomData, } impl PC5 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC5> { _set_alternate_mode(5, 0); PC5 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC5> { _set_alternate_mode(5, 1); PC5 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC5> { _set_alternate_mode(5, 2); PC5 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC5> { _set_alternate_mode(5, 3); PC5 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC5> { _set_alternate_mode(5, 4); PC5 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC5> { _set_alternate_mode(5, 5); PC5 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC5> { _set_alternate_mode(5, 6); PC5 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC5> { _set_alternate_mode(5, 7); PC5 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC5 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC5 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC5 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC5 { let offset = 2 * 5; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC5 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 5))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC5 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 5))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC5 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC5> { let offset = 2 * 5; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 5))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 5))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC5 { _mode: PhantomData } } } impl PC5> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 5; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC5> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 5; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC5> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 5; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC5> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 5, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC5> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(5) }) } } impl OutputPin for PC5> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(5) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(5) }) } } impl toggleable::Default for PC5> {} impl InputPin for PC5> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(5) }) } } impl PC5> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 5, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC5> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(5) }) } } /// Pin pub struct PC6 { _mode: PhantomData, } impl PC6 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC6> { _set_alternate_mode(6, 0); PC6 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC6> { _set_alternate_mode(6, 1); PC6 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC6> { _set_alternate_mode(6, 2); PC6 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC6> { _set_alternate_mode(6, 3); PC6 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC6> { _set_alternate_mode(6, 4); PC6 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC6> { _set_alternate_mode(6, 5); PC6 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC6> { _set_alternate_mode(6, 6); PC6 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC6> { _set_alternate_mode(6, 7); PC6 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC6 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC6 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC6 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC6 { let offset = 2 * 6; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC6 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 6))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC6 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 6))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC6 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC6> { let offset = 2 * 6; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 6))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 6))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC6 { _mode: PhantomData } } } impl PC6> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 6; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC6> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 6; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC6> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 6; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC6> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 6, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC6> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(6) }) } } impl OutputPin for PC6> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(6) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(6) }) } } impl toggleable::Default for PC6> {} impl InputPin for PC6> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(6) }) } } impl PC6> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 6, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC6> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(6) }) } } /// Pin pub struct PC7 { _mode: PhantomData, } impl PC7 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC7> { _set_alternate_mode(7, 0); PC7 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC7> { _set_alternate_mode(7, 1); PC7 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC7> { _set_alternate_mode(7, 2); PC7 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC7> { _set_alternate_mode(7, 3); PC7 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC7> { _set_alternate_mode(7, 4); PC7 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC7> { _set_alternate_mode(7, 5); PC7 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC7> { _set_alternate_mode(7, 6); PC7 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC7> { _set_alternate_mode(7, 7); PC7 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC7 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC7 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC7 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC7 { let offset = 2 * 7; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC7 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 7))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC7 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 7))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC7 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC7> { let offset = 2 * 7; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 7))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 7))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC7 { _mode: PhantomData } } } impl PC7> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 7; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC7> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 7; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC7> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 7; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC7> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 7, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC7> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(7) }) } } impl OutputPin for PC7> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(7) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(7) }) } } impl toggleable::Default for PC7> {} impl InputPin for PC7> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(7) }) } } impl PC7> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 7, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC7> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(7) }) } } /// Pin pub struct PC8 { _mode: PhantomData, } impl PC8 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC8> { _set_alternate_mode(8, 0); PC8 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC8> { _set_alternate_mode(8, 1); PC8 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC8> { _set_alternate_mode(8, 2); PC8 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC8> { _set_alternate_mode(8, 3); PC8 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC8> { _set_alternate_mode(8, 4); PC8 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC8> { _set_alternate_mode(8, 5); PC8 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC8> { _set_alternate_mode(8, 6); PC8 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC8> { _set_alternate_mode(8, 7); PC8 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC8 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC8 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC8 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC8 { let offset = 2 * 8; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC8 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 8))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC8 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 8))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC8 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC8> { let offset = 2 * 8; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 8))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 8))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC8 { _mode: PhantomData } } } impl PC8> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 8; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC8> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 8; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC8> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 8; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC8> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 8, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC8> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(8) }) } } impl OutputPin for PC8> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(8) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(8) }) } } impl toggleable::Default for PC8> {} impl InputPin for PC8> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(8) }) } } impl PC8> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 8, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC8> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(8) }) } } /// Pin pub struct PC9 { _mode: PhantomData, } impl PC9 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC9> { _set_alternate_mode(9, 0); PC9 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC9> { _set_alternate_mode(9, 1); PC9 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC9> { _set_alternate_mode(9, 2); PC9 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC9> { _set_alternate_mode(9, 3); PC9 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC9> { _set_alternate_mode(9, 4); PC9 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC9> { _set_alternate_mode(9, 5); PC9 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC9> { _set_alternate_mode(9, 6); PC9 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC9> { _set_alternate_mode(9, 7); PC9 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC9 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC9 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC9 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC9 { let offset = 2 * 9; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC9 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 9))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC9 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 9))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC9 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC9> { let offset = 2 * 9; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 9))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 9))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC9 { _mode: PhantomData } } } impl PC9> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 9; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC9> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 9; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC9> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 9; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC9> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 9, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC9> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(9) }) } } impl OutputPin for PC9> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(9) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(9) }) } } impl toggleable::Default for PC9> {} impl InputPin for PC9> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(9) }) } } impl PC9> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 9, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC9> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(9) }) } } /// Pin pub struct PC10 { _mode: PhantomData, } impl PC10 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC10> { _set_alternate_mode(10, 0); PC10 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC10> { _set_alternate_mode(10, 1); PC10 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC10> { _set_alternate_mode(10, 2); PC10 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC10> { _set_alternate_mode(10, 3); PC10 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC10> { _set_alternate_mode(10, 4); PC10 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC10> { _set_alternate_mode(10, 5); PC10 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC10> { _set_alternate_mode(10, 6); PC10 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC10> { _set_alternate_mode(10, 7); PC10 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC10 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC10 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC10 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC10 { let offset = 2 * 10; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC10 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 10))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC10 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 10))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC10 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC10> { let offset = 2 * 10; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 10))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 10))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC10 { _mode: PhantomData } } } impl PC10> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 10; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC10> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 10; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC10> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 10; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC10> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 10, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC10> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(10) }) } } impl OutputPin for PC10> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(10) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(10) }) } } impl toggleable::Default for PC10> {} impl InputPin for PC10> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(10) }) } } impl PC10> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 10, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC10> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(10) }) } } /// Pin pub struct PC11 { _mode: PhantomData, } impl PC11 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC11> { _set_alternate_mode(11, 0); PC11 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC11> { _set_alternate_mode(11, 1); PC11 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC11> { _set_alternate_mode(11, 2); PC11 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC11> { _set_alternate_mode(11, 3); PC11 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC11> { _set_alternate_mode(11, 4); PC11 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC11> { _set_alternate_mode(11, 5); PC11 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC11> { _set_alternate_mode(11, 6); PC11 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC11> { _set_alternate_mode(11, 7); PC11 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC11 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC11 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC11 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC11 { let offset = 2 * 11; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC11 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 11))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC11 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 11))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC11 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC11> { let offset = 2 * 11; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 11))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 11))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC11 { _mode: PhantomData } } } impl PC11> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 11; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC11> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 11; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC11> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 11; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC11> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 11, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC11> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(11) }) } } impl OutputPin for PC11> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(11) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(11) }) } } impl toggleable::Default for PC11> {} impl InputPin for PC11> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(11) }) } } impl PC11> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 11, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC11> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(11) }) } } /// Pin pub struct PC12 { _mode: PhantomData, } impl PC12 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC12> { _set_alternate_mode(12, 0); PC12 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC12> { _set_alternate_mode(12, 1); PC12 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC12> { _set_alternate_mode(12, 2); PC12 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC12> { _set_alternate_mode(12, 3); PC12 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC12> { _set_alternate_mode(12, 4); PC12 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC12> { _set_alternate_mode(12, 5); PC12 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC12> { _set_alternate_mode(12, 6); PC12 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC12> { _set_alternate_mode(12, 7); PC12 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC12 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC12 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC12 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC12 { let offset = 2 * 12; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC12 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 12))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC12 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 12))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC12 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC12> { let offset = 2 * 12; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 12))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 12))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC12 { _mode: PhantomData } } } impl PC12> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 12; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC12> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 12; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC12> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 12; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC12> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 12, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC12> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(12) }) } } impl OutputPin for PC12> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(12) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(12) }) } } impl toggleable::Default for PC12> {} impl InputPin for PC12> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(12) }) } } impl PC12> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 12, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC12> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(12) }) } } /// Pin pub struct PC13 { _mode: PhantomData, } impl PC13 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC13> { _set_alternate_mode(13, 0); PC13 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC13> { _set_alternate_mode(13, 1); PC13 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC13> { _set_alternate_mode(13, 2); PC13 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC13> { _set_alternate_mode(13, 3); PC13 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC13> { _set_alternate_mode(13, 4); PC13 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC13> { _set_alternate_mode(13, 5); PC13 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC13> { _set_alternate_mode(13, 6); PC13 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC13> { _set_alternate_mode(13, 7); PC13 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC13 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC13 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC13 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC13 { let offset = 2 * 13; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC13 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 13))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC13 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 13))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC13 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC13> { let offset = 2 * 13; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 13))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 13))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC13 { _mode: PhantomData } } } impl PC13> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 13; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC13> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 13; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC13> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 13; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC13> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 13, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC13> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(13) }) } } impl OutputPin for PC13> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(13) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(13) }) } } impl toggleable::Default for PC13> {} impl InputPin for PC13> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(13) }) } } impl PC13> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 13, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC13> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(13) }) } } /// Pin pub struct PC14 { _mode: PhantomData, } impl PC14 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC14> { _set_alternate_mode(14, 0); PC14 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC14> { _set_alternate_mode(14, 1); PC14 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC14> { _set_alternate_mode(14, 2); PC14 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC14> { _set_alternate_mode(14, 3); PC14 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC14> { _set_alternate_mode(14, 4); PC14 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC14> { _set_alternate_mode(14, 5); PC14 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC14> { _set_alternate_mode(14, 6); PC14 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC14> { _set_alternate_mode(14, 7); PC14 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC14 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC14 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC14 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC14 { let offset = 2 * 14; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC14 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 14))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC14 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 14))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC14 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC14> { let offset = 2 * 14; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 14))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 14))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC14 { _mode: PhantomData } } } impl PC14> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 14; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC14> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 14; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC14> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 14; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC14> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 14, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC14> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(14) }) } } impl OutputPin for PC14> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(14) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(14) }) } } impl toggleable::Default for PC14> {} impl InputPin for PC14> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(14) }) } } impl PC14> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 14, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC14> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(14) }) } } /// Pin pub struct PC15 { _mode: PhantomData, } impl PC15 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PC15> { _set_alternate_mode(15, 0); PC15 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PC15> { _set_alternate_mode(15, 1); PC15 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PC15> { _set_alternate_mode(15, 2); PC15 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PC15> { _set_alternate_mode(15, 3); PC15 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PC15> { _set_alternate_mode(15, 4); PC15 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PC15> { _set_alternate_mode(15, 5); PC15 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PC15> { _set_alternate_mode(15, 6); PC15 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PC15> { _set_alternate_mode(15, 7); PC15 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PC15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC15 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PC15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC15 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PC15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PC15 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PC15 { let offset = 2 * 15; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PC15 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PC15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 15))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC15 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PC15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 15))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC15 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PC15> { let offset = 2 * 15; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 15))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 15))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PC15 { _mode: PhantomData } } } impl PC15> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 15; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PC15> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 15; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOC::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PC15> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 15; unsafe { let reg = &(*GPIOC::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PC15> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 15, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PC15> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_set_low(15) }) } } impl OutputPin for PC15> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_high(15) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOC::ptr()).set_low(15) }) } } impl toggleable::Default for PC15> {} impl InputPin for PC15> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(15) }) } } impl PC15> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 15, port: GPIOC::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PC15> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOC::ptr()).is_low(15) }) } } } /// GPIO #[cfg(any( feature = "stm32f030", feature = "stm32f051", feature = "stm32f058", feature = "stm32f070" ))] pub mod gpiod { use core::marker::PhantomData; use core::convert::Infallible; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, toggleable}; use crate::{rcc::Rcc, pac::GPIOD}; use cortex_m::interrupt::CriticalSection; use super::{ Alternate, Analog, Floating, GpioExt, Input, OpenDrain, Output, PullDown, PullUp, PushPull, AF0, AF1, AF2, AF3, AF4, AF5, AF6, AF7, Pin, GpioRegExt, }; /// GPIO parts pub struct Parts { /// Pin pub pd2: PD2>, } impl GpioExt for GPIOD { type Parts = Parts; fn split(self, rcc: &mut Rcc) -> Parts { rcc.regs.ahbenr.modify(|_, w| w.iopden().set_bit()); Parts { pd2: PD2 { _mode: PhantomData }, } } } fn _set_alternate_mode(index: usize, mode: u32) { let offset = 2 * index; let offset2 = 4 * index; unsafe { let reg = &(*GPIOD::ptr()); if offset2 < 32 { reg.afrl.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } else { let offset2 = offset2 - 32; reg.afrh.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); } } /// Pin pub struct PD2 { _mode: PhantomData, } impl PD2 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PD2> { _set_alternate_mode(2, 0); PD2 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PD2> { _set_alternate_mode(2, 1); PD2 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PD2> { _set_alternate_mode(2, 2); PD2 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PD2> { _set_alternate_mode(2, 3); PD2 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PD2> { _set_alternate_mode(2, 4); PD2 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PD2> { _set_alternate_mode(2, 5); PD2 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PD2> { _set_alternate_mode(2, 6); PD2 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PD2> { _set_alternate_mode(2, 7); PD2 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PD2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOD::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PD2 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PD2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOD::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PD2 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PD2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOD::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PD2 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PD2 { let offset = 2 * 2; unsafe { let reg = &(*GPIOD::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PD2 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PD2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOD::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PD2 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PD2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOD::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PD2 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PD2> { let offset = 2 * 2; unsafe { let reg = &(*GPIOD::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 2))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PD2 { _mode: PhantomData } } } impl PD2> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 2; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOD::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PD2> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 2; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOD::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PD2> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 2; unsafe { let reg = &(*GPIOD::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PD2> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 2, port: GPIOD::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PD2> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOD::ptr()).is_set_low(2) }) } } impl OutputPin for PD2> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOD::ptr()).set_high(2) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOD::ptr()).set_low(2) }) } } impl toggleable::Default for PD2> {} impl InputPin for PD2> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOD::ptr()).is_low(2) }) } } impl PD2> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 2, port: GPIOD::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PD2> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOD::ptr()).is_low(2) }) } } } /// GPIO #[cfg(any(feature = "stm32f030xc", feature = "stm32f070"))] pub mod gpiof { use core::marker::PhantomData; use core::convert::Infallible; use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, toggleable}; use crate::{rcc::Rcc, pac::GPIOF}; use cortex_m::interrupt::CriticalSection; use super::{ Alternate, Analog, Floating, GpioExt, Input, OpenDrain, Output, PullDown, PullUp, PushPull, AF0, AF1, AF2, AF3, AF4, AF5, AF6, AF7, Pin, GpioRegExt, }; /// GPIO parts pub struct Parts { /// Pin pub pf0: PF0>, /// Pin pub pf1: PF1>, } impl GpioExt for GPIOF { type Parts = Parts; fn split(self, rcc: &mut Rcc) -> Parts { rcc.regs.ahbenr.modify(|_, w| w.iopfen().set_bit()); Parts { pf0: PF0 { _mode: PhantomData }, pf1: PF1 { _mode: PhantomData }, } } } fn _set_alternate_mode(index: usize, mode: u32) { let offset = 2 * index; let offset2 = 4 * index; unsafe { let reg = &(*GPIOF::ptr()); if offset2 < 32 { reg.afrl.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } else { let offset2 = offset2 - 32; reg.afrh.modify(|r, w| { w.bits((r.bits() & !(0b1111 << offset2)) | (mode << offset2)) }); } reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); } } /// Pin pub struct PF0 { _mode: PhantomData, } impl PF0 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PF0> { _set_alternate_mode(0, 0); PF0 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PF0> { _set_alternate_mode(0, 1); PF0 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PF0> { _set_alternate_mode(0, 2); PF0 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PF0> { _set_alternate_mode(0, 3); PF0 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PF0> { _set_alternate_mode(0, 4); PF0 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PF0> { _set_alternate_mode(0, 5); PF0 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PF0> { _set_alternate_mode(0, 6); PF0 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PF0> { _set_alternate_mode(0, 7); PF0 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PF0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PF0 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PF0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PF0 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PF0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PF0 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PF0 { let offset = 2 * 0; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PF0 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PF0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PF0 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PF0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PF0 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PF0> { let offset = 2 * 0; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 0))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PF0 { _mode: PhantomData } } } impl PF0> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 0; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PF0> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 0; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PF0> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 0; unsafe { let reg = &(*GPIOF::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PF0> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 0, port: GPIOF::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PF0> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOF::ptr()).is_set_low(0) }) } } impl OutputPin for PF0> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOF::ptr()).set_high(0) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOF::ptr()).set_low(0) }) } } impl toggleable::Default for PF0> {} impl InputPin for PF0> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOF::ptr()).is_low(0) }) } } impl PF0> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 0, port: GPIOF::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PF0> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOF::ptr()).is_low(0) }) } } /// Pin pub struct PF1 { _mode: PhantomData, } impl PF1 { /// Configures the pin to operate in AF0 mode pub fn into_alternate_af0(self, _cs: &CriticalSection) -> PF1> { _set_alternate_mode(1, 0); PF1 { _mode: PhantomData } } /// Configures the pin to operate in AF1 mode pub fn into_alternate_af1(self, _cs: &CriticalSection) -> PF1> { _set_alternate_mode(1, 1); PF1 { _mode: PhantomData } } /// Configures the pin to operate in AF2 mode pub fn into_alternate_af2(self, _cs: &CriticalSection) -> PF1> { _set_alternate_mode(1, 2); PF1 { _mode: PhantomData } } /// Configures the pin to operate in AF3 mode pub fn into_alternate_af3(self, _cs: &CriticalSection) -> PF1> { _set_alternate_mode(1, 3); PF1 { _mode: PhantomData } } /// Configures the pin to operate in AF4 mode pub fn into_alternate_af4(self, _cs: &CriticalSection) -> PF1> { _set_alternate_mode(1, 4); PF1 { _mode: PhantomData } } /// Configures the pin to operate in AF5 mode pub fn into_alternate_af5(self, _cs: &CriticalSection) -> PF1> { _set_alternate_mode(1, 5); PF1 { _mode: PhantomData } } /// Configures the pin to operate in AF6 mode pub fn into_alternate_af6(self, _cs: &CriticalSection) -> PF1> { _set_alternate_mode(1, 6); PF1 { _mode: PhantomData } } /// Configures the pin to operate in AF7 mode pub fn into_alternate_af7(self, _cs: &CriticalSection) -> PF1> { _set_alternate_mode(1, 7); PF1 { _mode: PhantomData } } /// Configures the pin to operate as a floating input pin pub fn into_floating_input(self, _cs: &CriticalSection) -> PF1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PF1 { _mode: PhantomData } } /// Configures the pin to operate as a pulled down input pin pub fn into_pull_down_input(self, _cs: &CriticalSection) -> PF1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b10 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PF1 { _mode: PhantomData } } /// Configures the pin to operate as a pulled up input pin pub fn into_pull_up_input(self, _cs: &CriticalSection) -> PF1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); } PF1 { _mode: PhantomData } } /// Configures the pin to operate as an analog pin pub fn into_analog(self, _cs: &CriticalSection) -> PF1 { let offset = 2 * 1; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b11 << offset))); } PF1 { _mode: PhantomData } } /// Configures the pin to operate as an open drain output pin pub fn into_open_drain_output(self, _cs: &CriticalSection) -> PF1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() | (0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PF1 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin pub fn into_push_pull_output(self, _cs: &CriticalSection) -> PF1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PF1 { _mode: PhantomData } } /// Configures the pin to operate as an push pull output pin with quick fall /// and rise times pub fn into_push_pull_output_hs(self, _cs: &CriticalSection) -> PF1> { let offset = 2 * 1; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b00 << offset))); reg.otyper.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.ospeedr.modify(|r, w| w.bits(r.bits() & !(0b1 << 1))); reg.moder .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (0b01 << offset))); } PF1 { _mode: PhantomData } } } impl PF1> { /// Enables / disables the internal pull up pub fn internal_pull_up(&mut self, _cs: &CriticalSection, on: bool) { let offset = 2 * 1; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } } } impl PF1> { /// Enables / disables the internal pull up pub fn internal_pull_up(self, _cs: &CriticalSection, on: bool) -> Self { let offset = 2 * 1; let value = if on { 0b01 } else { 0b00 }; unsafe { let reg = &(*GPIOF::ptr()); reg.pupdr .modify(|r, w| w.bits((r.bits() & !(0b11 << offset)) | (value << offset))); } self } } impl PF1> { /// Turns pin alternate configuration pin into open drain pub fn set_open_drain(self, _cs: &CriticalSection) -> Self { let offset = 1; unsafe { let reg = &(*GPIOF::ptr()); reg.otyper.modify(|r, w| w.bits(r.bits() | (1 << offset))); } self } } impl PF1> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 1, port: GPIOF::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl StatefulOutputPin for PF1> { fn is_set_high(&self) -> Result { self.is_set_low().map(|v| !v) } fn is_set_low(&self) -> Result { Ok(unsafe { (*GPIOF::ptr()).is_set_low(1) }) } } impl OutputPin for PF1> { type Error = Infallible; fn set_high(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOF::ptr()).set_high(1) }) } fn set_low(&mut self) -> Result<(), Self::Error> { Ok(unsafe { (*GPIOF::ptr()).set_low(1) }) } } impl toggleable::Default for PF1> {} impl InputPin for PF1> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOF::ptr()).is_low(1) }) } } impl PF1> { /// 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 pub fn downgrade(self) -> Pin> { Pin { i: 1, port: GPIOF::ptr() as *const dyn GpioRegExt, _mode: self._mode, } } } impl InputPin for PF1> { type Error = Infallible; fn is_high(&self) -> Result { self.is_low().map(|v| !v) } fn is_low(&self) -> Result { Ok(unsafe { (*GPIOF::ptr()).is_low(1) }) } } } }