[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 14/17] hw/display/ads7846: Implement the 'temperature-sensor'
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 14/17] hw/display/ads7846: Implement the 'temperature-sensor' qdev interface |
Date: |
Tue, 21 Apr 2020 14:16:23 +0200 |
The 4-wire ADS7846 Touch Screen Controller is able to report a
pair of temperatures. Let it implement the 'temperature-sensor'
interface.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
hw/display/ads7846.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/hw/display/ads7846.c b/hw/display/ads7846.c
index 9228b40b1a..e37e99f5ec 100644
--- a/hw/display/ads7846.c
+++ b/hw/display/ads7846.c
@@ -16,6 +16,7 @@
#include "migration/vmstate.h"
#include "qemu/module.h"
#include "ui/console.h"
+#include "hw/misc/temp-sensor.h"
typedef struct {
SSISlave ssidev;
@@ -53,6 +54,12 @@ typedef struct {
#define ADS_Z1POS(x, y) 600
#define ADS_Z2POS(x, y) (600 + 6000 / ADS_XPOS(x, y))
+/* TI Datasheet SBAS125H "TEMP DIODE VOLTAGE vs TEMPERATURE (2.7V SUPPLY)" */
+#define ADS_TEMP0_OFS_MILLIV 666.f
+#define ADS_TEMP1_OFS_MILLIV 761.f
+#define ADS_TEMP0_COEFF 2.08f
+#define ADS_TEMP1_COEFF 1.60f
+
static void ads7846_int_update(ADS7846State *s)
{
if (s->interrupt)
@@ -157,12 +164,39 @@ static void ads7846_realize(SSISlave *d, Error **errp)
vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_ads7846, s);
}
+static float ads7846_get_temp(TempSensor *obj, unsigned sensor_id)
+{
+ ADS7846State *s = (ADS7846State *)obj;
+
+ if (sensor_id) {
+ return (ADS_TEMP1_OFS_MILLIV - s->input[7]) / ADS_TEMP1_COEFF;
+ } else {
+ return (ADS_TEMP0_OFS_MILLIV - s->input[0]) / ADS_TEMP0_COEFF;
+ }
+}
+
+static void ads7846_set_temp(TempSensor *obj, unsigned sensor_id,
+ float temp_C, Error **errp)
+{
+ ADS7846State *s = (ADS7846State *)obj;
+
+ if (sensor_id) {
+ s->input[7] = ADS_TEMP1_OFS_MILLIV - ADS_TEMP1_COEFF * temp_C;
+ } else {
+ s->input[0] = ADS_TEMP0_OFS_MILLIV - ADS_TEMP0_COEFF * temp_C;
+ }
+}
+
static void ads7846_class_init(ObjectClass *klass, void *data)
{
SSISlaveClass *k = SSI_SLAVE_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
k->realize = ads7846_realize;
k->transfer = ads7846_transfer;
+ tc->sensor_count = 2;
+ tc->set_temperature = ads7846_set_temp;
+ tc->get_temperature = ads7846_get_temp;
}
static const TypeInfo ads7846_info = {
@@ -170,6 +204,10 @@ static const TypeInfo ads7846_info = {
.parent = TYPE_SSI_SLAVE,
.instance_size = sizeof(ADS7846State),
.class_init = ads7846_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static void ads7846_register_types(void)
--
2.21.1
- [RFC PATCH 06/17] hw/misc/tmp421: Add definition for SENSORS_COUNT, (continued)
- [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é, 2020/04/21
- [RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 12/17] hw/misc/bcm2835_property: Hold the temperature in the device state, 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 14/17] hw/display/ads7846: Implement the 'temperature-sensor' qdev interface,
Philippe Mathieu-Daudé <=
- [RFC PATCH 17/17] tests/qtest/tmp105-test: Trivial test for TempSensorClass, 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 13/17] hw/misc/bcm2835_property: Implement the 'temperature-sensor' interface, Philippe Mathieu-Daudé, 2020/04/21