1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//! Example of using the MS4525DO sensor with the blocking API.
//!
//! This example demonstrates how to read pressure and temperature data
//! from the MS4525DO sensor using the blocking/synchronous API.
//!
//! ## Hardware Requirements
//!
//! - MS4525DO sensor connected via I2C
//! - I2C bus configured at appropriate speed (typically 100-400 kHz)
//! - Sensor connected to default address 0x28
//!
//! ## Usage
//!
//! This is a no_std example that can be adapted for your specific platform.
//! You'll need to provide:
//! - An I2C peripheral that implements `embedded_hal::i2c::I2c`
//! - A delay provider that implements `embedded_hal::delay::DelayNs`
//! Note: This is a template example that needs to be adapted for your specific platform.
//! The code below is commented out as it requires platform-specific implementations.
//! Uncomment and modify according to your hardware setup.
// Uncomment for no_std embedded platforms:
// #![no_std]
// #![no_main]
// Note: You'll need to adjust these imports based on your platform
// This example shows the general structure for an embedded platform
// use ms4525do::blocking::Ms4525do;
// use ms4525do::calculate_airspeed;
// use embedded_hal::delay::DelayNs;
// Platform-specific imports (adjust for your platform)
// use your_hal::i2c::I2c;
// use your_hal::delay::Delay;
// use your_hal::prelude::*;
// #[entry]
// fn main() -> ! {
// // Initialize your platform's peripherals
// let peripherals = ...; // Platform-specific initialization
//
// // Configure I2C
// let i2c = I2c::new(
// peripherals.I2C0,
// sda_pin,
// scl_pin,
// 100_000, // 100 kHz
// );
//
// // Create delay provider
// let mut delay = Delay::new();
//
// // Create sensor instance
// let mut sensor = Ms4525do::new(i2c);
//
// loop {
// // Read sensor data
// match sensor.read_data(&mut delay) {
// Ok((pressure_pa, temp_c)) => {
// // Calculate airspeed from pressure and temperature
// let airspeed_ms = calculate_airspeed(pressure_pa, temp_c);
//
// // Log or use the data (adjust based on your platform)
// // println!("Pressure: {:.2} Pa", pressure_pa);
// // println!("Temperature: {:.2} °C", temp_c);
// // println!("Airspeed: {:.2} m/s", airspeed_ms);
// }
// Err(e) => {
// // Handle error (adjust based on your platform)
// // println!("Sensor error: {:?}", e);
//
// // Wait before retrying
// delay.delay_ms(100);
// }
// }
//
// // Read at ~50 Hz (adjust based on your requirements)
// delay.delay_ms(20);
// }
// }
// Panic handler (adjust for your platform)
// #[panic_handler]
// fn panic(_info: &core::panic::PanicInfo) -> ! {
// loop {}
// }
// Dummy main for example compilation