Struct kxtj3_1057::Kxtj3

source ·
pub struct Kxtj3<I2C> { /* private fields */ }
Expand description

KXTJ3-1057 driver.

Implementations§

source§

impl<I2C, E> Kxtj3<I2C>
where I2C: WriteRead<Error = E> + Write<Error = E>,

source

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();     
source

pub fn get_device_id(&mut self) -> Result<u8, Error<E, Infallible>>

WHO_AM_I register.

source

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.

source

pub fn get_mode(&mut self) -> Result<Mode, Error<E, Infallible>>

Read the current operating mode.

source

pub fn set_datarate( &mut self, datarate: DataRate ) -> Result<(), Error<E, Infallible>>

Data rate selection.

source

pub fn get_datarate(&mut self) -> Result<DataRate, Error<E, Infallible>>

Read the current data selection rate.

source

pub fn set_range(&mut self, range: Range) -> Result<(), Error<E, Infallible>>

Set the acceleration Range

source

pub fn get_range(&mut self) -> Result<Range, Error<E, Infallible>>

Read the acceleration Range

source

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.

source

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>
where I2C: WriteRead<Error = E> + Write<Error = E>, E: Debug,

source§

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>>

Get the sample rate of the accelerometer data.

§

type Error = Error<E, Infallible>

Error type
source§

impl<I2C, E> RawAccelerometer<I16x3> for Kxtj3<I2C>
where I2C: WriteRead<Error = E> + Write<Error = E>, E: Debug,

§

type Error = Error<E, Infallible>

Error type
source§

fn accel_raw(&mut self) -> Result<I16x3, AccelerometerError<Self::Error>>

Get raw acceleration data from the accelerometer

Auto Trait Implementations§

§

impl<I2C> RefUnwindSafe for Kxtj3<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for Kxtj3<I2C>
where I2C: Send,

§

impl<I2C> Sync for Kxtj3<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for Kxtj3<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for Kxtj3<I2C>
where I2C: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.