Enum stm32wlxx_hal::adc::Ts

source ·
#[repr(u8)]
pub enum Ts { Cyc1 = 0, Cyc3 = 1, Cyc7 = 2, Cyc12 = 3, Cyc19 = 4, Cyc39 = 5, Cyc79 = 6, Cyc160 = 7, }
Expand description

ADC sample times

Variants§

§

Cyc1 = 0

1.5 ADC clock cycles

§

Cyc3 = 1

3.5 ADC clock cycles

§

Cyc7 = 2

7.5 ADC clock cycles

§

Cyc12 = 3

12.5 ADC clock cycles

§

Cyc19 = 4

19.5 ADC clock cycles

§

Cyc39 = 5

39.5 ADC clock cycles

§

Cyc79 = 6

79.5 ADC clock cycles

§

Cyc160 = 7

160.5 ADC clock cycles

Implementations§

source§

impl Ts

source

pub const MAX: Self = Self::Cyc160

Maximum sample time, 160.5 ADC clock cycles.

Example
use stm32wlxx_hal::adc::Ts;

assert_eq!(Ts::MAX, Ts::Cyc160);
source

pub const MIN: Self = Self::Cyc1

Minimum sample time, 1.5 ADC clock cycles.

Example
use stm32wlxx_hal::adc::Ts;

assert_eq!(Ts::MIN, Ts::Cyc1);
source

pub const fn cycles(&self) -> Ratio<u16>

Number of cycles.

Example
use stm32wlxx_hal::adc::Ts;

assert!(f32::from(Ts::Cyc1.cycles()) - 1.5 < 0.001);
assert!(f32::from(Ts::Cyc3.cycles()) - 3.5 < 0.001);
assert!(f32::from(Ts::Cyc7.cycles()) - 7.5 < 0.001);
assert!(f32::from(Ts::Cyc12.cycles()) - 12.5 < 0.001);
assert!(f32::from(Ts::Cyc19.cycles()) - 19.5 < 0.001);
assert!(f32::from(Ts::Cyc39.cycles()) - 39.5 < 0.001);
assert!(f32::from(Ts::Cyc79.cycles()) - 79.5 < 0.001);
assert!(f32::from(Ts::Cyc160.cycles()) - 160.5 < 0.001);
source

pub const fn as_duration(&self, hz: u32) -> Duration

Get the cycles as a duration.

Fractional nano-seconds are rounded towards zero.

You can get the ADC frequency with Adc::clock_hz.

Example

Assuming the ADC clock frequency is 16 MHz.

use core::time::Duration;
use stm32wlxx_hal::adc::Ts;

const FREQ: u32 = 16_000_000;

assert_eq!(Ts::Cyc1.as_duration(FREQ), Duration::from_nanos(93));
assert_eq!(Ts::Cyc3.as_duration(FREQ), Duration::from_nanos(218));
assert_eq!(Ts::Cyc7.as_duration(FREQ), Duration::from_nanos(468));
assert_eq!(Ts::Cyc12.as_duration(FREQ), Duration::from_nanos(781));
assert_eq!(Ts::Cyc19.as_duration(FREQ), Duration::from_nanos(1_218));
assert_eq!(Ts::Cyc39.as_duration(FREQ), Duration::from_nanos(2_468));
assert_eq!(Ts::Cyc79.as_duration(FREQ), Duration::from_nanos(4_968));
assert_eq!(Ts::Cyc160.as_duration(FREQ), Duration::from_nanos(10_031));

Trait Implementations§

source§

impl Clone for Ts

source§

fn clone(&self) -> Ts

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Ts

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Ts

source§

fn default() -> Self

Reset value of the sample time.

source§

impl From<Ts> for u32

source§

fn from(ts: Ts) -> Self

Converts to this type from the input type.
source§

impl From<Ts> for u8

source§

fn from(ts: Ts) -> Self

Converts to this type from the input type.
source§

impl Ord for Ts

source§

fn cmp(&self, other: &Ts) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Ts

source§

fn eq(&self, other: &Ts) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Ts

source§

fn partial_cmp(&self, other: &Ts) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for Ts

source§

impl Eq for Ts

source§

impl StructuralEq for Ts

source§

impl StructuralPartialEq for Ts

Auto Trait Implementations§

§

impl RefUnwindSafe for Ts

§

impl Send for Ts

§

impl Sync for Ts

§

impl Unpin for Ts

§

impl UnwindSafe for Ts

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.