ADS7952 Driver
API reference
Loading...
Searching...
No Matches
Typedefs | Functions | Variables
ads7952::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 ads7952::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
}
};
constexpr bool kTransferReportsStatus
True when the port's transfer() reports a status (returns bool).

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 programming and mode functions, Error::SpiError from 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 ads7952::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).

Definition at line 59 of file ads7952_spi_interface.hpp.

Function Documentation

◆ Transfer()

template<typename Port >
bool ads7952::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.

Definition at line 74 of file ads7952_spi_interface.hpp.

References kTransferReportsStatus.

Referenced by ads7952::SpiInterface< Derived >::transfer().

Variable Documentation

◆ kTransferReportsStatus

template<typename Port >
constexpr bool ads7952::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).

Definition at line 64 of file ads7952_spi_interface.hpp.

Referenced by Transfer().