1 unstable release
0.1.0 | Jan 4, 2019 |
---|
12KB
140 lines
Driver for the Bosch BMA222E and family
Currently this only support I2C configuration as I can't remove the itty bitty package from its home on a populated PCB. If you want to play with one, you can find them in Xfinity XR11 remote controls. 😊
The register maps in this family are very similar and so it should be possible to support the following chips with minimal changes to the code here:
- BMA222 - 8bit resolution
- BMA250 - 10bit resolution
- BMA253 - 12bit resolution
- BMA255 - 12bit resolution
- BMA280 - 14bit resolution
Specifically, these chips should work with the library now, but you wouldn't benefit from the enhanced resolution.
More info on the product line from Bosch's website: https://www.bosch-sensortec.com/bst/products/all_products/bma222e
What's currently supported
- Accessing the chip via I2C
- Reading X, Y, Z axis and whether they've updated since last poll
- Reading the event FIFO for X, Y, Z axis (32 element deep queue version of #1)
- Changing FIFO mode (stream, fifo, bypass) and reading how full the FIFO is
- Checking what data is in the EEPROM and how many writes it has left
- Software reset
- Reading temperature
What's not currently supported
If anything here seems meaningful to you, feel free to reach out and help implement these features. I just didn't need any of them personally.
- Any chip other than the BMA222E
- Accessing the chip via SPI
- Changing which axis are thrown on the FIFO
- Enabling interrupts for slope, tap, FIFO full, orientation, etc
- Tap detection
- Acceleration data filters
- Power modes (normal, deep sleep, low power, suspend)
- Lower power sleep duration
- Whether to shadow acceleration data or not
- Configuration of the INT1 and INT2 pins nor their sources
- Interrupt thresholds for acceleration, slope, etc
- FIFO watermark interrupt level
- Self-test
- Actually programming the EEPROM or setting the values
- Setting the offset compensation
- Offset compensation
- And many more!
Example usage:
fn main() {
// Get an instance of an i2c struct here with one of the [device crates](https://github.com/rust-embedded/awesome-embedded-rust#device-crates).
let mut accel = Bma222e::new(i2c);
accel.reset().unwrap();
examples(accel).unwrap();
}
fn examples(accel: Bma222e) -> Result<(), ()> {
let chip_id = accel.who_am_i()?;
println!("About to Begin. ID is {} and should be {}", chip_id, bma222e::IDENTIFIER)?;
let temp = accel.temperature()?;
println!("Temperature: {}", temp)?;
let writes_remaining = accel.eeprom_writes_remaining()?;
println!("EEPROM Writes Remaining: {}", writes_remaining)?;
let nvm_data = accel.eeprom_data()?;
hprint!("EEPROM Data: ")?;
for byte in &nvm_data {
hprint!("{:02X} ", byte)?;
}
println!()?;
// FIFO-related goodness!
// TODO: Find out why the output data wasn't consistent
let fifo_size = accel.fifo_size()?;
println!("Events in the FIFO: {}", fifo_size)?;
let mut events = [AxisData {value: 0, changed: false}; 3];
accel.fifo_set_mode(FIFOConfig::BYPASS)?;
accel.fifo_get(&mut events)?;
let x = accel.axis_x()?;
let y = accel.axis_y()?;
let z = accel.axis_z()?;
println!("X:{0:03} Y:{1:03} Z:{2:03}",
x.value,
y.value,
z.value)?;
Ok(())
}
Dependencies
~71KB