Skip to main content

Crate tmag5273

Crate tmag5273 

Source
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.

VariantAddressXY range (low / high)Z range (low / high)
A1, B1, C1, D10x35, 0x22, 0x78, 0x44±40 / ±80 mT±40 / ±80 mT
A2, B2, C2, D20x35, 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 — Enables defmt::Format derives on all public types
  • libm — Enables the L3 analysis layer: magnitude_3d(), plane_angles() with per-plane angle/magnitude, AxisCalibrator for auto-detecting the optimal hardware angle axis pair, and related types (PlaneAxis, PlaneAngle, PlaneAngles, AxisRecommendation)

Structs§

AngleReading
Angle measurement result from the TMAG5273 angle engine.
AxisCalibratorlibm
Accumulates per-axis running statistics from MagneticReading samples and recommends the optimal hardware angle configuration.
AxisRecommendationlibm
Recommended hardware angle configuration from AxisCalibrator::recommend.
CalibrationConfig
Magnetic gain and offset calibration configuration.
Celsius
Temperature in degrees Celsius.
Config
Validated device configuration for the TMAG5273.
ConfigBuilder
Builder for validated Config.
Configured
Typestate marker type: sensor has been initialized and is ready for measurement.
ConversionStatus
Parsed contents of the CONV_STATUS register (0x18).
Cordic
CORDIC-based angle tracking mode.
CordicMagnitude
Hardware-computed 2-axis CORDIC magnitude in millitesla.
Crossings
Total zero-crossings counted by a ZeroCrossing tracker.
Degrees
Absolute sensor angle in degrees, always in the range [0°, 360°].
DeviceStatus
Parsed contents of the DEVICE_STATUS register (0x1C).
InitError
Initialization failure that returns the I2C bus and delay backend to the caller.
InterruptConfig
Interrupt configuration for the TMAG5273.
Lsb
Raw 8-bit threshold register value.
MagneticReading
Magnetic field reading from all enabled axes.
MicrosIsr
Duration in micros_isreconds.
MicrosRange
A range of micros_isrecond durations, matching Linux usleep_range(min, max) semantics.
MilliTesla
Magnetic flux density in millitesla.
NoDelay
Zero-sized no-op delay backend (default).
PlaneAnglelibm
Angle and magnitude for a single canonical plane.
PlaneAngleslibm
Angle and magnitude results for all three canonical planes.
RotationTracker
Rotation tracker with compile-time pole count and algorithm selection.
Rpm
Rotational speed in revolutions per minute.
SensorReading
Complete sensor reading from a single conversion cycle.
SignedDegrees
Signed angular delta in degrees, used for rotation steps and displacements.
TempThresholdConfig
Temperature threshold register code (7-bit, T_CONFIG bits [7:1]).
ThresholdConfig
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.
Welfordlibm
Welford’s online algorithm for numerically stable mean and variance.
ZeroCrossing
Zero-crossing Schmitt trigger tracking mode.

Enums§

AngleEnable
Angle calculation axis pair.
Axis
Single physical sensor axis.
ConfigError
Errors that can occur during ConfigBuilder::build().
ConversionAverage
Conversion averaging samples (maps to CONV_AVG field in DEVICE_CONFIG_1[4:2]).
DeviceVariant
TMAG5273 device variant.
Diagnostics
Per-sample diagnostic checking policy.
Error
Errors produced by the TMAG5273 driver.
I2cReadMode
I2C read mode for the TMAG5273.
InterruptMode
Interrupt routing mode (maps to INT_MODE field in INT_CONFIG_1[4:2]).
InterruptState
INT pin assertion behavior.
MagneticChannel
Magnetic channel selection.
MagneticGainChannel
Gain adjustment channel selection.
MagneticTempCoefficient
Magnetic temperature compensation coefficient (maps to MAG_TEMPCO field in DEVICE_CONFIG_1[6:5]).
MagneticThresholdDirection
Threshold crossing direction.
OperatingMode
Operating mode for the TMAG5273.
PlaneAxislibm
Canonical measurement plane for 2-axis angle computation.
PoleCount
Supported magnet pole counts for rotation tracking.
PowerNoiseMode
Power mode.
Range
Magnetic field measurement range.
SleepTime
Sleep duration between measurements in wake-up-and-sleep mode (maps to SLEEPTIME field in SENSOR_CONFIG_1[3:0]).
ThresholdCrossingCount
Number of threshold crossings before the interrupt is asserted (maps to THRX_COUNT field in SENSOR_CONFIG_2[6]).
ThresholdHysteresis
Threshold hysteresis mode — maps to the THR_HYST field in DEVICE_CONFIG_2[7:5].
TriggerMode
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§

TrackingMode
Marker trait for rotation tracking algorithm selection.

Type Aliases§

CordicTracker
Type alias for the 2-pole CORDIC-based rotation tracker.