diff --git a/.clippy.toml b/.clippy.toml index cef91fde7..ece14b8d2 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.52" +msrv = "1.54" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3e90f3993..232b0c5f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,7 +57,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.52.0 + toolchain: 1.54.0 target: thumbv7em-none-eabihf override: true profile: minimal diff --git a/CHANGELOG.md b/CHANGELOG.md index 49214e95c..0e4d52e9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +- The MSRV was bumped to 1.54 ([#308]) +- Generic `into_af_push_pull` and `into_af_open_drain` ([#308]) - `BusClock` and `BusTimerClock` traits ([#302]) - `RccBus`, `Enable`, `Reset` traits and implementations for peripherals ([#299]) - Support cortex-m-rt `v0.7.0` but still allow `v0.6.13` ([#283]) @@ -508,6 +510,7 @@ let clocks = rcc [defmt]: https://github.com/knurling-rs/defmt [filter]: https://defmt.ferrous-systems.com/filtering.html +[#308]: https://github.com/stm32-rs/stm32f3xx-hal/pull/308 [#304]: https://github.com/stm32-rs/stm32f3xx-hal/pull/304 [#302]: https://github.com/stm32-rs/stm32f3xx-hal/pull/302 [#299]: https://github.com/stm32-rs/stm32f3xx-hal/pull/299 diff --git a/Cargo.toml b/Cargo.toml index 755869590..248aa9f5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ exclude = [ ".markdownlint.yml" ] resolver = "2" -rust-version = "1.52" +rust-version = "1.54" [workspace] members = [ @@ -35,7 +35,7 @@ rustc-args = ["--cfg", "docsrs"] [dependencies] cfg-if = "1.0.0" -cortex-m = "0.7.2" +cortex-m = "0.7.4" cortex-m-rt = "0.7" defmt = { version = ">=0.2.3, <0.4.0", optional = true } embedded-dma = "0.1.2" @@ -55,7 +55,6 @@ enumset = { version = "1.0.6", optional = true} bare-metal = "0.2.5" [dev-dependencies] -cortex-m = "0.7.2" cortex-m-semihosting = "0.3.7" defmt-rtt = "0.3.0" defmt-test = "0.3.0" @@ -63,10 +62,10 @@ panic-probe = "0.3.0" panic-semihosting = "0.5.6" usbd-serial = "0.1.1" usb-device = "0.2.8" -cortex-m-rtic = "=0.6.0-rc.4, <0.6.0-rc.5" -systick-monotonic = "0.1.0-rc.2" +cortex-m-rtic = "1.0" +systick-monotonic = "1.0" panic-rtt-target = { version = "0.1", features = ["cortex-m"] } -rtt-target = { version = "0.3.0", features = ["cortex-m"] } +rtt-target = { version = "0.3.1", features = ["cortex-m"] } [build-dependencies] slice-group-by = "0.2.6" diff --git a/README.md b/README.md index e51c968d7..d3f6c9b1f 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Crate](https://img.shields.io/crates/v/stm32f3xx-hal.svg)](https://crates.io/crates/stm32f3xx-hal) [![Docs](https://docs.rs/stm32f3xx-hal/badge.svg)](https://docs.rs/stm32f3xx-hal) [![Crates.io](https://img.shields.io/crates/d/stm32f3xx-hal.svg)](https://crates.io/crates/stm32f3xx-hal) -![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.52+-blue.svg) +![Minimum Supported Rust Version](https://img.shields.io/badge/rustc-1.54+-blue.svg) `stm32f3xx-hal` contains a multi device hardware abstraction on top of the peripheral access API for the STMicro STM32F3 series microcontrollers. The @@ -139,7 +139,7 @@ See the [examples folder](examples) for more example programs. ## Minimum Supported Rust Version (MSRV) -This crate is guaranteed to compile on stable Rust 1.52.0 and up. It *might* +This crate is guaranteed to compile on stable Rust 1.54.0 and up. It *might* compile with older versions but that may change in any new patch release. diff --git a/examples/can.rs b/examples/can.rs index 79ea7c293..73e5990f4 100644 --- a/examples/can.rs +++ b/examples/can.rs @@ -43,21 +43,20 @@ fn main() -> ! { // Configure CAN RX and TX pins (AF9) let rx = gpioa .pa11 - .into_af9_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh); + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh); let tx = gpioa .pa12 - .into_af9_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh); + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh); // Initialize the CAN peripheral - let mut can = Can::new(dp.CAN, tx, rx, &mut rcc.apb1); - // Use loopback mode: No pins need to be assigned to peripheral. // APB1 (PCLK1): 64MHz, Bit rate: 500kBit/s, Sample Point 87.5% // Value was calculated with http://www.bittiming.can-wiki.info/ - can.modify_config() + let mut can = bxcan::Can::builder(Can::new(dp.CAN, tx, rx, &mut rcc.apb1)) .set_bit_timing(0x001c_0003) .set_loopback(false) - .set_silent(false); + .set_silent(false) + .leave_disabled(); let mut filters = can.modify_filters(); @@ -67,7 +66,7 @@ fn main() -> ! { drop(filters); // Sync to the bus and start normal operation. - block!(can.enable()).ok(); + block!(can.enable_non_blocking()).ok(); let mut led0 = gpiob .pb15 diff --git a/examples/i2c_scanner.rs b/examples/i2c_scanner.rs index 160108a17..c371095e6 100644 --- a/examples/i2c_scanner.rs +++ b/examples/i2c_scanner.rs @@ -31,11 +31,11 @@ fn main() -> ! { let mut scl = gpiob .pb6 - .into_af4_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); + .into_af_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); let mut sda = gpiob .pb7 - .into_af4_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); + .into_af_open_drain(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); scl.internal_pull_up(&mut gpiob.pupdr, true); sda.internal_pull_up(&mut gpiob.pupdr, true); let mut i2c = hal::i2c::I2c::new( diff --git a/examples/pwm.rs b/examples/pwm.rs index aa56f4bc7..3a00c49d7 100644 --- a/examples/pwm.rs +++ b/examples/pwm.rs @@ -34,38 +34,38 @@ fn main() -> ! { let mut gpioa = dp.GPIOA.split(&mut rcc.ahb); let pa4 = gpioa .pa4 - .into_af2_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl); + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl); let pa6 = gpioa .pa6 - .into_af2_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl); + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl); let pa7 = gpioa .pa7 - .into_af2_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl); + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl); let mut gpiob = dp.GPIOB.split(&mut rcc.ahb); let pb0 = gpiob .pb0 - .into_af2_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); + .into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); let pb1 = gpiob .pb1 - .into_af2_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); + .into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); let pb4 = gpiob .pb4 - .into_af2_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); + .into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); let pb5 = gpiob .pb5 - .into_af2_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); + .into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrl); let pb8 = gpiob .pb8 - .into_af1_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh); + .into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh); let pb10 = gpiob .pb10 - .into_af1_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh); + .into_af_push_pull(&mut gpiob.moder, &mut gpiob.otyper, &mut gpiob.afrh); let mut gpioc = dp.GPIOC.split(&mut rcc.ahb); let pc10 = gpioc .pc10 - .into_af4_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh); + .into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh); // TIM3 // diff --git a/examples/serial_dma.rs b/examples/serial_dma.rs index 2e7e358ed..bf580dbce 100644 --- a/examples/serial_dma.rs +++ b/examples/serial_dma.rs @@ -35,10 +35,10 @@ fn main() -> ! { let pins = ( gpioa .pa9 - .into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh), + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh), gpioa .pa10 - .into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh), + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh), ); let serial = Serial::new(dp.USART1, pins, 9600.Bd(), clocks, &mut rcc.apb2); let (tx, rx) = serial.split(); diff --git a/examples/serial_echo_rtic.rs b/examples/serial_echo_rtic.rs index 0940ba391..0e7aac75a 100644 --- a/examples/serial_echo_rtic.rs +++ b/examples/serial_echo_rtic.rs @@ -69,14 +69,14 @@ mod app { // configure this pin to make use of its `USART1_TX` alternative function // (AF mapping taken from table 14 "Alternate functions for port A" of the datasheet at // https://www.st.com/en/microcontrollers-microprocessors/stm32f303vc.html) - .into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh), + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh), gpioa // Rx pin .pa10 // configure this pin to make use of its `USART1_RX` alternative function // (AF mapping taken from table 14 "Alternate functions for port A" of the datasheet at // https://www.st.com/en/microcontrollers-microprocessors/stm32f303vc.html) - .into_af7_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh), + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh), ); pins.1.internal_pull_up(&mut gpioa.pupdr, true); let mut serial: SerialType = diff --git a/examples/spi.rs b/examples/spi.rs index 9c6e17706..63727ea72 100644 --- a/examples/spi.rs +++ b/examples/spi.rs @@ -32,13 +32,13 @@ fn main() -> ! { // Configure pins for SPI let sck = gpioc .pc10 - .into_af6_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh); + .into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh); let miso = gpioc .pc11 - .into_af6_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh); + .into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh); let mosi = gpioc .pc12 - .into_af6_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh); + .into_af_push_pull(&mut gpioc.moder, &mut gpioc.otyper, &mut gpioc.afrh); let mut spi = Spi::new(dp.SPI3, (sck, miso, mosi), 3.MHz(), clocks, &mut rcc.apb1); diff --git a/examples/usb_serial.rs b/examples/usb_serial.rs index 5933e8ad9..749bbeadd 100644 --- a/examples/usb_serial.rs +++ b/examples/usb_serial.rs @@ -53,11 +53,10 @@ fn main() -> ! { usb_dp.set_low().ok(); delay(clocks.sysclk().0 / 100); - let usb_dm = - gpioa - .pa11 - .into_af14_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh); - let usb_dp = usb_dp.into_af14_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh); + let usb_dm = gpioa + .pa11 + .into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh); + let usb_dp = usb_dp.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrh); let usb = Peripheral { usb: dp.USB, diff --git a/src/can.rs b/src/can.rs index e1531dd83..9a4213c63 100644 --- a/src/can.rs +++ b/src/can.rs @@ -55,11 +55,11 @@ where Rx: RxPin, { /// Create a new `bxcan::CAN` instance. - pub fn new(can: pac::CAN, tx: Tx, rx: Rx, apb1: &mut APB1) -> bxcan::Can { + pub fn new(can: pac::CAN, tx: Tx, rx: Rx, apb1: &mut APB1) -> Self { pac::CAN::enable(apb1); pac::CAN::reset(apb1); - bxcan::Can::builder(Can { can, tx, rx }).enable() + Can { can, tx, rx } } /// Releases the CAN peripheral and associated pins diff --git a/src/gpio.rs b/src/gpio.rs index 00e88f58f..99a32748e 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -159,21 +159,11 @@ pub mod marker { /// Marker trait for active pin modes pub trait Active {} - macro_rules! af_marker_trait { - ([$($i:literal),+ $(,)?]) => { - paste::paste! { - $( - #[doc = "Marker trait for pins with alternate function " $i " mapping"] - pub trait [] { - /// Associated AFR register - type AFR: super::Afr; - } - )+ - } - }; + /// Marker trait for pins with alternate function `A` mapping + pub trait IntoAf { + /// Associated AFR register + type AFR: super::Afr; } - - af_marker_trait!([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]); } /// Runtime defined GPIO port (type state) @@ -673,43 +663,75 @@ where } } +impl Pin +where + Gpio: marker::GpioStatic, + Index: marker::Index, +{ + /// Configures the pin to operate as an alternate function push-pull output pin + pub fn into_af_push_pull( + self, + moder: &mut Gpio::MODER, + otyper: &mut Gpio::OTYPER, + afr: &mut >::AFR, + ) -> Pin> + where + Self: marker::IntoAf, + { + moder.alternate(self.index.index()); + otyper.push_pull(self.index.index()); + afr.afx(self.index.index(), A); + self.into_mode() + } + + /// Configures the pin to operate as an alternate function open-drain output pin + pub fn into_af_open_drain( + self, + moder: &mut Gpio::MODER, + otyper: &mut Gpio::OTYPER, + afr: &mut >::AFR, + ) -> Pin> + where + Self: marker::IntoAf, + { + moder.alternate(self.index.index()); + otyper.open_drain(self.index.index()); + afr.afx(self.index.index(), A); + self.into_mode() + } +} + macro_rules! af { - ($i:literal, $AFi:ident, $IntoAfi:ident, $into_afi_push_pull:ident, $into_afi_open_drain:ident) => { - paste::paste! { - #[doc = "Alternate function " $i " (type state)"] - pub type $AFi = Alternate; - } + ($i:literal, $AFi:ident, $into_afi_push_pull:ident, $into_afi_open_drain:ident) => { + #[doc = concat!("Alternate function ", $i, " (type state)" )] + pub type $AFi = Alternate; impl Pin where - Self: marker::$IntoAfi, + Self: marker::IntoAf<$i>, Gpio: marker::GpioStatic, Index: marker::Index, { /// Configures the pin to operate as an alternate function push-pull output pin + #[deprecated(since = "0.9.0", note = "Will be removed with the next version. Use `info_af_push_pull()` instead")] pub fn $into_afi_push_pull( self, moder: &mut Gpio::MODER, otyper: &mut Gpio::OTYPER, - afr: &mut ::AFR, + afr: &mut >::AFR, ) -> Pin> { - moder.alternate(self.index.index()); - otyper.push_pull(self.index.index()); - afr.afx(self.index.index(), $i); - self.into_mode() + self.into_af_push_pull::<$i>(moder, otyper, afr) } /// Configures the pin to operate as an alternate function open-drain output pin + #[deprecated(since = "0.9.0", note = "Will be removed with the next version. Use `info_af_open_drain()` instead")] pub fn $into_afi_open_drain( self, moder: &mut Gpio::MODER, otyper: &mut Gpio::OTYPER, - afr: &mut ::AFR, + afr: &mut >::AFR, ) -> Pin> { - moder.alternate(self.index.index()); - otyper.open_drain(self.index.index()); - afr.afx(self.index.index(), $i); - self.into_mode() + self.into_af_open_drain::<$i>(moder, otyper, afr) } } }; @@ -717,7 +739,7 @@ macro_rules! af { ([$($i:literal),+ $(,)?]) => { paste::paste! { $( - af!($i, [], [], [], []); + af!($i, [], [], []); )+ } }; @@ -781,196 +803,194 @@ macro_rules! gpio { ({ GPIO: $GPIOX:ident, gpio: $gpiox:ident, - Gpio: $Gpiox:ty, + Gpio: $Gpiox:ident, port_index: $port_index:literal, gpio_mapped: $gpioy:ident, partially_erased_pin: $PXx:ident, pins: [$( $i:literal => ( - $PXi:ident, $pxi:ident, $MODE:ty, $AFR:ident, [$($IntoAfi:ident),*], + $PXi:ident, $pxi:ident, $MODE:ty, $AFR:ident, [$($af:literal),*], ), )+], }) => { - paste::paste! { - #[doc = "GPIO port " $GPIOX " (type state)"] - #[derive(Debug)] - #[cfg_attr(feature = "defmt", derive(defmt::Format))] - pub struct $Gpiox; + #[doc = concat!("GPIO port ", stringify!($GPIOX), " (type state)")] + #[derive(Debug)] + #[cfg_attr(feature = "defmt", derive(defmt::Format))] + pub struct $Gpiox; - impl private::Gpio for $Gpiox { - type Reg = crate::pac::$gpioy::RegisterBlock; + impl private::Gpio for $Gpiox { + type Reg = crate::pac::$gpioy::RegisterBlock; - #[inline(always)] - fn ptr(&self) -> *const Self::Reg { - crate::pac::$GPIOX::ptr() - } + #[inline(always)] + fn ptr(&self) -> *const Self::Reg { + crate::pac::$GPIOX::ptr() + } - #[inline(always)] - fn port_index(&self) -> u8 { - $port_index - } + #[inline(always)] + fn port_index(&self) -> u8 { + $port_index } + } - impl marker::Gpio for $Gpiox {} + impl marker::Gpio for $Gpiox {} - impl marker::GpioStatic for $Gpiox { - type MODER = $gpiox::MODER; - type OTYPER = $gpiox::OTYPER; - type OSPEEDR = $gpiox::OSPEEDR; - type PUPDR = $gpiox::PUPDR; - } + impl marker::GpioStatic for $Gpiox { + type MODER = $gpiox::MODER; + type OTYPER = $gpiox::OTYPER; + type OSPEEDR = $gpiox::OSPEEDR; + type PUPDR = $gpiox::PUPDR; + } + + $( + #[doc = concat!("Pin ", stringify!($PXi))] + pub type $PXi = Pin<$Gpiox, U<$i>, Mode>; $( - #[doc = "Pin " $PXi] - pub type $PXi = Pin<$Gpiox, U<$i>, Mode>; + impl marker::IntoAf<$af> for $PXi { + type AFR = $gpiox::$AFR; + } + )* + )+ + #[doc = concat!("Partially erased pin for ", stringify!($GPIOX))] + pub type $PXx = Pin<$Gpiox, Ux, Mode>; + + #[doc = concat!("All Pins and associated registers for GPIO port ", stringify!($GPIOX))] + pub mod $gpiox { + use core::marker::PhantomData; + + use crate::{ + pac::{$gpioy, $GPIOX}, + rcc::{AHB, Enable, Reset}, + }; + + use super::{Afr, $Gpiox, GpioExt, Moder, Ospeedr, Otyper, Pupdr, U}; + + #[allow(unused_imports)] + use super::{ + Input, Output, Analog, PushPull, OpenDrain, + AF0, AF1, AF2, AF3, AF4, AF5, AF6, AF7, AF8, AF9, AF10, AF11, AF12, AF13, AF14, AF15, + }; + + pub use super::{ + $PXx, $( - impl marker::$IntoAfi for $PXi { - type AFR = $gpiox::$AFR; - } - )* - )+ + $PXi, + )+ + }; - #[doc = "Partially erased pin for " $GPIOX] - pub type $PXx = Pin<$Gpiox, Ux, Mode>; - - #[doc = "All Pins and associated registers for GPIO port " $GPIOX] - pub mod $gpiox { - use core::marker::PhantomData; - - use crate::{ - pac::{$gpioy, $GPIOX}, - rcc::{AHB, Enable, Reset}, - }; - - use super::{Afr, $Gpiox, GpioExt, Moder, Ospeedr, Otyper, Pupdr, U}; - - #[allow(unused_imports)] - use super::{ - Input, Output, Analog, PushPull, OpenDrain, - AF0, AF1, AF2, AF3, AF4, AF5, AF6, AF7, AF8, AF9, AF10, AF11, AF12, AF13, AF14, AF15, - }; - - pub use super::{ - $PXx, - $( - $PXi, - )+ - }; - - /// GPIO parts - pub struct Parts { - /// Opaque AFRH register - pub afrh: AFRH, - /// Opaque AFRL register - pub afrl: AFRL, - /// Opaque MODER register - pub moder: MODER, - /// Opaque OSPEEDR register - pub ospeedr: OSPEEDR, - /// Opaque OTYPER register - pub otyper: OTYPER, - /// Opaque PUPDR register - pub pupdr: PUPDR, - $( - #[doc = "Pin " $PXi] - pub $pxi: $PXi<$MODE>, - )+ - } + /// GPIO parts + pub struct Parts { + /// Opaque AFRH register + pub afrh: AFRH, + /// Opaque AFRL register + pub afrl: AFRL, + /// Opaque MODER register + pub moder: MODER, + /// Opaque OSPEEDR register + pub ospeedr: OSPEEDR, + /// Opaque OTYPER register + pub otyper: OTYPER, + /// Opaque PUPDR register + pub pupdr: PUPDR, + $( + #[doc = concat!("Pin ", stringify!($PXi))] + pub $pxi: $PXi<$MODE>, + )+ + } - impl GpioExt for $GPIOX { - type Parts = Parts; - - fn split(self, ahb: &mut AHB) -> Parts { - <$GPIOX>::enable(ahb); - <$GPIOX>::reset(ahb); - - Parts { - afrh: AFRH(()), - afrl: AFRL(()), - moder: MODER(()), - ospeedr: OSPEEDR(()), - otyper: OTYPER(()), - pupdr: PUPDR(()), - $( - $pxi: $PXi { - gpio: $Gpiox, - index: U::<$i>, - _mode: PhantomData, - }, - )+ - } + impl GpioExt for $GPIOX { + type Parts = Parts; + + fn split(self, ahb: &mut AHB) -> Parts { + <$GPIOX>::enable(ahb); + <$GPIOX>::reset(ahb); + + Parts { + afrh: AFRH(()), + afrl: AFRL(()), + moder: MODER(()), + ospeedr: OSPEEDR(()), + otyper: OTYPER(()), + pupdr: PUPDR(()), + $( + $pxi: $PXi { + gpio: $Gpiox, + index: U::<$i>, + _mode: PhantomData, + }, + )+ } } + } - /// Opaque AFRH register - pub struct AFRH(()); + /// Opaque AFRH register + pub struct AFRH(()); - impl Afr for AFRH { - #[inline] - fn afx(&mut self, i: u8, x: u8) { - const BITWIDTH: u8 = 4; - unsafe { crate::modify_at!((*$GPIOX::ptr()).afrh, BITWIDTH, i - 8, x as u32) }; - } + impl Afr for AFRH { + #[inline] + fn afx(&mut self, i: u8, x: u8) { + const BITWIDTH: u8 = 4; + unsafe { crate::modify_at!((*$GPIOX::ptr()).afrh, BITWIDTH, i - 8, x as u32) }; } + } - /// Opaque AFRL register - pub struct AFRL(()); + /// Opaque AFRL register + pub struct AFRL(()); - impl Afr for AFRL { - #[inline] - fn afx(&mut self, i: u8, x: u8) { - const BITWIDTH: u8 = 4; - unsafe { crate::modify_at!((*$GPIOX::ptr()).afrl, BITWIDTH, i, x as u32) }; - } + impl Afr for AFRL { + #[inline] + fn afx(&mut self, i: u8, x: u8) { + const BITWIDTH: u8 = 4; + unsafe { crate::modify_at!((*$GPIOX::ptr()).afrl, BITWIDTH, i, x as u32) }; } + } - /// Opaque MODER register - pub struct MODER(()); - - r_trait! { - ($GPIOX, $gpioy::moder::MODER15_A, 2); - impl Moder for MODER { - fn input { INPUT } - fn output { OUTPUT } - fn alternate { ALTERNATE } - fn analog { ANALOG } - } + /// Opaque MODER register + pub struct MODER(()); + + r_trait! { + ($GPIOX, $gpioy::moder::MODER15_A, 2); + impl Moder for MODER { + fn input { INPUT } + fn output { OUTPUT } + fn alternate { ALTERNATE } + fn analog { ANALOG } } + } - /// Opaque OSPEEDR register - pub struct OSPEEDR(()); - - r_trait! { - ($GPIOX, $gpioy::ospeedr::OSPEEDR15_A, 2); - impl Ospeedr for OSPEEDR { - fn low { LOWSPEED } - fn medium { MEDIUMSPEED } - fn high { HIGHSPEED } - } + /// Opaque OSPEEDR register + pub struct OSPEEDR(()); + + r_trait! { + ($GPIOX, $gpioy::ospeedr::OSPEEDR15_A, 2); + impl Ospeedr for OSPEEDR { + fn low { LOWSPEED } + fn medium { MEDIUMSPEED } + fn high { HIGHSPEED } } + } - /// Opaque OTYPER register - pub struct OTYPER(()); + /// Opaque OTYPER register + pub struct OTYPER(()); - r_trait! { - ($GPIOX, $gpioy::otyper::OT15_A, 1); - impl Otyper for OTYPER { - fn push_pull { PUSHPULL } - fn open_drain { OPENDRAIN } - } + r_trait! { + ($GPIOX, $gpioy::otyper::OT15_A, 1); + impl Otyper for OTYPER { + fn push_pull { PUSHPULL } + fn open_drain { OPENDRAIN } } + } - /// Opaque PUPDR register - pub struct PUPDR(()); - - r_trait! { - ($GPIOX, $gpioy::pupdr::PUPDR15_A, 2); - impl Pupdr for PUPDR { - fn floating { FLOATING } - fn pull_up { PULLUP } - fn pull_down { PULLDOWN } - } + /// Opaque PUPDR register + pub struct PUPDR(()); + + r_trait! { + ($GPIOX, $gpioy::pupdr::PUPDR15_A, 2); + impl Pupdr for PUPDR { + fn floating { FLOATING } + fn pull_up { PULLUP } + fn pull_down { PULLDOWN } } } } @@ -1003,7 +1023,7 @@ macro_rules! gpio { partially_erased_pin: [

], pins: [$( $i => ( - [

], [

], $MODE, [], [$([]),*], + [

], [

], $MODE, [], [$($af),*], ), )+], }); diff --git a/src/timer.rs b/src/timer.rs index 4618c089a..f15b808ea 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -61,7 +61,7 @@ impl MonoTimer { /// Returns an `Instant` corresponding to "now" pub fn now(&self) -> Instant { Instant { - now: DWT::get_cycle_count(), + now: DWT::cycle_count(), } } } @@ -76,7 +76,7 @@ pub struct Instant { impl Instant { /// Ticks elapsed since the `Instant` was created pub fn elapsed(self) -> u32 { - DWT::get_cycle_count().wrapping_sub(self.now) + DWT::cycle_count().wrapping_sub(self.now) } }