aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-mspm0/src/mathacl.rs10
-rw-r--r--examples/mspm0g3507/src/bin/mathacl_ops.rs4
2 files changed, 8 insertions, 6 deletions
diff --git a/embassy-mspm0/src/mathacl.rs b/embassy-mspm0/src/mathacl.rs
index 59687ce49..1b1c67a71 100644
--- a/embassy-mspm0/src/mathacl.rs
+++ b/embassy-mspm0/src/mathacl.rs
@@ -5,10 +5,10 @@
5#![macro_use] 5#![macro_use]
6 6
7use embassy_hal_internal::PeripheralType; 7use embassy_hal_internal::PeripheralType;
8use micromath::F32Ext;
8 9
9use crate::Peri; 10use crate::Peri;
10use crate::pac::mathacl::{Mathacl as Regs, vals}; 11use crate::pac::mathacl::{Mathacl as Regs, vals};
11use micromath::F32Ext;
12 12
13pub enum Precision { 13pub enum Precision {
14 High = 31, 14 High = 31,
@@ -64,7 +64,9 @@ impl Mathacl {
64 } 64 }
65 65
66 match signed_f32_to_register(angle, 0) { 66 match signed_f32_to_register(angle, 0) {
67 Ok(val) => self.regs.op1().write(|w| {w.set_data(val);}), 67 Ok(val) => self.regs.op1().write(|w| {
68 w.set_data(val);
69 }),
68 Err(er) => return Err(er), 70 Err(er) => return Err(er),
69 }; 71 };
70 72
@@ -142,7 +144,7 @@ fn signed_f32_to_register(data: f32, n_bits: u8) -> Result<u32, Error> {
142 let mut m = ((abs - abs.floor()) * (1u32 << shift) as f32).round() as u32; 144 let mut m = ((abs - abs.floor()) * (1u32 << shift) as f32).round() as u32;
143 145
144 // Handle trimming integer part 146 // Handle trimming integer part
145 if n_bits == 0 && n > 0 { 147 if n_bits == 0 && n > 0 {
146 m = 0x7FFFFFFF; 148 m = 0x7FFFFFFF;
147 } 149 }
148 150
@@ -189,7 +191,7 @@ fn register_to_signed_f32(data: u32, n_bits: u8) -> Result<f32, Error> {
189 let mut n = if n_bits == 0 { 191 let mut n = if n_bits == 0 {
190 0 192 0
191 } else if shift >= 32 { 193 } else if shift >= 32 {
192 data & n_mask 194 data & n_mask
193 } else { 195 } else {
194 (data >> shift) & n_mask 196 (data >> shift) & n_mask
195 }; 197 };
diff --git a/examples/mspm0g3507/src/bin/mathacl_ops.rs b/examples/mspm0g3507/src/bin/mathacl_ops.rs
index 429cc5ad6..06265ae18 100644
--- a/examples/mspm0g3507/src/bin/mathacl_ops.rs
+++ b/examples/mspm0g3507/src/bin/mathacl_ops.rs
@@ -22,12 +22,12 @@ async fn main(_spawner: Spawner) -> ! {
22 // in range [-1,1) 22 // in range [-1,1)
23 let angle = 0.5; 23 let angle = 0.5;
24 match macl.sin(angle, Precision::High) { 24 match macl.sin(angle, Precision::High) {
25 Ok(res) => info!("sin({}) = {}", angle*180.0, res), 25 Ok(res) => info!("sin({}) = {}", angle * 180.0, res),
26 Err(e) => error!("sin Error: {:?}", e), 26 Err(e) => error!("sin Error: {:?}", e),
27 } 27 }
28 28
29 match macl.cos(angle, Precision::Medium) { 29 match macl.cos(angle, Precision::Medium) {
30 Ok(res) => info!("cos({}) = {}", angle*180.0, res), 30 Ok(res) => info!("cos({}) = {}", angle * 180.0, res),
31 Err(e) => error!("cos Error: {:?}", e), 31 Err(e) => error!("cos Error: {:?}", e),
32 } 32 }
33 33