rust bindings for the prebuilt cmsis-dsp math
Currently only requires unzip
and curl
cli commands. Happy to take prs to use pure rust instead. Downloads the cmsis math pack file during build.
```rust use cmsisdspsys::{armsinf32};
let sin = unsafe { armsinf32(core::f32::consts::PI) }; assert_eq!(sin, 0f32); ```
Its complicated. Im currently not building any c files that accompany the arm dsp libraries. Bringing the necessary libc, libm and abstracting against every possible architecture and build flag seems hopeless atm. As a result you're going to have to do some work on your end.
When you start to do anything complicated you're probably going to see something like:
```bash = note: rust-lld: error: undefined symbol: sqrtf
referenced by armmath.h:6841 (../../Include/armmath.h:6841) armcmplxmagf32.o:(armcmplxmagf32) in archive /home/jacob/Downloads/dsp-discoveryf4-rust/lab4/libarmcortexM4lfmath.a ```
Which means you need to bring some libm type function with you. Possibilitie pure rust options I've seen include libm or micromath with differing tradeoffs. Stub one in with:
```rust use micromath::F32Ext;
//C needs access to a sqrt fn, lets use micromath
pub extern "C" fn sqrtf(x: f32) -> f32 { x.sqrt() } ```
Further you're going to want to use something from armconststructs.c like armcfftsRf32len16 which uses tables in armcommontables.c. I would look those up inside the cmsis pack and translate it into some armcommontables.rs file in your project
```rust
pub const ARMBITREVINDEXTABLE16TABLE_LENGTH: u16 = 20;
pub static armBitRevIndexTable16: &[u16] = &[ /* 8x2, size 20 */ 8, 64, 24, 72, 16, 64, 40, 80, 32, 64, 56, 88, 48, 72, 88, 104, 72, 96, 104, 112, ];
pub static twiddleCoef_16: &[f32] = &[ 1.000000000, 0.000000000, 0.923879533, 0.382683432, 0.707106781, 0.707106781, 0.382683432, 0.923879533, 0.000000000, 1.000000000, -0.382683432, 0.923879533, -0.707106781, 0.707106781, -0.923879533, 0.382683432, -1.000000000, 0.000000000, -0.923879533, -0.382683432, -0.707106781, -0.707106781, -0.382683432, -0.923879533, -0.000000000, -1.000000000, 0.382683432, -0.923879533, 0.707106781, -0.707106781, 0.923879533, -0.382683432, ]; ```
```rust mod armcommontables; use armcommontables::{ armBitRevIndexTable16, twiddleCoef16, ARMBITREVINDEXTABLE16TABLELENGTH, }; use cmsisdspsys::{armcfftf32, armcfftinstancef32, armcmplxmagf32};
//your data as stored as real and imaginary pairs here let mut dtfsecoef = [0f32; 32];
let cfft = armcfftinstancef32 { fftLen: 16, pTwiddle: twiddleCoef16.asptr(), pBitRevTable: armBitRevIndexTable16.asptr(), bitRevLength: ARMBITREVINDEXTABLE16TABLE_LENGTH, };
let mut mag = [0f32; 16];
//Coefficient calculation with CFFT function unsafe {
//CFFT calculation
arm_cfft_f32(&cfft, dtfsecoef.as_mut_ptr(), 0, 1);
// Magnitude calculation
arm_cmplx_mag_f32(s.as_ptr(), mag.as_mut_ptr(), N::to_usize() as uint32_t);
} ```