diff --git a/pkg/driver_bme680/Makefile b/pkg/driver_bme680/Makefile new file mode 100644 index 0000000000..5c7d959a9b --- /dev/null +++ b/pkg/driver_bme680/Makefile @@ -0,0 +1,12 @@ +PKG_NAME=driver_bme680 +PKG_URL=https://github.com/BoschSensortec/BME680_driver +PKG_VERSION=63bb5336db4659519860832be2738c685133aa33 +PKG_LICENSE=BSD-3-Clause + +include $(RIOTBASE)/pkg/pkg.mk + +.PHONY: all + +all: + @cp Makefile.$(PKG_NAME) $(PKG_BUILDDIR)/Makefile + "$(MAKE)" -C $(PKG_BUILDDIR) diff --git a/pkg/driver_bme680/Makefile.dep b/pkg/driver_bme680/Makefile.dep new file mode 100644 index 0000000000..0567ee2f56 --- /dev/null +++ b/pkg/driver_bme680/Makefile.dep @@ -0,0 +1 @@ +USEMODULE += driver_bme680_contrib diff --git a/pkg/driver_bme680/Makefile.driver_bme680 b/pkg/driver_bme680/Makefile.driver_bme680 new file mode 100644 index 0000000000..7f0b7555c4 --- /dev/null +++ b/pkg/driver_bme680/Makefile.driver_bme680 @@ -0,0 +1,7 @@ +MODULE = driver_bme680 + +ifneq (,$(filter bme680_fp,$(USEMODULE))) + CFLAGS += -DBME680_FLOAT_POINT_COMPENSATION +endif + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/driver_bme680/Makefile.include b/pkg/driver_bme680/Makefile.include new file mode 100644 index 0000000000..91522faa40 --- /dev/null +++ b/pkg/driver_bme680/Makefile.include @@ -0,0 +1,4 @@ +INCLUDES += -I$(PKGDIRBASE)/driver_bme680 +INCLUDES += -I$(RIOTPKG)/driver_bme680/include + +DIRS += $(RIOTPKG)/driver_bme680/contrib diff --git a/pkg/driver_bme680/README.md b/pkg/driver_bme680/README.md new file mode 100644 index 0000000000..f7bfb11ede --- /dev/null +++ b/pkg/driver_bme680/README.md @@ -0,0 +1,41 @@ +# BME680 vendor driver + +## Introduction + +The [BME680_driver](https://github.com/BoschSensortec/BME680_driver) is an +I2C/SPI API for BME680 sensor. + +The library is written and maintained by Bosch Sensortec. It is platform +independent, as long as the right drivers are available for the given MCU. + +In addition, this driver can use floating point if available on your MCU. +By default, this package does not use it. + +## Usage + +Refer to the code documentation at +[GitHub](https://github.com/BoschSensortec/BME680_driver) for more information +on the API. + +## RIOT-OS interface + +BME680 sensors are connected either via I2C or SPI. Which interface is used by +which BME680 sensor is defined in the `bme680_params` parameters. The +respective implementation is enabled by the modules `bme680_i2c` and +`bme680_spi`. Both I2C and SPI can be used in one application. +``` +USEMODULE='bme680_spi bme680_i2c' make BOARD=... -C tests/driver_bme680 +``` + +In order to use floating point, you can enable module `bme680_fp` variable: +``` +USEMODULE='bme680_fp bme680_i2c' make BOARD=... -C tests/driver_bme680 +``` + +The following callbacks add support for the included drivers via I2C and SPI +peripherals: + +* `bme680_i2c_read_hal` +* `bme680_i2c_write_hal` +* `bme680_spi_read_hal` +* `bme680_spi_write_hal` diff --git a/pkg/driver_bme680/contrib/Makefile b/pkg/driver_bme680/contrib/Makefile new file mode 100644 index 0000000000..5ca9ec4958 --- /dev/null +++ b/pkg/driver_bme680/contrib/Makefile @@ -0,0 +1,3 @@ +MODULE = driver_bme680_contrib + +include $(RIOTBASE)/Makefile.base diff --git a/pkg/driver_bme680/contrib/bme680_hal.c b/pkg/driver_bme680/contrib/bme680_hal.c new file mode 100644 index 0000000000..01af5a5d2a --- /dev/null +++ b/pkg/driver_bme680/contrib/bme680_hal.c @@ -0,0 +1,116 @@ +/* + * Copyright (C) 2019 Mesotic SAS + * 2020 Gunar Schorcht + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup pkg_driver_bme680 + * @ingroup drivers_bme680 + * @{ + * + * @file + * @brief Abstraction layer for RIOT adaption + * + * @author Dylan Laduranty + * @author Gunar Schorcht + */ + +#include +#include + +#include "bme680.h" +#include "bme680_hal.h" + +#ifdef MODULE_PERIPH_I2C +#include "periph/i2c.h" +#endif +#ifdef MODULE_PERIPH_SPI +#include "periph/spi.h" +#endif + +#include "xtimer.h" + +#ifndef BME680_SPI_SPEED +#define BME680_SPI_SPEED (SPI_CLK_1MHZ) +#endif /* BME680_SPI_SPEED */ + +#ifndef BME680_SPI_MODE +#define BME680_SPI_MODE (SPI_MODE_0) +#endif /* BME680_SPI_MODE */ + +void bme680_ms_sleep(uint32_t msleep) +{ + xtimer_usleep(msleep * US_PER_MS); +} + +#ifdef MODULE_PERIPH_I2C +int8_t bme680_i2c_read_hal(uint8_t dev_id, uint8_t reg_addr, + uint8_t *data, uint16_t len) +{ + assert(dev_id < bme680_devs_numof); + + bme680_intf_i2c_t* intf = &(bme680_devs[dev_id]->intf.i2c); + uint8_t ret; + + i2c_acquire(intf->dev); + ret = i2c_read_regs(intf->dev, intf->addr, reg_addr, data, len, 0); + i2c_release(intf->dev); + return ret; +} + +int8_t bme680_i2c_write_hal(uint8_t dev_id, uint8_t reg_addr, + uint8_t *data, uint16_t len) +{ + assert(dev_id < bme680_devs_numof); + + bme680_intf_i2c_t* intf = &(bme680_devs[dev_id]->intf.i2c); + uint8_t ret; + + i2c_acquire(intf->dev); + ret = i2c_write_regs(intf->dev, intf->addr, reg_addr, data, len, 0); + i2c_release(intf->dev); + return ret; +} +#endif /* MODULE_PERIPH_I2C */ + +#ifdef MODULE_PERIPH_SPI +int8_t bme680_spi_read_hal(uint8_t dev_id, uint8_t reg_addr, + uint8_t *data, uint16_t len) +{ + assert(dev_id < bme680_devs_numof); + + bme680_intf_spi_t* intf = &(bme680_devs[dev_id]->intf.spi); + unsigned int cpsr = irq_disable(); + + gpio_clear(intf->nss_pin); + spi_acquire(intf->dev, SPI_CS_UNDEF, BME680_SPI_MODE, BME680_SPI_SPEED); + spi_transfer_regs(intf->dev, SPI_CS_UNDEF, reg_addr, NULL, data, len); + gpio_set(intf->nss_pin); + + irq_restore(cpsr); + spi_release(intf->dev); + return 0; +} + +int8_t bme680_spi_write_hal(uint8_t dev_id, uint8_t reg_addr, + uint8_t *data, uint16_t len) +{ + assert(dev_id < bme680_devs_numof); + + bme680_intf_spi_t* intf = &(bme680_devs[dev_id]->intf.spi); + unsigned int cpsr = irq_disable(); + + gpio_clear(intf->nss_pin); + spi_acquire(intf->dev, SPI_CS_UNDEF, BME680_SPI_MODE, BME680_SPI_SPEED); + spi_transfer_regs(intf->dev, SPI_CS_UNDEF, reg_addr, data, NULL, len); + gpio_set(intf->nss_pin); + + irq_restore(cpsr); + spi_release(intf->dev); + return 0; +} +#endif /* MODULE_PERIPH_SPI */ diff --git a/pkg/driver_bme680/doc.txt b/pkg/driver_bme680/doc.txt new file mode 100644 index 0000000000..46a287fc4e --- /dev/null +++ b/pkg/driver_bme680/doc.txt @@ -0,0 +1,6 @@ +/** + * @defgroup pkg_driver_bme680 Driver package for I2C/SPI BME680 sensor + * @ingroup pkg + * @brief Provides the Bosch Sensortec's BME680 gas sensor API + * @see https://github.com/BoschSensortec/BME680_driver + */ diff --git a/pkg/driver_bme680/include/bme680_hal.h b/pkg/driver_bme680/include/bme680_hal.h new file mode 100644 index 0000000000..fbd148572e --- /dev/null +++ b/pkg/driver_bme680/include/bme680_hal.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2018 Mesotic SAS + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup pkg_driver_bme680 + * @{ + * + * @file + * @brief Abstraction layer for RIOT adaption + * + * @author Dylan Laduranty + */ + +#ifndef BME680_HAL_H +#define BME680_HAL_H + +#ifdef __cplusplus +extern "C" { +#endif + +void bme680_ms_sleep(uint32_t msleep); + +#ifdef MODULE_PERIPH_I2C + +int8_t bme680_i2c_read_hal(uint8_t dev_id, uint8_t reg_addr, + uint8_t *data, uint16_t len); +int8_t bme680_i2c_write_hal(uint8_t dev_id, uint8_t reg_addr, + uint8_t *data, uint16_t len); +#endif + +#ifdef MODULE_PERIPH_SPI + +int8_t bme680_spi_read_hal(uint8_t dev_id, uint8_t reg_addr, + uint8_t *data, uint16_t len); +int8_t bme680_spi_write_hal(uint8_t dev_id, uint8_t reg_addr, + uint8_t *data, uint16_t len); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* BME680_HAL_H */ +/** @} */ diff --git a/pkg/driver_bme680/patches/0001-reword-files-and-functions.patch b/pkg/driver_bme680/patches/0001-reword-files-and-functions.patch new file mode 100644 index 0000000000..efc1e06255 --- /dev/null +++ b/pkg/driver_bme680/patches/0001-reword-files-and-functions.patch @@ -0,0 +1,56 @@ +From 60f0355beaeea25bf3cee187b8ce8244cc1bbf6a Mon Sep 17 00:00:00 2001 +From: dylad +Date: Fri, 8 Nov 2019 20:05:46 +0100 +Subject: [PATCH] reword files and functions + +--- + bme680.c => bme680_internal.c | 4 ++-- + bme680.h => bme680_internal.h | 2 +- + 2 files changed, 3 insertions(+), 3 deletions(-) + rename bme680.c => bme680_internal.c (96%) + rename bme680.h => bme680_internal.h (96%) + +diff --git a/bme680.c b/bme680_internal.c +similarity index 96% +rename from bme680.c +rename to bme680_internal.c +index ccd1bf8..33ffb90 100644 +--- a/bme680.c ++++ b/bme680_internal.c +@@ -47,7 +47,7 @@ + + /*! @file bme680.c + @brief Sensor driver for BME680 sensor */ +-#include "bme680.h" ++#include "bme680_internal.h" + + /*! + * @brief This internal API is used to read the calibrated data from the sensor. +@@ -284,7 +284,7 @@ static int8_t boundary_check(uint8_t *value, uint8_t min, uint8_t max, struct bm + *@brief This API is the entry point. + *It reads the chip-id and calibration data from the sensor. + */ +-int8_t bme680_init(struct bme680_dev *dev) ++int8_t bme680_init_internal(struct bme680_dev *dev) + { + int8_t rslt; + +diff --git a/bme680.h b/bme680_internal.h +similarity index 96% +rename from bme680.h +rename to bme680_internal.h +index 8274a8e..6578b3c 100644 +--- a/bme680.h ++++ b/bme680_internal.h +@@ -72,7 +72,7 @@ extern "C" + * @return Result of API execution status + * @retval zero -> Success / +ve value -> Warning / -ve value -> Error + */ +-int8_t bme680_init(struct bme680_dev *dev); ++int8_t bme680_init_internal(struct bme680_dev *dev); + + /*! + * @brief This API writes the given data to the register address +-- +2.17.1 +