diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs index 46c485b3..0a15563e 100644 --- a/embassy-stm32/src/dac/mod.rs +++ b/embassy-stm32/src/dac/mod.rs @@ -7,8 +7,7 @@ use crate::peripherals; pub use _version::*; pub(crate) mod sealed { - use super::*; - use crate::gpio::{OptionalPin, Pin}; + use crate::gpio::OptionalPin; pub trait Instance { fn regs() -> &'static crate::pac::dac::Dac; diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs index 18ac0f86..a7aad04f 100644 --- a/embassy-stm32/src/dac/v2.rs +++ b/embassy-stm32/src/dac/v2.rs @@ -1,11 +1,12 @@ use crate::dac::{DacPin, Instance}; -use crate::gpio::Pin; -use crate::gpio::{AnyPin, OptionalPin}; +use crate::fmt::*; +use crate::gpio::AnyPin; use crate::pac::dac; use core::marker::PhantomData; use embassy::util::Unborrow; use embassy_extras::unborrow; +#[derive(Debug, defmt::Format)] pub enum Error { UnconfiguredChannel, InvalidValue, @@ -77,7 +78,6 @@ pub enum Value { } pub struct Dac<'d, T: Instance> { - //peri: T, ch1: Option, ch2: Option, phantom: PhantomData<&'d mut T>, @@ -85,11 +85,10 @@ pub struct Dac<'d, T: Instance> { impl<'d, T: Instance> Dac<'d, T> { pub fn new( - peri: impl Unborrow + 'd, + _peri: impl Unborrow + 'd, ch1: impl Unborrow>, ch2: impl Unborrow>, ) -> Self { - unborrow!(peri); unborrow!(ch1, ch2); let ch1 = ch1.degrade_optional(); @@ -110,13 +109,11 @@ impl<'d, T: Instance> Dac<'d, T> { } } - let mut dac = Self { + Self { ch1, ch2, phantom: PhantomData, - }; - - dac + } } pub fn enable_channel(&mut self, ch: Channel) -> Result<(), Error> { @@ -181,7 +178,7 @@ impl<'d, T: Instance> Dac<'d, T> { if self.ch1.is_none() { return Err(Error::UnconfiguredChannel); } - self.disable_channel(Channel::Ch1); + unwrap!(self.disable_channel(Channel::Ch1)); unsafe { T::regs().cr().modify(|reg| { reg.set_tsel1(trigger.tsel()); @@ -194,7 +191,7 @@ impl<'d, T: Instance> Dac<'d, T> { if self.ch2.is_none() { return Err(Error::UnconfiguredChannel); } - self.disable_channel(Channel::Ch2); + unwrap!(self.disable_channel(Channel::Ch2)); unsafe { T::regs().cr().modify(|reg| { reg.set_tsel2(trigger.tsel()); diff --git a/embassy-stm32/src/dma/v2.rs b/embassy-stm32/src/dma/v2.rs index ba13f8d4..5b250546 100644 --- a/embassy-stm32/src/dma/v2.rs +++ b/embassy-stm32/src/dma/v2.rs @@ -35,6 +35,7 @@ impl State { static STATE: State = State::new(); +#[allow(unused)] // Used by usart/v1.rs which may or may not be enabled pub(crate) async unsafe fn transfer_m2p( ch: &mut impl Channel, ch_func: u8, diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs index 0f9414c5..c108a0a8 100644 --- a/embassy-stm32/src/i2c/mod.rs +++ b/embassy-stm32/src/i2c/mod.rs @@ -16,7 +16,6 @@ pub enum Error { } pub(crate) mod sealed { - use super::*; use crate::gpio::Pin; pub trait Instance { diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs index ac971963..91bc37db 100644 --- a/embassy-stm32/src/i2c/v1.rs +++ b/embassy-stm32/src/i2c/v1.rs @@ -1,5 +1,3 @@ -use crate::gpio::AnyPin; -use crate::gpio::Pin; use crate::i2c::{Error, Instance, SclPin, SdaPin}; use crate::time::Hertz; use core::marker::PhantomData; @@ -10,24 +8,18 @@ use embedded_hal::blocking::i2c::Write; use embedded_hal::blocking::i2c::WriteRead; use crate::pac::i2c; -use crate::pac::i2c::I2c as I2cTrait; -use core::cmp; use crate::pac::gpio::vals::{Afr, Moder, Ot}; use crate::pac::gpio::Gpio; -use core::ops::Deref; pub struct I2c<'d, T: Instance> { - //peri: T, - scl: AnyPin, - sda: AnyPin, phantom: PhantomData<&'d mut T>, } impl<'d, T: Instance> I2c<'d, T> { pub fn new( pclk: Hertz, - peri: impl Unborrow + 'd, + _peri: impl Unborrow + 'd, scl: impl Unborrow>, sda: impl Unborrow>, freq: F, @@ -35,7 +27,6 @@ impl<'d, T: Instance> I2c<'d, T> { where F: Into, { - unborrow!(peri); unborrow!(scl, sda); unsafe { @@ -66,9 +57,6 @@ impl<'d, T: Instance> I2c<'d, T> { }); } - let scl = scl.degrade(); - let sda = sda.degrade(); - unsafe { T::regs().cr1().modify(|reg| { reg.set_pe(true); @@ -76,8 +64,6 @@ impl<'d, T: Instance> I2c<'d, T> { } Self { - scl, - sda, phantom: PhantomData, } } @@ -261,7 +247,7 @@ impl<'d, T: Instance> Read for I2c<'d, T> { *last = unsafe { self.recv_byte()? }; // Wait for the STOP to be sent. - while { unsafe { T::regs().cr1().read().stop() == i2c::vals::Stop::STOP } } {} + while unsafe { T::regs().cr1().read().stop() == i2c::vals::Stop::STOP } {} // Fallthrough is success Ok(()) @@ -282,7 +268,7 @@ impl<'d, T: Instance> Write for I2c<'d, T> { .cr1() .modify(|reg| reg.set_stop(i2c::vals::Stop::STOP)); // Wait for STOP condition to transmit. - while { unsafe { T::regs().cr1().read().stop() == i2c::vals::Stop::STOP } } {} + while T::regs().cr1().read().stop() == i2c::vals::Stop::STOP {} }; // Fallthrough is success diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs index 80d8fc0c..03ad29f1 100644 --- a/embassy-stm32/src/i2c/v2.rs +++ b/embassy-stm32/src/i2c/v2.rs @@ -6,26 +6,20 @@ use embedded_hal::blocking::i2c::Read; use embedded_hal::blocking::i2c::Write; use embedded_hal::blocking::i2c::WriteRead; -use crate::gpio::AnyPin; -use crate::gpio::Pin; use crate::i2c::{Error, Instance, SclPin, SdaPin}; use crate::pac::gpio::vals::{Afr, Moder, Ot}; use crate::pac::gpio::Gpio; use crate::pac::i2c; -use crate::pac::i2c::I2c as I2cTrait; use crate::time::Hertz; pub struct I2c<'d, T: Instance> { - //peri: T, - scl: AnyPin, - sda: AnyPin, phantom: PhantomData<&'d mut T>, } impl<'d, T: Instance> I2c<'d, T> { pub fn new( pclk: Hertz, - peri: impl Unborrow + 'd, + _peri: impl Unborrow + 'd, scl: impl Unborrow>, sda: impl Unborrow>, freq: F, @@ -33,7 +27,6 @@ impl<'d, T: Instance> I2c<'d, T> { where F: Into, { - unborrow!(peri); unborrow!(scl, sda); unsafe { @@ -60,9 +53,6 @@ impl<'d, T: Instance> I2c<'d, T> { }); } - let scl = scl.degrade(); - let sda = sda.degrade(); - unsafe { T::regs().cr1().modify(|reg| { reg.set_pe(true); @@ -70,8 +60,6 @@ impl<'d, T: Instance> I2c<'d, T> { } Self { - scl, - sda, phantom: PhantomData, } } @@ -110,7 +98,7 @@ impl<'d, T: Instance> I2c<'d, T> { w.set_rd_wrn(i2c::vals::RdWrn::READ); w.set_nbytes(length as u8); w.set_start(i2c::vals::Start::START); - w.set_autoend(i2c::vals::Autoend::AUTOMATIC); + w.set_autoend(stop.autoend()); }); } } diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs index 1c10ab1b..46fe817e 100644 --- a/embassy-stm32/src/spi/v2.rs +++ b/embassy-stm32/src/spi/v2.rs @@ -29,7 +29,6 @@ impl WordSize { } pub struct Spi<'d, T: Instance> { - //peri: T, sck: AnyPin, mosi: AnyPin, miso: AnyPin, @@ -39,7 +38,7 @@ pub struct Spi<'d, T: Instance> { impl<'d, T: Instance> Spi<'d, T> { pub fn new( pclk: Hertz, - peri: impl Unborrow + 'd, + _peri: impl Unborrow + 'd, sck: impl Unborrow>, mosi: impl Unborrow>, miso: impl Unborrow>, @@ -49,7 +48,6 @@ impl<'d, T: Instance> Spi<'d, T> { where F: Into, { - unborrow!(peri); unborrow!(sck, mosi, miso); unsafe { @@ -95,7 +93,6 @@ impl<'d, T: Instance> Spi<'d, T> { } Self { - //peri, sck, mosi, miso, diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs index c3f66430..da4686b9 100644 --- a/embassy-stm32/src/spi/v3.rs +++ b/embassy-stm32/src/spi/v3.rs @@ -20,7 +20,7 @@ impl WordSize { } } - fn frxth(&self) -> spi::vals::Fthlv { + fn _frxth(&self) -> spi::vals::Fthlv { match self { WordSize::EightBit => spi::vals::Fthlv::ONEFRAME, WordSize::SixteenBit => spi::vals::Fthlv::ONEFRAME, @@ -29,7 +29,6 @@ impl WordSize { } pub struct Spi<'d, T: Instance> { - //peri: T, sck: AnyPin, mosi: AnyPin, miso: AnyPin, @@ -39,7 +38,7 @@ pub struct Spi<'d, T: Instance> { impl<'d, T: Instance> Spi<'d, T> { pub fn new( pclk: Hertz, - peri: impl Unborrow + 'd, + _peri: impl Unborrow + 'd, sck: impl Unborrow>, mosi: impl Unborrow>, miso: impl Unborrow>, @@ -49,7 +48,6 @@ impl<'d, T: Instance> Spi<'d, T> { where F: Into, { - unborrow!(peri); unborrow!(sck, mosi, miso); unsafe { @@ -110,7 +108,6 @@ impl<'d, T: Instance> Spi<'d, T> { } Self { - //peri, sck, mosi, miso, @@ -218,7 +215,7 @@ impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer for Spi<'d, T> { Self::set_word_size(WordSize::EightBit); let regs = T::regs(); - for (i, word) in words.iter_mut().enumerate() { + for word in words.iter_mut() { unsafe { regs.cr1().modify(|reg| { reg.set_ssi(false); diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 2c16af5f..8625f83b 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml @@ -28,8 +28,8 @@ defmt-rtt = "0.2.0" cortex-m = "0.7.1" cortex-m-rt = "0.6.14" -embedded-hal = { version = "0.2.4" } +embedded-hal = { version = "0.2.4" } panic-probe = { version = "0.2.0", features= ["print-defmt"] } futures = { version = "0.3.8", default-features = false, features = ["async-await"] } rtt-target = { version = "0.3", features = ["cortex-m"] } -heapless = { version = "0.7.1", default-features = false } \ No newline at end of file +heapless = { version = "0.7.1", default-features = false }