HF-AS5047U Driver  0.1.0-dev
HF-AS5047U C++ Driver
Loading...
Searching...
No Matches
as5047u::SpiInterface< Derived > Class Template Reference

CRTP-based template interface for SPI bus operations. More...

#include <as5047u_spi_interface.hpp>

Public Member Functions

void transfer (const uint8_t *tx, uint8_t *rx, std::size_t len)
 Perform a full-duplex SPI data transfer.
 
 SpiInterface (const SpiInterface &)=delete
 
SpiInterfaceoperator= (const SpiInterface &)=delete
 

Protected Member Functions

 SpiInterface ()=default
 Protected constructor to prevent direct instantiation.
 
 SpiInterface (SpiInterface &&)=default
 
SpiInterfaceoperator= (SpiInterface &&)=default
 
 ~SpiInterface ()=default
 Protected destructor.
 

Detailed Description

template<typename Derived>
class as5047u::SpiInterface< Derived >

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:

  • Compile-time polymorphism (no virtual function overhead)
  • Static dispatch instead of dynamic dispatch
  • Better optimization opportunities for the compiler

Example usage:

class MySPI : public as5047u::SpiInterface<MySPI> {
public:
void transfer(const uint8_t* tx, uint8_t* rx, std::size_t len) {
// Platform-specific SPI implementation
}
};
CRTP-based template interface for SPI bus operations.
Definition as5047u_spi_interface.hpp:36
Template Parameters
DerivedThe derived class type (CRTP pattern)

Constructor & Destructor Documentation

◆ SpiInterface() [1/3]

template<typename Derived >
as5047u::SpiInterface< Derived >::SpiInterface ( const SpiInterface< Derived > & )
delete

◆ SpiInterface() [2/3]

template<typename Derived >
as5047u::SpiInterface< Derived >::SpiInterface ( )
protecteddefault

Protected constructor to prevent direct instantiation.

◆ SpiInterface() [3/3]

template<typename Derived >
as5047u::SpiInterface< Derived >::SpiInterface ( SpiInterface< Derived > && )
protecteddefault

◆ ~SpiInterface()

template<typename Derived >
as5047u::SpiInterface< Derived >::~SpiInterface ( )
protecteddefault

Protected destructor.

Note
Derived classes can have public destructors

Member Function Documentation

◆ operator=() [1/2]

template<typename Derived >
SpiInterface & as5047u::SpiInterface< Derived >::operator= ( const SpiInterface< Derived > & )
delete

◆ operator=() [2/2]

template<typename Derived >
SpiInterface & as5047u::SpiInterface< Derived >::operator= ( SpiInterface< Derived > && )
protecteddefault

◆ transfer()

template<typename Derived >
void as5047u::SpiInterface< Derived >::transfer ( const uint8_t * tx,
uint8_t * rx,
std::size_t len )
inline

Perform a full-duplex SPI data transfer.

Sends len bytes from tx and simultaneously receives len bytes into rx. Implementations should assert the device's chip select for the duration of the transfer.

Parameters
txPointer to data to transmit (len bytes). If nullptr, zeros can be sent.
rxPointer to buffer for received data (len bytes). If nullptr, received data can be ignored.
lenNumber of bytes to transfer.

The documentation for this class was generated from the following file: