Remove builders from Config(s) and examples.
This commit is contained in:
parent
07a095be0d
commit
03f15d3a60
8 changed files with 67 additions and 104 deletions
|
@ -67,14 +67,7 @@ pub use generated::{peripherals, Peripherals};
|
|||
|
||||
#[non_exhaustive]
|
||||
pub struct Config {
|
||||
rcc: rcc::Config,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn rcc(mut self, rcc: rcc::Config) -> Self {
|
||||
self.rcc = rcc;
|
||||
self
|
||||
}
|
||||
pub rcc: rcc::Config,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
|
|
@ -70,83 +70,6 @@ pub struct Config {
|
|||
pub pll3: PllConfig,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn sys_ck<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.sys_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn per_ck<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.per_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pclk1<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pclk1 = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pclk2<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pclk2 = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pclk3<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pclk3 = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pclk4<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pclk4 = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll1_p<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll1.p_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll1_q<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll1.q_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll1_r<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll1.r_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll2_p<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll2.p_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll2_q<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll2.q_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll2_r<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll2.r_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll3_p<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll3.p_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll3_q<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll3.q_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll3_r<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll3.r_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Rcc<'d> {
|
||||
inner: PhantomData<&'d ()>,
|
||||
config: Config,
|
||||
|
|
|
@ -12,7 +12,9 @@ use embassy_stm32::Config;
|
|||
pub fn config() -> Config {
|
||||
let mut rcc_config = rcc::Config::default();
|
||||
rcc_config.enable_debug_wfe = true;
|
||||
Config::default().rcc(rcc_config)
|
||||
let mut config = Config::default();
|
||||
config.rcc = rcc_config;
|
||||
config
|
||||
}
|
||||
|
||||
defmt::timestamp! {"{=u64}", {
|
||||
|
|
|
@ -22,7 +22,9 @@ fn config() -> Config {
|
|||
rcc_config.sys_ck = Some(Hertz(84_000_000));
|
||||
rcc_config.enable_debug_wfe = true;
|
||||
|
||||
Config::default().rcc(rcc_config)
|
||||
let mut config = Config::default();
|
||||
config.rcc = rcc_config;
|
||||
config
|
||||
}
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
|
|
|
@ -22,9 +22,7 @@ use embassy_stm32::Config;
|
|||
fn main() -> ! {
|
||||
info!("Hello World, dude!");
|
||||
|
||||
let p = embassy_stm32::init(
|
||||
Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())),
|
||||
);
|
||||
let p = embassy_stm32::init( config() );
|
||||
|
||||
unsafe {
|
||||
Dbgmcu::enable_all();
|
||||
|
@ -54,3 +52,16 @@ fn to_sine_wave(v: u8) -> u8 {
|
|||
(r.sin() * 128.0 + 127.0) as u8
|
||||
}
|
||||
}
|
||||
|
||||
fn config() -> Config {
|
||||
let mut config = Config::default();
|
||||
config.rcc = rcc_config();
|
||||
config
|
||||
}
|
||||
|
||||
fn rcc_config() -> rcc::Config {
|
||||
let mut config = rcc::Config::default();
|
||||
config.sys_ck = Some(400.mhz().into());
|
||||
config.pll1.q_ck = Some( 100.mhz().into() );
|
||||
config
|
||||
}
|
|
@ -22,9 +22,10 @@ use embassy_net::{
|
|||
use embassy_stm32::clock::{Alarm, Clock};
|
||||
use embassy_stm32::eth::lan8742a::LAN8742A;
|
||||
use embassy_stm32::eth::{Ethernet, State};
|
||||
use embassy_stm32::rcc::{Config as RccConfig, Rcc};
|
||||
use embassy_stm32::rcc::{self, Rcc};
|
||||
use embassy_stm32::rng::Random;
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::time::U32Ext;
|
||||
use embassy_stm32::{interrupt, peripherals, Config};
|
||||
use heapless::Vec;
|
||||
use panic_probe as _;
|
||||
|
@ -108,16 +109,11 @@ fn main() -> ! {
|
|||
info!("Hello World!");
|
||||
|
||||
info!("Setup RCC...");
|
||||
let mut rcc_config = RccConfig::default();
|
||||
rcc_config.sys_ck = Some(Hertz(400_000_000));
|
||||
rcc_config.pll1.q_ck = Some(Hertz(100_000_000));
|
||||
let config = Config::default().rcc(rcc_config);
|
||||
|
||||
let mut p = embassy_stm32::init(config);
|
||||
let mut p = embassy_stm32::init(config());
|
||||
|
||||
// Constrain and Freeze clock
|
||||
|
||||
let mut rcc = Rcc::new(&mut p.RCC, RccConfig::default());
|
||||
let mut rcc = Rcc::new(&mut p.RCC, rcc::Config::default());
|
||||
rcc.enable_debug_wfe(&mut p.DBGMCU, true);
|
||||
|
||||
let rtc_int = interrupt_take!(TIM2);
|
||||
|
@ -157,3 +153,16 @@ fn main() -> ! {
|
|||
unwrap!(spawner.spawn(main_task(eth, config, spawner)));
|
||||
})
|
||||
}
|
||||
|
||||
fn config() -> Config {
|
||||
let mut config = Config::default();
|
||||
config.rcc = rcc_config();
|
||||
config
|
||||
}
|
||||
|
||||
fn rcc_config() -> rcc::Config {
|
||||
let mut config = rcc::Config::default();
|
||||
config.sys_ck = Some(400.mhz().into());
|
||||
config.pll1.q_ck = Some( 100.mhz().into() );
|
||||
config
|
||||
}
|
|
@ -60,9 +60,7 @@ fn main() -> ! {
|
|||
Dbgmcu::enable_all();
|
||||
}
|
||||
|
||||
let p = embassy_stm32::init(
|
||||
Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())),
|
||||
);
|
||||
let p = embassy_stm32::init( config() );
|
||||
|
||||
let spi = spi::Spi::new(
|
||||
p.SPI3,
|
||||
|
@ -82,3 +80,16 @@ fn main() -> ! {
|
|||
unwrap!(spawner.spawn(main_task(spi)));
|
||||
})
|
||||
}
|
||||
|
||||
fn config() -> Config {
|
||||
let mut config = Config::default();
|
||||
config.rcc = rcc_config();
|
||||
config
|
||||
}
|
||||
|
||||
fn rcc_config() -> rcc::Config {
|
||||
let mut config = rcc::Config::default();
|
||||
config.sys_ck = Some(400.mhz().into());
|
||||
config.pll1.q_ck = Some( 100.mhz().into() );
|
||||
config
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use core::fmt::Write;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::time::Clock;
|
||||
|
@ -55,9 +56,7 @@ fn main() -> ! {
|
|||
Dbgmcu::enable_all();
|
||||
}
|
||||
|
||||
let p = embassy_stm32::init(
|
||||
Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())),
|
||||
);
|
||||
let p = embassy_stm32::init( config() );
|
||||
|
||||
let spi = spi::Spi::new(
|
||||
p.SPI3,
|
||||
|
@ -77,3 +76,16 @@ fn main() -> ! {
|
|||
unwrap!(spawner.spawn(main_task(spi)));
|
||||
})
|
||||
}
|
||||
|
||||
fn config() -> Config {
|
||||
let mut config = Config::default();
|
||||
config.rcc = rcc_config();
|
||||
config
|
||||
}
|
||||
|
||||
fn rcc_config() -> rcc::Config {
|
||||
let mut config = rcc::Config::default();
|
||||
config.sys_ck = Some(400.mhz().into());
|
||||
config.pll1.q_ck = Some( 100.mhz().into() );
|
||||
config
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue