Struct kxtj3_1057::Kxtj3
source · pub struct Kxtj3<I2C> { /* private fields */ }Expand description
KXTJ3-1057 driver.
Implementations§
source§impl<I2C, E> Kxtj3<I2C>
impl<I2C, E> Kxtj3<I2C>
sourcepub fn new(i2c: I2C, address: SlaveAddr) -> Result<Self, Error<E, Infallible>>
pub fn new(i2c: I2C, address: SlaveAddr) -> Result<Self, Error<E, Infallible>>
Create a new KXTJ3-1057 driver from the given I2C peripheral. Default is Hz_400 LowPower. An example using the esp_idf_hal:
use esp_idf_hal::i2c::*;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::prelude::*;
use kxtj3_1057::Kxtj3;
let peripherals = Peripherals::take().unwrap();
let i2c = peripherals.i2c0;
let sda = peripherals.pins.gpio10;
let scl = peripherals.pins.gpio8;
let config = I2cConfig::new().baudrate(400.kHz().into()).scl_enable_pullup(true).sda_enable_pullup(true);
let i2c = I2cDriver::new(i2c, sda, scl, &config).unwrap();
let kxtj3 = Kxtj3::new(i2c, kxtj3_1057::SlaveAddr::Default).unwrap(); sourcepub fn get_device_id(&mut self) -> Result<u8, Error<E, Infallible>>
pub fn get_device_id(&mut self) -> Result<u8, Error<E, Infallible>>
WHO_AM_I register.
sourcepub fn set_mode(&mut self, mode: Mode) -> Result<(), Error<E, Infallible>>
pub fn set_mode(&mut self, mode: Mode) -> Result<(), Error<E, Infallible>>
Controls the operating mode of the KXTJ3 .
CTRL_REG1: PC1 bit , CTRL_REG1: RES` bit.
sourcepub fn get_mode(&mut self) -> Result<Mode, Error<E, Infallible>>
pub fn get_mode(&mut self) -> Result<Mode, Error<E, Infallible>>
Read the current operating mode.
sourcepub fn set_datarate(
&mut self,
datarate: DataRate
) -> Result<(), Error<E, Infallible>>
pub fn set_datarate( &mut self, datarate: DataRate ) -> Result<(), Error<E, Infallible>>
Data rate selection.
sourcepub fn get_datarate(&mut self) -> Result<DataRate, Error<E, Infallible>>
pub fn get_datarate(&mut self) -> Result<DataRate, Error<E, Infallible>>
Read the current data selection rate.
sourcepub fn set_range(&mut self, range: Range) -> Result<(), Error<E, Infallible>>
pub fn set_range(&mut self, range: Range) -> Result<(), Error<E, Infallible>>
Set the acceleration Range
sourcepub fn register_clear_bits(
&mut self,
reg: Register,
bits: u8
) -> Result<(), Error<E, Infallible>>
pub fn register_clear_bits( &mut self, reg: Register, bits: u8 ) -> Result<(), Error<E, Infallible>>
Clear the given bits in the given register. For example:
kxtj3.register_clear_bits(0b0110)This call clears (sets to 0) the bits at index 1 and 2. Other bits of the register are not touched.
sourcepub fn register_set_bits(
&mut self,
reg: Register,
bits: u8
) -> Result<(), Error<E, Infallible>>
pub fn register_set_bits( &mut self, reg: Register, bits: u8 ) -> Result<(), Error<E, Infallible>>
Set the given bits in the given register. For example:
kxtj3.register_set_bits(0b0110)This call sets to 1 the bits at index 1 and 2. Other bits of the register are not touched.
Trait Implementations§
source§impl<I2C, E> Accelerometer for Kxtj3<I2C>
impl<I2C, E> Accelerometer for Kxtj3<I2C>
source§fn accel_norm(&mut self) -> Result<F32x3, AccelerometerError<Self::Error>>
fn accel_norm(&mut self) -> Result<F32x3, AccelerometerError<Self::Error>>
Get normalized ±g reading from the accelerometer.
source§fn sample_rate(&mut self) -> Result<f32, AccelerometerError<Self::Error>>
fn sample_rate(&mut self) -> Result<f32, AccelerometerError<Self::Error>>
Get the sample rate of the accelerometer data.