time: replace dyn clock/alarm with a global Driver trait
This commit is contained in:
@ -6,30 +6,29 @@
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
info!("Hello World!");
|
||||
|
||||
unsafe { Dbgmcu::enable_all() };
|
||||
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
|
||||
let mut led = Output::new(p.PB14, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
led.set_high().unwrap();
|
||||
cortex_m::asm::delay(10_000_000);
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
info!("low");
|
||||
led.set_low().unwrap();
|
||||
cortex_m::asm::delay(10_000_000);
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ use embassy_macros::interrupt_take;
|
||||
use embassy_net::{
|
||||
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
||||
};
|
||||
use embassy_stm32::clock::{Alarm, Clock};
|
||||
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||
use embassy_stm32::eth::lan8742a::LAN8742A;
|
||||
use embassy_stm32::eth::{Ethernet, State};
|
||||
@ -27,7 +26,7 @@ use embassy_stm32::rng::Random;
|
||||
use embassy_stm32::{interrupt, peripherals};
|
||||
use heapless::Vec;
|
||||
use panic_probe as _;
|
||||
use peripherals::{RNG, TIM2};
|
||||
use peripherals::RNG;
|
||||
|
||||
#[embassy::task]
|
||||
async fn main_task(
|
||||
@ -86,8 +85,6 @@ fn _embassy_rand(buf: &mut [u8]) {
|
||||
static mut RNG_INST: Option<Random<RNG>> = None;
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
static TIMER_RTC: Forever<Clock<TIM2>> = Forever::new();
|
||||
static ALARM: Forever<Alarm<TIM2>> = Forever::new();
|
||||
static STATE: Forever<State<'static, 4, 4>> = Forever::new();
|
||||
static ETH: Forever<Ethernet<'static, LAN8742A, 4, 4>> = Forever::new();
|
||||
static CONFIG: Forever<StaticConfigurator> = Forever::new();
|
||||
@ -105,13 +102,6 @@ fn main() -> ! {
|
||||
|
||||
let p = embassy_stm32::init(config());
|
||||
|
||||
let rtc_int = interrupt_take!(TIM2);
|
||||
let rtc = TIMER_RTC.put(Clock::new(p.TIM2, rtc_int));
|
||||
rtc.start();
|
||||
let alarm = ALARM.put(rtc.alarm1());
|
||||
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let rng = Random::new(p.RNG);
|
||||
unsafe {
|
||||
RNG_INST.replace(rng);
|
||||
@ -136,7 +126,6 @@ fn main() -> ! {
|
||||
let config = CONFIG.put(config);
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.set_alarm(alarm);
|
||||
|
||||
executor.run(move |spawner| {
|
||||
unwrap!(spawner.spawn(main_task(eth, config, spawner)));
|
||||
|
@ -9,7 +9,6 @@ mod example_common;
|
||||
|
||||
use core::fmt::Write;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::time::Clock;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::spi;
|
||||
@ -38,14 +37,6 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) {
|
||||
}
|
||||
}
|
||||
|
||||
struct ZeroClock;
|
||||
|
||||
impl Clock for ZeroClock {
|
||||
fn now(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
@ -69,7 +60,6 @@ fn main() -> ! {
|
||||
spi::Config::default(),
|
||||
);
|
||||
|
||||
unsafe { embassy::time::set_clock(&ZeroClock) };
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
|
@ -9,7 +9,6 @@ mod example_common;
|
||||
|
||||
use core::fmt::Write;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::time::Clock;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::time::U32Ext;
|
||||
use embassy_traits::spi::FullDuplex;
|
||||
@ -34,14 +33,6 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) {
|
||||
}
|
||||
}
|
||||
|
||||
struct ZeroClock;
|
||||
|
||||
impl Clock for ZeroClock {
|
||||
fn now(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
@ -65,7 +56,6 @@ fn main() -> ! {
|
||||
spi::Config::default(),
|
||||
);
|
||||
|
||||
unsafe { embassy::time::set_clock(&ZeroClock) };
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
|
@ -8,7 +8,6 @@
|
||||
mod example_common;
|
||||
use cortex_m::prelude::_embedded_hal_blocking_serial_Write;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::time::Clock;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
@ -34,14 +33,6 @@ async fn main_task() {
|
||||
}
|
||||
}
|
||||
|
||||
struct ZeroClock;
|
||||
|
||||
impl Clock for ZeroClock {
|
||||
fn now(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
@ -52,8 +43,6 @@ fn main() -> ! {
|
||||
Dbgmcu::enable_all();
|
||||
}
|
||||
|
||||
unsafe { embassy::time::set_clock(&ZeroClock) };
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
|
@ -8,7 +8,6 @@
|
||||
mod example_common;
|
||||
use core::fmt::Write;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::time::Clock;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
@ -36,14 +35,6 @@ async fn main_task() {
|
||||
}
|
||||
}
|
||||
|
||||
struct ZeroClock;
|
||||
|
||||
impl Clock for ZeroClock {
|
||||
fn now(&self) -> u64 {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
|
||||
#[entry]
|
||||
@ -54,8 +45,6 @@ fn main() -> ! {
|
||||
Dbgmcu::enable_all();
|
||||
}
|
||||
|
||||
unsafe { embassy::time::set_clock(&ZeroClock) };
|
||||
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
|
||||
executor.run(|spawner| {
|
||||
|
Reference in New Issue
Block a user