SFM_FLOW_METER Driver 0.1.0
API reference
Loading...
Searching...
No Matches
sfm_flow_meter_registers.hpp
Go to the documentation of this file.
1
17#ifndef SFM_FLOW_METER_REGISTERS_HPP
18#define SFM_FLOW_METER_REGISTERS_HPP
19
20#include <array>
21#include <cstddef>
22#include <cstdint>
23
25
27namespace sfm::reg {
28
35// SF06 families (SFM4300 section 4.3, SFM3xxx section 4.3, SFM3304 section 4.3,
36// SFM3505 section 3.3).
37inline constexpr uint16_t kCmdStartGas0 = 0x3603;
38inline constexpr uint16_t kCmdStartGas1 = 0x3608;
39inline constexpr uint16_t kCmdStartGas2 = 0x3615;
40inline constexpr uint16_t kCmdStartGas3 = 0x361E;
41inline constexpr uint16_t kCmdStartGas4 =
42 0x3624;
43inline constexpr uint16_t kCmdStartMixture0 =
44 0x3632;
45inline constexpr uint16_t kCmdStartMixture1 = 0x3639;
46inline constexpr uint16_t kCmdStartMixture2 = 0x3646;
47inline constexpr uint16_t kCmdStartSfxMixture0 = 0x3650;
48inline constexpr uint16_t kCmdUpdateConcentration =
49 0xE17D;
50inline constexpr uint16_t kCmdResultPointer = 0xE000;
51inline constexpr uint16_t kCmdStop = 0x3FF9;
52inline constexpr uint16_t kCmdAveraging = 0x366A;
53inline constexpr uint16_t kCmdAveragingDual = 0x364D;
54inline constexpr uint16_t kCmdReadScale =
55 0x3661;
56inline constexpr uint16_t kCmdSleep = 0x3677;
57inline constexpr uint16_t kCmdProductId = 0xE102;
58inline constexpr uint16_t kCmdDeviceIdDual = 0x365B;
59inline constexpr uint16_t kCmdSfxScalePointer =
60 0xE151;
61inline constexpr uint16_t kCmdSfxTemperature =
62 0xE102;
63inline constexpr uint8_t kGeneralCallReset = 0x06;
64inline constexpr uint8_t kGeneralCallAddress = 0x00;
65
66// SF05 family (AN-05 section 4 and 8, SFM4200 section 5).
67inline constexpr uint16_t kSf05Flow = 0x1000;
68inline constexpr uint16_t kSf05Temperature = 0x1001;
69inline constexpr uint16_t kSf05Reset = 0x2000;
70inline constexpr uint16_t kSf05ScaleFlow = 0x30DE;
71inline constexpr uint16_t kSf05OffsetFlow = 0x30DF;
72inline constexpr uint16_t kSf05Serial = 0x31AE;
74inline constexpr uint16_t kSf05SerialLow = 0x31AF;
75
76// SF04 family (SFM4100 section 4, application note sample code).
77inline constexpr uint8_t kSf04TriggerFlow = 0xF1;
78inline constexpr uint8_t kSf04TriggerTemperature = 0xF3;
79inline constexpr uint8_t kSf04SoftReset = 0xFE;
80inline constexpr uint8_t kSf04UserRegister = 0xE3;
81inline constexpr uint8_t kSf04ReadOnly2 = 0xE9;
82inline constexpr uint8_t kSf04Eeprom = 0xFA;
83inline constexpr uint16_t kSf04EepromSerial =
84 0x02F8;
85inline constexpr uint16_t kSf04EepromScale = 0x02B6;
86inline constexpr uint16_t kSf04EepromUnit = 0x02B7;
87inline constexpr uint16_t kSf04FieldStride = 0x0300;
88
91inline constexpr uint16_t kUnitSlm = 0x0148;
94inline constexpr uint16_t kUnitSccm = 0x0145;
95
96inline constexpr uint16_t kStatusPureGas = 0x3FF;
97
100using StatusCommand = detail::Field<uint16_t, 12U, 4U>;
102using StatusSmoothing = detail::Field<uint16_t, 11U, 1U>;
104using StatusFixedN = detail::Field<uint16_t, 10U, 1U>;
107using StatusConcentration = detail::Field<uint16_t, 0U, 10U>;
109using StatusFilterArg = detail::Field<uint16_t, 9U, 1U>;
111using StatusAverages = detail::Field<uint16_t, 0U, 9U>;
112
123constexpr uint8_t Crc8(uint8_t init, uint8_t high, uint8_t low) noexcept {
124 uint32_t crc = init; // all arithmetic in uint32_t (KB-CPP20-021)
125 for (uint32_t byte = 0U; byte < 2U; ++byte) {
126 crc ^= (byte == 0U) ? static_cast<uint32_t>(high) : static_cast<uint32_t>(low);
127 for (uint32_t bit = 0U; bit < 8U; ++bit) {
128 crc = ((crc & 0x80U) != 0U) ? ((crc << 1U) ^ 0x31U) : (crc << 1U);
129 crc &= 0xFFU;
130 }
131 }
132 return static_cast<uint8_t>(crc);
133}
134
140[[nodiscard]] constexpr bool CrcVectorsHold() noexcept {
141 using detail::operator""_u8;
142 // CRC(0xBEEF) = 0x92 with initial value 0xFF (every SF06 document, Table 14).
143 bool ok = Crc8(0xFF_u8, 0xBE_u8, 0xEF_u8) == 0x92_u8;
144 // The same word with the SF05 initial value 0x00 (AN-SFM-04): 0x13.
145 ok = ok && (Crc8(0x00_u8, 0xBE_u8, 0xEF_u8) == 0x13_u8);
146 // The SFx6000 worked sequence `36 61 36 08 D0`: CRC(0x3608) = 0xD0.
147 ok = ok && (Crc8(0xFF_u8, 0x36_u8, 0x08_u8) == 0xD0_u8);
148 // The SFM3304 scale-read argument 0x3603 carries CRC 0x3A (SFM3304
149 // section 4.3.5).
150 ok = ok && (Crc8(0xFF_u8, 0x36_u8, 0x03_u8) == 0x3A_u8);
151 // A zero word is not a valid frame with the SF06 initial value: a stuck-low
152 // bus fails its CRC.
153 ok = ok && (Crc8(0xFF_u8, 0x00_u8, 0x00_u8) == 0x81_u8);
154 // A zero word with the SF05 initial value is valid (CRC 0x00), so SF05 needs
155 // a reply check too.
156 return ok && (Crc8(0x00_u8, 0x00_u8, 0x00_u8) == 0x00_u8);
157}
158static_assert(CrcVectorsHold());
159
162} // namespace sfm::reg
163
164#endif // SFM_FLOW_METER_REGISTERS_HPP
constexpr uint16_t kSf05Reset
Soft reset (SFM3x00).
Definition sfm_flow_meter_registers.hpp:69
constexpr uint16_t kSf05ScaleFlow
Flow scale factor.
Definition sfm_flow_meter_registers.hpp:70
constexpr uint16_t kCmdAveragingDual
SFM3505: configure averaging.
Definition sfm_flow_meter_registers.hpp:53
constexpr uint16_t kUnitSccm
Definition sfm_flow_meter_registers.hpp:94
constexpr uint16_t kCmdStartGas0
Start continuous measurement, gas 0.
Definition sfm_flow_meter_registers.hpp:37
detail::Field< uint16_t, 0U, 10U > StatusConcentration
Definition sfm_flow_meter_registers.hpp:107
constexpr uint16_t kCmdStartMixture1
Start, mixture 1.
Definition sfm_flow_meter_registers.hpp:45
constexpr uint16_t kUnitSlm
Definition sfm_flow_meter_registers.hpp:91
constexpr uint8_t kSf04ReadOnly2
Read read-only register 2.
Definition sfm_flow_meter_registers.hpp:81
detail::Field< uint16_t, 0U, 9U > StatusAverages
SFM3304 status word, bits 8:0: the configured number of averages.
Definition sfm_flow_meter_registers.hpp:111
constexpr uint16_t kCmdStartMixture2
Start, mixture 2.
Definition sfm_flow_meter_registers.hpp:46
constexpr uint8_t kSf04Eeprom
Read the EEPROM.
Definition sfm_flow_meter_registers.hpp:82
constexpr uint16_t kCmdReadScale
Read scale factor, offset and unit (argument).
Definition sfm_flow_meter_registers.hpp:54
constexpr uint16_t kSf05Flow
Start flow measurement / point at the flow.
Definition sfm_flow_meter_registers.hpp:67
constexpr uint16_t kCmdProductId
Read the product identifier (idle).
Definition sfm_flow_meter_registers.hpp:57
constexpr uint8_t kSf04UserRegister
Read the user register.
Definition sfm_flow_meter_registers.hpp:80
constexpr uint16_t kSf04EepromSerial
EEPROM address of the product serial number.
Definition sfm_flow_meter_registers.hpp:83
constexpr uint16_t kSf05Serial
Definition sfm_flow_meter_registers.hpp:72
constexpr uint8_t Crc8(uint8_t init, uint8_t high, uint8_t low) noexcept
CRC-8 of one 16-bit word as the chip computes it: polynomial 0x31 (x^8.
Definition sfm_flow_meter_registers.hpp:123
constexpr bool CrcVectorsHold() noexcept
The CRC vectors of the datasheets, proved at build time (see the static_assert below).
Definition sfm_flow_meter_registers.hpp:140
detail::Field< uint16_t, 10U, 1U > StatusFixedN
Status word, bit 10: fixed-N averaging is active (SF06 and SFM3304).
Definition sfm_flow_meter_registers.hpp:104
constexpr uint16_t kCmdStartGas3
Start continuous measurement, gas 3.
Definition sfm_flow_meter_registers.hpp:40
constexpr uint8_t kGeneralCallReset
Byte sent to address 0x00 to reset.
Definition sfm_flow_meter_registers.hpp:63
constexpr uint16_t kCmdSfxTemperature
SFx6000: point the read at the temperature.
Definition sfm_flow_meter_registers.hpp:61
constexpr uint16_t kCmdStartGas4
Start, gas 4 (SFx6000 argon; reserved on SF06).
Definition sfm_flow_meter_registers.hpp:41
constexpr uint16_t kCmdSfxScalePointer
SFx6000: point the read at the gas information.
Definition sfm_flow_meter_registers.hpp:59
detail::Field< uint16_t, 11U, 1U > StatusSmoothing
Status word, bit 11: exponential smoothing is active (SF06 and SFM3304).
Definition sfm_flow_meter_registers.hpp:102
constexpr uint8_t kSf04TriggerTemperature
Trigger a temperature measurement.
Definition sfm_flow_meter_registers.hpp:78
constexpr uint16_t kCmdStartGas2
Start continuous measurement, gas 2.
Definition sfm_flow_meter_registers.hpp:39
detail::Field< uint16_t, 12U, 4U > StatusCommand
Definition sfm_flow_meter_registers.hpp:100
constexpr uint16_t kSf04EepromUnit
EEPROM address of the flow-unit word.
Definition sfm_flow_meter_registers.hpp:86
detail::Field< uint16_t, 9U, 1U > StatusFilterArg
SFM3304 status word, bit 9: a filter argument was received.
Definition sfm_flow_meter_registers.hpp:109
constexpr uint16_t kSf04EepromScale
EEPROM address of the scale factor.
Definition sfm_flow_meter_registers.hpp:85
constexpr uint16_t kCmdAveraging
SF06 and SFM3304: configure averaging.
Definition sfm_flow_meter_registers.hpp:52
constexpr uint16_t kCmdStartSfxMixture0
SFx6000: start, mixture 0.
Definition sfm_flow_meter_registers.hpp:47
constexpr uint16_t kStatusPureGas
Status bits 9:0 of a pure gas.
Definition sfm_flow_meter_registers.hpp:96
constexpr uint16_t kCmdSleep
Enter sleep mode.
Definition sfm_flow_meter_registers.hpp:56
constexpr uint16_t kSf05SerialLow
Serial number, least significant word.
Definition sfm_flow_meter_registers.hpp:74
constexpr uint16_t kSf04FieldStride
EEPROM size of one calibration field.
Definition sfm_flow_meter_registers.hpp:87
constexpr uint8_t kSf04SoftReset
Soft reset.
Definition sfm_flow_meter_registers.hpp:79
constexpr uint8_t kGeneralCallAddress
The I2C general-call address.
Definition sfm_flow_meter_registers.hpp:64
constexpr uint16_t kCmdDeviceIdDual
SFM3505: read the device identifier.
Definition sfm_flow_meter_registers.hpp:58
constexpr uint16_t kSf05Temperature
Point at the temperature.
Definition sfm_flow_meter_registers.hpp:68
constexpr uint16_t kCmdResultPointer
Point the read at the result buffer.
Definition sfm_flow_meter_registers.hpp:50
constexpr uint16_t kCmdStop
Stop continuous measurement.
Definition sfm_flow_meter_registers.hpp:51
constexpr uint16_t kCmdStartGas1
Start continuous measurement, gas 1.
Definition sfm_flow_meter_registers.hpp:38
constexpr uint16_t kCmdStartMixture0
Start, mixture 0 (argument: O2 in per mille).
Definition sfm_flow_meter_registers.hpp:43
constexpr uint16_t kCmdUpdateConcentration
Update concentration, part 1 (argument).
Definition sfm_flow_meter_registers.hpp:48
constexpr uint8_t kSf04TriggerFlow
Trigger a flow measurement.
Definition sfm_flow_meter_registers.hpp:77
constexpr uint16_t kSf05OffsetFlow
Flow offset.
Definition sfm_flow_meter_registers.hpp:71
Command codes and field helpers.
Definition sfm_flow_meter_registers.hpp:27
Compile-time helpers of the SFM_FLOW_METER driver: typed integer literals, exact hook matching,...