File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change @@ -139,3 +139,7 @@ required-features = ["stm32f303"]
139
139
[[example ]]
140
140
name = " i2c_scanner"
141
141
required-features = [" stm32f303xc" ]
142
+
143
+ [[example ]]
144
+ name = " gpio_erased"
145
+ required-features = [" rt" , " stm32f303xc" ]
Original file line number Diff line number Diff line change
1
+ // TOOD Implement:
2
+ // https://github.com/dfrankland/proton-c/commit/0289f1cfa15000d6b1b2a8175420c16ffdff7451
3
+ #![ no_main]
4
+ #![ no_std]
5
+
6
+ use panic_semihosting as _;
7
+
8
+ use cortex_m:: asm;
9
+ use cortex_m_rt:: entry;
10
+ use cortex_m_semihosting:: hprintln;
11
+
12
+ use hal:: gpio:: { self , Floating , Input } ;
13
+ use hal:: pac;
14
+ use hal:: prelude:: * ;
15
+ use stm32f3xx_hal as hal;
16
+
17
+ #[ entry]
18
+ fn main ( ) -> ! {
19
+ let dp = pac:: Peripherals :: take ( ) . unwrap ( ) ;
20
+
21
+ let mut rcc = dp. RCC . constrain ( ) ;
22
+ let mut gpiob = dp. GPIOB . split ( & mut rcc. ahb ) ;
23
+ let mut gpioc = dp. GPIOC . split ( & mut rcc. ahb ) ;
24
+ let mut gpiod = dp. GPIOD . split ( & mut rcc. ahb ) ;
25
+
26
+ let mut pin_array: [ gpio:: PXx < Input < Floating > > ; 4 ] = [
27
+ gpiob
28
+ . pb11
29
+ . into_floating_input ( & mut gpiob. moder , & mut gpiob. pupdr )
30
+ . downgrade ( )
31
+ . downgrade ( ) ,
32
+ gpioc
33
+ . pc4
34
+ . into_floating_input ( & mut gpioc. moder , & mut gpioc. pupdr )
35
+ . downgrade ( )
36
+ . downgrade ( ) ,
37
+ gpiod
38
+ . pd3
39
+ . into_floating_input ( & mut gpiod. moder , & mut gpiod. pupdr )
40
+ . downgrade ( )
41
+ . downgrade ( ) ,
42
+ gpiod
43
+ . pd2
44
+ . into_floating_input ( & mut gpiod. moder , & mut gpiod. pupdr )
45
+ . downgrade ( )
46
+ . downgrade ( ) ,
47
+ ] ;
48
+
49
+ hprintln ! ( "Start scanning pin array" ) . unwrap ( ) ;
50
+ loop {
51
+ for pin in pin_array. iter_mut ( ) {
52
+ hprintln ! ( "Value is {}" , pin. is_high( ) . unwrap( ) ) . unwrap ( ) ;
53
+ asm:: delay ( 1_000 ) ;
54
+ }
55
+ }
56
+ }
Original file line number Diff line number Diff line change @@ -156,6 +156,14 @@ macro_rules! gpio {
156
156
}
157
157
158
158
/// Fully erased pin
159
+ ///
160
+ /// This moves the pin type information to be known
161
+ /// at runtime, and erases the specific compile time type of the GPIO.
162
+ /// It does only matter, that it is a GPIO pin with a specific MODE.
163
+ ///
164
+ /// See [examples/gpio_erased.rs] as an example.
165
+ ///
166
+ /// [examples/gpio_erased.rs]: https://github.com/stm32-rs/stm32f3xx-hal/blob/v0.5.0/examples/gpio_erased.rs
159
167
pub struct PXx <MODE > {
160
168
i: u8 ,
161
169
gpio: Gpio ,
You can’t perform that action at this time.
0 commit comments