-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: sensor: temperature: Add i.MX RT die temperature sensor #83880
base: main
Are you sure you want to change the base?
Changes from all commits
27f1397
14b52e0
753dd74
b891f14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
zephyr_library() | ||
|
||
zephyr_library_sources(nxp_tmpsns.c) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# NXP i.MX RT temperature sensor configuration options | ||
|
||
# Copyright (c) 2025 Polytech A/S | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config NXP_TMPSNS | ||
bool "NXP TMPSNS sensor" | ||
depends on SENSOR | ||
depends on DT_HAS_NXP_TMPSNS_ENABLED | ||
depends on SOC_SERIES_IMXRT11XX || SOC_SERIES_IMXRT118X | ||
default y | ||
help | ||
Enable temperature measurement for NXP TMPSNS sensor | ||
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,68 @@ | ||||||
/* | ||||||
* Copyright (c) 2025 Polytech A/S | ||||||
* | ||||||
* SPDX-License-Identifier: Apache-2.0 | ||||||
*/ | ||||||
|
||||||
#define DT_DRV_COMPAT nxp_tmpsns | ||||||
|
||||||
#include <fsl_tempsensor.h> | ||||||
#include <zephyr/drivers/sensor.h> | ||||||
|
||||||
struct nxp_tmpsns_data { | ||||||
float die_temp; | ||||||
}; | ||||||
|
||||||
static int nxp_tmpsns_channel_get(const struct device *dev, enum sensor_channel chan, | ||||||
struct sensor_value *val) | ||||||
{ | ||||||
const struct nxp_tmpsns_data *data = dev->data; | ||||||
|
||||||
switch (chan) { | ||||||
case SENSOR_CHAN_ALL: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete this line. |
||||||
case SENSOR_CHAN_DIE_TEMP: | ||||||
return sensor_value_from_float(val, data->die_temp); | ||||||
default: | ||||||
return -ENOTSUP; | ||||||
} | ||||||
} | ||||||
|
||||||
static int nxp_tmpsns_channel_fetch(const struct device *dev, enum sensor_channel chan) | ||||||
{ | ||||||
struct nxp_tmpsns_data *data = dev->data; | ||||||
|
||||||
switch (chan) { | ||||||
case SENSOR_CHAN_ALL: | ||||||
case SENSOR_CHAN_DIE_TEMP: | ||||||
data->die_temp = TMPSNS_GetCurrentTemperature(TMPSNS); | ||||||
return 0; | ||||||
default: | ||||||
return -ENOTSUP; | ||||||
} | ||||||
} | ||||||
|
||||||
static const struct sensor_driver_api tmpsns_driver_api = { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.channel_get = nxp_tmpsns_channel_get, | ||||||
.sample_fetch = nxp_tmpsns_channel_fetch, | ||||||
}; | ||||||
|
||||||
static int nxp_tmpsns_init(const struct device *dev) | ||||||
{ | ||||||
tmpsns_config_t config; | ||||||
|
||||||
TMPSNS_GetDefaultConfig(&config); | ||||||
config.measureMode = kTEMPSENSOR_ContinuousMode; | ||||||
config.frequency = 0x03U; | ||||||
TMPSNS_Init(TMPSNS, &config); | ||||||
TMPSNS_StartMeasure(TMPSNS); | ||||||
|
||||||
return 0; | ||||||
} | ||||||
|
||||||
#define NXP_TMPSNS_DEFINE(inst) \ | ||||||
struct nxp_tmpsns_data nxp_tmpsns_data_##inst; \ | ||||||
SENSOR_DEVICE_DT_INST_DEFINE(inst, nxp_tmpsns_init, NULL, &nxp_tmpsns_data_##inst, NULL, \ | ||||||
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, \ | ||||||
&tmpsns_driver_api); | ||||||
|
||||||
DT_INST_FOREACH_STATUS_OKAY(NXP_TMPSNS_DEFINE) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,13 @@ | |
}; | ||
}; | ||
}; | ||
|
||
soc { | ||
temp: temp { | ||
compatible = "nxp,tmpsns"; | ||
status = "disabled"; | ||
}; | ||
}; | ||
}; | ||
|
||
&peripheral { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) 2024 Polytech A/S | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: NXP TMPSNS | ||
|
||
compatible: "nxp,tmpsns" | ||
|
||
include: base.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
temp_sensor: &temp { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File needs a license/copyright header |
||
status = "okay"; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.