[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 07/17] hw/misc/tmp421: Extract get_temp_mC() helper
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 07/17] hw/misc/tmp421: Extract get_temp_mC() helper |
Date: |
Tue, 21 Apr 2020 14:16:16 +0200 |
Since we are going to reuse this code, extract it first.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
hw/misc/tmp421.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
index 04c3b3ca6e..8003356307 100644
--- a/hw/misc/tmp421.c
+++ b/hw/misc/tmp421.c
@@ -112,12 +112,19 @@ typedef struct TMP421Class {
static const int32_t mins[2] = { -40000, -55000 };
static const int32_t maxs[2] = { 127000, 150000 };
+static int64_t get_temp_mC(TMP421State *s, unsigned int id)
+{
+ bool ext_range = (s->config[0] & TMP421_CONFIG_RANGE);
+ int offset = ext_range * 64 * 256;
+
+ assert(id < SENSORS_COUNT);
+
+ return ((s->temperature[id] - offset) * 1000 + 128) / 256;
+}
+
static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
- TMP421State *s = TMP421(obj);
- bool ext_range = (s->config[0] & TMP421_CONFIG_RANGE);
- int offset = ext_range * 64 * 256;
int64_t value;
int tempid;
@@ -131,7 +138,7 @@ static void tmp421_get_temperature(Object *obj, Visitor *v,
const char *name,
return;
}
- value = ((s->temperature[tempid] - offset) * 1000 + 128) / 256;
+ value = get_temp_mC(TMP421(obj), tempid);
visit_type_int(v, name, &value, errp);
}
--
2.21.1
- Re: [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command, (continued)
- [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 01/17] hw/misc: Introduce the temperature sensor interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 06/17] hw/misc/tmp421: Add definition for SENSORS_COUNT, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 08/17] hw/misc/tmp421: Extract set_temp_mC() helper, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 04/17] hw/misc/tmp105: Extract get_temp_mC() and set_temp_mC() helpers, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 05/17] hw/misc/tmp105: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 09/17] hw/misc/tmp421: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 10/17] hw/misc/bcm2835_thermal: Hold the temperature in the device state, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 07/17] hw/misc/tmp421: Extract get_temp_mC() helper,
Philippe Mathieu-Daudé <=
- [RFC PATCH 12/17] hw/misc/bcm2835_property: Hold the temperature in the device state, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 16/17] hw/misc/imx6ul_ccm: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 14/17] hw/display/ads7846: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 17/17] tests/qtest/tmp105-test: Trivial test for TempSensorClass, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 15/17] hw/ide/qdev: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 13/17] hw/misc/bcm2835_property: Implement the 'temperature-sensor' interface, Philippe Mathieu-Daudé, 2020/04/21