Explorar el Código

display: Fix pins/SPI and configure some default pin states.

Mathias Gottschlag hace 5 años
padre
commit
a6b8646090
Se han modificado 1 ficheros con 26 adiciones y 10 borrados
  1. 26
    10
      display/firmware/src/pins.rs

+ 26
- 10
display/firmware/src/pins.rs Ver fichero

@@ -1,19 +1,22 @@
1
+use embedded_hal::digital::v2::OutputPin;
1 2
 use mkl25z4::{GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, SIM, SPI0, SPI1};
3
+use mkl25z4_hal::clocks::Clocks;
2 4
 use mkl25z4_hal::gpio::{self, gpioa, gpiob, gpioc, gpiod, gpioe, GpioExt};
3 5
 use mkl25z4_hal::spi::{self, Phase, Polarity, Spi};
6
+use mkl25z4_hal::time::U32Ext;
4 7
 
5 8
 pub struct Pins {
6 9
     /// 5V supply for the LED (active high).
7 10
     pub enable_5v: gpioa::PA1<gpio::Output<gpio::PushPull>>,
8 11
     /// Red display frontlight LEDs (active high).
9
-    pub red: gpioe::PE29<gpio::Output<gpio::PushPull>>,
12
+    pub red: gpioe::PE31<gpio::Output<gpio::PushPull>>,
10 13
     /// Green display frontlight LEDs (active high).
11 14
     pub green: gpioe::PE30<gpio::Output<gpio::PushPull>>,
12 15
     /// Blue display frontlight LEDs (active high).
13
-    pub blue: gpioe::PE31<gpio::Output<gpio::PushPull>>,
16
+    pub blue: gpioe::PE29<gpio::Output<gpio::PushPull>>,
14 17
 
15 18
     /// Top switch (active low).
16
-    pub top_switch: gpioc::PC1<gpio::Input<gpio::PullUp>>,
19
+    pub top_switch: gpioc::PC1<gpio::Input<gpio::Floating>>,
17 20
     /// Left switches (top to bottom, active low).
18 21
     pub left_switches: (
19 22
         gpiod::PD1<gpio::Input<gpio::PullUp>>,
@@ -81,6 +84,7 @@ pub struct Pins {
81 84
 impl Pins {
82 85
     pub fn configure(
83 86
         sim: &mut SIM,
87
+        clocks: Clocks,
84 88
         gpioa: GPIOA,
85 89
         gpiob: GPIOB,
86 90
         gpioc: GPIOC,
@@ -103,7 +107,7 @@ impl Pins {
103 107
             polarity: Polarity::IdleLow,
104 108
             phase: Phase::CaptureOnFirstTransition,
105 109
         };
106
-        let spi0 = Spi::spi0(spi0, mosi, miso, sck, mode, sim);
110
+        let spi0 = Spi::spi0(spi0, mosi, miso, sck, mode, 500000u32.hz(), clocks, sim);
107 111
 
108 112
         // SPI1 for the NRF module.
109 113
         let mosi = gpiob.pb16.into_alternate(&mut gpiob.pddr);
@@ -113,14 +117,14 @@ impl Pins {
113 117
             polarity: Polarity::IdleLow,
114 118
             phase: Phase::CaptureOnFirstTransition,
115 119
         };
116
-        let spi1 = Spi::spi1(spi1, mosi, miso, sck, mode, sim);
120
+        let spi1 = Spi::spi1(spi1, mosi, miso, sck, mode, 500000u32.hz(), clocks, sim);
117 121
 
118
-        Pins {
122
+        let mut pins = Pins {
119 123
             enable_5v: gpioa.pa1.into_push_pull_output(&mut gpioa.pddr),
120
-            red: gpioe.pe29.into_push_pull_output(&mut gpioe.pddr),
124
+            red: gpioe.pe31.into_push_pull_output(&mut gpioe.pddr),
121 125
             green: gpioe.pe30.into_push_pull_output(&mut gpioe.pddr),
122
-            blue: gpioe.pe31.into_push_pull_output(&mut gpioe.pddr),
123
-            top_switch: gpioc.pc1.into_pull_up_input(&mut gpioc.pddr),
126
+            blue: gpioe.pe29.into_push_pull_output(&mut gpioe.pddr),
127
+            top_switch: gpioc.pc1.into_floating_input(&mut gpioc.pddr),
124 128
             left_switches: (
125 129
                 gpiod.pd1.into_pull_up_input(&mut gpiod.pddr),
126 130
                 gpiod.pd2.into_pull_up_input(&mut gpiod.pddr),
@@ -149,6 +153,18 @@ impl Pins {
149 153
             display_pwr: gpioc.pc11.into_push_pull_output(&mut gpioc.pddr),
150 154
 
151 155
             display_bme_spi: spi0,
152
-        }
156
+        };
157
+
158
+        // Disable all power, set all chip-select lines high.
159
+        pins.enable_5v.set_low().ok();
160
+        pins.als_en.set_low().ok();
161
+        pins.buzzer.set_low().ok();
162
+        pins.nrf_cs.set_high().ok();
163
+        pins.nrf_pwr.set_high().ok();
164
+        pins.bme_cs.set_high().ok();
165
+        pins.display_cs.set_high().ok();
166
+        pins.display_pwr.set_high().ok();
167
+
168
+        pins
153 169
     }
154 170
 }

Loading…
Cancelar
Guardar