kxcj9 0.1.0

Platform-agnostic Rust driver for the KXCJ9 ultra-low-power tri-axis accelerometer.
Documentation

Rust KXCJ9 Ultra-Low-Power Tri-Axis Accelerometer

crates.io Docs Build Status Coverage Status Maintenance Intention

This is a platform agnostic Rust driver for the KXCJ9 ultra-low-power tri-axis accelerometer (up to +/-16g) using the embedded-hal traits.

This driver allows you to:

  • Enable/disable the device. See enable().
  • Read the acceleration measurement. See read().
  • Read the unscaled acceleration measurement. See read_unscaled().
  • Set resolution. See set_resolution().
  • Set output data rate. See set_output_data_rate().
  • Set +/- G range. See set_scale().
  • Read WHO_AM_I register. See who_am_i().
  • Perform a software reset. See reset().
  • Run a communication self-test. See self_test().

The device

The KXCJ9 is a high-performance, ultra-low-power, tri-axis accelerometer designed for mobile applications. It offers our best power performance along with an embedded wake-up feature, Fast-mode I²C and up to 14-bit resolution. The KXCJ9 sensor offers improved shock, reflow, and temperature performance, and the ASIC has internal voltage regulators that allow operation from 1.8 V to 3.6 V within the specified product performance.

The communication is done through an I2C bidirectional bus.

Datasheet:

Application Note:

Usage

To use this driver, import this crate and an embedded_hal implementation, then instantiate the appropriate device.

Please find additional examples using hardware in this repository: driver-examples

extern crate kxcj9;
extern crate linux_embedded_hal as hal;
use kxcj9::{Kxcj9, SlaveAddr};

fn main() {
    let dev = hal::I2cdev::new("/dev/i2c-1").unwrap();
    let address =  SlaveAddr::default();
    let mut sensor = Kxcj9::new_1018(dev, address);
    sensor.enable().unwrap();
    let acc = sensor.read().unwrap();
    println!("X: {:2}, Y: {:2}, Z: {:2}", acc.x, acc.y, acc.z);
}

Support

For questions, issues, feature requests, and other changes, please file an issue in the github project.

License

Licensed under either of

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.