MCP9700 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Classes | Namespaces | Enumerations | Functions | Variables
mcp9700_types.hpp File Reference

Public types of the MCP970x driver: errors, Result<T>, the variant table, configuration, presets, Validate() and the pure conversion functions. More...

#include <array>
#include <cstddef>
#include <cstdint>
#include "mcp9700_detail.hpp"
#include "mcp9700_version.h"

Go to the source code of this file.

Classes

struct  mcp9700::Result< T >
 The value of a call, or why there is none. More...
 
struct  mcp9700::Result< void >
 The result of a call that returns no value. More...
 
struct  mcp9700::CustomSpec
 What the user declares for Variant::Custom. Every field must be set (an all-zero declaration fails Validate()); every field must stay zero for a named variant. More...
 
struct  mcp9700::Config
 Everything EnsureInitialized() uses. Config{} is an MCP9700 on a 12 bit, 3.3 V ADC. More...
 
struct  mcp9700::AccuracyBand
 One accuracy limit of the datasheet: the error band guaranteed over a temperature span. More...
 
struct  mcp9700::VariantSpec
 One row of the variant table: the only place a coefficient, range, supply, accuracy band or package list lives. The code never branches on a variant name. More...
 
struct  mcp9700::AccuracyLimits
 The guaranteed error limits at one temperature, milli-C. More...
 
struct  mcp9700::Measurement
 The temperature and the voltage behind it, from one validated reading. More...
 

Namespaces

namespace  mcp9700
 The MCP970x driver: everything it declares lives here; internals in detail.
 

Enumerations

enum class  mcp9700::Error : uint8_t {
  mcp9700::Error::Ok = 0 , mcp9700::Error::NotInitialized = 1 , mcp9700::Error::InvalidArgument = 2 , mcp9700::Error::Bus = 3 ,
  mcp9700::Error::Timeout = 4 , mcp9700::Error::DeviceIdMismatch = 5 , mcp9700::Error::Crc = 6 , mcp9700::Error::Busy = 7 ,
  mcp9700::Error::DeviceFault = 8 , mcp9700::Error::Unsupported = 9 , mcp9700::Error::OutputLow = 16 , mcp9700::Error::OutputHigh = 17 ,
  mcp9700::Error::Saturated = 18 , mcp9700::Error::Unstable = 19
}
 Why a call failed. Values 0 to 9 are the shared base set; chip-specific values start at 16. More...
 
enum class  mcp9700::Variant : uint8_t {
  mcp9700::Variant::Mcp9700 = 0 , mcp9700::Variant::Mcp9700A = 1 , mcp9700::Variant::Mcp9700B = 2 , mcp9700::Variant::Mcp9701 = 3 ,
  mcp9700::Variant::Mcp9701A = 4 , mcp9700::Variant::Custom = 5
}
 Which part of the family is wired up: one of the five datasheet devices, or Custom. More...
 
enum class  mcp9700::TemperatureClass : uint8_t { mcp9700::TemperatureClass::Extended = 0 , mcp9700::TemperatureClass::High = 1 }
 The temperature class of the part: the upper end of its specified range. More...
 
enum class  mcp9700::LogLevel : uint8_t { mcp9700::LogLevel::Error = 0 , mcp9700::LogLevel::Warning , mcp9700::LogLevel::Info , mcp9700::LogLevel::Debug }
 Severity passed to the optional Log() hook. More...
 

Functions

constexpr const char * mcp9700::ToString (Error error) noexcept
 The name of an error, for logs.
 
constexpr Error mcp9700::Validate (const Config &config) noexcept
 Check a configuration without touching the hardware.
 
constexpr Result< VariantSpec > mcp9700::ResolveSpec (const Config &config) noexcept
 The effective variant row of a configuration: a table row, or the row built from the Custom declaration. No I/O.
 
constexpr int32_t mcp9700::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. No window check, no calibration.
 
constexpr uint32_t mcp9700::MilliCToOutputMv (const VariantSpec &spec, int32_t temperature_mc) noexcept
 The output voltage of a temperature: the inverse of OutputMvToMilliC(), rounded to the nearest millivolt.
 
constexpr Result< AccuracyLimits > mcp9700::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, narrowest first). With High only the High-option rows (-40 to +150 C) apply over the whole range: the datasheet does not say that an H part also meets the tighter Extended rows. For a named variant they hold at its tested supply; the driver never applies them to a reading.
 
constexpr float mcp9700::ToCelsius (int32_t milli_c) noexcept
 A temperature as float degrees Celsius, for printing and for callers that want it. The only floating-point in the driver.
 
constexpr Config mcp9700::ConfigFor (Variant variant) noexcept
 The configuration of a named part: Config{} with that variant.
 
constexpr Config mcp9700::FastPreset () noexcept
 One conversion per reading: lowest latency, no noise rejection.
 
constexpr Config mcp9700::LowNoisePreset () noexcept
 32 conversions 200 us apart: averages ADC noise and mains pickup.
 
