Commit e8d00908 authored by Bogdan Davidoaia's avatar Bogdan Davidoaia Committed by Inaky Perez-Gonzalez
Browse files

sensor: tmp007: fix negative sample values bug

Fix bug that caused negative temperature values to be computed incorrectly.
The sign bit needs to be perserved, when extracting the data sample from
the TMP007_REG_TOBJ register.

Jira: ZEP-499
Change-Id: Idbebd48b3164d7d4883352ef7128ef73be70e1b2
Signed-off-by: default avatarBogdan Davidoaia <bogdan.m.davidoaia@intel.com>
parent 65cc01ac
Loading
Loading
Loading
Loading
+3 −2
Changes for drivers/sensor/sensor_tmp007.c: 3 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include <i2c.h>
#include <gpio.h>
#include <misc/byteorder.h>
#include <misc/util.h>
#include <nanokernel.h>
#include <sensor.h>
#include <misc/__assert.h>
@@ -87,7 +88,7 @@ static int tmp007_sample_fetch(struct device *dev, enum sensor_channel chan)
		return -EIO;
	}

	drv_data->sample = val >> 2;
	drv_data->sample = arithmetic_shift_right((int16_t)val, 2);

	return 0;
}
@@ -97,7 +98,7 @@ static int tmp007_channel_get(struct device *dev,
			       struct sensor_value *val)
{
	struct tmp007_data *drv_data = dev->driver_data;
	int64_t uval;
	int32_t uval;

	if (chan != SENSOR_CHAN_TEMP) {
		return -ENOTSUP;
+1 −1
Changes for drivers/sensor/sensor_tmp007.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@

struct tmp007_data {
	struct device *i2c;
	uint16_t sample;
	int16_t sample;

#ifdef CONFIG_TMP007_TRIGGER
	struct device *gpio;