From 6437ec72cc00c0eccc48c7419f2c39472441f399 Mon Sep 17 00:00:00 2001 From: Bradley Myers Date: Tue, 5 Nov 2024 17:38:36 -0500 Subject: [PATCH] Convert CRC from enum to bitflag --- crates/ads126x/src/register.rs | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/crates/ads126x/src/register.rs b/crates/ads126x/src/register.rs index f7fa1f9..46d77bf 100644 --- a/crates/ads126x/src/register.rs +++ b/crates/ads126x/src/register.rs @@ -66,34 +66,11 @@ bitflags! { } bitflags! { + /// WARNING: If CRC is 0b11 set by ADC, it will reflect as CRC enabled not reserved. + /// CRC only accounts for 0b00 disabled and 0b01 enabled. pub struct InterfaceRegister: u8 { + const CRC = 0b0000_0001; const STATUS = 0b0000_0100; const TIMEOUT = 0b0000_1000; - - const _ = 0b0000_0011; // Source may set CDC bits - } -} - -pub enum Crc { - DISABLED = 0b00, - ENABLED = 0b01, -} - -impl InterfaceRegister { - pub fn get_crc(&self) -> Crc { - match self.bits() & 0b0000_0011 { - 0b00 => Crc::DISABLED, - 0b01 => Crc::ENABLED, - - 0b11 => panic!("Reserved state is set. Should not be 0b11."), - - // Exhaustive list for possible combinations of 2 bits - _ => unreachable!("Only 2 bits should be set.") - } - } - - pub fn set_crc(&mut self, crc: Crc) { - let crc_bits = crc as u8 & 0b0000_0011; - self.insert(InterfaceRegister::from_bits_truncate(crc_bits)); } }