From c8301c630051d0960e9738a6ab768b8836065e25 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Sat, 30 Mar 2019 13:21:57 +0200 Subject: Code simplifications --- src/devices/features/tier1.rs | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/devices/features/tier1.rs') diff --git a/src/devices/features/tier1.rs b/src/devices/features/tier1.rs index 6bd1a99..9e5cb77 100644 --- a/src/devices/features/tier1.rs +++ b/src/devices/features/tier1.rs @@ -9,16 +9,16 @@ where /// Set data rate pub fn set_data_rate(&mut self, rate: DataRate12Bit) -> Result<(), Error> { use DataRate12Bit as DR; - let config; - match rate { - DR::Sps128 => config = self.config.with_low( BF::DR2).with_low( BF::DR1).with_low( BF::DR0), - DR::Sps250 => config = self.config.with_low( BF::DR2).with_low( BF::DR1).with_high(BF::DR0), - DR::Sps490 => config = self.config.with_low( BF::DR2).with_high(BF::DR1).with_low( BF::DR0), - DR::Sps920 => config = self.config.with_low( BF::DR2).with_high(BF::DR1).with_high(BF::DR0), - DR::Sps1600 => config = self.config.with_high(BF::DR2).with_low( BF::DR1).with_low( BF::DR0), - DR::Sps2400 => config = self.config.with_high(BF::DR2).with_low( BF::DR1).with_high(BF::DR0), - DR::Sps3300 => config = self.config.with_high(BF::DR2).with_high(BF::DR1).with_low( BF::DR0), - } + let cfg = self.config.clone(); + let config = match rate { + DR::Sps128 => cfg.with_low(BF::DR2).with_low(BF::DR1).with_low(BF::DR0), + DR::Sps250 => cfg.with_low(BF::DR2).with_low(BF::DR1).with_high(BF::DR0), + DR::Sps490 => cfg.with_low(BF::DR2).with_high(BF::DR1).with_low(BF::DR0), + DR::Sps920 => cfg.with_low(BF::DR2).with_high(BF::DR1).with_high(BF::DR0), + DR::Sps1600 => cfg.with_high(BF::DR2).with_low(BF::DR1).with_low(BF::DR0), + DR::Sps2400 => cfg.with_high(BF::DR2).with_low(BF::DR1).with_high(BF::DR0), + DR::Sps3300 => cfg.with_high(BF::DR2).with_high(BF::DR1).with_low(BF::DR0), + }; self.iface.write_register(Register::CONFIG, config.bits)?; self.config = config; Ok(()) @@ -27,22 +27,22 @@ where impl Ads1x1x where - DI: interface::WriteData + DI: interface::WriteData, { /// Set data rate pub fn set_data_rate(&mut self, rate: DataRate16Bit) -> Result<(), Error> { use DataRate16Bit as DR; - let config; - match rate { - DR::Sps8 => config = self.config.with_low( BF::DR2).with_low( BF::DR1).with_low( BF::DR0), - DR::Sps16 => config = self.config.with_low( BF::DR2).with_low( BF::DR1).with_high(BF::DR0), - DR::Sps32 => config = self.config.with_low( BF::DR2).with_high(BF::DR1).with_low( BF::DR0), - DR::Sps64 => config = self.config.with_low( BF::DR2).with_high(BF::DR1).with_high(BF::DR0), - DR::Sps128 => config = self.config.with_high(BF::DR2).with_low( BF::DR1).with_low( BF::DR0), - DR::Sps250 => config = self.config.with_high(BF::DR2).with_low( BF::DR1).with_high(BF::DR0), - DR::Sps475 => config = self.config.with_high(BF::DR2).with_high(BF::DR1).with_low( BF::DR0), - DR::Sps860 => config = self.config.with_high(BF::DR2).with_high(BF::DR1).with_high(BF::DR0), - } + let cfg = self.config.clone(); + let config = match rate { + DR::Sps8 => cfg.with_low(BF::DR2).with_low(BF::DR1).with_low(BF::DR0), + DR::Sps16 => cfg.with_low(BF::DR2).with_low(BF::DR1).with_high(BF::DR0), + DR::Sps32 => cfg.with_low(BF::DR2).with_high(BF::DR1).with_low(BF::DR0), + DR::Sps64 => cfg.with_low(BF::DR2).with_high(BF::DR1).with_high(BF::DR0), + DR::Sps128 => cfg.with_high(BF::DR2).with_low(BF::DR1).with_low(BF::DR0), + DR::Sps250 => cfg.with_high(BF::DR2).with_low(BF::DR1).with_high(BF::DR0), + DR::Sps475 => cfg.with_high(BF::DR2).with_high(BF::DR1).with_low(BF::DR0), + DR::Sps860 => cfg.with_high(BF::DR2).with_high(BF::DR1).with_high(BF::DR0), + }; self.iface.write_register(Register::CONFIG, config.bits)?; self.config = config; Ok(()) -- cgit v1.2.3-54-g00ecf