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/26 08:36:13 UTC

[incubator-nuttx] branch master updated: Added configuration files for usinf BMP280 with ESP32-DevkitC

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


The following commit(s) were added to refs/heads/master by this push:
     new c6c0baa233 Added configuration files for usinf BMP280 with ESP32-DevkitC
c6c0baa233 is described below

commit c6c0baa233594dd8e5319a82a6708121e8e94349
Author: Andrey <an...@gmail.com>
AuthorDate: Sat Jun 25 22:18:03 2022 +0200

    Added configuration files for usinf BMP280 with ESP32-DevkitC
---
 boards/xtensa/esp32/common/include/esp32_bmp280.h  |  84 ++++++++++++++++
 boards/xtensa/esp32/common/src/Make.defs           |   4 +
 boards/xtensa/esp32/common/src/esp32_bmp280.c      | 109 +++++++++++++++++++++
 .../esp32/esp32-devkitc/configs/bmp280/defconfig   |  66 +++++++++++++
 .../xtensa/esp32/esp32-devkitc/src/esp32_bringup.c |  15 +++
 5 files changed, 278 insertions(+)

diff --git a/boards/xtensa/esp32/common/include/esp32_bmp280.h b/boards/xtensa/esp32/common/include/esp32_bmp280.h
new file mode 100644
index 0000000000..229c6d5f88
--- /dev/null
+++ b/boards/xtensa/esp32/common/include/esp32_bmp280.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/include/esp32_bmp280.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BMP280_H
+#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BMP280_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Type Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_bmp280_initialize
+ *
+ * Description:
+ *   Initialize and register the BMP280 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_bmp280_initialize(int devno, int busno);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_ESP32_BMP280_H */
diff --git a/boards/xtensa/esp32/common/src/Make.defs b/boards/xtensa/esp32/common/src/Make.defs
index 28f6e4f355..e46c11e667 100644
--- a/boards/xtensa/esp32/common/src/Make.defs
+++ b/boards/xtensa/esp32/common/src/Make.defs
@@ -56,6 +56,10 @@ ifeq ($(CONFIG_SENSORS_BMP180),y)
   CSRCS += esp32_bmp180.c
 endif
 
+ifeq ($(CONFIG_SENSORS_BMP280),y)
+CSRCS += esp32_bmp280.c
+endif
+
 ifeq ($(CONFIG_SENSORS_SHT3X),y)
   CSRCS += esp32_sht3x.c
 endif
diff --git a/boards/xtensa/esp32/common/src/esp32_bmp280.c b/boards/xtensa/esp32/common/src/esp32_bmp280.c
new file mode 100644
index 0000000000..37638bd704
--- /dev/null
+++ b/boards/xtensa/esp32/common/src/esp32_bmp280.c
@@ -0,0 +1,109 @@
+/****************************************************************************
+ * boards/xtensa/esp32/common/src/esp32_bmp280.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 <stdio.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/sensors/bmp280.h>
+#include <nuttx/i2c/i2c_master.h>
+
+#include "esp32_board_i2c.h"
+#include "esp32_i2c.h"
+#include "esp32_bmp280.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_bmp280_initialize
+ *
+ * Description:
+ *   Initialize and register the BMP280 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_bmp280_initialize(int devno, int busno)
+{
+  struct i2c_master_s *i2c;
+  int ret;
+
+  sninfo("Initializing BMP280!\n");
+
+  /* Initialize BMP280 */
+
+  i2c = esp32_i2cbus_initialize(busno);
+
+  if (i2c)
+    {
+      /* Then try to register the barometer sensor in I2C0 */
+
+      ret = bmp280_register(devno, i2c);
+      if (ret < 0)
+        {
+          snerr("ERROR: Error registering BMP280 in I2C%d\n", busno);
+        }
+    }
+  else
+    {
+      ret = -ENODEV;
+    }
+
+  return ret;
+}
+
diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/bmp280/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/bmp280/defconfig
new file mode 100644
index 0000000000..ef3962dcc5
--- /dev/null
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/bmp280/defconfig
@@ -0,0 +1,66 @@
+#
+# This file is autogenerated: PLEASE DO NOT EDIT IT.
+#
+# You can use "make menuconfig" to make any modifications to the installed .config file.
+# You can then do "make savedefconfig" to generate a new defconfig file that includes your
+# modifications.
+#
+# CONFIG_ARCH_LEDS is not set
+# CONFIG_NSH_ARGCAT is not set
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+# CONFIG_NSH_CMDPARMS is not set
+CONFIG_ARCH="xtensa"
+CONFIG_ARCH_BOARD="esp32-devkitc"
+CONFIG_ARCH_BOARD_COMMON=y
+CONFIG_ARCH_BOARD_ESP32_DEVKITC=y
+CONFIG_ARCH_BUTTONS=y
+CONFIG_ARCH_CHIP="esp32"
+CONFIG_ARCH_CHIP_ESP32=y
+CONFIG_ARCH_CHIP_ESP32WROVER=y
+CONFIG_ARCH_IRQBUTTONS=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_XTENSA=y
+CONFIG_BOARD_LOOPSPERMSEC=16717
+CONFIG_BUILTIN=y
+CONFIG_DEBUG_ERROR=y
+CONFIG_DEBUG_FEATURES=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_SENSORS=y
+CONFIG_DEBUG_SENSORS_ERROR=y
+CONFIG_DEBUG_SENSORS_INFO=y
+CONFIG_DEBUG_SENSORS_WARN=y
+CONFIG_DEBUG_WARN=y
+CONFIG_ESP32_GPIO_IRQ=y
+CONFIG_ESP32_I2C0=y
+CONFIG_ESP32_UART0=y
+CONFIG_FS_PROCFS=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_IDLETHREAD_STACKSIZE=3072
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=y
+CONFIG_LIBC_FLOATINGPOINT=y
+CONFIG_MM_REGIONS=3
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+CONFIG_NSH_LINELEN=64
+CONFIG_NSH_READLINE=y
+CONFIG_PREALLOC_TIMERS=4
+CONFIG_RAMLOG=y
+CONFIG_RAMLOG_SYSLOG=y
+CONFIG_RAM_SIZE=114688
+CONFIG_RAM_START=0x20000000
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_SENSORS=y
+CONFIG_SENSORS_BMP280=y
+CONFIG_START_DAY=6
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2011
+CONFIG_SYSLOG_DEFAULT=y
+CONFIG_SYSLOG_MAX_CHANNELS=2
+CONFIG_SYSTEM_I2CTOOL=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_TESTING_SENSORTEST=y
+CONFIG_UART0_SERIAL_CONSOLE=y
diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c
index e781007238..058cee002d 100644
--- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c
+++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32_bringup.c
@@ -95,6 +95,10 @@
 #  include "esp32_bmp180.h"
 #endif
 
+#ifdef CONFIG_SENSORS_BMP280
+#  include "esp32_bmp280.h"
+#endif
+
 #ifdef CONFIG_SENSORS_SHT3X
 #  include "esp32_sht3x.h"
 #endif
@@ -438,6 +442,17 @@ int esp32_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_SENSORS_BMP280
+  /* Try to register BMP280 device in I2C0 */
+
+  ret = board_bmp280_initialize(0, 0);
+
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "Failed to initialize BMP280 driver: %d\n", ret);
+    }
+#endif
+
 #ifdef CONFIG_SENSORS_SHT3X
   /* Try to register SHT3x device in I2C0 */