diff options
| author | eZio Pan <[email protected]> | 2024-03-22 00:58:03 +0800 |
|---|---|---|
| committer | eZio Pan <[email protected]> | 2024-03-23 09:15:25 +0800 |
| commit | 83069e7b49bd181236e6a68005ad6119d39b39c3 (patch) | |
| tree | 3f3608c796284194bae4e0c43c834dac85e0dfcb /examples/stm32h5 | |
| parent | 441aa4c8cede2b63cc55b51db6eb89b1e35671f9 (diff) | |
stm32 CORDIC: add example
Diffstat (limited to 'examples/stm32h5')
| -rw-r--r-- | examples/stm32h5/src/bin/cordic.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/stm32h5/src/bin/cordic.rs b/examples/stm32h5/src/bin/cordic.rs new file mode 100644 index 000000000..d49f75b8f --- /dev/null +++ b/examples/stm32h5/src/bin/cordic.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::*; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_stm32::cordic; | ||
| 7 | use {defmt_rtt as _, panic_probe as _}; | ||
| 8 | |||
| 9 | #[embassy_executor::main] | ||
| 10 | async fn main(_spawner: Spawner) { | ||
| 11 | let mut dp = embassy_stm32::init(Default::default()); | ||
| 12 | |||
| 13 | let mut cordic = cordic::Cordic::new( | ||
| 14 | &mut dp.CORDIC, | ||
| 15 | unwrap!(cordic::Config::new( | ||
| 16 | cordic::Function::Sin, | ||
| 17 | Default::default(), | ||
| 18 | Default::default(), | ||
| 19 | false, | ||
| 20 | )), | ||
| 21 | ); | ||
| 22 | |||
| 23 | let mut output = [0f64; 16]; | ||
| 24 | |||
| 25 | let arg1 = [1.0, 0.0, -1.0]; // for trigonometric function, the ARG1 value [-pi, pi] should be map to [-1, 1] | ||
| 26 | let arg2 = [0.5, 1.0]; | ||
| 27 | |||
| 28 | let cnt = unwrap!( | ||
| 29 | cordic | ||
| 30 | .async_calc_32bit(&mut dp.GPDMA1_CH0, &mut dp.GPDMA1_CH1, &arg1, Some(&arg2), &mut output,) | ||
| 31 | .await | ||
| 32 | ); | ||
| 33 | |||
| 34 | println!("async calc 32bit: {}", output[..cnt]); | ||
| 35 | } | ||
