1 /*
2  * Copyright (c) 2023 Google LLC
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef NTC_THERMISTOR_H
8 #define NTC_THERMISTOR_H
9 
10 #include <stdbool.h>
11 #include <zephyr/types.h>
12 
13 struct ntc_compensation {
14 	const int32_t temp_c;
15 	const uint32_t ohm;
16 };
17 
18 struct ntc_type {
19 	const struct ntc_compensation *comp;
20 	int n_comp;
21 };
22 
23 struct ntc_config {
24 	bool connected_positive;
25 	uint32_t pullup_mv;
26 	uint32_t pullup_ohm;
27 	uint32_t pulldown_ohm;
28 	struct ntc_type type;
29 };
30 
31 /**
32  * @brief Converts ohm to temperature in milli centigrade.
33  *
34  * @param[in] type Pointer to ntc_type table info
35  * @param[in] ohm Read resistance of NTC thermistor
36  *
37  * @return Temperature in milli centigrade
38  */
39 int32_t ntc_get_temp_mc(const struct ntc_type *type, unsigned int ohm);
40 
41 /**
42  * @brief Calculate the resistance read from NTC thermistor.
43  *
44  * @param[in] cfg NTC thermistor configuration
45  * @param[in] sample_value Measured voltage relative to `sample_value_max`
46  * @param[in] sample_value_max Maximum of `sample_value`
47  *
48  * @return Thermistor resistance
49  */
50 uint32_t ntc_get_ohm_of_thermistor(const struct ntc_config *cfg, int sample_value,
51 				  int sample_value_max);
52 
53 #endif /* NTC_THERMISTOR_H */
54