updated example

This commit is contained in:
2026-02-10 12:15:35 +01:00
parent 8b19f784e1
commit 625a97b5ad

View File

@@ -13,11 +13,7 @@ use log::{error, info};
use mmc56x3::MMC56X3; use mmc56x3::MMC56X3;
#[panic_handler] #[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! { fn panic(_info: &core::panic::PanicInfo) -> ! {
for _ in 0..20 {
error!("PANIC: {info}");
}
info!("Doing cold boot from panic");
embassy_rp::rom_data::reset_to_usb_boot(0, 0); embassy_rp::rom_data::reset_to_usb_boot(0, 0);
loop {} loop {}
@@ -46,23 +42,30 @@ async fn main(spawner: Spawner) {
let i2c = I2c::new_async(p.I2C0, scl, sda, Irqs, i2c::Config::default()); let i2c = I2c::new_async(p.I2C0, scl, sda, Irqs, i2c::Config::default());
let mut device = MMC56X3::new(i2c, Delay); let mut device = MMC56X3::new(i2c, Delay);
device.init().await.expect("Failed to init"); if let Err(e) = device.init().await {
error!("Failed to init {:?}", e);
reboot().await;
};
device if let Err(e) = device.set_data_rate(mmc56x3::DataRate::Max1000Hz).await {
.set_data_rate(mmc56x3::DataRate::Hz(100)) error!("Failed to set data rate {:?}", e);
.await reboot().await;
.expect("Failed to set data rate"); }
device if let Err(e) = device.set_continuous_mode(true).await {
.set_continuous_mode(true) error!("Failed to set_continuous_mode {:?}", e);
.await reboot().await;
.expect("Failed to set continuous mode"); }
for _ in 0..20 { for _ in 0..200 {
Timer::after_secs(1).await; Timer::after_millis(50).await;
// let result = device.read_temperature().await; // let result = device.read_temperature().await;
// device.trigger_messurement().await.expect("Failed to trigger trigger_messurement"); // info!("T: {:?}", result);
// device
// .trigger_messurement()
// .await
// .expect("Failed to trigger trigger_messurement");
match device.read_messurement().await { match device.read_messurement().await {
Ok(d) => info!("Got: {:?}", d), Ok(d) => info!("Got: {:?}", d),
@@ -70,6 +73,10 @@ async fn main(spawner: Spawner) {
} }
} }
reboot().await;
}
async fn reboot() {
info!("Doing cold boot"); info!("Doing cold boot");
Timer::after_secs(1).await; Timer::after_secs(1).await;
embassy_rp::rom_data::reset_to_usb_boot(0, 0); embassy_rp::rom_data::reset_to_usb_boot(0, 0);