From 31332d220e1cb09578dc41dfe64157676413045d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Wed, 12 May 2021 12:59:58 +0200 Subject: [PATCH] remove unused dependencies --- Cargo.lock | 34 +++++++++++++++++++++++++++++++++- Cargo.toml | 3 +-- src/hardware/afe.rs | 24 ++++++------------------ 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b72b0be..20f83ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -200,6 +200,17 @@ dependencies = [ "cortex-m 0.7.2", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "derive_miniconf" version = "0.1.0" @@ -537,6 +548,27 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_enum" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "226b45a5c2ac4dd696ed30fa6b94b057ad909c7b7fc2e0d0808192bced894066" +dependencies = [ + "derivative", + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c0fd9eba1d5db0994a239e09c1be402d35622277e35468ba891aa5e3188ce7e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "panic-semihosting" version = "0.5.6" @@ -752,13 +784,13 @@ dependencies = [ "dsp", "embedded-hal", "enum-iterator", - "generic-array 0.14.4", "heapless 0.6.1", "log", "mcp23017", "miniconf", "minimq", "nb 1.0.0", + "num_enum", "panic-semihosting", "paste", "serde", diff --git a/Cargo.toml b/Cargo.toml index 3d57a47..2f8054f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,11 +39,10 @@ cortex-m-rtic = "0.5.6" embedded-hal = "0.2.4" nb = "1.0.0" asm-delay = "0.9.0" -enum-iterator = "0.6.0" +num_enum = { version = "0.5.1", default-features = false } paste = "1" dsp = { path = "dsp" } ad9959 = { path = "ad9959" } -generic-array = "0.14" miniconf = "0.1.0" shared-bus = {version = "0.2.2", features = ["cortex-m"] } serde-json-core = "0.3" diff --git a/src/hardware/afe.rs b/src/hardware/afe.rs index 962c417..35b7d66 100644 --- a/src/hardware/afe.rs +++ b/src/hardware/afe.rs @@ -2,11 +2,12 @@ use miniconf::Miniconf; use serde::{Deserialize, Serialize}; use core::convert::TryFrom; -use enum_iterator::IntoEnumIterator; +use num_enum::TryFromPrimitive; #[derive( - Copy, Clone, Debug, Serialize, Deserialize, IntoEnumIterator, Miniconf, + Copy, Clone, Debug, Serialize, Deserialize, TryFromPrimitive, Miniconf, )] +#[repr(u8)] pub enum Gain { G1 = 0b00, G2 = 0b01, @@ -32,20 +33,6 @@ impl Gain { } } -impl TryFrom for Gain { - type Error = (); - - fn try_from(value: u8) -> Result { - for gain in Gain::into_enum_iter() { - if value == gain as u8 { - return Ok(gain); - } - } - - Err(()) - } -} - impl ProgrammableGainAmplifier where A0: embedded_hal::digital::v2::StatefulOutputPin, @@ -82,7 +69,7 @@ where } /// Get the programmed gain of the analog front-end. - pub fn get_gain(&self) -> Result { + pub fn get_gain(&self) -> Gain { let mut code: u8 = 0; if self.a0.is_set_high().unwrap() { code |= 0b1; @@ -91,6 +78,7 @@ where code |= 0b10; } - Gain::try_from(code) + // NOTE(unwrap): All possibilities covered. + Gain::try_from(code).unwrap() } }