MCP9700 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
mcp9700_types.hpp
Go to the documentation of this file.
1
17#ifndef MCP9700_TYPES_HPP
18#define MCP9700_TYPES_HPP
19
20#include <array>
21#include <cstddef>
22#include <cstdint>
23
24#include "mcp9700_detail.hpp"
25#include "mcp9700_version.h"
26
29namespace mcp9700 {
30
46enum class [[nodiscard]] Error : uint8_t {
47 Ok = 0,
48 NotInitialized = 1,
50 InvalidArgument = 2,
51 Bus = 3,
52 Timeout = 4,
54 Crc = 6,
55 Busy = 7,
56 DeviceFault = 8,
57 Unsupported = 9,
59 OutputLow = 16,
60 OutputHigh = 17,
61 Saturated = 18,
63 Unstable = 19,
65};
66
72constexpr const char* ToString(Error error) noexcept {
73 switch (error) {
74 case Error::Ok:
75 return "Ok";
77 return "NotInitialized";
79 return "InvalidArgument";
80 case Error::Bus:
81 return "Bus";
82 case Error::Timeout:
83 return "Timeout";
85 return "DeviceIdMismatch";
86 case Error::Crc:
87 return "Crc";
88 case Error::Busy:
89 return "Busy";
91 return "DeviceFault";
93 return "Unsupported";
95 return "OutputLow";
97 return "OutputHigh";
99 return "Saturated";
100 case Error::Unstable:
101 return "Unstable";
102 default:
103 break;
104 }
105 return "Unknown";
106}
111template <typename T>
112struct [[nodiscard]] Result {
113 T value{};
114 Error error{Error::Ok};
115
117 [[nodiscard]] constexpr bool ok() const noexcept {
118 return error == Error::Ok;
119 }
121 constexpr explicit operator bool() const noexcept {
122 return ok();
123 }
129 static constexpr Result Success(T v) noexcept {
130 return {v, Error::Ok};
131 }
137 static constexpr Result Failure(Error e) noexcept {
138 return {T{}, e};
139 }
140};
141
143template <>
144struct [[nodiscard]] Result<void> {
145 Error error{Error::Ok};
146
148 [[nodiscard]] constexpr bool ok() const noexcept {
149 return error == Error::Ok;
150 }
152 constexpr explicit operator bool() const noexcept {
153 return ok();
154 }
156 static constexpr Result Success() noexcept {
157 return {Error::Ok};
158 }
164 static constexpr Result Failure(Error e) noexcept {
165 return {e};
166 }
167};
168
177enum class Variant : uint8_t {
178 Mcp9700 = 0,
180 Mcp9700A = 1,
181 Mcp9700B = 2,
183 Mcp9701 = 3,
184 Mcp9701A = 4,
185 Custom = 5,
187};
188
191enum class TemperatureClass : uint8_t {
192 Extended = 0,
193 High = 1,
195};
196
197namespace detail {
199template <>
200struct EnumLast<Variant> {
201 static constexpr Variant kValue = Variant::Custom;
202};
204template <>
205struct EnumLast<TemperatureClass> {
206 static constexpr TemperatureClass kValue = TemperatureClass::High;
207};
208} // namespace detail
209
211inline constexpr uint16_t kMaxSamples = 64U;
213inline constexpr uint32_t kMaxSampleIntervalUs = 100'000U;
215inline constexpr uint8_t kMaxDiscard = 4U;
217inline constexpr uint32_t kMaxPowerOnSettleUs = 1'000'000U;
223inline constexpr uint64_t kMaxAveragingWindowUs = 1'000'000ULL;
225inline constexpr uint32_t kMaxSpreadLimitMv = 1000U;
227inline constexpr int32_t kMaxOffsetCalMc = 20'000;
229inline constexpr int32_t kMaxRangeMarginMc = 20'000;
231inline constexpr uint32_t kMinAdcFullScaleMv = 100U;
233inline constexpr uint32_t kMaxAdcFullScaleMv = 10'000U;
235inline constexpr uint8_t kMinAdcResolutionBits = 8U;
237inline constexpr uint8_t kMaxAdcResolutionBits = 16U;
239inline constexpr uint32_t kCustomMinTcUvPerC = 1000U;
241inline constexpr uint32_t kCustomMaxTcUvPerC = 100'000U;
243inline constexpr uint32_t kCustomMaxV0Mv = 5000U;
245inline constexpr int32_t kCustomMaxTemperatureMc = 200'000;
248inline constexpr uint32_t kCustomMaxOutputMv = 20'000U;
250inline constexpr int32_t kCustomMaxAccuracyMc = 20'000;
251
261 uint32_t v0_mv{0U};
262 uint32_t tc_uv_per_c{0U};
263 int32_t min_mc{0};
264 int32_t max_mc{0};
265 int32_t accuracy_min_mc{0};
267 int32_t accuracy_max_mc{0};
269};
270
274struct Config {
275 uint8_t channel{0U};
279 uint32_t adc_full_scale_mv{3300U};
280 uint8_t adc_resolution_bits{12U};
281 uint16_t divider_num{1U};
282 uint16_t divider_den{1U};
283 int32_t offset_cal_mc{0};
284 int32_t range_margin_mc{8000};
285 uint16_t samples{8U};
286 uint32_t sample_interval_us{100U};
288 uint32_t max_spread_mv{30U};
290 2400U};
291};
292
297 int32_t from_mc{0};
298 int32_t to_mc{0};
299 int32_t min_mc{0};
300 int32_t max_mc{0};
301 bool high_only{false};
302};
303
305inline constexpr uint8_t kPackageSot23 = 1U;
307inline constexpr uint8_t kPackageSc70 = 2U;
309inline constexpr uint8_t kPackageTo92 = 4U;
310
312inline constexpr uint8_t kPackagesAll =
313 static_cast<uint8_t>(kPackageSot23 + kPackageSc70 + kPackageTo92);
316inline constexpr uint8_t kPackagesNoTo92 = static_cast<uint8_t>(kPackageSot23 + kPackageSc70);
317
319inline constexpr std::size_t kMaxBands = 4U;
320
327 uint32_t v0_mv{0U};
328 uint32_t tc_uv_per_c{0U};
329 int32_t min_mc{0};
330 int32_t max_ext_mc{0};
331 int32_t max_high_mc{0};
332 bool has_high{false};
333 uint32_t vdd_min_mv{0U};
334 uint32_t vdd_max_mv{0U};
335 uint32_t tested_vdd_mv{0U};
336 uint8_t packages{0U};
337 uint8_t high_packages{0U};
338 uint8_t band_count{0U};
339 std::array<AccuracyBand, kMaxBands> bands{};
340};
341
344 int32_t min_mc{0};
345 int32_t max_mc{0};
346};
347
348namespace detail {
350constexpr AccuracyBand Band(int32_t from_mc, int32_t to_mc, int32_t min_mc, int32_t max_mc,
351 bool high_only) noexcept {
352 return {.from_mc = from_mc,
353 .to_mc = to_mc,
354 .min_mc = min_mc,
355 .max_mc = max_mc,
356 .high_only = high_only};
357}
358} // namespace detail
359
365inline constexpr std::array<VariantSpec, 5> kVariantTable{
366 {// MCP9700
367 {.v0_mv = 500U,
368 .tc_uv_per_c = 10'000U,
369 .min_mc = -40'000,
370 .max_ext_mc = 125'000,
371 .max_high_mc = 150'000,
372 .has_high = true,
373 .vdd_min_mv = 2300U,
374 .vdd_max_mv = 5500U,
375 .tested_vdd_mv = 3300U,
376 .packages = kPackagesAll,
377 .high_packages = kPackagesNoTo92,
378 .band_count = 3U,
379 .bands = {{detail::Band(0, 70'000, -4000, 4000, false),
380 detail::Band(-40'000, 125'000, -4000, 6000, false),
381 detail::Band(-40'000, 150'000, -4000, 6000, true)}}},
382 // MCP9700A
383 {.v0_mv = 500U,
384 .tc_uv_per_c = 10'000U,
385 .min_mc = -40'000,
386 .max_ext_mc = 125'000,
387 .max_high_mc = 125'000,
388 .has_high = false,
389 .vdd_min_mv = 2300U,
390 .vdd_max_mv = 5500U,
391 .tested_vdd_mv = 3300U,
392 .packages = kPackagesAll,
393 .high_packages = 0U,
394 .band_count = 2U,
395 .bands = {{detail::Band(0, 70'000, -2000, 2000, false),
396 detail::Band(-40'000, 125'000, -2000, 4000, false)}}},
397 // MCP9700B
398 {.v0_mv = 500U,
399 .tc_uv_per_c = 10'000U,
400 .min_mc = -40'000,
401 .max_ext_mc = 125'000,
402 .max_high_mc = 150'000,
403 .has_high = true,
404 .vdd_min_mv = 2300U,
405 .vdd_max_mv = 5500U,
406 .tested_vdd_mv = 3300U,
407 .packages = kPackagesNoTo92,
408 .high_packages = kPackagesNoTo92,
409 .band_count = 4U,
410 .bands = {{detail::Band(20'000, 70'000, -1000, 1000, false),
411 detail::Band(0, 125'000, -2000, 3000, false),
412 detail::Band(-40'000, 125'000, -2000, 4000, false),
413 detail::Band(-40'000, 150'000, -4000, 4000, true)}}},
414 // MCP9701
415 {.v0_mv = 400U,
416 .tc_uv_per_c = 19'500U,
417 .min_mc = -10'000,
418 .max_ext_mc = 125'000,
419 .max_high_mc = 125'000,
420 .has_high = false,
421 .vdd_min_mv = 3100U,
422 .vdd_max_mv = 5500U,
423 .tested_vdd_mv = 5000U,
424 .packages = kPackagesAll,
425 .high_packages = 0U,
426 .band_count = 2U,
427 .bands = {{detail::Band(0, 70'000, -4000, 4000, false),
428 detail::Band(-10'000, 125'000, -4000, 6000, false)}}},
429 // MCP9701A
430 {.v0_mv = 400U,
431 .tc_uv_per_c = 19'500U,
432 .min_mc = -10'000,
433 .max_ext_mc = 125'000,
434 .max_high_mc = 125'000,
435 .has_high = false,
436 .vdd_min_mv = 3100U,
437 .vdd_max_mv = 5500U,
438 .tested_vdd_mv = 5000U,
439 .packages = kPackagesAll,
440 .high_packages = 0U,
441 .band_count = 2U,
442 .bands = {{detail::Band(0, 70'000, -2000, 2000, false),
443 detail::Band(-10'000, 125'000, -2000, 4000, false)}}}}};
444
448 int32_t temperature_mc{0};
449 uint32_t output_mv{0U};
450 uint32_t spread_mv{0U};
451};
452
454enum class LogLevel : uint8_t {
455 Error = 0,
456 Warning,
457 Info,
458 Debug,
459};
460
461namespace detail {
462
465inline constexpr int64_t kPerMega = 1'000'000;
466
468constexpr int64_t RoundDivAway(int64_t num, int64_t den) noexcept {
469 const int64_t half = den / 2;
470 return (num >= 0) ? ((num + half) / den) : (-((-num + half) / den));
471}
472
474constexpr int64_t OutputNanoVolts(uint32_t v0_mv, uint32_t tc_uv_per_c, int64_t t_mc) noexcept {
475 return (static_cast<int64_t>(v0_mv) * kPerMega) + (static_cast<int64_t>(tc_uv_per_c) * t_mc);
476}
477
479constexpr bool WithinSymmetric(int32_t x, int32_t limit) noexcept {
480 return (x >= -limit) && (x <= limit);
481}
482
484constexpr bool CustomIsZero(const CustomSpec& c) noexcept {
485 return (c.v0_mv == 0U) && (c.tc_uv_per_c == 0U) && (c.min_mc == 0) && (c.max_mc == 0) &&
486 (c.accuracy_min_mc == 0) && (c.accuracy_max_mc == 0);
487}
488
491constexpr bool CustomOutputInWindow(const CustomSpec& c, int32_t t_mc) noexcept {
492 const int64_t nv = OutputNanoVolts(c.v0_mv, c.tc_uv_per_c, t_mc);
493 return (nv >= 0) && (nv <= (static_cast<int64_t>(kCustomMaxOutputMv) * kPerMega));
494}
495
497constexpr bool CustomTransferOk(const CustomSpec& c) noexcept {
498 return (c.tc_uv_per_c >= kCustomMinTcUvPerC) && (c.tc_uv_per_c <= kCustomMaxTcUvPerC) &&
499 (c.v0_mv <= kCustomMaxV0Mv) && (c.min_mc < c.max_mc) &&
500 WithinSymmetric(c.min_mc, kCustomMaxTemperatureMc) &&
501 WithinSymmetric(c.max_mc, kCustomMaxTemperatureMc) && CustomOutputInWindow(c, c.min_mc) &&
502 CustomOutputInWindow(c, c.max_mc);
503}
504
507constexpr bool CustomAccuracyOk(const CustomSpec& c) noexcept {
508 return (c.accuracy_min_mc <= 0) && (c.accuracy_max_mc >= 0) &&
509 ((c.accuracy_min_mc != 0) || (c.accuracy_max_mc != 0)) &&
510 WithinSymmetric(c.accuracy_min_mc, kCustomMaxAccuracyMc) &&
511 WithinSymmetric(c.accuracy_max_mc, kCustomMaxAccuracyMc);
512}
513
516constexpr bool VariantDeclarationOk(const Config& config) noexcept {
517 if (!IsEnumerator(config.variant) || !IsEnumerator(config.range)) {
518 return false;
519 }
520 if (config.variant == Variant::Custom) {
521 return (config.range == TemperatureClass::Extended) && CustomTransferOk(config.custom) &&
522 CustomAccuracyOk(config.custom);
523 }
524 if (!CustomIsZero(config.custom)) {
525 return false;
526 }
527 return (config.range != TemperatureClass::High) ||
528 kVariantTable[static_cast<std::size_t>(ToUnderlying(config.variant))].has_high;
529}
530
532constexpr bool AdcDeclarationOk(const Config& config) noexcept {
533 return (config.adc_full_scale_mv >= kMinAdcFullScaleMv) &&
534 (config.adc_full_scale_mv <= kMaxAdcFullScaleMv) &&
535 (config.adc_resolution_bits >= kMinAdcResolutionBits) &&
536 (config.adc_resolution_bits <= kMaxAdcResolutionBits) && (config.divider_num != 0U) &&
537 (config.divider_den != 0U) && WithinSymmetric(config.offset_cal_mc, kMaxOffsetCalMc) &&
538 (config.range_margin_mc >= 0) && (config.range_margin_mc <= kMaxRangeMarginMc);
539}
540
542constexpr bool SamplingOk(const Config& config) noexcept {
543 if ((config.samples == 0U) || (config.samples > kMaxSamples) ||
544 (config.discard_conversions > kMaxDiscard) ||
545 (config.sample_interval_us > kMaxSampleIntervalUs)) {
546 return false;
547 }
548 const uint64_t conversions = static_cast<uint64_t>(config.discard_conversions) +
549 static_cast<uint64_t>(config.samples) - 1U;
550 return ((conversions * static_cast<uint64_t>(config.sample_interval_us)) <=
552 (config.max_spread_mv <= kMaxSpreadLimitMv) &&
553 (config.power_on_settle_us <= kMaxPowerOnSettleUs);
554}
555
556} // namespace detail
557
566constexpr Error Validate(const Config& config) noexcept {
567 if (!detail::VariantDeclarationOk(config) || !detail::AdcDeclarationOk(config) ||
568 !detail::SamplingOk(config)) {
570 }
571 return Error::Ok;
572}
573
580constexpr Result<VariantSpec> ResolveSpec(const Config& config) noexcept {
581 if (Validate(config) != Error::Ok) {
583 }
584 if (config.variant != Variant::Custom) {
586 kVariantTable[static_cast<std::size_t>(detail::ToUnderlying(config.variant))]);
587 }
588 VariantSpec spec{};
589 spec.v0_mv = config.custom.v0_mv;
590 spec.tc_uv_per_c = config.custom.tc_uv_per_c;
591 spec.min_mc = config.custom.min_mc;
592 spec.max_ext_mc = config.custom.max_mc;
593 spec.max_high_mc = config.custom.max_mc;
594 spec.band_count = 1U;
595 spec.bands[0] = detail::Band(config.custom.min_mc, config.custom.max_mc,
596 config.custom.accuracy_min_mc, config.custom.accuracy_max_mc, false);
597 return Result<VariantSpec>::Success(spec);
598}
599
608constexpr int32_t OutputMvToMilliC(const VariantSpec& spec, uint32_t output_mv) noexcept {
609 constexpr uint32_t kLargest = 65'535U;
610 const uint32_t mv = (output_mv < kLargest) ? output_mv : kLargest;
611 const int64_t num =
612 (static_cast<int64_t>(mv) - static_cast<int64_t>(spec.v0_mv)) * detail::kPerMega;
613 return static_cast<int32_t>(detail::RoundDivAway(num, static_cast<int64_t>(spec.tc_uv_per_c)));
614}
615
623constexpr uint32_t MilliCToOutputMv(const VariantSpec& spec, int32_t temperature_mc) noexcept {
624 const int64_t nv = detail::OutputNanoVolts(spec.v0_mv, spec.tc_uv_per_c, temperature_mc);
625 if (nv <= 0) {
626 return 0U;
627 }
628 const int64_t mv = detail::RoundDivAway(nv, detail::kPerMega);
629 constexpr int64_t kLargest = 0xFFFF'FFFFLL;
630 return static_cast<uint32_t>((mv < kLargest) ? mv : kLargest);
631}
632
646 int32_t temperature_mc) noexcept {
647 const bool high = range == TemperatureClass::High;
648 const int32_t top = high ? spec.max_high_mc : spec.max_ext_mc;
649 if ((high && !spec.has_high) || (temperature_mc < spec.min_mc) || (temperature_mc > top)) {
651 }
652 for (std::size_t i = 0; i < kMaxBands; ++i) {
653 const AccuracyBand& band = spec.bands[i];
654 if ((i < static_cast<std::size_t>(spec.band_count)) && (band.high_only == high) &&
655 (temperature_mc >= band.from_mc) && (temperature_mc <= band.to_mc)) {
656 return Result<AccuracyLimits>::Success({.min_mc = band.min_mc, .max_mc = band.max_mc});
657 }
658 }
660}
661
668constexpr float ToCelsius(int32_t milli_c) noexcept {
669 return static_cast<float>(milli_c) / 1000.0F;
670}
671
678constexpr Config ConfigFor(Variant variant) noexcept {
679 Config c{};
680 c.variant = variant;
681 return c;
682}
683
688constexpr Config FastPreset() noexcept {
689 Config c{};
690 c.samples = 1U;
691 c.sample_interval_us = 0U;
692 return c;
693}
694
699constexpr Config LowNoisePreset() noexcept {
700 Config c{};
701 c.samples = 32U;
702 c.sample_interval_us = 200U;
703 return c;
704}
705
710constexpr Config Mcp9701Preset() noexcept {
712}
713
718constexpr Config HighTemperaturePreset() noexcept {
719 Config c{};
721 return c;
722}
723
724static_assert(Validate(Config{}) == Error::Ok, "the default configuration is valid");
725static_assert(Validate(FastPreset()) == Error::Ok, "FastPreset is valid");
726static_assert(Validate(LowNoisePreset()) == Error::Ok, "LowNoisePreset is valid");
727static_assert(Validate(Mcp9701Preset()) == Error::Ok, "Mcp9701Preset is valid");
728static_assert(Validate(HighTemperaturePreset()) == Error::Ok, "HighTemperaturePreset is valid");
729
731constexpr const char* GetDriverVersion() noexcept {
732 return MCP9700_VERSION_STRING;
733}
735constexpr uint32_t GetDriverVersionMajor() noexcept {
736 return MCP9700_VERSION_MAJOR;
737}
739constexpr uint32_t GetDriverVersionMinor() noexcept {
740 return MCP9700_VERSION_MINOR;
741}
743constexpr uint32_t GetDriverVersionPatch() noexcept {
744 return MCP9700_VERSION_PATCH;
745}
746
749} // namespace mcp9700
750
751#endif // MCP9700_TYPES_HPP
constexpr uint8_t kMaxAdcResolutionBits
Largest declarable ADC resolution, bits.
Definition mcp9700_types.hpp:237
constexpr Config HighTemperaturePreset() noexcept
An MCP9700 with the High temperature option (to +150 C).
Definition mcp9700_types.hpp:718
LogLevel
Severity passed to the optional Log() hook.
Definition mcp9700_types.hpp:454
constexpr float ToCelsius(int32_t milli_c) noexcept
A temperature as float degrees Celsius, for printing and for callers that want it....
Definition mcp9700_types.hpp:668
constexpr uint8_t kMaxDiscard
Largest number of dummy conversions before a reading.
Definition mcp9700_types.hpp:215
constexpr Config FastPreset() noexcept
One conversion per reading: lowest latency, no noise rejection.
Definition mcp9700_types.hpp:688
constexpr uint32_t kCustomMinTcUvPerC
Custom: smallest slope, microvolts per degree.
Definition mcp9700_types.hpp:239
constexpr uint32_t GetDriverVersionPatch() noexcept
Definition mcp9700_types.hpp:743
constexpr int32_t OutputMvToMilliC(const VariantSpec &spec, uint32_t output_mv) noexcept
The temperature of an output voltage, from the row's V0 and TC; rounded half away from zero....
Definition mcp9700_types.hpp:608
constexpr int32_t kMaxRangeMarginMc
Largest range_margin_mc, milli-degrees.
Definition mcp9700_types.hpp:229
constexpr std::array< VariantSpec, 5 > kVariantTable
The five datasheet devices (DS20001942L), indexed by Variant. Every value is cited in docs/hardware....
Definition mcp9700_types.hpp:365
constexpr uint16_t kMaxSamples
Largest number of conversions one reading averages.
Definition mcp9700_types.hpp:211
constexpr uint8_t kPackagesAll
Every package: SOT-23-3, SC70-5 and TO-92-3.
Definition mcp9700_types.hpp:312
constexpr uint32_t kMaxPowerOnSettleUs
Largest power-on wait, microseconds.
Definition mcp9700_types.hpp:217
constexpr uint32_t MilliCToOutputMv(const VariantSpec &spec, int32_t temperature_mc) noexcept
The output voltage of a temperature: the inverse of OutputMvToMilliC(), rounded to the nearest milliv...
Definition mcp9700_types.hpp:623
constexpr int32_t kCustomMaxAccuracyMc
Custom: largest absolute accuracy limit, milli-degrees.
Definition mcp9700_types.hpp:250
constexpr uint8_t kMinAdcResolutionBits
Smallest declarable ADC resolution, bits.
Definition mcp9700_types.hpp:235
constexpr const char * GetDriverVersion() noexcept
Definition mcp9700_types.hpp:731
constexpr uint64_t kMaxAveragingWindowUs
Longest span of one reading, (discard + samples - 1) x interval, microseconds: below the 1....
Definition mcp9700_types.hpp:223
constexpr uint8_t kPackagesNoTo92
The packages without TO-92-3 (the MCP9700B, and the High option of every part).
Definition mcp9700_types.hpp:316
constexpr int32_t kMaxOffsetCalMc
Largest absolute offset_cal_mc, milli-degrees.
Definition mcp9700_types.hpp:227
constexpr uint32_t GetDriverVersionMinor() noexcept
Definition mcp9700_types.hpp:739
constexpr uint32_t kCustomMaxV0Mv
Custom: largest output at 0 C, millivolts.
Definition mcp9700_types.hpp:243
constexpr uint32_t kCustomMaxOutputMv
Custom: largest output voltage anywhere in the declared range, millivolts.
Definition mcp9700_types.hpp:248
constexpr uint8_t kPackageSc70
Package bit: SC70-5 (/LT).
Definition mcp9700_types.hpp:307
constexpr int32_t kCustomMaxTemperatureMc
Custom: largest absolute temperature limit, milli-degrees.
Definition mcp9700_types.hpp:245
constexpr uint32_t kMaxSpreadLimitMv
Largest max_spread_mv.
Definition mcp9700_types.hpp:225
constexpr uint32_t GetDriverVersionMajor() noexcept
Definition mcp9700_types.hpp:735
constexpr const char * ToString(Error error) noexcept
The name of an error, for logs.
Definition mcp9700_types.hpp:72
constexpr uint32_t kMaxSampleIntervalUs
Largest wait between two conversions, microseconds.
Definition mcp9700_types.hpp:213
Variant
Which part of the family is wired up: one of the five datasheet devices, or Custom.
Definition mcp9700_types.hpp:177
TemperatureClass
The temperature class of the part: the upper end of its specified range.
Definition mcp9700_types.hpp:191
constexpr uint32_t kMinAdcFullScaleMv
Smallest declarable ADC full scale, millivolts.
Definition mcp9700_types.hpp:231
constexpr Result< VariantSpec > ResolveSpec(const Config &config) noexcept
The effective variant row of a configuration: a table row, or the row built from the Custom declarati...
Definition mcp9700_types.hpp:580
constexpr std::size_t kMaxBands
Most accuracy bands one row holds.
Definition mcp9700_types.hpp:319
constexpr uint8_t kPackageTo92
Package bit: TO-92-3 (/TO).
Definition mcp9700_types.hpp:309
Error
Why a call failed. Values 0 to 9 are the shared base set; chip-specific values start at 16.
Definition mcp9700_types.hpp:46
constexpr uint32_t kCustomMaxTcUvPerC
Custom: largest slope, microvolts per degree.
Definition mcp9700_types.hpp:241
constexpr Error Validate(const Config &config) noexcept
Check a configuration without touching the hardware.
Definition mcp9700_types.hpp:566
constexpr uint8_t kPackageSot23
Package bit: SOT-23-3 (/TT).
Definition mcp9700_types.hpp:305
constexpr Result< AccuracyLimits > AccuracyLimitsFor(const VariantSpec &spec, TemperatureClass range, int32_t temperature_mc) noexcept
The error limits the datasheet guarantees at a temperature (first band that contains it,...
Definition mcp9700_types.hpp:645
constexpr Config LowNoisePreset() noexcept
32 conversions 200 us apart: averages ADC noise and mains pickup.
Definition mcp9700_types.hpp:699
constexpr Config Mcp9701Preset() noexcept
The MCP9701 transfer function and range.
Definition mcp9700_types.hpp:710
constexpr Config ConfigFor(Variant variant) noexcept
The configuration of a named part: Config{} with that variant.
Definition mcp9700_types.hpp:678
constexpr uint32_t kMaxAdcFullScaleMv
Largest declarable ADC full scale, millivolts.
Definition mcp9700_types.hpp:233
@ Warning
Something unexpected the driver continued from.
@ Info
Lifecycle events.
@ Debug
Detail for bring-up.
@ Mcp9701
400 mV at 0 C, 19.5 mV/C, -10 to +125 C, accuracy +-4 C.
@ Mcp9701A
As the MCP9701 with the +-2 C grade (0 to +70 C).
@ Mcp9700A
As the MCP9700 with the +-2 C grade (0 to +70 C).
@ Extended
-40 (MCP9701: -10) to +125 C, every part.
@ InvalidArgument
Validate() failed (at EnsureInitialized()); nothing was sent.
@ DeviceIdMismatch
Start-up found no plausible, stable output on the channel.
@ Crc
Not returned by this driver.
@ Bus
The port's ADC bring-up, a conversion or a pin write failed.
@ DeviceFault
Not returned by this driver.
@ OutputLow
The output is below the specified range minus the margin.
@ Ok
The call succeeded.
@ OutputHigh
The output is above the specified range plus the margin.
@ Timeout
Not returned by this driver.
@ Busy
Not returned by this driver.
Compile-time helpers of the MCP9700 driver: typed integer literals, exact hook matching,...
The MCP970x driver: everything it declares lives here; internals in detail.
Definition mcp9700.hpp:24
One accuracy limit of the datasheet: the error band guaranteed over a temperature span.
Definition mcp9700_types.hpp:296
bool high_only
The row exists for the High temperature class only.
Definition mcp9700_types.hpp:301
int32_t max_mc
Highest error, milli-C.
Definition mcp9700_types.hpp:300
int32_t to_mc
Upper end of the span, milli-C.
Definition mcp9700_types.hpp:298
int32_t min_mc
Lowest error, milli-C.
Definition mcp9700_types.hpp:299
int32_t from_mc
Lower end of the span, milli-C.
Definition mcp9700_types.hpp:297
The guaranteed error limits at one temperature, milli-C.
Definition mcp9700_types.hpp:343
int32_t min_mc
Lowest error.
Definition mcp9700_types.hpp:344
int32_t max_mc
Highest error.
Definition mcp9700_types.hpp:345
Everything EnsureInitialized() uses. Config{} is an MCP9700 on a 12 bit, 3.3 V ADC.
Definition mcp9700_types.hpp:274
uint8_t discard_conversions
Dummy conversions before a reading, up to kMaxDiscard.
Definition mcp9700_types.hpp:287
uint16_t divider_num
VOUT = pin x divider_num / divider_den.
Definition mcp9700_types.hpp:281
uint16_t divider_den
See divider_num.
Definition mcp9700_types.hpp:282
CustomSpec custom
Only with Variant::Custom.
Definition mcp9700_types.hpp:278
uint16_t samples
Conversions averaged per reading, 1 to kMaxSamples.
Definition mcp9700_types.hpp:285
uint32_t sample_interval_us
Wait between conversions, up to kMaxSampleIntervalUs.
Definition mcp9700_types.hpp:286
uint32_t max_spread_mv
Largest max-min of one reading at VOUT, mV.
Definition mcp9700_types.hpp:288
uint32_t power_on_settle_us
Wait after enabling the sensor, up to kMaxPowerOnSettleUs.
Definition mcp9700_types.hpp:289
uint32_t adc_full_scale_mv
Largest voltage the port can report, mV.
Definition mcp9700_types.hpp:279
int32_t range_margin_mc
Plausibility margin each side of the range, milli-C.
Definition mcp9700_types.hpp:284
Variant variant
A named part, or Custom.
Definition mcp9700_types.hpp:276
uint8_t adc_resolution_bits
ADC resolution, 8 to 16 bits.
Definition mcp9700_types.hpp:280
TemperatureClass range
High only for a part with that option.
Definition mcp9700_types.hpp:277
uint8_t channel
Passed to ReadVoltageMv() unchanged.
Definition mcp9700_types.hpp:275
int32_t offset_cal_mc
Added to the result: one-point calibration.
Definition mcp9700_types.hpp:283
What the user declares for Variant::Custom. Every field must be set (an all-zero declaration fails Va...
Definition mcp9700_types.hpp:260
int32_t accuracy_min_mc
Definition mcp9700_types.hpp:265
uint32_t v0_mv
Output at 0 C, millivolts (0 is valid).
Definition mcp9700_types.hpp:261
int32_t max_mc
Highest specified temperature, milli-C.
Definition mcp9700_types.hpp:264
uint32_t tc_uv_per_c
Slope, microvolts per C, 1000 to 100000 (positive only).
Definition mcp9700_types.hpp:262
int32_t accuracy_max_mc
Definition mcp9700_types.hpp:267
int32_t min_mc
Lowest specified temperature, milli-C.
Definition mcp9700_types.hpp:263
The temperature and the voltage behind it, from one validated reading.
Definition mcp9700_types.hpp:447
int32_t temperature_mc
Temperature after offset_cal_mc, milli-C.
Definition mcp9700_types.hpp:448
uint32_t spread_mv
Max minus min of the conversions, scaled, millivolts.
Definition mcp9700_types.hpp:450
uint32_t output_mv
Mean VOUT, scaled by the divider, millivolts.
Definition mcp9700_types.hpp:449
constexpr bool ok() const noexcept
Definition mcp9700_types.hpp:148
static constexpr Result Success() noexcept
Definition mcp9700_types.hpp:156
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition mcp9700_types.hpp:164
The value of a call, or why there is none.
Definition mcp9700_types.hpp:112
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition mcp9700_types.hpp:137
static constexpr Result Success(T v) noexcept
A successful result.
Definition mcp9700_types.hpp:129
constexpr bool ok() const noexcept
Definition mcp9700_types.hpp:117
One row of the variant table: the only place a coefficient, range, supply, accuracy band or package l...
Definition mcp9700_types.hpp:326
bool has_high
The row has a High class.
Definition mcp9700_types.hpp:332
uint8_t packages
kPackage* mask of the packages sold; 0 for Custom.
Definition mcp9700_types.hpp:336
uint32_t tested_vdd_mv
Supply at which the accuracy is tested, mV (0 unknown).
Definition mcp9700_types.hpp:335
int32_t max_ext_mc
Highest, Extended class, milli-C.
Definition mcp9700_types.hpp:330
uint8_t high_packages
kPackage* mask of the High option.
Definition mcp9700_types.hpp:337
std::array< AccuracyBand, kMaxBands > bands
Accuracy bands, narrowest first.
Definition mcp9700_types.hpp:339
int32_t min_mc
Lowest specified temperature, milli-C.
Definition mcp9700_types.hpp:329
uint32_t vdd_min_mv
Lowest supply, mV (0 when unknown).
Definition mcp9700_types.hpp:333
int32_t max_high_mc
Highest, High class, milli-C (= Extended when none).
Definition mcp9700_types.hpp:331
uint32_t vdd_max_mv
Highest supply, mV (0 when unknown).
Definition mcp9700_types.hpp:334
uint32_t tc_uv_per_c
Slope, microvolts per C (typical).
Definition mcp9700_types.hpp:328
uint8_t band_count
Used entries of bands.
Definition mcp9700_types.hpp:338
uint32_t v0_mv
Output at 0 C, millivolts (typical).
Definition mcp9700_types.hpp:327