Compare commits

...

3 Commits

2 changed files with 39 additions and 21 deletions

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);

View File

@@ -269,6 +269,10 @@ where
self.magnet_set_reset().await?; self.magnet_set_reset().await?;
self.set_continuous_mode(false).await?; self.set_continuous_mode(false).await?;
// According to the datasheet this is recommended to
// be set to true
self.set_auto_set_reset(true).await?;
Ok(()) Ok(())
} }
@@ -290,11 +294,10 @@ where
} }
pub async fn set_continuous_mode(&mut self, enable: bool) -> Result<(), Error<I::Error>> { pub async fn set_continuous_mode(&mut self, enable: bool) -> Result<(), Error<I::Error>> {
if matches!(self.data_rate, DataRate::Unset) {
return Err(Error::NoDataRateSet);
}
if enable { if enable {
if matches!(self.data_rate, DataRate::Unset) {
return Err(Error::NoDataRateSet);
}
self.write_reg_controll_0(self.ctrl0 | Control0RegisterFlags::CMM_FRE_EN) self.write_reg_controll_0(self.ctrl0 | Control0RegisterFlags::CMM_FRE_EN)
.await?; .await?;
@@ -346,6 +349,14 @@ where
self.write_reg_controll_1(bandwidth.to_flags()).await self.write_reg_controll_1(bandwidth.to_flags()).await
} }
/// Enable or disable the automatic set/reset. This also impacts the maximum data rate.
pub async fn set_auto_set_reset(&mut self, enable: bool) -> Result<(), Error<I::Error>> {
self.ctrl0
.set(Control0RegisterFlags::AUTO_SET_RESET_EN, enable);
self.write_reg_controll_0(self.ctrl0).await?;
Ok(())
}
/// Read temperature in Celcius with steps of 0.8 C /// Read temperature in Celcius with steps of 0.8 C
pub async fn read_temperature(&mut self) -> Result<f32, Error<I::Error>> { pub async fn read_temperature(&mut self) -> Result<f32, Error<I::Error>> {
if self.is_continuous_mode() { if self.is_continuous_mode() {