You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/06/16 00:01:25 UTC

[incubator-nuttx] 01/02: bmp280: support getting temperature via ioctl()

This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 6c333d7cbfaf834b8fb45468f64384db00c57e54
Author: Matias Nitsche <mn...@dc.uba.ar>
AuthorDate: Mon Jun 15 12:29:52 2020 -0300

    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 ff557cc..fb0ea49 100644
--- a/drivers/sensors/bmp280.c
+++ b/drivers/sensors/bmp280.c
@@ -549,6 +549,33 @@ static uint32_t bmp280_getpressure(FAR struct bmp280_dev_s *priv)
 }
 
 /****************************************************************************
+ * 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
  *
  * Description:
@@ -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 44da043..7c74987 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 */