Skip to content
sunsidedPublic

About

Rust driver and register map for the STMicroelectronics LIS2MDL magnetometer, with Wokwi emulation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

STMicroelectronics LIS2MDL Magnetometer

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.

Emulation

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.

Use the chip in your own Wokwi project

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.

Run the example locally

Needs wokwi-cli and a WOKWI_CLI_TOKEN from the Wokwi CI dashboard:

task wokwi:test

sim/wokwi-chip describes building the chip and its pins; examples/esp32c3 the wiring and the scenario.

Code of Conduct

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

License

Copyright © 2026 Markus Mayer

Triple licensed under your choice of either of:

About

Rust driver and register map for the STMicroelectronics LIS2MDL magnetometer, with Wokwi emulation

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages