application: Perform a system reset if PTA12 is pressed.
[gps-watch.git] / src / application / main.rs
index 55214279c599367e8010a578cb597291b7449675..bd1091f3c2bbca3632de41c8c536bd7619b34d80 100644 (file)
@@ -30,6 +30,9 @@ extern crate common;
 use common::buffer::Buffer;
 use common::clock;
 use common::systick;
+use common::port;
+use common::gpio;
+use common::nvic;
 use common::usb_serial;
 
 extern {
@@ -42,6 +45,12 @@ extern {
 pub unsafe extern fn main() {
     clock::configure();
     systick::init();
+    port::init();
+
+    // Configure upper right push button.
+    gpio::set_direction(gpio::GPIOA, 1 << 12, gpio::Direction::Input);
+    port::set_af(port::PORTA, 12, 1);
+    port::set_pull(port::PORTA, 12, port::Pull::Up);
 
     enable_interrupts();
 
@@ -55,5 +64,9 @@ pub unsafe extern fn main() {
 
         cdc_tx_buf.write(b".\n");
         cdc_tx_buf.flush();
+
+        if (gpio::get(gpio::GPIOA) & (1 << 12)) == 0 {
+            nvic::system_reset();
+        }
     }
 }