kxtj3_1057/config.rs
1//! This module provides definitions for configuring the accelerometer sensor.
2
3use crate::register::*;
4
5/// Sensor configuration options
6#[derive(Debug, Clone, Copy)]
7pub struct Configuration {
8 /// The operating mode, default [`Mode::HighResolution`].
9 pub mode: Mode,
10 /// The output data rate, default [`DataRate::Hz_6_25`].
11 pub datarate: DataRate,
12 /// The output acceleration range , default [`Range::G2`].
13 pub range: Range,
14 /// The reporting of the availability of new acceleration data as an interrupt , default [`false`]
15 pub enable_new_acceleration_interrupt: bool,
16 /// The Wake-Up (motion detect) function, default [`None`]
17 pub motion_detection: Option<MotionDetctionConfiguration>,
18}
19
20impl Default for Configuration {
21 fn default() -> Self {
22 Self {
23 mode: Mode::HighResolution,
24 datarate: DataRate::Hz_6_25,
25 range: Range::G2,
26 enable_new_acceleration_interrupt: false,
27 motion_detection: None,
28 }
29 }
30}
31
32/// Motion detction configuration options
33#[derive(Debug, Clone, Copy)]
34pub struct MotionDetctionConfiguration {
35 /// The Output Data Rate for the Wake-Up function (motion detection) , default [`MotionDetectionDataRate::Hz_6_25`]
36 pub datarate: MotionDetectionDataRate,
37 /// The latche mode of motion interrupt, default [`MotionDetectionLatchMode::Latched`] (clears after INT_REL is read)
38 pub latch_mode: MotionDetectionLatchMode,
39 /// The non-activity time required before another wake-up interrupt can be set , default `10` (1.6s)
40 pub non_activity_counter: u8,
41 /// The time motion must be present before a wake-up interrupt is set , default `1` (160ms)
42 pub wakeup_counter: u8,
43 /// The threshold for wake-up (motion detect) interrupt is set , default `128` (0.5g)
44 pub wakeup_threshold: u8,
45 /// The physical interrupt pin , default [`None`]
46 pub interrupt_pin: Option<InterruptPinConfiguration>,
47 /// The X- can cause an interrupt or not , default [`true`]
48 pub enable_x_negative: bool,
49 /// The X+ can cause an interrupt or not , default [`true`]
50 pub enable_x_positive: bool,
51 /// The Y- can cause an interrupt or not , default [`true`]
52 pub enable_y_negative: bool,
53 /// The Y+ can cause an interrupt or not , default [`true`]
54 pub enable_y_positive: bool,
55 /// The Z- can cause an interrupt or not , default [`true`]
56 pub enable_z_negative: bool,
57 /// The Z+ can cause an interrupt or not , default [`true`]
58 pub enable_z_positive: bool,
59}
60
61impl Default for MotionDetctionConfiguration {
62 fn default() -> Self {
63 Self {
64 datarate: MotionDetectionDataRate::Hz_6_25,
65 latch_mode: MotionDetectionLatchMode::Latched,
66 non_activity_counter: 10,
67 wakeup_counter: 1,
68 wakeup_threshold: 40,
69 interrupt_pin: None,
70 enable_x_negative: true,
71 enable_x_positive: true,
72 enable_y_negative: true,
73 enable_y_positive: true,
74 enable_z_negative: true,
75 enable_z_positive: true,
76 }
77 }
78}
79
80///Physical interrupt pin configuration options
81#[derive(Debug, Clone, Copy)]
82pub struct InterruptPinConfiguration {
83 /// The polarity of the physical interrupt pin , default [`InterruptPinPolarity::ActiveLow`]
84 pub polarity: InterruptPinPolarity,
85 /// The response of the physical interrupt pin , default [`InterruptPinResponse::Latched`]
86 pub response: InterruptPinResponse,
87}
88
89impl Default for InterruptPinConfiguration {
90 fn default() -> Self {
91 Self {
92 polarity: InterruptPinPolarity::ActiveLow,
93 response: InterruptPinResponse::Latched,
94 }
95 }
96}