adxl345_driver2 2.0.1

Driver for Analog Device ADXL345/ADXL346 3-Axis Digital Accelerometer
Documentation
<!DOCTYPE html><html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>
<h1>adxl345_driver2</h1>

<p>This is a hardware driver for [ADXL345] and [ADXL346] type 3-Axis
Digital Accelerometers written in [Rust] using [embedded-hal] <code>I2c</code> and <code>Spi</code> traits.
That means it runs on all hardware layers that implement the [embedded-hal] traits.</p>

<p>Although the name says adxl345 the driver should also work with the [ADXL346]
device as well since the only difference between them is the physical packaging
and not the internal workings.</p>

<p>This crate is a fork of the adxl345<em>driver crate.
This crate still is API compatible with the original adxl345</em>driver crate.</p>

<h2>Getting Started</h2>

<p>You will need to have a recent version of [Rust] installed.</p>

<p>This crate supports all hardware abstraction layers that implement the
[embedded-hal] <code>I2c</code> and <code>Spi</code> traits. That includes the [rppal] driver for
the Raspberry Pi. But it is not restricted to that platform. Platforms
that are known to work correctly are the Raspberry Pi with [rppal] and the
ESP32 with [esp-idf-hal]. But this crate is not restricted to these HAL layers.</p>

<h3>Using The Crate</h3>

<p>You can use <code>cargo add</code> to add the driver to your <code>Cargo.toml</code></p>

<p><code>sh
cargo add adxl345_driver2
</code></p>

<p>or you can manually add the driver to your <code>Cargo.toml</code>:</p>

<p><code>toml
[dependencies]
adxl345_driver2 = "2"
</code></p>

<h2>Examples</h2>

<p>You will find examples in the <code>examples</code> directory.
The Raspberry Pi I²C and SPI examples are available.</p>

<p>To build the I²C example start by clone this project somewhere on your Raspberry
Pi:</p>

<p><code>sh
git clone https://git.bues.ch/git/adxl345_driver2
</code></p>

<p>Next execute the follow to build the example:</p>

<p><code>sh
cd adxl345_driver2
cargo build --example rppal-i2c
</code></p>

<p>And finally execute the example:</p>

<p><code>sh
sudo ./target/debug/examples/rppal-i2c
</code></p>

<p>You should see the series of x, y, z values displayed in the terminal if your
device has been hooked up using the primary I²C that the example expects.</p>

<p>Output example:</p>

<p><code>console
axis: {'x': 1.6083, 'y': 0.0392, 'z': 8.7868} m/s²
axis: {'x': 1.6867, 'y': 0.1177, 'z': 8.7868} m/s²
axis: {'x': 1.6475, 'y': 0.1177, 'z': 8.8260} m/s²
...
</code></p>

<h2>no_std</h2>

<p>This crate can be used in <code>no_std</code> environments.
Just enable the <code>no_std</code> feature, if you want to build without <code>std</code> library.</p>

<p><code>no_std</code> currently only disables the implementation of <code>std::error::Error</code> for <code>AdxlError</code>.</p>

<p><code>toml
[dependencies]
adxl345_driver2 = { version = "2", features = ["no_std"] }
</code></p>

<h2>TODO</h2>

<ul>
<li>Most of the driver is currently implemented as <code>provided</code> methods in a chain of traits.
That is more complicated than it needs to be.
And it also exposes the low level bus access routines to the user API.
It would be better to have two trait based low level bus access structs for I²C and SPI
and then implement a driver struct that is generic over this trait.
The problem with this change is that it is a user visible API change.
Therefore, we'll keep the old implementation for now.</li>
</ul>

<h2>Licenses</h2>

<p>All code files are available under the <code>MIT</code> license.
You can find a copy of the license in the <code>LICENSE</code> file.</p>

<p>All additional documentation like this <code>README</code> is licensed under a
<a href="https://creativecommons.org/licenses/by-sa/4.0/">CC-BY-SA / Creative Commons Attribution-ShareAlike 4.0 International License</a>.</p>
</body></html>