|
MAX22200 Driver 0.1.0
API reference
|
The SPI port of the MAX22200 driver: the CRTP base, its pin enums, the SpiPort concept and the two-phase register access.
More...
#include <array>#include <concepts>#include <cstddef>#include <cstdint>#include <span>#include "max22200_detail.hpp"#include "max22200_registers.hpp"#include "max22200_types.hpp"Go to the source code of this file.
Classes | |
| class | max22200::SpiInterface< Derived > |
| CRTP base of the platform SPI port. More... | |
Namespaces | |
| namespace | max22200 |
The MAX22200 driver: everything it declares lives here; internals in detail. | |
Concepts | |
| concept | max22200::SpiPort |
Satisfied by a class that derives from SpiInterface<Port> and implements the required hooks with exactly the types above, noexcept and returning bool: EnsureInitialized(), Transfer() and GpioSet() (CMD and ENABLE). | |
Enumerations | |
| enum class | max22200::CtrlPin : uint8_t { max22200::Enable = 0 , max22200::Cmd = 1 , max22200::Fault = 2 } |
| The chip's control pins the port drives or reads. More... | |
| enum class | max22200::GpioSignal : uint8_t { max22200::INACTIVE = 0 , max22200::ACTIVE = 1 } |
| Logical level of a control pin; the port maps it to the physical polarity. More... | |
Variables | |
Bus requirements | |
What the MAX22200 needs from the SPI bus ("SPI Detailed Description", p23; Electrical Characteristics, SPI rows, p10; Figure 1, p11). A port and a board configuration check their settings against these with | |
| constexpr uint8_t | max22200::kSpiMode = 0 |
| SPI mode 0: CPOL = 0, CPHA = 0 ("SPI Detailed Description": the only mode the chip supports). | |
| constexpr bool | max22200::kMsbFirst = true |
| constexpr uint32_t | max22200::kMaxClockHz = 10'000'000 |
| constexpr uint32_t | max22200::kMinCsHighNs = 30 |
| Shortest time CSB stays high between two transfers, tCSPW. | |
| constexpr uint32_t | max22200::kCsSetupNs = 30 |
| CSB falling edge to the first SCK rising edge, tCSS. | |
| constexpr uint32_t | max22200::kCsHoldNs = 30 |
| Last SCK edge to CSB rising, tCSH. | |
| constexpr bool | max22200::kContinuousWord = false |
| constexpr uint32_t | max22200::kCmdSetupNs = 20 |
| constexpr std::array< std::size_t, 2 > | max22200::kTransferBytes = {1, 4} |
| constexpr bool | max22200::kSdoOpenDrain = true |
| SDO is open drain (Pin Description): the board fits a pull-up. | |
The SPI port of the MAX22200 driver: the CRTP base, its pin enums, the SpiPort concept and the two-phase register access.
The driver never calls an SDK. It calls hooks on a class you derive from max22200::SpiInterface<Self>:
| Hook | Contract |
|---|---|
bool EnsureInitialized() noexcept | Bring the bus and the CMD and ENABLE outputs up on the first call (CMD high, its idle level); true at once afterwards |
bool Transfer(const uint8_t* tx, uint8_t* rx, std::size_t len) noexcept | One full-duplex transfer of len = 1 or 4 bytes, both buffers given, CSB low throughout and high after |
bool GpioSet(CtrlPin pin, GpioSignal signal) noexcept | Drive CMD or ENABLE; false when the pin could not be driven |
void DelayUs(uint32_t us) noexcept | Wait at least us microseconds (tEN and tWU at start-up) |
What the chip needs from the bus is below as constexpr values (kSpiMode to kCmdSetupNs, from "SPI Detailed Description" and the SPI rows of the Electrical Characteristics, Figure 1); a port checks its settings against them with static_assert (handbook KB-CPP-123). SDO is open drain: the board needs a pull-up, and its RC sets how fast the bus can run (Electrical Characteristics, note 2). CMD idles high: the driver drives it low only around each data transfer and high again after it, so a GPIO write that returns after the pin changed meets tCMS and tCMH on any MCU.
Control pins and their idle levels (handbook KB-HW-018): the port drives each output to its idle level before it enables the pin's output driver and before the first transfer. CMD idles high (GpioSignal::ACTIVE: the level that selects the Command Register; the driver also drives it high first). ENABLE idles low (GpioSignal::INACTIVE: the chip asleep, every output Hi-Z, until EnsureInitialized() raises it). A board that ties ENABLE high returns true for CtrlPin::Enable without doing anything. FAULT is an input. The port moves raw bytes: it never retries, never interprets the data and never configures the chip. The optional hooks (GpioRead for the FAULT pin, DelayUs is required, Log) are described in max22200.hpp.