AS5047U Driver
API reference
Loading...
Searching...
No Matches
Typedefs | Functions | Variables
as5047u::detail Namespace 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).
 

Detailed Description

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:

class MySPI : public as5047u::SpiInterface<MySPI> {
public:
bool transfer(const uint8_t* tx, uint8_t* rx, std::size_t len) {
// Platform-specific SPI implementation; false on a bus error
return my_sdk_spi_transfer(tx, rx, len) == MY_SDK_OK;
}
};
Definition as5047u_spi_interface.hpp:81

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.

Template Parameters
DerivedThe derived class type (CRTP pattern)

Typedef Documentation

◆ TransferResult

template<typename Port >
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).

Function Documentation

◆ Transfer()

template<typename Port >
bool as5047u::detail::Transfer ( Port &  port,
const uint8_t *  tx,
uint8_t *  rx,
std::size_t  len 
)
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.

Variable Documentation

◆ kTransferReportsStatus

template<typename Port >
constexpr bool as5047u::detail::kTransferReportsStatus
inlineconstexpr
Initial value:
=
std::is_same_v<std::remove_cv_t<std::remove_reference_t<TransferResult<Port>>>, bool>

True when the port's transfer() reports a status (returns bool).