From 8c1cb71bbe54301b711519267d40bf854f6fcf1f Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Mon, 8 Aug 2022 15:05:31 -0400 Subject: =?UTF-8?q?use=20=E2=80=98nb=E2=80=99=20crate=20instead=20of=20cus?= =?UTF-8?q?tom=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/blink.rs | 15 +++++++++------ src/main.rs | 18 +++++++----------- 2 files changed, 16 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/blink.rs b/src/blink.rs index 7c992d7..8e17b21 100644 --- a/src/blink.rs +++ b/src/blink.rs @@ -1,13 +1,16 @@ -use crate::{PollResult, led::LED}; - use gd32vf103xx_hal::prelude::_embedded_hal_timer_CountDown; +use core::convert::Infallible; + use gd32vf103xx_hal::{ eclic::{self, EclicExt}, pac::{self, Interrupt}, time::Hertz, timer, }; +use nb; + +use crate::led::LED; enum State { WaitForTimer, @@ -33,21 +36,21 @@ impl Task { Self { timer, frequency, led, state: State::ToggleLED } } - pub fn poll(&mut self) -> PollResult { + pub fn poll(&mut self) -> nb::Result<(), Infallible> { match self.state { State::WaitForTimer => { if let Ok(_) = self.timer.wait() { self.state = State::ToggleLED; - PollResult::Ok + Ok(()) } else { - PollResult::WouldBlock + Err(nb::Error::WouldBlock) } }, State::ToggleLED => { self.led.toggle(); self.timer.start(self.frequency); self.state = State::WaitForTimer; - PollResult::WouldBlock + Err(nb::Error::WouldBlock) } } } diff --git a/src/main.rs b/src/main.rs index 707feed..6cb4139 100755 --- a/src/main.rs +++ b/src/main.rs @@ -25,12 +25,6 @@ use led::LED; // global_asm!(include_str!("boot.S")); -#[derive(PartialEq)] -pub enum PollResult { - Ok, - WouldBlock, -} - #[entry] fn main(_hartid: usize) -> ! { let p = Peripherals::take().expect("couldn't take peripherals"); @@ -40,11 +34,7 @@ fn main(_hartid: usize) -> ! { let mut rcu = p.RCU.configure().freeze(); let mut afio = p.AFIO.constrain(&mut rcu); - - let timer = Timer::::timer6(p.TIMER6, Hertz(1), &mut rcu); let gpioa = p.GPIOA.split(&mut rcu); - let led = LED::new(gpioa.pa7); - let mut blink = blink::Task::new(timer, Hertz(5), led); // TODO: figure out how to use the usb serial on the start board. // @@ -59,10 +49,16 @@ fn main(_hartid: usize) -> ! { let (tx, _rx) = serial.split(); log::init(tx); + let timer = Timer::::timer6(p.TIMER6, Hertz(1), &mut rcu); + let led = LED::new(gpioa.pa7); + let mut blink = blink::Task::new(timer, Hertz(5), led); + loop { let mut can_sleep = true; - can_sleep &= blink.poll() == PollResult::WouldBlock; + if let Ok(_) = blink.poll() { + can_sleep = false; + } log!("yo!"); logln!(" mtv raps"); -- cgit v1.2.3