1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use fpa::I30F2;
use nb;
use void::Void;
use crate::target::TEMP;
pub struct Temp(TEMP);
impl Temp {
pub fn new(raw: TEMP) -> Self {
Temp(raw)
}
pub fn measure(&mut self) -> I30F2 {
self.stop_measurement();
self.start_measurement();
nb::block!(self.read()).unwrap()
}
pub fn start_measurement(&mut self) {
unsafe {
self.0.tasks_start.write(|w| w.bits(1));
}
}
pub fn stop_measurement(&mut self) {
unsafe {
self.0.tasks_stop.write(|w| w.bits(1));
self.0.events_datardy.reset();
}
}
pub fn read(&mut self) -> nb::Result<I30F2, Void> {
if self.0.events_datardy.read().bits() == 0 {
return Err(nb::Error::WouldBlock);
} else {
self.0.events_datardy.reset();
let raw = self.0.temp.read().bits();
Ok(I30F2::from_bits(raw as i32))
}
}
}