#register #i2c #mems #embedded-hal #named-fields #lsm303dlhc

no-std lsm303dlhc-registers

A typed map of the STMicroelectronics LSM303DLHC E-Compass registers

3 releases

0.1.4 Jul 5, 2024
0.1.3 Jul 2, 2024
0.1.2 Jul 2, 2024
0.1.1 Jul 1, 2024
0.1.0 Jul 1, 2024

#1708 in Embedded development

21 downloads per month
Used in lsm303dlhc-ng

EUPL-1.2 OR MIT OR Apache-2.0

60KB
901 lines

STMicroelectronics LSM303DLHC E-Compass Registers

Crates.io Docs Build Status Safety Dance MSRV EUPL 1.2 licensed Apache 2.0 licensed MIT licensed

A typed map of the LSM303DLHC's I²C registers.

Provides functions and named fields to read and modify the sensor registers. For example:

fn configure_sensor(sensor: &mut LSM303DLHC) {
    // configure the accelerometer to operate at 400 Hz
    sensor.write_register(
        ControlRegister1A::new()
            .with_output_data_rate(AccelOdr::Hz400)
            .with_low_power_enable(false)
            .with_x_enable(true)
            .with_y_enable(true)
            .with_z_enable(true),
    )?;

    // Reset other accelerometer control registers.
    sensor.write_register(ControlRegister2A::new())?;
    sensor.write_register(ControlRegister3A::new())?;
    sensor.write_register(ControlRegister4A::new())?;
    sensor.write_register(ControlRegister5A::new())?;
    sensor.write_register(ControlRegister6A::new())?;

    // Configure the magnetometer to operate in continuous mode.
    sensor.write_register(
        ModeRegisterM::new()
            .with_sleep_mode(false)
            .with_single_conversion(false),
    )?;

    // Enable the temperature sensor.
    sensor.write_register(
        CraRegisterM::new()
            .with_temp_en(true)
            .with_data_output_rate(MagOdr::Hz75),
    )?;
}

Code of Conduct

We abide by the Contributor Covenant and ask that you do as well.

License

Copyright © 2024 Markus Mayer

Triple licensed under your choice of either of:

This work includes parts of Jorge Aparicio's lsm303dlhc crate, made available under MIT and Apache 2.0 licenses.

Dependencies

~260–760KB
~18K SLoC