aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-02-10 02:34:59 +0100
committerDario Nieuwenhuis <[email protected]>2022-02-10 02:38:10 +0100
commit550da471be7b56927b50b5955a6de0916ebe6b1f (patch)
tree27b37e111dce9a3a5327c901c1bf139b1c1486d0 /examples
parent1d265b73b2f46baf60a481c8b8036e50c2b6583f (diff)
stm32: Remove OptionalPin
The idea behind OptionalPin has a few problems: - you need to impl the signal traits for NoPin which is a bit weird https://github.com/embassy-rs/embassy/blob/master/embassy-stm32/src/dcmi.rs#L413-L416 - you can pass any combination of set/unset pins, which needs checking at runtime https://github.com/embassy-rs/embassy/blob/master/embassy-stm32/src/dcmi.rs#L130 The replacement is to do multiple `new` constructors for each combination of pins you want to take.
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32g4/src/bin/pwm.rs3
-rw-r--r--examples/stm32h7/src/bin/camera.rs33
-rw-r--r--examples/stm32h7/src/bin/dac.rs3
-rw-r--r--examples/stm32h7/src/bin/low_level_timer_api.rs3
-rw-r--r--examples/stm32h7/src/bin/pwm.rs3
-rw-r--r--examples/stm32l4/src/bin/dac.rs3
6 files changed, 11 insertions, 37 deletions
diff --git a/examples/stm32g4/src/bin/pwm.rs b/examples/stm32g4/src/bin/pwm.rs
index 3dd45318d..fb71c8b7d 100644
--- a/examples/stm32g4/src/bin/pwm.rs
+++ b/examples/stm32g4/src/bin/pwm.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use embassy::executor::Spawner; 7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::NoPin;
10use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel}; 9use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel};
11use embassy_stm32::time::U32Ext; 10use embassy_stm32::time::U32Ext;
12use embassy_stm32::Peripherals; 11use embassy_stm32::Peripherals;
@@ -16,7 +15,7 @@ use example_common::*;
16async fn main(_spawner: Spawner, p: Peripherals) { 15async fn main(_spawner: Spawner, p: Peripherals) {
17 info!("Hello World!"); 16 info!("Hello World!");
18 17
19 let mut pwm = SimplePwm::new(p.TIM2, p.PA5, NoPin, NoPin, NoPin, 10000.hz()); 18 let mut pwm = SimplePwm::new_1ch(p.TIM2, p.PA5, 10000.hz());
20 let max = pwm.get_max_duty(); 19 let max = pwm.get_max_duty();
21 pwm.enable(Channel::Ch1); 20 pwm.enable(Channel::Ch1);
22 21
diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs
index 9760d0f74..f87b27f4f 100644
--- a/examples/stm32h7/src/bin/camera.rs
+++ b/examples/stm32h7/src/bin/camera.rs
@@ -4,8 +4,8 @@
4 4
5use embassy::executor::Spawner; 5use embassy::executor::Spawner;
6use embassy::time::{Duration, Timer}; 6use embassy::time::{Duration, Timer};
7use embassy_stm32::dcmi::*; 7use embassy_stm32::dcmi::{self, *};
8use embassy_stm32::gpio::{Level, NoPin, Output, Speed}; 8use embassy_stm32::gpio::{Level, Output, Speed};
9use embassy_stm32::i2c::I2c; 9use embassy_stm32::i2c::I2c;
10use embassy_stm32::interrupt; 10use embassy_stm32::interrupt;
11use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; 11use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
@@ -78,31 +78,10 @@ async fn main(_spawner: Spawner, p: Peripherals) {
78 ); 78 );
79 79
80 let dcmi_irq = interrupt::take!(DCMI); 80 let dcmi_irq = interrupt::take!(DCMI);
81 let mut dcmi = Dcmi::new( 81 let config = dcmi::Config::default();
82 p.DCMI, 82 let mut dcmi = Dcmi::new_8bit(
83 p.DMA1_CH0, 83 p.DCMI, p.DMA1_CH0, dcmi_irq, p.PC6, p.PC7, p.PE0, p.PE1, p.PE4, p.PD3, p.PE5, p.PE6,
84 VSyncDataInvalidLevel::High, 84 p.PB7, p.PA4, p.PA6, config,
85 HSyncDataInvalidLevel::Low,
86 PixelClockPolarity::RisingEdge,
87 false,
88 dcmi_irq,
89 p.PC6,
90 p.PC7,
91 p.PE0,
92 p.PE1,
93 p.PE4,
94 p.PD3,
95 p.PE5,
96 p.PE6,
97 NoPin,
98 NoPin,
99 NoPin,
100 NoPin,
101 NoPin,
102 NoPin,
103 p.PB7,
104 p.PA4,
105 p.PA6,
106 ); 85 );
107 86
108 defmt::info!("attempting capture"); 87 defmt::info!("attempting capture");
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs
index 4cd2f2cd1..8353405ad 100644
--- a/examples/stm32h7/src/bin/dac.rs
+++ b/examples/stm32h7/src/bin/dac.rs
@@ -5,7 +5,6 @@
5#[path = "../example_common.rs"] 5#[path = "../example_common.rs"]
6mod example_common; 6mod example_common;
7 7
8use embassy_stm32::gpio::NoPin;
9use example_common::*; 8use example_common::*;
10 9
11use cortex_m_rt::entry; 10use cortex_m_rt::entry;
@@ -17,7 +16,7 @@ fn main() -> ! {
17 16
18 let p = embassy_stm32::init(config()); 17 let p = embassy_stm32::init(config());
19 18
20 let mut dac = Dac::new(p.DAC1, p.PA4, NoPin); 19 let mut dac = Dac::new_1ch(p.DAC1, p.PA4);
21 20
22 loop { 21 loop {
23 for v in 0..=255 { 22 for v in 0..=255 {
diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs
index 2640f249d..1bf69104d 100644
--- a/examples/stm32h7/src/bin/low_level_timer_api.rs
+++ b/examples/stm32h7/src/bin/low_level_timer_api.rs
@@ -10,7 +10,6 @@ use embassy::executor::Spawner;
10use embassy::time::{Duration, Timer}; 10use embassy::time::{Duration, Timer};
11use embassy::util::Unborrow; 11use embassy::util::Unborrow;
12use embassy_hal_common::unborrow; 12use embassy_hal_common::unborrow;
13use embassy_stm32::gpio::NoPin;
14use embassy_stm32::pwm::{pins::*, Channel, OutputCompareMode}; 13use embassy_stm32::pwm::{pins::*, Channel, OutputCompareMode};
15use embassy_stm32::time::{Hertz, U32Ext}; 14use embassy_stm32::time::{Hertz, U32Ext};
16use embassy_stm32::timer::GeneralPurpose32bitInstance; 15use embassy_stm32::timer::GeneralPurpose32bitInstance;
@@ -33,7 +32,7 @@ pub fn config() -> Config {
33async fn main(_spawner: Spawner, p: Peripherals) { 32async fn main(_spawner: Spawner, p: Peripherals) {
34 info!("Hello World!"); 33 info!("Hello World!");
35 34
36 let mut pwm = SimplePwm32::new(p.TIM5, p.PA0, NoPin, NoPin, NoPin, 10000.hz()); 35 let mut pwm = SimplePwm32::new(p.TIM5, p.PA0, p.PA1, p.PA2, p.PA3, 10000.hz());
37 let max = pwm.get_max_duty(); 36 let max = pwm.get_max_duty();
38 pwm.enable(Channel::Ch1); 37 pwm.enable(Channel::Ch1);
39 38
diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs
index 020150a39..b3edbde68 100644
--- a/examples/stm32h7/src/bin/pwm.rs
+++ b/examples/stm32h7/src/bin/pwm.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7use embassy::executor::Spawner; 7use embassy::executor::Spawner;
8use embassy::time::{Duration, Timer}; 8use embassy::time::{Duration, Timer};
9use embassy_stm32::gpio::NoPin;
10use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel}; 9use embassy_stm32::pwm::{simple_pwm::SimplePwm, Channel};
11use embassy_stm32::time::U32Ext; 10use embassy_stm32::time::U32Ext;
12use embassy_stm32::{Config, Peripherals}; 11use embassy_stm32::{Config, Peripherals};
@@ -28,7 +27,7 @@ pub fn config() -> Config {
28async fn main(_spawner: Spawner, p: Peripherals) { 27async fn main(_spawner: Spawner, p: Peripherals) {
29 info!("Hello World!"); 28 info!("Hello World!");
30 29
31 let mut pwm = SimplePwm::new(p.TIM3, p.PA6, NoPin, NoPin, NoPin, 10000.hz()); 30 let mut pwm = SimplePwm::new_1ch(p.TIM3, p.PA6, 10000.hz());
32 let max = pwm.get_max_duty(); 31 let max = pwm.get_max_duty();
33 pwm.enable(Channel::Ch1); 32 pwm.enable(Channel::Ch1);
34 33
diff --git a/examples/stm32l4/src/bin/dac.rs b/examples/stm32l4/src/bin/dac.rs
index 6cdd6d3ff..201ba473b 100644
--- a/examples/stm32l4/src/bin/dac.rs
+++ b/examples/stm32l4/src/bin/dac.rs
@@ -6,7 +6,6 @@
6mod example_common; 6mod example_common;
7 7
8use embassy_stm32::dac::{Channel, Dac, Value}; 8use embassy_stm32::dac::{Channel, Dac, Value};
9use embassy_stm32::gpio::NoPin;
10use embassy_stm32::pac; 9use embassy_stm32::pac;
11use example_common::*; 10use example_common::*;
12 11
@@ -22,7 +21,7 @@ fn main() -> ! {
22 21
23 let p = embassy_stm32::init(Default::default()); 22 let p = embassy_stm32::init(Default::default());
24 23
25 let mut dac = Dac::new(p.DAC1, p.PA4, NoPin); 24 let mut dac = Dac::new_1ch(p.DAC1, p.PA4);
26 25
27 loop { 26 loop {
28 for v in 0..=255 { 27 for v in 0..=255 {