SFM_FLOW_METER Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Classes | Namespaces | Concepts
sfm_flow_meter_i2c_interface.hpp File Reference

The I2C port of the SFM flow meter driver: the CRTP base, the I2cPort concept and the bus requirements of every supported family. More...

#include <concepts>
#include <cstddef>
#include <cstdint>
#include "sfm_flow_meter_detail.hpp"
#include "sfm_flow_meter_types.hpp"

Go to the source code of this file.

Classes

class  sfm::I2cInterface< Derived >
 CRTP base of the platform I2C port. More...
 

Namespaces

namespace  sfm
 The SFM flow meter driver: everything it declares lives here; internals in detail.
 

Concepts

concept  sfm::I2cPort
 Satisfied by a class that derives from I2cInterface<Port> and implements the required hooks with exactly the types above, noexcept and returning bool.
 

Variables

Bus requirements

What the SFM family needs from the I2C bus. A port and a board configuration check their settings against these with static_assert (handbook KB-CPP-123). Per-part clock limits are in PartInfo::max_clock_hz.

constexpr uint8_t sfm::kI2cAddress = 0x2A
 
constexpr uint32_t sfm::kMaxClockHz = 1'000'000
 
constexpr uint32_t sfm::kTypClockHz = 400'000
 Typical SCL frequency of the SF06 family.
 
constexpr uint32_t sfm::kSafeClockHz = 100'000
 
constexpr bool sfm::kRepeatedStart = false
 
constexpr std::size_t sfm::kMaxRead = 18
 
constexpr std::size_t sfm::kMaxWrite = 5
 

Detailed Description

The I2C port of the SFM flow meter driver: the CRTP base, the I2cPort concept and the bus requirements of every supported family.

The driver never calls an SDK. It calls hooks on a class you derive from sfm::I2cInterface<Self>. The chip has no register map on the bus: a transaction is a raw command write (a pointer or command code, optionally an argument) or a raw read of 16-bit words that are each followed by a CRC-8 byte.

Hook Contract Required
bool EnsureInitialized() noexcept Bring the bus up on the first call; true at once afterwards yes
bool Write(uint8_t addr, const uint8_t* data, std::size_t len) noexcept START, addr + W, len bytes, STOP; false on a NACK or bus error. len is at least 1: the driver never sends an empty transfer. A NACK is expected while a sensor sleeps or resets; the driver polls with the next real command yes
bool Read(uint8_t addr, uint8_t* data, std::size_t len) noexcept START, addr + R, len bytes, the master ACKs every byte but the last, STOP; false when the address is NACKed (the "no data yet" signal) or on a bus error. It must never abort after the first byte (SF05 lock-up hazard) yes
bool ReadStretch(uint8_t addr, uint8_t* data, std::size_t len) noexcept and static constexpr bool kClockStretch = true A read that tolerates the slave holding SCL low (SF04, "hold master") SFM4100 only
bool WriteGeneralCall(uint8_t byte) noexcept START, address 0x00 + W, byte, STOP reset of SF06 families
bool PowerCycle() noexcept Remove and restore the sensor supply; hold SDA and SCL low while it is off, so the sensor is not powered through the bus (SFM4200 2.3, SFM3505 3.3.5) optional
bool SetResetPin(bool asserted) noexcept Drive the /RES pin of the SFM4200 optional
void DelayUs(uint32_t us) noexcept, uint32_t NowUs() noexcept, void Log(LogLevel, const char*) noexcept waits, a free-running microsecond clock, one log line per event optional

addr is the 7-bit address. The port moves raw bytes and never retries. A write is followed by a STOP and a read by its own START: the SF06 and SFx6000 documents show the read header after a STOP and neither permit nor forbid a repeated START (ambiguity K-RS), so the driver has no WriteRead hook. What the chip needs from the bus is below as constexpr values; a port checks its settings against them with static_assert.