common: Make Gps::update() access UART0's receive buffer via a closure.
[gps-watch.git] / src / application / main.rs
index 3523b885fe9a907b081c9b85da75f9d8b3380643..444ffd464da0219263f11038f4abd6df6561704d 100644 (file)
@@ -30,6 +30,7 @@ extern crate common;
 mod uart0;
 
 use common::buffer::Buffer;
+use common::ringbuf::Ringbuf;
 use common::clock;
 use common::systick;
 use common::port;
@@ -122,6 +123,20 @@ fn configure_push_buttons() {
     port::set_pull(port::PORTE, 31, port::Pull::Up);
 }
 
+fn uart0_try_read() -> Option<u8> {
+    extern {
+        static mut uart0_rx_buf: Ringbuf;
+    }
+
+    unsafe {
+        if uart0_rx_buf.is_empty() {
+            None
+        } else {
+            Some(uart0_rx_buf.read())
+        }
+    }
+}
+
 #[no_mangle]
 pub unsafe extern "C" fn _start() -> ! {
     clock::configure();
@@ -207,7 +222,7 @@ pub unsafe extern "C" fn _start() -> ! {
         let mut show_time = false;
         let old_gps_has_fix = gps_has_fix;
 
-        while gps.update(&mut tap) {
+        while gps.update(&mut tap, uart0_try_read) {
             prev_tap = tap;
 
             show_time = true;