14#ifndef NTC_THERMISTOR_HPP
15#define NTC_THERMISTOR_HPP
23#include "ntc_thermistor_version.h"
34template <
typename Port>
35concept DeclaresSetBias =
requires(Port& port) { port.SetBias(
true); };
38template <
typename Port>
39concept HasSetBias =
requires { ExactHook<Port, bool(
bool)
noexcept>::Take(&Port::SetBias); };
42template <
typename Port>
43concept DeclaresDelayUs =
requires(Port& port) { port.DelayUs(1_u32); };
46template <
typename Port>
47concept HasDelayUs =
requires { ExactHook<Port, void(uint32_t)
noexcept>::Take(&Port::DelayUs); };
73template <AdcPort Port>
75 static_assert(!detail::DeclaresSetBias<Port> || detail::HasSetBias<Port>,
76 "ntc_thermistor: the optional SetBias hook must be `bool "
78 "noexcept`, so that a failed pin write is reported");
79 static_assert(!detail::DeclaresDelayUs<Port> || detail::HasDelayUs<Port>,
80 "ntc_thermistor: the DelayUs hook must be `void "
81 "DelayUs(uint32_t us) noexcept`, "
82 "so that no wait is truncated");
178 bool initialized_{
false};
179 uint32_t last_code_{0};
187#include "../src/ntc_thermistor.ipp"
Driver for one NTC thermistor in a resistor divider on an ADC port.
Definition ntc_thermistor.hpp:74
Result< void > EnsureInitialized() noexcept
Start the driver, once: the only way to initialise it.
bool IsInitialized() const noexcept
Definition ntc_thermistor.hpp:115
NtcThermistor(Port &port, const Config &config) noexcept
Bind the driver to a port and store the configuration. No I/O, cannot fail.
Definition ntc_thermistor.hpp:93
NtcThermistor(const NtcThermistor &)=delete
One driver object per thermistor.
Result< Reading > Read() noexcept
Read the temperature: bias on, settle, sample_count conversions, bias off, convert.
Result< void > SetConfig(const Config &config) noexcept
Replace the configuration. It is validated first; on failure the old one stays.
uint32_t GetLastCode() const noexcept
Definition ntc_thermistor.hpp:166
Result< uint32_t > ReadResistance() noexcept
Read the thermistor's resistance in ohms: the divider arithmetic only, no curve and no window.
Result< uint32_t > ReadRawCode() noexcept
One raw conversion, with no averaging and no conversion: bias on, settle, one sample,...
const Config & GetConfig() const &noexcept
Definition ntc_thermistor.hpp:155
void GetConfig() const &&=delete
Not on a temporary driver: the reference would dangle (handbook KB-CPP20-044).
NtcThermistor & operator=(const NtcThermistor &)=delete
One driver object per thermistor.
Error
Why a call failed. Values 0 to 9 are the shared base set; this driver's own values start at 16.
Definition ntc_thermistor_types.hpp:45
The NTC thermistor driver: everything it declares lives here; internals in detail.
Definition ntc_thermistor.hpp:25
The ADC port of the NTC thermistor driver: the CRTP base and the AdcPort concept.
From an ADC code to a temperature: the divider, the curve, the bound, and the helpers around them....
Compile-time helpers of the NTC_THERMISTOR driver: typed integer literals, exact hook matching and en...
Public types of the NTC thermistor driver: errors, Result<T>, the curve and the configuration,...
Everything one thermistor and its divider need. There is no default part: a Config{} fails Validate()...
Definition ntc_thermistor_types.hpp:284
The value of a call, or why there is none.
Definition ntc_thermistor_types.hpp:120