Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
fix: update from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 16, 2023
1 parent 72a9414 commit a8441b8
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 460 deletions.
3 changes: 2 additions & 1 deletion boards/thingy91_nrf9160_ns.overlay
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
Expand All @@ -9,6 +9,7 @@
temp-sensor = &bme680;
humidity-sensor = &bme680;
pressure-sensor = &bme680;
iaq-sensor = &bme680;
accelerometer = &adxl362;
impact-sensor = &adxl372;
};
Expand Down
20 changes: 8 additions & 12 deletions doc/sensor_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,16 @@ Bosch Software Environmental Cluster (BSEC) library
The sensor module supports integration with the BSEC signal processing library using the external sensors, internal convenience API.
If enabled, the BSEC library is used instead of the BME680 Zephyr driver to provide sensor readings from the BME680 for temperature, humidity, and atmospheric pressure.
In addition, the BSEC driver provides an additional sensor reading, indoor air quality (IAQ), which is a metric given in between 0-500 range, which estimates the air quality of the environment.
In the beginning, the IAQ shows 50 (good air), but it is automatically calibrated over time.

As the BSEC library requires a separate license, it is not a default part of |NCS|, but can be downloaded externally and imported into the |NCS| source tree.
.. note::
Using the BSEC library requires accepting a separate license agreement.
For details, see :ref:`bme68x_iaq`.

Perform the following steps to enable BSEC:

1. Download the BSEC library, using the `Bosch BSEC`_ link.
#. Extract and store the folder containing the library contents in the path specified by :ref:`CONFIG_EXTERNAL_SENSORS_BME680_BSEC_PATH <CONFIG_EXTERNAL_SENSORS_BME680_BSEC_PATH>` option or update the path configuration to reference the library location.
#. Disable the Zephyr BME680 driver by setting :kconfig:option:`CONFIG_BME680` to false.
#. Enable the external sensors API BSEC integration layer by enabling :ref:`CONFIG_EXTERNAL_SENSORS_BME680_BSEC <CONFIG_EXTERNAL_SENSORS_BME680_BSEC>` option.
1. To disable the Zephyr BME680 driver, set the :kconfig:option:`CONFIG_BME680` Kconfig option to false.
#. To enable the external sensors API BSEC integration layer, use the :ref:`CONFIG_BME68X_IAQ <CONFIG_BME68X_IAQ>` Kconfig option.

Air quality readings are provided with the :c:enum:`SENSOR_EVT_ENVIRONMENTAL_DATA_READY` event.

Expand All @@ -136,16 +137,11 @@ CONFIG_EXTERNAL_SENSORS_IMPACT_DETECTION
External sensors API BSEC configurations
========================================

.. _CONFIG_EXTERNAL_SENSORS_BME680_BSEC:
.. _CONFIG_BME68X_IAQ:

CONFIG_EXTERNAL_SENSORS_BME680_BSEC
CONFIG_BME68X_IAQ
This option configures the Bosch BSEC library for the BME680.

.. _CONFIG_EXTERNAL_SENSORS_BME680_BSEC_PATH:

CONFIG_EXTERNAL_SENSORS_BME680_BSEC_PATH
This option sets the path for the Bosch BSEC library folder.

.. _CONFIG_EXTERNAL_SENSORS_BSEC_SAMPLE_MODE_ULTRA_LOW_POWER:

CONFIG_EXTERNAL_SENSORS_BSEC_SAMPLE_MODE_ULTRA_LOW_POWER
Expand Down
32 changes: 1 addition & 31 deletions src/ext_sensors/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
#
# Copyright (c) 2021 Nordic Semiconductor ASA
# Copyright (c) 2023 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

target_include_directories(app PRIVATE .)
target_sources_ifdef(CONFIG_EXTERNAL_SENSORS app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ext_sensors.c)

