From ea70a003a8fb811ae211eb2320729ff223481e2f Mon Sep 17 00:00:00 2001 From: Bradley Myers Date: Sat, 9 Nov 2024 13:08:59 -0500 Subject: [PATCH] Moved status register to register module --- crates/ads126x/src/lib.rs | 48 ---------------------------------- crates/ads126x/src/register.rs | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/crates/ads126x/src/lib.rs b/crates/ads126x/src/lib.rs index 5e5931f..16816d0 100644 --- a/crates/ads126x/src/lib.rs +++ b/crates/ads126x/src/lib.rs @@ -7,7 +7,6 @@ mod register; use error::ADS126xError; use register::{Register, IdRegister, PowerRegister, InterfaceRegister}; -use bitflags::bitflags; use embedded_hal::spi::FullDuplex; use heapless::Vec; @@ -18,53 +17,6 @@ where spi: SPI, } -bitflags! { - pub struct StatusRegister: u8 { - const ADC2 = 0b1000_0000; - const ADC1 = 0b0100_0000; - const EXTCLK = 0b0010_0000; - const REF_ALM = 0b0001_0000; - const PGAL_ALM = 0b0000_1000; - const PGAH_ALM = 0b0000_0100; - const PGAD_ALM = 0b0000_0010; - const RESET = 0b0000_0001; - } -} - -impl StatusRegister { - pub fn is_adc2_data_new(&self) -> bool { - self.contains(StatusRegister::ADC2) - } - - pub fn is_adc1_data_new(&self) -> bool { - self.contains(StatusRegister::ADC1) - } - - pub fn is_extclk(&self) -> bool { - self.contains(StatusRegister::EXTCLK) - } - - pub fn is_ref_alm(&self) -> bool { - self.contains(StatusRegister::REF_ALM) - } - - pub fn is_pgal_alm(&self) -> bool { - self.contains(StatusRegister::PGAL_ALM) - } - - pub fn is_pgah_alm(&self) -> bool { - self.contains(StatusRegister::PGAH_ALM) - } - - pub fn is_pgad_alm(&self) -> bool { - self.contains(StatusRegister::PGAD_ALM) - } - - pub fn is_reset(&self) -> bool { - self.contains(StatusRegister::RESET) - } -} - pub enum ADCCommand { NOP, RESET, diff --git a/crates/ads126x/src/register.rs b/crates/ads126x/src/register.rs index 46d77bf..fc2df66 100644 --- a/crates/ads126x/src/register.rs +++ b/crates/ads126x/src/register.rs @@ -31,6 +31,53 @@ pub enum Register { ADC2FSC1 = 0x1A, } +bitflags! { + pub struct StatusRegister: u8 { + const ADC2 = 0b1000_0000; + const ADC1 = 0b0100_0000; + const EXTCLK = 0b0010_0000; + const REF_ALM = 0b0001_0000; + const PGAL_ALM = 0b0000_1000; + const PGAH_ALM = 0b0000_0100; + const PGAD_ALM = 0b0000_0010; + const RESET = 0b0000_0001; + } +} + +impl StatusRegister { + pub fn is_adc2_data_new(&self) -> bool { + self.contains(StatusRegister::ADC2) + } + + pub fn is_adc1_data_new(&self) -> bool { + self.contains(StatusRegister::ADC1) + } + + pub fn is_extclk(&self) -> bool { + self.contains(StatusRegister::EXTCLK) + } + + pub fn is_ref_alm(&self) -> bool { + self.contains(StatusRegister::REF_ALM) + } + + pub fn is_pgal_alm(&self) -> bool { + self.contains(StatusRegister::PGAL_ALM) + } + + pub fn is_pgah_alm(&self) -> bool { + self.contains(StatusRegister::PGAH_ALM) + } + + pub fn is_pgad_alm(&self) -> bool { + self.contains(StatusRegister::PGAD_ALM) + } + + pub fn is_reset(&self) -> bool { + self.contains(StatusRegister::RESET) + } +} + bitflags! { pub struct IdRegister: u8 { const _ = !0; // Source may set any bits