tmag5170/
sensor_config.rs1pub enum AngleEn {
3 NoAngle = 0x00,
5
6 Xy = 0x01,
8
9 Yz = 0x02,
11
12 Zx = 0x03,
14}
15
16pub enum SleepTime {
19 Ms1 = 0x00,
21
22 Ms5 = 0x01,
24
25 Ms10 = 0x02,
27
28 Ms15 = 0x03,
30
31 Ms20 = 0x04,
33
34 Ms30 = 0x05,
36
37 Ms50 = 0x06,
39
40 Ms100 = 0x07,
42
43 Ms500 = 0x08,
45
46 Ms1000 = 0x09,
48}
49
50#[allow(non_camel_case_types)]
52pub enum MagChEn {
53 Off = 0x00,
55
56 X = 0x01,
58
59 Y = 0x02,
61
62 Xy = 0x03,
64
65 Z = 0x04,
67
68 Zx = 0x05,
70
71 Yz = 0x06,
73
74 Xyz = 0x07,
76
77 Xyx = 0x08,
79
80 Yxy = 0x09,
82
83 Yzy = 0x0a,
85
86 Zyz = 0x0b,
88
89 Zxz = 0x0c,
91
92 Xzx = 0x0d,
94
95 Xyzyx = 0x0e,
97
98 Xyzzyx = 0x0f,
100}
101
102#[allow(non_camel_case_types)]
104pub enum Range {
105 A1_50mT_A2_200mT = 0x00,
107
108 A1_25mT_A2_133mT = 0x01,
110
111 A1_100mT_A2_300mT = 0x02,
113}
114
115pub struct SensorConfig {
117 config: u16,
118}
119
120impl SensorConfig {
121 pub fn new() -> Self {
123 let config = 0x00;
124 SensorConfig { config }
125 }
126
127 pub fn form_u16(config: u16) -> Self {
129 SensorConfig { config }
130 }
131
132 pub fn to_u16(&self) -> u16 {
134 self.config
135 }
136
137 pub fn set_angle_en(mut self, angle_en: AngleEn) -> Self {
139 self.config = self.config & !(0b11 << 14) | ((angle_en as u16) << 14);
140 self
141 }
142
143 pub fn set_sleep_time(mut self, sleep_time: SleepTime) -> Self {
145 self.config = self.config & !(0b1111 << 10) | ((sleep_time as u16) << 10);
146 self
147 }
148
149 pub fn set_mag_ch_en(mut self, mag_ch_en: MagChEn) -> Self {
151 self.config = self.config & !(0b1111 << 6) | ((mag_ch_en as u16) << 6);
152 self
153 }
154
155 pub fn set_z_range(mut self, z_range: Range) -> Self {
157 self.config = self.config & !(0b11 << 4) | ((z_range as u16) << 4);
158 self
159 }
160
161 pub fn set_y_range(mut self, y_range: Range) -> Self {
163 self.config = self.config & !(0b11 << 2) | ((y_range as u16) << 2);
164 self
165 }
166
167 pub fn set_x_range(mut self, x_range: Range) -> Self {
169 self.config = self.config & !(0b11) | (x_range as u16);
170 self
171 }
172}
173
174impl Default for SensorConfig {
175 fn default() -> Self {
176 SensorConfig::new()
177 }
178}