You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2022/06/29 21:32:11 UTC

[incubator-nuttx] 03/03: esp32s2-saola-1: Add support for BMP180 pressure sensor

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

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

commit 43685aefc8fda38b892e5467ea8ddde295ffac44
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Wed Jun 15 16:17:10 2022 -0300

    esp32s2-saola-1: Add support for BMP180 pressure sensor
    
    Signed-off-by: Gustavo Henrique Nihei <gu...@espressif.com>
---
 .../xtensa/esp32s2/esp32s2-saola-1/src/Make.defs   |  4 ++
 .../esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h  | 19 ++++++
 .../esp32s2/esp32s2-saola-1/src/esp32s2_bmp180.c   | 75 ++++++++++++++++++++++
 .../esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c  | 15 +++++
 4 files changed, 113 insertions(+)

diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/Make.defs b/boards/xtensa/esp32s2/esp32s2-saola-1/src/Make.defs
index 43ce38abba..cb7977835d 100644
--- a/boards/xtensa/esp32s2/esp32s2-saola-1/src/Make.defs
+++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/Make.defs
@@ -45,6 +45,10 @@ ifeq ($(CONFIG_I2C_DRIVER),y)
 CSRCS += esp32s2_board_i2c.c
 endif
 
+ifeq ($(CONFIG_SENSORS_BMP180),y)
+CSRCS += esp32s2_bmp180.c
+endif
+
 SCRIPTIN = $(SCRIPTDIR)$(DELIM)esp32s2.template.ld
 SCRIPTOUT = $(SCRIPTDIR)$(DELIM)esp32s2_out.ld
 
diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h
index 89f5263a28..b2a1a455b9 100644
--- a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h
+++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h
@@ -133,5 +133,24 @@ int board_oneshot_init(int timer, uint16_t resolution);
 int board_i2c_init(void);
 #endif
 
+/****************************************************************************
+ * Name: board_bmp180_initialize
+ *
+ * Description:
+ *   Initialize and register the BMP180 Pressure Sensor driver.
+ *
+ * Input Parameters:
+ *   devno - The device number, used to build the device path as /dev/pressN
+ *   busno - The I2C bus number
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_SENSORS_BMP180
+int board_bmp180_initialize(int devno, int busno);
+#endif
+
 #endif /* __ASSEMBLY__ */
 #endif /* __BOARDS_XTENSA_ESP32S2_ESP32S2_SAOLA_1_SRC_ESP32S2_SAOLA_1_H */
diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bmp180.c b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bmp180.c
new file mode 100644
index 0000000000..08eed07862
--- /dev/null
+++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bmp180.c
@@ -0,0 +1,75 @@
+/****************************************************************************
+ * boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bmp180.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <debug.h>
+#include <stdio.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/sensors/bmp180.h>
+
+#include "esp32s2_i2c.h"
+#include "esp32s2-saola-1.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_bmp180_initialize
+ *
+ * Description:
+ *   Initialize and register the BMP180 Pressure Sensor driver.
+ *
+ * Input Parameters:
+ *   devno - The device number, used to build the device path as /dev/pressN
+ *   busno - The I2C bus number
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_bmp180_initialize(int devno, int busno)
+{
+  struct i2c_master_s *i2c;
+  char devpath[12];
+
+  /* Initialize BMP180 */
+
+  i2c = esp32s2_i2cbus_initialize(busno);
+  if (i2c == NULL)
+    {
+      return -ENODEV;
+    }
+
+  /* Register the barometer sensor */
+
+  (void)snprintf(devpath, sizeof(devpath), "/dev/press%d", devno);
+
+  return bmp180_register(devpath, i2c);
+}
+
diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c
index 7835f1bf40..d8607faaa9 100644
--- a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c
+++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c
@@ -50,6 +50,10 @@
 #  include "esp32s2_tim_lowerhalf.h"
 #endif
 
+#ifdef CONFIG_ESP32S2_I2C
+#  include "esp32s2_i2c.h"
+#endif
+
 #ifdef CONFIG_ESP32S2_RT_TIMER
 #  include "esp32s2_rt_timer.h"
 #endif
@@ -202,6 +206,17 @@ int esp32s2_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_SENSORS_BMP180
+  /* Try to register BMP180 device in I2C0 */
+
+  ret = board_bmp180_initialize(0, ESP32S2_I2C0);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR,
+             "Failed to initialize BMP180 driver for I2C0: %d\n", ret);
+    }
+#endif
+
   /* If we got here then perhaps not all initialization was successful, but
    * at least enough succeeded to bring-up NSH with perhaps reduced
    * capabilities.