1#[derive(Copy, Clone, Debug)]
2#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3pub struct Config {
4 pub acc_range: AccRange,
5 pub gyr_range: GyrRange,
6 pub acc_unit: AccUnit,
7 pub gyr_unit: GyrUnit,
8 pub acc_dlp: AccDlp,
9 pub gyr_dlp: GyrDlp,
10 pub acc_odr: u16,
11 pub gyr_odr: u8,
12}
13
14impl Default for Config {
15 fn default() -> Self {
16 Self {
17 acc_range: AccRange::Gs2,
18 gyr_range: GyrRange::Dps1000,
19 acc_unit: AccUnit::Gs,
20 gyr_unit: GyrUnit::Dps,
21 acc_dlp: AccDlp::Disabled,
22 gyr_dlp: GyrDlp::Disabled,
23 acc_odr: 0,
24 gyr_odr: 0,
25 }
26 }
27}
28
29#[derive(Copy, Clone, Debug, Default)]
30pub enum I2cAddress {
31 X68,
33 #[default]
35 X69,
36 Any(u8),
38}
39
40impl From<u8> for I2cAddress {
41 fn from(address: u8) -> Self {
42 I2cAddress::Any(address)
43 }
44}
45
46impl I2cAddress {
47 pub const fn get(&self) -> u8 {
48 match self {
49 I2cAddress::X68 => 0x68,
50 I2cAddress::X69 => 0x69,
51 I2cAddress::Any(a) => *a,
52 }
53 }
54}
55
56#[derive(Copy, Clone, Debug)]
58#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
59pub enum AccRange {
60 Gs2 = 0b00,
61 Gs4 = 0b01,
62 Gs8 = 0b10,
63 Gs16 = 0b11,
64}
65
66impl AccRange {
67 pub const fn divisor(self) -> f32 {
68 match self {
69 Self::Gs2 => i16::MAX as f32 / 2.0,
70 Self::Gs4 => i16::MAX as f32 / 4.0,
71 Self::Gs8 => i16::MAX as f32 / 8.0,
72 Self::Gs16 => i16::MAX as f32 / 16.0,
73 }
74 }
75}
76
77#[derive(Copy, Clone, Debug)]
79#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
80pub enum GyrRange {
81 Dps250 = 0b00,
82 Dps500 = 0b01,
83 Dps1000 = 0b10,
84 Dps2000 = 0b11,
85}
86
87impl GyrRange {
88 pub const fn divisor(self) -> f32 {
89 match self {
90 Self::Dps250 => i16::MAX as f32 / 250.,
91 Self::Dps500 => i16::MAX as f32 / 500.,
92 Self::Dps1000 => i16::MAX as f32 / 1000.,
93 Self::Dps2000 => i16::MAX as f32 / 2000.,
94 }
95 }
96}
97
98#[derive(Copy, Clone, Debug)]
100#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
101pub enum AccUnit {
102 Mpss,
104 Gs,
106}
107
108impl AccUnit {
109 pub const fn scalar(self) -> f32 {
110 match self {
111 Self::Mpss => 9.82,
112 Self::Gs => 1.0,
113 }
114 }
115}
116
117#[derive(Copy, Clone, Debug)]
119#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
120pub enum GyrUnit {
121 Rps,
123 Dps,
125}
126
127impl GyrUnit {
128 pub const fn scalar(self) -> f32 {
129 match self {
130 Self::Rps => 1.0f32.to_radians(),
131 Self::Dps => 1.0f32,
132 }
133 }
134}
135
136#[derive(Copy, Clone, Debug, PartialEq)]
138#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
139pub enum AccDlp {
140 Hz473 = 7,
141 Hz246 = 1,
142 Hz111 = 2,
143 Hz50 = 3,
144 Hz24 = 4,
145 Hz12 = 5,
146 Hz6 = 6,
147 Disabled = 8,
148}
149
150#[derive(Copy, Clone, Debug, PartialEq)]
152#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
153pub enum GyrDlp {
154 Hz361 = 7,
155 Hz196 = 0,
156 Hz152 = 1,
157 Hz120 = 2,
158 Hz51 = 3,
159 Hz24 = 4,
160 Hz12 = 5,
161 Hz6 = 6,
162 Disabled = 8,
163}