application: Initialize and clear the display on startup.
[gps-watch.git] / src / application / main.rs
index 1fdc577cf9c55fca378798ce5434a390ac345eb4..b1bf3afd24818147146c5a2a89e3773adcdd9372 100644 (file)
@@ -32,7 +32,10 @@ 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();
@@ -46,6 +49,18 @@ pub unsafe extern fn main() {
     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);
@@ -58,10 +73,19 @@ pub unsafe extern fn main() {
     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();
+        }
     }
 }