application: Initialize and clear the display on startup.
[gps-watch.git] / src / application / main.rs
index ca5d1c155333dff629a47c9c79503ce732a09100..b1bf3afd24818147146c5a2a89e3773adcdd9372 100644 (file)
@@ -30,9 +30,16 @@ extern crate common;
 use common::buffer::Buffer;
 use common::clock;
 use common::systick;
+use common::port;
+use common::gpio;
+use common::nvic;
+use common::i2c;
 use common::usb_serial;
+use common::display;
 
 extern {
+    fn enable_interrupts();
+
     static mut cdc_tx_buf: Buffer;
 }
 
@@ -40,16 +47,45 @@ extern {
 pub unsafe extern fn main() {
     clock::configure();
     systick::init();
+    port::init();
+
+    // Configure pins for I2C0.
+    port::set_af(port::PORTC, 8, 2);
+    port::set_af(port::PORTC, 9, 2);
+
+    i2c::configure(i2c::I2C0);
+
+    nvic::disable_irq(8); // I2C0
+
+    // Configure pin for the display's reset line.
+    gpio::set_direction(gpio::GPIOB, 1 << 16, gpio::Direction::Output);
+    port::set_af(port::PORTB, 16, 1);
+
+    // 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);
 
     cdc_tx_buf.write(b"\n");
     cdc_tx_buf.flush();
 
+    let mut display = display::Display::new(gpio::GPIOB, 1 << 16, 0x3c);
+
+    display.init();
+    display.clear();
+
     loop {
         systick::delay_ms(1000);
 
         cdc_tx_buf.write(b".\n");
         cdc_tx_buf.flush();
+
+        if (gpio::get(gpio::GPIOA) & (1 << 12)) == 0 {
+            nvic::system_reset();
+        }
     }
 }