pub struct As5048a<SPI> { /* private fields */ }Expand description
AS5048A driver instance (asynchronous)
Implementations§
Source§impl<SPI, E> As5048a<SPI>
impl<SPI, E> As5048a<SPI>
Sourcepub async fn angle(&mut self) -> Result<u16, Error<E>>
pub async fn angle(&mut self) -> Result<u16, Error<E>>
Get the 14-bit corrected angular position
Value ranges from 0 to 16383 (0° to 359.978°)
Use ANGLE_MAX constant for conversion calculations
For integer degree conversion, use Self::angle_degrees
§Errors
Returns an error if SPI communication fails, parity check fails, or the sensor reports an error
Sourcepub async fn angle_degrees(&mut self) -> Result<u16, Error<E>>
pub async fn angle_degrees(&mut self) -> Result<u16, Error<E>>
Get the angular position in degrees (0-359)
This method converts the raw 14-bit angle value to degrees using integer arithmetic with saturation. The result is rounded down
§Errors
Returns an error if SPI communication fails, parity check fails, or the sensor reports an error
Sourcepub async fn magnitude(&mut self) -> Result<u16, Error<E>>
pub async fn magnitude(&mut self) -> Result<u16, Error<E>>
Get the 14-bit magnitude value from CORDIC
Useful for checking magnet presence and strength
§Errors
Returns an error if SPI communication fails, parity check fails, or the sensor reports an error
Sourcepub async fn diagnostics(&mut self) -> Result<Diagnostics, Error<E>>
pub async fn diagnostics(&mut self) -> Result<Diagnostics, Error<E>>
Get the diagnostics and AGC register
Returns a Diagnostics struct with helper methods to check:
- Magnetic field strength (
COMP_HIGH,COMP_LOW) - CORDIC overflow
- Offset compensation status
- AGC value
§Errors
Returns an error if SPI communication fails, parity check fails, or the sensor reports an error
§Example
let diag = sensor.diagnostics().await?;
if diag.is_valid() {
println!("AGC value: {}", diag.agc_value());
} else if diag.cordic_overflow() {
println!("CORDIC overflow - data invalid!");
} else if diag.comp_high() {
println!("Magnet too close");
} else if diag.comp_low() {
println!("Magnet too far");
}