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
impl Ts
sourcepub const MAX: Self = Self::Cyc160
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);
sourcepub const MIN: Self = Self::Cyc1
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);
sourcepub const fn cycles(&self) -> Ratio<u16>
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);
sourcepub const fn as_duration(&self, hz: u32) -> Duration
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 Ord for Ts
impl Ord for Ts
source§impl PartialOrd for Ts
impl PartialOrd for Ts
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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 moreimpl Copy for Ts
impl Eq for Ts
impl StructuralEq for Ts
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more