diff options
author | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-11 18:04:37 +0100 |
---|---|---|
committer | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-11 18:04:37 +0100 |
commit | 62a9825c41fd0b859eeb2aa3a25b8f2a2eba58b5 (patch) | |
tree | e90146dca2fd075398c4231da12b98a77c602c17 /src | |
parent | fbb2099933e6e287d838995836a857127c18efa2 (diff) | |
download | ads1x1x-async-62a9825c41fd0b859eeb2aa3a25b8f2a2eba58b5.tar.gz ads1x1x-async-62a9825c41fd0b859eeb2aa3a25b8f2a2eba58b5.tar.xz ads1x1x-async-62a9825c41fd0b859eeb2aa3a25b8f2a2eba58b5.zip |
Add support for setting the data rate in 16bit devices
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/features/tier1.rs | 20 | ||||
-rw-r--r-- | src/lib.rs | 21 |
2 files changed, 32 insertions, 9 deletions
diff --git a/src/devices/features/tier1.rs b/src/devices/features/tier1.rs index bd19419..16ed96c 100644 --- a/src/devices/features/tier1.rs +++ b/src/devices/features/tier1.rs @@ -1,6 +1,6 @@ //! Common functions -use { Ads1x1x, DataRate12Bit, Error, Register, BitFlags, interface, ic }; +use { Ads1x1x, DataRate12Bit, DataRate16Bit, Error, Register, BitFlags, interface, ic }; impl<DI, IC, MODE, E> Ads1x1x<DI, IC, ic::Resolution12Bit, MODE> where @@ -24,20 +24,22 @@ where } } +impl<DI, IC, MODE, E> Ads1x1x<DI, IC, ic::Resolution16Bit, MODE> where DI: interface::WriteData<Error = E> { /// Set data rate - pub fn set_data_rate(&mut self, rate: DataRate) -> Result<(), Error<E>> { + pub fn set_data_rate(&mut self, rate: DataRate16Bit) -> Result<(), Error<E>> { let config; match rate { - DataRate::Sps128 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), - DataRate::Sps250 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), - DataRate::Sps490 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), - DataRate::Sps920 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0), - DataRate::Sps1600 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), - DataRate::Sps2400 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), - DataRate::Sps3300 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), + DataRate16Bit::Sps8 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), + DataRate16Bit::Sps16 => config = self.config.with_low( BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), + DataRate16Bit::Sps32 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), + DataRate16Bit::Sps64 => config = self.config.with_low( BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0), + DataRate16Bit::Sps128 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_low( BitFlags::DR0), + DataRate16Bit::Sps250 => config = self.config.with_high(BitFlags::DR2).with_low( BitFlags::DR1).with_high(BitFlags::DR0), + DataRate16Bit::Sps475 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_low( BitFlags::DR0), + DataRate16Bit::Sps860 => config = self.config.with_high(BitFlags::DR2).with_high(BitFlags::DR1).with_high(BitFlags::DR0), } self.iface.write_register(Register::CONFIG, config.bits)?; self.config = config; @@ -150,6 +150,27 @@ pub enum DataRate12Bit { Sps3300 } + +/// Data rate for ADS1113, ADS1114, ADS1115, ADS1118 +#[derive(Debug, Clone, PartialEq)] +pub enum DataRate16Bit { + /// 8 SPS + Sps8, + /// 16 SPS + Sps16, + /// 32 SPS + Sps32, + /// 64 SPS + Sps64, + /// 128 SPS (default) + Sps128, + /// 250 SPS + Sps250, + /// 475 SPS + Sps475, + /// 860 SPS + Sps860 +} /// Comparator mode (only for ADS1x14, ADS1x15) #[derive(Debug, Clone, PartialEq)] pub enum ComparatorMode { |