Platform-agnostic Rust support for the STMicroelectronics LIS2MDL 3-axis magnetometer.
Status: tested against a behavioral model of the chip (host tests and Wokwi), not yet verified on real hardware. See #6.
| Crate | Description |
|---|---|
lis2mdl-registers |
A typed map of the LIS2MDL's I²C/SPI registers. |
lis2mdl |
An embedded-hal 1.0 I²C/SPI driver (blocking and async). |
lis2mdl-sim |
A behavioral model of the chip for tests and emulation. |
The register map follows the LIS2MDL datasheet (DS12144). ST's official driver,
lis2mdl-rs, served as a cross-check; no code was taken from it.
The behavioral model in lis2mdl-sim is used as a fake I²C bus and SPI device in host tests.
Try it in the browser: an ESP32-C3 talking to the emulated LIS2MDL on wokwi.com. Click the chip and use its magnetic-field and temperature sliders.
Every GitHub Release carries the chip as
chip.zip. Add a chip-lis2mdl part and this dependency to your diagram.json, with the
latest release version written without the tag's v (@v0.2.1 fails to load):
"dependencies": { "chip-lis2mdl": "github:sunsided/lis2mdl@0.2.1" }This works on wokwi.com, in the Wokwi VS Code extension and with
wokwi-cli; nothing needs to be built.
For a browser demo, examples/arduino-esp32c3 has an
Arduino sketch and diagram.json to paste into a new wokwi.com project.
Needs wokwi-cli and a
WOKWI_CLI_TOKEN from the Wokwi CI dashboard:
task wokwi:testsim/wokwi-chip describes building the chip and its pins;
examples/esp32c3 the wiring and the scenario.
We abide by the Contributor Covenant and ask that you do as well.
Copyright © 2026 Markus Mayer
Triple licensed under your choice of either of:
- European Union Public Licence, Version 1.2, (LICENSE-EUPL or https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12)
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)