File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change
1
+ #![ no_std]
2
+ #![ no_main]
3
+
4
+ use defmt_rtt as _;
5
+ use panic_probe as _;
6
+
7
+ use stm32f3xx_hal as hal;
8
+
9
+ use hal:: gpio:: { Input , Output , PXx , PushPull } ;
10
+
11
+ struct State {
12
+ input_pin : PXx < Input > ,
13
+ output_pin : PXx < Output < PushPull > > ,
14
+ }
15
+
16
+ #[ defmt_test:: tests]
17
+ mod tests {
18
+ use defmt:: { assert, unwrap} ;
19
+ use stm32f3xx_hal:: { pac, prelude:: * } ;
20
+
21
+ // Test the defaults with no configuration
22
+ #[ init]
23
+ fn init ( ) -> super :: State {
24
+ let dp = unwrap ! ( pac:: Peripherals :: take( ) ) ;
25
+
26
+ let mut rcc = dp. RCC . constrain ( ) ;
27
+ let mut gpioc = dp. GPIOC . split ( & mut rcc. ahb ) ;
28
+
29
+ let input_pin = gpioc
30
+ . pc0
31
+ . into_floating_input ( & mut gpioc. moder , & mut gpioc. pupdr )
32
+ . downgrade ( )
33
+ . downgrade ( ) ;
34
+ let output_pin = gpioc
35
+ . pc1
36
+ . into_push_pull_output ( & mut gpioc. moder , & mut gpioc. otyper )
37
+ . downgrade ( )
38
+ . downgrade ( ) ;
39
+
40
+ super :: State {
41
+ input_pin,
42
+ output_pin,
43
+ }
44
+ }
45
+
46
+ #[ test]
47
+ fn set_low_is_low ( state : & mut super :: State ) {
48
+ unwrap ! ( state. output_pin. set_low( ) ) ;
49
+ assert ! ( unwrap!( state. output_pin. is_set_low( ) ) ) ;
50
+ assert ! ( unwrap!( state. input_pin. is_low( ) ) ) ;
51
+ }
52
+
53
+ #[ test]
54
+ fn set_high_is_high ( state : & mut super :: State ) {
55
+ unwrap ! ( state. output_pin. set_high( ) ) ;
56
+ assert ! ( unwrap!( state. output_pin. is_set_high( ) ) ) ;
57
+ assert ! ( unwrap!( state. input_pin. is_high( ) ) ) ;
58
+ }
59
+ }
You can’t perform that action at this time.
0 commit comments