Skip to main content

mpu9250/
conf.rs

1//! Configuration for MPU9250.
2
3use core::default::Default;
4use core::marker::PhantomData;
5
6use super::types;
7
8/// Controls the gyroscope and temperature sensor data rates and bandwidth.
9/// Can be either set to one of two FChoices, or to one of the 8
10/// digital low pass filter modes. If the DLPF mode is used rate and bandwith
11/// can be further tweaked by Sample Rate Divisor.
12/// See page 13 of [`Register map`] for details.
13/// Default is dlpf with default dlpf mode.
14#[derive(Copy, Clone, Debug)]
15pub enum GyroTempDataRate {
16    /// FChoice x0:
17    /// Gyroscope bandwidth=8800Hz, delay=0.064ms, Fs=32kHz;
18    /// Temperature sensor bandwidth=4000Hz, delay=0.04ms.
19    FChoice0, // Fchoice_b: 01 (inverted bits)
20    /// FChoice 01:
21    /// Gyroscope bandwidth=3600Hz, delay=0.11ms, Fs=32kHz;
22    /// Temperature sensor bandwidth=4000Hz, delay=0.04ms.
23    FChoice1, // Fchoice_b: 10
24    /// FChoice set to 11 and data rate and bandwidth are controlled
25    /// by Dlpf.
26    DlpfConf(Dlpf),
27}
28impl Default for GyroTempDataRate {
29    fn default() -> Self {
30        GyroTempDataRate::DlpfConf(Dlpf::default())
31    }
32}
33impl GyroTempDataRate {
34    pub(crate) fn fchoice_b_bits(&self) -> u8 {
35        match self {
36            GyroTempDataRate::FChoice0 => 0b01,
37            GyroTempDataRate::FChoice1 => 0b10,
38            GyroTempDataRate::DlpfConf(_) => 0b00,
39        }
40    }
41
42    pub(crate) fn dlpf_bits(&self) -> u8 {
43        match self {
44            GyroTempDataRate::FChoice0 => 0b000,
45            GyroTempDataRate::FChoice1 => 0b000,
46            GyroTempDataRate::DlpfConf(dlpf) => *dlpf as u8,
47        }
48    }
49}
50
51/// Controls the accelerometer data rate and bandwidth.
52/// Can be either set to FChoice, or to one of the 8
53/// digital low pass filter modes. If the DLPF mode is used rate and bandwith
54/// can be further tweaked by Sample Rate Divisor.
55/// See page 13 of [`Register map`] for details.
56/// Noise Density for all values is 300 μg/rtHz.
57/// Default is dlpf with default dlpf mode.
58#[derive(Copy, Clone, Debug)]
59pub enum AccelDataRate {
60    /// ACCEL_FCHOICE 0:
61    /// 3dB BW=1046Hz, delay=0.503ms, rate=4kHz.
62    FChoice0, // Fchoice_b: 1 (inverted bit)
63    /// FChoice set to 1 and data rate and bandwidth are controlled
64    /// by Dlpf; rate = 1kHz.
65    DlpfConf(Dlpf),
66}
67impl Default for AccelDataRate {
68    fn default() -> Self {
69        AccelDataRate::DlpfConf(Dlpf::default())
70    }
71}
72impl AccelDataRate {
73    pub(crate) fn accel_config_bits(&self) -> u8 {
74        match self {
75            AccelDataRate::FChoice0 => 0b00001000,
76            // 0x40 for 1024 bit fifo
77            AccelDataRate::DlpfConf(dlpf) => 0b01000000 | (*dlpf as u8),
78        }
79    }
80}
81
82/// Digital low pass filter configuration; default: _0;
83#[derive(Copy, Clone, Debug)]
84pub enum Dlpf {
85    /// Accelerometer: bandwitdh=218.Hz, delay=1.88ms;
86    /// Gyroscope: bandwidth=250Hz, delay=0.97ms, Fs=8kHz;
87    /// Temperature sensor: bandwidth=4000 Hz, delay=0.04ms.
88    _0 = 0,
89    /// Accelerometer: bandwidth=218.1Hz, delay=1.88ms;
90    /// Gyroscope: bandwidth=184Hz, delay=2.9ms, Fs=1kHz;
91    /// Temperature sensor: bandwidth=188Hz delay=1.9ms.
92    _1 = 1,
93    /// Accelerometer: bandwidth=99Hz, delay=2.88ms;
94    /// Gyroscope: bandwidth=92Hz, delay=3.9ms, Fs=1kHz;
95    /// Temperature sensor: bandwidth=92Hz, delay=2.8ms.
96    _2 = 2,
97    /// Accelerometer bandwidth=44.8Hz, delay=4.88ms;
98    /// Gyroscope: bandwidth=41Hz, delay=5.9ms, Fs=1kHz;
99    /// Temperature sensor: bandwidth=42Hz, delay=4.8ms.
100    _3 = 3,
101    /// Accelerometer: bandwidth=21.2Hz, delay=8.87ms;
102    /// Gyroscope: bandwidth=20Hz, delay=9.9ms, Fs=1kHz;
103    /// Temperature sensor: bandwidth=20Hz, delay=8.3ms.
104    _4 = 4,
105    /// Accelerometer: bandwidth=10.2Hz, delay=16.83ms;
106    /// Gyroscope: bandwidth=10Hz, delay=17.85ms, Fs=1kHz;
107    /// Temperature sensor: bandwidth=10Hz, delay=13.4ms.
108    _5 = 5,
109    /// Accelerometer: bandwidth=5.05Hz, delay=32.48ms;
110    /// Gyroscope: bandwidth=5Hz, delay=33.48ms, Fs=1kHz;
111    /// Temperature sensor: bandwidth=5Hz, delay=18.6ms.
112    _6 = 6,
113    /// Accelerometer: bandwidth=420Hz, delay=1.38ms;
114    /// Gyroscope: bandwidth=3600Hz, delay=0.17ms, Fs=8kHz;
115    /// Temperature sensor: bandwidth=4000Hz, delay=0.04ms.
116    _7 = 7,
117}
118impl Default for Dlpf {
119    fn default() -> Self {
120        Dlpf::_0
121    }
122}
123
124#[allow(non_camel_case_types)]
125#[derive(Copy, Clone, Debug)]
126/// Gyroscope reading full scale configuration; default: +250 dps.
127pub enum GyroScale {
128    /// +250 dps
129    _250DPS = 0,
130    /// +500 dps
131    _500DPS,
132    /// +1000 dps
133    _1000DPS,
134    /// +2000 dps
135    _2000DPS,
136}
137impl GyroScale {
138    pub(crate) fn resolution(&self) -> f32 {
139        match self {
140            GyroScale::_250DPS => 250.0 / 32768.0,
141            GyroScale::_500DPS => 500.0 / 32768.0,
142            GyroScale::_1000DPS => 1000.0 / 32768.0,
143            GyroScale::_2000DPS => 2000.0 / 32768.0,
144        }
145    }
146}
147impl Default for GyroScale {
148    fn default() -> Self {
149        GyroScale::_250DPS
150    }
151}
152
153#[allow(non_camel_case_types)]
154#[derive(Copy, Clone, Debug)]
155/// Accelerometer reading full scale configuration, default: +2g.
156pub enum AccelScale {
157    /// +2g
158    _2G = 0,
159    /// +4g
160    _4G,
161    /// +8g
162    _8G,
163    /// +16g
164    _16G,
165}
166impl AccelScale {
167    pub(crate) fn resolution(&self) -> f32 {
168        match self {
169            AccelScale::_2G => 2.0 / 32768.0,
170            AccelScale::_4G => 4.0 / 32768.0,
171            AccelScale::_8G => 8.0 / 32768.0,
172            AccelScale::_16G => 16.0 / 32768.0,
173        }
174    }
175}
176impl Default for AccelScale {
177    fn default() -> Self {
178        AccelScale::_2G
179    }
180}
181
182#[allow(non_camel_case_types)]
183#[derive(Copy, Clone, Debug)]
184/// Gyroscope reading full scale configuration; default: 0.6 mG per LSB
185pub enum MagScale {
186    /// 0.6 mG per LSB
187    _14BITS = 0,
188    /// 0.15 mG per LSB
189    _16BITS,
190}
191impl MagScale {
192    pub(crate) fn resolution(&self) -> f32 {
193        match self {
194            MagScale::_14BITS => 10. * 4912. / 8192.,
195            MagScale::_16BITS => 10. * 4912. / 32768.0,
196        }
197    }
198}
199impl Default for MagScale {
200    fn default() -> Self {
201        MagScale::_14BITS
202    }
203}
204
205#[derive(Copy, Clone, Debug)]
206/// Dmp data output rate, default 100Hz
207// rate = 200 / div - 1
208pub enum DmpRate {
209    /// Update data at 200Hz
210    _200Hz = 0,
211    /// Update data at 100Hz
212    _100Hz = 1,
213    /// Update data at 50Hz
214    _50Hz = 3,
215    /// Update data at 40Hz
216    _40Hz = 4,
217    /// Update data at 20Hz
218    _25Hz = 8,
219    /// Update data at 25Hz
220    _20Hz = 9,
221    /// Update data at 10Hz
222    _10Hz = 19,
223    /// Update data at 8Hz
224    _8Hz = 24,
225    /// Update data at 5Hz
226    _5Hz = 39,
227    /// Update data at 4Hz
228    _4Hz = 49,
229}
230impl Default for DmpRate {
231    fn default() -> Self {
232        DmpRate::_100Hz
233    }
234}
235
236#[derive(Copy, Clone, Debug)]
237/// DMP base orienatation, default Z axe pointing up
238pub enum Orientation {
239    /// Z axe pointing up
240    ZUp = 0x088,
241    /// Z axe pointing down
242    ZDown = 0x18c,
243    /// X axe pointing up
244    XUp = 0x00e,
245    /// X axe pointing down
246    XDown = 0x10a,
247    /// Y axe pointing up
248    YUp = 0x070,
249    /// Y axe pointing down
250    YDown = 0x150,
251    /// X pointing forward
252    XForward = 0x085,
253    /// X pointing forward
254    XBackward = 0x0a1,
255}
256#[cfg(feature = "dmp")]
257impl Orientation {
258    pub(crate) fn gyro_axes(&self) -> [u8; 3] {
259        const AXES: [u8; 3] = [0x4c, 0xcd, 0x6c];
260        [AXES[*self as usize & 3],
261         AXES[(*self as usize >> 3) & 3],
262         AXES[(*self as usize >> 6) & 3]]
263    }
264
265    pub(crate) fn accel_axes(&self) -> [u8; 3] {
266        const AXES: [u8; 3] = [0x0c, 0xc9, 0x2c];
267        [AXES[*self as usize & 3],
268         AXES[(*self as usize >> 3) & 3],
269         AXES[(*self as usize >> 6) & 3]]
270    }
271
272    pub(crate) fn gyro_signs(&self) -> [u8; 3] {
273        let mut sign: [u8; 3] = [0x36, 0x56, 0x76];
274        if *self as u16 & 0x002 != 0 {
275            sign[0] |= 1;
276        }
277        if *self as u16 & 0x020 != 0 {
278            sign[1] |= 1;
279        }
280        if *self as u16 & 0x100 != 0 {
281            sign[2] |= 1;
282        }
283        sign
284    }
285
286    pub(crate) fn accel_signs(&self) -> [u8; 3] {
287        let mut sign: [u8; 3] = [0x26, 0x46, 0x66];
288        if *self as u16 & 0x002 != 0 {
289            sign[0] |= 1;
290        }
291        if *self as u16 & 0x020 != 0 {
292            sign[1] |= 1;
293        }
294        if *self as u16 & 0x100 != 0 {
295            sign[2] |= 1;
296        }
297        sign
298    }
299}
300impl Default for Orientation {
301    fn default() -> Self {
302        Orientation::ZUp
303    }
304}
305
306#[derive(Copy, Clone, Debug)]
307/// Dmp features to enable, default with raw gyro and accel and 6 axes
308/// quaternion
309pub struct DmpFeatures {
310    /// DMP output raw gyro measurement
311    pub raw_gyro: bool,
312    /// DMP output raw accel measurement
313    pub raw_accel: bool,
314    /// DMP output tap motions detection
315    pub tap: bool,
316    /// DMP output orientation motions detection
317    pub android_orient: bool,
318    /// DMP output quaternion based on accelrometer and gyroscope
319    pub quat6: bool,
320    /// DMP output quaternion based on gyroscope only
321    pub quat: bool,
322    /// DMP auto calibrate gyro
323    pub gyro_auto_calibrate: bool,
324}
325#[cfg(feature = "dmp")]
326impl DmpFeatures {
327    pub(crate) fn packet_size(self) -> usize {
328        let mut size = 0;
329        if self.raw_gyro {
330            size += 6
331        }
332        if self.raw_accel {
333            size += 6
334        }
335        if self.quat | self.quat6 {
336            size += 16
337        }
338        if self.android_orient | self.tap {
339            size += 4
340        }
341        size
342    }
343}
344impl Default for DmpFeatures {
345    fn default() -> Self {
346        DmpFeatures { raw_gyro: true,
347                      raw_accel: true,
348                      tap: false,
349                      android_orient: false,
350                      quat6: true,
351                      quat: false,
352                      gyro_auto_calibrate: false }
353    }
354}
355
356#[derive(Copy, Clone, Debug)]
357/// Dmp configuration
358pub struct DmpConfiguration {
359    pub(crate) orientation: Orientation,
360    pub(crate) features: DmpFeatures,
361    pub(crate) rate: DmpRate,
362}
363impl Default for DmpConfiguration {
364    fn default() -> Self {
365        DmpConfiguration { orientation: Default::default(),
366                           features: Default::default(),
367                           rate: Default::default() }
368    }
369}
370
371/// Configuration of MPU9250
372#[derive(Copy, Clone, Debug)]
373pub struct MpuConfig<MODE> {
374    pub(crate) gyro_scale: Option<GyroScale>,
375    pub(crate) accel_scale: Option<AccelScale>,
376    pub(crate) mag_scale: Option<MagScale>,
377    pub(crate) accel_data_rate: Option<AccelDataRate>,
378    pub(crate) gyro_temp_data_rate: Option<GyroTempDataRate>,
379    pub(crate) sample_rate_divisor: Option<u8>,
380    pub(crate) dmp_configuration: Option<DmpConfiguration>,
381    _mode: PhantomData<MODE>,
382}
383
384impl MpuConfig<types::Imu> {
385    /// Creates configuration for [`Imu`] driver (accelerometer + gyroscope).
386    /// with default [`Accel scale`], [`Gyro scale`], [`Mag scale`],
387    /// [`AccelDataRate`], [`GyroTempDataRate`],
388    /// and no sample rate divisor.
389    ///
390    /// [`Imu`]: ./struct.Imu.html
391    /// [`Accel scale`]: ./enum.AccelScale.html
392    /// [`Gyro scale`]: ./enum.GyroScale.html
393    /// [`AccelDataRate`]: ./enum.AccelDataRate.html
394    /// [`GyroTempDataRate`]: ./enum.GyroTempDataRate.html
395    pub fn imu() -> Self {
396        MpuConfig { gyro_scale: None,
397                    accel_scale: None,
398                    mag_scale: None,
399                    accel_data_rate: None,
400                    gyro_temp_data_rate: None,
401                    sample_rate_divisor: None,
402                    dmp_configuration: None,
403                    _mode: PhantomData }
404    }
405}
406
407impl MpuConfig<types::Marg> {
408    /// Creates configuration for [`Marg`] driver
409    /// (accelerometer + gyroscope + magnetometer)
410    /// with default [`Accel scale`], [`Gyro scale`], [`Mag scale`],
411    /// [`AccelDataRate`], [`GyroTempDataRate`],
412    /// and no sample rate divisor.
413    ///
414    /// [`Marg`]: ./struct.Marg.html
415    /// [`Accel scale`]: ./enum.AccelScale.html
416    /// [`Gyro scale`]: ./enum.GyroScale.html
417    /// [`Mag scale`]: ./enum.MagScale.html
418    /// [`AccelDataRate`]: ./enum.AccelDataRate.html
419    /// [`GyroTempDataRate`]: ./enum.GyroTempDataRate.html
420    pub fn marg() -> Self {
421        MpuConfig { gyro_scale: None,
422                    accel_scale: None,
423                    mag_scale: None,
424                    accel_data_rate: None,
425                    gyro_temp_data_rate: None,
426                    sample_rate_divisor: None,
427                    dmp_configuration: None,
428                    _mode: PhantomData }
429    }
430}
431
432#[cfg(feature = "dmp")]
433impl MpuConfig<types::Dmp> {
434    /// Creates configuration for [`Dmp`] driver
435    /// (accelerometer + gyroscope + dmp)
436    /// with recommended [`Accel scale`], [`Gyro scale`], [`Mag scale`],
437    /// [`AccelDataRate`], [`GyroTempDataRate`], [`Dmp rate`]
438    /// and a sample rate of 200Hz. The default [`features`] and the
439    /// default [`orientation`] are used
440    ///
441    /// [`Dmp`]: ./struct.Dmp.html
442    /// [`Accel scale`]: ./enum.AccelScale.html
443    /// [`Gyro scale`]: ./enum.GyroScale.html
444    /// [`Mag scale`]: ./enum.MagScale.html
445    /// [`AccelDataRate`]: ./enum.AccelDataRate.html
446    /// [`GyroTempDataRate`]: ./enum.GyroTempDataRate.html
447    /// [`Dmp rate`]: ./enum.DmpRate.html
448    /// [`features`]: ./struct.DmpFeatures.html
449    /// [`orientation`]: ./enum.Orientation.html
450    pub fn dmp() -> Self {
451        MpuConfig { gyro_scale: Some(GyroScale::_2000DPS),
452                    accel_scale: Some(AccelScale::_8G),
453                    mag_scale: None,
454                    accel_data_rate: Some(AccelDataRate::DlpfConf(Dlpf::_1)),
455                    gyro_temp_data_rate:
456                        Some(GyroTempDataRate::DlpfConf(Dlpf::_1)),
457                    sample_rate_divisor: Some(4),
458                    dmp_configuration: None,
459                    _mode: PhantomData }
460    }
461
462    /// Sets dmp data output rate [`Dmp rate`]
463    ///
464    /// [`Dmp rate`]: ./enum.DmpRate.html
465    pub fn dmp_rate(&mut self, rate: DmpRate) -> &mut Self {
466        match self.dmp_configuration.as_mut() {
467            Some(mut x) => x.rate = rate,
468            None => {
469                self.dmp_configuration =
470                    Some(DmpConfiguration { rate,
471                                            ..Default::default() })
472            },
473        }
474        self
475    }
476
477    /// Sets dmp base [`orientation`]
478    ///
479    /// [`orientation`]: ./enum.Orientation.html
480    pub fn dmp_orientation(&mut self, orientation: Orientation) -> &mut Self {
481        match self.dmp_configuration.as_mut() {
482            Some(mut x) => x.orientation = orientation,
483            None => {
484                self.dmp_configuration =
485                    Some(DmpConfiguration { orientation,
486                                            ..Default::default() })
487            },
488        }
489        self
490    }
491
492    /// Selects [`dmp features`] to send raw gyro measurement
493    ///
494    /// [`dmp features`]: ./struct.DmpFeatures.html
495    pub fn dmp_features_raw_gyro(&mut self, feature: bool) -> &mut Self {
496        match self.dmp_configuration.as_mut() {
497            Some(mut x) => x.features.raw_gyro = feature,
498            None => self.dmp_configuration =
499                Some(DmpConfiguration { features:
500                                            DmpFeatures { raw_gyro: feature,
501                                                          ..Default::default() },
502                                        ..Default::default() }),
503        }
504        self
505    }
506
507    /// Selects [`dmp features`] to send raw accel measurement
508    ///
509    /// [`dmp features`]: ./struct.DmpFeatures.html
510    pub fn dmp_features_raw_accel(&mut self, feature: bool) -> &mut Self {
511        match self.dmp_configuration.as_mut() {
512            Some(mut x) => x.features.raw_accel = feature,
513            None => self.dmp_configuration =
514                Some(DmpConfiguration { features:
515                                            DmpFeatures { raw_accel: feature,
516                                                          ..Default::default() },
517                                        ..Default::default() }),
518        }
519        self
520    }
521
522    /// Selects [`dmp features`] to detect tap
523    ///
524    /// [`dmp features`]: ./struct.DmpFeatures.html
525    pub fn dmp_features_tap(&mut self, feature: bool) -> &mut Self {
526        match self.dmp_configuration.as_mut() {
527            Some(mut x) => x.features.tap = feature,
528            None => self.dmp_configuration =
529                Some(DmpConfiguration { features:
530                                            DmpFeatures { tap: feature,
531                                                          ..Default::default() },
532                                        ..Default::default() }),
533        }
534        self
535    }
536
537    /// Selects [`dmp features`] to send 3 axes quaternion
538    ///
539    /// [`dmp features`]: ./struct.DmpFeatures.html
540    pub fn dmp_features_quat(&mut self, feature: bool) -> &mut Self {
541        match self.dmp_configuration.as_mut() {
542            Some(mut x) => x.features.quat = feature,
543            None => self.dmp_configuration =
544                Some(DmpConfiguration { features:
545                                            DmpFeatures { quat: feature,
546                                                          ..Default::default() },
547                                        ..Default::default() }),
548        }
549        self
550    }
551
552    /// Selects [`dmp features`] to send 6 axes quaternion
553    ///
554    /// [`dmp features`]: ./struct.DmpFeatures.html
555    pub fn dmp_features_quat6(&mut self, feature: bool) -> &mut Self {
556        match self.dmp_configuration.as_mut() {
557            Some(mut x) => x.features.quat6 = feature,
558            None => self.dmp_configuration =
559                Some(DmpConfiguration { features:
560                                            DmpFeatures { quat6: feature,
561                                                          ..Default::default() },
562                                        ..Default::default() }),
563        }
564        self
565    }
566
567    /// Selects [`dmp features`] to auto calibrate gyro
568    ///
569    /// [`dmp features`]: ./struct.DmpFeatures.html
570    pub fn dmp_features_gyro_auto_calibrate(&mut self,
571                                            feature: bool)
572                                            -> &mut Self {
573        match self.dmp_configuration.as_mut() {
574            Some(mut x) => x.features.gyro_auto_calibrate = feature,
575            None => self.dmp_configuration =
576                Some(DmpConfiguration { features:
577                                            DmpFeatures { gyro_auto_calibrate:
578                                                              feature,
579                                                          ..Default::default() },
580                                        ..Default::default() }),
581        }
582        self
583    }
584
585    /// Selects [`dmp features`] to detect orientation changement
586    ///
587    /// [`dmp features`]: ./struct.DmpFeatures.html
588    pub fn dmp_features_orientation(&mut self, feature: bool) -> &mut Self {
589        match self.dmp_configuration.as_mut() {
590            Some(mut x) => x.features.android_orient = feature,
591            None => self.dmp_configuration =
592                Some(DmpConfiguration { features:
593                                            DmpFeatures { android_orient:
594                                                              feature,
595                                                          ..Default::default() },
596                                        ..Default::default() }),
597        }
598        self
599    }
600}
601
602impl<MODE> MpuConfig<MODE> {
603    /// Sets gyroscope full reading scale ([`Gyro scale`]).
604    ///
605    /// [`Gyro scale`]: ./enum.GyroScale.html
606    pub fn gyro_scale(&mut self, scale: GyroScale) -> &mut Self {
607        self.gyro_scale = Some(scale);
608        self
609    }
610
611    /// Sets accelerometer full reading scale ([`Accel scale`]).
612    ///
613    /// [`Accel scale`]: ./enum.AccelScale.html
614    pub fn accel_scale(&mut self, scale: AccelScale) -> &mut Self {
615        self.accel_scale = Some(scale);
616        self
617    }
618
619    /// Sets accelerometer data rate config ([`AccelDataRate`]).
620    ///
621    /// [`AccelDataRate`]: ./conf/enum.AccelDataRate.html
622    pub fn accel_data_rate(&mut self, data_rate: AccelDataRate) -> &mut Self {
623        self.accel_data_rate = Some(data_rate);
624        self
625    }
626
627    /// Sets gyroscope and temperatures data rate config
628    /// ([`GyroTempDataRate`]).
629    ///
630    /// [`GyroTempDataRate`]: ./enum.GyroTempDataRate.html
631    pub fn gyro_temp_data_rate(&mut self,
632                               data_rate: GyroTempDataRate)
633                               -> &mut Self {
634        self.gyro_temp_data_rate = Some(data_rate);
635        self
636    }
637
638    /// Sets sample rate divisor.
639    /// Sample rate divisor divides the internal sample rate to generate
640    /// the sample rate that controls sensor data output rate, FIFO sample
641    /// rate. NOTE: This register is only effective when dlpf mode used for
642    /// GyroTempDataRate see [`GyroTempDataRate`].
643    /// SampleRate = InternalSampleRate / (1 + SMPLRT_DIV).
644    ///
645    /// [`GyroTempDataRate`]: ./enum.GyroTempDataRate.html
646    pub fn sample_rate_divisor(&mut self, smplrt_div: u8) -> &mut Self {
647        self.sample_rate_divisor = Some(smplrt_div);
648        self
649    }
650}
651
652impl MpuConfig<types::Marg> {
653    /// Sets magnetrometer full reading scale ([`MagScale`])
654    ///
655    /// [`Mag scale`]: ./enum.MagScale.html
656    pub fn mag_scale(&mut self, scale: MagScale) -> &mut Self {
657        self.mag_scale = Some(scale);
658        self
659    }
660}
661
662bitflags! {
663    /// Enable interrupt for:
664    #[allow(non_camel_case_types)]
665    pub struct InterruptEnable: u8 {
666        /// Wake up on motion
667        const WOM_EN = 0b0100_0000;
668        /// FIFO overflow
669        const FIFO_OVERFLOW_EN = 0b0001_0000;
670        /// fsync
671        const FSYNC_INT_EN = 0b0000_1000;
672        /// raw sensor data ready
673        const RAW_RDY_EN = 0b0000_0001;
674    }
675}
676
677bitflags! {
678    /// Interrupt configuration
679    /// Defaults:
680    /// active high, push-pull, 50 us pulse, cleared only by reading INT_STATUS
681    #[allow(non_camel_case_types)]
682    pub struct InterruptConfig: u8 {
683        /// Sets logic level for INT pin is active low (high if not set)
684        const ACL = 0b1000_0000;
685        /// INT pin is configured as open drain (push pull if not set)
686        const OPEN = 0b0100_0000;
687        /// INT pin level held untilinterrupt status is cleared (cleared within 50us if not set)
688        const LATCH_INT_EN = 0b0010_0000;
689        /// Interrupt status is cleared if any read operation is performed (cleared only by reading INT_STATUS if not set)
690        const INT_ANYRD_CLEAR = 0b0001_0000;
691        /// The logic level for the FSYNC pin as an interrupt is active low (active high if not set)
692        const ACTL_FSYNC = 0b0000_1000;
693        /// This enables the FSYNC pin to be used as an interrupt.
694        /// A transition to the active level described by the ACTL_FSYNC bit
695        /// will cause an interrupt.  The status of the interrupt is read in
696        /// the I2C Master Status register PASS_THROUGH bit (disabled if not set)
697        const FSYNC_INT_MODE_EN = 0b0000_0100;
698        /// When asserted, the i2c_master interface pins(ES_CL and ES_DA) will
699        /// go into ‘bypass mode’ when the i2c master interface is disabled.
700        /// The pins will float high due to the internal pull-up if not enabled
701        /// and the i2c master interface is disabled
702        const BYPASS_EN = 0b0000_0010;
703    }
704}