Skip to content

Commit 72f2b85

Browse files
Jonathan Pallant (42 Technology)Yatekii
authored andcommitted
Fix so that SAADC works on nRF9160.
1 parent b690a7b commit 72f2b85

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

nrf52-hal-common/src/saadc.rs

100644100755
Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
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};
33

4-
#[cfg(not(feature="9160"))]
5-
use crate::target::{SAADC, saadc};
4+
#[cfg(not(feature = "9160"))]
5+
use crate::target::{saadc, SAADC};
66

7-
use crate::{
8-
gpio::{Floating, Input},
9-
};
7+
use crate::gpio::{Floating, Input};
108
use core::{
119
hint::unreachable_unchecked,
1210
sync::atomic::{compiler_fence, Ordering::SeqCst},
@@ -35,13 +33,11 @@ impl Saadc {
3533
reference,
3634
gain,
3735
resistor,
38-
time
36+
time,
3937
} = config;
4038

4139
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));
4541
saadc
4642
.oversample
4743
.write(|w| w.oversample().variant(oversample));
@@ -74,12 +70,12 @@ impl Saadc {
7470
}
7571

7672
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,
8379
}
8480

8581
// 0 volts reads as 0, VDD volts reads as u16::MAX
@@ -96,12 +92,12 @@ impl Default for SaadcConfig {
9692
}
9793
}
9894

99-
impl<PIN> OneShot<Saadc, u16, PIN> for Saadc
95+
impl<PIN> OneShot<Saadc, i16, PIN> for Saadc
10096
where
10197
PIN: Channel<Saadc, ID = u8>,
10298
{
10399
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> {
105101
match PIN::channel() {
106102
0 => self.0.ch[0].pselp.write(|w| w.pselp().analog_input0()),
107103
1 => self.0.ch[0].pselp.write(|w| w.pselp().analog_input1()),
@@ -116,7 +112,7 @@ where
116112
_ => unsafe { unreachable_unchecked() },
117113
}
118114

119-
let mut val: u16 = 0;
115+
let mut val: i16 = 0;
120116
self.0
121117
.result
122118
.ptr
@@ -162,6 +158,19 @@ macro_rules! channel_mappings {
162158
};
163159
}
164160

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"))]
165174
channel_mappings! {
166175
0 => crate::gpio::p0::P0_02<Input<Floating>>,
167176
1 => crate::gpio::p0::P0_03<Input<Floating>>,

0 commit comments

Comments
 (0)