From 8ba6242484308959bc24e84a8a77a28101679e1e Mon Sep 17 00:00:00 2001 From: Ian McIntyre Date: Sat, 29 Oct 2022 15:47:16 -0400 Subject: Explicitly match family variants in host impl Might help the next person who wants to add a new family. There's a way to defeat this lint when the enum is (Partial)Eq: use if / else to emulate a fallthrough. I can't find _another_ lint that would prevent that pattern, so I'll try to be vigilent here. --- src/host.rs | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/host.rs b/src/host.rs index f0fa512..2e47e50 100644 --- a/src/host.rs +++ b/src/host.rs @@ -3,6 +3,11 @@ //! See [`RuntimeBuilder::build`] to understand the linker script generation //! steps. +// Please explicitly match all `Family` variants. If someone wants to add +// a new `Family`, this will show help them find all the settings they need +// to consider. +#![warn(clippy::wildcard_enum_match_arm)] + use std::{ env, fmt::Display, @@ -54,10 +59,14 @@ pub enum FlexSpi { impl FlexSpi { fn family_default(family: Family) -> Self { - if Family::Imxrt1064 == family { - FlexSpi::FlexSpi2 - } else { - FlexSpi::FlexSpi1 + match family { + Family::Imxrt1064 => FlexSpi::FlexSpi2, + Family::Imxrt1010 + | Family::Imxrt1015 + | Family::Imxrt1020 + | Family::Imxrt1050 + | Family::Imxrt1060 + | Family::Imxrt1170 => FlexSpi::FlexSpi1, } } fn start_address(self, family: Family) -> Option { @@ -593,7 +602,11 @@ impl Family { fn fcb_offset(self) -> usize { match self { Family::Imxrt1010 | Family::Imxrt1170 => 0x400, - _ => 0x000, + Family::Imxrt1015 + | Family::Imxrt1020 + | Family::Imxrt1050 + | Family::Imxrt1060 + | Family::Imxrt1064 => 0x000, } } @@ -601,13 +614,17 @@ impl Family { /// /// This includes dedicated any OCRAM regions, if any exist for the chip. fn ocram_start(self) -> u32 { - if Family::Imxrt1170 == self { + match self { // 256 KiB offset from the OCRAM M4 backdoor. - 0x2024_0000 - } else { + Family::Imxrt1170 => 0x2024_0000, // Either starts the FlexRAM OCRAM banks, or the // dedicated OCRAM regions (for supported devices). - 0x2020_0000 + Family::Imxrt1010 + | Family::Imxrt1015 + | Family::Imxrt1020 + | Family::Imxrt1050 + | Family::Imxrt1060 + | Family::Imxrt1064 => 0x2020_0000, } } -- cgit v1.2.3