From bcdb5e3c0ffbf401ee8747ff3887ca9ba00e177d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 10 May 2021 17:31:53 +0200 Subject: [PATCH] dsp/lowpass,lockin: const generics --- CHANGELOG.md | 4 ++++ Cargo.lock | 1 - README.md | 1 + dsp/Cargo.toml | 1 - dsp/benches/micro.rs | 7 +++---- dsp/src/lockin.rs | 5 ++--- dsp/src/lowpass.rs | 16 ++++++++++------ src/bin/lockin.rs | 3 +-- 8 files changed, 21 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04aa2fe..70665b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Added +* Telemetry + ### Changed +* Const generics bumping the MSRV to 1.51.0 + ### Fixed ## [v0.5.0] - 2021-04-21 diff --git a/Cargo.lock b/Cargo.lock index 06309e3..b72b0be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -215,7 +215,6 @@ name = "dsp" version = "0.1.0" dependencies = [ "easybench", - "generic-array 0.14.4", "libm", "miniconf", "ndarray", diff --git a/README.md b/README.md index 80cda1d..b6c1af7 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ to implement different use cases. Several applications are provides by default * Get [rustup](https://rustup.rs/) * `rustup target add thumbv7em-none-eabihf` * `cargo build --release` +* Minimum supported Rust version (MSRV) is 1.51.0 * When using debug (non `--release`) mode, increase the sample interval significantly. The added error checking code and missing optimizations may lead to the code missing deadlines and panicing. diff --git a/dsp/Cargo.toml b/dsp/Cargo.toml index 7b680d3..f9f680b 100644 --- a/dsp/Cargo.toml +++ b/dsp/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" [dependencies] libm = "0.2.1" serde = { version = "1.0", features = ["derive"], default-features = false } -generic-array = "0.14" num = { version = "0.4.0", default-features = false } miniconf = "0.1" diff --git a/dsp/benches/micro.rs b/dsp/benches/micro.rs index 22a2540..c3588df 100644 --- a/dsp/benches/micro.rs +++ b/dsp/benches/micro.rs @@ -1,7 +1,6 @@ use core::f32::consts::PI; use easybench::bench_env; -use generic_array::typenum::U4; use dsp::{atan2, cossin, iir, iir_int, Lowpass, PLL, RPLL}; @@ -72,13 +71,13 @@ fn iir_bench() { } fn lowpass_bench() { - let mut dut = Lowpass::::default(); + let mut dut = Lowpass::<4>::default(); println!( - "Lowpass::::update(x, k): {}", + "Lowpass::<4>::update(x, k): {}", bench_env((0x32421, 14), |(x, k)| dut.update(*x, *k)) ); println!( - "Lowpass::::update(x, 14): {}", + "Lowpass::<4>::update(x, 14): {}", bench_env(0x32421, |x| dut.update(*x, 14)) ); } diff --git a/dsp/src/lockin.rs b/dsp/src/lockin.rs index 613a133..a9f5e84 100644 --- a/dsp/src/lockin.rs +++ b/dsp/src/lockin.rs @@ -1,12 +1,11 @@ use super::{Complex, ComplexExt, Lowpass, MulScaled}; -use generic_array::ArrayLength; #[derive(Clone, Default)] -pub struct Lockin> { +pub struct Lockin { state: [Lowpass; 2], } -impl> Lockin { +impl Lockin { /// Update the lockin with a sample taken at a given phase. pub fn update(&mut self, sample: i32, phase: i32, k: u8) -> Complex { // Get the LO signal for demodulation and mix the sample; diff --git a/dsp/src/lowpass.rs b/dsp/src/lowpass.rs index 10d5838..265929b 100644 --- a/dsp/src/lowpass.rs +++ b/dsp/src/lowpass.rs @@ -1,16 +1,20 @@ -use generic_array::{ArrayLength, GenericArray}; - /// Arbitrary order, high dynamic range, wide coefficient range, /// lowpass filter implementation. DC gain is 1. /// /// Type argument N is the filter order. -#[derive(Clone, Default)] -pub struct Lowpass> { +#[derive(Clone)] +pub struct Lowpass { // IIR state storage - y: GenericArray, + y: [i32; N], } -impl> Lowpass { +impl Default for Lowpass { + fn default() -> Self { + Lowpass { y: [0i32; N] } + } +} + +impl Lowpass { /// Update the filter with a new sample. /// /// # Args diff --git a/src/bin/lockin.rs b/src/bin/lockin.rs index 944b87a..a187767 100644 --- a/src/bin/lockin.rs +++ b/src/bin/lockin.rs @@ -3,7 +3,6 @@ #![no_main] use embedded_hal::digital::v2::InputPin; -use generic_array::typenum::U4; use serde::Deserialize; @@ -92,7 +91,7 @@ const APP: () = { timestamper: InputStamper, pll: RPLL, - lockin: Lockin, + lockin: Lockin<4>, } #[init(spawn=[settings_update, telemetry])]