diff options
author | Diego Barrios Romero <eldruin@gmail.com> | 2019-03-30 13:21:57 +0200 |
---|---|---|
committer | Diego Barrios Romero <eldruin@gmail.com> | 2019-03-31 13:41:26 +0200 |
commit | c8301c630051d0960e9738a6ab768b8836065e25 (patch) | |
tree | d0c1adcebd9d7b64d17fc24fb579aede47d7a477 /src/devices/features/tier1.rs | |
parent | 281e2eb97c694f4978e6d28eb51c5b8642224960 (diff) | |
download | ads1x1x-async-c8301c630051d0960e9738a6ab768b8836065e25.tar.gz ads1x1x-async-c8301c630051d0960e9738a6ab768b8836065e25.tar.xz ads1x1x-async-c8301c630051d0960e9738a6ab768b8836065e25.zip |
Code simplifications
Diffstat (limited to 'src/devices/features/tier1.rs')
-rw-r--r-- | src/devices/features/tier1.rs | 44 |
1 files changed, 22 insertions, 22 deletions
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<E>> { 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<DI, IC, MODE, E> Ads1x1x<DI, IC, ic::Resolution16Bit, MODE> where - DI: interface::WriteData<Error = E> + DI: interface::WriteData<Error = E>, { /// Set data rate pub fn set_data_rate(&mut self, rate: DataRate16Bit) -> Result<(), Error<E>> { 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(()) |