Skip to content

Commit

Permalink
Add {get,set}_u8_reg utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
ksedgwic committed Oct 20, 2022
1 parent 40d4139 commit 5b9c434
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ where

impl<I2C, E> Ft6X06<I2C>
where
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>,
I2C: i2c::WriteRead<Error = E> + i2c::Write<Error = E>, E: core::fmt::Debug
{
/// Creates a new sensor associated with an I2C peripheral.
///
Expand Down Expand Up @@ -274,6 +274,20 @@ where
Ok(value == 0)
}

/// Get the value of an 8 bit register
pub fn get_u8_reg(&self, i2c: &mut I2C, reg: u8) -> Result<u8, E> {
let mut ibuf: [u8; 1] = [0];
i2c.write_read(self.addr, &[reg], &mut ibuf)?;
Ok(ibuf[0])
}

/// Set the value of an 8 bit register
pub fn set_u8_reg(&self, i2c: &mut I2C, reg: u8, val: u8) -> Result<(), E> {
let obuf: [u8; 2] = [reg, val];
i2c.write(self.addr, &obuf)?;
Ok(())
}

/// Run an internal calibration on the FT6X06
pub fn ts_calibration(
&mut self,
Expand Down

0 comments on commit 5b9c434

Please sign in to comment.