aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRukai <[email protected]>2021-06-05 18:15:35 +1000
committerRukai <[email protected]>2021-06-06 00:46:20 +1000
commit010b2b9497ecab40279cb751a1f5cbff4df5d163 (patch)
treea64a1942a78c458ed7335fd929e3bb24d1e21e84
parent6f5c85c50f20fa336d2144c8161aea391bea52f7 (diff)
Fix stm32 warnings
-rw-r--r--embassy-stm32/src/dac/mod.rs3
-rw-r--r--embassy-stm32/src/dac/v2.rs19
-rw-r--r--embassy-stm32/src/dma/v2.rs1
-rw-r--r--embassy-stm32/src/i2c/mod.rs1
-rw-r--r--embassy-stm32/src/i2c/v1.rs20
-rw-r--r--embassy-stm32/src/i2c/v2.rs16
-rw-r--r--embassy-stm32/src/spi/v2.rs5
-rw-r--r--embassy-stm32/src/spi/v3.rs9
-rw-r--r--examples/stm32f4/Cargo.toml4
9 files changed, 21 insertions, 57 deletions
diff --git a/embassy-stm32/src/dac/mod.rs b/embassy-stm32/src/dac/mod.rs
index 46c485b35..0a15563ef 100644
--- a/embassy-stm32/src/dac/mod.rs
+++ b/embassy-stm32/src/dac/mod.rs
@@ -7,8 +7,7 @@ use crate::peripherals;
7pub use _version::*; 7pub use _version::*;
8 8
9pub(crate) mod sealed { 9pub(crate) mod sealed {
10 use super::*; 10 use crate::gpio::OptionalPin;
11 use crate::gpio::{OptionalPin, Pin};
12 11
13 pub trait Instance { 12 pub trait Instance {
14 fn regs() -> &'static crate::pac::dac::Dac; 13 fn regs() -> &'static crate::pac::dac::Dac;
diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs
index 18ac0f86a..a7aad04f0 100644
--- a/embassy-stm32/src/dac/v2.rs
+++ b/embassy-stm32/src/dac/v2.rs
@@ -1,11 +1,12 @@
1use crate::dac::{DacPin, Instance}; 1use crate::dac::{DacPin, Instance};
2use crate::gpio::Pin; 2use crate::fmt::*;
3use crate::gpio::{AnyPin, OptionalPin}; 3use crate::gpio::AnyPin;
4use crate::pac::dac; 4use crate::pac::dac;
5use core::marker::PhantomData; 5use core::marker::PhantomData;
6use embassy::util::Unborrow; 6use embassy::util::Unborrow;
7use embassy_extras::unborrow; 7use embassy_extras::unborrow;
8 8
9#[derive(Debug, defmt::Format)]
9pub enum Error { 10pub enum Error {
10 UnconfiguredChannel, 11 UnconfiguredChannel,
11 InvalidValue, 12 InvalidValue,
@@ -77,7 +78,6 @@ pub enum Value {
77} 78}
78 79
79pub struct Dac<'d, T: Instance> { 80pub struct Dac<'d, T: Instance> {
80 //peri: T,
81 ch1: Option<AnyPin>, 81 ch1: Option<AnyPin>,
82 ch2: Option<AnyPin>, 82 ch2: Option<AnyPin>,
83 phantom: PhantomData<&'d mut T>, 83 phantom: PhantomData<&'d mut T>,
@@ -85,11 +85,10 @@ pub struct Dac<'d, T: Instance> {
85 85
86impl<'d, T: Instance> Dac<'d, T> { 86impl<'d, T: Instance> Dac<'d, T> {
87 pub fn new( 87 pub fn new(
88 peri: impl Unborrow<Target = T> + 'd, 88 _peri: impl Unborrow<Target = T> + 'd,
89 ch1: impl Unborrow<Target = impl DacPin<T, 1>>, 89 ch1: impl Unborrow<Target = impl DacPin<T, 1>>,
90 ch2: impl Unborrow<Target = impl DacPin<T, 2>>, 90 ch2: impl Unborrow<Target = impl DacPin<T, 2>>,
91 ) -> Self { 91 ) -> Self {
92 unborrow!(peri);
93 unborrow!(ch1, ch2); 92 unborrow!(ch1, ch2);
94 93
95 let ch1 = ch1.degrade_optional(); 94 let ch1 = ch1.degrade_optional();
@@ -110,13 +109,11 @@ impl<'d, T: Instance> Dac<'d, T> {
110 } 109 }
111 } 110 }
112 111
113 let mut dac = Self { 112 Self {
114 ch1, 113 ch1,
115 ch2, 114 ch2,
116 phantom: PhantomData, 115 phantom: PhantomData,
117 }; 116 }
118
119 dac
120 } 117 }
121 118
122 pub fn enable_channel(&mut self, ch: Channel) -> Result<(), Error> { 119 pub fn enable_channel(&mut self, ch: Channel) -> Result<(), Error> {
@@ -181,7 +178,7 @@ impl<'d, T: Instance> Dac<'d, T> {
181 if self.ch1.is_none() { 178 if self.ch1.is_none() {
182 return Err(Error::UnconfiguredChannel); 179 return Err(Error::UnconfiguredChannel);
183 } 180 }
184 self.disable_channel(Channel::Ch1); 181 unwrap!(self.disable_channel(Channel::Ch1));
185 unsafe { 182 unsafe {
186 T::regs().cr().modify(|reg| { 183 T::regs().cr().modify(|reg| {
187 reg.set_tsel1(trigger.tsel()); 184 reg.set_tsel1(trigger.tsel());
@@ -194,7 +191,7 @@ impl<'d, T: Instance> Dac<'d, T> {
194 if self.ch2.is_none() { 191 if self.ch2.is_none() {
195 return Err(Error::UnconfiguredChannel); 192 return Err(Error::UnconfiguredChannel);
196 } 193 }
197 self.disable_channel(Channel::Ch2); 194 unwrap!(self.disable_channel(Channel::Ch2));
198 unsafe { 195 unsafe {
199 T::regs().cr().modify(|reg| { 196 T::regs().cr().modify(|reg| {
200 reg.set_tsel2(trigger.tsel()); 197 reg.set_tsel2(trigger.tsel());
diff --git a/embassy-stm32/src/dma/v2.rs b/embassy-stm32/src/dma/v2.rs
index ba13f8d4c..5b2505463 100644
--- a/embassy-stm32/src/dma/v2.rs
+++ b/embassy-stm32/src/dma/v2.rs
@@ -35,6 +35,7 @@ impl State {
35 35
36static STATE: State = State::new(); 36static STATE: State = State::new();
37 37
38#[allow(unused)] // Used by usart/v1.rs which may or may not be enabled
38pub(crate) async unsafe fn transfer_m2p( 39pub(crate) async unsafe fn transfer_m2p(
39 ch: &mut impl Channel, 40 ch: &mut impl Channel,
40 ch_func: u8, 41 ch_func: u8,
diff --git a/embassy-stm32/src/i2c/mod.rs b/embassy-stm32/src/i2c/mod.rs
index 0f9414c53..c108a0a87 100644
--- a/embassy-stm32/src/i2c/mod.rs
+++ b/embassy-stm32/src/i2c/mod.rs
@@ -16,7 +16,6 @@ pub enum Error {
16} 16}
17 17
18pub(crate) mod sealed { 18pub(crate) mod sealed {
19 use super::*;
20 use crate::gpio::Pin; 19 use crate::gpio::Pin;
21 20
22 pub trait Instance { 21 pub trait Instance {
diff --git a/embassy-stm32/src/i2c/v1.rs b/embassy-stm32/src/i2c/v1.rs
index ac9719638..91bc37db3 100644
--- a/embassy-stm32/src/i2c/v1.rs
+++ b/embassy-stm32/src/i2c/v1.rs
@@ -1,5 +1,3 @@
1use crate::gpio::AnyPin;
2use crate::gpio::Pin;
3use crate::i2c::{Error, Instance, SclPin, SdaPin}; 1use crate::i2c::{Error, Instance, SclPin, SdaPin};
4use crate::time::Hertz; 2use crate::time::Hertz;
5use core::marker::PhantomData; 3use core::marker::PhantomData;
@@ -10,24 +8,18 @@ use embedded_hal::blocking::i2c::Write;
10use embedded_hal::blocking::i2c::WriteRead; 8use embedded_hal::blocking::i2c::WriteRead;
11 9
12use crate::pac::i2c; 10use crate::pac::i2c;
13use crate::pac::i2c::I2c as I2cTrait;
14use core::cmp;
15 11
16use crate::pac::gpio::vals::{Afr, Moder, Ot}; 12use crate::pac::gpio::vals::{Afr, Moder, Ot};
17use crate::pac::gpio::Gpio; 13use crate::pac::gpio::Gpio;
18use core::ops::Deref;
19 14
20pub struct I2c<'d, T: Instance> { 15pub struct I2c<'d, T: Instance> {
21 //peri: T,
22 scl: AnyPin,
23 sda: AnyPin,
24 phantom: PhantomData<&'d mut T>, 16 phantom: PhantomData<&'d mut T>,
25} 17}
26 18
27impl<'d, T: Instance> I2c<'d, T> { 19impl<'d, T: Instance> I2c<'d, T> {
28 pub fn new<F>( 20 pub fn new<F>(
29 pclk: Hertz, 21 pclk: Hertz,
30 peri: impl Unborrow<Target = T> + 'd, 22 _peri: impl Unborrow<Target = T> + 'd,
31 scl: impl Unborrow<Target = impl SclPin<T>>, 23 scl: impl Unborrow<Target = impl SclPin<T>>,
32 sda: impl Unborrow<Target = impl SdaPin<T>>, 24 sda: impl Unborrow<Target = impl SdaPin<T>>,
33 freq: F, 25 freq: F,
@@ -35,7 +27,6 @@ impl<'d, T: Instance> I2c<'d, T> {
35 where 27 where
36 F: Into<Hertz>, 28 F: Into<Hertz>,
37 { 29 {
38 unborrow!(peri);
39 unborrow!(scl, sda); 30 unborrow!(scl, sda);
40 31
41 unsafe { 32 unsafe {
@@ -66,9 +57,6 @@ impl<'d, T: Instance> I2c<'d, T> {
66 }); 57 });
67 } 58 }
68 59
69 let scl = scl.degrade();
70 let sda = sda.degrade();
71
72 unsafe { 60 unsafe {
73 T::regs().cr1().modify(|reg| { 61 T::regs().cr1().modify(|reg| {
74 reg.set_pe(true); 62 reg.set_pe(true);
@@ -76,8 +64,6 @@ impl<'d, T: Instance> I2c<'d, T> {
76 } 64 }
77 65
78 Self { 66 Self {
79 scl,
80 sda,
81 phantom: PhantomData, 67 phantom: PhantomData,
82 } 68 }
83 } 69 }
@@ -261,7 +247,7 @@ impl<'d, T: Instance> Read for I2c<'d, T> {
261 *last = unsafe { self.recv_byte()? }; 247 *last = unsafe { self.recv_byte()? };
262 248
263 // Wait for the STOP to be sent. 249 // Wait for the STOP to be sent.
264 while { unsafe { T::regs().cr1().read().stop() == i2c::vals::Stop::STOP } } {} 250 while unsafe { T::regs().cr1().read().stop() == i2c::vals::Stop::STOP } {}
265 251
266 // Fallthrough is success 252 // Fallthrough is success
267 Ok(()) 253 Ok(())
@@ -282,7 +268,7 @@ impl<'d, T: Instance> Write for I2c<'d, T> {
282 .cr1() 268 .cr1()
283 .modify(|reg| reg.set_stop(i2c::vals::Stop::STOP)); 269 .modify(|reg| reg.set_stop(i2c::vals::Stop::STOP));
284 // Wait for STOP condition to transmit. 270 // Wait for STOP condition to transmit.
285 while { unsafe { T::regs().cr1().read().stop() == i2c::vals::Stop::STOP } } {} 271 while T::regs().cr1().read().stop() == i2c::vals::Stop::STOP {}
286 }; 272 };
287 273
288 // Fallthrough is success 274 // Fallthrough is success
diff --git a/embassy-stm32/src/i2c/v2.rs b/embassy-stm32/src/i2c/v2.rs
index 80d8fc0c7..03ad29f13 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;
6use embedded_hal::blocking::i2c::Write; 6use embedded_hal::blocking::i2c::Write;
7use embedded_hal::blocking::i2c::WriteRead; 7use embedded_hal::blocking::i2c::WriteRead;
8 8
9use crate::gpio::AnyPin;
10use crate::gpio::Pin;
11use crate::i2c::{Error, Instance, SclPin, SdaPin}; 9use crate::i2c::{Error, Instance, SclPin, SdaPin};
12use crate::pac::gpio::vals::{Afr, Moder, Ot}; 10use crate::pac::gpio::vals::{Afr, Moder, Ot};
13use crate::pac::gpio::Gpio; 11use crate::pac::gpio::Gpio;
14use crate::pac::i2c; 12use crate::pac::i2c;
15use crate::pac::i2c::I2c as I2cTrait;
16use crate::time::Hertz; 13use crate::time::Hertz;
17 14
18pub struct I2c<'d, T: Instance> { 15pub struct I2c<'d, T: Instance> {
19 //peri: T,
20 scl: AnyPin,
21 sda: AnyPin,
22 phantom: PhantomData<&'d mut T>, 16 phantom: PhantomData<&'d mut T>,
23} 17}
24 18
25impl<'d, T: Instance> I2c<'d, T> { 19impl<'d, T: Instance> I2c<'d, T> {
26 pub fn new<F>( 20 pub fn new<F>(
27 pclk: Hertz, 21 pclk: Hertz,
28 peri: impl Unborrow<Target = T> + 'd, 22 _peri: impl Unborrow<Target = T> + 'd,
29 scl: impl Unborrow<Target = impl SclPin<T>>, 23 scl: impl Unborrow<Target = impl SclPin<T>>,
30 sda: impl Unborrow<Target = impl SdaPin<T>>, 24 sda: impl Unborrow<Target = impl SdaPin<T>>,
31 freq: F, 25 freq: F,
@@ -33,7 +27,6 @@ impl<'d, T: Instance> I2c<'d, T> {
33 where 27 where
34 F: Into<Hertz>, 28 F: Into<Hertz>,
35 { 29 {
36 unborrow!(peri);
37 unborrow!(scl, sda); 30 unborrow!(scl, sda);
38 31
39 unsafe { 32 unsafe {
@@ -60,9 +53,6 @@ impl<'d, T: Instance> I2c<'d, T> {
60 }); 53 });
61 } 54 }
62 55
63 let scl = scl.degrade();
64 let sda = sda.degrade();
65
66 unsafe { 56 unsafe {
67 T::regs().cr1().modify(|reg| { 57 T::regs().cr1().modify(|reg| {
68 reg.set_pe(true); 58 reg.set_pe(true);
@@ -70,8 +60,6 @@ impl<'d, T: Instance> I2c<'d, T> {
70 } 60 }
71 61
72 Self { 62 Self {
73 scl,
74 sda,
75 phantom: PhantomData, 63 phantom: PhantomData,
76 } 64 }
77 } 65 }
@@ -110,7 +98,7 @@ impl<'d, T: Instance> I2c<'d, T> {
110 w.set_rd_wrn(i2c::vals::RdWrn::READ); 98 w.set_rd_wrn(i2c::vals::RdWrn::READ);
111 w.set_nbytes(length as u8); 99 w.set_nbytes(length as u8);
112 w.set_start(i2c::vals::Start::START); 100 w.set_start(i2c::vals::Start::START);
113 w.set_autoend(i2c::vals::Autoend::AUTOMATIC); 101 w.set_autoend(stop.autoend());
114 }); 102 });
115 } 103 }
116 } 104 }
diff --git a/embassy-stm32/src/spi/v2.rs b/embassy-stm32/src/spi/v2.rs
index 1c10ab1b5..46fe817ea 100644
--- a/embassy-stm32/src/spi/v2.rs
+++ b/embassy-stm32/src/spi/v2.rs
@@ -29,7 +29,6 @@ impl WordSize {
29} 29}
30 30
31pub struct Spi<'d, T: Instance> { 31pub struct Spi<'d, T: Instance> {
32 //peri: T,
33 sck: AnyPin, 32 sck: AnyPin,
34 mosi: AnyPin, 33 mosi: AnyPin,
35 miso: AnyPin, 34 miso: AnyPin,
@@ -39,7 +38,7 @@ pub struct Spi<'d, T: Instance> {
39impl<'d, T: Instance> Spi<'d, T> { 38impl<'d, T: Instance> Spi<'d, T> {
40 pub fn new<F>( 39 pub fn new<F>(
41 pclk: Hertz, 40 pclk: Hertz,
42 peri: impl Unborrow<Target = T> + 'd, 41 _peri: impl Unborrow<Target = T> + 'd,
43 sck: impl Unborrow<Target = impl SckPin<T>>, 42 sck: impl Unborrow<Target = impl SckPin<T>>,
44 mosi: impl Unborrow<Target = impl MosiPin<T>>, 43 mosi: impl Unborrow<Target = impl MosiPin<T>>,
45 miso: impl Unborrow<Target = impl MisoPin<T>>, 44 miso: impl Unborrow<Target = impl MisoPin<T>>,
@@ -49,7 +48,6 @@ impl<'d, T: Instance> Spi<'d, T> {
49 where 48 where
50 F: Into<Hertz>, 49 F: Into<Hertz>,
51 { 50 {
52 unborrow!(peri);
53 unborrow!(sck, mosi, miso); 51 unborrow!(sck, mosi, miso);
54 52
55 unsafe { 53 unsafe {
@@ -95,7 +93,6 @@ impl<'d, T: Instance> Spi<'d, T> {
95 } 93 }
96 94
97 Self { 95 Self {
98 //peri,
99 sck, 96 sck,
100 mosi, 97 mosi,
101 miso, 98 miso,
diff --git a/embassy-stm32/src/spi/v3.rs b/embassy-stm32/src/spi/v3.rs
index c3f66430c..da4686b9c 100644
--- a/embassy-stm32/src/spi/v3.rs
+++ b/embassy-stm32/src/spi/v3.rs
@@ -20,7 +20,7 @@ impl WordSize {
20 } 20 }
21 } 21 }
22 22
23 fn frxth(&self) -> spi::vals::Fthlv { 23 fn _frxth(&self) -> spi::vals::Fthlv {
24 match self { 24 match self {
25 WordSize::EightBit => spi::vals::Fthlv::ONEFRAME, 25 WordSize::EightBit => spi::vals::Fthlv::ONEFRAME,
26 WordSize::SixteenBit => spi::vals::Fthlv::ONEFRAME, 26 WordSize::SixteenBit => spi::vals::Fthlv::ONEFRAME,
@@ -29,7 +29,6 @@ impl WordSize {
29} 29}
30 30
31pub struct Spi<'d, T: Instance> { 31pub struct Spi<'d, T: Instance> {
32 //peri: T,
33 sck: AnyPin, 32 sck: AnyPin,
34 mosi: AnyPin, 33 mosi: AnyPin,
35 miso: AnyPin, 34 miso: AnyPin,
@@ -39,7 +38,7 @@ pub struct Spi<'d, T: Instance> {
39impl<'d, T: Instance> Spi<'d, T> { 38impl<'d, T: Instance> Spi<'d, T> {
40 pub fn new<F>( 39 pub fn new<F>(
41 pclk: Hertz, 40 pclk: Hertz,
42 peri: impl Unborrow<Target = T> + 'd, 41 _peri: impl Unborrow<Target = T> + 'd,
43 sck: impl Unborrow<Target = impl SckPin<T>>, 42 sck: impl Unborrow<Target = impl SckPin<T>>,
44 mosi: impl Unborrow<Target = impl MosiPin<T>>, 43 mosi: impl Unborrow<Target = impl MosiPin<T>>,
45 miso: impl Unborrow<Target = impl MisoPin<T>>, 44 miso: impl Unborrow<Target = impl MisoPin<T>>,
@@ -49,7 +48,6 @@ impl<'d, T: Instance> Spi<'d, T> {
49 where 48 where
50 F: Into<Hertz>, 49 F: Into<Hertz>,
51 { 50 {
52 unborrow!(peri);
53 unborrow!(sck, mosi, miso); 51 unborrow!(sck, mosi, miso);
54 52
55 unsafe { 53 unsafe {
@@ -110,7 +108,6 @@ impl<'d, T: Instance> Spi<'d, T> {
110 } 108 }
111 109
112 Self { 110 Self {
113 //peri,
114 sck, 111 sck,
115 mosi, 112 mosi,
116 miso, 113 miso,
@@ -218,7 +215,7 @@ impl<'d, T: Instance> embedded_hal::blocking::spi::Transfer<u8> for Spi<'d, T> {
218 Self::set_word_size(WordSize::EightBit); 215 Self::set_word_size(WordSize::EightBit);
219 let regs = T::regs(); 216 let regs = T::regs();
220 217
221 for (i, word) in words.iter_mut().enumerate() { 218 for word in words.iter_mut() {
222 unsafe { 219 unsafe {
223 regs.cr1().modify(|reg| { 220 regs.cr1().modify(|reg| {
224 reg.set_ssi(false); 221 reg.set_ssi(false);
diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml
index 2c16af5fb..8625f83b5 100644
--- a/examples/stm32f4/Cargo.toml
+++ b/examples/stm32f4/Cargo.toml
@@ -28,8 +28,8 @@ defmt-rtt = "0.2.0"
28 28
29cortex-m = "0.7.1" 29cortex-m = "0.7.1"
30cortex-m-rt = "0.6.14" 30cortex-m-rt = "0.6.14"
31embedded-hal = { version = "0.2.4" } 31embedded-hal = { version = "0.2.4" }
32panic-probe = { version = "0.2.0", features= ["print-defmt"] } 32panic-probe = { version = "0.2.0", features= ["print-defmt"] }
33futures = { version = "0.3.8", default-features = false, features = ["async-await"] } 33futures = { version = "0.3.8", default-features = false, features = ["async-await"] }
34rtt-target = { version = "0.3", features = ["cortex-m"] } 34rtt-target = { version = "0.3", features = ["cortex-m"] }
35heapless = { version = "0.7.1", default-features = false } \ No newline at end of file 35heapless = { version = "0.7.1", default-features = false }