mirror of
				https://github.com/embassy-rs/embassy.git
				synced 2025-11-04 06:45:35 +00:00 
			
		
		
		
	Merge pull request #225 from rukai/fix_stm32_warnings2
Fix stm32 warnings
This commit is contained in:
		
						commit
						2bbde6c4e1
					
				@ -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;
 | 
			
		||||
 | 
			
		||||
@ -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<AnyPin>,
 | 
			
		||||
    ch2: Option<AnyPin>,
 | 
			
		||||
    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<Target = T> + 'd,
 | 
			
		||||
        _peri: impl Unborrow<Target = T> + 'd,
 | 
			
		||||
        ch1: impl Unborrow<Target = impl DacPin<T, 1>>,
 | 
			
		||||
        ch2: impl Unborrow<Target = impl DacPin<T, 2>>,
 | 
			
		||||
    ) -> 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());
 | 
			
		||||
 | 
			
		||||
@ -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,
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,6 @@ pub enum Error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub(crate) mod sealed {
 | 
			
		||||
    use super::*;
 | 
			
		||||
    use crate::gpio::Pin;
 | 
			
		||||
 | 
			
		||||
    pub trait Instance {
 | 
			
		||||
 | 
			
		||||
@ -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<F>(
 | 
			
		||||
        pclk: Hertz,
 | 
			
		||||
        peri: impl Unborrow<Target = T> + 'd,
 | 
			
		||||
        _peri: impl Unborrow<Target = T> + 'd,
 | 
			
		||||
        scl: impl Unborrow<Target = impl SclPin<T>>,
 | 
			
		||||
        sda: impl Unborrow<Target = impl SdaPin<T>>,
 | 
			
		||||
        freq: F,
 | 
			
		||||
@ -35,7 +27,6 @@ impl<'d, T: Instance> I2c<'d, T> {
 | 
			
		||||
    where
 | 
			
		||||
        F: Into<Hertz>,
 | 
			
		||||
    {
 | 
			
		||||
        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
 | 
			
		||||
 | 
			
		||||
@ -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<F>(
 | 
			
		||||
        pclk: Hertz,
 | 
			
		||||
        peri: impl Unborrow<Target = T> + 'd,
 | 
			
		||||
        _peri: impl Unborrow<Target = T> + 'd,
 | 
			
		||||
        scl: impl Unborrow<Target = impl SclPin<T>>,
 | 
			
		||||
        sda: impl Unborrow<Target = impl SdaPin<T>>,
 | 
			
		||||
        freq: F,
 | 
			
		||||
@ -33,7 +27,6 @@ impl<'d, T: Instance> I2c<'d, T> {
 | 
			
		||||
    where
 | 
			
		||||
        F: Into<Hertz>,
 | 
			
		||||
    {
 | 
			
		||||
        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());
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -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<F>(
 | 
			
		||||
        pclk: Hertz,
 | 
			
		||||
        peri: impl Unborrow<Target = T> + 'd,
 | 
			
		||||
        _peri: impl Unborrow<Target = T> + 'd,
 | 
			
		||||
        sck: impl Unborrow<Target = impl SckPin<T>>,
 | 
			
		||||
        mosi: impl Unborrow<Target = impl MosiPin<T>>,
 | 
			
		||||
        miso: impl Unborrow<Target = impl MisoPin<T>>,
 | 
			
		||||
@ -49,7 +48,6 @@ impl<'d, T: Instance> Spi<'d, T> {
 | 
			
		||||
    where
 | 
			
		||||
        F: Into<Hertz>,
 | 
			
		||||
    {
 | 
			
		||||
        unborrow!(peri);
 | 
			
		||||
        unborrow!(sck, mosi, miso);
 | 
			
		||||
 | 
			
		||||
        unsafe {
 | 
			
		||||
@ -95,7 +93,6 @@ impl<'d, T: Instance> Spi<'d, T> {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Self {
 | 
			
		||||
            //peri,
 | 
			
		||||
            sck,
 | 
			
		||||
            mosi,
 | 
			
		||||
            miso,
 | 
			
		||||
 | 
			
		||||
@ -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<F>(
 | 
			
		||||
        pclk: Hertz,
 | 
			
		||||
        peri: impl Unborrow<Target = T> + 'd,
 | 
			
		||||
        _peri: impl Unborrow<Target = T> + 'd,
 | 
			
		||||
        sck: impl Unborrow<Target = impl SckPin<T>>,
 | 
			
		||||
        mosi: impl Unborrow<Target = impl MosiPin<T>>,
 | 
			
		||||
        miso: impl Unborrow<Target = impl MisoPin<T>>,
 | 
			
		||||
@ -49,7 +48,6 @@ impl<'d, T: Instance> Spi<'d, T> {
 | 
			
		||||
    where
 | 
			
		||||
        F: Into<Hertz>,
 | 
			
		||||
    {
 | 
			
		||||
        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<u8> 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);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user