diff options
| -rw-r--r-- | examples/mspm0g3507/src/bin/mathacl_ops.rs | 37 |
1 files changed, 37 insertions, 0 deletions
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 @@ | |||
| 1 | //! Example of using mathematical calculations performed by the MSPM0G3507 chip. | ||
| 2 | //! | ||
| 3 | //! It prints the result of basics trigonometric calculation. | ||
| 4 | |||
| 5 | #![no_std] | ||
| 6 | #![no_main] | ||
| 7 | |||
| 8 | use defmt::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_mspm0::mathacl::{Mathacl, Precision}; | ||
| 11 | use embassy_time::Timer; | ||
| 12 | use {defmt_rtt as _, panic_halt as _}; | ||
| 13 | |||
| 14 | #[embassy_executor::main] | ||
| 15 | async fn main(_spawner: Spawner) -> ! { | ||
| 16 | info!("Hello world!"); | ||
| 17 | |||
| 18 | let d = embassy_mspm0::init(Default::default()); | ||
| 19 | |||
| 20 | let mut macl = Mathacl::new(d.MATHACL); | ||
| 21 | |||
| 22 | // in range [-1,1) | ||
| 23 | let angle = 0.5; | ||
| 24 | match macl.sin(angle, Precision::High) { | ||
| 25 | Ok(res) => info!("sin({}) = {}", angle*180.0, res), | ||
| 26 | Err(e) => error!("sin Error: {:?}", e), | ||
| 27 | } | ||
| 28 | |||
| 29 | match macl.cos(angle, Precision::Medium) { | ||
| 30 | Ok(res) => info!("cos({}) = {}", angle*180.0, res), | ||
| 31 | Err(e) => error!("cos Error: {:?}", e), | ||
| 32 | } | ||
| 33 | |||
| 34 | loop { | ||
| 35 | Timer::after_millis(500).await; | ||
| 36 | } | ||
| 37 | } | ||
