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

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


The following commit(s) were added to refs/heads/master by this push:
     new 105b97d799 boards/raspberrypi-pico: Add support to BMP280
105b97d799 is described below

commit 105b97d799664364b7f037fe6dfac01b0c3d4414
Author: Alan Carvalho de Assis <[email protected]>
AuthorDate: Tue May 28 19:17:03 2024 -0300

    boards/raspberrypi-pico: Add support to BMP280
    
    Signed-off-by: Alan C. Assis <[email protected]>
---
 .../arm/rp2040/boards/raspberrypi-pico/index.rst   |  12 +++
 boards/arm/rp2040/common/include/rp2040_bmp280.h   |  84 ++++++++++++++++
 boards/arm/rp2040/common/src/Make.defs             |   4 +
 boards/arm/rp2040/common/src/rp2040_bmp280.c       | 108 +++++++++++++++++++++
 .../arm/rp2040/common/src/rp2040_common_bringup.c  |  16 ++-
 .../raspberrypi-pico/configs/bmp280/defconfig      |  57 +++++++++++
 6 files changed, 280 insertions(+), 1 deletion(-)

diff --git 
a/Documentation/platforms/arm/rp2040/boards/raspberrypi-pico/index.rst 
b/Documentation/platforms/arm/rp2040/boards/raspberrypi-pico/index.rst
index f55a3261a4..e25db55f90 100644
--- a/Documentation/platforms/arm/rp2040/boards/raspberrypi-pico/index.rst
+++ b/Documentation/platforms/arm/rp2040/boards/raspberrypi-pico/index.rst
@@ -129,6 +129,18 @@ audiopack
 NuttShell configuration (console enabled in UART0, at 115200 bps) with
 support for NXPlayer audio player.
 
+bmp280
+------
+
+NuttShell configuration (console enabled in USB Port, at 115200 bps) with 
support for Bosch BMP280 sensor:
+
+.. code-block:: console
+
+   nsh> bmp280
+   Absolute pressure [hPa] = 1008.460022
+   Temperature [C] = 21.809999
+   nsh>
+
 composite
 ---------
 
diff --git a/boards/arm/rp2040/common/include/rp2040_bmp280.h 
b/boards/arm/rp2040/common/include/rp2040_bmp280.h
new file mode 100644
index 0000000000..cd5467e90e
--- /dev/null
+++ b/boards/arm/rp2040/common/include/rp2040_bmp280.h
@@ -0,0 +1,84 @@
+/****************************************************************************
+ * boards/arm/rp2040/common/include/rp2040_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_ARM_RP2040_COMMON_INCLUDE_RP2040_BMP280_H
+#define __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_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 busno);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BOARDS_ARM_RP2040_COMMON_INCLUDE_RP2040_BMP280_H */
diff --git a/boards/arm/rp2040/common/src/Make.defs 
b/boards/arm/rp2040/common/src/Make.defs
index f9f4ec49b4..89b476323e 100644
--- a/boards/arm/rp2040/common/src/Make.defs
+++ b/boards/arm/rp2040/common/src/Make.defs
@@ -79,6 +79,10 @@ ifeq ($(CONFIG_SENSORS_BMP180),y)
   CSRCS += rp2040_bmp180.c
 endif
 
+ifeq ($(CONFIG_SENSORS_BMP280),y)
+  CSRCS += rp2040_bmp280.c
+endif
+
 ifeq ($(CONFIG_SENSORS_INA219),y)
   CSRCS += rp2040_ina219.c
 endif
