BMP581 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
bmp581.hpp
Go to the documentation of this file.
1
16#ifndef BMP581_HPP
17#define BMP581_HPP
18
19#include <algorithm>
20#include <array>
21#include <cstddef>
22#include <cstdint>
23#include <span>
24
25#include "bmp581_detail.hpp"
27#include "bmp581_registers.hpp"
29#include "bmp581_types.hpp"
30#include "bmp581_version.h"
31
32namespace bmp581 {
33
39template <typename Port>
41
42namespace detail {
43
44// Optional hooks: a `Declares*` concept only tests the name, the `Has*` concept the exact
45// signature, `noexcept` and the result type; the driver rejects a hook that is declared but does
46// not match (KB-CPP20-007).
47
49template <typename Port>
50concept DeclaresDelayUs = requires(Port& port) { port.DelayUs(1_u32); };
51
54template <typename Port>
55concept HasDelayUs = requires { ExactHook<Port, void(uint32_t) noexcept>::Take(&Port::DelayUs); };
56
58template <typename Port>
59concept DeclaresLog = requires(Port& port) { port.Log(LogLevel::Info, ""); };
60
62template <typename Port>
63concept HasLog =
64 requires { ExactHook<Port, void(LogLevel, const char*) noexcept>::Take(&Port::Log); };
65
67template <BusPort Port>
68struct BusFor;
70template <BusPort Port>
71 requires I2cPort<Port>
72struct BusFor<Port> {
73 using Type = I2cRegisterBus<Port>;
75 static constexpr bool kSelectionFrame = false;
76};
78template <BusPort Port>
79 requires SpiPort<Port>
80struct BusFor<Port> {
81 using Type = SpiRegisterBus<Port>;
84 static constexpr bool kSelectionFrame = true;
85};
86
89template <typename Port>
90void DelayUs(Port& port, uint32_t us) noexcept {
91 if constexpr (HasDelayUs<Port>) {
92 port.DelayUs(us);
93 } else {
94 static_assert(kAlwaysFalse<Port>,
95 "bmp581: the port must implement `void DelayUs(uint32_t us) noexcept`");
96 }
97}
98
100template <typename Port>
101void Log(Port& port, [[maybe_unused]] LogLevel level,
102 [[maybe_unused]] const char* message) noexcept {
103 if constexpr (HasLog<Port>) {
104 port.Log(level, message);
105 } else {
106 (void)port;
107 }
108}
109
110// Register encoders and decoders: free constexpr functions, emitted once whatever the port type,
111// and proved below with static_assert (KB-CPP20-009, -012).
112
114[[nodiscard]] constexpr uint8_t SetIf(uint8_t value, uint8_t bit, bool on) noexcept {
115 return on ? static_cast<uint8_t>(static_cast<uint32_t>(value) | static_cast<uint32_t>(bit))
116 : value;
117}
118
120[[nodiscard]] constexpr bool Has(uint8_t value, uint8_t bits) noexcept {
121 return (static_cast<uint32_t>(value) & static_cast<uint32_t>(bits)) != 0U;
122}
123
125[[nodiscard]] constexpr uint8_t IntConfigValue(const Config& c) noexcept {
126 auto v = reg::IntConfigMode::Insert(0_u8, ToUnderlying(c.int_mode));
127 v = reg::IntConfigPol::Insert(v, ToUnderlying(c.int_polarity));
128 v = reg::IntConfigOd::Insert(v, ToUnderlying(c.int_drive));
129 v = reg::IntConfigEn::Insert(v, c.int_pin_enable ? 1_u32 : 0_u32);
130 return reg::IntConfigPadDrv::Insert(v, c.int_pad_drive);
131}
132
134[[nodiscard]] constexpr uint8_t IntSourceValue(const Config& c) noexcept {
135 auto v = SetIf(0_u8, reg::kIntDrdy, c.source_data_ready);
136 v = SetIf(v, reg::kIntFifoFull, c.source_fifo_full);
137 v = SetIf(v, reg::kIntFifoThs, c.source_fifo_threshold);
138 return SetIf(v, reg::kIntOorP, c.source_out_of_range);
139}
140
142[[nodiscard]] constexpr uint8_t FifoConfigValue(const Config& c) noexcept {
143 return reg::FifoModeBit::Insert(reg::FifoThreshold::Insert(0_u8, c.fifo_threshold),
144 ToUnderlying(c.fifo_mode));
145}
146
148[[nodiscard]] constexpr uint8_t FifoSelValue(const Config& c) noexcept {
149 return reg::FifoDecSel::Insert(reg::FifoFrameSel::Insert(0_u8, ToUnderlying(c.fifo_frame)),
150 c.fifo_decimation);
151}
152
155[[nodiscard]] constexpr uint8_t DspConfigValue(const Config& c) noexcept {
156 auto v = reg::DspCompPtEn::Insert(0_u8, 3_u32);
157 v = SetIf(v, reg::kDspIirFlushForced, c.iir_flush_in_forced);
158 v = SetIf(v, reg::kDspShdwSelIir, c.iir_to_data_registers);
159 v = SetIf(v, reg::kDspFifoSelIir, c.iir_to_fifo);
160 return SetIf(v, reg::kDspOorSelIirP, c.iir_to_out_of_range);
161}
162
164[[nodiscard]] constexpr uint8_t DspIirValue(const Config& c) noexcept {
165 return reg::DspIirP::Insert(reg::DspIirT::Insert(0_u8, ToUnderlying(c.temperature_iir)),
166 ToUnderlying(c.pressure_iir));
167}
168
170[[nodiscard]] constexpr uint8_t OorConfigValue(const Config& c) noexcept {
171 return reg::OorCntLim::Insert(reg::OorThrP16::Insert(0_u8, c.oor_reference_pa >> 16U),
172 ToUnderlying(c.oor_count));
173}
174
178[[nodiscard]] constexpr uint8_t OsrConfigValue(const Config& c) noexcept {
179 const auto v =
180 reg::OsrP::Insert(reg::OsrT::Insert(0_u8, ToUnderlying(c.temperature_oversampling)),
181 ToUnderlying(c.pressure_oversampling));
182 return SetIf(v, reg::kOsrPressEn, true);
183}
184
186[[nodiscard]] constexpr uint8_t OdrConfigValue(const Config& c, PowerMode mode) noexcept {
187 const auto v =
188 reg::OdrPwrMode::Insert(reg::OdrOdr::Insert(0_u8, ToUnderlying(c.odr)), ToUnderlying(mode));
189 return SetIf(v, reg::kOdrDeepDis, !c.deep_standby);
190}
191
193struct RegisterWrite {
194 uint8_t reg;
195 uint8_t value;
196};
197
202[[nodiscard]] constexpr std::array<RegisterWrite, 12> ConfigWrites(const Config& c) noexcept {
203 return {
204 {{.reg = reg::kIntConfig, .value = IntConfigValue(c)},
205 {.reg = reg::kDspConfig, .value = DspConfigValue(c)},
206 {.reg = reg::kDspIir, .value = DspIirValue(c)},
207 {.reg = reg::kFifoConfig, .value = FifoConfigValue(c)},
208 {.reg = reg::kFifoSel, .value = FifoSelValue(c)},
209 {.reg = reg::kOorThrPLsb, .value = static_cast<uint8_t>(c.oor_reference_pa & 0xFFU)},
210 {.reg = reg::kOorThrPMsb, .value = static_cast<uint8_t>((c.oor_reference_pa >> 8U) & 0xFFU)},
211 {.reg = reg::kOorRange, .value = c.oor_window_pa},
212 {.reg = reg::kOorConfig, .value = OorConfigValue(c)},
213 {.reg = reg::kOsrConfig, .value = OsrConfigValue(c)},
214 {.reg = reg::kIntSource, .value = IntSourceValue(c)},
215 {.reg = reg::kOdrConfig, .value = OdrConfigValue(c, PowerMode::Standby)}}};
216}
217
220[[nodiscard]] constexpr std::array<uint8_t, 5> ExpectedBlockA(const Config& c) noexcept {
221 return {IntConfigValue(c), IntSourceValue(c), FifoConfigValue(c), 0_u8, FifoSelValue(c)};
222}
223
225[[nodiscard]] constexpr std::array<uint8_t, 8> ExpectedBlockB(const Config& c) noexcept {
226 return {DspConfigValue(c),
227 DspIirValue(c),
228 static_cast<uint8_t>(c.oor_reference_pa & 0xFFU),
229 static_cast<uint8_t>((c.oor_reference_pa >> 8U) & 0xFFU),
230 c.oor_window_pa,
231 OorConfigValue(c),
232 OsrConfigValue(c),
233 OdrConfigValue(c, PowerMode::Standby)};
234}
235
238[[nodiscard]] constexpr uint8_t OdrAwakeStandby(const Config& c) noexcept {
239 return SetIf(OdrConfigValue(c, PowerMode::Standby), reg::kOdrDeepDis, true);
240}
241
248inline constexpr std::array<uint8_t, 2> kMarker{0x3CU, 0xC3U};
249
251[[nodiscard]] constexpr bool OsrShowsReset(uint8_t osr) noexcept {
252 return !Has(osr, reg::kOsrPressEn);
253}
254
256[[nodiscard]] constexpr InterruptStatus DecodeIntStatus(uint8_t raw) noexcept {
257 return InterruptStatus{.data_ready = Has(raw, reg::kIntDrdy),
258 .fifo_full = Has(raw, reg::kIntFifoFull),
259 .fifo_threshold = Has(raw, reg::kIntFifoThs),
260 .out_of_range = Has(raw, reg::kIntOorP),
261 .power_on_reset = Has(raw, reg::kIntPor)};
262}
263
265[[nodiscard]] constexpr uint32_t Le24(std::span<const uint8_t, 3> b) noexcept {
266 return static_cast<uint32_t>(b[0]) | (static_cast<uint32_t>(b[1]) << 8U) |
267 (static_cast<uint32_t>(b[2]) << 16U);
268}
269
271inline constexpr std::size_t kDataFrameBytes = 12U;
273inline constexpr std::size_t kDataIntStatus = 10U;
275inline constexpr std::size_t kDataStatus = 11U;
276
278[[nodiscard]] constexpr bool AllBytes(std::span<const uint8_t> bytes, uint8_t value) noexcept {
279 return std::ranges::all_of(bytes, [value](uint8_t b) noexcept -> bool { return b == value; });
280}
281
286[[nodiscard]] constexpr bool DataFrameValid(std::span<const uint8_t, kDataFrameBytes> f) noexcept {
287 const auto reserved = f.subspan<6, 4>();
288 return AllBytes(reserved, 0_u8) && !Has(f[kDataIntStatus], 0xE0_u8) &&
289 !Has(f[kDataStatus], reg::kStatusReserved) && !AllBytes(f, 0_u8);
290}
291
294[[nodiscard]] constexpr Result<Measurement> DecodeMeasurement(uint32_t temperature,
295 uint32_t pressure) noexcept {
296 if ((temperature == reg::kDataReset) || (pressure == reg::kDataReset)) {
298 }
299 const Measurement m{.pressure_raw = SignExtend24(pressure),
300 .temperature_raw = SignExtend24(temperature)};
301 if (!PressureInRange(m.pressure_raw) || !TemperatureInRange(m.temperature_raw)) {
303 }
305}
306
309[[nodiscard]] constexpr uint32_t FifoFrameBytes(FifoFrame frame) noexcept {
310 switch (frame) {
313 return 3U;
315 return 6U;
317 default:
318 break;
319 }
320 return 0U;
321}
322
324[[nodiscard]] constexpr uint32_t FifoCapacity(FifoFrame frame) noexcept {
326}
327
330[[nodiscard]] constexpr FifoSample DecodeFifoValue(FifoSample s, uint32_t raw,
331 bool pressure) noexcept {
332 if (s.error != Error::Ok) {
333 return s;
334 }
335 if (raw == reg::kDataReset) {
336 return FifoSample{.error = Error::NoData};
337 }
338 const int32_t value = SignExtend24(raw);
339 if (pressure ? !PressureInRange(value) : !TemperatureInRange(value)) {
340 return FifoSample{.error = Error::OutOfRange};
341 }
342 if (pressure) {
343 s.has_pressure = true;
344 s.pressure_raw = value;
345 } else {
346 s.has_temperature = true;
347 s.temperature_raw = value;
348 }
349 return s;
350}
351
353[[nodiscard]] constexpr FifoSample DecodeFifoFrame(FifoFrame frame,
354 std::span<const uint8_t, 6> b) noexcept {
355 const uint32_t first = Le24(b.first<3>());
357 const FifoSample t = DecodeFifoValue(FifoSample{}, first, false);
358 return DecodeFifoValue(t, Le24(b.last<3>()), true);
359 }
360 return DecodeFifoValue(FifoSample{}, first, frame == FifoFrame::Pressure);
361}
362
363// The reset configuration encodes to the reset values of section 7, except press_en.
364static_assert(IntConfigValue(Config{}) == reg::kIntConfigReset);
365static_assert(DspConfigValue(Config{}) == reg::kDspConfigReset);
366static_assert(OdrConfigValue(Config{}, PowerMode::Standby) == reg::kOdrConfigReset);
367static_assert(OsrConfigValue(Config{}) == reg::kOsrPressEn);
368static_assert((IntSourceValue(Config{}) == 0U) && (FifoConfigValue(Config{}) == 0U) &&
369 (FifoSelValue(Config{}) == 0U) && (DspIirValue(Config{}) == 0U) &&
370 (OorConfigValue(Config{}) == 0U));
371// No configuration encodes OSR_CONFIG without press_en; the reset value shows a reset.
372static_assert(!OsrShowsReset(OsrConfigValue(HighResolutionPreset())));
373static_assert(OsrShowsReset(reg::kOsrConfigReset));
374// The example of section 4.7.2.3: 97150 Pa +/- 50 Pa.
375static_assert(OorConfigValue(Config{.oor_reference_pa = 97'150U}) == 0x01U);
376static_assert(ConfigWrites(Config{.oor_reference_pa = 97'150U})[6].value == 0x7BU);
377static_assert(ConfigWrites(Config{.oor_reference_pa = 97'150U})[5].value == 0x7EU);
378// The FIFO frames of tables 11 to 13 and the empty frame of table 14.
379static_assert(Le24(std::array<uint8_t, 3>{0x00U, 0xA6U, 0x0EU}) == 0x0E'A600U);
380static_assert(DecodeFifoFrame(FifoFrame::Pressure,
381 std::array<uint8_t, 6>{0x00U, 0xA6U, 0x5EU, 0U, 0U, 0U})
382 .pressure_raw == 6'202'880);
383static_assert(DecodeFifoFrame(FifoFrame::Temperature,
384 std::array<uint8_t, 6>{0x7FU, 0x7FU, 0x7FU, 0U, 0U, 0U})
385 .error == Error::NoData);
386static_assert(DecodeMeasurement(0x7F'7F7FU, 0x7F'7F7FU).error == Error::NoData);
387static_assert(DecodeMeasurement(0x19'0000U, 0x61'A800U).value.pressure_raw == 6'400'000);
388static_assert(DecodeMeasurement(0U, 0U).error == Error::OutOfRange);
389static_assert(DecodeIntStatus(reg::kIntStatusAfterReset).power_on_reset);
390
391} // namespace detail
392
399// clang-format off: the table below must keep one row per line.
445// clang-format on
446template <BusPort Port>
447class BMP581 {
448 static_assert(!detail::DeclaresDelayUs<Port> || detail::HasDelayUs<Port>,
449 "bmp581: the DelayUs hook must be `void DelayUs(uint32_t us) noexcept`, so that no "
450 "wait is truncated");
451 static_assert(!detail::DeclaresLog<Port> || detail::HasLog<Port>,
452 "bmp581: the optional Log hook must be `void Log(LogLevel, const char* message) "
453 "noexcept`");
454 static_assert(!detail::DeclaresGetLastFailure<Port> || detail::HasGetLastFailure<Port>,
455 "bmp581: the optional GetLastFailure hook must be `bool "
456 "GetLastFailure(I2cFailure& failure) noexcept`");
457
458public:
465 explicit BMP581(Port& port, const Config& config = {}) noexcept : bus_(port), config_(config) {}
466
474 BMP581(Port& port, uint8_t address, const Config& config = {}) noexcept
475 requires I2cPort<Port>
476 : bus_(port, address), config_(config) {}
477
479 BMP581(const BMP581&) = delete;
481 BMP581& operator=(const BMP581&) = delete;
482
485
515
518 [[nodiscard]] bool IsInitialized() const noexcept {
519 return initialized_;
520 }
521
538
553 Result<void> ApplyConfig(const Config& config) noexcept;
554
556 [[nodiscard]] const Config& GetConfig() const& noexcept {
557 return config_;
558 }
560 void GetConfig() const&& = delete;
561
564 [[nodiscard]] bool IsConfigKnown() const noexcept {
565 return config_known_;
566 }
567
586
598
602
621
637
648 Result<void> WaitDataReady() noexcept;
649
657
661
669 Result<uint8_t> ReadFifoCount() noexcept;
670
686 Result<std::size_t> ReadFifo(std::span<FifoSample> out, Verify verify = Verify::None) noexcept;
687
691
698 [[nodiscard]] InterruptStatus GetLatchedInterrupts() const noexcept {
699 return detail::DecodeIntStatus(latched_int_);
700 }
701
703 void ClearLatchedInterrupts() noexcept {
704 latched_int_ = 0;
705 }
706
708 [[nodiscard]] uint8_t GetLastIntStatus() const noexcept {
709 return last_int_status_;
710 }
711
713 [[nodiscard]] uint8_t GetLastStatus() const noexcept {
714 return last_status_;
715 }
716
718 [[nodiscard]] uint8_t GetLastOsrEff() const noexcept {
719 return last_osr_eff_;
720 }
721
723 [[nodiscard]] uint8_t GetRevision() const noexcept {
724 return revision_;
725 }
726
740 Result<uint8_t> ReadRegister(uint8_t address) noexcept;
741
743
744private:
745 using Bus = typename detail::BusFor<Port>::Type;
746
747 Result<void> initialize() noexcept;
748 Result<void> resetChip() noexcept;
749 Result<void> identify() noexcept;
750 Result<void> waitNvmReady() noexcept;
751 Result<void> checkResetFlags() noexcept;
752 Result<void> wake(const Config& config) noexcept;
753 void leaveDeepStandby() noexcept;
754 Result<void> configure(const Config& config, uint8_t odr) noexcept;
755 void waitFifoFlush() noexcept;
756 Result<bool> markerCleared() noexcept;
757 Result<void> ensureMarker() noexcept;
758 Result<void> waitForcedShown() noexcept;
759 Result<void> checkSelectionFrame() noexcept;
760 Result<void> writeConfig(const Config& config) noexcept;
761 Result<void> readBackConfig(const Config& config) noexcept;
762 Result<void> enterStandby(const Config& config) noexcept;
763 Result<void> enterMode(const Config& config, PowerMode mode) noexcept;
764 Error checkModeReadBack(const Config& config, PowerMode mode) noexcept;
765 Result<void> afterFailedSequence(Error own) noexcept;
766 Result<void> standbyAfterStart() noexcept;
767 Result<Measurement> readData(Verify verify) noexcept;
768 Result<Measurement> confirmData(std::span<const uint8_t, 6> first) noexcept;
769 Result<uint8_t> readFifoCountRaw() noexcept;
770 Result<std::size_t> readFifoFrames(std::span<FifoSample> out, uint32_t count) noexcept;
771 Result<uint8_t> readIntStatus() noexcept;
772 void noteIntStatus(uint8_t raw) noexcept;
773 Result<uint8_t> checkSentinel() noexcept;
774 [[nodiscard]] bool sentinelEvidence(const Result<std::array<uint8_t, 2>>& pair) const noexcept;
775 Result<std::array<uint8_t, 2>> readSentinelPair() noexcept;
776 Error settle(Error own) noexcept;
777 Error porContradicted(Error own) noexcept;
778 Result<bool> configHeld() noexcept;
779 Result<uint8_t> checkBeforeWrite() noexcept;
780 Result<void> gate() noexcept;
781 Result<uint8_t> readByte(uint8_t reg) noexcept;
782 Error read(uint8_t reg, std::size_t count) noexcept;
783 Error write(uint8_t reg, uint8_t value) noexcept;
784 Error markReset() noexcept;
785 Result<void> fail(Error error, const char* message) noexcept;
786
787 Bus bus_;
788 Config config_{};
789 std::array<uint8_t, kFifoMaxBytes> buffer_{};
790 uint8_t revision_{0};
791 uint8_t last_int_status_{0};
792 uint8_t last_status_{0};
793 uint8_t last_osr_eff_{0};
794 uint8_t latched_int_{0};
795 bool initialized_{false};
796 bool started_once_{false};
797 bool config_known_{false};
798 bool check_pending_{false};
799 bool por_unconfirmed_{false};
800 bool marker_fresh_{false};
802 bool sentinel_doubt_{false};
804};
805
808} // namespace bmp581
809
810// codeql::misra_deviation_next_line(MD-CPP-009)
811#include "../src/bmp581.ipp" // IWYU pragma: export
812
813#endif // BMP581_HPP
Compile-time helpers of the BMP581 driver: typed integer literals, exact hook matching,...
The I2C port of the BMP581 driver: the CRTP base, the I2cPort concept, the bus requirements and the r...
BMP581 register map: addresses, bit fields and reset values (datasheet section 7).
The SPI port of the BMP581 driver: the CRTP base, the SpiPort concept, the bus requirements and the r...
Public types of the BMP581 driver: errors, Result<T>, configuration, measurements and the datasheet's...
Driver for one BMP581 on a platform port.
Definition bmp581.hpp:447
Result< Measurement > MeasureOnce(Verify verify=Verify::None) noexcept
One forced measurement (section 4.3.3): the reset check, ODR_CONFIG with pwr_mode = forced,...
BMP581(Port &port, const Config &config={}) noexcept
Bind the driver to a port (on I2C at i2c::kI2cAddress) and store the configuration....
Definition bmp581.hpp:465
uint8_t GetLastStatus() const noexcept
Definition bmp581.hpp:713
Result< std::size_t > ReadFifo(std::span< FifoSample > out, Verify verify=Verify::None) noexcept
Read up to out.size() frames from the FIFO: FIFO_COUNT, then one burst of whole frames from FIFO_DATA...
Result< void > CheckForReset() noexcept
Find out whether the chip reset since the start: one 3-byte read of OSR_CONFIG to OSR_EFF,...
void ClearLatchedInterrupts() noexcept
Empty the latch of GetLatchedInterrupts(). No I/O.
Definition bmp581.hpp:703
uint8_t GetLastIntStatus() const noexcept
Definition bmp581.hpp:708
BMP581 & operator=(const BMP581 &)=delete
One driver object per chip.
BMP581(Port &port, uint8_t address, const Config &config={}) noexcept
Bind the driver to an I2C port at a 7-bit address and store the configuration. No I/O.
Definition bmp581.hpp:474
Result< Measurement > ReadMeasurement(Verify verify=Verify::None) noexcept
Read the latest measurement from the data registers: one 12-byte read of TEMP_DATA to STATUS (section...
Result< void > SetPowerMode(PowerMode mode) noexcept
Change the power mode (section 4.3.7).
Result< void > WaitDataReady() noexcept
Wait for new data in normal or continuous mode: INT_STATUS polled every kPollUs until drdy_data_reg,...
InterruptStatus GetLatchedInterrupts() const noexcept
The INT_STATUS flags seen by any read since ClearLatchedInterrupts(), the driver's own reads included...
Definition bmp581.hpp:698
Result< InterruptStatus > ReadInterruptStatus() noexcept
Read INT_STATUS once (section 7.21): clears its flags on the chip; the driver latches them....
bool IsInitialized() const noexcept
Definition bmp581.hpp:518
Result< void > Deinitialize() noexcept
Put the chip in its lowest-power state with the soft reset, CMD = 0xB6: it leaves the chip in deep st...
Result< void > EnsureInitialized() noexcept
Start the chip. Once started, a later call runs the reset check (one 3-byte read) and returns Ok,...
void GetConfig() const &&=delete
Not on a temporary driver: the reference would dangle (KB-CPP20-044).
uint8_t GetLastOsrEff() const noexcept
Definition bmp581.hpp:718
BMP581(const BMP581 &)=delete
One driver object per chip.
const Config & GetConfig() const &noexcept
Definition bmp581.hpp:556
Result< uint8_t > ReadRegister(uint8_t address) noexcept
Read one register once: one transfer, no retry, no decoding (handbook KB-CPP-129).
bool IsConfigKnown() const noexcept
Definition bmp581.hpp:564
Result< void > ApplyConfig(const Config &config) noexcept
Replace the configuration.
Result< uint8_t > ReadFifoCount() noexcept
Read FIFO_COUNT (section 4.6.2). With the FIFO on, a count of 0 runs the reset check: a reset empties...
uint8_t GetRevision() const noexcept
Definition bmp581.hpp:723
A port the driver accepts: an I2cPort or an SpiPort, never both, so the bus framing is never ambiguou...
Definition bmp581.hpp:40
Satisfied by a class that derives from I2cInterface<Port> and implements the required hooks with exac...
Definition bmp581_i2c_interface.hpp:104
Satisfied by a class that derives from SpiInterface<Port> and implements the required hooks with exac...
Definition bmp581_spi_interface.hpp:100
constexpr uint8_t kFifoConfig
FIFO_CONFIG (R/W): threshold, mode (7.7).
Definition bmp581_registers.hpp:42
constexpr uint8_t kOsrConfigReset
OSR_CONFIG: x1, x1, pressure off.
Definition bmp581_registers.hpp:76
constexpr uint8_t kIntPor
INT_STATUS only: POR or soft reset complete.
Definition bmp581_registers.hpp:99
constexpr uint8_t kDspIirFlushForced
iir_flush_forced_en.
Definition bmp581_registers.hpp:121
constexpr uint8_t kOdrConfig
ODR_CONFIG (R/W): power mode, ODR (7.34).
Definition bmp581_registers.hpp:67
constexpr uint8_t kOorConfig
OOR_CONFIG (R/W): reference bit 16, count (7.32).
Definition bmp581_registers.hpp:65
constexpr uint8_t kIntFifoThs
FIFO threshold reached.
Definition bmp581_registers.hpp:97
constexpr uint8_t kFifoSel
FIFO_SEL (R/W): frame type, decimation (7.9).
Definition bmp581_registers.hpp:44
constexpr uint8_t kOsrConfig
OSR_CONFIG (R/W): oversampling, press_en (7.33).
Definition bmp581_registers.hpp:66
constexpr uint8_t kOorThrPMsb
OOR_THR_P_MSB (R/W): reference bits 15..8.
Definition bmp581_registers.hpp:63
constexpr uint8_t kOorThrPLsb
OOR_THR_P_LSB (R/W): reference bits 7..0.
Definition bmp581_registers.hpp:62
constexpr uint8_t kIntConfig
INT_CONFIG (R/W): the INT pin (section 7.5).
Definition bmp581_registers.hpp:40
constexpr uint8_t kDspIir
DSP_IIR (R/W): IIR coefficients (7.28).
Definition bmp581_registers.hpp:61
constexpr uint8_t kIntConfigReset
Definition bmp581_registers.hpp:73
constexpr uint8_t kStatusReserved
reserved_6_5: read 0.
Definition bmp581_registers.hpp:117
constexpr uint8_t kDspOorSelIirP
Out-of-range check after the IIR.
Definition bmp581_registers.hpp:126
constexpr uint32_t kDataReset
Definition bmp581_registers.hpp:79
constexpr uint8_t kOorRange
OOR_RANGE (R/W): window, Pa (7.31).
Definition bmp581_registers.hpp:64
constexpr uint8_t kIntDrdy
Data ready (drdy_data_reg).
Definition bmp581_registers.hpp:95
constexpr uint8_t kDspConfigReset
DSP_CONFIG: both compensated, IIR off.
Definition bmp581_registers.hpp:75
constexpr uint8_t kOdrConfigReset
ODR_CONFIG: standby, 1 Hz, deep standby on.
Definition bmp581_registers.hpp:77
constexpr uint8_t kDspShdwSelIir
Both data registers after the IIR.
Definition bmp581_registers.hpp:127
constexpr uint8_t kDspFifoSelIir
Both FIFO values after the IIR.
Definition bmp581_registers.hpp:128
constexpr uint8_t kOdrDeepDis
deep_dis: deep standby disabled.
Definition bmp581_registers.hpp:156
constexpr uint8_t kDspConfig
DSP_CONFIG (R/W): compensation, IIR routing.
Definition bmp581_registers.hpp:60
constexpr uint8_t kIntStatusAfterReset
Definition bmp581_registers.hpp:82
constexpr uint8_t kIntFifoFull
FIFO full.
Definition bmp581_registers.hpp:96
constexpr uint8_t kIntSource
INT_SOURCE (R/W): interrupt sources (7.6).
Definition bmp581_registers.hpp:41
constexpr uint8_t kOsrPressEn
press_en: pressure measured as well.
Definition bmp581_registers.hpp:150
constexpr uint8_t kIntOorP
Pressure out of range.
Definition bmp581_registers.hpp:98
constexpr bool TemperatureInRange(int32_t raw) noexcept
Whether a raw temperature lies in the measurement range, -40 to 85 °C (table 2).
Definition bmp581_types.hpp:635
constexpr Config HighResolutionPreset() noexcept
High resolution at 25 Hz: pressure x16 (table 9), the IIR on the data registers, data ready reported.
Definition bmp581_types.hpp:722
LogLevel
Severity passed to the optional Log() hook.
Definition bmp581_types.hpp:205
FifoFrame
What the FIFO stores, FIFO_SEL.fifo_frame_sel (section 4.6.1).
Definition bmp581_types.hpp:289
constexpr bool PressureInRange(int32_t raw) noexcept
Whether a raw pressure lies in the measurement range, 30 to 125 kPa (table 1).
Definition bmp581_types.hpp:625
constexpr uint32_t kFifoFramesSingle
Frames the FIFO holds with 3-byte frames (section 4.6).
Definition bmp581_types.hpp:377
PowerMode
The power mode, ODR_CONFIG.pwr_mode (sections 4.3, 7.34).
Definition bmp581_types.hpp:220
Verify
Extra traffic a call may spend to check what it did (handbook KB-ARCH-041).
Definition bmp581_types.hpp:213
constexpr uint32_t kFifoFramesBoth
Frames the FIFO holds with 6-byte frames (section 4.6).
Definition bmp581_types.hpp:379
constexpr int32_t SignExtend24(uint32_t raw) noexcept
A 24-bit two's complement register value as a signed integer, the one place the driver reinterprets w...
Definition bmp581_types.hpp:597
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition bmp581_types.hpp:40
@ Info
Lifecycle events: initialised, reset.
@ Pressure
3-byte pressure frames, up to 32.
@ Disabled
FIFO off. Reset value.
@ PressureAndTemperature
6-byte frames, temperature first, up to 16.
@ Temperature
3-byte temperature frames, up to 32.
@ None
Only the traffic the datasheet needs.
@ Ok
The call succeeded.
The BMP581 driver: everything it declares lives here; internals in detail.
Definition bmp581.hpp:32
Everything EnsureInitialized() and ApplyConfig() write to the chip.
Definition bmp581_types.hpp:411
One FIFO frame, with its own validity: a multi-item read reports each item.
Definition bmp581_types.hpp:352
Error error
Ok, NoData (0x7F7F7F) or OutOfRange; the values are 0 then.
Definition bmp581_types.hpp:353
The interrupt status flags, INT_STATUS (section 7.21), decoded. Reading INT_STATUS clears them on the...
Definition bmp581_types.hpp:332
bool data_ready
drdy_data_reg: new data in the data registers and the FIFO.
Definition bmp581_types.hpp:333
bool power_on_reset
por: a power-on or soft reset completed.
Definition bmp581_types.hpp:337
One measurement in the chip's own units, as the data registers hold it (section 4....
Definition bmp581_types.hpp:346
The value of a call, or why there is none.
Definition bmp581_types.hpp:145
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition bmp581_types.hpp:171
static constexpr Result Success(T v) noexcept
A successful result.
Definition bmp581_types.hpp:163