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

View File

@@ -269,6 +269,10 @@ where
self.magnet_set_reset().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(())
}
@@ -290,11 +294,10 @@ where
}
pub async fn set_continuous_mode(&mut self, enable: bool) -> Result<(), Error<I::Error>> {
if enable {
if matches!(self.data_rate, DataRate::Unset) {
return Err(Error::NoDataRateSet);
}
if enable {
self.write_reg_controll_0(self.ctrl0 | Control0RegisterFlags::CMM_FRE_EN)
.await?;
@@ -346,6 +349,14 @@ where
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
pub async fn read_temperature(&mut self) -> Result<f32, Error<I::Error>> {
if self.is_continuous_mode() {