From 6c333d7cbfaf834b8fb45468f64384db00c57e54 Mon Sep 17 00:00:00 2001 From: Matias Nitsche Date: Mon, 15 Jun 2020 12:29:52 -0300 Subject: [PATCH] bmp280: support getting temperature via ioctl() --- drivers/sensors/bmp280.c | 30 ++++++++++++++++++++++++++++++ include/nuttx/sensors/bmp280.h | 7 +++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/sensors/bmp280.c b/drivers/sensors/bmp280.c index ff557ccc69..fb0ea491a1 100644 --- a/drivers/sensors/bmp280.c +++ b/drivers/sensors/bmp280.c @@ -548,6 +548,33 @@ static uint32_t bmp280_getpressure(FAR struct bmp280_dev_s *priv) return press; } +/**************************************************************************** + * Name: bmp280_gettemp + * + * Description: + * Read temperature only + * + ****************************************************************************/ + +static uint32_t bmp280_gettemp(FAR struct bmp280_dev_s *priv) +{ + uint8_t buf[3]; + int32_t temp; + + bmp280_getregs(priv, BMP280_TEMP_MSB, buf, 3); + + temp = COMBINE(buf); + + sninfo("temp = %d\n", temp); + + if (priv->compensated == ENABLE_COMPENSATED) + { + temp = bmp280_compensate_temp(priv, temp); + } + + return temp; +} + /**************************************************************************** * Name: bmp280_open * @@ -641,6 +668,9 @@ static int bmp280_ioctl(FAR struct file *filep, int cmd, unsigned long arg) ret = bmp280_set_standby(priv, arg); break; + case SNIOC_GET_TEMP: + *(uint32_t*)arg = bmp280_gettemp(priv); + default: snerr("Unrecognized cmd: %d\n", cmd); ret = - ENOTTY; diff --git a/include/nuttx/sensors/bmp280.h b/include/nuttx/sensors/bmp280.h index 44da0432b9..7c74987e02 100644 --- a/include/nuttx/sensors/bmp280.h +++ b/include/nuttx/sensors/bmp280.h @@ -112,6 +112,13 @@ extern "C" #define SNIOC_SETSTB _SNIOC(0x0003) +/* Get temperature value + * + * Arg: Pointer to uint32_t (raw value) + */ + +#define SNIOC_GET_TEMP _SNIOC(0x0004) + struct bmp280_press_adj_s { uint16_t dig_p1; /* calibration P1 data */