aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/blink.rs15
-rwxr-xr-xsrc/main.rs18
2 files changed, 16 insertions, 17 deletions
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::<pac::TIMER6>::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::<pac::TIMER6>::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");