diff --git a/boards/arm/rp2040/common/src/rp2040_bmp280.c 
b/boards/arm/rp2040/common/src/rp2040_bmp280.c
new file mode 100644
index 0000000000..09f8f5508c
--- /dev/null
+++ b/boards/arm/rp2040/common/src/rp2040_bmp280.c
@@ -0,0 +1,108 @@
+/****************************************************************************
+ * boards/arm/rp2040/common/src/rp2040_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 "rp2040_i2c.h"
+#include "rp2040_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 busno)
+{
+  struct i2c_master_s *i2c;
+  int ret;
+  const int devno = 0;
+
+  sninfo("Initializing BMP280!\n");
+
+  /* Initialize BMP280 */
+
+  i2c = rp2040_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/arm/rp2040/common/src/rp2040_common_bringup.c 
b/boards/arm/rp2040/common/src/rp2040_common_bringup.c
index 7fdc2d89fc..d344772644 100644
--- a/boards/arm/rp2040/common/src/rp2040_common_bringup.c
+++ b/boards/arm/rp2040/common/src/rp2040_common_bringup.c
@@ -63,6 +63,11 @@
 #include "rp2040_bmp180.h"
 #endif
 
+#ifdef CONFIG_SENSORS_BMP280
+#include <nuttx/sensors/bmp280.h>
+#include "rp2040_bmp280.h"
+#endif
+
 #ifdef CONFIG_RP2040_PWM
 #include "rp2040_pwm.h"
 #include "rp2040_pwmdev.h"
@@ -460,7 +465,16 @@ int rp2040_common_bringup(void)
   if (ret < 0)
     {
       syslog(LOG_ERR, "Failed to initialize BMP180 driver: %d\n", ret);
-      return ret;
+    }
+#endif
+
+#ifdef CONFIG_SENSORS_BMP280
+  /* Try to register BMP280 device in I2C0 */
+
+  ret = board_bmp280_initialize(0);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "Failed to initialize BMP280 driver: %d\n", ret);
     }
 #endif
 
diff --git a/boards/arm/rp2040/raspberrypi-pico/configs/bmp280/defconfig 
b/boards/arm/rp2040/raspberrypi-pico/configs/bmp280/defconfig
new file mode 100644
index 0000000000..c0cbc66e58
--- /dev/null
+++ b/boards/arm/rp2040/raspberrypi-pico/configs/bmp280/defconfig
@@ -0,0 +1,57 @@
+#
+# 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_DEV_CONSOLE is not set
+# CONFIG_LIBC_LONG_LONG is not set
+# CONFIG_NSH_ARGCAT is not set
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+# CONFIG_NSH_DISABLE_DATE is not set
+# CONFIG_NSH_DISABLE_LOSMART is not set
+# CONFIG_RP2040_UART0 is not set
+CONFIG_ARCH="arm"
+CONFIG_ARCH_BOARD="raspberrypi-pico"
+CONFIG_ARCH_BOARD_RASPBERRYPI_PICO=y
+CONFIG_ARCH_CHIP="rp2040"
+CONFIG_ARCH_CHIP_RP2040=y
+CONFIG_ARCH_RAMVECTORS=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_BOARDCTL_RESET=y
+CONFIG_BOARD_LOOPSPERMSEC=10450
+CONFIG_BUILTIN=y
+CONFIG_CDCACM=y
+CONFIG_CDCACM_CONSOLE=y
+CONFIG_DEBUG_FULLOPT=y
+CONFIG_DEBUG_SYMBOLS=y
+CONFIG_DISABLE_POSIX_TIMERS=y
+CONFIG_EXAMPLES_BMP280=y
+CONFIG_EXAMPLES_HELLO=y
+CONFIG_FS_PROCFS=y
+CONFIG_FS_PROCFS_REGISTER=y
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_LIBC_FLOATINGPOINT=y
+CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_READLINE=y
+CONFIG_NSH_USBCONSOLE=y
+CONFIG_RAM_SIZE=270336
+CONFIG_RAM_START=0x20000000
+CONFIG_READLINE_CMD_HISTORY=y
+CONFIG_RP2040_I2C0=y
+CONFIG_RP2040_I2C=y
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_SENSORS=y
+CONFIG_SENSORS_BMP280=y
+CONFIG_START_DAY=9
+CONFIG_START_MONTH=2
+CONFIG_START_YEAR=2021
+CONFIG_SYSTEM_NSH=y
+CONFIG_TESTING_GETPRIME=y
+CONFIG_TESTING_OSTEST=y
+CONFIG_USBDEV=y
+CONFIG_USBDEV_BUSPOWERED=y

Reply via email to