if (CONFIG_EXTERNAL_SENSORS_BME680_BSEC)
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/ext_sensors_bsec.c)
set(bsec_dir ${CONFIG_EXTERNAL_SENSORS_BME680_BSEC_PATH})
if (CONFIG_FP_SOFTABI)
set(BSEC_LIB_DIR ${bsec_dir}/algo/normal_version/bin/gcc/Cortex_M33)
endif()
if (CONFIG_FP_HARDABI)
set(BSEC_LIB_DIR ${bsec_dir}/algo/normal_version/bin/gcc/Cortex_M33F)
endif()

if(NOT EXISTS "${BSEC_LIB_DIR}/libalgobsec.a")
assert(0 "Could not find BSEC library. Minimum version is 1.4.8.0_Generic_Release")
endif()

target_include_directories(app PRIVATE ${bsec_dir}/examples/bsec_iot_example)
target_include_directories(app PRIVATE ${BSEC_LIB_DIR})

target_sources(app PRIVATE ${bsec_dir}/examples/bsec_iot_example/bsec_integration.c)
target_sources(app PRIVATE ${bsec_dir}/examples/bsec_iot_example/bme680.c)

add_library(bsec_lib STATIC IMPORTED GLOBAL)
add_dependencies(bsec_lib math_lib bsec_target)

set_target_properties(bsec_lib PROPERTIES IMPORTED_LOCATION "${BSEC_LIB_DIR}/libalgobsec.a")
set_target_properties(bsec_lib PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${BSEC_LIB_DIR})

target_link_libraries(bsec_lib INTERFACE -L${LIBC_LIBRARY_DIR})
target_link_libraries(app PUBLIC bsec_lib)
endif()
62 changes: 1 addition & 61 deletions src/ext_sensors/Kconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Nordic Semiconductor
# Copyright (c) 2023 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
Expand Down Expand Up @@ -28,66 +28,6 @@ endchoice

endif # EXTERNAL_SENSORS_IMPACT_DETECTION

config EXTERNAL_SENSORS_BME680_BSEC
bool "Use Bosch BME680 library"
depends on !BME680
help
Enable the use of Bosch BSEC library. The library itself is not a part of
NCS and must be downloaded from Bosch Sensortec and placed in the path referenced to by
the CONFIG_EXTERNAL_SENSORS_BME680_BSEC_PATH.
This configuration depends on the BME680 zephyr driver being disabled.

if EXTERNAL_SENSORS_BME680_BSEC

config EXTERNAL_SENSORS_BSEC_THREAD_STACK_SIZE
int "BSEC thread stack size"
default 4096

choice EXTERNAL_SENSORS_BSEC_SAMPLE_MODE
prompt "Bosch BSEC sample mode"
default EXTERNAL_SENSORS_BSEC_SAMPLE_MODE_LOW_POWER
help
Configuration that sets how often sensor data is sampled from the BSEC library.
Each mode corresponds an internal preset that decides how often data is sampled from the
BME680.

config EXTERNAL_SENSORS_BSEC_SAMPLE_MODE_ULTRA_LOW_POWER
bool "BSEC low ultra power mode"
help
Sample data from BSEC every 0.0033333 Hz (300 second interval).

config EXTERNAL_SENSORS_BSEC_SAMPLE_MODE_LOW_POWER
bool "BSEC low power mode"
help
Sample data from BSEC every 0.33333 Hz (3 second interval).

config EXTERNAL_SENSORS_BSEC_SAMPLE_MODE_CONTINUOUS
bool "BSEC continuous mode"
help
Sample data from BSEC every 1 Hz (1 second interval).
This is a particularly power-hungry sample mode that should only be considered for
testing purposes.

endchoice # EXTERNAL_SENSORS_BME680_BSEC_MODE

config EXTERNAL_SENSORS_BSEC_TEMPERATURE_OFFSET
int "BSEC temperature offset in degree celsius * 100"
default 120 if BOARD_THINGY91_NRF9160_NS
default 100
help
BSEC temperature offset. To account for external heat sources on the board.
The actual value is divided by 100. This is due to the Kconfig parser
not supporting floating point types.
The default value 120 is translated to 1.2 degrees celsius offset.

config EXTERNAL_SENSORS_BME680_BSEC_PATH
string "Path to Bosch BSEC library folder"
default "$(ZEPHYR_NRF_MODULE_DIR)/ext/BSEC_1.4.8.0_Generic_Release_updated_v3"
help
Path to the folder where the Bosch BSEC library is placed.

endif # EXTERNAL_SENSORS_BME680_BSEC

module = EXTERNAL_SENSORS
module-str = External sensors
source "subsys/logging/Kconfig.template.log_config"
Expand Down
77 changes: 50 additions & 27 deletions src/ext_sensors/ext_sensors.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
Expand All @@ -11,8 +11,8 @@
#include <stdlib.h>
#include <math.h>

#if defined(CONFIG_EXTERNAL_SENSORS_BME680_BSEC)
#include "ext_sensors_bsec.h"
#if defined(CONFIG_BME68X_IAQ)
#include <drivers/bme68x_iaq.h>
#endif

#include "ext_sensors.h"
Expand Down Expand Up @@ -75,6 +75,14 @@ static struct env_sensor press_sensor = {
.dev = DEVICE_DT_GET(DT_ALIAS(pressure_sensor)),
};

#if defined(CONFIG_BME68X_IAQ)
static struct env_sensor iaq_sensor = {
.channel = SENSOR_CHAN_IAQ,
.dev = DEVICE_DT_GET(DT_ALIAS(iaq_sensor)),

};
#endif

