Skip to content
Snippets Groups Projects
Commit 349f1ce6 authored by Matt Johnston's avatar Matt Johnston
Browse files

move to probe-run

parent 36b8ff74
Branches
No related merge requests found
......@@ -33,3 +33,6 @@ embedded-hal-1 = { package = "embedded-hal", version = "1.0.0-alpha.8" }
embedded-hal-async = { version = "0.1.0-alpha.1" }
embedded-io = { version = "0.3.0", features = ["async", "defmt"] }
static_cell = "1.0.0"
[profile.release]
debug = 2
......@@ -78,19 +78,22 @@ async fn main(_spawner: Spawner) {
let mut gpio6 = Flex::new(p.PIN_6);
// Do stuff with the class!
let echo_fut = async {
loop {
class.wait_connection().await;
info!("Connected");
let _ = echo(&mut class, &mut gpio6, &mut cp.SYST).await;
info!("Disconnected");
}
};
// Run everything concurrently.
// If we had made everything `'static` above instead, we could do this using separate tasks instead.
join(usb_fut, echo_fut).await;
run(&mut gpio6, &mut cp.SYST).await;
// // Do stuff with the class!
// let echo_fut = async {
// loop {
// class.wait_connection().await;
// info!("Connected");
// let _ = usb_echo(&mut class, &mut gpio6, &mut cp.SYST).await;
// info!("Disconnected");
// }
// };
// // Run everything concurrently.
// // If we had made everything `'static` above instead, we could do this using separate tasks instead.
// join(usb_fut, echo_fut).await;
}
struct Disconnected {}
......@@ -131,7 +134,7 @@ impl core::fmt::Write for FmtBuf {
}
}
async fn echo<'d, P: Pin, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>,
async fn usb_echo<'d, P: Pin, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'d, T>>,
pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), Disconnected> {
class.write_packet(b"hello\r\n").await?;
......@@ -161,6 +164,37 @@ async fn echo<'d, P: Pin, T: Instance + 'd>(class: &mut CdcAcmClass<'d, Driver<'
});
let del = t1 - t2;
FmtBuf::write(class, format_args!("{del}\n")).await.map_err(|_| Disconnected{})?;
}
}
async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), Disconnected> {
info!("hello");
syst.set_reload(10_000_000-1);
syst.clear_current();
syst.set_clock_source(cortex_m::peripheral::syst::SystClkSource::Core);
syst.enable_counter();
unsafe{ pac::ROSC.ctrl().modify(|s| s.set_enable(pac::rosc::vals::Enable::DISABLE))};
loop {
let (t1, t2) = critical_section::with(|_cs| {
syst.clear_current();
pin.set_pull(Pull::Down);
pin.set_as_output();
pin.set_high();
// // approx 1ms
// cortex_m::asm::delay(125_000);
cortex_m::asm::delay(900);
let t1 = SYST::get_current();
pin.set_as_input();
while pin.is_high() {}
let t2 = SYST::get_current();
(t1, t2)
});
let del = t1 - t2;
info!("{}", del);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment