Expand description
Platform-agnostic no_std driver for the TI TMAG5273 3-axis Hall-effect sensor.
This crate provides a type-safe, zero-allocation driver for the TMAG5273 family
of linear 3D Hall-effect sensors over I2C, using embedded-hal 1.0 traits.
§Supported Variants
All eight TMAG5273 variants are supported (A1, A2, B1, B2, C1, C2, D1, D2), differing in default I2C address and magnetic field sensitivity range.
| Variant | Address | XY range (low / high) | Z range (low / high) |
|---|---|---|---|
| A1, B1, C1, D1 | 0x35, 0x22, 0x78, 0x44 | ±40 / ±80 mT | ±40 / ±80 mT |
| A2, B2, C2, D2 | 0x35, 0x22, 0x78, 0x44 | ±133 / ±266 mT | ±133 / ±266 mT |
§Quick Start
Three ways to construct the driver (simplest first):
use tmag5273::{Tmag5273, DeviceVariant, ConfigBuilder};
// Option 1: Plug-and-play — scans all known addresses, auto-detects variant
// let sensor = Tmag5273::scan(i2c).expect("no TMAG5273 found");
// Option 2: Known address, auto-detect variant
// let sensor = Tmag5273::detect(i2c, 0x22).expect("no sensor at 0x22");
// Option 3: Fully explicit — no I2C activity until init()
let sensor = Tmag5273::new(i2c, DeviceVariant::B1);
// Configure and initialize
let config = ConfigBuilder::new().build().unwrap();
// let mut sensor = sensor.init(&config).unwrap();
// Read measurements
// let mag = sensor.read_magnetic().unwrap();
// let temp = sensor.read_temperature().unwrap();
// let all = sensor.read_all().unwrap(); // coherent temp + mag in one burst§Features
crc— Enables CRC-8 validation on I2C reads (disables burst reads)defmt— Enablesdefmt::Formatderives on all public typeslibm— Enables the L3 analysis layer:magnitude_3d(),plane_angles()with per-plane angle/magnitude,AxisCalibratorfor auto-detecting the optimal hardware angle axis pair, and related types (PlaneAxis,PlaneAngle,PlaneAngles,AxisRecommendation)
Structs§
- Angle
Reading - Angle measurement result from the TMAG5273 angle engine.
- Axis
Calibrator libm - Accumulates per-axis running statistics from
MagneticReadingsamples and recommends the optimal hardware angle configuration. - Axis
Recommendation libm - Recommended hardware angle configuration from
AxisCalibrator::recommend. - Calibration
Config - Magnetic gain and offset calibration configuration.
- Celsius
- Temperature in degrees Celsius.
- Config
- Validated device configuration for the TMAG5273.
- Config
Builder - Builder for validated
Config. - Configured
- Typestate marker type: sensor has been initialized and is ready for measurement.
- Conversion
Status - Parsed contents of the
CONV_STATUSregister (0x18). - Cordic
- CORDIC-based angle tracking mode.
- Cordic
Magnitude - Hardware-computed 2-axis CORDIC magnitude in millitesla.
- Crossings
- Total zero-crossings counted by a
ZeroCrossingtracker. - Degrees
- Absolute sensor angle in degrees, always in the range [0°, 360°].
- Device
Status - Parsed contents of the
DEVICE_STATUSregister (0x1C). - Init
Error - Initialization failure that returns the I2C bus and delay backend to the caller.
- Interrupt
Config - Interrupt configuration for the TMAG5273.
- Lsb
- Raw 8-bit threshold register value.
- Magnetic
Reading - Magnetic field reading from all enabled axes.
- Micros
Isr - Duration in micros_isreconds.
- Micros
Range - A range of micros_isrecond durations, matching Linux
usleep_range(min, max)semantics. - Milli
Tesla - Magnetic flux density in millitesla.
- NoDelay
- Zero-sized no-op delay backend (default).
- Plane
Angle libm - Angle and magnitude for a single canonical plane.
- Plane
Angles libm - Angle and magnitude results for all three canonical planes.
- Rotation
Tracker - Rotation tracker with compile-time pole count and algorithm selection.
- Rpm
- Rotational speed in revolutions per minute.
- Sensor
Reading - Complete sensor reading from a single conversion cycle.
- Signed
Degrees - Signed angular delta in degrees, used for rotation steps and displacements.
- Temp
Threshold Config - Temperature threshold register code (7-bit,
T_CONFIGbits [7:1]). - Threshold
Config - Per-axis threshold configuration for magnetic field and temperature.
- Tmag5273
- Driver for the TI TMAG5273 3-axis Hall-effect sensor.
- Unconfigured
- Typestate marker type: sensor has not been initialized.
- Welford
libm - Welford’s online algorithm for numerically stable mean and variance.
- Zero
Crossing - Zero-crossing Schmitt trigger tracking mode.
Enums§
- Angle
Enable - Angle calculation axis pair.
- Axis
- Single physical sensor axis.
- Config
Error - Errors that can occur during
ConfigBuilder::build(). - Conversion
Average - Conversion averaging samples (maps to
CONV_AVGfield inDEVICE_CONFIG_1[4:2]). - Device
Variant - TMAG5273 device variant.
- Diagnostics
- Per-sample diagnostic checking policy.
- Error
- Errors produced by the TMAG5273 driver.
- I2cRead
Mode - I2C read mode for the TMAG5273.
- Interrupt
Mode - Interrupt routing mode (maps to
INT_MODEfield inINT_CONFIG_1[4:2]). - Interrupt
State - INT pin assertion behavior.
- Magnetic
Channel - Magnetic channel selection.
- Magnetic
Gain Channel - Gain adjustment channel selection.
- Magnetic
Temp Coefficient - Magnetic temperature compensation coefficient (maps to
MAG_TEMPCOfield inDEVICE_CONFIG_1[6:5]). - Magnetic
Threshold Direction - Threshold crossing direction.
- Operating
Mode - Operating mode for the TMAG5273.
- Plane
Axis libm - Canonical measurement plane for 2-axis angle computation.
- Pole
Count - Supported magnet pole counts for rotation tracking.
- Power
Noise Mode - Power mode.
- Range
- Magnetic field measurement range.
- Sleep
Time - Sleep duration between measurements in wake-up-and-sleep mode
(maps to
SLEEPTIMEfield inSENSOR_CONFIG_1[3:0]). - Threshold
Crossing Count - Number of threshold crossings before the interrupt is asserted
(maps to
THRX_COUNTfield inSENSOR_CONFIG_2[6]). - Threshold
Hysteresis - Threshold hysteresis mode — maps to the
THR_HYSTfield inDEVICE_CONFIG_2[7:5]. - Trigger
Mode - Trigger mode for standby conversions.
Constants§
- WAKE_
DELAY - Wake-up delay range after transitioning from Sleep to an active mode.
- WAKE_
RETRY_ DELAY - Inter-retry delay between NACK’d register reads during
set_mode()wake.
Traits§
- Tracking
Mode - Marker trait for rotation tracking algorithm selection.
Type Aliases§
- Cordic
Tracker - Type alias for the 2-pole CORDIC-based rotation tracker.