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>,
impl<I2C, E> Kxtj3<I2C>where
I2C: I2c<Error = E>,
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. 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();
pub fn new_with_config( i2c: I2C, address: SlaveAddr, config: Configuration ) -> Result<Self, Error<E, Infallible>>
sourcepub fn configure(
&mut self,
conf: Configuration
) -> Result<(), Error<E, Infallible>>
pub fn configure( &mut self, conf: Configuration ) -> Result<(), Error<E, Infallible>>
Configures the device
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 enable_standby_mode(&mut self) -> Result<(), Error<E, Infallible>>
pub fn enable_standby_mode(&mut self) -> Result<(), Error<E, Infallible>>
Enable stand-by mode .
CTRL_REG1
: PC1
bit.
sourcepub fn disable_standby_mode(&mut self) -> Result<(), Error<E, Infallible>>
pub fn disable_standby_mode(&mut self) -> Result<(), Error<E, Infallible>>
Disable stand-by mode .
CTRL_REG1
: PC1
bit.
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
: RES
bit.
Before using this function, the device must be in standby mode.
sourcepub fn get_mode(&mut self) -> Result<Mode, Error<E, Infallible>>
pub fn get_mode(&mut self) -> Result<Mode, Error<E, Infallible>>
Reads 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.
Before using this function, the device must be in standby mode.
sourcepub fn get_datarate(&mut self) -> Result<DataRate, Error<E, Infallible>>
pub fn get_datarate(&mut self) -> Result<DataRate, Error<E, Infallible>>
Reads 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>>
Sets the acceleration Range.
Before using this function, the device must be in standby mode.
sourcepub fn get_range(&mut self) -> Result<Range, Error<E, Infallible>>
pub fn get_range(&mut self) -> Result<Range, Error<E, Infallible>>
Reads the acceleration Range
sourcepub fn enable_new_accelration_interrupt(
&mut self
) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn enable_motion_detection(&mut self) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn enable_motion_detection_physical_interrupt_pin(
&mut self
) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn set_motion_detection_interrupt_pin_polarity(
&mut self,
polarity: InterruptPinPolarity
) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn set_motion_detection_interrupt_pin_response(
&mut self,
response: InterruptPinResponse
) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn set_motion_detection_datarate(
&mut self,
datarate: MotionDetectionDataRate
) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn get_motion_detection_datarate(
&mut self
) -> Result<MotionDetectionDataRate, Error<E, Infallible>>
pub fn get_motion_detection_datarate( &mut self ) -> Result<MotionDetectionDataRate, Error<E, Infallible>>
Reads the current data selection rate the motion detection function.
sourcepub fn set_motion_detection_latch_mode(
&mut self,
latch_mode: MotionDetectionLatchMode
) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn set_motion_detection_wakeup_counter(
&mut self,
wakeup_counter: u8
) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn set_motion_detection_na_counter(
&mut self,
na_counter: u8
) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn set_motion_detection_threshold(
&mut self,
desired_threshold: u8
) -> Result<(), Error<E, Infallible>>
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.
sourcepub fn get_motion_detection_axis(
&mut self
) -> Result<MotionDetectionAxis, Error<E, Infallible>>
pub fn get_motion_detection_axis( &mut self ) -> Result<MotionDetectionAxis, Error<E, Infallible>>
Reports the axis and direction of detected motion.
sourcepub fn is_motion_detected(&mut self) -> Result<bool, Error<E, Infallible>>
pub fn is_motion_detected(&mut self) -> Result<bool, Error<E, Infallible>>
Indicates Wake-up has occurred or not.
sourcepub fn is_acceleration_data_ready(
&mut self
) -> Result<bool, Error<E, Infallible>>
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 .
sourcepub 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>>
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.
sourcepub fn clear_motion_detection_lathced_info(
&mut self
) -> Result<(), Error<E, Infallible>>
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.
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.