Skip to content

Commit

Permalink
Rename read_register to read_multiple_registers. Remove call to read_…
Browse files Browse the repository at this point in the history
…multiple_registers for a single register call.
  • Loading branch information
NoahSprenger committed Nov 5, 2024
1 parent 48c63fd commit 645acec
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions crates/ads126x/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ where
Ok(())
}

pub fn read_register(&mut self, reg: Register, num: u8) -> Result<Vec<u8, 27>, ADS126xError> {
pub fn read_multiple_registers(&mut self, reg: Register, num: u8) -> Result<Vec<u8, 27>, ADS126xError> {
if num > 27 {
return Err(ADS126xError::InvalidInputData);
}
Expand All @@ -135,9 +135,11 @@ where

/// Reads data from only the single provided register.
/// To read multiple registers, see [read_register](ADS126x::read_register).
pub fn read_single_register(&mut self, reg: Register) -> Result<u8, ADS126xError> {
let data = self.read_register(reg, 1)?;
Ok(data[0])
pub fn read_register(&mut self, reg: Register) -> Result<u8, ADS126xError> {
// zero since number of registers read - 1, so 1-1=0.
self.send_command(ADCCommand::RREG(reg, 0))?;
let data = self.spi.read().map_err(|_| ADS126xError::IO)?;
Ok(data)
}

pub fn write_register(&mut self, reg: Register, data: &[u8]) -> Result<(), ADS126xError> {
Expand All @@ -152,7 +154,7 @@ where
}

pub fn get_id(&mut self) -> Result<IdRegister, ADS126xError> {
let bits = self.read_single_register(Register::ID)?;
let bits = self.read_register(Register::ID)?;
let data = IdRegister::from_bits(bits);
match data {
Some(reg) => Ok(reg),
Expand All @@ -161,7 +163,7 @@ where
}

pub fn get_power(&mut self) -> Result<PowerRegister, ADS126xError> {
let bits = self.read_single_register(Register::POWER)?;
let bits = self.read_register(Register::POWER)?;
let data = PowerRegister::from_bits(bits);
match data {
Some(reg) => Ok(reg),
Expand All @@ -174,7 +176,7 @@ where
}

pub fn get_interface(&mut self) -> Result<InterfaceRegister, ADS126xError> {
let bits = self.read_single_register(Register::INTERFACE)?;
let bits = self.read_register(Register::INTERFACE)?;
let data = InterfaceRegister::from_bits(bits);
match data {
Some(reg) => Ok(reg),
Expand Down

0 comments on commit 645acec

Please sign in to comment.