-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add CORDIC support * should fix CI failure * add example * require defmt for cordic example * put cordic stuff behind feature gate this will fail CI pending fix * significant refactor and dynamic mode * remove some erroneous whitespace, O -> OFFSET, more inline const exprs * simplify type signature, distinguish state vs feature
- Loading branch information
Showing
4 changed files
with
1,027 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#![deny(warnings)] | ||
#![deny(unsafe_code)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
extern crate cortex_m; | ||
extern crate cortex_m_rt as rt; | ||
extern crate stm32g4xx_hal as hal; | ||
|
||
use fixed::types::I1F15; | ||
use hal::cordic::{ | ||
func::{dynamic::Mode as _, scale::N0, Magnitude, SinCos, Sqrt}, | ||
prec::P60, | ||
types::{Q15, Q31}, | ||
Ext as _, | ||
}; | ||
use hal::prelude::*; | ||
use hal::pwr::PwrExt; | ||
use hal::rcc::Config; | ||
use hal::stm32; | ||
use rt::entry; | ||
|
||
#[macro_use] | ||
mod utils; | ||
|
||
use utils::logger::println; | ||
|
||
#[entry] | ||
fn main() -> ! { | ||
let dp = stm32::Peripherals::take().expect("cannot take peripherals"); | ||
let pwr = dp.PWR.constrain().freeze(); | ||
let mut rcc = dp.RCC.freeze(Config::hsi(), pwr); | ||
|
||
let mut cordic = dp | ||
.CORDIC | ||
.constrain(&mut rcc) | ||
.freeze::<Q15, Q31, SinCos, P60>(); // 16 bit arguments, 32 bit results, compute sine and cosine, 60 iterations | ||
|
||
// static operation (zero overhead) | ||
|
||
cordic.start(I1F15::from_num(-0.25 /* -45 degreees */)); | ||
|
||
let (sin, cos) = cordic.result(); | ||
|
||
println!("sin: {}, cos: {}", sin.to_num::<f32>(), cos.to_num::<f32>()); | ||
|
||
// dynamic operation | ||
|
||
let mut cordic = cordic.into_dynamic(); | ||
|
||
let sqrt = cordic.run::<Sqrt<N0>>(I1F15::from_num(0.25)); | ||
println!("sqrt: {}", sqrt.to_num::<f32>()); | ||
let magnitude = cordic.run::<Magnitude>((I1F15::from_num(0.25), I1F15::from_num(0.5))); | ||
println!("magnitude: {}", magnitude.to_num::<f32>()); | ||
|
||
loop {} | ||
} |
Oops, something went wrong.