1
- #[ cfg( feature= "9160" ) ]
2
- use crate :: target:: { SAADC_NS as SAADC , saadc_ns as saadc } ;
1
+ #[ cfg( feature = "9160" ) ]
2
+ use crate :: target:: { saadc_ns as saadc , SAADC_NS as SAADC } ;
3
3
4
- #[ cfg( not( feature= "9160" ) ) ]
5
- use crate :: target:: { SAADC , saadc } ;
4
+ #[ cfg( not( feature = "9160" ) ) ]
5
+ use crate :: target:: { saadc , SAADC } ;
6
6
7
- use crate :: {
8
- gpio:: { Floating , Input } ,
9
- } ;
7
+ use crate :: gpio:: { Floating , Input } ;
10
8
use core:: {
11
9
hint:: unreachable_unchecked,
12
10
sync:: atomic:: { compiler_fence, Ordering :: SeqCst } ,
@@ -35,13 +33,11 @@ impl Saadc {
35
33
reference,
36
34
gain,
37
35
resistor,
38
- time
36
+ time,
39
37
} = config;
40
38
41
39
saadc. enable . write ( |w| w. enable ( ) . enabled ( ) ) ;
42
- saadc
43
- . resolution
44
- . write ( |w| w. val ( ) . variant ( resolution) ) ;
40
+ saadc. resolution . write ( |w| w. val ( ) . variant ( resolution) ) ;
45
41
saadc
46
42
. oversample
47
43
. write ( |w| w. oversample ( ) . variant ( oversample) ) ;
@@ -74,12 +70,12 @@ impl Saadc {
74
70
}
75
71
76
72
pub struct SaadcConfig {
77
- resolution : Resolution ,
78
- oversample : Oversample ,
79
- reference : Reference ,
80
- gain : Gain ,
81
- resistor : Resistor ,
82
- time : Time ,
73
+ pub resolution : Resolution ,
74
+ pub oversample : Oversample ,
75
+ pub reference : Reference ,
76
+ pub gain : Gain ,
77
+ pub resistor : Resistor ,
78
+ pub time : Time ,
83
79
}
84
80
85
81
// 0 volts reads as 0, VDD volts reads as u16::MAX
@@ -96,12 +92,12 @@ impl Default for SaadcConfig {
96
92
}
97
93
}
98
94
99
- impl < PIN > OneShot < Saadc , u16 , PIN > for Saadc
95
+ impl < PIN > OneShot < Saadc , i16 , PIN > for Saadc
100
96
where
101
97
PIN : Channel < Saadc , ID = u8 > ,
102
98
{
103
99
type Error = ( ) ;
104
- fn read ( & mut self , _pin : & mut PIN ) -> nb:: Result < u16 , Self :: Error > {
100
+ fn read ( & mut self , _pin : & mut PIN ) -> nb:: Result < i16 , Self :: Error > {
105
101
match PIN :: channel ( ) {
106
102
0 => self . 0 . ch [ 0 ] . pselp . write ( |w| w. pselp ( ) . analog_input0 ( ) ) ,
107
103
1 => self . 0 . ch [ 0 ] . pselp . write ( |w| w. pselp ( ) . analog_input1 ( ) ) ,
@@ -116,7 +112,7 @@ where
116
112
_ => unsafe { unreachable_unchecked ( ) } ,
117
113
}
118
114
119
- let mut val: u16 = 0 ;
115
+ let mut val: i16 = 0 ;
120
116
self . 0
121
117
. result
122
118
. ptr
@@ -162,6 +158,19 @@ macro_rules! channel_mappings {
162
158
} ;
163
159
}
164
160
161
+ #[ cfg( feature = "9160" ) ]
162
+ channel_mappings ! {
163
+ 0 => crate :: gpio:: p0:: P0_13 <Input <Floating >>,
164
+ 1 => crate :: gpio:: p0:: P0_14 <Input <Floating >>,
165
+ 2 => crate :: gpio:: p0:: P0_15 <Input <Floating >>,
166
+ 3 => crate :: gpio:: p0:: P0_16 <Input <Floating >>,
167
+ 4 => crate :: gpio:: p0:: P0_17 <Input <Floating >>,
168
+ 5 => crate :: gpio:: p0:: P0_18 <Input <Floating >>,
169
+ 6 => crate :: gpio:: p0:: P0_19 <Input <Floating >>,
170
+ 7 => crate :: gpio:: p0:: P0_20 <Input <Floating >>
171
+ }
172
+
173
+ #[ cfg( not( feature = "9160" ) ) ]
165
174
channel_mappings ! {
166
175
0 => crate :: gpio:: p0:: P0_02 <Input <Floating >>,
167
176
1 => crate :: gpio:: p0:: P0_03 <Input <Floating >>,
0 commit comments