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: I2c<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. An example using the esp_idf_hal:

use esp_idf_svc::hal::{delay::FreeRtos, i2c::*, prelude::Peripherals, units::Hertz};
use kxtj3_1057::{register::SlaveAddr, 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(Hertz(400_000)).scl_enable_pullup(true).sda_enable_pullup(true);
let i2c = I2cDriver::new(i2c, sda, scl, &config).unwrap();
let mut kxtj3 = Kxtj3::new(i2c, SlaveAddr::Default).unwrap();
source

pub fn new_with_config( i2c: I2C, address: SlaveAddr, config: Configuration ) -> Result<Self, Error<E, Infallible>>

source

pub fn configure( &mut self, conf: Configuration ) -> Result<(), Error<E, Infallible>>

Configures the device

source

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

WHO_AM_I register.

source

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

Enable stand-by mode . CTRL_REG1: PC1 bit.

source

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

Disable stand-by mode . CTRL_REG1: PC1 bit.

source

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

Controls the operating mode of the KXTJ3 . CTRL_REG1: RES bit. Before using this function, the device must be in standby mode.

source

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

Reads the current operating mode.

source

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

Data rate selection.

Before using this function, the device must be in standby mode.

source

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

Reads the current data selection rate.

source

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

Sets the acceleration Range.

Before using this function, the device must be in standby mode.

source

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

Reads the acceleration Range

source

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

Enables the reporting of the availability of new acceleration data as an interrupt.

Before using this function, the device must be in standby mode.

source

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

Enables the Wake-Up (motion detect) function.

Before using this function, the device must be in standby mode.

source

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

Enables the physical interrupt pin (INT).

Before using this function, the device must be in standby mode.

source

pub fn set_motion_detection_interrupt_pin_polarity( &mut self, polarity: InterruptPinPolarity ) -> Result<(), Error<E, Infallible>>

Sets the polarity of the physical interrupt pin

Before using this function, the device must be in standby mode.

source

pub fn set_motion_detection_interrupt_pin_response( &mut self, response: InterruptPinResponse ) -> Result<(), Error<E, Infallible>>

Sets the response of the physical interrupt pin.

Before using this function, the device must be in standby mode.

source

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

Sets the Output Data Rate for the motion detection function

Before using this function, the device must be in standby mode.

source

pub fn get_motion_detection_datarate( &mut self ) -> Result<MotionDetectionDataRate, Error<E, Infallible>>

Reads the current data selection rate the motion detection function.

source

pub fn set_motion_detection_latch_mode( &mut self, latch_mode: MotionDetectionLatchMode ) -> Result<(), Error<E, Infallible>>

Sets the motion detection latch mode.

Before using this function, the device must be in standby mode.

source

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

Sets the time motion must be present before a wake-up interrupt is set.

WAKEUP_COUNTER (counts) = Wake-Up Delay Time (sec) x Wake-Up Function ODR (Hz)

Before using this function, the device must be in standby mode.

source

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

Sets the non-activity time required before another wake-up interrupt can be set.

NA_COUNTER (counts) = Non-Activity Time (sec) x Wake-Up Function ODR (Hz)

Before using this function, the device must be in standby mode.

source

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

Sets the threshold for motion detection interrupt is set.

WAKEUP_THRESHOLD (counts) = Desired Threshold (g) x 256 (counts/g)

Before using this function, the device must be in standby mode.

source

pub fn get_motion_detection_axis( &mut self ) -> Result<MotionDetectionAxis, Error<E, Infallible>>

Reports the axis and direction of detected motion.

source

pub fn is_motion_detected(&mut self) -> Result<bool, Error<E, Infallible>>

Indicates Wake-up has occurred or not.

source

pub fn is_acceleration_data_ready( &mut self ) -> Result<bool, Error<E, Infallible>>

Indicates that new acceleration data (0x06 to 0x0B) is available or not .

source

pub fn enable_motion_detection_axes( &mut self, x_negative: bool, x_positive: bool, y_negative: bool, y_positive: bool, z_negative: bool, z_positive: bool ) -> Result<(), Error<E, Infallible>>

Sets which axes and directions of detected motion can cause an interrupt.

Before using this function, the device must be in standby mode.

source

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

Clears Latched interrupt source information (INT_SOURCE1 and INT_SOURCE2). Changes physical interrupt latched pin (INT) to inactive state.

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: I2c<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: I2c<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.