From bc0515cd9960d51fbcf367557b3c102196eb210c Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Sun, 11 Nov 2018 17:54:44 +0100 Subject: Rename data rate to be specific to the resolution --- src/devices/features/tier1.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/devices') diff --git a/src/devices/features/tier1.rs b/src/devices/features/tier1.rs index 30e900e..bd19419 100644 --- a/src/devices/features/tier1.rs +++ b/src/devices/features/tier1.rs @@ -1,8 +1,29 @@ //! Common functions -use { Ads1x1x, DataRate, Error, Register, BitFlags, interface }; +use { Ads1x1x, DataRate12Bit, Error, Register, BitFlags, interface, ic }; + +impl Ads1x1x +where + DI: interface::WriteData, +{ + /// Set data rate + pub fn set_data_rate(&mut self, rate: DataRate12Bit) -> Result<(), Error> { + let config; + match rate { + DataRate12Bit::Sps128 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), + DataRate12Bit::Sps250 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), + DataRate12Bit::Sps490 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), + DataRate12Bit::Sps920 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0), + DataRate12Bit::Sps1600 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), + DataRate12Bit::Sps2400 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), + DataRate12Bit::Sps3300 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), + } + self.iface.write_register(Register::CONFIG, config.bits)?; + self.config = config; + Ok(()) + } +} -impl Ads1x1x where DI: interface::WriteData { -- cgit v1.2.3-54-g00ecf