embedded_drivers/onewire/
ds18b20.rs1use super::Device;
2
3pub struct DS18B20;
5
6pub const CMD_CONVERT_T: u8 = 0x44;
8pub const CMD_WRITE_SCRATCHPAD: u8 = 0x4e;
10pub const CMD_READ_SCRATCHPAD: u8 = 0xbe;
12pub const CMD_COPY_SCRATCHPAD: u8 = 0x48;
15pub const CMD_RECALL_EEPROM: u8 = 0xb8;
18pub const CMD_POWER_SUPPLY: u8 = 0xb4;
20
21#[repr(u8)]
22pub enum Resolution {
23 Nine = 0b000_11111,
24 Ten = 0b001_11111,
25 Eleven = 0b010_11111,
26 Twelve = 0b011_11111,
27}
28
29impl Resolution {
30 pub fn bits(&self) -> u8 {
31 match self {
32 Resolution::Nine => 9,
33 Resolution::Ten => 10,
34 Resolution::Eleven => 11,
35 Resolution::Twelve => 12,
36 }
37 }
38
39 pub fn conversion_time_ms(&self) -> u16 {
40 match self {
41 Resolution::Nine => 94,
42 Resolution::Ten => 188,
43 Resolution::Eleven => 375,
44 Resolution::Twelve => 750,
45 }
46 }
47}
48
49impl Default for Resolution {
50 fn default() -> Self {
51 Resolution::Twelve
52 }
53}
54
55pub struct Config {
56 pub resolution: Resolution,
57 pub t_h: i8,
58 pub t_l: i8,
59}
60
61impl Default for Config {
62 fn default() -> Self {
63 Config {
64 resolution: Resolution::Twelve,
65 t_h: 125,
66 t_l: -55,
67 }
68 }
69}
70
71pub trait DB18B20Ext {
72 fn set_config(&mut self, config: Config);
74
75 fn read_config(&mut self) -> Config;
76
77 fn start_measurement(&mut self);
79
80 fn read_measurement(&mut self) -> f32;
82
83 fn read_raw_measurement(&mut self) -> [u8; 2];
85
86 fn save_config(&mut self);
89
90 fn load_saved_config(&mut self);
92
93 fn is_parasite(&mut self) -> bool;
95}