boards/raspberrypi-pico: Add support to BMP280

Signed-off-by: Alan C. Assis <acassis@gmail.com>
This commit is contained in:
Alan Carvalho de Assis 2024-05-28 19:17:03 -03:00 committed by Xiang Xiao
parent f525bc2802
commit 105b97d799
6 changed files with 280 additions and 1 deletions

View File

@ -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
---------

View File

@ -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 */

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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