application: Perform a system reset if PTA12 is pressed.
[gps-watch.git] / src / application / main.rs
index ca5d1c155333dff629a47c9c79503ce732a09100..bd1091f3c2bbca3632de41c8c536bd7619b34d80 100644 (file)
@@ -30,9 +30,14 @@ 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 {
+    fn enable_interrupts();
+
     static mut cdc_tx_buf: Buffer;
 }
 
@@ -40,6 +45,14 @@ 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();
 
     usb_serial::init(0xf055, 0x635d);
 
@@ -51,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();
+        }
     }
 }