Skip to content

Commit

Permalink
Merge pull request #4 from Ragarnoy/tweak-xe125-example
Browse files Browse the repository at this point in the history
Update radar logging and version retrieval, tweak 'xe125' example
  • Loading branch information
Ragarnoy authored Feb 17, 2024
2 parents 9b0e5bd + 81a36c5 commit 12ed052
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
6 changes: 1 addition & 5 deletions examples/xe125/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "probe-rs run --chip STM32L431CBYx --chip-erase --connect-under-reset --verify"
runner = "probe-rs run --chip STM32L431CBYx --connect-under-reset"

[target.thumbv7em-none-eabihf]
rustflags = [
Expand All @@ -13,7 +13,3 @@ target = "thumbv7em-none-eabihf"

[env]
DEFMT_LOG = "trace"

[net]
git-fetch-with-cli = true

21 changes: 17 additions & 4 deletions examples/xe125/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

use core::cell::RefCell;

use a121_rs::radar;
use a121_rs::radar::Radar;
use defmt::info;
use embassy_executor::Spawner;
use embassy_stm32::exti::ExtiInput;
Expand All @@ -15,7 +17,7 @@ use embassy_stm32::spi::{Config, Spi};
use embassy_stm32::time::Hertz;
use embassy_time::{Delay, Duration, Timer};
use embedded_hal_bus::spi::ExclusiveDevice;
use a121_rs::radar::Radar;
use radar::rss_version;
#[allow(unused_imports)]
use {defmt_rtt as _, panic_probe as _};

Expand Down Expand Up @@ -56,11 +58,17 @@ async fn main(_spawner: Spawner) {
enable.set_high();
Timer::after(Duration::from_millis(10)).await;

let radar = Radar::new(1, spi_mut_ref.get_mut(), interrupt).enable();
info!("RSS Version: {}", rss_version());

let mut radar = Radar::new(1, spi_mut_ref.get_mut(), interrupt).enable();
info!("Radar enabled");
let mut buffer = [0u8; 100];
let mut calibration = radar.sensor.calibrate(&mut buffer).await.unwrap();
radar
.sensor
.prepare(&radar.config, &mut calibration, &mut buffer)
.unwrap();

let rss_version = radar.version();
info!("RSS Version: {}", rss_version);
loop {
Timer::after(Duration::from_secs(1)).await;
info!("Hello, radar!");
Expand Down Expand Up @@ -113,3 +121,8 @@ pub extern "C" fn __hardfp_sinf(f: f32) -> f32 {
pub extern "C" fn __hardfp_roundf(f: f32) -> f32 {
libm::roundf(f)
}

#[no_mangle]
pub extern "C" fn __hardfp_sqrtf(f: f32) -> f32 {
libm::sqrtf(f)
}
4 changes: 2 additions & 2 deletions src/hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl AccHalImpl {
) {
let tmp_buf = unsafe { core::slice::from_raw_parts_mut(buffer, buffer_length) };
trace!(
"Transfer16 function called: buffer={:x} (size:{})",
"Transfer16 function called: buffer={:#X} (size:{})",
tmp_buf,
buffer_length
);
Expand All @@ -90,7 +90,7 @@ impl AccHalImpl {
let spi = binding.as_mut().unwrap_unchecked();
// Perform the SPI transfer
spi.transfer_in_place(tmp_buf).unwrap_unchecked();
trace!("Transfer16 function completed, buffer={:x}", tmp_buf);
trace!("Transfer16 function completed, buffer={:#X}", tmp_buf);
});
}

Expand Down
20 changes: 13 additions & 7 deletions src/radar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@ where

/// Radar Sensor Software Version
/// 0xMMMMmmPP where M is major, m is minor and P is patch
#[derive(Debug, defmt::Format)]
#[derive(Debug)]
pub struct RssVersion {
version: u32,
}

impl defmt::Format for RssVersion {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "{}.{}.{}", self.major(), self.minor(), self.patch())
}
}

impl Display for RssVersion {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{}.{}.{}", self.major(), self.minor(), self.patch())
Expand All @@ -43,11 +49,11 @@ impl RssVersion {
}

pub fn minor(&self) -> u8 {
((self.version & 0x0000FF00) >> 16) as u8
((self.version & 0x0000FF00) >> 8) as u8
}

pub fn patch(&self) -> u8 {
((self.version & 0x000000FF) >> 8) as u8
(self.version & 0x000000FF) as u8
}
}

Expand Down Expand Up @@ -92,9 +98,9 @@ where
pub fn id(&self) -> u32 {
self.id
}
}

pub fn version(&self) -> RssVersion {
let version = unsafe { acc_version_get_hex() };
RssVersion::new(version)
}
pub fn rss_version() -> RssVersion {
let version = unsafe { acc_version_get_hex() };
RssVersion::new(version)
}

0 comments on commit 12ed052

Please sign in to comment.