SFM_FLOW_METER Driver 0.1.0
API reference
Loading...
Searching...
No Matches
sfm_flow_meter_i2c_interface.hpp
Go to the documentation of this file.
1// clang-format off: the table below must keep one row per line.
31// clang-format on
32#ifndef SFM_FLOW_METER_I2C_INTERFACE_HPP
33#define SFM_FLOW_METER_I2C_INTERFACE_HPP
34
35#include <concepts>
36#include <cstddef>
37#include <cstdint>
38
41
42namespace sfm {
43
54inline constexpr uint8_t kI2cAddress = 0x2A;
57inline constexpr uint32_t kMaxClockHz = 1'000'000;
59inline constexpr uint32_t kTypClockHz = 400'000;
62inline constexpr uint32_t kSafeClockHz = 100'000;
65inline constexpr bool kRepeatedStart = false;
68inline constexpr std::size_t kMaxRead = 18;
71inline constexpr std::size_t kMaxWrite = 5;
85template <typename Derived>
87public:
89 I2cInterface(const I2cInterface&) = delete;
92
93protected:
95 I2cInterface() noexcept = default;
97 ~I2cInterface() noexcept = default;
98};
99
112template <typename Port>
113concept I2cPort = std::derived_from<Port, I2cInterface<Port>> && requires {
114 detail::ExactHook<Port, bool() noexcept>::Take(&Port::EnsureInitialized);
115 detail::ExactHook<Port, bool(uint8_t, const uint8_t*, std::size_t) noexcept>::Take(&Port::Write);
116 detail::ExactHook<Port, bool(uint8_t, uint8_t*, std::size_t) noexcept>::Take(&Port::Read);
117};
118
119} // namespace sfm
120
121#endif // SFM_FLOW_METER_I2C_INTERFACE_HPP
CRTP base of the platform I2C port.
Definition sfm_flow_meter_i2c_interface.hpp:86
I2cInterface(const I2cInterface &)=delete
Ports are not copied: the driver holds a reference.
I2cInterface & operator=(const I2cInterface &)=delete
Ports are not copied: the driver holds a reference.
I2cInterface() noexcept=default
Only the derived port is constructed.
Satisfied by a class that derives from I2cInterface<Port> and implements the required hooks with exac...
Definition sfm_flow_meter_i2c_interface.hpp:113
The SFM flow meter driver: everything it declares lives here; internals in detail.
Definition sfm_flow_meter.hpp:35
constexpr std::size_t kMaxWrite
Definition sfm_flow_meter_i2c_interface.hpp:71
constexpr uint32_t kSafeClockHz
Definition sfm_flow_meter_i2c_interface.hpp:62
constexpr std::size_t kMaxRead
Definition sfm_flow_meter_i2c_interface.hpp:68
constexpr uint32_t kMaxClockHz
Definition sfm_flow_meter_i2c_interface.hpp:57
constexpr bool kRepeatedStart
Definition sfm_flow_meter_i2c_interface.hpp:65
constexpr uint8_t kI2cAddress
Definition sfm_flow_meter_i2c_interface.hpp:54
constexpr uint32_t kTypClockHz
Typical SCL frequency of the SF06 family.
Definition sfm_flow_meter_i2c_interface.hpp:59
Compile-time helpers of the SFM_FLOW_METER driver: typed integer literals, exact hook matching,...
Public types of the SFM flow meter driver: errors, Result<T>, the families, variants and gases,...