constexpr Config mcp9700::Mcp9701Preset () noexcept
 The MCP9701 transfer function and range.
 
constexpr Config mcp9700::HighTemperaturePreset () noexcept
 An MCP9700 with the High temperature option (to +150 C).
 
constexpr const char * mcp9700::GetDriverVersion () noexcept
 
constexpr uint32_t mcp9700::GetDriverVersionMajor () noexcept
 
constexpr uint32_t mcp9700::GetDriverVersionMinor () noexcept
 
constexpr uint32_t mcp9700::GetDriverVersionPatch () noexcept
 

Variables

constexpr uint16_t mcp9700::kMaxSamples = 64U
 Largest number of conversions one reading averages.
 
constexpr uint32_t mcp9700::kMaxSampleIntervalUs = 100'000U
 Largest wait between two conversions, microseconds.
 
constexpr uint8_t mcp9700::kMaxDiscard = 4U
 Largest number of dummy conversions before a reading.
 
constexpr uint32_t mcp9700::kMaxPowerOnSettleUs = 1'000'000U
 Largest power-on wait, microseconds.
 
constexpr uint64_t mcp9700::kMaxAveragingWindowUs = 1'000'000ULL
 Longest span of one reading, (discard + samples - 1) x interval, microseconds: below the 1.3 s thermal response (t_RES, p.4), so an average is never staler than the sensor (design decision).
 
constexpr uint32_t mcp9700::kMaxSpreadLimitMv = 1000U
 Largest max_spread_mv.
 
constexpr int32_t mcp9700::kMaxOffsetCalMc = 20'000
 Largest absolute offset_cal_mc, milli-degrees.
 
constexpr int32_t mcp9700::kMaxRangeMarginMc = 20'000
 Largest range_margin_mc, milli-degrees.
 
constexpr uint32_t mcp9700::kMinAdcFullScaleMv = 100U
 Smallest declarable ADC full scale, millivolts.
 
constexpr uint32_t mcp9700::kMaxAdcFullScaleMv = 10'000U
 Largest declarable ADC full scale, millivolts.
 
constexpr uint8_t mcp9700::kMinAdcResolutionBits = 8U
 Smallest declarable ADC resolution, bits.
 
constexpr uint8_t mcp9700::kMaxAdcResolutionBits = 16U
 Largest declarable ADC resolution, bits.
 
constexpr uint32_t mcp9700::kCustomMinTcUvPerC = 1000U
 Custom: smallest slope, microvolts per degree.
 
constexpr uint32_t mcp9700::kCustomMaxTcUvPerC = 100'000U
 Custom: largest slope, microvolts per degree.
 
constexpr uint32_t mcp9700::kCustomMaxV0Mv = 5000U
 Custom: largest output at 0 C, millivolts.
 
constexpr int32_t mcp9700::kCustomMaxTemperatureMc = 200'000
 Custom: largest absolute temperature limit, milli-degrees.
 
constexpr uint32_t mcp9700::kCustomMaxOutputMv = 20'000U
 Custom: largest output voltage anywhere in the declared range, millivolts.
 
constexpr int32_t mcp9700::kCustomMaxAccuracyMc = 20'000
 Custom: largest absolute accuracy limit, milli-degrees.
 
constexpr uint8_t mcp9700::kPackageSot23 = 1U
 Package bit: SOT-23-3 (/TT).
 
constexpr uint8_t mcp9700::kPackageSc70 = 2U
 Package bit: SC70-5 (/LT).
 
constexpr uint8_t mcp9700::kPackageTo92 = 4U
 Package bit: TO-92-3 (/TO).
 
constexpr uint8_t mcp9700::kPackagesAll
 Every package: SOT-23-3, SC70-5 and TO-92-3.
 
constexpr uint8_t mcp9700::kPackagesNoTo92 = static_cast<uint8_t>(kPackageSot23 + kPackageSc70)
 The packages without TO-92-3 (the MCP9700B, and the High option of every part).
 
constexpr std::size_t mcp9700::kMaxBands = 4U
 Most accuracy bands one row holds.
 
constexpr std::array< VariantSpec, 5 > mcp9700::kVariantTable
 The five datasheet devices (DS20001942L), indexed by Variant. Every value is cited in docs/hardware.md: coefficients p.3 and p.4, supply p.3, ranges p.4, accuracy p.3, packages p.12 and p.23.
 

Detailed Description

Public types of the MCP970x driver: errors, Result<T>, the variant table, configuration, presets, Validate() and the pure conversion functions.

The sensor's transfer function is first order, V_OUT = V_0C + T_C x T (datasheet DS20001942L, Equation 4-1, p.10). Temperatures are milli-degrees Celsius (_mc), voltages millivolts (_mv), coefficients microvolts per degree (_uv_per_c); the driver uses integers only. One constexpr table holds the five named parts; Variant::Custom takes a fully declared first-order part.