-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix/Add: Self-Test accelerometer and gyroscope
* Fix gyroscope self-test converting u12_4 to dps * Add accelerometer self-test * Add libm for libm::fabs
- Loading branch information
1 parent
0424495
commit 398f0cc
Showing
3 changed files
with
164 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
pub fn to_signed_u12_4_f32(value: i16) -> f32 { | ||
// Extract the integer part by shifting right 4 bits (keeping the sign) | ||
let integer_part = value >> 4; | ||
pub fn to_signed_u12_4_to_dps(raw_value: i16) -> f32 { | ||
// Extract the integer part (top 12 bits) | ||
let integer_part = raw_value >> 4; | ||
|
||
// Extract the fractional part by masking the lower 4 bits (as a positive value) | ||
let fractional_part = f32::from(value & 0xF) / 16.0; | ||
// Extract the fractional part (lower 4 bits) | ||
let fractional_mask = 0xF; // Mask to extract the lower 4 bits (0xF = 15) | ||
let fractional_part = f32::from(raw_value & fractional_mask) * 0.0625; // 1 / 2^4 = 0.0625 dps | ||
|
||
// Combine the integer and fractional parts | ||
f32::from(integer_part) + fractional_part | ||
} | ||
|
||
#[allow(clippy::suboptimal_flops)] | ||
pub fn abs_f32(value: f32) -> f32 { | ||
if value < 0.0 { | ||
-value | ||
} else { | ||
value | ||
} | ||
pub fn to_signed_u5_11_g(raw_value: i16) -> f32 { | ||
// Extract the integer part (top 5 bits) | ||
let integer_part = raw_value >> 11; | ||
|
||
// Extract the fractional part (lower 11 bits) | ||
let fractional_mask = 0x7FF; // Mask to extract the lower 11 bits (0x7FF = 2047) | ||
let fractional_part = f32::from(raw_value & fractional_mask) * 0.0005; // 0.5 mg = 0.0005 g | ||
|
||
// Combine the integer and fractional parts | ||
f32::from(integer_part) + fractional_part | ||
} |