|
AS5047U Driver
API reference
|
CRTP-based template interface for SPI bus operations. More...
Typedefs | |
| template<typename Port > | |
| using | TransferResult = decltype(std::declval< Port & >().transfer(std::declval< const uint8_t * >(), std::declval< uint8_t * >(), std::declval< std::size_t >())) |
Return type of Port::transfer(const uint8_t*, uint8_t*, std::size_t). | |
Functions | |
| template<typename Port > | |
| bool | Transfer (Port &port, const uint8_t *tx, uint8_t *rx, std::size_t len) |
| Call the port's transfer() and return its status. | |
Variables | |
| template<typename Port > | |
| constexpr bool | kTransferReportsStatus |
| True when the port's transfer() reports a status (returns bool). | |
CRTP-based template interface for SPI bus operations.
This template class provides a hardware-agnostic interface for SPI communication using the CRTP pattern. Platform-specific implementations should inherit from this template with themselves as the template parameter.
Benefits of CRTP:
Example usage:
The port's transfer() returns bool: true when the frame was clocked, false on a bus error. The driver turns false into a failed call (false from the setters, WriteReg() and ProgramOTP(), the BusError sticky flag for the reads). A port written for the earlier contract, with a void transfer, still compiles and is treated as never failing. Any other return type is rejected at compile time, so an SDK status code (for example an esp_err_t, where 0 means success) cannot be mistaken for a bool.
| Derived | The derived class type (CRTP pattern) |
| using as5047u::detail::TransferResult = typedef decltype(std::declval<Port&>().transfer( std::declval<const uint8_t*>(), std::declval<uint8_t*>(), std::declval<std::size_t>())) |
Return type of Port::transfer(const uint8_t*, uint8_t*, std::size_t).
|
inline |
Call the port's transfer() and return its status.
A bool result is returned as-is; a void transfer (the earlier contract) is treated as always successful.
|
inlineconstexpr |
True when the port's transfer() reports a status (returns bool).