Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub source: ClockSource,
    pub frequency: u32,
}

Fields§

§source: ClockSource§frequency: u32

Implementations§

Source§

impl Config

Source

pub const fn default() -> Self

Examples found in repository?
examples/tsense.rs (line 21)
15pub extern "C" fn main() -> ! {
16    let peripherals = Peripherals::take().unwrap();
17
18    let rcc_config = RCC::default();
19    RCC::init(&rcc_config);
20
21    let sensor_config = Config::default()
22        .clock_from_source(ClockSource::HSI32M)
23        .with_frequency(SENSOR_CLOCK_HZ);
24
25    let mut sensor = TSENS::new(peripherals.tsens, &rcc_config.clocks, sensor_config).unwrap();
26
27    let mut current_temperature_c = sensor.single_measurement(Some(STARTUP_TIMEOUT)).unwrap();
28    let mut min_temperature_c = current_temperature_c;
29    let mut max_temperature_c = current_temperature_c;
30
31    sensor.start_continuous();
32
33    loop {
34        current_temperature_c = sensor.get_temperature();
35
36        if current_temperature_c < min_temperature_c {
37            min_temperature_c = current_temperature_c;
38        }
39
40        if current_temperature_c > max_temperature_c {
41            max_temperature_c = current_temperature_c;
42        }
43
44        let _temperature_snapshot = (current_temperature_c, min_temperature_c, max_temperature_c);
45
46        delay(SAMPLE_DELAY_SPINS);
47    }
48}
Source

pub fn clock_from_source(self, source: ClockSource) -> Self

Выбор источника тактирования термодатчика

§Arguments
  • source (ClockSource) - источник
§Returns
  • Self - объект конфигурации
§Examples
let _ = clock_from_source(ClockSource::OSC32K);
Examples found in repository?
examples/tsense.rs (line 22)
15pub extern "C" fn main() -> ! {
16    let peripherals = Peripherals::take().unwrap();
17
18    let rcc_config = RCC::default();
19    RCC::init(&rcc_config);
20
21    let sensor_config = Config::default()
22        .clock_from_source(ClockSource::HSI32M)
23        .with_frequency(SENSOR_CLOCK_HZ);
24
25    let mut sensor = TSENS::new(peripherals.tsens, &rcc_config.clocks, sensor_config).unwrap();
26
27    let mut current_temperature_c = sensor.single_measurement(Some(STARTUP_TIMEOUT)).unwrap();
28    let mut min_temperature_c = current_temperature_c;
29    let mut max_temperature_c = current_temperature_c;
30
31    sensor.start_continuous();
32
33    loop {
34        current_temperature_c = sensor.get_temperature();
35
36        if current_temperature_c < min_temperature_c {
37            min_temperature_c = current_temperature_c;
38        }
39
40        if current_temperature_c > max_temperature_c {
41            max_temperature_c = current_temperature_c;
42        }
43
44        let _temperature_snapshot = (current_temperature_c, min_temperature_c, max_temperature_c);
45
46        delay(SAMPLE_DELAY_SPINS);
47    }
48}
Source

pub fn with_frequency(self, frequency: u32) -> Self

Установка частоты встроенного термодатчика

§Arguments
  • frequency (u32) - частота
§Returns
  • Self - объект конфигурации
§Examples
let _ = with_frequency(40_000u32);
Examples found in repository?
examples/tsense.rs (line 23)
15pub extern "C" fn main() -> ! {
16    let peripherals = Peripherals::take().unwrap();
17
18    let rcc_config = RCC::default();
19    RCC::init(&rcc_config);
20
21    let sensor_config = Config::default()
22        .clock_from_source(ClockSource::HSI32M)
23        .with_frequency(SENSOR_CLOCK_HZ);
24
25    let mut sensor = TSENS::new(peripherals.tsens, &rcc_config.clocks, sensor_config).unwrap();
26
27    let mut current_temperature_c = sensor.single_measurement(Some(STARTUP_TIMEOUT)).unwrap();
28    let mut min_temperature_c = current_temperature_c;
29    let mut max_temperature_c = current_temperature_c;
30
31    sensor.start_continuous();
32
33    loop {
34        current_temperature_c = sensor.get_temperature();
35
36        if current_temperature_c < min_temperature_c {
37            min_temperature_c = current_temperature_c;
38        }
39
40        if current_temperature_c > max_temperature_c {
41            max_temperature_c = current_temperature_c;
42        }
43
44        let _temperature_snapshot = (current_temperature_c, min_temperature_c, max_temperature_c);
45
46        delay(SAMPLE_DELAY_SPINS);
47    }
48}

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Config

Source§

impl Debug for Config

Source§

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

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

impl Eq for Config

Source§

impl PartialEq for Config

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Config

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.