drivers: sensor: zephyr_thermistor: refactor driver
Refactor driver to align a bit more with its Linux counterpart, ie, ntc_thermistor. This driver did quite a few _unconventional_ things, like using "zephyr," compatibles, a dedicated node for pre-computed compensation table (referenced by the actual pseudo-device node), etc. The comparison helper function should likely be simplified as well (to avoid the need for custom wrapper for bsearch), but this can be done later. In this refactor, each thermistor gets a compatible, e.g. "epcos,xxxx". Compatibles are known by the driver, so are compensation tables. This simplifies devicetree files. There's no need to bother about compensation tables in **every** board file if Zephyr supports a certain NTC model. In general we should respect Linux bindings, which in the end influence how drivers are implemented. In this case, this principle resulted in simplified, easier to use code. For future developers, this is how support for a new NTC can be added: 1. Add to the end of the driver: ```c #undef DT_DRV_COMPAT #define DT_DRV_COMPAT vnd_model static __unused const struct ntc_compensation comp_vnd_model[] = { { x, y }, ..., }; #define DT_INST_FOREACH_STATUS_OKAY_VARGS(NTC_THERMISTOR_DEV_INIT, DT_DRV_COMPAT, comp_vnd_model) ``` 3. In driver's Kconfig make sure it depends on DT_HAS_$DT_DRV_COMPAT$_ENABLED Note: $X$ means _value_ of X. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
parent
c60e4ec989
commit
44f48f6da7
16 changed files with 194 additions and 266 deletions
|
@ -23,32 +23,9 @@ test_adc_emul: adc {
|
|||
status = "okay";
|
||||
};
|
||||
|
||||
thermistor_R25_10000_B_3974: thermistor-R25-10000-B-3974 {
|
||||
compatible = "zephyr,ntc-thermistor-rt-table";
|
||||
/* Format <temp resistance> */
|
||||
tr-table = <(-25) 146676>,
|
||||
<(-15) 78875>,
|
||||
<(-5) 44424>,
|
||||
<(5) 26075>,
|
||||
<(15) 15881>,
|
||||
<(25) 10000>,
|
||||
<(35) 6488>,
|
||||
<(45) 4326>,
|
||||
<(55) 2956>,
|
||||
<(65) 2066>,
|
||||
<(75) 1474>,
|
||||
<(85) 1072>,
|
||||
<(95) 793>,
|
||||
<(105) 596>,
|
||||
<(115) 454>,
|
||||
<(125) 351>;
|
||||
};
|
||||
|
||||
test_adc_b57861s: b57861s@0 {
|
||||
compatible = "zephyr,ntc-thermistor";
|
||||
reg = <0x0 0x1000>;
|
||||
test_epcos_b57861s0103a039: epcos-b57861s0103a039 {
|
||||
compatible = "epcos,b57861s0103a039";
|
||||
io-channels = <&adc0 0>;
|
||||
zephyr,rt-table = <&thermistor_R25_10000_B_3974>;
|
||||
r25-ohm = <10000>;
|
||||
pullup-uv = <3300000>;
|
||||
pullup-ohm = <0>;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue