From 90fb78969738d03bc2d02e7ab369f2f62f1617a7 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Tue, 10 Mar 2020 15:30:14 +0100 Subject: [PATCH] pkg: add Bosch Sensortech BME680 driver Add the vendor driver implementation from Bosch Sensortech as a package. --- pkg/driver_bme680/Makefile | 12 ++ pkg/driver_bme680/Makefile.dep | 1 + pkg/driver_bme680/Makefile.driver_bme680 | 7 ++ pkg/driver_bme680/Makefile.include | 4 + pkg/driver_bme680/README.md | 41 +++++++ pkg/driver_bme680/contrib/Makefile | 3 + pkg/driver_bme680/contrib/bme680_hal.c | 116 ++++++++++++++++++ pkg/driver_bme680/doc.txt | 6 + pkg/driver_bme680/include/bme680_hal.h | 49 ++++++++ .../0001-reword-files-and-functions.patch | Bin 0 -> 1685 bytes 10 files changed, 239 insertions(+) create mode 100644 pkg/driver_bme680/Makefile create mode 100644 pkg/driver_bme680/Makefile.dep create mode 100644 pkg/driver_bme680/Makefile.driver_bme680 create mode 100644 pkg/driver_bme680/Makefile.include create mode 100644 pkg/driver_bme680/README.md create mode 100644 pkg/driver_bme680/contrib/Makefile create mode 100644 pkg/driver_bme680/contrib/bme680_hal.c create mode 100644 pkg/driver_bme680/doc.txt create mode 100644 pkg/driver_bme680/include/bme680_hal.h create mode 100644 pkg/driver_bme680/patches/0001-reword-files-and-functions.patch 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 0000000000000000000000000000000000000000..efc1e06255ef78626ea299f6ece09bce8d9962e1 GIT binary patch literal 1685 zcmbVMZExE)5dJ&@{twp-0}{(pBw4lj%eB%uHA06LEAVbBGGIv*{|H;60VGzKn`!4 zEyX7nG%VxUGMhsXCvnWK+u{QXw}e05J$wJ+)t_MSV`C(gszwW3)2!9PsYYAI!Z2h| zY;c~(k$_(=hxv`t4vpqD8NWaVL2%$#9rLTmFNJ_kONX08#q}EH1g4<0Mbq7Q8k~89 z#2Wi`c*Y2z<{SJM7^fHWpC0%=0;Tt5Qk5ly;aWN1=l4k#!}K6WX4OX3+$gsrtP<~l zE@K0%(pPyOy*Ik%Aycdm6+$LOnMcudT9(B{3{;ePmU*fVV6Y$v;24zE3c_qLSwPT@ zs}+M0gY)qdSosRxBOxQK3Zt+jRcYH8kVb9MKuOc*Z(dSG!S);D^AQVwR9e)nL^v68 zsZK^L_}2P2DSmsn*y6R}3w}4D zV@xY3e&cZu9Cfepd)XLfMg(4ho|{9d~bz3t&w>NZre>y~{g)G&|bLgAj`J?^fZ zh)Ly6@1gh(yOFqsF%4(L{6pt^?jMhW&xG}dA=KE~{Y>l8QK45y)K&dwp;!MP^lA`# zo-Q(;V-(G2i@cbMqe8D95qi}LV3GRzcO#V_@4TwuH{5Nr`T&3N{E- literal 0 HcmV?d00001