AS5600_Driver/traits.rs
1use crate::types::*;
2use crate::error::AS56Error;
3
4/// A common interface for any AS5600-compatible sensor (real or simulated).
5///
6/// This trait allows writing generic code that works with both the real
7/// hardware driver and the mock implementation for testing.
8pub trait AS5600Interface {
9 /// The error type returned by the sensor methods.
10 type Error;
11
12 /// Reads the raw 12-bit angle from the Hall sensors.
13 fn read_raw_angle(&mut self) -> Result<u16, AS56Error<Self::Error>>;
14
15 /// Reads the 12-bit angle after applying all settings.
16 fn read_angle(&mut self) -> Result<u16, AS56Error<Self::Error>>;
17
18 /// Returns the current magnet status and field strength health.
19 fn get_magnet_status(&mut self) -> Result<MagnetStatus, AS56Error<Self::Error>>;
20
21 /// Returns the raw value of the status register.
22 fn get_status_raw(&mut self) -> Result<u8, AS56Error<Self::Error>>;
23
24 /// Returns the magnitude value from the Hall sensors.
25 fn get_magnitude(&mut self) -> Result<u16, AS56Error<Self::Error>>;
26
27 /// Returns the current Automatic Gain Control (AGC) value.
28 fn get_agc(&mut self) -> Result<u8, AS56Error<Self::Error>>;
29
30 /// Returns the number of times the settings have been permanently burned to the chip.
31 fn get_burn_count(&mut self) -> Result<u8, AS56Error<Self::Error>>;
32
33 /// Reads the current full configuration from the chip.
34 fn get_config(&mut self) -> Result<Configuration, AS56Error<Self::Error>>;
35
36 /// Writes a new configuration to the chip's volatile memory.
37 fn set_config(&mut self, config: Configuration) -> Result<(), AS56Error<Self::Error>>;
38
39 /// Gets the current zero position (ZPOS).
40 fn get_zero_position(&mut self) -> Result<u16, AS56Error<Self::Error>>;
41
42 /// Sets the zero position (ZPOS) in volatile memory.
43 fn set_zero_position(&mut self, angle: u16) -> Result<(), AS56Error<Self::Error>>;
44
45 /// Gets the current maximum position (MPOS).
46 fn get_max_position(&mut self) -> Result<u16, AS56Error<Self::Error>>;
47
48 /// Sets the maximum position (MPOS) in volatile memory.
49 fn set_max_position(&mut self, angle: u16) -> Result<(), AS56Error<Self::Error>>;
50
51 /// Gets the current maximum angle (MANG).
52 fn get_max_angle(&mut self) -> Result<u16, AS56Error<Self::Error>>;
53
54 /// Sets the maximum angle (MANG) in volatile memory.
55 fn set_max_angle(&mut self, angle: u16) -> Result<(), AS56Error<Self::Error>>;
56}