1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Asynchronous driver for AS5048A magnetic position sensor
//!
//! This driver implements an async interface for the AS5048A 14-bit magnetic rotary
//! position sensor using the SPI interface. It is compatible with embedded-hal-async
//! and works with embassy and other async embedded frameworks
//!
//! # Features
//!
//! - Async SPI communication using `embedded-hal-async`
//! - Read 14-bit angular position
//! - Read magnitude and diagnostics
//! - Automatic parity checking
//! - Error flag handling
//!
//! # Example
//!
//! ```no_run
//! use as5048a_async::As5048a;
//! use embedded_hal_async::spi::SpiDevice;
//!
//! async fn read_angle<SPI, E>(spi: SPI) -> Result<(), as5048a_async::Error<E>>
//! where
//! SPI: SpiDevice<u8, Error = E>,
//! {
//! let mut sensor = As5048a::new(spi);
//!
//! // Read angle in degrees (0-359)
//! match sensor.angle_degrees().await {
//! Ok(degrees) => {
//! // degrees is 0-359
//! }
//! Err(e) => {
//! // Handle error
//! }
//! }
//!
//! // Or read raw 14-bit value (0-16383)
//! let raw_angle = sensor.angle().await?;
//! Ok(())
//! }
//! ```
//!
//! # Important Timing Requirements
//!
//! The AS5048A requires a minimum CS (Chip Select) high time of **350ns** between
//! SPI transactions. Ensure your `SpiDevice` implementation provides adequate
//! inter-frame delay to meet this requirement. The maximum SPI clock frequency is 10 MHz
//!
//! # Error Handling
//!
//! When `Error::SensorError` occurs, the sensor's internal error flag is set
//! To recover:
//! 1. Call `clear_error_flag()` to reset the error state
//! 2. Retry the operation
//!
//! Example:
//! ```no_run
//! # use as5048a_async::{As5048a, Error};
//! # async fn example<SPI, E>(mut sensor: As5048a<SPI>) -> Result<u16, Error<E>>
//! # where SPI: embedded_hal_async::spi::SpiDevice<u8, Error = E>
//! # {
//! match sensor.angle().await {
//! Err(Error::SensorError) => {
//! sensor.clear_error_flag().await?;
//! sensor.angle().await // Retry
//! }
//! result => result
//! }
//! # }
//! ```
pub use Diagnostics;
pub use ;
pub use Error;
pub use Register;