aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob McWhirter <[email protected]>2021-08-04 11:32:39 -0400
committerBob McWhirter <[email protected]>2021-08-04 11:32:39 -0400
commit03f15d3a6093fe169791c5b132688bb115e8046f (patch)
tree86d415c30411417c2038fc1b853c55e4aac1f9da
parent07a095be0d439a0977de09aa5341885cbf399f06 (diff)
Remove builders from Config(s) and examples.
-rw-r--r--embassy-stm32/src/lib.rs9
-rw-r--r--embassy-stm32/src/rcc/h7/mod.rs77
-rw-r--r--examples/stm32f0/src/example_common.rs4
-rw-r--r--examples/stm32f4/src/bin/hello.rs4
-rw-r--r--examples/stm32h7/src/bin/dac.rs17
-rw-r--r--examples/stm32h7/src/bin/eth.rs25
-rw-r--r--examples/stm32h7/src/bin/spi.rs17
-rw-r--r--examples/stm32h7/src/bin/spi_dma.rs18
8 files changed, 67 insertions, 104 deletions
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs
index 0567aa72a..eb893353b 100644
--- a/embassy-stm32/src/lib.rs
+++ b/embassy-stm32/src/lib.rs
@@ -67,14 +67,7 @@ pub use generated::{peripherals, Peripherals};
67 67
68#[non_exhaustive] 68#[non_exhaustive]
69pub struct Config { 69pub struct Config {
70 rcc: rcc::Config, 70 pub rcc: rcc::Config,
71}
72
73impl Config {
74 pub fn rcc(mut self, rcc: rcc::Config) -> Self {
75 self.rcc = rcc;
76 self
77 }
78} 71}
79 72
80impl Default for Config { 73impl Default for Config {
diff --git a/embassy-stm32/src/rcc/h7/mod.rs b/embassy-stm32/src/rcc/h7/mod.rs
index 70632f280..5ec531820 100644
--- a/embassy-stm32/src/rcc/h7/mod.rs
+++ b/embassy-stm32/src/rcc/h7/mod.rs
@@ -70,83 +70,6 @@ pub struct Config {
70 pub pll3: PllConfig, 70 pub pll3: PllConfig,
71} 71}
72 72
73impl Config {
74 pub fn sys_ck<T: Into<Hertz>>(mut self, freq: T) -> Self {
75 self.sys_ck = Some(freq.into());
76 self
77 }
78
79 pub fn per_ck<T: Into<Hertz>>(mut self, freq: T) -> Self {
80 self.per_ck = Some(freq.into());
81 self
82 }
83
84 pub fn pclk1<T: Into<Hertz>>(mut self, freq: T) -> Self {
85 self.pclk1 = Some(freq.into());
86 self
87 }
88
89 pub fn pclk2<T: Into<Hertz>>(mut self, freq: T) -> Self {
90 self.pclk2 = Some(freq.into());
91 self
92 }
93
94 pub fn pclk3<T: Into<Hertz>>(mut self, freq: T) -> Self {
95 self.pclk3 = Some(freq.into());
96 self
97 }
98
99 pub fn pclk4<T: Into<Hertz>>(mut self, freq: T) -> Self {
100 self.pclk4 = Some(freq.into());
101 self
102 }
103
104 pub fn pll1_p<T: Into<Hertz>>(mut self, freq: T) -> Self {
105 self.pll1.p_ck = Some(freq.into());
106 self
107 }
108
109 pub fn pll1_q<T: Into<Hertz>>(mut self, freq: T) -> Self {
110 self.pll1.q_ck = Some(freq.into());
111 self
112 }
113
114 pub fn pll1_r<T: Into<Hertz>>(mut self, freq: T) -> Self {
115 self.pll1.r_ck = Some(freq.into());
116 self
117 }
118
119 pub fn pll2_p<T: Into<Hertz>>(mut self, freq: T) -> Self {
120 self.pll2.p_ck = Some(freq.into());
121 self
122 }
123
124 pub fn pll2_q<T: Into<Hertz>>(mut self, freq: T) -> Self {
125 self.pll2.q_ck = Some(freq.into());
126 self
127 }
128
129 pub fn pll2_r<T: Into<Hertz>>(mut self, freq: T) -> Self {
130 self.pll2.r_ck = Some(freq.into());
131 self
132 }
133
134 pub fn pll3_p<T: Into<Hertz>>(mut self, freq: T) -> Self {
135 self.pll3.p_ck = Some(freq.into());
136 self
137 }
138
139 pub fn pll3_q<T: Into<Hertz>>(mut self, freq: T) -> Self {
140 self.pll3.q_ck = Some(freq.into());
141 self
142 }
143
144 pub fn pll3_r<T: Into<Hertz>>(mut self, freq: T) -> Self {
145 self.pll3.r_ck = Some(freq.into());
146 self
147 }
148}
149
150pub struct Rcc<'d> { 73pub struct Rcc<'d> {
151 inner: PhantomData<&'d ()>, 74 inner: PhantomData<&'d ()>,
152 config: Config, 75 config: Config,
diff --git a/examples/stm32f0/src/example_common.rs b/examples/stm32f0/src/example_common.rs
index e0ba4cd01..c166522e2 100644
--- a/examples/stm32f0/src/example_common.rs
+++ b/examples/stm32f0/src/example_common.rs
@@ -12,7 +12,9 @@ use embassy_stm32::Config;
12pub fn config() -> Config { 12pub fn config() -> Config {
13 let mut rcc_config = rcc::Config::default(); 13 let mut rcc_config = rcc::Config::default();
14 rcc_config.enable_debug_wfe = true; 14 rcc_config.enable_debug_wfe = true;
15 Config::default().rcc(rcc_config) 15 let mut config = Config::default();
16 config.rcc = rcc_config;
17 config
16} 18}
17 19
18defmt::timestamp! {"{=u64}", { 20defmt::timestamp! {"{=u64}", {
diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs
index 8ee6c1ef8..8cbd46d6e 100644
--- a/examples/stm32f4/src/bin/hello.rs
+++ b/examples/stm32f4/src/bin/hello.rs
@@ -22,7 +22,9 @@ fn config() -> Config {
22 rcc_config.sys_ck = Some(Hertz(84_000_000)); 22 rcc_config.sys_ck = Some(Hertz(84_000_000));
23 rcc_config.enable_debug_wfe = true; 23 rcc_config.enable_debug_wfe = true;
24 24
25 Config::default().rcc(rcc_config) 25 let mut config = Config::default();
26 config.rcc = rcc_config;
27 config
26} 28}
27 29
28#[embassy::main(config = "config()")] 30#[embassy::main(config = "config()")]
diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs
index 658449f11..fb2feb7bb 100644
--- a/examples/stm32h7/src/bin/dac.rs
+++ b/examples/stm32h7/src/bin/dac.rs
@@ -22,9 +22,7 @@ use embassy_stm32::Config;
22fn main() -> ! { 22fn main() -> ! {
23 info!("Hello World, dude!"); 23 info!("Hello World, dude!");
24 24
25 let p = embassy_stm32::init( 25 let p = embassy_stm32::init( config() );
26 Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())),
27 );
28 26
29 unsafe { 27 unsafe {
30 Dbgmcu::enable_all(); 28 Dbgmcu::enable_all();
@@ -54,3 +52,16 @@ fn to_sine_wave(v: u8) -> u8 {
54 (r.sin() * 128.0 + 127.0) as u8 52 (r.sin() * 128.0 + 127.0) as u8
55 } 53 }
56} 54}
55
56fn config() -> Config {
57 let mut config = Config::default();
58 config.rcc = rcc_config();
59 config
60}
61
62fn rcc_config() -> rcc::Config {
63 let mut config = rcc::Config::default();
64 config.sys_ck = Some(400.mhz().into());
65 config.pll1.q_ck = Some( 100.mhz().into() );
66 config
67} \ No newline at end of file
diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs
index e49a101bf..233c5e4c3 100644
--- a/examples/stm32h7/src/bin/eth.rs
+++ b/examples/stm32h7/src/bin/eth.rs
@@ -22,9 +22,10 @@ use embassy_net::{
22use embassy_stm32::clock::{Alarm, Clock}; 22use embassy_stm32::clock::{Alarm, Clock};
23use embassy_stm32::eth::lan8742a::LAN8742A; 23use embassy_stm32::eth::lan8742a::LAN8742A;
24use embassy_stm32::eth::{Ethernet, State}; 24use embassy_stm32::eth::{Ethernet, State};
25use embassy_stm32::rcc::{Config as RccConfig, Rcc}; 25use embassy_stm32::rcc::{self, Rcc};
26use embassy_stm32::rng::Random; 26use embassy_stm32::rng::Random;
27use embassy_stm32::time::Hertz; 27use embassy_stm32::time::Hertz;
28use embassy_stm32::time::U32Ext;
28use embassy_stm32::{interrupt, peripherals, Config}; 29use embassy_stm32::{interrupt, peripherals, Config};
29use heapless::Vec; 30use heapless::Vec;
30use panic_probe as _; 31use panic_probe as _;
@@ -108,16 +109,11 @@ fn main() -> ! {
108 info!("Hello World!"); 109 info!("Hello World!");
109 110
110 info!("Setup RCC..."); 111 info!("Setup RCC...");
111 let mut rcc_config = RccConfig::default(); 112 let mut p = embassy_stm32::init(config());
112 rcc_config.sys_ck = Some(Hertz(400_000_000));
113 rcc_config.pll1.q_ck = Some(Hertz(100_000_000));
114 let config = Config::default().rcc(rcc_config);
115
116 let mut p = embassy_stm32::init(config);
117 113
118 // Constrain and Freeze clock 114 // Constrain and Freeze clock
119 115
120 let mut rcc = Rcc::new(&mut p.RCC, RccConfig::default()); 116 let mut rcc = Rcc::new(&mut p.RCC, rcc::Config::default());
121 rcc.enable_debug_wfe(&mut p.DBGMCU, true); 117 rcc.enable_debug_wfe(&mut p.DBGMCU, true);
122 118
123 let rtc_int = interrupt_take!(TIM2); 119 let rtc_int = interrupt_take!(TIM2);
@@ -157,3 +153,16 @@ fn main() -> ! {
157 unwrap!(spawner.spawn(main_task(eth, config, spawner))); 153 unwrap!(spawner.spawn(main_task(eth, config, spawner)));
158 }) 154 })
159} 155}
156
157fn config() -> Config {
158 let mut config = Config::default();
159 config.rcc = rcc_config();
160 config
161}
162
163fn rcc_config() -> rcc::Config {
164 let mut config = rcc::Config::default();
165 config.sys_ck = Some(400.mhz().into());
166 config.pll1.q_ck = Some( 100.mhz().into() );
167 config
168} \ No newline at end of file
diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs
index 3ae2ae7d7..b2cf19615 100644
--- a/examples/stm32h7/src/bin/spi.rs
+++ b/examples/stm32h7/src/bin/spi.rs
@@ -60,9 +60,7 @@ fn main() -> ! {
60 Dbgmcu::enable_all(); 60 Dbgmcu::enable_all();
61 } 61 }
62 62
63 let p = embassy_stm32::init( 63 let p = embassy_stm32::init( config() );
64 Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())),
65 );
66 64
67 let spi = spi::Spi::new( 65 let spi = spi::Spi::new(
68 p.SPI3, 66 p.SPI3,
@@ -82,3 +80,16 @@ fn main() -> ! {
82 unwrap!(spawner.spawn(main_task(spi))); 80 unwrap!(spawner.spawn(main_task(spi)));
83 }) 81 })
84} 82}
83
84fn config() -> Config {
85 let mut config = Config::default();
86 config.rcc = rcc_config();
87 config
88}
89
90fn rcc_config() -> rcc::Config {
91 let mut config = rcc::Config::default();
92 config.sys_ck = Some(400.mhz().into());
93 config.pll1.q_ck = Some( 100.mhz().into() );
94 config
95} \ No newline at end of file
diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs
index 17cc98f95..0ce4212b8 100644
--- a/examples/stm32h7/src/bin/spi_dma.rs
+++ b/examples/stm32h7/src/bin/spi_dma.rs
@@ -8,6 +8,7 @@
8 8
9#[path = "../example_common.rs"] 9#[path = "../example_common.rs"]
10mod example_common; 10mod example_common;
11
11use core::fmt::Write; 12use core::fmt::Write;
12use embassy::executor::Executor; 13use embassy::executor::Executor;
13use embassy::time::Clock; 14use embassy::time::Clock;
@@ -55,9 +56,7 @@ fn main() -> ! {
55 Dbgmcu::enable_all(); 56 Dbgmcu::enable_all();
56 } 57 }
57 58
58 let p = embassy_stm32::init( 59 let p = embassy_stm32::init( config() );
59 Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())),
60 );
61 60
62 let spi = spi::Spi::new( 61 let spi = spi::Spi::new(
63 p.SPI3, 62 p.SPI3,
@@ -77,3 +76,16 @@ fn main() -> ! {
77 unwrap!(spawner.spawn(main_task(spi))); 76 unwrap!(spawner.spawn(main_task(spi)));
78 }) 77 })
79} 78}
79
80fn config() -> Config {
81 let mut config = Config::default();
82 config.rcc = rcc_config();
83 config
84}
85
86fn rcc_config() -> rcc::Config {
87 let mut config = rcc::Config::default();
88 config.sys_ck = Some(400.mhz().into());
89 config.pll1.q_ck = Some( 100.mhz().into() );
90 config
91}