|
HF-MAX22200 Driver 0.1.0-dev
HF-MAX22200 C++ Driver
|
CRTP-based template interface for SPI communication. More...
#include <max22200_spi_interface.hpp>
Public Member Functions | |
| bool | Initialize () |
| Initialize the SPI interface. | |
| bool | Transfer (const uint8_t *tx_data, uint8_t *rx_data, size_t length) |
| Transfer data over SPI interface. | |
| void | SetChipSelect (bool state) |
| Set chip select state. | |
| bool | Configure (uint32_t speed_hz, uint8_t mode, bool msb_first=true) |
| Configure SPI parameters. | |
| bool | IsReady () const |
| Check if SPI interface is ready. | |
| void | DelayUs (uint32_t us) |
| Blocking delay in microseconds (from comm/CRTP implementation). | |
GPIO Pin Control | |
Unified interface for controlling MAX22200 hardware control pins. The platform bus implementation maps GpioSignal::ACTIVE/INACTIVE to the correct physical level for each pin based on its polarity. | |
| void | GpioSet (CtrlPin pin, GpioSignal signal) |
| Set a control pin to the specified signal state. | |
| bool | GpioRead (CtrlPin pin, GpioSignal &signal) |
| Read the current state of a control pin. | |
| void | GpioSetActive (CtrlPin pin) |
Assert a control pin (set to ACTIVE). Convenience wrapper for GpioSet(pin, GpioSignal::ACTIVE). | |
| void | GpioSetInactive (CtrlPin pin) |
Deassert a control pin (set to INACTIVE). Convenience wrapper for GpioSet(pin, GpioSignal::INACTIVE). | |
Protected Member Functions | |
| SpiInterface ()=default | |
| Protected constructor to prevent direct instantiation. | |
| SpiInterface (const SpiInterface &)=delete | |
| SpiInterface & | operator= (const SpiInterface &)=delete |
| SpiInterface (SpiInterface &&)=default | |
| SpiInterface & | operator= (SpiInterface &&)=default |
| ~SpiInterface ()=default | |
| Protected destructor. | |
CRTP-based template interface for SPI communication.
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:
| Derived | The derived class type (CRTP pattern) |
|
protecteddefault |
Protected constructor to prevent direct instantiation.
|
protecteddelete |
|
protecteddefault |
|
protecteddefault |
Protected destructor.
|
inline |
Configure SPI parameters.
Sets up SPI communication parameters such as clock speed, data mode, and bit order.
| speed_hz | SPI clock speed in Hz
|
| mode | SPI mode (0-3) defining clock polarity and phase
|
| msb_first | true for MSB first, false for LSB first
|
Blocking delay in microseconds (from comm/CRTP implementation).
Used for device timing requirements, e.g. MAX22200 power-up delay (0.5 ms after ENABLE) before first SPI access. Platform implements the actual wait (e.g. esp_rom_delay_us, or RTOS-aware delay).
| us | Delay duration in microseconds. |
|
inline |
Read the current state of a control pin.
Primarily used for reading the FAULT pin status to detect fault conditions.
| [in] | pin | Which control pin to read:
|
| [out] | signal | Receives the current signal state:
|
|
inline |
Set a control pin to the specified signal state.
Controls the MAX22200 hardware control pins (ENABLE, CMD, FAULT). The platform implementation maps GpioSignal::ACTIVE/INACTIVE to the correct physical level based on each pin's polarity.
| [in] | pin | Which control pin to drive:
|
| [in] | signal | ACTIVE to assert the pin function, INACTIVE to deassert. |
|
inline |
Assert a control pin (set to ACTIVE). Convenience wrapper for GpioSet(pin, GpioSignal::ACTIVE).
| [in] | pin | Which control pin to assert. |
|
inline |
Deassert a control pin (set to INACTIVE). Convenience wrapper for GpioSet(pin, GpioSignal::INACTIVE).
| [in] | pin | Which control pin to deassert. |
|
inline |
Initialize the SPI interface.
This method should perform any necessary initialization of the SPI hardware, including setting up clock rates, modes, and other configuration parameters.
|
inline |
Check if SPI interface is ready.
Verifies that the SPI interface is properly initialized and ready for communication.
|
protecteddelete |
|
protecteddefault |
|
inline |
Set chip select state.
Controls the chip select (CS) line for the SPI device.
| state | true to assert CS (active low), false to deassert |
|
inline |
Transfer data over SPI interface.
Performs a full-duplex SPI transfer. The method should handle both transmission and reception of data simultaneously.
| tx_data | Pointer to data buffer to transmit |
| rx_data | Pointer to buffer for received data (can be same as tx_data) |
| length | Number of bytes to transfer |