As5048a

Struct As5048a 

Source
pub struct As5048a<SPI> { /* private fields */ }
Expand description

AS5048A driver instance (asynchronous)

Implementations§

Source§

impl<SPI, E> As5048a<SPI>
where SPI: SpiDevice<u8, Error = E>,

Source

pub fn new(spi: SPI) -> Self

Create a new AS5048A driver instance

Source

pub fn release(self) -> SPI

Release the SPI bus, consuming the driver

Source

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

Source

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

Source

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

Source

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");
}
Source

pub async fn clear_error_flag(&mut self) -> Result<(), Error<E>>

Clear the error flag by reading the clear error flag register

§Errors

Returns an error if SPI communication fails, parity check fails, or the sensor reports an error

Trait Implementations§

Source§

impl<SPI: Debug> Debug for As5048a<SPI>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<SPI> Freeze for As5048a<SPI>
where SPI: Freeze,

§

impl<SPI> RefUnwindSafe for As5048a<SPI>
where SPI: RefUnwindSafe,

§

impl<SPI> Send for As5048a<SPI>
where SPI: Send,

§

impl<SPI> Sync for As5048a<SPI>
where SPI: Sync,

§

impl<SPI> Unpin for As5048a<SPI>
where SPI: Unpin,

§

impl<SPI> UnwindSafe for As5048a<SPI>
where SPI: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.