From 5729b653ae5a95fe1af131dcbceb9dbb0397f4c6 Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Sun, 16 Nov 2025 01:16:30 +0100 Subject: mspm0: add example of MATHACL based & tested on mspm0g3507 --- examples/mspm0g3507/src/bin/mathacl_ops.rs | 37 ++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/mspm0g3507/src/bin/mathacl_ops.rs diff --git a/examples/mspm0g3507/src/bin/mathacl_ops.rs b/examples/mspm0g3507/src/bin/mathacl_ops.rs new file mode 100644 index 000000000..429cc5ad6 --- /dev/null +++ b/examples/mspm0g3507/src/bin/mathacl_ops.rs @@ -0,0 +1,37 @@ +//! Example of using mathematical calculations performed by the MSPM0G3507 chip. +//! +//! It prints the result of basics trigonometric calculation. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::mathacl::{Mathacl, Precision}; +use embassy_time::Timer; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + + let d = embassy_mspm0::init(Default::default()); + + let mut macl = Mathacl::new(d.MATHACL); + + // in range [-1,1) + let angle = 0.5; + match macl.sin(angle, Precision::High) { + Ok(res) => info!("sin({}) = {}", angle*180.0, res), + Err(e) => error!("sin Error: {:?}", e), + } + + match macl.cos(angle, Precision::Medium) { + Ok(res) => info!("cos({}) = {}", angle*180.0, res), + Err(e) => error!("cos Error: {:?}", e), + } + + loop { + Timer::after_millis(500).await; + } +} -- cgit