aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-07-23 13:15:17 +0000
committerGitHub <[email protected]>2022-07-23 13:15:17 +0000
commite61e36a8158073ec92df1a751cfdd7fce5004cf8 (patch)
tree4a54aee47c0d3881b9e0bc809e075728cee8eeae /examples
parent96f67671677d8bf7175f98e87c98954dc728286c (diff)
parent709df0dc1dfff577fb79bbc2f67ea84670072456 (diff)
Merge #842
842: WIP: Make unborrow safe to use r=Dirbaio a=GrantM11235 The basic idea is that `Unborrow::unborrow` is now safe to call and returns an `Unborrowed<'a, T>` which impls `Deref` and `DerefMut` ```rust /// This is essentially a `&mut T`, but it is the size of `T` not the size /// of a pointer. This is useful if T is a zero sized type. pub struct Unborrowed<'a, T> { inner: T, _lifetime: PhantomData<&'a mut T>, } ``` ## Todo - [x] Update other crates - [x] embassy-cortex-m - [x] embassy-hal-common - [x] embassy-lora - [x] embassy-nrf - [x] embassy-rp - [x] embassy-stm32 - [x] Remove usage of the unsafe `into_inner` method if possible - [x] Review and amend docs for `Unborrow` and `Unborrowed` Co-authored-by: Grant Miller <[email protected]> Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32f4/src/bin/sdmmc.rs11
-rw-r--r--examples/stm32f7/src/bin/sdmmc.rs11
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs24
-rw-r--r--examples/stm32h7/src/bin/sdmmc.rs9
4 files changed, 32 insertions, 23 deletions
diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs
index 665670261..752ad57bf 100644
--- a/examples/stm32f4/src/bin/sdmmc.rs
+++ b/examples/stm32f4/src/bin/sdmmc.rs
@@ -21,12 +21,17 @@ async fn main(_spawner: Spawner, p: Peripherals) -> ! {
21 21
22 let irq = interrupt::take!(SDIO); 22 let irq = interrupt::take!(SDIO);
23 23
24 let mut sdmmc = Sdmmc::new( 24 let mut sdmmc = Sdmmc::new_4bit(
25 p.SDIO, 25 p.SDIO,
26 (p.PC12, p.PD2, p.PC8, p.PC9, p.PC10, p.PC11),
27 irq, 26 irq,
28 Default::default(),
29 p.DMA2_CH3, 27 p.DMA2_CH3,
28 p.PC12,
29 p.PD2,
30 p.PC8,
31 p.PC9,
32 p.PC10,
33 p.PC11,
34 Default::default(),
30 ); 35 );
31 36
32 // Should print 400kHz for initialization 37 // Should print 400kHz for initialization
diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs
index 011e1fd95..be1c2b152 100644
--- a/examples/stm32f7/src/bin/sdmmc.rs
+++ b/examples/stm32f7/src/bin/sdmmc.rs
@@ -21,12 +21,17 @@ async fn main(_spawner: Spawner, p: Peripherals) -> ! {
21 21
22 let irq = interrupt::take!(SDMMC1); 22 let irq = interrupt::take!(SDMMC1);
23 23
24 let mut sdmmc = Sdmmc::new( 24 let mut sdmmc = Sdmmc::new_4bit(
25 p.SDMMC1, 25 p.SDMMC1,
26 (p.PC12, p.PD2, p.PC8, p.PC9, p.PC10, p.PC11),
27 irq, 26 irq,
28 Default::default(),
29 p.DMA2_CH3, 27 p.DMA2_CH3,
28 p.PC12,
29 p.PD2,
30 p.PC8,
31 p.PC9,
32 p.PC10,
33 p.PC11,
34 Default::default(),
30 ); 35 );
31 36
32 // Should print 400kHz for initialization 37 // Should print 400kHz for initialization
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index fc19d84e4..d7c6da5bd 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -2,8 +2,6 @@
2#![no_main] 2#![no_main]
3#![feature(type_alias_impl_trait)] 3#![feature(type_alias_impl_trait)]
4 4
5use core::marker::PhantomData;
6
7use defmt::*; 5use defmt::*;
8use embassy::executor::Spawner; 6use embassy::executor::Spawner;
9use embassy::time::{Duration, Timer}; 7use embassy::time::{Duration, Timer};
@@ -11,7 +9,7 @@ use embassy_stm32::gpio::low_level::AFType;
11use embassy_stm32::gpio::Speed; 9use embassy_stm32::gpio::Speed;
12use embassy_stm32::pwm::*; 10use embassy_stm32::pwm::*;
13use embassy_stm32::time::{khz, mhz, Hertz}; 11use embassy_stm32::time::{khz, mhz, Hertz};
14use embassy_stm32::{unborrow, Config, Peripherals, Unborrow}; 12use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef, Peripherals};
15use {defmt_rtt as _, panic_probe as _}; 13use {defmt_rtt as _, panic_probe as _};
16 14
17pub fn config() -> Config { 15pub fn config() -> Config {
@@ -49,20 +47,19 @@ async fn main(_spawner: Spawner, p: Peripherals) {
49 } 47 }
50} 48}
51pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> { 49pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> {
52 phantom: PhantomData<&'d mut T>, 50 inner: PeripheralRef<'d, T>,
53 inner: T,
54} 51}
55 52
56impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { 53impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
57 pub fn new( 54 pub fn new(
58 tim: impl Unborrow<Target = T> + 'd, 55 tim: impl Peripheral<P = T> + 'd,
59 ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, 56 ch1: impl Peripheral<P = impl Channel1Pin<T>> + 'd,
60 ch2: impl Unborrow<Target = impl Channel2Pin<T>> + 'd, 57 ch2: impl Peripheral<P = impl Channel2Pin<T>> + 'd,
61 ch3: impl Unborrow<Target = impl Channel3Pin<T>> + 'd, 58 ch3: impl Peripheral<P = impl Channel3Pin<T>> + 'd,
62 ch4: impl Unborrow<Target = impl Channel4Pin<T>> + 'd, 59 ch4: impl Peripheral<P = impl Channel4Pin<T>> + 'd,
63 freq: Hertz, 60 freq: Hertz,
64 ) -> Self { 61 ) -> Self {
65 unborrow!(tim, ch1, ch2, ch3, ch4); 62 into_ref!(tim, ch1, ch2, ch3, ch4);
66 63
67 T::enable(); 64 T::enable();
68 <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); 65 <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset();
@@ -78,10 +75,7 @@ impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> {
78 ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); 75 ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull);
79 } 76 }
80 77
81 let mut this = Self { 78 let mut this = Self { inner: tim };
82 inner: tim,
83 phantom: PhantomData,
84 };
85 79
86 this.set_freq(freq); 80 this.set_freq(freq);
87 this.inner.start(); 81 this.inner.start();
diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs
index 787f700ae..163807d86 100644
--- a/examples/stm32h7/src/bin/sdmmc.rs
+++ b/examples/stm32h7/src/bin/sdmmc.rs
@@ -21,10 +21,15 @@ async fn main(_spawner: Spawner, p: Peripherals) -> ! {
21 21
22 let irq = interrupt::take!(SDMMC1); 22 let irq = interrupt::take!(SDMMC1);
23 23
24 let mut sdmmc = Sdmmc::new( 24 let mut sdmmc = Sdmmc::new_4bit(
25 p.SDMMC1, 25 p.SDMMC1,
26 (p.PC12, p.PD2, p.PC8, p.PC9, p.PC10, p.PC11),
27 irq, 26 irq,
27 p.PC12,
28 p.PD2,
29 p.PC8,
30 p.PC9,
31 p.PC10,
32 p.PC11,
28 Default::default(), 33 Default::default(),
29 ); 34 );
30 35