SFM Flow Meter Driver 1.0.0
API reference
Loading...
Searching...
No Matches
sfm_i2c_interface.hpp
Go to the documentation of this file.
1
27#pragma once
28
29#include <cstddef>
30#include <cstdint>
31#include <type_traits>
32
33namespace sfm {
34
39template <typename Derived>
41public:
43 bool Write(uint8_t addr7, const uint8_t* data, std::size_t len) noexcept {
44 return static_cast<Derived*>(this)->Write(addr7, data, len);
45 }
46
48 bool Read(uint8_t addr7, uint8_t* out, std::size_t len) noexcept {
49 return static_cast<Derived*>(this)->Read(addr7, out, len);
50 }
51
53 void DelayMs(uint32_t ms) noexcept { static_cast<Derived*>(this)->DelayMs(ms); }
54
56 bool EnsureInitialized() noexcept {
57 return static_cast<Derived*>(this)->EnsureInitialized();
58 }
59
61 bool WriteGeneralCall(uint8_t byte) noexcept {
62 if constexpr (HasGeneralCall<Derived>::value) {
63 return static_cast<Derived*>(this)->WriteGeneralCallImpl(byte);
64 } else {
65 (void)byte;
66 return false;
67 }
68 }
69
70private:
72 template <typename, typename = void>
73 struct HasGeneralCall : std::false_type {};
74 template <typename T>
75 struct HasGeneralCall<
76 T, std::void_t<decltype(std::declval<T>().WriteGeneralCallImpl(uint8_t{}))>>
77 : std::true_type {};
79};
80
81} // namespace sfm
CRTP base for the SF06 I2C transport.
Definition sfm_i2c_interface.hpp:40
bool EnsureInitialized() noexcept
Lazy bus bring-up; must return true before any transfer.
Definition sfm_i2c_interface.hpp:56
void DelayMs(uint32_t ms) noexcept
Blocking delay used for start-up (12 ms) and reset (20 ms) waits.
Definition sfm_i2c_interface.hpp:53
bool Write(uint8_t addr7, const uint8_t *data, std::size_t len) noexcept
Raw write of len bytes to 7-bit address addr7 (no register byte).
Definition sfm_i2c_interface.hpp:43
bool Read(uint8_t addr7, uint8_t *out, std::size_t len) noexcept
Raw read of len bytes from 7-bit address addr7.
Definition sfm_i2c_interface.hpp:48
bool WriteGeneralCall(uint8_t byte) noexcept
Optional I2C general-call write (address 0x00). Default: unsupported.
Definition sfm_i2c_interface.hpp:61
Definition sfm.hpp:20