diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-02-11 23:11:12 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-11 23:11:12 +0000 |
| commit | 5ae4e20f8654bdc129d152b5364b6864457c2e02 (patch) | |
| tree | 684ad8ac522778cbb0322decab3806c5b1eb7fd0 /examples | |
| parent | 621a280042c76786a7832382a6fe8b78acac6d34 (diff) | |
| parent | b99ab3d5d9d8fdee135956dcbc2111b00abd1d72 (diff) | |
Merge #607
607: stm32: Add standard crate-wide macros for pin/dma traits r=Dirbaio a=Dirbaio
All drivers will declare the traits using these macros.
This has a few implications:
- ALL drivers will have an Instance trait, even for drivers that usually have only one instance (for example crc, eth)
- It's no longer possible to have a fn configure() in pin traits, drivers will have to do that some other way
In the future, build.rs will generate all the impls instead of macrotables.
Pin/Dma traits are no longer explicitly sealed, since gpio::Pin and dma::Channel are already sealed, which has the same effect. This means the `af_num()` and `request()` funcs are now public, but IMO that's okay, they're unlikely to change.
Co-authored-by: Dario Nieuwenhuis <[email protected]>
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f7/src/bin/eth.rs | 7 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/eth.rs | 7 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/low_level_timer_api.rs | 21 |
3 files changed, 21 insertions, 14 deletions
diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index 521b031e3..15169d2dc 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #[path = "../example_common.rs"] | 5 | #[path = "../example_common.rs"] |
| 6 | mod example_common; | 6 | mod example_common; |
| 7 | use embassy_stm32::peripherals::ETH; | ||
| 7 | use example_common::config; | 8 | use example_common::config; |
| 8 | 9 | ||
| 9 | use cortex_m_rt::entry; | 10 | use cortex_m_rt::entry; |
| @@ -27,7 +28,7 @@ use peripherals::RNG; | |||
| 27 | 28 | ||
| 28 | #[embassy::task] | 29 | #[embassy::task] |
| 29 | async fn main_task( | 30 | async fn main_task( |
| 30 | device: &'static mut Ethernet<'static, LAN8742A, 4, 4>, | 31 | device: &'static mut Ethernet<'static, ETH, LAN8742A, 4, 4>, |
| 31 | config: &'static mut StaticConfigurator, | 32 | config: &'static mut StaticConfigurator, |
| 32 | spawner: Spawner, | 33 | spawner: Spawner, |
| 33 | ) { | 34 | ) { |
| @@ -82,8 +83,8 @@ fn _embassy_rand(buf: &mut [u8]) { | |||
| 82 | static mut RNG_INST: Option<Rng<RNG>> = None; | 83 | static mut RNG_INST: Option<Rng<RNG>> = None; |
| 83 | 84 | ||
| 84 | static EXECUTOR: Forever<Executor> = Forever::new(); | 85 | static EXECUTOR: Forever<Executor> = Forever::new(); |
| 85 | static STATE: Forever<State<'static, 4, 4>> = Forever::new(); | 86 | static STATE: Forever<State<'static, ETH, 4, 4>> = Forever::new(); |
| 86 | static ETH: Forever<Ethernet<'static, LAN8742A, 4, 4>> = Forever::new(); | 87 | static ETH: Forever<Ethernet<'static, ETH, LAN8742A, 4, 4>> = Forever::new(); |
| 87 | static CONFIG: Forever<StaticConfigurator> = Forever::new(); | 88 | static CONFIG: Forever<StaticConfigurator> = Forever::new(); |
| 88 | static NET_RESOURCES: Forever<StackResources<1, 2, 8>> = Forever::new(); | 89 | static NET_RESOURCES: Forever<StackResources<1, 2, 8>> = Forever::new(); |
| 89 | 90 | ||
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 9998bc4e9..47d8c5c56 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #[path = "../example_common.rs"] | 5 | #[path = "../example_common.rs"] |
| 6 | mod example_common; | 6 | mod example_common; |
| 7 | use embassy_stm32::peripherals::ETH; | ||
| 7 | use example_common::config; | 8 | use example_common::config; |
| 8 | 9 | ||
| 9 | use cortex_m_rt::entry; | 10 | use cortex_m_rt::entry; |
| @@ -26,7 +27,7 @@ use peripherals::RNG; | |||
| 26 | 27 | ||
| 27 | #[embassy::task] | 28 | #[embassy::task] |
| 28 | async fn main_task( | 29 | async fn main_task( |
| 29 | device: &'static mut Ethernet<'static, LAN8742A, 4, 4>, | 30 | device: &'static mut Ethernet<'static, ETH, LAN8742A, 4, 4>, |
| 30 | config: &'static mut StaticConfigurator, | 31 | config: &'static mut StaticConfigurator, |
| 31 | spawner: Spawner, | 32 | spawner: Spawner, |
| 32 | ) { | 33 | ) { |
| @@ -81,8 +82,8 @@ fn _embassy_rand(buf: &mut [u8]) { | |||
| 81 | static mut RNG_INST: Option<Rng<RNG>> = None; | 82 | static mut RNG_INST: Option<Rng<RNG>> = None; |
| 82 | 83 | ||
| 83 | static EXECUTOR: Forever<Executor> = Forever::new(); | 84 | static EXECUTOR: Forever<Executor> = Forever::new(); |
| 84 | static STATE: Forever<State<'static, 4, 4>> = Forever::new(); | 85 | static STATE: Forever<State<'static, ETH, 4, 4>> = Forever::new(); |
| 85 | static ETH: Forever<Ethernet<'static, LAN8742A, 4, 4>> = Forever::new(); | 86 | static ETH: Forever<Ethernet<'static, ETH, LAN8742A, 4, 4>> = Forever::new(); |
| 86 | static CONFIG: Forever<StaticConfigurator> = Forever::new(); | 87 | static CONFIG: Forever<StaticConfigurator> = Forever::new(); |
| 87 | static NET_RESOURCES: Forever<StackResources<1, 2, 8>> = Forever::new(); | 88 | static NET_RESOURCES: Forever<StackResources<1, 2, 8>> = Forever::new(); |
| 88 | 89 | ||
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index 1bf69104d..0c99b0941 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs | |||
| @@ -10,9 +10,10 @@ use embassy::executor::Spawner; | |||
| 10 | use embassy::time::{Duration, Timer}; | 10 | use embassy::time::{Duration, Timer}; |
| 11 | use embassy::util::Unborrow; | 11 | use embassy::util::Unborrow; |
| 12 | use embassy_hal_common::unborrow; | 12 | use embassy_hal_common::unborrow; |
| 13 | use embassy_stm32::pwm::{pins::*, Channel, OutputCompareMode}; | 13 | use embassy_stm32::gpio::low_level::AFType; |
| 14 | use embassy_stm32::gpio::Speed; | ||
| 15 | use embassy_stm32::pwm::*; | ||
| 14 | use embassy_stm32::time::{Hertz, U32Ext}; | 16 | use embassy_stm32::time::{Hertz, U32Ext}; |
| 15 | use embassy_stm32::timer::GeneralPurpose32bitInstance; | ||
| 16 | use embassy_stm32::{Config, Peripherals}; | 17 | use embassy_stm32::{Config, Peripherals}; |
| 17 | use example_common::*; | 18 | use example_common::*; |
| 18 | 19 | ||
| @@ -50,12 +51,12 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 50 | Timer::after(Duration::from_millis(300)).await; | 51 | Timer::after(Duration::from_millis(300)).await; |
| 51 | } | 52 | } |
| 52 | } | 53 | } |
| 53 | pub struct SimplePwm32<'d, T: GeneralPurpose32bitInstance> { | 54 | pub struct SimplePwm32<'d, T: CaptureCompare32bitInstance> { |
| 54 | phantom: PhantomData<&'d mut T>, | 55 | phantom: PhantomData<&'d mut T>, |
| 55 | inner: T, | 56 | inner: T, |
| 56 | } | 57 | } |
| 57 | 58 | ||
| 58 | impl<'d, T: GeneralPurpose32bitInstance> SimplePwm32<'d, T> { | 59 | impl<'d, T: CaptureCompare32bitInstance> SimplePwm32<'d, T> { |
| 59 | pub fn new<F: Into<Hertz>>( | 60 | pub fn new<F: Into<Hertz>>( |
| 60 | tim: impl Unborrow<Target = T> + 'd, | 61 | tim: impl Unborrow<Target = T> + 'd, |
| 61 | ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, | 62 | ch1: impl Unborrow<Target = impl Channel1Pin<T>> + 'd, |
| @@ -70,10 +71,14 @@ impl<'d, T: GeneralPurpose32bitInstance> SimplePwm32<'d, T> { | |||
| 70 | <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); | 71 | <T as embassy_stm32::rcc::low_level::RccPeripheral>::reset(); |
| 71 | 72 | ||
| 72 | unsafe { | 73 | unsafe { |
| 73 | ch1.configure(); | 74 | ch1.set_speed(Speed::VeryHigh); |
| 74 | ch2.configure(); | 75 | ch1.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 75 | ch3.configure(); | 76 | ch2.set_speed(Speed::VeryHigh); |
| 76 | ch4.configure(); | 77 | ch2.set_as_af(ch1.af_num(), AFType::OutputPushPull); |
| 78 | ch3.set_speed(Speed::VeryHigh); | ||
| 79 | ch3.set_as_af(ch1.af_num(), AFType::OutputPushPull); | ||
| 80 | ch4.set_speed(Speed::VeryHigh); | ||
| 81 | ch4.set_as_af(ch1.af_num(), AFType::OutputPushPull); | ||
| 77 | } | 82 | } |
| 78 | 83 | ||
| 79 | let mut this = Self { | 84 | let mut this = Self { |
