diff options
Diffstat (limited to 'embassy-mspm0/src/mathacl.rs')
| -rw-r--r-- | embassy-mspm0/src/mathacl.rs | 10 |
1 files changed, 6 insertions, 4 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 | ||
| 7 | use embassy_hal_internal::PeripheralType; | 7 | use embassy_hal_internal::PeripheralType; |
| 8 | use micromath::F32Ext; | ||
| 8 | 9 | ||
| 9 | use crate::Peri; | 10 | use crate::Peri; |
| 10 | use crate::pac::mathacl::{Mathacl as Regs, vals}; | 11 | use crate::pac::mathacl::{Mathacl as Regs, vals}; |
| 11 | use micromath::F32Ext; | ||
| 12 | 12 | ||
| 13 | pub enum Precision { | 13 | pub 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 | }; |
