494: nrf: saadc do not reexport pac enums r=Dirbaio a=jacobrosenthal

Closes #415

Co-authored-by: Jacob Rosenthal <jacobrosenthal@gmail.com>
This commit is contained in:
bors[bot] 2021-11-21 19:47:31 +00:00 committed by GitHub
commit d7bbaf1a4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -18,10 +18,10 @@ use pac::{saadc, SAADC};
// We treat the positive and negative channels with the same enum values to keep our type tidy and given they are the same
pub(crate) use saadc::ch::pselp::PSELP_A as InputChannel;
pub use saadc::{
ch::config::{GAIN_A as Gain, REFSEL_A as Reference, RESP_A as Resistor, TACQ_A as Time},
oversample::OVERSAMPLE_A as Oversample,
resolution::VAL_A as Resolution,
use saadc::{
ch::config::{GAIN_A, REFSEL_A, RESP_A, TACQ_A},
oversample::OVERSAMPLE_A,
resolution::VAL_A,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@ -161,8 +161,9 @@ impl<'d, const N: usize> Saadc<'d, N> {
// Configure channels
r.enable.write(|w| w.enable().enabled());
r.resolution.write(|w| w.val().variant(resolution));
r.oversample.write(|w| w.oversample().variant(oversample));
r.resolution.write(|w| w.val().variant(resolution.into()));
r.oversample
.write(|w| w.oversample().variant(oversample.into()));
for (i, cc) in channel_configs.iter().enumerate() {
r.ch[i].pselp.write(|w| w.pselp().variant(cc.p_channel));
@ -172,15 +173,15 @@ impl<'d, const N: usize> Saadc<'d, N> {
.write(|w| unsafe { w.pseln().bits(n_channel as u8) });
}
r.ch[i].config.write(|w| {
w.refsel().variant(cc.reference);
w.gain().variant(cc.gain);
w.tacq().variant(cc.time);
w.refsel().variant(cc.reference.into());
w.gain().variant(cc.gain.into());
w.tacq().variant(cc.time.into());
if cc.n_channel.is_none() {
w.mode().se();
} else {
w.mode().diff();
}
w.resp().variant(cc.resistor);
w.resp().variant(cc.resistor.into());
w.resn().bypass();
if !matches!(oversample, Oversample::BYPASS) {
w.burst().enabled();
@ -405,6 +406,183 @@ impl<'d, const N: usize> Drop for Saadc<'d, N> {
}
}
impl From<Gain> for GAIN_A {
fn from(gain: Gain) -> Self {
match gain {
Gain::GAIN1_6 => GAIN_A::GAIN1_6,
Gain::GAIN1_5 => GAIN_A::GAIN1_5,
Gain::GAIN1_4 => GAIN_A::GAIN1_4,
Gain::GAIN1_3 => GAIN_A::GAIN1_3,
Gain::GAIN1_2 => GAIN_A::GAIN1_2,
Gain::GAIN1 => GAIN_A::GAIN1,
Gain::GAIN2 => GAIN_A::GAIN2,
Gain::GAIN4 => GAIN_A::GAIN4,
}
}
}
/// Gain control
#[non_exhaustive]
#[derive(Clone, Copy)]
pub enum Gain {
/// 1/6
GAIN1_6 = 0,
/// 1/5
GAIN1_5 = 1,
/// 1/4
GAIN1_4 = 2,
/// 1/3
GAIN1_3 = 3,
/// 1/2
GAIN1_2 = 4,
/// 1
GAIN1 = 5,
/// 2
GAIN2 = 6,
/// 4
GAIN4 = 7,
}
impl From<Reference> for REFSEL_A {
fn from(reference: Reference) -> Self {
match reference {
Reference::INTERNAL => REFSEL_A::INTERNAL,
Reference::VDD1_4 => REFSEL_A::VDD1_4,
}
}
}
/// Reference control
#[non_exhaustive]
#[derive(Clone, Copy)]
pub enum Reference {
/// Internal reference (0.6 V)
INTERNAL = 0,
/// VDD/4 as reference
VDD1_4 = 1,
}
impl From<Resistor> for RESP_A {
fn from(resistor: Resistor) -> Self {
match resistor {
Resistor::BYPASS => RESP_A::BYPASS,
Resistor::PULLDOWN => RESP_A::PULLDOWN,
Resistor::PULLUP => RESP_A::PULLUP,
Resistor::VDD1_2 => RESP_A::VDD1_2,
}
}
}
/// Positive channel resistor control
#[non_exhaustive]
#[derive(Clone, Copy)]
pub enum Resistor {
/// Bypass resistor ladder
BYPASS = 0,
/// Pull-down to GND
PULLDOWN = 1,
/// Pull-up to VDD
PULLUP = 2,
/// Set input at VDD/2
VDD1_2 = 3,
}
impl From<Time> for TACQ_A {
fn from(time: Time) -> Self {
match time {
Time::_3US => TACQ_A::_3US,
Time::_5US => TACQ_A::_5US,
Time::_10US => TACQ_A::_10US,
Time::_15US => TACQ_A::_15US,
Time::_20US => TACQ_A::_20US,
Time::_40US => TACQ_A::_40US,
}
}
}
/// Acquisition time, the time the SAADC uses to sample the input voltage
#[non_exhaustive]
#[derive(Clone, Copy)]
pub enum Time {
/// 3 us
_3US = 0,
/// 5 us
_5US = 1,
/// 10 us
_10US = 2,
/// 15 us
_15US = 3,
/// 20 us
_20US = 4,
/// 40 us
_40US = 5,
}
impl From<Oversample> for OVERSAMPLE_A {
fn from(oversample: Oversample) -> Self {
match oversample {
Oversample::BYPASS => OVERSAMPLE_A::BYPASS,
Oversample::OVER2X => OVERSAMPLE_A::OVER2X,
Oversample::OVER4X => OVERSAMPLE_A::OVER4X,
Oversample::OVER8X => OVERSAMPLE_A::OVER8X,
Oversample::OVER16X => OVERSAMPLE_A::OVER16X,
Oversample::OVER32X => OVERSAMPLE_A::OVER32X,
Oversample::OVER64X => OVERSAMPLE_A::OVER64X,
Oversample::OVER128X => OVERSAMPLE_A::OVER128X,
Oversample::OVER256X => OVERSAMPLE_A::OVER256X,
}
}
}
/// Oversample control
#[non_exhaustive]
#[derive(Clone, Copy)]
pub enum Oversample {
/// Bypass oversampling
BYPASS = 0,
/// Oversample 2x
OVER2X = 1,
/// Oversample 4x
OVER4X = 2,
/// Oversample 8x
OVER8X = 3,
/// Oversample 16x
OVER16X = 4,
/// Oversample 32x
OVER32X = 5,
/// Oversample 64x
OVER64X = 6,
/// Oversample 128x
OVER128X = 7,
/// Oversample 256x
OVER256X = 8,
}
impl From<Resolution> for VAL_A {
fn from(resolution: Resolution) -> Self {
match resolution {
Resolution::_8BIT => VAL_A::_8BIT,
Resolution::_10BIT => VAL_A::_10BIT,
Resolution::_12BIT => VAL_A::_12BIT,
Resolution::_14BIT => VAL_A::_14BIT,
}
}
}
/// Set the resolution
#[non_exhaustive]
#[derive(Clone, Copy)]
pub enum Resolution {
/// 8 bits
_8BIT = 0,
/// 10 bits
_10BIT = 1,
/// 12 bits
_12BIT = 2,
/// 14 bits
_14BIT = 3,
}
pub(crate) mod sealed {
use super::*;