Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ default = []
defmt-03 = ["dep:defmt"]
serde = ["dep:serde"]
async = ["dep:embedded-hal-async"]
postcard = ["dep:postcard"]
postcard-experimental = ["postcard", "postcard/experimental-derive"]

[dependencies]
embedded-hal = { version = "1" }
Expand All @@ -26,3 +28,4 @@ libm = "0.2"

serde = { version = "1", features = ["derive"], default-features = false, optional = true }
defmt = { version = "0.3", optional = true }
postcard = { version = "1", optional = true }
3 changes: 3 additions & 0 deletions src/accel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
pub struct Accel {
pub(crate) x: i16,
pub(crate) y: i16,
Expand Down Expand Up @@ -95,6 +96,7 @@ impl Accel {
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
pub enum AccelFullScale {
/// ±2g range (16384 LSB/g)
G2 = 0,
Expand Down Expand Up @@ -134,6 +136,7 @@ impl AccelFullScale {
#[derive(Debug, Clone, Copy)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
pub struct AccelF32 {
/// X-axis acceleration in g-force
x: f32,
Expand Down
1 change: 1 addition & 0 deletions src/gravity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::quaternion::Quaternion;
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
pub struct Gravity {
/// Forward/backward tilt component
pub x: f32,
Expand Down
15 changes: 15 additions & 0 deletions src/gyro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
pub struct Gyro {
pub(crate) x: i16,
pub(crate) y: i16,
Expand Down Expand Up @@ -61,6 +62,12 @@ impl Gyro {
}
}

impl From<Gyro> for [i16; 3] {
fn from(value: Gyro) -> Self {
[value.x, value.y, value.z]
}
}

/// Full-scale range settings for the gyroscope.
///
/// Each setting defines the maximum measurable rotation rate:
Expand All @@ -71,6 +78,7 @@ impl Gyro {
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
pub enum GyroFullScale {
/// ±250°/s range (131 LSB/°/s)
Deg250 = 0,
Expand Down Expand Up @@ -105,6 +113,7 @@ impl GyroFullScale {
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
pub struct GyroF32 {
/// Roll rate (°/s)
x: f32,
Expand All @@ -131,3 +140,9 @@ impl GyroF32 {
self.z
}
}

impl From<GyroF32> for [f32; 3] {
fn from(value: GyroF32) -> Self {
[value.x, value.y, value.z]
}
}
1 change: 1 addition & 0 deletions src/quaternion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "defmt-03", derive(defmt::Format))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "postcard-experimental", derive(postcard::experimental::max_size::MaxSize))]
pub struct Quaternion {
/// Scalar (real) component
pub w: f32,
Expand Down