/** Sensor struct for the low-power accelerometer */
static struct env_sensor accel_sensor_lp = {
.channel = SENSOR_CHAN_ACCEL_XYZ,
Expand Down Expand Up @@ -195,15 +203,15 @@ int ext_sensors_init(ext_sensor_handler_t handler)

evt_handler = handler;

#if defined(CONFIG_EXTERNAL_SENSORS_BME680_BSEC)
int err = ext_sensors_bsec_init();

if (err) {
LOG_ERR("ext_sensors_bsec_init, error: %d", err);
evt.type = EXT_SENSOR_EVT_BME680_BSEC_ERROR;
#if defined(CONFIG_BME68X_IAQ)
if (!device_is_ready(iaq_sensor.dev)) {
LOG_ERR("Air quality sensor device is not ready");
evt.type = EXT_SENSOR_EVT_AIR_QUALITY_ERROR;
evt_handler(&evt);
}
#else
#endif /* if defined(CONFIG_BME68X_IAQ) */


if (!device_is_ready(temp_sensor.dev)) {
LOG_ERR("Temperature sensor device is not ready");
evt.type = EXT_SENSOR_EVT_TEMPERATURE_ERROR;
Expand All @@ -221,7 +229,6 @@ int ext_sensors_init(ext_sensor_handler_t handler)
evt.type = EXT_SENSOR_EVT_PRESSURE_ERROR;
evt_handler(&evt);
}
#endif /* if defined(CONFIG_EXTERNAL_SENSORS_BME680_BSEC) */

if (!device_is_ready(accel_sensor_lp.dev)) {
LOG_ERR("Low-power accelerometer device is not ready");
Expand Down Expand Up @@ -253,10 +260,6 @@ int ext_sensors_temperature_get(double *ext_temp)
struct sensor_value data = {0};
struct ext_sensor_evt evt = {0};

#if defined(CONFIG_EXTERNAL_SENSORS_BME680_BSEC)
return ext_sensors_bsec_temperature_get(ext_temp);
#endif

err = sensor_sample_fetch_chan(temp_sensor.dev, SENSOR_CHAN_ALL);
if (err) {
LOG_ERR("Failed to fetch data from %s, error: %d",
Expand Down Expand Up @@ -288,10 +291,6 @@ int ext_sensors_humidity_get(double *ext_hum)
struct sensor_value data = {0};
struct ext_sensor_evt evt = {0};

#if defined(CONFIG_EXTERNAL_SENSORS_BME680_BSEC)
return ext_sensors_bsec_humidity_get(ext_hum);
#endif

err = sensor_sample_fetch_chan(humid_sensor.dev, SENSOR_CHAN_ALL);
if (err) {
LOG_ERR("Failed to fetch data from %s, error: %d",
Expand Down Expand Up @@ -323,10 +322,6 @@ int ext_sensors_pressure_get(double *ext_press)
struct sensor_value data = {0};
struct ext_sensor_evt evt = {0};

#if defined(CONFIG_EXTERNAL_SENSORS_BME680_BSEC)
return ext_sensors_bsec_pressure_get(ext_press);
#endif

err = sensor_sample_fetch_chan(press_sensor.dev, SENSOR_CHAN_ALL);
if (err) {
LOG_ERR("Failed to fetch data from %s, error: %d",
Expand All @@ -346,18 +341,46 @@ int ext_sensors_pressure_get(double *ext_press)
}

k_spinlock_key_t key = k_spin_lock(&(press_sensor.lock));
*ext_press = sensor_value_to_double(&data);
*ext_press = sensor_value_to_double(&data) / 1000.0f;
k_spin_unlock(&(press_sensor.lock), key);

return 0;
}

int ext_sensors_air_quality_get(uint16_t *ext_bsec_air_quality)
{
#if defined(CONFIG_EXTERNAL_SENSORS_BME680_BSEC)
return ext_sensors_bsec_air_quality_get(ext_bsec_air_quality);
#endif
#if defined(CONFIG_BME68X_IAQ)

int err;
struct sensor_value data = {0};
struct ext_sensor_evt evt = {0};

err = sensor_sample_fetch_chan(iaq_sensor.dev, SENSOR_CHAN_ALL);
if (err) {
LOG_ERR("Failed to fetch data from %s, error: %d",
iaq_sensor.dev->name, err);
evt.type = EXT_SENSOR_EVT_AIR_QUALITY_ERROR;
evt_handler(&evt);
return -ENODATA;
}

err = sensor_channel_get(iaq_sensor.dev, iaq_sensor.channel, &data);
if (err) {
LOG_ERR("Failed to fetch data from %s, error: %d",
iaq_sensor.dev->name, err);
evt.type = EXT_SENSOR_EVT_AIR_QUALITY_ERROR;
evt_handler(&evt);
return -ENODATA;
}

k_spinlock_key_t key = k_spin_lock(&(iaq_sensor.lock));
*ext_bsec_air_quality = sensor_value_to_double(&data);
k_spin_unlock(&(iaq_sensor.lock), key);

return 0;
#else
return -ENOTSUP;
#endif /* defined(CONFIG_BME68X_IAQ) */
}

int ext_sensors_accelerometer_threshold_set(double threshold, bool upper)
Expand Down
6 changes: 3 additions & 3 deletions src/ext_sensors/ext_sensors.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Nordic Semiconductor ASA
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
Expand Down Expand Up @@ -42,8 +42,8 @@ enum ext_sensor_evt_type {
EXT_SENSOR_EVT_HUMIDITY_ERROR,
/** Event propagated when an error has occurred with the pressure sensor. */
EXT_SENSOR_EVT_PRESSURE_ERROR,
/** Event propagated when an error has occurred with the Bosch BSEC library. */
EXT_SENSOR_EVT_BME680_BSEC_ERROR
/** Event propagated when an error has occurred with the virtual air quality sensor. */
EXT_SENSOR_EVT_AIR_QUALITY_ERROR
};

/** @brief Structure containing external sensor data. */
Expand Down
Loading

0 comments on commit a8441b8

Please sign in to comment.