|
| | AS5047U (Port &port, const Config &config={}) noexcept |
| | Bind the driver to a port and store the configuration. No I/O, cannot fail.
|
| |
|
| AS5047U (const AS5047U &)=delete |
| | One driver object per chip.
|
| |
|
AS5047U & | operator= (const AS5047U &)=delete |
| | One driver object per chip.
|
| |
|
| Result< void > | EnsureInitialized () noexcept |
| | Start the chip, once: the only way to initialise the driver.
|
| |
| bool | IsInitialized () const noexcept |
| |
| Result< void > | Deinitialize () noexcept |
| | Mark the driver uninitialised; the next EnsureInitialized() starts the chip again (the recovery after a fault). No I/O: the AS5047U has no low-power mode to enter.
|
| |
|
| Result< void > | ApplyConfig (const Config &config, Verify verify=Verify::None) noexcept |
| | Change the configuration.
|
| |
| const Config & | GetConfig () const &noexcept |
| |
|
void | GetConfig () const &&=delete |
| | Not on a temporary driver: the reference would dangle (KB-CPP20-044).
|
| |
| Result< void > | SetZeroPosition (uint16_t counts, Verify verify=Verify::None) noexcept |
| | Set the zero position (ZPOSM, ZPOSL).
|
| |
| Result< uint16_t > | SetZeroHere (Verify verify=Verify::None) noexcept |
| | Make the current position read as 0.
|
| |
| Result< void > | SetDirection (Direction direction, Verify verify=Verify::None) noexcept |
| | Set the direction in which the angle increases.
|
| |
|
| Result< uint16_t > | ReadAngleCounts () noexcept |
| | The angle at address 0x3FFF (with DAEC unless it is off): the hot path.
|
| |
| Result< uint16_t > | ReadUncompensatedAngleCounts () noexcept |
| |
| Result< float > | ReadAngleDegrees () noexcept |
| |
| Result< float > | ReadAngleRadians () noexcept |
| |
| Result< int16_t > | ReadVelocityCounts () noexcept |
| |
| Result< float > | ReadVelocityDegPerSec () noexcept |
| |
| Result< float > | ReadVelocityRpm () noexcept |
| |
| Result< uint8_t > | ReadAgc () noexcept |
| |
| Result< uint16_t > | ReadMagnitude () noexcept |
| |
|
| Result< Diagnostics > | ReadDiagnostics () noexcept |
| |
| Result< void > | CheckForReset () noexcept |
| | Check that the chip still holds the settings the driver wrote: the cheap test for a reset of the chip that ERRFL may not report.
|
| |
| Result< ErrorFlags > | ReadErrorFlags () noexcept |
| | Read ERRFL, which clears it on the chip. The value is also kept in GetLastErrorFlags() and ORed into GetLatchedErrorFlags().
|
| |
| ErrorFlags | GetLastErrorFlags () const noexcept |
| |
| ErrorFlags | GetLatchedErrorFlags () const noexcept |
| | Every ERRFL flag the driver has read since the last ClearLatchedErrorFlags(). No I/O.
|
| |
|
void | ClearLatchedErrorFlags () noexcept |
| | Empty the latch of GetLatchedErrorFlags(), flags_lost included. No I/O.
|
| |
| uint16_t | GetLastReply () const noexcept |
| |
| Result< uint16_t > | ReadRegister (uint16_t address) noexcept |
| | Read one register once: the command frame and the NOP frame that carries the answer, no retry (handbook KB-CPP-129).
|
| |
| Result< void > | WriteRegister (uint16_t address, uint16_t value, Verify verify=Verify::None) noexcept |
| | Write a register: the command and data frames, nothing more unless verify asks for a read-back. PROG is refused: use ProgramOtp(). A write to DISABLE to SETTINGS3 does not change GetConfig(), so the next ApplyConfig() or setter writes the configuration over it. When such a write fails, DISABLE to ECC are read back (14 frames) for the reset check's copy.
|
| |
| Result< NonVolatileRegisters > | ReadNonVolatile () noexcept |
| |
|
| Result< void > | ProgramOtp (OtpBurnConfirm confirm, OtpReport &report) noexcept |
| | Burn the current settings into the OTP. This cannot be undone.
|
| |
template<SpiPort Port>
class as5047u::AS5047U< Port >
Driver for one AS5047U on a platform port.
Lifecycle: construct with the configuration (no I/O), then EnsureInitialized(), the one way to start (bus up, presence check, error flags cleared, settings written and read back), use, optionally Deinitialize(). Every call that touches the chip returns Error::NotInitialized until EnsureInitialized() has succeeded; no call starts the chip as a side effect, so a read is always the frames it needs and nothing more.
Every read checks the two flag bits of the reply. A read whose reply has neither set costs exactly its two frames. When the error bit is set the driver reads ERRFL (which clears it on the chip, so the driver ORs it into GetLatchedErrorFlags()) and fails the call with Crc, Framing, Command or DeviceFault. When an angle or velocity reply carries the warning bit, the driver reads ERRFL the same way and refuses the value with MagnetWarning if the field is out of range (AGC at a limit, field at half); a P2RAM single-bit warning (corrected by the ECC) does not refuse it. Other reads (AGC, magnitude, DIA, settings) return their value under a warning and leave ERRFL on the chip for ReadErrorFlags().
Reset detection: a power-on reset or brown-out of the chip reloads its settings from the OTP and loses every soft write ("Non-Volatile Registers (OTP)"). When any ERRFL read after start-up holds OffCompNotFinished or WDTST (the offset compensation restarts at power-up, Figure 33), the driver reads DISABLE to ECC (14 frames) and compares them with what it last wrote or read there. A read of ERRFL that failed (and may have taken that flag) costs the same compare. On a difference, or when that read cannot be completed after a flag, the call fails with DeviceReset and the driver is uninitialised: call EnsureInitialized() again, which writes the configuration anew. The datasheet does not promise that flag after a reset, so call CheckForReset() periodically where a reset must not go unnoticed (docs/limitations.md).
Port hooks beyond the required bus hooks, found at compile time:
| Hook | Used for | Without it |
void DelayUs(uint32_t us) noexcept | 1 ms between polls of DIA at start-up and of the OTP burn | Compile error: the waits are required |
void Log(LogLevel, const char* message) noexcept | One line per lifecycle event or failure | Nothing is logged |
A hook declared with the wrong signature (for example DelayUs(uint16_t)) is a compile error.
- Template Parameters
-
Start the chip, once: the only way to initialise the driver.
The first call brings the bus up and waits for the chip: it reads DIA, once per millisecond for at most Config::startup_timeout_ms, until every magnetic loop reports finished, and accepts that only when the next DIA read says the same (a ready status a line could fake counts only when a second read confirms it, KB-CPP-116, KB-CPP-124). Then it reads ERRFL, which clears what the power-up left there (the value goes into GetLatchedErrorFlags(), which the call empties first), and applies the stored configuration: the settings registers read (to keep their DIA bits), then every setting written and read back (start-up always verifies), or, with write_settings false (an OTP-burned part), the chip's settings read into GetConfig(). A chip that is already up costs 6 frames before the settings; one that is not yet ready adds 2 frames and 1 ms per poll. After it succeeds, later calls return Ok at once with no I/O. After it fails, the driver stays uninitialised and the next call starts again from the beginning.
- Returns
Ok, InvalidArgument (the stored configuration fails Validate(); no I/O), Bus, NoDevice (only line patterns until the deadline), NotReady (the chip answers but its loops did not finish by the deadline), DeviceIdMismatch (a DIA with a bit set that reads 0 on an AS5047U), Crc, Framing, Command, DeviceFault or WriteMismatch. After a DeviceReset from any call, this call starts the chip again and writes the stored configuration (GetConfig() still holds it).
Every ERRFL flag the driver has read since the last ClearLatchedErrorFlags(). No I/O.
ERRFL clears when it is read, and the driver reads it inside other calls: to resolve a reply's error or warning bit, and once at start-up. Each of those reads, ReadErrorFlags() and a raw ReadRegister(reg::kErrfl) OR the value into this latch, so no internal read hides a flag from the caller (handbook KB-CPP-119). EnsureInitialized() empties it first; after start-up it holds what the power-up left in ERRFL (for example offset_comp from before the loops settled): clear it there if only later flags matter.
flags_lost is set when a read of ERRFL failed once its command may have reached the chip (a reply CRC error, a failed transfer, NoDevice for the reserved bit): the chip cleared the flags that read took, so a fault may have been missed. The driver then compares the settings registers itself (14 frames, DeviceReset on a difference). When that compare cannot be read either, the call keeps its own error and the compare stays pending: each later call runs it and fails with its error until it is read, so no value is returned meanwhile. Check the bus, read ReadDiagnostics(), and call CheckForReset() when it is set.
- Returns
- The latched flags;
raw is their OR.