From 3b15bbe0e04b4e9190e3bc4ac92127e8fdcaccbf Mon Sep 17 00:00:00 2001 From: MiroZ Date: Sat, 8 Jun 2024 15:27:18 -0700 Subject: [PATCH 1/5] ota download is now not using tls to download image, added Bme68x and sensors task --- README.md | 2 + Wifi.md | 28 +- certs/eventgrid.azure.pem | 28 +- components/BME68x/.piopm | 1 + components/BME68x/CMakeLists.txt | 16 + components/BME68x/LICENSE | 34 + components/BME68x/README.md | 11 + .../bme688_dev_kit/bme688_dev_kit.ino | 228 ++ .../examples/bme688_dev_kit/commMux.cpp | 155 ++ .../BME68x/examples/bme688_dev_kit/commMux.h | 98 + .../examples/forced_mode/forced_mode.ino | 70 + .../examples/parallel_mode/parallel_mode.ino | 89 + .../sequential_mode/sequential_mode.ino | 87 + components/BME68x/keywords.txt | 58 + components/BME68x/library.properties | 10 + components/BME68x/src/bme68x/LICENSE | 30 + components/BME68x/src/bme68x/README.md | 30 + components/BME68x/src/bme68x/bme68x.c | 1848 +++++++++++++++++ components/BME68x/src/bme68x/bme68x.h | 323 +++ components/BME68x/src/bme68x/bme68x_defs.h | 972 +++++++++ components/BME68x/src/bme68xLibrary.cpp | 668 ++++++ components/BME68x/src/bme68xLibrary.h | 350 ++++ main/App.cpp | 12 +- main/App.h | 4 +- main/Bmp280.cpp | 27 - main/CMakeLists.txt | 3 +- main/Led.cpp | 3 +- main/Ota.cpp | 35 +- main/app_config.h | 12 + main/sensors/Bme68x.cpp | 60 + main/sensors/Bme68x.h | 23 + main/sensors/Bmp280.cpp | 43 + main/{ => sensors}/Bmp280.h | 7 +- main/sensors/Sensors.cpp | 49 + main/sensors/Sensors.h | 24 + make.sh | 2 - ota.sh | 7 +- partitions.csv | 3 +- plot/plot.py | 69 + wellhub.code-workspace | 3 +- 40 files changed, 5438 insertions(+), 84 deletions(-) create mode 100755 components/BME68x/.piopm create mode 100755 components/BME68x/CMakeLists.txt create mode 100755 components/BME68x/LICENSE create mode 100755 components/BME68x/README.md create mode 100755 components/BME68x/examples/bme688_dev_kit/bme688_dev_kit.ino create mode 100755 components/BME68x/examples/bme688_dev_kit/commMux.cpp create mode 100755 components/BME68x/examples/bme688_dev_kit/commMux.h create mode 100755 components/BME68x/examples/forced_mode/forced_mode.ino create mode 100755 components/BME68x/examples/parallel_mode/parallel_mode.ino create mode 100755 components/BME68x/examples/sequential_mode/sequential_mode.ino create mode 100755 components/BME68x/keywords.txt create mode 100755 components/BME68x/library.properties create mode 100755 components/BME68x/src/bme68x/LICENSE create mode 100755 components/BME68x/src/bme68x/README.md create mode 100755 components/BME68x/src/bme68x/bme68x.c create mode 100755 components/BME68x/src/bme68x/bme68x.h create mode 100755 components/BME68x/src/bme68x/bme68x_defs.h create mode 100755 components/BME68x/src/bme68xLibrary.cpp create mode 100755 components/BME68x/src/bme68xLibrary.h delete mode 100644 main/Bmp280.cpp create mode 100644 main/sensors/Bme68x.cpp create mode 100644 main/sensors/Bme68x.h create mode 100644 main/sensors/Bmp280.cpp rename main/{ => sensors}/Bmp280.h (71%) create mode 100644 main/sensors/Sensors.cpp create mode 100644 main/sensors/Sensors.h create mode 100755 plot/plot.py diff --git a/README.md b/README.md index ac490a7..b726675 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ MQTT server: This produces eventgrid.azure.pem certificate file. +need root certificates openssl s_client -showcerts -connect www.bigfoot-inc.com:443 +openssl s_client -showcerts -connect mqtt-dev-server.westus2-1.ts.eventgrid.azure.net:8883 \ No newline at end of file diff --git a/Wifi.md b/Wifi.md index 1c8eb01..25e06f5 100644 --- a/Wifi.md +++ b/Wifi.md @@ -1,17 +1,27 @@ ```mermaid graph -A(Wifi start) +A(Wifi start) +A-->AA +AA[start wifi service] B[Start provision] -A-->|not provisioned -SETTINGS.wifi.num = 0|B +AA-->|not provisioned +SETTINGS.wifi.num == 0|B C{{single or - multiple}} -A-->|provisioned +multiple}} +AA-->|provisioned SETTINGS.wifi.num > 0|C -D[connect] -C-->|single -SETTINGS.wifi.num = 1|D - +D[try 3 times: +connect] +C-->|single +SETTINGS.wifi.num == 1|D +E[try 3 times: +connect to known SSID +with highest rssi] +C-->|multiple +SETTINGS.wifi.num > 1|E +F[try 3 times: +connect round robin] +E-->|failed|F ``` diff --git a/certs/eventgrid.azure.pem b/certs/eventgrid.azure.pem index 3e8d50c..43860a1 100755 --- a/certs/eventgrid.azure.pem +++ b/certs/eventgrid.azure.pem @@ -1,22 +1,20 @@ -----BEGIN CERTIFICATE----- -MIIDqDCCAy6gAwIBAgIQDo2+XqYQ5su1acc29tcASzAKBggqhkjOPQQDAzBhMQsw +MIIDXDCCAuOgAwIBAgIQDvLl2DaBUgJV6Sxgj7wv9DAKBggqhkjOPQQDAzBhMQsw CQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cu ZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBHMzAe -Fw0yMDA4MTIwMDAwMDBaFw0yNDA2MjcyMzU5NTlaMF0xCzAJBgNVBAYTAlVTMR4w +Fw0yMzA2MDgwMDAwMDBaFw0yNjA4MjUyMzU5NTlaMF0xCzAJBgNVBAYTAlVTMR4w HAYDVQQKExVNaWNyb3NvZnQgQ29ycG9yYXRpb24xLjAsBgNVBAMTJU1pY3Jvc29m -dCBBenVyZSBFQ0MgVExTIElzc3VpbmcgQ0EgMDIwdjAQBgcqhkjOPQIBBgUrgQQA -IgNiAATlxJr7ThHOTChFtITU0Taop1bFSVf3h9toLKI7bi0GVWd3a3uQVIImulk4 -pdVuOkoCI+wEIBkrsEnNUrH28+uUXb48SnwzdhArFcG3zygvZEnBYdcWNlOLKZ5X -ZhqUZKKjggGtMIIBqTAdBgNVHQ4EFgQUneUOdzdHngkz2ZC+KgnCEn9O0qMwHwYD -VR0jBBgwFoAUs9tIpPmhxdiuNkHMEWNpYim8S8YwDgYDVR0PAQH/BAQDAgGGMB0G -A1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjASBgNVHRMBAf8ECDAGAQH/AgEA +dCBBenVyZSBFQ0MgVExTIElzc3VpbmcgQ0EgMDgwdjAQBgcqhkjOPQIBBgUrgQQA +IgNiAATlQzoKIJQIe8bd4sX2x9XBtFvoh5m7Neph3MYORvv/rg2Ew7Cfb00eZ+zS +njUosyOUCspenehe0PyKtmq6pPshLu5Ww/hLEoQT3drwxZ5PaYHmGEGoy2aPBeXa +23k5ruijggFiMIIBXjASBgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQWBBStVB0D +VHHGL17WWxhYzm4kxdaiCjAfBgNVHSMEGDAWgBSz20ik+aHF2K42QcwRY2liKbxL +xjAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC MHYGCCsGAQUFBwEBBGowaDAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNl cnQuY29tMEAGCCsGAQUFBzAChjRodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20v -RGlnaUNlcnRHbG9iYWxSb290RzMuY3J0MHsGA1UdHwR0MHIwN6A1oDOGMWh0dHA6 -Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RHMy5jcmwwN6A1 -oDOGMWh0dHA6Ly9jcmw0LmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RH -My5jcmwwHQYDVR0gBBYwFDAIBgZngQwBAgEwCAYGZ4EMAQICMBAGCSsGAQQBgjcV -AQQDAgEAMAoGCCqGSM49BAMDA2gAMGUCMCIdzL1WliSNxC+uX8IzgfyxdmELlX0I -7TtWowrKUov8QSfi57irRIGpHvmxoFW7XQIxAPdJJZ/jAbKJ5lS21mLnKcdsctXO -tl2eFVqGSfIFWbJUihZCKesfoSMThZ4fa/Ir8g== +RGlnaUNlcnRHbG9iYWxSb290RzMuY3J0MEIGA1UdHwQ7MDkwN6A1oDOGMWh0dHA6 +Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RHMy5jcmwwHQYD +VR0gBBYwFDAIBgZngQwBAgEwCAYGZ4EMAQICMAoGCCqGSM49BAMDA2cAMGQCMD+q +5Uq1fSGZSKRhrnWKKXlp4DvfZCEU/MF3rbdwAaXI/KVM65YRO9HvRbfDpV3x1wIw +CHvqqpg/8YJPDn8NJIS/Rg+lYraOseXeuNYzkjeY6RLxIDB+nLVDs9QJ3/co89Cd -----END CERTIFICATE----- diff --git a/components/BME68x/.piopm b/components/BME68x/.piopm new file mode 100755 index 0000000..d4c4253 --- /dev/null +++ b/components/BME68x/.piopm @@ -0,0 +1 @@ +{"type": "library", "name": "BME68x Sensor library", "version": "1.1.40407", "spec": {"owner": "boschsensortec", "id": 14368, "name": "BME68x Sensor library", "requirements": null, "uri": null}} \ No newline at end of file diff --git a/components/BME68x/CMakeLists.txt b/components/BME68x/CMakeLists.txt new file mode 100755 index 0000000..660f5a4 --- /dev/null +++ b/components/BME68x/CMakeLists.txt @@ -0,0 +1,16 @@ +set(COMPONENT_SRCDIRS + "src" + "src/bme68x" +) + +set(COMPONENT_ADD_INCLUDEDIRS + "src" +) + +set(COMPONENT_REQUIRES + "arduino" +) + +register_component() + +target_compile_options(${COMPONENT_TARGET} PRIVATE -fno-rtti) diff --git a/components/BME68x/LICENSE b/components/BME68x/LICENSE new file mode 100755 index 0000000..f1e8a94 --- /dev/null +++ b/components/BME68x/LICENSE @@ -0,0 +1,34 @@ +Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. + +BME68x Library +Date : 2021/06/26 +Usage : Arduino Library and example code for the BME68x family of sensors + +BSD-3-Clause + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/components/BME68x/README.md b/components/BME68x/README.md new file mode 100755 index 0000000..5134820 --- /dev/null +++ b/components/BME68x/README.md @@ -0,0 +1,11 @@ +# Bosch BME68x Library + +This Arduino library wraps the [BME68x Sensor API](https://github.com/BoschSensortec/BME68x-Sensor-API) to provide a simpler experience to use the BME680 or BME688 Sensors from Bosch Sensortec. + +## Supported sensors + +- [BME680](https://www.bosch-sensortec.com/products/environmental-sensors/gas-sensors/bme680/) +- [BME688](https://www.bosch-sensortec.com/products/environmental-sensors/gas-sensors/bme688/) + +--- +### Copyright (c) 2021 Bosch Sensortec GmbH \ No newline at end of file diff --git a/components/BME68x/examples/bme688_dev_kit/bme688_dev_kit.ino b/components/BME68x/examples/bme688_dev_kit/bme688_dev_kit.ino new file mode 100755 index 0000000..2c6ee1b --- /dev/null +++ b/components/BME68x/examples/bme688_dev_kit/bme688_dev_kit.ino @@ -0,0 +1,228 @@ +/** + * + * Copyright (C) 2021 Bosch Sensortec GmbH + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +/** + * bme688_dev_kit.ino : + * This is an example to log data using the BME688 development + * kit which has been designed to work with Adafruit ESP32 Feather Board + * For more information visit : + * https://www.bosch-sensortec.com/software-tools/software/bme688-software/ + */ + +#include "Arduino.h" +#include "FS.h" +#include "bme68xLibrary.h" +#include "commMux.h" +#include + +/* Macros used in BME68x_datalogger module */ +#define N_KIT_SENS 8 +#define SD_PIN_CS 33 +#define SPI_COMM_SPEED 32000000 +#define SD_MAX_FILES 5 +#define PANIC_LED LED_BUILTIN +#define PANIC_DUR 1000 +/* measurement duration */ +#define MEAS_DUR 140 +#define LOG_FILE_NAME "/BME688_Datalogger_Log.csv" + +/* Declaration of variables */ +Bme68x bme[N_KIT_SENS]; +commMux commSetup[N_KIT_SENS]; +uint8_t lastMeasindex[N_KIT_SENS] = {0}; +bme68xData sensorData[N_KIT_SENS] = {0}; +String logHeader; +uint32_t lastLogged = 0; + +/** + * @brief Initializes the sensor and hardware settings + * Initializes the SD card module + */ +void setup(void) { + Serial.begin(115200); + /* Initiate SPI communication */ + commMuxBegin(Wire, SPI); + pinMode(PANIC_LED, OUTPUT); + delay(100); + + /* Setting SD Card */ + if (!SD.begin(SD_PIN_CS, SPI, SPI_COMM_SPEED, "/sd", SD_MAX_FILES)) { + Serial.println("SD Card not found"); + panicLeds(); + } else { + SD.remove(LOG_FILE_NAME); + File file = SD.open(LOG_FILE_NAME, "w"); + if (!file) { + Serial.println("Failed to open file for writing"); + panicLeds(); + } + /* Parameters for logging in the file */ + logHeader = "TimeStamp(ms),Sensor Index,Temperature(deg " + "C),Pressure(Pa),Humidity(%),Gas Resistance(ohm),Gas " + "Index,Meas Index,idac,Status,Gas Valid,Heater Stable"; + + if (file.println(logHeader)) { + Serial.println(logHeader); + file.close(); + } else { + panicLeds(); + } + logHeader = ""; + } + + /* Communication interface set for all the 8 sensors in the development kit */ + for (uint8_t i = 0; i < N_KIT_SENS; i++) { + commSetup[i] = commMuxSetConfig(Wire, SPI, i, commSetup[i]); + bme[i].begin(BME68X_SPI_INTF, commMuxRead, commMuxWrite, commMuxDelay, + &commSetup[i]); + if(bme[i].checkStatus()) { + Serial.println("Initializing sensor " + String(i) + " failed with error " + bme[i].statusString()); + panicLeds(); + } + } + + /* Setting the default heater profile configuration */ + for (uint8_t i = 0; i < N_KIT_SENS; i++) { + bme[i].setTPH(); + + /* Heater temperature in degree Celsius as per the suggested heater profile + */ + uint16_t tempProf[10] = {320, 100, 100, 100, 200, 200, 200, 320, 320, 320}; + /* Multiplier to the shared heater duration */ + uint16_t mulProf[10] = {5, 2, 10, 30, 5, 5, 5, 5, 5, 5}; + /* Shared heating duration in milliseconds */ + uint16_t sharedHeatrDur = + MEAS_DUR - bme[i].getMeasDur(BME68X_PARALLEL_MODE); + + bme[i].setHeaterProf(tempProf, mulProf, sharedHeatrDur, 10); + + /* Parallel mode of sensor operation */ + bme[i].setOpMode(BME68X_PARALLEL_MODE); + } +} + +void loop(void) { + uint8_t nFieldsLeft = 0; + int16_t indexDiff; + bool newLogdata = false; + /* Control loop for data acquisition - checks if the data is available */ + if ((millis() - lastLogged) >= MEAS_DUR) { + + lastLogged = millis(); + for (uint8_t i = 0; i < N_KIT_SENS; i++) { + if (bme[i].fetchData()) { + do { + nFieldsLeft = bme[i].getData(sensorData[i]); + /* Check if new data is received */ + if (sensorData[i].status & BME68X_NEW_DATA_MSK) { + /* Inspect miss of data index */ + indexDiff = + (int16_t)sensorData[i].meas_index - (int16_t)lastMeasindex[i]; + if (indexDiff > 1) { + + Serial.println("Skip I:" + String(i) + + ", DIFF:" + String(indexDiff) + + ", MI:" + String(sensorData[i].meas_index) + + ", LMI:" + String(lastMeasindex[i]) + + ", S:" + String(sensorData[i].status, HEX)); + panicLeds(); + } + lastMeasindex[i] = sensorData[i].meas_index; + + logHeader += millis(); + logHeader += ","; + logHeader += i; + logHeader += ","; + logHeader += sensorData[i].temperature; + logHeader += ","; + logHeader += sensorData[i].pressure; + logHeader += ","; + logHeader += sensorData[i].humidity; + logHeader += ","; + logHeader += sensorData[i].gas_resistance; + logHeader += ","; + logHeader += sensorData[i].gas_index; + logHeader += ","; + logHeader += sensorData[i].meas_index; + logHeader += ","; + logHeader += sensorData[i].idac; + logHeader += ","; + logHeader += String(sensorData[i].status, HEX); + logHeader += ","; + logHeader += sensorData[i].status & BME68X_GASM_VALID_MSK; + logHeader += ","; + logHeader += sensorData[i].status & BME68X_HEAT_STAB_MSK; + logHeader += "\r\n"; + newLogdata = true; + } + } while (nFieldsLeft); + } + } + } + + if (newLogdata) { + newLogdata = false; + + digitalWrite(PANIC_LED, HIGH); + + appendFile(logHeader); + logHeader = ""; + + digitalWrite(PANIC_LED, LOW); + } +} + +/*! + * @brief Configuring the sensor with digital pin 13 as + * an output and toggles it at one second pace + */ +static void panicLeds(void) { + while (1) { + digitalWrite(PANIC_LED, HIGH); + delay(PANIC_DUR); + digitalWrite(PANIC_LED, LOW); + delay(PANIC_DUR); + } +} + +/*! + * @brief Writing the sensor data to the log file(csv) + * @param sensorData + */ +static void writeFile(String sensorData) { + + File file = SD.open(LOG_FILE_NAME, FILE_WRITE); + if (!file) { + Serial.println("Failed to open file for writing"); + panicLeds(); + } + if (file.print(sensorData)) { + Serial.print(sensorData); + } else { + Serial.println("Write failed"); + } + file.close(); +} + +/*! + * @brief Appending the sensor data into the log file(csv) + * @param sensorData + */ +static void appendFile(String sensorData) { + File file = SD.open(LOG_FILE_NAME, FILE_APPEND); + if (!file) { + Serial.println("Failed to open file for appending"); + panicLeds(); + } + if (file.print(sensorData)) { + Serial.print(sensorData); + } else { + Serial.println("Write append"); + } + file.close(); +} diff --git a/components/BME68x/examples/bme688_dev_kit/commMux.cpp b/components/BME68x/examples/bme688_dev_kit/commMux.cpp new file mode 100755 index 0000000..54a2b3c --- /dev/null +++ b/components/BME68x/examples/bme688_dev_kit/commMux.cpp @@ -0,0 +1,155 @@ +/** + Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. + + BSD-3-Clause + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + @file commMux.cpp + @date 8 Feb 2022 + @version 1.1.40407 + + */ + +#include "commMux.h" + +#define CLOCK_FREQUENCY 400000 +#define COMM_SPEED 8000000 + +const uint8_t I2C_EXPANDER_ADDR = 0x20; +const uint8_t I2C_EXPANDER_OUTPUT_REG_ADDR = 0x01; +const uint8_t I2C_EXPANDER_OUTPUT_DESELECT = 0xFF; +const uint8_t I2C_EXPANDER_CONFIG_REG_ADDR = 0x03; +const uint8_t I2C_EXPANDER_CONFIG_REG_MASK = 0x00; + +/** + * @brief Function to configure the communication across sensors + */ +commMux commMuxSetConfig(TwoWire &wireobj, SPIClass &spiobj, uint8_t idx, commMux &comm) +{ + comm.select = ((0x01 << idx) ^ 0xFF); + comm.spiobj = &spiobj; + comm.wireobj = &wireobj; + + return comm; +} + +/** + * @brief Function to trigger the communication + */ +void commMuxBegin(TwoWire &wireobj, SPIClass &spiobj) +{ + wireobj.begin(); + wireobj.setClock(CLOCK_FREQUENCY); + wireobj.beginTransmission(I2C_EXPANDER_ADDR); + wireobj.write(I2C_EXPANDER_CONFIG_REG_ADDR); + wireobj.write(I2C_EXPANDER_CONFIG_REG_MASK); + wireobj.endTransmission(); + + spiobj.begin(); +} + +/** + * @brief Function to set the ship select pin of the SPI + */ +static void setChipSelect(TwoWire *wireobj, uint8_t mask) +{ + // send I2C-Expander device address + wireobj->beginTransmission(I2C_EXPANDER_ADDR); + // send I2C-Expander output register address + wireobj->write(I2C_EXPANDER_OUTPUT_REG_ADDR); + // send mask to set output level of GPIO pins + wireobj->write(mask); + // end communication + wireobj->endTransmission(); +} + +/** + * @brief Function to write the sensor data to the register + */ +int8_t commMuxWrite(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr) +{ + commMux *comm = (commMux*) intf_ptr; + uint32_t i; + + if (comm) + { + setChipSelect(comm->wireobj, comm->select); + + comm->spiobj->beginTransaction(SPISettings(COMM_SPEED, MSBFIRST, SPI_MODE0)); + comm->spiobj->transfer(reg_addr); + for (i = 0; i < length; i++) + { + comm->spiobj->transfer(reg_data[i]); + } + comm->spiobj->endTransaction(); + + setChipSelect(comm->wireobj, I2C_EXPANDER_OUTPUT_DESELECT); + + return 0; + } + + return 1; +} + +/** + * @brief Function to read the sensor data from the register + */ +int8_t commMuxRead(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr) +{ + commMux *comm = (commMux*) intf_ptr; + uint32_t i; + + if (comm) + { + setChipSelect(comm->wireobj, comm->select); + + comm->spiobj->beginTransaction(SPISettings(COMM_SPEED, MSBFIRST, SPI_MODE0)); + comm->spiobj->transfer(reg_addr); + for (i = 0; i < length; i++) + { + reg_data[i] = comm->spiobj->transfer(0xFF); + } + comm->spiobj->endTransaction(); + + setChipSelect(comm->wireobj, I2C_EXPANDER_OUTPUT_DESELECT); + + return 0; + } + + return 1; +} + +/** + * @brief Function to maintain a delay between communication + */ +void commMuxDelay(uint32_t period_us, void *intf_ptr) +{ + (void) intf_ptr; + delayMicroseconds(period_us); +} diff --git a/components/BME68x/examples/bme688_dev_kit/commMux.h b/components/BME68x/examples/bme688_dev_kit/commMux.h new file mode 100755 index 0000000..c3160bb --- /dev/null +++ b/components/BME68x/examples/bme688_dev_kit/commMux.h @@ -0,0 +1,98 @@ +/** + Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. + + BSD-3-Clause + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + + @file commMux.h + @date 8 Feb 2022 + @version 1.1.40407 + +*/ +#ifndef COMM_MUX_H +#define COMM_MUX_H + +#include "Arduino.h" +#include "Wire.h" +#include "SPI.h" + +/** + * Datatype working as an interface descriptor + */ +typedef struct { + TwoWire *wireobj; + SPIClass *spiobj; + uint8_t select; +} commMux; + +/** + * @brief Function to configure the communication across sensors + * @param wireobj : The TwoWire object + * @param spiobj : The SPIClass object + * @param idx : Selected sensor for communication interface + * @param comm : Structure for selected sensor + * @return : Structure holding the communication setup + */ +commMux commMuxSetConfig(TwoWire &wireobj, SPIClass &spiobj, uint8_t idx, commMux &comm); + +/** + * @brief Function to trigger the communication + * @param wireobj : The TwoWire object + * @param spiobj : The SPIClass object + */ +void commMuxBegin(TwoWire &wireobj, SPIClass &spiobj); + +/** + * @brief Function to write the sensor data to the register + * @param reg_addr : Address of the register + * @param reg_data : Pointer to the data to be written + * @param length : length of the register data + * @param intf_ptr : Pointer to the interface descriptor + * @return 0 if successful, non-zero otherwise + */ +int8_t commMuxWrite(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr); + +/** + * @brief Function to read the sensor data from the register + * @param reg_addr : Address of the register + * @param reg_data : Pointer to the data to be read from the sensor + * @param length : length of the register data + * @param intf_ptr : Pointer to the interface descriptor + * @return 0 if successful, non-zero otherwise + */ +int8_t commMuxRead(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr); + +/** + * @brief Function to maintain a delay between communication + * @param period_us : Time delay in micro secs + * @param intf_ptr : Pointer to the interface descriptor + */ +void commMuxDelay(uint32_t period_us, void *intf_ptr); + +#endif /* COMM_MUX_H */ diff --git a/components/BME68x/examples/forced_mode/forced_mode.ino b/components/BME68x/examples/forced_mode/forced_mode.ino new file mode 100755 index 0000000..b588c3b --- /dev/null +++ b/components/BME68x/examples/forced_mode/forced_mode.ino @@ -0,0 +1,70 @@ +/** + * Copyright (C) 2021 Bosch Sensortec GmbH + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#include "Arduino.h" +#include "bme68xLibrary.h" + +#ifndef PIN_CS +#define PIN_CS SS +#endif + +Bme68x bme; + +/** + * @brief Initializes the sensor and hardware settings + */ +void setup(void) +{ + SPI.begin(); + Serial.begin(115200); + + while (!Serial) + delay(10); + + /* initializes the sensor based on SPI library */ + bme.begin(PIN_CS, SPI); + + if(bme.checkStatus()) + { + if (bme.checkStatus() == BME68X_ERROR) + { + Serial.println("Sensor error:" + bme.statusString()); + return; + } + else if (bme.checkStatus() == BME68X_WARNING) + { + Serial.println("Sensor Warning:" + bme.statusString()); + } + } + + /* Set the default configuration for temperature, pressure and humidity */ + bme.setTPH(); + + /* Set the heater configuration to 300 deg C for 100ms for Forced mode */ + bme.setHeaterProf(300, 100); + + Serial.println("TimeStamp(ms), Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm), Status"); +} + +void loop(void) +{ + bme68xData data; + + bme.setOpMode(BME68X_FORCED_MODE); + delayMicroseconds(bme.getMeasDur()); + + if (bme.fetchData()) + { + bme.getData(data); + Serial.print(String(millis()) + ", "); + Serial.print(String(data.temperature) + ", "); + Serial.print(String(data.pressure) + ", "); + Serial.print(String(data.humidity) + ", "); + Serial.print(String(data.gas_resistance) + ", "); + Serial.println(data.status, HEX); + } +} diff --git a/components/BME68x/examples/parallel_mode/parallel_mode.ino b/components/BME68x/examples/parallel_mode/parallel_mode.ino new file mode 100755 index 0000000..52660a1 --- /dev/null +++ b/components/BME68x/examples/parallel_mode/parallel_mode.ino @@ -0,0 +1,89 @@ +/** + * Copyright (C) 2021 Bosch Sensortec GmbH + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#include "Arduino.h" +#include "bme68xLibrary.h" + +#define NEW_GAS_MEAS (BME68X_GASM_VALID_MSK | BME68X_HEAT_STAB_MSK | BME68X_NEW_DATA_MSK) +#define MEAS_DUR 140 + +#ifndef PIN_CS +#define PIN_CS SS +#endif + +Bme68x bme; + +/** + * @brief Initializes the sensor and hardware settings + */ +void setup(void) +{ + SPI.begin(); + Serial.begin(115200); + + while (!Serial) + delay(10); + + /* initializes the sensor based on SPI library */ + bme.begin(PIN_CS, SPI); + + if(bme.checkStatus()) + { + if (bme.checkStatus() == BME68X_ERROR) + { + Serial.println("Sensor error:" + bme.statusString()); + return; + } + else if (bme.checkStatus() == BME68X_WARNING) + { + Serial.println("Sensor Warning:" + bme.statusString()); + } + } + + /* Set the default configuration for temperature, pressure and humidity */ + bme.setTPH(); + + /* Heater temperature in degree Celsius */ + uint16_t tempProf[10] = { 320, 100, 100, 100, 200, 200, 200, 320, 320, + 320 }; + /* Multiplier to the shared heater duration */ + uint16_t mulProf[10] = { 5, 2, 10, 30, 5, 5, 5, 5, 5, 5 }; + /* Shared heating duration in milliseconds */ + uint16_t sharedHeatrDur = MEAS_DUR - (bme.getMeasDur(BME68X_PARALLEL_MODE) / 1000); + + bme.setHeaterProf(tempProf, mulProf, sharedHeatrDur, 10); + bme.setOpMode(BME68X_PARALLEL_MODE); + + Serial.println("TimeStamp(ms), Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm), Status, Gas index"); +} + +void loop(void) +{ + bme68xData data; + uint8_t nFieldsLeft = 0; + + /* data being fetched for every 140ms */ + delay(MEAS_DUR); + + if (bme.fetchData()) + { + do + { + nFieldsLeft = bme.getData(data); + if (data.status == NEW_GAS_MEAS) + { + Serial.print(String(millis()) + ", "); + Serial.print(String(data.temperature) + ", "); + Serial.print(String(data.pressure) + ", "); + Serial.print(String(data.humidity) + ", "); + Serial.print(String(data.gas_resistance) + ", "); + Serial.print(String(data.status, HEX) + ", "); + Serial.println(data.gas_index); + } + } while (nFieldsLeft); + } +} diff --git a/components/BME68x/examples/sequential_mode/sequential_mode.ino b/components/BME68x/examples/sequential_mode/sequential_mode.ino new file mode 100755 index 0000000..0987b0f --- /dev/null +++ b/components/BME68x/examples/sequential_mode/sequential_mode.ino @@ -0,0 +1,87 @@ +/** + * Copyright (C) 2021 Bosch Sensortec GmbH + * + * SPDX-License-Identifier: BSD-3-Clause + * + */ + +#include "Arduino.h" +#include "bme68xLibrary.h" + +#define NEW_GAS_MEAS (BME68X_GASM_VALID_MSK | BME68X_HEAT_STAB_MSK | BME68X_NEW_DATA_MSK) + +#ifndef PIN_CS +#define PIN_CS SS +#endif + +Bme68x bme; + +/** + * @brief Initializes the sensor and hardware settings + */ +void setup(void) +{ + SPI.begin(); + Serial.begin(115200); + + while (!Serial) + delay(10); + + /* Initializes the sensor based on SPI library */ + bme.begin(PIN_CS, SPI); + + if(bme.checkStatus()) + { + if (bme.checkStatus() == BME68X_ERROR) + { + Serial.println("Sensor error:" + bme.statusString()); + return; + } + else if (bme.checkStatus() == BME68X_WARNING) + { + Serial.println("Sensor Warning:" + bme.statusString()); + } + } + + /* Set the default configuration for temperature, pressure and humidity */ + bme.setTPH(); + + /* Heater temperature in degree Celsius */ + uint16_t tempProf[10] = { 100, 200, 320 }; + /* Heating duration in milliseconds */ + uint16_t durProf[10] = { 150, 150, 150 }; + + bme.setSeqSleep(BME68X_ODR_250_MS); + bme.setHeaterProf(tempProf, durProf, 3); + bme.setOpMode(BME68X_SEQUENTIAL_MODE); + + Serial.println("TimeStamp(ms), Temperature(deg C), Pressure(Pa), Humidity(%), Gas resistance(ohm), Status, Gas index"); +} + +void loop(void) +{ + bme68xData data; + uint8_t nFieldsLeft = 0; + + delay(150); + + if (bme.fetchData()) + { + do + { + nFieldsLeft = bme.getData(data); + //if (data.status == NEW_GAS_MEAS) + { + Serial.print(String(millis()) + ", "); + Serial.print(String(data.temperature) + ", "); + Serial.print(String(data.pressure) + ", "); + Serial.print(String(data.humidity) + ", "); + Serial.print(String(data.gas_resistance) + ", "); + Serial.print(String(data.status, HEX) + ", "); + Serial.println(data.gas_index); + if(data.gas_index == 2) /* Sequential mode sleeps after this measurement */ + delay(250); + } + } while (nFieldsLeft); + } +} diff --git a/components/BME68x/keywords.txt b/components/BME68x/keywords.txt new file mode 100755 index 0000000..d747a22 --- /dev/null +++ b/components/BME68x/keywords.txt @@ -0,0 +1,58 @@ +####################################### +# BME68x Keywords # +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Bme68x KEYWORD1 +bme68xScommT KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) # +####################################### + +Bme68x KEYWORD2 +begin KEYWORD2 +readReg KEYWORD2 +writeReg KEYWORD2 +softReset KEYWORD2 +setAmbientTemp KEYWORD2 +getMeasDur KEYWORD2 +setOpMode KEYWORD2 +getOpMode KEYWORD2 +getTPH KEYWORD2 +setTPH KEYWORD2 +getFilter KEYWORD2 +setFilter KEYWORD2 +getSeqSleep KEYWORD2 +setSeqSleep KEYWORD2 +setHeaterProf KEYWORD2 +fetchData KEYWORD2 +getData KEYWORD2 +getSensorData KEYWORD2 +getHeaterConfiguration KEYWORD2 +getUniqueId KEYWORD2 +intfError KEYWORD2 +checkStatus KEYWORD2 +statusString KEYWORD2 + +####################################### +# Constants (LITERAL1) # +####################################### + +BME68X_SLEEP_MODE LITERAL1 +BME68X_FORCED_MODE LITERAL1 +BME68X_PARALLEL_MODE LITERAL1 +BME68X_SEQUENTIAL_MODE LITERAL1 + +####################################### +# Structures (KEYWORD3) # +####################################### + + +bme68xData KEYWORD3 +bme68xDev KEYWORD3 +bme68xConf KEYWORD3 +bme68xHeatrConf KEYWORD3 diff --git a/components/BME68x/library.properties b/components/BME68x/library.properties new file mode 100755 index 0000000..e344c60 --- /dev/null +++ b/components/BME68x/library.properties @@ -0,0 +1,10 @@ +name=BME68x Sensor library +version=1.1.40407 +author=Bosch Sensortec +maintainer=Bosch Sensortec +sentence=Bosch Sensortec BME680 and BME688 sensor library +url=https://www.bosch-sensortec.com/software-tools/software/bme688-software/ +paragraph= +category=Sensors +architectures=* +includes=bme68xLibrary.h \ No newline at end of file diff --git a/components/BME68x/src/bme68x/LICENSE b/components/BME68x/src/bme68x/LICENSE new file mode 100755 index 0000000..39d6442 --- /dev/null +++ b/components/BME68x/src/bme68x/LICENSE @@ -0,0 +1,30 @@ +Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. + +BSD-3-Clause + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/components/BME68x/src/bme68x/README.md b/components/BME68x/src/bme68x/README.md new file mode 100755 index 0000000..77f94ff --- /dev/null +++ b/components/BME68x/src/bme68x/README.md @@ -0,0 +1,30 @@ +# BME68X Sensor API + +> Bosch Sensortec's BME680 and BME688 sensor API + +## Sensor Overview +BME680 is an integrated environmental sensor developed specifically for mobile applications and wearables where size and low power consumption are key requirements. Expanding Bosch Sensortec’s existing family of environmental sensors, the BME680 integrates for the first time high-linearity and high-accuracy gas, pressure, humidity and temperature sensors. It consists of an 8-pin metal-lid 3.0 x 3.0 x 0.93 mm³ LGA package which is designed for optimized consumption depending on the specific operating mode, long term stability and high EMC robustness. The gas sensor within the BME680 can detect a broad range of gases to measure air quality for personal well being. Gases that can be detected by the BME680 include Volatile Organic Compounds (VOC) from paints (such as formaldehyde), lacquers, paint strippers, cleaning supplies, furnishings, office equipment, glues, adhesives and alcohol. + +### Features + +- Air quality measurement +- Personalized weather station +- Context awareness, e.g. skin moisture detection, room change detection +- Fitness monitoring / well-being +- Warning regarding dryness or high temperatures +- Measurement of volume and air flow +- Home automation control (e.g. HVAC) +- GPS enhancement (e.g. time-to-first-fix improvement, dead reckoning, slope detection) +- Indoor navigation (change of floor detection, elevator detection) +- Altitude tracking and calories expenditure for sports activities + +#### Important links: +For more information, please refer to: + +- [BME680 Product page](https://www.bosch-sensortec.com/bst/products/all_products/bme680) +- [BME680 & BME688 Github page](https://github.com/BoschSensortec/BME68x-Sensor-API) +- [BME680 gas sensor design guide](https://community.bosch-sensortec.com/t5/Knowledge-base/BME680-gas-sensor-series-design-guide/ta-p/5952) +- [Knowledge base page](https://community.bosch-sensortec.com/t5/Knowledge-base/tkb-p/bst_community-mems-tkb) +- [Community support page](https://community.bosch-sensortec.com) + +--- \ No newline at end of file diff --git a/components/BME68x/src/bme68x/bme68x.c b/components/BME68x/src/bme68x/bme68x.c new file mode 100755 index 0000000..7c3c935 --- /dev/null +++ b/components/BME68x/src/bme68x/bme68x.c @@ -0,0 +1,1848 @@ +/** +* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bme68x.c +* @date 2021-11-09 +* @version v4.4.7 +* +*/ + +#include "bme68x.h" +#include + +/* This internal API is used to read the calibration coefficients */ +static int8_t get_calib_data(struct bme68x_dev *dev); + +/* This internal API is used to read variant ID information register status */ +static int8_t read_variant_id(struct bme68x_dev *dev); + +/* This internal API is used to calculate the gas wait */ +static uint8_t calc_gas_wait(uint16_t dur); + +#ifndef BME68X_USE_FPU + +/* This internal API is used to calculate the temperature in integer */ +static int16_t calc_temperature(uint32_t temp_adc, struct bme68x_dev *dev); + +/* This internal API is used to calculate the pressure in integer */ +static uint32_t calc_pressure(uint32_t pres_adc, const struct bme68x_dev *dev); + +/* This internal API is used to calculate the humidity in integer */ +static uint32_t calc_humidity(uint16_t hum_adc, const struct bme68x_dev *dev); + +/* This internal API is used to calculate the gas resistance high */ +static uint32_t calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range); + +/* This internal API is used to calculate the gas resistance low */ +static uint32_t calc_gas_resistance_low(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev); + +/* This internal API is used to calculate the heater resistance using integer */ +static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev); + +#else + +/* This internal API is used to calculate the temperature value in float */ +static float calc_temperature(uint32_t temp_adc, struct bme68x_dev *dev); + +/* This internal API is used to calculate the pressure value in float */ +static float calc_pressure(uint32_t pres_adc, const struct bme68x_dev *dev); + +/* This internal API is used to calculate the humidity value in float */ +static float calc_humidity(uint16_t hum_adc, const struct bme68x_dev *dev); + +/* This internal API is used to calculate the gas resistance high value in float */ +static float calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range); + +/* This internal API is used to calculate the gas resistance low value in float */ +static float calc_gas_resistance_low(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev); + +/* This internal API is used to calculate the heater resistance value using float */ +static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev); + +#endif + +/* This internal API is used to read a single data of the sensor */ +static int8_t read_field_data(uint8_t index, struct bme68x_data *data, struct bme68x_dev *dev); + +/* This internal API is used to read all data fields of the sensor */ +static int8_t read_all_field_data(struct bme68x_data * const data[], struct bme68x_dev *dev); + +/* This internal API is used to switch between SPI memory pages */ +static int8_t set_mem_page(uint8_t reg_addr, struct bme68x_dev *dev); + +/* This internal API is used to get the current SPI memory page */ +static int8_t get_mem_page(struct bme68x_dev *dev); + +/* This internal API is used to check the bme68x_dev for null pointers */ +static int8_t null_ptr_check(const struct bme68x_dev *dev); + +/* This internal API is used to set heater configurations */ +static int8_t set_conf(const struct bme68x_heatr_conf *conf, uint8_t op_mode, uint8_t *nb_conv, struct bme68x_dev *dev); + +/* This internal API is used to limit the max value of a parameter */ +static int8_t boundary_check(uint8_t *value, uint8_t max, struct bme68x_dev *dev); + +/* This internal API is used to calculate the register value for + * shared heater duration */ +static uint8_t calc_heatr_dur_shared(uint16_t dur); + +/* This internal API is used to swap two fields */ +static void swap_fields(uint8_t index1, uint8_t index2, struct bme68x_data *field[]); + +/* This internal API is used sort the sensor data */ +static void sort_sensor_data(uint8_t low_index, uint8_t high_index, struct bme68x_data *field[]); + +/* + * @brief Function to analyze the sensor data + * + * @param[in] data Array of measurement data + * @param[in] n_meas Number of measurements + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +static int8_t analyze_sensor_data(const struct bme68x_data *data, uint8_t n_meas); + +/******************************************************************************************/ +/* Global API definitions */ +/******************************************************************************************/ + +/* @brief This API reads the chip-id of the sensor which is the first step to +* verify the sensor and also calibrates the sensor +* As this API is the entry point, call this API before using other APIs. +*/ +int8_t bme68x_init(struct bme68x_dev *dev) +{ + int8_t rslt; + + rslt = bme68x_soft_reset(dev); + if (rslt == BME68X_OK) + { + rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev); + if (rslt == BME68X_OK) + { + if (dev->chip_id == BME68X_CHIP_ID) + { + /* Read Variant ID */ + rslt = read_variant_id(dev); + + if (rslt == BME68X_OK) + { + /* Get the Calibration data */ + rslt = get_calib_data(dev); + } + } + else + { + rslt = BME68X_E_DEV_NOT_FOUND; + } + } + } + + return rslt; +} + +/* + * @brief This API writes the given data to the register address of the sensor + */ +int8_t bme68x_set_regs(const uint8_t *reg_addr, const uint8_t *reg_data, uint32_t len, struct bme68x_dev *dev) +{ + int8_t rslt; + + /* Length of the temporary buffer is 2*(length of register)*/ + uint8_t tmp_buff[BME68X_LEN_INTERLEAVE_BUFF] = { 0 }; + uint16_t index; + + /* Check for null pointer in the device structure*/ + rslt = null_ptr_check(dev); + if ((rslt == BME68X_OK) && reg_addr && reg_data) + { + if ((len > 0) && (len <= (BME68X_LEN_INTERLEAVE_BUFF / 2))) + { + /* Interleave the 2 arrays */ + for (index = 0; index < len; index++) + { + if (dev->intf == BME68X_SPI_INTF) + { + /* Set the memory page */ + rslt = set_mem_page(reg_addr[index], dev); + tmp_buff[(2 * index)] = reg_addr[index] & BME68X_SPI_WR_MSK; + } + else + { + tmp_buff[(2 * index)] = reg_addr[index]; + } + + tmp_buff[(2 * index) + 1] = reg_data[index]; + } + + /* Write the interleaved array */ + if (rslt == BME68X_OK) + { + dev->intf_rslt = dev->write(tmp_buff[0], &tmp_buff[1], (2 * len) - 1, dev->intf_ptr); + if (dev->intf_rslt != 0) + { + rslt = BME68X_E_COM_FAIL; + } + } + } + else + { + rslt = BME68X_E_INVALID_LENGTH; + } + } + else + { + rslt = BME68X_E_NULL_PTR; + } + + return rslt; +} + +/* + * @brief This API reads the data from the given register address of sensor. + */ +int8_t bme68x_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bme68x_dev *dev) +{ + int8_t rslt; + + /* Check for null pointer in the device structure*/ + rslt = null_ptr_check(dev); + if ((rslt == BME68X_OK) && reg_data) + { + if (dev->intf == BME68X_SPI_INTF) + { + /* Set the memory page */ + rslt = set_mem_page(reg_addr, dev); + if (rslt == BME68X_OK) + { + reg_addr = reg_addr | BME68X_SPI_RD_MSK; + } + } + + dev->intf_rslt = dev->read(reg_addr, reg_data, len, dev->intf_ptr); + if (dev->intf_rslt != 0) + { + rslt = BME68X_E_COM_FAIL; + } + } + else + { + rslt = BME68X_E_NULL_PTR; + } + + return rslt; +} + +/* + * @brief This API soft-resets the sensor. + */ +int8_t bme68x_soft_reset(struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t reg_addr = BME68X_REG_SOFT_RESET; + + /* 0xb6 is the soft reset command */ + uint8_t soft_rst_cmd = BME68X_SOFT_RESET_CMD; + + /* Check for null pointer in the device structure*/ + rslt = null_ptr_check(dev); + if (rslt == BME68X_OK) + { + if (dev->intf == BME68X_SPI_INTF) + { + rslt = get_mem_page(dev); + } + + /* Reset the device */ + if (rslt == BME68X_OK) + { + rslt = bme68x_set_regs(®_addr, &soft_rst_cmd, 1, dev); + + /* Wait for 5ms */ + dev->delay_us(BME68X_PERIOD_RESET, dev->intf_ptr); + if (rslt == BME68X_OK) + { + /* After reset get the memory page */ + if (dev->intf == BME68X_SPI_INTF) + { + rslt = get_mem_page(dev); + } + } + } + } + + return rslt; +} + +/* + * @brief This API is used to set the oversampling, filter and odr configuration + */ +int8_t bme68x_set_conf(struct bme68x_conf *conf, struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t odr20 = 0, odr3 = 1; + uint8_t current_op_mode; + + /* Register data starting from BME68X_REG_CTRL_GAS_1(0x71) up to BME68X_REG_CONFIG(0x75) */ + uint8_t reg_array[BME68X_LEN_CONFIG] = { 0x71, 0x72, 0x73, 0x74, 0x75 }; + uint8_t data_array[BME68X_LEN_CONFIG] = { 0 }; + + rslt = bme68x_get_op_mode(¤t_op_mode, dev); + if (rslt == BME68X_OK) + { + /* Configure only in the sleep mode */ + rslt = bme68x_set_op_mode(BME68X_SLEEP_MODE, dev); + } + + if (conf == NULL) + { + rslt = BME68X_E_NULL_PTR; + } + else if (rslt == BME68X_OK) + { + /* Read the whole configuration and write it back once later */ + rslt = bme68x_get_regs(reg_array[0], data_array, BME68X_LEN_CONFIG, dev); + dev->info_msg = BME68X_OK; + if (rslt == BME68X_OK) + { + rslt = boundary_check(&conf->filter, BME68X_FILTER_SIZE_127, dev); + } + + if (rslt == BME68X_OK) + { + rslt = boundary_check(&conf->os_temp, BME68X_OS_16X, dev); + } + + if (rslt == BME68X_OK) + { + rslt = boundary_check(&conf->os_pres, BME68X_OS_16X, dev); + } + + if (rslt == BME68X_OK) + { + rslt = boundary_check(&conf->os_hum, BME68X_OS_16X, dev); + } + + if (rslt == BME68X_OK) + { + rslt = boundary_check(&conf->odr, BME68X_ODR_NONE, dev); + } + + if (rslt == BME68X_OK) + { + data_array[4] = BME68X_SET_BITS(data_array[4], BME68X_FILTER, conf->filter); + data_array[3] = BME68X_SET_BITS(data_array[3], BME68X_OST, conf->os_temp); + data_array[3] = BME68X_SET_BITS(data_array[3], BME68X_OSP, conf->os_pres); + data_array[1] = BME68X_SET_BITS_POS_0(data_array[1], BME68X_OSH, conf->os_hum); + if (conf->odr != BME68X_ODR_NONE) + { + odr20 = conf->odr; + odr3 = 0; + } + + data_array[4] = BME68X_SET_BITS(data_array[4], BME68X_ODR20, odr20); + data_array[0] = BME68X_SET_BITS(data_array[0], BME68X_ODR3, odr3); + } + } + + if (rslt == BME68X_OK) + { + rslt = bme68x_set_regs(reg_array, data_array, BME68X_LEN_CONFIG, dev); + } + + if ((current_op_mode != BME68X_SLEEP_MODE) && (rslt == BME68X_OK)) + { + rslt = bme68x_set_op_mode(current_op_mode, dev); + } + + return rslt; +} + +/* + * @brief This API is used to get the oversampling, filter and odr + */ +int8_t bme68x_get_conf(struct bme68x_conf *conf, struct bme68x_dev *dev) +{ + int8_t rslt; + + /* starting address of the register array for burst read*/ + uint8_t reg_addr = BME68X_REG_CTRL_GAS_1; + uint8_t data_array[BME68X_LEN_CONFIG]; + + rslt = bme68x_get_regs(reg_addr, data_array, 5, dev); + if (!conf) + { + rslt = BME68X_E_NULL_PTR; + } + else if (rslt == BME68X_OK) + { + conf->os_hum = BME68X_GET_BITS_POS_0(data_array[1], BME68X_OSH); + conf->filter = BME68X_GET_BITS(data_array[4], BME68X_FILTER); + conf->os_temp = BME68X_GET_BITS(data_array[3], BME68X_OST); + conf->os_pres = BME68X_GET_BITS(data_array[3], BME68X_OSP); + if (BME68X_GET_BITS(data_array[0], BME68X_ODR3)) + { + conf->odr = BME68X_ODR_NONE; + } + else + { + conf->odr = BME68X_GET_BITS(data_array[4], BME68X_ODR20); + } + } + + return rslt; +} + +/* + * @brief This API is used to set the operation mode of the sensor + */ +int8_t bme68x_set_op_mode(const uint8_t op_mode, struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t tmp_pow_mode; + uint8_t pow_mode = 0; + uint8_t reg_addr = BME68X_REG_CTRL_MEAS; + + /* Call until in sleep */ + do + { + rslt = bme68x_get_regs(BME68X_REG_CTRL_MEAS, &tmp_pow_mode, 1, dev); + if (rslt == BME68X_OK) + { + /* Put to sleep before changing mode */ + pow_mode = (tmp_pow_mode & BME68X_MODE_MSK); + if (pow_mode != BME68X_SLEEP_MODE) + { + tmp_pow_mode &= ~BME68X_MODE_MSK; /* Set to sleep */ + rslt = bme68x_set_regs(®_addr, &tmp_pow_mode, 1, dev); + dev->delay_us(BME68X_PERIOD_POLL, dev->intf_ptr); + } + } + } while ((pow_mode != BME68X_SLEEP_MODE) && (rslt == BME68X_OK)); + + /* Already in sleep */ + if ((op_mode != BME68X_SLEEP_MODE) && (rslt == BME68X_OK)) + { + tmp_pow_mode = (tmp_pow_mode & ~BME68X_MODE_MSK) | (op_mode & BME68X_MODE_MSK); + rslt = bme68x_set_regs(®_addr, &tmp_pow_mode, 1, dev); + } + + return rslt; +} + +/* + * @brief This API is used to get the operation mode of the sensor. + */ +int8_t bme68x_get_op_mode(uint8_t *op_mode, struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t mode; + + if (op_mode) + { + rslt = bme68x_get_regs(BME68X_REG_CTRL_MEAS, &mode, 1, dev); + + /* Masking the other register bit info*/ + *op_mode = mode & BME68X_MODE_MSK; + } + else + { + rslt = BME68X_E_NULL_PTR; + } + + return rslt; +} + +/* + * @brief This API is used to get the remaining duration that can be used for heating. + */ +uint32_t bme68x_get_meas_dur(const uint8_t op_mode, struct bme68x_conf *conf, struct bme68x_dev *dev) +{ + int8_t rslt; + uint32_t meas_dur = 0; /* Calculate in us */ + uint32_t meas_cycles; + uint8_t os_to_meas_cycles[6] = { 0, 1, 2, 4, 8, 16 }; + + if (conf != NULL) + { + /* Boundary check for temperature oversampling */ + rslt = boundary_check(&conf->os_temp, BME68X_OS_16X, dev); + + if (rslt == BME68X_OK) + { + /* Boundary check for pressure oversampling */ + rslt = boundary_check(&conf->os_pres, BME68X_OS_16X, dev); + } + + if (rslt == BME68X_OK) + { + /* Boundary check for humidity oversampling */ + rslt = boundary_check(&conf->os_hum, BME68X_OS_16X, dev); + } + + if (rslt == BME68X_OK) + { + meas_cycles = os_to_meas_cycles[conf->os_temp]; + meas_cycles += os_to_meas_cycles[conf->os_pres]; + meas_cycles += os_to_meas_cycles[conf->os_hum]; + + /* TPH measurement duration */ + meas_dur = meas_cycles * UINT32_C(1963); + meas_dur += UINT32_C(477 * 4); /* TPH switching duration */ + meas_dur += UINT32_C(477 * 5); /* Gas measurement duration */ + + if (op_mode != BME68X_PARALLEL_MODE) + { + meas_dur += UINT32_C(1000); /* Wake up duration of 1ms */ + } + } + } + + return meas_dur; +} + +/* + * @brief This API reads the pressure, temperature and humidity and gas data + * from the sensor, compensates the data and store it in the bme68x_data + * structure instance passed by the user. + */ +int8_t bme68x_get_data(uint8_t op_mode, struct bme68x_data *data, uint8_t *n_data, struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t i = 0, j = 0, new_fields = 0; + struct bme68x_data *field_ptr[3] = { 0 }; + struct bme68x_data field_data[3] = { { 0 } }; + + field_ptr[0] = &field_data[0]; + field_ptr[1] = &field_data[1]; + field_ptr[2] = &field_data[2]; + + rslt = null_ptr_check(dev); + if ((rslt == BME68X_OK) && (data != NULL)) + { + /* Reading the sensor data in forced mode only */ + if (op_mode == BME68X_FORCED_MODE) + { + rslt = read_field_data(0, data, dev); + if (rslt == BME68X_OK) + { + if (data->status & BME68X_NEW_DATA_MSK) + { + new_fields = 1; + } + else + { + new_fields = 0; + rslt = BME68X_W_NO_NEW_DATA; + } + } + } + else if ((op_mode == BME68X_PARALLEL_MODE) || (op_mode == BME68X_SEQUENTIAL_MODE)) + { + /* Read the 3 fields and count the number of new data fields */ + rslt = read_all_field_data(field_ptr, dev); + + new_fields = 0; + for (i = 0; (i < 3) && (rslt == BME68X_OK); i++) + { + if (field_ptr[i]->status & BME68X_NEW_DATA_MSK) + { + new_fields++; + } + } + + /* Sort the sensor data in parallel & sequential modes*/ + for (i = 0; (i < 2) && (rslt == BME68X_OK); i++) + { + for (j = i + 1; j < 3; j++) + { + sort_sensor_data(i, j, field_ptr); + } + } + + /* Copy the sorted data */ + for (i = 0; ((i < 3) && (rslt == BME68X_OK)); i++) + { + data[i] = *field_ptr[i]; + } + + if (new_fields == 0) + { + rslt = BME68X_W_NO_NEW_DATA; + } + } + else + { + rslt = BME68X_W_DEFINE_OP_MODE; + } + + if (n_data == NULL) + { + rslt = BME68X_E_NULL_PTR; + } + else + { + *n_data = new_fields; + } + } + else + { + rslt = BME68X_E_NULL_PTR; + } + + return rslt; +} + +/* + * @brief This API is used to set the gas configuration of the sensor. + */ +int8_t bme68x_set_heatr_conf(uint8_t op_mode, const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t nb_conv = 0; + uint8_t hctrl, run_gas = 0; + uint8_t ctrl_gas_data[2]; + uint8_t ctrl_gas_addr[2] = { BME68X_REG_CTRL_GAS_0, BME68X_REG_CTRL_GAS_1 }; + + if (conf != NULL) + { + rslt = bme68x_set_op_mode(BME68X_SLEEP_MODE, dev); + if (rslt == BME68X_OK) + { + rslt = set_conf(conf, op_mode, &nb_conv, dev); + } + + if (rslt == BME68X_OK) + { + rslt = bme68x_get_regs(BME68X_REG_CTRL_GAS_0, ctrl_gas_data, 2, dev); + if (rslt == BME68X_OK) + { + if (conf->enable == BME68X_ENABLE) + { + hctrl = BME68X_ENABLE_HEATER; + if (dev->variant_id == BME68X_VARIANT_GAS_HIGH) + { + run_gas = BME68X_ENABLE_GAS_MEAS_H; + } + else + { + run_gas = BME68X_ENABLE_GAS_MEAS_L; + } + } + else + { + hctrl = BME68X_DISABLE_HEATER; + run_gas = BME68X_DISABLE_GAS_MEAS; + } + + ctrl_gas_data[0] = BME68X_SET_BITS(ctrl_gas_data[0], BME68X_HCTRL, hctrl); + ctrl_gas_data[1] = BME68X_SET_BITS_POS_0(ctrl_gas_data[1], BME68X_NBCONV, nb_conv); + ctrl_gas_data[1] = BME68X_SET_BITS(ctrl_gas_data[1], BME68X_RUN_GAS, run_gas); + rslt = bme68x_set_regs(ctrl_gas_addr, ctrl_gas_data, 2, dev); + } + } + } + else + { + rslt = BME68X_E_NULL_PTR; + } + + return rslt; +} + +/* + * @brief This API is used to get the gas configuration of the sensor. + */ +int8_t bme68x_get_heatr_conf(const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t data_array[10] = { 0 }; + uint8_t i; + + /* FIXME: Add conversion to deg C and ms and add the other parameters */ + rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0, data_array, 10, dev); + if (rslt == BME68X_OK) + { + if (conf && conf->heatr_dur_prof && conf->heatr_temp_prof) + { + for (i = 0; i < 10; i++) + { + conf->heatr_temp_prof[i] = data_array[i]; + } + + rslt = bme68x_get_regs(BME68X_REG_GAS_WAIT0, data_array, 10, dev); + if (rslt == BME68X_OK) + { + for (i = 0; i < 10; i++) + { + conf->heatr_dur_prof[i] = data_array[i]; + } + } + } + else + { + rslt = BME68X_E_NULL_PTR; + } + } + + return rslt; +} + +/* + * @brief This API performs Self-test of low and high gas variants of BME68X + */ +int8_t bme68x_selftest_check(const struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t n_fields; + uint8_t i = 0; + struct bme68x_data data[BME68X_N_MEAS] = { { 0 } }; + struct bme68x_dev t_dev; + struct bme68x_conf conf; + struct bme68x_heatr_conf heatr_conf; + + /* Copy required parameters from reference bme68x_dev struct */ + t_dev.amb_temp = 25; + t_dev.read = dev->read; + t_dev.write = dev->write; + t_dev.intf = dev->intf; + t_dev.delay_us = dev->delay_us; + t_dev.intf_ptr = dev->intf_ptr; + rslt = bme68x_init(&t_dev); + if (rslt == BME68X_OK) + { + /* Set the temperature, pressure and humidity & filter settings */ + conf.os_hum = BME68X_OS_1X; + conf.os_pres = BME68X_OS_16X; + conf.os_temp = BME68X_OS_2X; + + /* Set the remaining gas sensor settings and link the heating profile */ + heatr_conf.enable = BME68X_ENABLE; + heatr_conf.heatr_dur = BME68X_HEATR_DUR1; + heatr_conf.heatr_temp = BME68X_HIGH_TEMP; + rslt = bme68x_set_heatr_conf(BME68X_FORCED_MODE, &heatr_conf, &t_dev); + if (rslt == BME68X_OK) + { + rslt = bme68x_set_conf(&conf, &t_dev); + if (rslt == BME68X_OK) + { + rslt = bme68x_set_op_mode(BME68X_FORCED_MODE, &t_dev); /* Trigger a measurement */ + if (rslt == BME68X_OK) + { + /* Wait for the measurement to complete */ + t_dev.delay_us(BME68X_HEATR_DUR1_DELAY, t_dev.intf_ptr); + rslt = bme68x_get_data(BME68X_FORCED_MODE, &data[0], &n_fields, &t_dev); + if (rslt == BME68X_OK) + { + if ((data[0].idac != 0x00) && (data[0].idac != 0xFF) && + (data[0].status & BME68X_GASM_VALID_MSK)) + { + rslt = BME68X_OK; + } + else + { + rslt = BME68X_E_SELF_TEST; + } + } + } + } + } + + heatr_conf.heatr_dur = BME68X_HEATR_DUR2; + while ((rslt == BME68X_OK) && (i < BME68X_N_MEAS)) + { + if (i % 2 == 0) + { + heatr_conf.heatr_temp = BME68X_HIGH_TEMP; /* Higher temperature */ + } + else + { + heatr_conf.heatr_temp = BME68X_LOW_TEMP; /* Lower temperature */ + } + + rslt = bme68x_set_heatr_conf(BME68X_FORCED_MODE, &heatr_conf, &t_dev); + if (rslt == BME68X_OK) + { + rslt = bme68x_set_conf(&conf, &t_dev); + if (rslt == BME68X_OK) + { + rslt = bme68x_set_op_mode(BME68X_FORCED_MODE, &t_dev); /* Trigger a measurement */ + if (rslt == BME68X_OK) + { + /* Wait for the measurement to complete */ + t_dev.delay_us(BME68X_HEATR_DUR2_DELAY, t_dev.intf_ptr); + rslt = bme68x_get_data(BME68X_FORCED_MODE, &data[i], &n_fields, &t_dev); + } + } + } + + i++; + } + + if (rslt == BME68X_OK) + { + rslt = analyze_sensor_data(data, BME68X_N_MEAS); + } + } + + return rslt; +} + +/*****************************INTERNAL APIs***********************************************/ +#ifndef BME68X_USE_FPU + +/* @brief This internal API is used to calculate the temperature value. */ +static int16_t calc_temperature(uint32_t temp_adc, struct bme68x_dev *dev) +{ + int64_t var1; + int64_t var2; + int64_t var3; + int16_t calc_temp; + + /*lint -save -e701 -e702 -e704 */ + var1 = ((int32_t)temp_adc >> 3) - ((int32_t)dev->calib.par_t1 << 1); + var2 = (var1 * (int32_t)dev->calib.par_t2) >> 11; + var3 = ((var1 >> 1) * (var1 >> 1)) >> 12; + var3 = ((var3) * ((int32_t)dev->calib.par_t3 << 4)) >> 14; + dev->calib.t_fine = (int32_t)(var2 + var3); + calc_temp = (int16_t)(((dev->calib.t_fine * 5) + 128) >> 8); + + /*lint -restore */ + return calc_temp; +} + +/* @brief This internal API is used to calculate the pressure value. */ +static uint32_t calc_pressure(uint32_t pres_adc, const struct bme68x_dev *dev) +{ + int32_t var1; + int32_t var2; + int32_t var3; + int32_t pressure_comp; + + /* This value is used to check precedence to multiplication or division + * in the pressure compensation equation to achieve least loss of precision and + * avoiding overflows. + * i.e Comparing value, pres_ovf_check = (1 << 31) >> 1 + */ + const int32_t pres_ovf_check = INT32_C(0x40000000); + + /*lint -save -e701 -e702 -e713 */ + var1 = (((int32_t)dev->calib.t_fine) >> 1) - 64000; + var2 = ((((var1 >> 2) * (var1 >> 2)) >> 11) * (int32_t)dev->calib.par_p6) >> 2; + var2 = var2 + ((var1 * (int32_t)dev->calib.par_p5) << 1); + var2 = (var2 >> 2) + ((int32_t)dev->calib.par_p4 << 16); + var1 = (((((var1 >> 2) * (var1 >> 2)) >> 13) * ((int32_t)dev->calib.par_p3 << 5)) >> 3) + + (((int32_t)dev->calib.par_p2 * var1) >> 1); + var1 = var1 >> 18; + var1 = ((32768 + var1) * (int32_t)dev->calib.par_p1) >> 15; + pressure_comp = 1048576 - pres_adc; + pressure_comp = (int32_t)((pressure_comp - (var2 >> 12)) * ((uint32_t)3125)); + if (pressure_comp >= pres_ovf_check) + { + pressure_comp = ((pressure_comp / var1) << 1); + } + else + { + pressure_comp = ((pressure_comp << 1) / var1); + } + + var1 = ((int32_t)dev->calib.par_p9 * (int32_t)(((pressure_comp >> 3) * (pressure_comp >> 3)) >> 13)) >> 12; + var2 = ((int32_t)(pressure_comp >> 2) * (int32_t)dev->calib.par_p8) >> 13; + var3 = + ((int32_t)(pressure_comp >> 8) * (int32_t)(pressure_comp >> 8) * (int32_t)(pressure_comp >> 8) * + (int32_t)dev->calib.par_p10) >> 17; + pressure_comp = (int32_t)(pressure_comp) + ((var1 + var2 + var3 + ((int32_t)dev->calib.par_p7 << 7)) >> 4); + + /*lint -restore */ + return (uint32_t)pressure_comp; +} + +/* This internal API is used to calculate the humidity in integer */ +static uint32_t calc_humidity(uint16_t hum_adc, const struct bme68x_dev *dev) +{ + int32_t var1; + int32_t var2; + int32_t var3; + int32_t var4; + int32_t var5; + int32_t var6; + int32_t temp_scaled; + int32_t calc_hum; + + /*lint -save -e702 -e704 */ + temp_scaled = (((int32_t)dev->calib.t_fine * 5) + 128) >> 8; + var1 = (int32_t)(hum_adc - ((int32_t)((int32_t)dev->calib.par_h1 * 16))) - + (((temp_scaled * (int32_t)dev->calib.par_h3) / ((int32_t)100)) >> 1); + var2 = + ((int32_t)dev->calib.par_h2 * + (((temp_scaled * (int32_t)dev->calib.par_h4) / ((int32_t)100)) + + (((temp_scaled * ((temp_scaled * (int32_t)dev->calib.par_h5) / ((int32_t)100))) >> 6) / ((int32_t)100)) + + (int32_t)(1 << 14))) >> 10; + var3 = var1 * var2; + var4 = (int32_t)dev->calib.par_h6 << 7; + var4 = ((var4) + ((temp_scaled * (int32_t)dev->calib.par_h7) / ((int32_t)100))) >> 4; + var5 = ((var3 >> 14) * (var3 >> 14)) >> 10; + var6 = (var4 * var5) >> 1; + calc_hum = (((var3 + var6) >> 10) * ((int32_t)1000)) >> 12; + if (calc_hum > 100000) /* Cap at 100%rH */ + { + calc_hum = 100000; + } + else if (calc_hum < 0) + { + calc_hum = 0; + } + + /*lint -restore */ + return (uint32_t)calc_hum; +} + +/* This internal API is used to calculate the gas resistance low */ +static uint32_t calc_gas_resistance_low(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev) +{ + int64_t var1; + uint64_t var2; + int64_t var3; + uint32_t calc_gas_res; + uint32_t lookup_table1[16] = { + UINT32_C(2147483647), UINT32_C(2147483647), UINT32_C(2147483647), UINT32_C(2147483647), UINT32_C(2147483647), + UINT32_C(2126008810), UINT32_C(2147483647), UINT32_C(2130303777), UINT32_C(2147483647), UINT32_C(2147483647), + UINT32_C(2143188679), UINT32_C(2136746228), UINT32_C(2147483647), UINT32_C(2126008810), UINT32_C(2147483647), + UINT32_C(2147483647) + }; + uint32_t lookup_table2[16] = { + UINT32_C(4096000000), UINT32_C(2048000000), UINT32_C(1024000000), UINT32_C(512000000), UINT32_C(255744255), + UINT32_C(127110228), UINT32_C(64000000), UINT32_C(32258064), UINT32_C(16016016), UINT32_C(8000000), UINT32_C( + 4000000), UINT32_C(2000000), UINT32_C(1000000), UINT32_C(500000), UINT32_C(250000), UINT32_C(125000) + }; + + /*lint -save -e704 */ + var1 = (int64_t)((1340 + (5 * (int64_t)dev->calib.range_sw_err)) * ((int64_t)lookup_table1[gas_range])) >> 16; + var2 = (((int64_t)((int64_t)gas_res_adc << 15) - (int64_t)(16777216)) + var1); + var3 = (((int64_t)lookup_table2[gas_range] * (int64_t)var1) >> 9); + calc_gas_res = (uint32_t)((var3 + ((int64_t)var2 >> 1)) / (int64_t)var2); + + /*lint -restore */ + return calc_gas_res; +} + +/* This internal API is used to calculate the gas resistance */ +static uint32_t calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range) +{ + uint32_t calc_gas_res; + uint32_t var1 = UINT32_C(262144) >> gas_range; + int32_t var2 = (int32_t)gas_res_adc - INT32_C(512); + + var2 *= INT32_C(3); + var2 = INT32_C(4096) + var2; + + /* multiplying 10000 then dividing then multiplying by 100 instead of multiplying by 1000000 to prevent overflow */ + calc_gas_res = (UINT32_C(10000) * var1) / (uint32_t)var2; + calc_gas_res = calc_gas_res * 100; + + return calc_gas_res; +} + +/* This internal API is used to calculate the heater resistance value using float */ +static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev) +{ + uint8_t heatr_res; + int32_t var1; + int32_t var2; + int32_t var3; + int32_t var4; + int32_t var5; + int32_t heatr_res_x100; + + if (temp > 400) /* Cap temperature */ + { + temp = 400; + } + + var1 = (((int32_t)dev->amb_temp * dev->calib.par_gh3) / 1000) * 256; + var2 = (dev->calib.par_gh1 + 784) * (((((dev->calib.par_gh2 + 154009) * temp * 5) / 100) + 3276800) / 10); + var3 = var1 + (var2 / 2); + var4 = (var3 / (dev->calib.res_heat_range + 4)); + var5 = (131 * dev->calib.res_heat_val) + 65536; + heatr_res_x100 = (int32_t)(((var4 / var5) - 250) * 34); + heatr_res = (uint8_t)((heatr_res_x100 + 50) / 100); + + return heatr_res; +} + +#else + +/* @brief This internal API is used to calculate the temperature value. */ +static float calc_temperature(uint32_t temp_adc, struct bme68x_dev *dev) +{ + float var1; + float var2; + float calc_temp; + + /* calculate var1 data */ + var1 = ((((float)temp_adc / 16384.0f) - ((float)dev->calib.par_t1 / 1024.0f)) * ((float)dev->calib.par_t2)); + + /* calculate var2 data */ + var2 = + (((((float)temp_adc / 131072.0f) - ((float)dev->calib.par_t1 / 8192.0f)) * + (((float)temp_adc / 131072.0f) - ((float)dev->calib.par_t1 / 8192.0f))) * ((float)dev->calib.par_t3 * 16.0f)); + + /* t_fine value*/ + dev->calib.t_fine = (var1 + var2); + + /* compensated temperature data*/ + calc_temp = ((dev->calib.t_fine) / 5120.0f); + + return calc_temp; +} + +/* @brief This internal API is used to calculate the pressure value. */ +static float calc_pressure(uint32_t pres_adc, const struct bme68x_dev *dev) +{ + float var1; + float var2; + float var3; + float calc_pres; + + var1 = (((float)dev->calib.t_fine / 2.0f) - 64000.0f); + var2 = var1 * var1 * (((float)dev->calib.par_p6) / (131072.0f)); + var2 = var2 + (var1 * ((float)dev->calib.par_p5) * 2.0f); + var2 = (var2 / 4.0f) + (((float)dev->calib.par_p4) * 65536.0f); + var1 = (((((float)dev->calib.par_p3 * var1 * var1) / 16384.0f) + ((float)dev->calib.par_p2 * var1)) / 524288.0f); + var1 = ((1.0f + (var1 / 32768.0f)) * ((float)dev->calib.par_p1)); + calc_pres = (1048576.0f - ((float)pres_adc)); + + /* Avoid exception caused by division by zero */ + if ((int)var1 != 0) + { + calc_pres = (((calc_pres - (var2 / 4096.0f)) * 6250.0f) / var1); + var1 = (((float)dev->calib.par_p9) * calc_pres * calc_pres) / 2147483648.0f; + var2 = calc_pres * (((float)dev->calib.par_p8) / 32768.0f); + var3 = ((calc_pres / 256.0f) * (calc_pres / 256.0f) * (calc_pres / 256.0f) * (dev->calib.par_p10 / 131072.0f)); + calc_pres = (calc_pres + (var1 + var2 + var3 + ((float)dev->calib.par_p7 * 128.0f)) / 16.0f); + } + else + { + calc_pres = 0; + } + + return calc_pres; +} + +/* This internal API is used to calculate the humidity in integer */ +static float calc_humidity(uint16_t hum_adc, const struct bme68x_dev *dev) +{ + float calc_hum; + float var1; + float var2; + float var3; + float var4; + float temp_comp; + + /* compensated temperature data*/ + temp_comp = ((dev->calib.t_fine) / 5120.0f); + var1 = (float)((float)hum_adc) - + (((float)dev->calib.par_h1 * 16.0f) + (((float)dev->calib.par_h3 / 2.0f) * temp_comp)); + var2 = var1 * + ((float)(((float)dev->calib.par_h2 / 262144.0f) * + (1.0f + (((float)dev->calib.par_h4 / 16384.0f) * temp_comp) + + (((float)dev->calib.par_h5 / 1048576.0f) * temp_comp * temp_comp)))); + var3 = (float)dev->calib.par_h6 / 16384.0f; + var4 = (float)dev->calib.par_h7 / 2097152.0f; + calc_hum = var2 + ((var3 + (var4 * temp_comp)) * var2 * var2); + if (calc_hum > 100.0f) + { + calc_hum = 100.0f; + } + else if (calc_hum < 0.0f) + { + calc_hum = 0.0f; + } + + return calc_hum; +} + +/* This internal API is used to calculate the gas resistance low value in float */ +static float calc_gas_resistance_low(uint16_t gas_res_adc, uint8_t gas_range, const struct bme68x_dev *dev) +{ + float calc_gas_res; + float var1; + float var2; + float var3; + float gas_res_f = gas_res_adc; + float gas_range_f = (1U << gas_range); /*lint !e790 / Suspicious truncation, integral to float */ + const float lookup_k1_range[16] = { + 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, -0.8f, 0.0f, 0.0f, -0.2f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f + }; + const float lookup_k2_range[16] = { + 0.0f, 0.0f, 0.0f, 0.0f, 0.1f, 0.7f, 0.0f, -0.8f, -0.1f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f + }; + + var1 = (1340.0f + (5.0f * dev->calib.range_sw_err)); + var2 = (var1) * (1.0f + lookup_k1_range[gas_range] / 100.0f); + var3 = 1.0f + (lookup_k2_range[gas_range] / 100.0f); + calc_gas_res = 1.0f / (float)(var3 * (0.000000125f) * gas_range_f * (((gas_res_f - 512.0f) / var2) + 1.0f)); + + return calc_gas_res; +} + +/* This internal API is used to calculate the gas resistance value in float */ +static float calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range) +{ + float calc_gas_res; + uint32_t var1 = UINT32_C(262144) >> gas_range; + int32_t var2 = (int32_t)gas_res_adc - INT32_C(512); + + var2 *= INT32_C(3); + var2 = INT32_C(4096) + var2; + + calc_gas_res = 1000000.0f * (float)var1 / (float)var2; + + return calc_gas_res; +} + +/* This internal API is used to calculate the heater resistance value */ +static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev) +{ + float var1; + float var2; + float var3; + float var4; + float var5; + uint8_t res_heat; + + if (temp > 400) /* Cap temperature */ + { + temp = 400; + } + + var1 = (((float)dev->calib.par_gh1 / (16.0f)) + 49.0f); + var2 = ((((float)dev->calib.par_gh2 / (32768.0f)) * (0.0005f)) + 0.00235f); + var3 = ((float)dev->calib.par_gh3 / (1024.0f)); + var4 = (var1 * (1.0f + (var2 * (float)temp))); + var5 = (var4 + (var3 * (float)dev->amb_temp)); + res_heat = + (uint8_t)(3.4f * + ((var5 * (4 / (4 + (float)dev->calib.res_heat_range)) * + (1 / (1 + ((float)dev->calib.res_heat_val * 0.002f)))) - + 25)); + + return res_heat; +} + +#endif + +/* This internal API is used to calculate the gas wait */ +static uint8_t calc_gas_wait(uint16_t dur) +{ + uint8_t factor = 0; + uint8_t durval; + + if (dur >= 0xfc0) + { + durval = 0xff; /* Max duration*/ + } + else + { + while (dur > 0x3F) + { + dur = dur / 4; + factor += 1; + } + + durval = (uint8_t)(dur + (factor * 64)); + } + + return durval; +} + +/* This internal API is used to read a single data of the sensor */ +static int8_t read_field_data(uint8_t index, struct bme68x_data *data, struct bme68x_dev *dev) +{ + int8_t rslt = BME68X_OK; + uint8_t buff[BME68X_LEN_FIELD] = { 0 }; + uint8_t gas_range_l, gas_range_h; + uint32_t adc_temp; + uint32_t adc_pres; + uint16_t adc_hum; + uint16_t adc_gas_res_low, adc_gas_res_high; + uint8_t tries = 5; + + while ((tries) && (rslt == BME68X_OK)) + { + rslt = bme68x_get_regs(((uint8_t)(BME68X_REG_FIELD0 + (index * BME68X_LEN_FIELD_OFFSET))), + buff, + (uint16_t)BME68X_LEN_FIELD, + dev); + if (!data) + { + rslt = BME68X_E_NULL_PTR; + break; + } + + data->status = buff[0] & BME68X_NEW_DATA_MSK; + data->gas_index = buff[0] & BME68X_GAS_INDEX_MSK; + data->meas_index = buff[1]; + + /* read the raw data from the sensor */ + adc_pres = (uint32_t)(((uint32_t)buff[2] * 4096) | ((uint32_t)buff[3] * 16) | ((uint32_t)buff[4] / 16)); + adc_temp = (uint32_t)(((uint32_t)buff[5] * 4096) | ((uint32_t)buff[6] * 16) | ((uint32_t)buff[7] / 16)); + adc_hum = (uint16_t)(((uint32_t)buff[8] * 256) | (uint32_t)buff[9]); + adc_gas_res_low = (uint16_t)((uint32_t)buff[13] * 4 | (((uint32_t)buff[14]) / 64)); + adc_gas_res_high = (uint16_t)((uint32_t)buff[15] * 4 | (((uint32_t)buff[16]) / 64)); + gas_range_l = buff[14] & BME68X_GAS_RANGE_MSK; + gas_range_h = buff[16] & BME68X_GAS_RANGE_MSK; + if (dev->variant_id == BME68X_VARIANT_GAS_HIGH) + { + data->status |= buff[16] & BME68X_GASM_VALID_MSK; + data->status |= buff[16] & BME68X_HEAT_STAB_MSK; + } + else + { + data->status |= buff[14] & BME68X_GASM_VALID_MSK; + data->status |= buff[14] & BME68X_HEAT_STAB_MSK; + } + + if ((data->status & BME68X_NEW_DATA_MSK) && (rslt == BME68X_OK)) + { + rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0 + data->gas_index, &data->res_heat, 1, dev); + if (rslt == BME68X_OK) + { + rslt = bme68x_get_regs(BME68X_REG_IDAC_HEAT0 + data->gas_index, &data->idac, 1, dev); + } + + if (rslt == BME68X_OK) + { + rslt = bme68x_get_regs(BME68X_REG_GAS_WAIT0 + data->gas_index, &data->gas_wait, 1, dev); + } + + if (rslt == BME68X_OK) + { + data->temperature = calc_temperature(adc_temp, dev); + data->pressure = calc_pressure(adc_pres, dev); + data->humidity = calc_humidity(adc_hum, dev); + if (dev->variant_id == BME68X_VARIANT_GAS_HIGH) + { + data->gas_resistance = calc_gas_resistance_high(adc_gas_res_high, gas_range_h); + } + else + { + data->gas_resistance = calc_gas_resistance_low(adc_gas_res_low, gas_range_l, dev); + } + + break; + } + } + + if (rslt == BME68X_OK) + { + dev->delay_us(BME68X_PERIOD_POLL, dev->intf_ptr); + } + + tries--; + } + + return rslt; +} + +/* This internal API is used to read all data fields of the sensor */ +static int8_t read_all_field_data(struct bme68x_data * const data[], struct bme68x_dev *dev) +{ + int8_t rslt = BME68X_OK; + uint8_t buff[BME68X_LEN_FIELD * 3] = { 0 }; + uint8_t gas_range_l, gas_range_h; + uint32_t adc_temp; + uint32_t adc_pres; + uint16_t adc_hum; + uint16_t adc_gas_res_low, adc_gas_res_high; + uint8_t off; + uint8_t set_val[30] = { 0 }; /* idac, res_heat, gas_wait */ + uint8_t i; + + if (!data[0] && !data[1] && !data[2]) + { + rslt = BME68X_E_NULL_PTR; + } + + if (rslt == BME68X_OK) + { + rslt = bme68x_get_regs(BME68X_REG_FIELD0, buff, (uint32_t) BME68X_LEN_FIELD * 3, dev); + } + + if (rslt == BME68X_OK) + { + rslt = bme68x_get_regs(BME68X_REG_IDAC_HEAT0, set_val, 30, dev); + } + + for (i = 0; ((i < 3) && (rslt == BME68X_OK)); i++) + { + off = (uint8_t)(i * BME68X_LEN_FIELD); + data[i]->status = buff[off] & BME68X_NEW_DATA_MSK; + data[i]->gas_index = buff[off] & BME68X_GAS_INDEX_MSK; + data[i]->meas_index = buff[off + 1]; + + /* read the raw data from the sensor */ + adc_pres = + (uint32_t) (((uint32_t) buff[off + 2] * 4096) | ((uint32_t) buff[off + 3] * 16) | + ((uint32_t) buff[off + 4] / 16)); + adc_temp = + (uint32_t) (((uint32_t) buff[off + 5] * 4096) | ((uint32_t) buff[off + 6] * 16) | + ((uint32_t) buff[off + 7] / 16)); + adc_hum = (uint16_t) (((uint32_t) buff[off + 8] * 256) | (uint32_t) buff[off + 9]); + adc_gas_res_low = (uint16_t) ((uint32_t) buff[off + 13] * 4 | (((uint32_t) buff[off + 14]) / 64)); + adc_gas_res_high = (uint16_t) ((uint32_t) buff[off + 15] * 4 | (((uint32_t) buff[off + 16]) / 64)); + gas_range_l = buff[off + 14] & BME68X_GAS_RANGE_MSK; + gas_range_h = buff[off + 16] & BME68X_GAS_RANGE_MSK; + if (dev->variant_id == BME68X_VARIANT_GAS_HIGH) + { + data[i]->status |= buff[off + 16] & BME68X_GASM_VALID_MSK; + data[i]->status |= buff[off + 16] & BME68X_HEAT_STAB_MSK; + } + else + { + data[i]->status |= buff[off + 14] & BME68X_GASM_VALID_MSK; + data[i]->status |= buff[off + 14] & BME68X_HEAT_STAB_MSK; + } + + data[i]->idac = set_val[data[i]->gas_index]; + data[i]->res_heat = set_val[10 + data[i]->gas_index]; + data[i]->gas_wait = set_val[20 + data[i]->gas_index]; + data[i]->temperature = calc_temperature(adc_temp, dev); + data[i]->pressure = calc_pressure(adc_pres, dev); + data[i]->humidity = calc_humidity(adc_hum, dev); + if (dev->variant_id == BME68X_VARIANT_GAS_HIGH) + { + data[i]->gas_resistance = calc_gas_resistance_high(adc_gas_res_high, gas_range_h); + } + else + { + data[i]->gas_resistance = calc_gas_resistance_low(adc_gas_res_low, gas_range_l, dev); + } + } + + return rslt; +} + +/* This internal API is used to switch between SPI memory pages */ +static int8_t set_mem_page(uint8_t reg_addr, struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t reg; + uint8_t mem_page; + + /* Check for null pointers in the device structure*/ + rslt = null_ptr_check(dev); + if (rslt == BME68X_OK) + { + if (reg_addr > 0x7f) + { + mem_page = BME68X_MEM_PAGE1; + } + else + { + mem_page = BME68X_MEM_PAGE0; + } + + if (mem_page != dev->mem_page) + { + dev->mem_page = mem_page; + dev->intf_rslt = dev->read(BME68X_REG_MEM_PAGE | BME68X_SPI_RD_MSK, ®, 1, dev->intf_ptr); + if (dev->intf_rslt != 0) + { + rslt = BME68X_E_COM_FAIL; + } + + if (rslt == BME68X_OK) + { + reg = reg & (~BME68X_MEM_PAGE_MSK); + reg = reg | (dev->mem_page & BME68X_MEM_PAGE_MSK); + dev->intf_rslt = dev->write(BME68X_REG_MEM_PAGE & BME68X_SPI_WR_MSK, ®, 1, dev->intf_ptr); + if (dev->intf_rslt != 0) + { + rslt = BME68X_E_COM_FAIL; + } + } + } + } + + return rslt; +} + +/* This internal API is used to get the current SPI memory page */ +static int8_t get_mem_page(struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t reg; + + /* Check for null pointer in the device structure*/ + rslt = null_ptr_check(dev); + if (rslt == BME68X_OK) + { + dev->intf_rslt = dev->read(BME68X_REG_MEM_PAGE | BME68X_SPI_RD_MSK, ®, 1, dev->intf_ptr); + if (dev->intf_rslt != 0) + { + rslt = BME68X_E_COM_FAIL; + } + else + { + dev->mem_page = reg & BME68X_MEM_PAGE_MSK; + } + } + + return rslt; +} + +/* This internal API is used to limit the max value of a parameter */ +static int8_t boundary_check(uint8_t *value, uint8_t max, struct bme68x_dev *dev) +{ + int8_t rslt; + + rslt = null_ptr_check(dev); + if ((value != NULL) && (rslt == BME68X_OK)) + { + /* Check if value is above maximum value */ + if (*value > max) + { + /* Auto correct the invalid value to maximum value */ + *value = max; + dev->info_msg |= BME68X_I_PARAM_CORR; + } + } + else + { + rslt = BME68X_E_NULL_PTR; + } + + return rslt; +} + +/* This internal API is used to check the bme68x_dev for null pointers */ +static int8_t null_ptr_check(const struct bme68x_dev *dev) +{ + int8_t rslt = BME68X_OK; + + if ((dev == NULL) || (dev->read == NULL) || (dev->write == NULL) || (dev->delay_us == NULL)) + { + /* Device structure pointer is not valid */ + rslt = BME68X_E_NULL_PTR; + } + + return rslt; +} + +/* This internal API is used to set heater configurations */ +static int8_t set_conf(const struct bme68x_heatr_conf *conf, uint8_t op_mode, uint8_t *nb_conv, struct bme68x_dev *dev) +{ + int8_t rslt = BME68X_OK; + uint8_t i; + uint8_t shared_dur; + uint8_t write_len = 0; + uint8_t heater_dur_shared_addr = BME68X_REG_SHD_HEATR_DUR; + uint8_t rh_reg_addr[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + uint8_t rh_reg_data[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + uint8_t gw_reg_addr[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + uint8_t gw_reg_data[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + switch (op_mode) + { + case BME68X_FORCED_MODE: + rh_reg_addr[0] = BME68X_REG_RES_HEAT0; + rh_reg_data[0] = calc_res_heat(conf->heatr_temp, dev); + gw_reg_addr[0] = BME68X_REG_GAS_WAIT0; + gw_reg_data[0] = calc_gas_wait(conf->heatr_dur); + (*nb_conv) = 0; + write_len = 1; + break; + case BME68X_SEQUENTIAL_MODE: + if ((!conf->heatr_dur_prof) || (!conf->heatr_temp_prof)) + { + rslt = BME68X_E_NULL_PTR; + break; + } + + for (i = 0; i < conf->profile_len; i++) + { + rh_reg_addr[i] = BME68X_REG_RES_HEAT0 + i; + rh_reg_data[i] = calc_res_heat(conf->heatr_temp_prof[i], dev); + gw_reg_addr[i] = BME68X_REG_GAS_WAIT0 + i; + gw_reg_data[i] = calc_gas_wait(conf->heatr_dur_prof[i]); + } + + (*nb_conv) = conf->profile_len; + write_len = conf->profile_len; + break; + case BME68X_PARALLEL_MODE: + if ((!conf->heatr_dur_prof) || (!conf->heatr_temp_prof)) + { + rslt = BME68X_E_NULL_PTR; + break; + } + + if (conf->shared_heatr_dur == 0) + { + rslt = BME68X_W_DEFINE_SHD_HEATR_DUR; + } + + for (i = 0; i < conf->profile_len; i++) + { + rh_reg_addr[i] = BME68X_REG_RES_HEAT0 + i; + rh_reg_data[i] = calc_res_heat(conf->heatr_temp_prof[i], dev); + gw_reg_addr[i] = BME68X_REG_GAS_WAIT0 + i; + gw_reg_data[i] = (uint8_t) conf->heatr_dur_prof[i]; + } + + (*nb_conv) = conf->profile_len; + write_len = conf->profile_len; + shared_dur = calc_heatr_dur_shared(conf->shared_heatr_dur); + if (rslt == BME68X_OK) + { + rslt = bme68x_set_regs(&heater_dur_shared_addr, &shared_dur, 1, dev); + } + + break; + default: + rslt = BME68X_W_DEFINE_OP_MODE; + } + + if (rslt == BME68X_OK) + { + rslt = bme68x_set_regs(rh_reg_addr, rh_reg_data, write_len, dev); + } + + if (rslt == BME68X_OK) + { + rslt = bme68x_set_regs(gw_reg_addr, gw_reg_data, write_len, dev); + } + + return rslt; +} + +/* This internal API is used to calculate the register value for + * shared heater duration */ +static uint8_t calc_heatr_dur_shared(uint16_t dur) +{ + uint8_t factor = 0; + uint8_t heatdurval; + + if (dur >= 0x783) + { + heatdurval = 0xff; /* Max duration */ + } + else + { + /* Step size of 0.477ms */ + dur = (uint16_t)(((uint32_t)dur * 1000) / 477); + while (dur > 0x3F) + { + dur = dur >> 2; + factor += 1; + } + + heatdurval = (uint8_t)(dur + (factor * 64)); + } + + return heatdurval; +} + +/* This internal API is used sort the sensor data */ +static void sort_sensor_data(uint8_t low_index, uint8_t high_index, struct bme68x_data *field[]) +{ + int16_t meas_index1; + int16_t meas_index2; + + meas_index1 = (int16_t)field[low_index]->meas_index; + meas_index2 = (int16_t)field[high_index]->meas_index; + if ((field[low_index]->status & BME68X_NEW_DATA_MSK) && (field[high_index]->status & BME68X_NEW_DATA_MSK)) + { + int16_t diff = meas_index2 - meas_index1; + if (((diff > -3) && (diff < 0)) || (diff > 2)) + { + swap_fields(low_index, high_index, field); + } + } + else if (field[high_index]->status & BME68X_NEW_DATA_MSK) + { + swap_fields(low_index, high_index, field); + } + + /* Sorting field data + * + * The 3 fields are filled in a fixed order with data in an incrementing + * 8-bit sub-measurement index which looks like + * Field index | Sub-meas index + * 0 | 0 + * 1 | 1 + * 2 | 2 + * 0 | 3 + * 1 | 4 + * 2 | 5 + * ... + * 0 | 252 + * 1 | 253 + * 2 | 254 + * 0 | 255 + * 1 | 0 + * 2 | 1 + * + * The fields are sorted in a way so as to always deal with only a snapshot + * of comparing 2 fields at a time. The order being + * field0 & field1 + * field0 & field2 + * field1 & field2 + * Here the oldest data should be in field0 while the newest is in field2. + * In the following documentation, field0's position would referred to as + * the lowest and field2 as the highest. + * + * In order to sort we have to consider the following cases, + * + * Case A: No fields have new data + * Then do not sort, as this data has already been read. + * + * Case B: Higher field has new data + * Then the new field get's the lowest position. + * + * Case C: Both fields have new data + * We have to put the oldest sample in the lowest position. Since the + * sub-meas index contains in essence the age of the sample, we calculate + * the difference between the higher field and the lower field. + * Here we have 3 sub-cases, + * Case 1: Regular read without overwrite + * Field index | Sub-meas index + * 0 | 3 + * 1 | 4 + * + * Field index | Sub-meas index + * 0 | 3 + * 2 | 5 + * + * The difference is always <= 2. There is no need to swap as the + * oldest sample is already in the lowest position. + * + * Case 2: Regular read with an overflow and without an overwrite + * Field index | Sub-meas index + * 0 | 255 + * 1 | 0 + * + * Field index | Sub-meas index + * 0 | 254 + * 2 | 0 + * + * The difference is always <= -3. There is no need to swap as the + * oldest sample is already in the lowest position. + * + * Case 3: Regular read with overwrite + * Field index | Sub-meas index + * 0 | 6 + * 1 | 4 + * + * Field index | Sub-meas index + * 0 | 6 + * 2 | 5 + * + * The difference is always > -3. There is a need to swap as the + * oldest sample is not in the lowest position. + * + * Case 4: Regular read with overwrite and overflow + * Field index | Sub-meas index + * 0 | 0 + * 1 | 254 + * + * Field index | Sub-meas index + * 0 | 0 + * 2 | 255 + * + * The difference is always > 2. There is a need to swap as the + * oldest sample is not in the lowest position. + * + * To summarize, we have to swap when + * - The higher field has new data and the lower field does not. + * - If both fields have new data, then the difference of sub-meas index + * between the higher field and the lower field creates the + * following condition for swapping. + * - (diff > -3) && (diff < 0), combination of cases 1, 2, and 3. + * - diff > 2, case 4. + * + * Here the limits of -3 and 2 derive from the fact that there are 3 fields. + * These values decrease or increase respectively if the number of fields increases. + */ +} + +/* This internal API is used sort the sensor data */ +static void swap_fields(uint8_t index1, uint8_t index2, struct bme68x_data *field[]) +{ + struct bme68x_data *temp; + + temp = field[index1]; + field[index1] = field[index2]; + field[index2] = temp; +} + +/* This Function is to analyze the sensor data */ +static int8_t analyze_sensor_data(const struct bme68x_data *data, uint8_t n_meas) +{ + int8_t rslt = BME68X_OK; + uint8_t self_test_failed = 0, i; + uint32_t cent_res = 0; + + if ((data[0].temperature < BME68X_MIN_TEMPERATURE) || (data[0].temperature > BME68X_MAX_TEMPERATURE)) + { + self_test_failed++; + } + + if ((data[0].pressure < BME68X_MIN_PRESSURE) || (data[0].pressure > BME68X_MAX_PRESSURE)) + { + self_test_failed++; + } + + if ((data[0].humidity < BME68X_MIN_HUMIDITY) || (data[0].humidity > BME68X_MAX_HUMIDITY)) + { + self_test_failed++; + } + + for (i = 0; i < n_meas; i++) /* Every gas measurement should be valid */ + { + if (!(data[i].status & BME68X_GASM_VALID_MSK)) + { + self_test_failed++; + } + } + + if (n_meas >= 6) + { + cent_res = (uint32_t)((5 * (data[3].gas_resistance + data[5].gas_resistance)) / (2 * data[4].gas_resistance)); + } + + if (cent_res < 6) + { + self_test_failed++; + } + + if (self_test_failed) + { + rslt = BME68X_E_SELF_TEST; + } + + return rslt; +} + +/* This internal API is used to read the calibration coefficients */ +static int8_t get_calib_data(struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t coeff_array[BME68X_LEN_COEFF_ALL]; + + rslt = bme68x_get_regs(BME68X_REG_COEFF1, coeff_array, BME68X_LEN_COEFF1, dev); + if (rslt == BME68X_OK) + { + rslt = bme68x_get_regs(BME68X_REG_COEFF2, &coeff_array[BME68X_LEN_COEFF1], BME68X_LEN_COEFF2, dev); + } + + if (rslt == BME68X_OK) + { + rslt = bme68x_get_regs(BME68X_REG_COEFF3, + &coeff_array[BME68X_LEN_COEFF1 + BME68X_LEN_COEFF2], + BME68X_LEN_COEFF3, + dev); + } + + if (rslt == BME68X_OK) + { + /* Temperature related coefficients */ + dev->calib.par_t1 = + (uint16_t)(BME68X_CONCAT_BYTES(coeff_array[BME68X_IDX_T1_MSB], coeff_array[BME68X_IDX_T1_LSB])); + dev->calib.par_t2 = + (int16_t)(BME68X_CONCAT_BYTES(coeff_array[BME68X_IDX_T2_MSB], coeff_array[BME68X_IDX_T2_LSB])); + dev->calib.par_t3 = (int8_t)(coeff_array[BME68X_IDX_T3]); + + /* Pressure related coefficients */ + dev->calib.par_p1 = + (uint16_t)(BME68X_CONCAT_BYTES(coeff_array[BME68X_IDX_P1_MSB], coeff_array[BME68X_IDX_P1_LSB])); + dev->calib.par_p2 = + (int16_t)(BME68X_CONCAT_BYTES(coeff_array[BME68X_IDX_P2_MSB], coeff_array[BME68X_IDX_P2_LSB])); + dev->calib.par_p3 = (int8_t)coeff_array[BME68X_IDX_P3]; + dev->calib.par_p4 = + (int16_t)(BME68X_CONCAT_BYTES(coeff_array[BME68X_IDX_P4_MSB], coeff_array[BME68X_IDX_P4_LSB])); + dev->calib.par_p5 = + (int16_t)(BME68X_CONCAT_BYTES(coeff_array[BME68X_IDX_P5_MSB], coeff_array[BME68X_IDX_P5_LSB])); + dev->calib.par_p6 = (int8_t)(coeff_array[BME68X_IDX_P6]); + dev->calib.par_p7 = (int8_t)(coeff_array[BME68X_IDX_P7]); + dev->calib.par_p8 = + (int16_t)(BME68X_CONCAT_BYTES(coeff_array[BME68X_IDX_P8_MSB], coeff_array[BME68X_IDX_P8_LSB])); + dev->calib.par_p9 = + (int16_t)(BME68X_CONCAT_BYTES(coeff_array[BME68X_IDX_P9_MSB], coeff_array[BME68X_IDX_P9_LSB])); + dev->calib.par_p10 = (uint8_t)(coeff_array[BME68X_IDX_P10]); + + /* Humidity related coefficients */ + dev->calib.par_h1 = + (uint16_t)(((uint16_t)coeff_array[BME68X_IDX_H1_MSB] << 4) | + (coeff_array[BME68X_IDX_H1_LSB] & BME68X_BIT_H1_DATA_MSK)); + dev->calib.par_h2 = + (uint16_t)(((uint16_t)coeff_array[BME68X_IDX_H2_MSB] << 4) | ((coeff_array[BME68X_IDX_H2_LSB]) >> 4)); + dev->calib.par_h3 = (int8_t)coeff_array[BME68X_IDX_H3]; + dev->calib.par_h4 = (int8_t)coeff_array[BME68X_IDX_H4]; + dev->calib.par_h5 = (int8_t)coeff_array[BME68X_IDX_H5]; + dev->calib.par_h6 = (uint8_t)coeff_array[BME68X_IDX_H6]; + dev->calib.par_h7 = (int8_t)coeff_array[BME68X_IDX_H7]; + + /* Gas heater related coefficients */ + dev->calib.par_gh1 = (int8_t)coeff_array[BME68X_IDX_GH1]; + dev->calib.par_gh2 = + (int16_t)(BME68X_CONCAT_BYTES(coeff_array[BME68X_IDX_GH2_MSB], coeff_array[BME68X_IDX_GH2_LSB])); + dev->calib.par_gh3 = (int8_t)coeff_array[BME68X_IDX_GH3]; + + /* Other coefficients */ + dev->calib.res_heat_range = ((coeff_array[BME68X_IDX_RES_HEAT_RANGE] & BME68X_RHRANGE_MSK) / 16); + dev->calib.res_heat_val = (int8_t)coeff_array[BME68X_IDX_RES_HEAT_VAL]; + dev->calib.range_sw_err = ((int8_t)(coeff_array[BME68X_IDX_RANGE_SW_ERR] & BME68X_RSERROR_MSK)) / 16; + } + + return rslt; +} + +/* This internal API is used to read variant ID information from the register */ +static int8_t read_variant_id(struct bme68x_dev *dev) +{ + int8_t rslt; + uint8_t reg_data = 0; + + /* Read variant ID information register */ + rslt = bme68x_get_regs(BME68X_REG_VARIANT_ID, ®_data, 1, dev); + + if (rslt == BME68X_OK) + { + dev->variant_id = reg_data; + } + + return rslt; +} diff --git a/components/BME68x/src/bme68x/bme68x.h b/components/BME68x/src/bme68x/bme68x.h new file mode 100755 index 0000000..e6d4828 --- /dev/null +++ b/components/BME68x/src/bme68x/bme68x.h @@ -0,0 +1,323 @@ +/** +* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bme68x.h +* @date 2021-11-09 +* @version v4.4.7 +* +*/ + +/*! + * @defgroup bme68x BME68X + * @brief Product Overview + * and Sensor API Source Code + */ + +#ifndef BME68X_H_ +#define BME68X_H_ + +#include "bme68x_defs.h" + +/* CPP guard */ +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \ingroup bme68x + * \defgroup bme68xApiInit Initialization + * @brief Initialize the sensor and device structure + */ + +/*! + * \ingroup bme68xApiInit + * \page bme68x_api_bme68x_init bme68x_init + * \code + * int8_t bme68x_init(struct bme68x_dev *dev); + * \endcode + * @details This API reads the chip-id of the sensor which is the first step to + * verify the sensor and also calibrates the sensor + * As this API is the entry point, call this API before using other APIs. + * + * @param[in,out] dev : Structure instance of bme68x_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_init(struct bme68x_dev *dev); + +/** + * \ingroup bme68x + * \defgroup bme68xApiRegister Registers + * @brief Generic API for accessing sensor registers + */ + +/*! + * \ingroup bme68xApiRegister + * \page bme68x_api_bme68x_set_regs bme68x_set_regs + * \code + * int8_t bme68x_set_regs(const uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, struct bme68x_dev *dev) + * \endcode + * @details This API writes the given data to the register address of the sensor + * + * @param[in] reg_addr : Register addresses to where the data is to be written + * @param[in] reg_data : Pointer to data buffer which is to be written + * in the reg_addr of sensor. + * @param[in] len : No of bytes of data to write + * @param[in,out] dev : Structure instance of bme68x_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_set_regs(const uint8_t *reg_addr, const uint8_t *reg_data, uint32_t len, struct bme68x_dev *dev); + +/*! + * \ingroup bme68xApiRegister + * \page bme68x_api_bme68x_get_regs bme68x_get_regs + * \code + * int8_t bme68x_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bme68x_dev *dev) + * \endcode + * @details This API reads the data from the given register address of sensor. + * + * @param[in] reg_addr : Register address from where the data to be read + * @param[out] reg_data : Pointer to data buffer to store the read data. + * @param[in] len : No of bytes of data to be read. + * @param[in,out] dev : Structure instance of bme68x_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, struct bme68x_dev *dev); + +/** + * \ingroup bme68x + * \defgroup bme68xApiSystem System + * @brief API that performs system-level operations + */ + +/*! + * \ingroup bme68xApiSystem + * \page bme68x_api_bme68x_soft_reset bme68x_soft_reset + * \code + * int8_t bme68x_soft_reset(struct bme68x_dev *dev); + * \endcode + * @details This API soft-resets the sensor. + * + * @param[in,out] dev : Structure instance of bme68x_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_soft_reset(struct bme68x_dev *dev); + +/** + * \ingroup bme68x + * \defgroup bme68xApiOm Operation mode + * @brief API to configure operation mode + */ + +/*! + * \ingroup bme68xApiOm + * \page bme68x_api_bme68x_set_op_mode bme68x_set_op_mode + * \code + * int8_t bme68x_set_op_mode(const uint8_t op_mode, struct bme68x_dev *dev); + * \endcode + * @details This API is used to set the operation mode of the sensor + * @param[in] op_mode : Desired operation mode. + * @param[in] dev : Structure instance of bme68x_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_set_op_mode(const uint8_t op_mode, struct bme68x_dev *dev); + +/*! + * \ingroup bme68xApiOm + * \page bme68x_api_bme68x_get_op_mode bme68x_get_op_mode + * \code + * int8_t bme68x_get_op_mode(uint8_t *op_mode, struct bme68x_dev *dev); + * \endcode + * @details This API is used to get the operation mode of the sensor. + * + * @param[out] op_mode : Desired operation mode. + * @param[in,out] dev : Structure instance of bme68x_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_get_op_mode(uint8_t *op_mode, struct bme68x_dev *dev); + +/*! + * \ingroup bme68xApiConfig + * \page bme68x_api_bme68x_get_meas_dur bme68x_get_meas_dur + * \code + * uint32_t bme68x_get_meas_dur(const uint8_t op_mode, struct bme68x_conf *conf, struct bme68x_dev *dev); + * \endcode + * @details This API is used to get the remaining duration that can be used for heating. + * + * @param[in] op_mode : Desired operation mode. + * @param[in] conf : Desired sensor configuration. + * @param[in] dev : Structure instance of bme68x_dev + * + * @return Measurement duration calculated in microseconds + */ +uint32_t bme68x_get_meas_dur(const uint8_t op_mode, struct bme68x_conf *conf, struct bme68x_dev *dev); + +/** + * \ingroup bme68x + * \defgroup bme68xApiData Data Read out + * @brief Read our data from the sensor + */ + +/*! + * \ingroup bme68xApiData + * \page bme68x_api_bme68x_get_data bme68x_get_data + * \code + * int8_t bme68x_get_data(uint8_t op_mode, struct bme68x_data *data, uint8_t *n_data, struct bme68x_dev *dev); + * \endcode + * @details This API reads the pressure, temperature and humidity and gas data + * from the sensor, compensates the data and store it in the bme68x_data + * structure instance passed by the user. + * + * @param[in] op_mode : Expected operation mode. + * @param[out] data : Structure instance to hold the data. + * @param[out] n_data : Number of data instances available. + * @param[in,out] dev : Structure instance of bme68x_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_get_data(uint8_t op_mode, struct bme68x_data *data, uint8_t *n_data, struct bme68x_dev *dev); + +/** + * \ingroup bme68x + * \defgroup bme68xApiConfig Configuration + * @brief Configuration API of sensor + */ + +/*! + * \ingroup bme68xApiConfig + * \page bme68x_api_bme68x_set_conf bme68x_set_conf + * \code + * int8_t bme68x_set_conf(struct bme68x_conf *conf, struct bme68x_dev *dev); + * \endcode + * @details This API is used to set the oversampling, filter and odr configuration + * + * @param[in] conf : Desired sensor configuration. + * @param[in,out] dev : Structure instance of bme68x_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_set_conf(struct bme68x_conf *conf, struct bme68x_dev *dev); + +/*! + * \ingroup bme68xApiConfig + * \page bme68x_api_bme68x_get_conf bme68x_get_conf + * \code + * int8_t bme68x_get_conf(struct bme68x_conf *conf, struct bme68x_dev *dev); + * \endcode + * @details This API is used to get the oversampling, filter and odr + * configuration + * + * @param[out] conf : Present sensor configuration. + * @param[in,out] dev : Structure instance of bme68x_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_get_conf(struct bme68x_conf *conf, struct bme68x_dev *dev); + +/*! + * \ingroup bme68xApiConfig + * \page bme68x_api_bme68x_set_heatr_conf bme68x_set_heatr_conf + * \code + * int8_t bme68x_set_heatr_conf(uint8_t op_mode, const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev); + * \endcode + * @details This API is used to set the gas configuration of the sensor. + * + * @param[in] op_mode : Expected operation mode of the sensor. + * @param[in] conf : Desired heating configuration. + * @param[in,out] dev : Structure instance of bme68x_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_set_heatr_conf(uint8_t op_mode, const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev); + +/*! + * \ingroup bme68xApiConfig + * \page bme68x_api_bme68x_get_heatr_conf bme68x_get_heatr_conf + * \code + * int8_t bme68x_get_heatr_conf(const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev); + * \endcode + * @details This API is used to get the gas configuration of the sensor. + * + * @param[out] conf : Current configurations of the gas sensor. + * @param[in,out] dev : Structure instance of bme68x_dev. + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_get_heatr_conf(const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev); + +/*! + * \ingroup bme68xApiSystem + * \page bme68x_api_bme68x_selftest_check bme68x_selftest_check + * \code + * int8_t bme68x_selftest_check(const struct bme68x_dev *dev); + * \endcode + * @details This API performs Self-test of low gas variant of BME68X + * + * @param[in, out] dev : Structure instance of bme68x_dev + * + * @return Result of API execution status + * @retval 0 -> Success + * @retval < 0 -> Fail + */ +int8_t bme68x_selftest_check(const struct bme68x_dev *dev); + +#ifdef __cplusplus +} +#endif /* End of CPP guard */ +#endif /* BME68X_H_ */ diff --git a/components/BME68x/src/bme68x/bme68x_defs.h b/components/BME68x/src/bme68x/bme68x_defs.h new file mode 100755 index 0000000..861b2f7 --- /dev/null +++ b/components/BME68x/src/bme68x/bme68x_defs.h @@ -0,0 +1,972 @@ +/** +* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bme68x_defs.h +* @date 2021-11-09 +* @version v4.4.7 +* +*/ + +/*! @cond DOXYGEN_SUPRESS */ + +#ifndef BME68X_DEFS_H_ +#define BME68X_DEFS_H_ + +/********************************************************* */ +/*! Header includes */ +/********************************************************* */ +#ifdef __KERNEL__ +#include +#include +#else +#include +#include +#endif + +/********************************************************* */ +/*! Common Macros */ +/********************************************************* */ +#ifdef __KERNEL__ +#if !defined(UINT8_C) && !defined(INT8_C) +#define INT8_C(x) S8_C(x) +#define UINT8_C(x) U8_C(x) +#endif + +#if !defined(UINT16_C) && !defined(INT16_C) +#define INT16_C(x) S16_C(x) +#define UINT16_C(x) U16_C(x) +#endif + +#if !defined(INT32_C) && !defined(UINT32_C) +#define INT32_C(x) S32_C(x) +#define UINT32_C(x) U32_C(x) +#endif + +#if !defined(INT64_C) && !defined(UINT64_C) +#define INT64_C(x) S64_C(x) +#define UINT64_C(x) U64_C(x) +#endif +#endif + +/*! C standard macros */ +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void *) 0) +#endif +#endif + +#ifndef BME68X_DO_NOT_USE_FPU + +/* Comment or un-comment the macro to provide floating point data output */ +#define BME68X_USE_FPU +#endif + +/* Period between two polls (value can be given by user) */ +#ifndef BME68X_PERIOD_POLL +#define BME68X_PERIOD_POLL UINT32_C(10000) +#endif + +/* BME68X unique chip identifier */ +#define BME68X_CHIP_ID UINT8_C(0x61) + +/* Period for a soft reset */ +#define BME68X_PERIOD_RESET UINT32_C(10000) + +/* BME68X lower I2C address */ +#define BME68X_I2C_ADDR_LOW UINT8_C(0x76) + +/* BME68X higher I2C address */ +#define BME68X_I2C_ADDR_HIGH UINT8_C(0x77) + +/* Soft reset command */ +#define BME68X_SOFT_RESET_CMD UINT8_C(0xb6) + +/* Return code definitions */ +/* Success */ +#define BME68X_OK INT8_C(0) + +/* Errors */ +/* Null pointer passed */ +#define BME68X_E_NULL_PTR INT8_C(-1) + +/* Communication failure */ +#define BME68X_E_COM_FAIL INT8_C(-2) + +/* Sensor not found */ +#define BME68X_E_DEV_NOT_FOUND INT8_C(-3) + +/* Incorrect length parameter */ +#define BME68X_E_INVALID_LENGTH INT8_C(-4) + +/* Self test fail error */ +#define BME68X_E_SELF_TEST INT8_C(-5) + +/* Warnings */ +/* Define a valid operation mode */ +#define BME68X_W_DEFINE_OP_MODE INT8_C(1) + +/* No new data was found */ +#define BME68X_W_NO_NEW_DATA INT8_C(2) + +/* Define the shared heating duration */ +#define BME68X_W_DEFINE_SHD_HEATR_DUR INT8_C(3) + +/* Information - only available via bme68x_dev.info_msg */ +#define BME68X_I_PARAM_CORR UINT8_C(1) + +/* Register map addresses in I2C */ +/* Register for 3rd group of coefficients */ +#define BME68X_REG_COEFF3 UINT8_C(0x00) + +/* 0th Field address*/ +#define BME68X_REG_FIELD0 UINT8_C(0x1d) + +/* 0th Current DAC address*/ +#define BME68X_REG_IDAC_HEAT0 UINT8_C(0x50) + +/* 0th Res heat address */ +#define BME68X_REG_RES_HEAT0 UINT8_C(0x5a) + +/* 0th Gas wait address */ +#define BME68X_REG_GAS_WAIT0 UINT8_C(0x64) + +/* Shared heating duration address */ +#define BME68X_REG_SHD_HEATR_DUR UINT8_C(0x6E) + +/* CTRL_GAS_0 address */ +#define BME68X_REG_CTRL_GAS_0 UINT8_C(0x70) + +/* CTRL_GAS_1 address */ +#define BME68X_REG_CTRL_GAS_1 UINT8_C(0x71) + +/* CTRL_HUM address */ +#define BME68X_REG_CTRL_HUM UINT8_C(0x72) + +/* CTRL_MEAS address */ +#define BME68X_REG_CTRL_MEAS UINT8_C(0x74) + +/* CONFIG address */ +#define BME68X_REG_CONFIG UINT8_C(0x75) + +/* MEM_PAGE address */ +#define BME68X_REG_MEM_PAGE UINT8_C(0xf3) + +/* Unique ID address */ +#define BME68X_REG_UNIQUE_ID UINT8_C(0x83) + +/* Register for 1st group of coefficients */ +#define BME68X_REG_COEFF1 UINT8_C(0x8a) + +/* Chip ID address */ +#define BME68X_REG_CHIP_ID UINT8_C(0xd0) + +/* Soft reset address */ +#define BME68X_REG_SOFT_RESET UINT8_C(0xe0) + +/* Register for 2nd group of coefficients */ +#define BME68X_REG_COEFF2 UINT8_C(0xe1) + +/* Variant ID Register */ +#define BME68X_REG_VARIANT_ID UINT8_C(0xF0) + +/* Enable/Disable macros */ + +/* Enable */ +#define BME68X_ENABLE UINT8_C(0x01) + +/* Disable */ +#define BME68X_DISABLE UINT8_C(0x00) + +/* Variant ID macros */ + +/* Low Gas variant */ +#define BME68X_VARIANT_GAS_LOW UINT8_C(0x00) + +/* High Gas variant */ +#define BME68X_VARIANT_GAS_HIGH UINT8_C(0x01) + +/* Oversampling setting macros */ + +/* Switch off measurement */ +#define BME68X_OS_NONE UINT8_C(0) + +/* Perform 1 measurement */ +#define BME68X_OS_1X UINT8_C(1) + +/* Perform 2 measurements */ +#define BME68X_OS_2X UINT8_C(2) + +/* Perform 4 measurements */ +#define BME68X_OS_4X UINT8_C(3) + +/* Perform 8 measurements */ +#define BME68X_OS_8X UINT8_C(4) + +/* Perform 16 measurements */ +#define BME68X_OS_16X UINT8_C(5) + +/* IIR Filter settings */ + +/* Switch off the filter */ +#define BME68X_FILTER_OFF UINT8_C(0) + +/* Filter coefficient of 2 */ +#define BME68X_FILTER_SIZE_1 UINT8_C(1) + +/* Filter coefficient of 4 */ +#define BME68X_FILTER_SIZE_3 UINT8_C(2) + +/* Filter coefficient of 8 */ +#define BME68X_FILTER_SIZE_7 UINT8_C(3) + +/* Filter coefficient of 16 */ +#define BME68X_FILTER_SIZE_15 UINT8_C(4) + +/* Filter coefficient of 32 */ +#define BME68X_FILTER_SIZE_31 UINT8_C(5) + +/* Filter coefficient of 64 */ +#define BME68X_FILTER_SIZE_63 UINT8_C(6) + +/* Filter coefficient of 128 */ +#define BME68X_FILTER_SIZE_127 UINT8_C(7) + +/* ODR/Standby time macros */ + +/* Standby time of 0.59ms */ +#define BME68X_ODR_0_59_MS UINT8_C(0) + +/* Standby time of 62.5ms */ +#define BME68X_ODR_62_5_MS UINT8_C(1) + +/* Standby time of 125ms */ +#define BME68X_ODR_125_MS UINT8_C(2) + +/* Standby time of 250ms */ +#define BME68X_ODR_250_MS UINT8_C(3) + +/* Standby time of 500ms */ +#define BME68X_ODR_500_MS UINT8_C(4) + +/* Standby time of 1s */ +#define BME68X_ODR_1000_MS UINT8_C(5) + +/* Standby time of 10ms */ +#define BME68X_ODR_10_MS UINT8_C(6) + +/* Standby time of 20ms */ +#define BME68X_ODR_20_MS UINT8_C(7) + +/* No standby time */ +#define BME68X_ODR_NONE UINT8_C(8) + +/* Operating mode macros */ + +/* Sleep operation mode */ +#define BME68X_SLEEP_MODE UINT8_C(0) + +/* Forced operation mode */ +#define BME68X_FORCED_MODE UINT8_C(1) + +/* Parallel operation mode */ +#define BME68X_PARALLEL_MODE UINT8_C(2) + +/* Sequential operation mode */ +#define BME68X_SEQUENTIAL_MODE UINT8_C(3) + +/* SPI page macros */ + +/* SPI memory page 0 */ +#define BME68X_MEM_PAGE0 UINT8_C(0x10) + +/* SPI memory page 1 */ +#define BME68X_MEM_PAGE1 UINT8_C(0x00) + +/* Coefficient index macros */ + +/* Length for all coefficients */ +#define BME68X_LEN_COEFF_ALL UINT8_C(42) + +/* Length for 1st group of coefficients */ +#define BME68X_LEN_COEFF1 UINT8_C(23) + +/* Length for 2nd group of coefficients */ +#define BME68X_LEN_COEFF2 UINT8_C(14) + +/* Length for 3rd group of coefficients */ +#define BME68X_LEN_COEFF3 UINT8_C(5) + +/* Length of the field */ +#define BME68X_LEN_FIELD UINT8_C(17) + +/* Length between two fields */ +#define BME68X_LEN_FIELD_OFFSET UINT8_C(17) + +/* Length of the configuration register */ +#define BME68X_LEN_CONFIG UINT8_C(5) + +/* Length of the interleaved buffer */ +#define BME68X_LEN_INTERLEAVE_BUFF UINT8_C(20) + +/* Coefficient index macros */ + +/* Coefficient T2 LSB position */ +#define BME68X_IDX_T2_LSB (0) + +/* Coefficient T2 MSB position */ +#define BME68X_IDX_T2_MSB (1) + +/* Coefficient T3 position */ +#define BME68X_IDX_T3 (2) + +/* Coefficient P1 LSB position */ +#define BME68X_IDX_P1_LSB (4) + +/* Coefficient P1 MSB position */ +#define BME68X_IDX_P1_MSB (5) + +/* Coefficient P2 LSB position */ +#define BME68X_IDX_P2_LSB (6) + +/* Coefficient P2 MSB position */ +#define BME68X_IDX_P2_MSB (7) + +/* Coefficient P3 position */ +#define BME68X_IDX_P3 (8) + +/* Coefficient P4 LSB position */ +#define BME68X_IDX_P4_LSB (10) + +/* Coefficient P4 MSB position */ +#define BME68X_IDX_P4_MSB (11) + +/* Coefficient P5 LSB position */ +#define BME68X_IDX_P5_LSB (12) + +/* Coefficient P5 MSB position */ +#define BME68X_IDX_P5_MSB (13) + +/* Coefficient P7 position */ +#define BME68X_IDX_P7 (14) + +/* Coefficient P6 position */ +#define BME68X_IDX_P6 (15) + +/* Coefficient P8 LSB position */ +#define BME68X_IDX_P8_LSB (18) + +/* Coefficient P8 MSB position */ +#define BME68X_IDX_P8_MSB (19) + +/* Coefficient P9 LSB position */ +#define BME68X_IDX_P9_LSB (20) + +/* Coefficient P9 MSB position */ +#define BME68X_IDX_P9_MSB (21) + +/* Coefficient P10 position */ +#define BME68X_IDX_P10 (22) + +/* Coefficient H2 MSB position */ +#define BME68X_IDX_H2_MSB (23) + +/* Coefficient H2 LSB position */ +#define BME68X_IDX_H2_LSB (24) + +/* Coefficient H1 LSB position */ +#define BME68X_IDX_H1_LSB (24) + +/* Coefficient H1 MSB position */ +#define BME68X_IDX_H1_MSB (25) + +/* Coefficient H3 position */ +#define BME68X_IDX_H3 (26) + +/* Coefficient H4 position */ +#define BME68X_IDX_H4 (27) + +/* Coefficient H5 position */ +#define BME68X_IDX_H5 (28) + +/* Coefficient H6 position */ +#define BME68X_IDX_H6 (29) + +/* Coefficient H7 position */ +#define BME68X_IDX_H7 (30) + +/* Coefficient T1 LSB position */ +#define BME68X_IDX_T1_LSB (31) + +/* Coefficient T1 MSB position */ +#define BME68X_IDX_T1_MSB (32) + +/* Coefficient GH2 LSB position */ +#define BME68X_IDX_GH2_LSB (33) + +/* Coefficient GH2 MSB position */ +#define BME68X_IDX_GH2_MSB (34) + +/* Coefficient GH1 position */ +#define BME68X_IDX_GH1 (35) + +/* Coefficient GH3 position */ +#define BME68X_IDX_GH3 (36) + +/* Coefficient res heat value position */ +#define BME68X_IDX_RES_HEAT_VAL (37) + +/* Coefficient res heat range position */ +#define BME68X_IDX_RES_HEAT_RANGE (39) + +/* Coefficient range switching error position */ +#define BME68X_IDX_RANGE_SW_ERR (41) + +/* Gas measurement macros */ + +/* Disable gas measurement */ +#define BME68X_DISABLE_GAS_MEAS UINT8_C(0x00) + +/* Enable gas measurement low */ +#define BME68X_ENABLE_GAS_MEAS_L UINT8_C(0x01) + +/* Enable gas measurement high */ +#define BME68X_ENABLE_GAS_MEAS_H UINT8_C(0x02) + +/* Heater control macros */ + +/* Enable heater */ +#define BME68X_ENABLE_HEATER UINT8_C(0x00) + +/* Disable heater */ +#define BME68X_DISABLE_HEATER UINT8_C(0x01) + +#ifdef BME68X_USE_FPU + +/* 0 degree Celsius */ +#define BME68X_MIN_TEMPERATURE INT16_C(0) + +/* 60 degree Celsius */ +#define BME68X_MAX_TEMPERATURE INT16_C(60) + +/* 900 hecto Pascals */ +#define BME68X_MIN_PRESSURE UINT32_C(90000) + +/* 1100 hecto Pascals */ +#define BME68X_MAX_PRESSURE UINT32_C(110000) + +/* 20% relative humidity */ +#define BME68X_MIN_HUMIDITY UINT32_C(20) + +/* 80% relative humidity*/ +#define BME68X_MAX_HUMIDITY UINT32_C(80) +#else + +/* 0 degree Celsius */ +#define BME68X_MIN_TEMPERATURE INT16_C(0) + +/* 60 degree Celsius */ +#define BME68X_MAX_TEMPERATURE INT16_C(6000) + +/* 900 hecto Pascals */ +#define BME68X_MIN_PRESSURE UINT32_C(90000) + +/* 1100 hecto Pascals */ +#define BME68X_MAX_PRESSURE UINT32_C(110000) + +/* 20% relative humidity */ +#define BME68X_MIN_HUMIDITY UINT32_C(20000) + +/* 80% relative humidity*/ +#define BME68X_MAX_HUMIDITY UINT32_C(80000) + +#endif + +#define BME68X_HEATR_DUR1 UINT16_C(1000) +#define BME68X_HEATR_DUR2 UINT16_C(2000) +#define BME68X_HEATR_DUR1_DELAY UINT32_C(1000000) +#define BME68X_HEATR_DUR2_DELAY UINT32_C(2000000) +#define BME68X_N_MEAS UINT8_C(6) +#define BME68X_LOW_TEMP UINT8_C(150) +#define BME68X_HIGH_TEMP UINT16_C(350) + +/* Mask macros */ +/* Mask for number of conversions */ +#define BME68X_NBCONV_MSK UINT8_C(0X0f) + +/* Mask for IIR filter */ +#define BME68X_FILTER_MSK UINT8_C(0X1c) + +/* Mask for ODR[3] */ +#define BME68X_ODR3_MSK UINT8_C(0x80) + +/* Mask for ODR[2:0] */ +#define BME68X_ODR20_MSK UINT8_C(0xe0) + +/* Mask for temperature oversampling */ +#define BME68X_OST_MSK UINT8_C(0Xe0) + +/* Mask for pressure oversampling */ +#define BME68X_OSP_MSK UINT8_C(0X1c) + +/* Mask for humidity oversampling */ +#define BME68X_OSH_MSK UINT8_C(0X07) + +/* Mask for heater control */ +#define BME68X_HCTRL_MSK UINT8_C(0x08) + +/* Mask for run gas */ +#define BME68X_RUN_GAS_MSK UINT8_C(0x30) + +/* Mask for operation mode */ +#define BME68X_MODE_MSK UINT8_C(0x03) + +/* Mask for res heat range */ +#define BME68X_RHRANGE_MSK UINT8_C(0x30) + +/* Mask for range switching error */ +#define BME68X_RSERROR_MSK UINT8_C(0xf0) + +/* Mask for new data */ +#define BME68X_NEW_DATA_MSK UINT8_C(0x80) + +/* Mask for gas index */ +#define BME68X_GAS_INDEX_MSK UINT8_C(0x0f) + +/* Mask for gas range */ +#define BME68X_GAS_RANGE_MSK UINT8_C(0x0f) + +/* Mask for gas measurement valid */ +#define BME68X_GASM_VALID_MSK UINT8_C(0x20) + +/* Mask for heater stability */ +#define BME68X_HEAT_STAB_MSK UINT8_C(0x10) + +/* Mask for SPI memory page */ +#define BME68X_MEM_PAGE_MSK UINT8_C(0x10) + +/* Mask for reading a register in SPI */ +#define BME68X_SPI_RD_MSK UINT8_C(0x80) + +/* Mask for writing a register in SPI */ +#define BME68X_SPI_WR_MSK UINT8_C(0x7f) + +/* Mask for the H1 calibration coefficient */ +#define BME68X_BIT_H1_DATA_MSK UINT8_C(0x0f) + +/* Position macros */ + +/* Filter bit position */ +#define BME68X_FILTER_POS UINT8_C(2) + +/* Temperature oversampling bit position */ +#define BME68X_OST_POS UINT8_C(5) + +/* Pressure oversampling bit position */ +#define BME68X_OSP_POS UINT8_C(2) + +/* ODR[3] bit position */ +#define BME68X_ODR3_POS UINT8_C(7) + +/* ODR[2:0] bit position */ +#define BME68X_ODR20_POS UINT8_C(5) + +/* Run gas bit position */ +#define BME68X_RUN_GAS_POS UINT8_C(4) + +/* Heater control bit position */ +#define BME68X_HCTRL_POS UINT8_C(3) + +/* Macro to combine two 8 bit data's to form a 16 bit data */ +#define BME68X_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb) + +/* Macro to set bits */ +#define BME68X_SET_BITS(reg_data, bitname, data) \ + ((reg_data & ~(bitname##_MSK)) | \ + ((data << bitname##_POS) & bitname##_MSK)) + +/* Macro to get bits */ +#define BME68X_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \ + (bitname##_POS)) + +/* Macro to set bits starting from position 0 */ +#define BME68X_SET_BITS_POS_0(reg_data, bitname, data) \ + ((reg_data & ~(bitname##_MSK)) | \ + (data & bitname##_MSK)) + +/* Macro to get bits starting from position 0 */ +#define BME68X_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK)) + +/** + * BME68X_INTF_RET_TYPE is the read/write interface return type which can be overwritten by the build system. + * The default is set to int8_t. + */ +#ifndef BME68X_INTF_RET_TYPE +#define BME68X_INTF_RET_TYPE int8_t +#endif + +/** + * BME68X_INTF_RET_SUCCESS is the success return value read/write interface return type which can be + * overwritten by the build system. The default is set to 0. It is used to check for a successful + * execution of the read/write functions + */ +#ifndef BME68X_INTF_RET_SUCCESS +#define BME68X_INTF_RET_SUCCESS INT8_C(0) +#endif + +/********************************************************* */ +/*! Function Pointers */ +/********************************************************* */ + +/*! + * @brief Bus communication function pointer which should be mapped to + * the platform specific read functions of the user + * + * @param[in] reg_addr : 8bit register address of the sensor + * @param[out] reg_data : Data from the specified address + * @param[in] length : Length of the reg_data array + * @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors + * for interface related callbacks + * @retval 0 for Success + * @retval Non-zero for Failure + */ +typedef BME68X_INTF_RET_TYPE (*bme68x_read_fptr_t)(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, + void *intf_ptr); + +/*! + * @brief Bus communication function pointer which should be mapped to + * the platform specific write functions of the user + * + * @param[in] reg_addr : 8bit register address of the sensor + * @param[out] reg_data : Data to the specified address + * @param[in] length : Length of the reg_data array + * @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors + * for interface related callbacks + * @retval 0 for Success + * @retval Non-zero for Failure + * + */ +typedef BME68X_INTF_RET_TYPE (*bme68x_write_fptr_t)(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, + void *intf_ptr); + +/*! + * @brief Delay function pointer which should be mapped to + * delay function of the user + * + * @param period - The time period in microseconds + * @param[in,out] intf_ptr : Void pointer that can enable the linking of descriptors + * for interface related callbacks + */ +typedef void (*bme68x_delay_us_fptr_t)(uint32_t period, void *intf_ptr); + +/* + * @brief Generic communication function pointer + * @param[in] dev_id: Place holder to store the id of the device structure + * Can be used to store the index of the Chip select or + * I2C address of the device. + * @param[in] reg_addr: Used to select the register the where data needs to + * be read from or written to. + * @param[in,out] reg_data: Data array to read/write + * @param[in] len: Length of the data array + */ + +/* + * @brief Interface selection Enumerations + */ +enum bme68x_intf { + /*! SPI interface */ + BME68X_SPI_INTF, + /*! I2C interface */ + BME68X_I2C_INTF +}; + +/* Structure definitions */ + +/* + * @brief Sensor field data structure + */ +struct bme68x_data +{ + /*! Contains new_data, gasm_valid & heat_stab */ + uint8_t status; + + /*! The index of the heater profile used */ + uint8_t gas_index; + + /*! Measurement index to track order */ + uint8_t meas_index; + + /*! Heater resistance */ + uint8_t res_heat; + + /*! Current DAC */ + uint8_t idac; + + /*! Gas wait period */ + uint8_t gas_wait; +#ifndef BME68X_USE_FPU + + /*! Temperature in degree celsius x100 */ + int16_t temperature; + + /*! Pressure in Pascal */ + uint32_t pressure; + + /*! Humidity in % relative humidity x1000 */ + uint32_t humidity; + + /*! Gas resistance in Ohms */ + uint32_t gas_resistance; +#else + + /*! Temperature in degree celsius */ + float temperature; + + /*! Pressure in Pascal */ + float pressure; + + /*! Humidity in % relative humidity x1000 */ + float humidity; + + /*! Gas resistance in Ohms */ + float gas_resistance; + +#endif + +}; + +/* + * @brief Structure to hold the calibration coefficients + */ +struct bme68x_calib_data +{ + /*! Calibration coefficient for the humidity sensor */ + uint16_t par_h1; + + /*! Calibration coefficient for the humidity sensor */ + uint16_t par_h2; + + /*! Calibration coefficient for the humidity sensor */ + int8_t par_h3; + + /*! Calibration coefficient for the humidity sensor */ + int8_t par_h4; + + /*! Calibration coefficient for the humidity sensor */ + int8_t par_h5; + + /*! Calibration coefficient for the humidity sensor */ + uint8_t par_h6; + + /*! Calibration coefficient for the humidity sensor */ + int8_t par_h7; + + /*! Calibration coefficient for the gas sensor */ + int8_t par_gh1; + + /*! Calibration coefficient for the gas sensor */ + int16_t par_gh2; + + /*! Calibration coefficient for the gas sensor */ + int8_t par_gh3; + + /*! Calibration coefficient for the temperature sensor */ + uint16_t par_t1; + + /*! Calibration coefficient for the temperature sensor */ + int16_t par_t2; + + /*! Calibration coefficient for the temperature sensor */ + int8_t par_t3; + + /*! Calibration coefficient for the pressure sensor */ + uint16_t par_p1; + + /*! Calibration coefficient for the pressure sensor */ + int16_t par_p2; + + /*! Calibration coefficient for the pressure sensor */ + int8_t par_p3; + + /*! Calibration coefficient for the pressure sensor */ + int16_t par_p4; + + /*! Calibration coefficient for the pressure sensor */ + int16_t par_p5; + + /*! Calibration coefficient for the pressure sensor */ + int8_t par_p6; + + /*! Calibration coefficient for the pressure sensor */ + int8_t par_p7; + + /*! Calibration coefficient for the pressure sensor */ + int16_t par_p8; + + /*! Calibration coefficient for the pressure sensor */ + int16_t par_p9; + + /*! Calibration coefficient for the pressure sensor */ + uint8_t par_p10; +#ifndef BME68X_USE_FPU + + /*! Variable to store the intermediate temperature coefficient */ + int32_t t_fine; +#else + + /*! Variable to store the intermediate temperature coefficient */ + float t_fine; +#endif + + /*! Heater resistance range coefficient */ + uint8_t res_heat_range; + + /*! Heater resistance value coefficient */ + int8_t res_heat_val; + + /*! Gas resistance range switching error coefficient */ + int8_t range_sw_err; +}; + +/* + * @brief BME68X sensor settings structure which comprises of ODR, + * over-sampling and filter settings. + */ +struct bme68x_conf +{ + /*! Humidity oversampling. Refer @ref osx*/ + uint8_t os_hum; + + /*! Temperature oversampling. Refer @ref osx */ + uint8_t os_temp; + + /*! Pressure oversampling. Refer @ref osx */ + uint8_t os_pres; + + /*! Filter coefficient. Refer @ref filter*/ + uint8_t filter; + + /*! + * Standby time between sequential mode measurement profiles. + * Refer @ref odr + */ + uint8_t odr; +}; + +/* + * @brief BME68X gas heater configuration + */ +struct bme68x_heatr_conf +{ + /*! Enable gas measurement. Refer @ref en_dis */ + uint8_t enable; + + /*! Store the heater temperature for forced mode degree Celsius */ + uint16_t heatr_temp; + + /*! Store the heating duration for forced mode in milliseconds */ + uint16_t heatr_dur; + + /*! Store the heater temperature profile in degree Celsius */ + uint16_t *heatr_temp_prof; + + /*! Store the heating duration profile in milliseconds */ + uint16_t *heatr_dur_prof; + + /*! Variable to store the length of the heating profile */ + uint8_t profile_len; + + /*! + * Variable to store heating duration for parallel mode + * in milliseconds + */ + uint16_t shared_heatr_dur; +}; + +/* + * @brief BME68X device structure + */ +struct bme68x_dev +{ + /*! Chip Id */ + uint8_t chip_id; + + /*! + * The interface pointer is used to enable the user + * to link their interface descriptors for reference during the + * implementation of the read and write interfaces to the + * hardware. + */ + void *intf_ptr; + + /*! + * Variant id + * ---------------------------------------- + * Value | Variant + * ---------------------------------------- + * 0 | BME68X_VARIANT_GAS_LOW + * 1 | BME68X_VARIANT_GAS_HIGH + * ---------------------------------------- + */ + uint32_t variant_id; + + /*! SPI/I2C interface */ + enum bme68x_intf intf; + + /*! Memory page used */ + uint8_t mem_page; + + /*! Ambient temperature in Degree C*/ + int8_t amb_temp; + + /*! Sensor calibration data */ + struct bme68x_calib_data calib; + + /*! Read function pointer */ + bme68x_read_fptr_t read; + + /*! Write function pointer */ + bme68x_write_fptr_t write; + + /*! Delay function pointer */ + bme68x_delay_us_fptr_t delay_us; + + /*! To store interface pointer error */ + BME68X_INTF_RET_TYPE intf_rslt; + + /*! Store the info messages */ + uint8_t info_msg; +}; + +#endif /* BME68X_DEFS_H_ */ +/*! @endcond */ diff --git a/components/BME68x/src/bme68xLibrary.cpp b/components/BME68x/src/bme68xLibrary.cpp new file mode 100755 index 0000000..ab15aa1 --- /dev/null +++ b/components/BME68x/src/bme68xLibrary.cpp @@ -0,0 +1,668 @@ +/** + * Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file bme68xLibrary.cpp + * @date 8 Feb 2022 + * @version 1.1.40407 + * + */ + +#include + +#include "bme68xLibrary.h" + +/* Maximum transaction size. Field size 17 x 3 */ +#define BME68X_MAX_READ_LENGTH 51 + +#ifdef ARDUINO_ARCH_ESP32 +#define BME68X_I2C_BUFFER_SIZE I2C_BUFFER_LENGTH + +#define BME68X_BURST_SPI_TRANSFER +#endif + +#ifdef ARDUINO_ARCH_MBED +/* Assuming all MBED implementations of Wire have 256 byte sized buffers */ +#define BME68X_I2C_BUFFER_SIZE 256 + +#define BME68X_BURST_SPI_TRANSFER +#endif + +#ifdef ARDUINO_ARCH_ESP8266 +#define BME68X_I2C_BUFFER_SIZE BUFFER_LENGTH + +#define BME68X_BURST_SPI_TRANSFER +#endif + +#ifdef ARDUINO_ARCH_AVR +#define BME68X_I2C_BUFFER_SIZE BUFFER_LENGTH + +#define BME68X_BURST_SPI_TRANSFER +#endif + +#ifdef ARDUINO_ARCH_NRF52 +#define BME68X_I2C_BUFFER_SIZE SERIAL_BUFFER_SIZE + +#define BME68X_BURST_SPI_TRANSFER +#endif + +#ifdef ARDUINO_ARCH_SAMD +/* Assuming all Arduino's and Adafruit's SAMD + * implementations of Wire have 256 byte sized buffers */ +#define BME68X_I2C_BUFFER_SIZE 256 + +#define BME68X_BURST_SPI_TRANSFER +#endif + +#ifdef ARDUINO_ARCH_SAM +#define BME68X_I2C_BUFFER_SIZE BUFFER_LENGTH + +#define BME68X_BURST_SPI_TRANSFER +#endif + +/* Optimistically assume support for at least 64 byte reads */ +#ifndef BME68X_I2C_BUFFER_SIZE +#define BME68X_I2C_BUFFER_SIZE 64 +#endif + +#if BME68X_MAX_READ_LENGTH > BME68X_I2C_BUFFER_SIZE +#warning "Wire read requires a larger buffer size. Use SPI" +#endif + +MyLibs::Bme68x::Bme68x(void) +{ + comm.i2c.wireobj = NULL; + comm.i2c.i2cAddr = 0; + comm.spi.spiobj = NULL; + comm.spi.cs = 0; + status = BME68X_OK; + memset(&bme6, 0, sizeof(bme6)); + memset(&conf, 0, sizeof(conf)); + memset(&heatrConf, 0, sizeof(heatrConf)); + memset(sensorData, 0, sizeof(sensorData)); + bme6.amb_temp = 25; /* Typical room temperature in Celsius */ + nFields = 0; + iFields = 0; + lastOpMode = BME68X_SLEEP_MODE; +} + +/** + * @brief Function to initialize the sensor based on custom callbacks +*/ +void MyLibs::Bme68x::begin(bme68xIntf intf, bme68x_read_fptr_t read, bme68x_write_fptr_t write, + bme68x_delay_us_fptr_t idleTask, void *intfPtr) +{ + + bme6.intf = intf; + bme6.read = read; + bme6.write = write; + bme6.delay_us = idleTask; + bme6.intf_ptr = intfPtr; + bme6.amb_temp = 25; + + status = bme68x_init(&bme6); +} + +/** + * @brief Function to initialize the sensor based on the Wire library + */ +void MyLibs::Bme68x::begin(uint8_t i2cAddr, TwoWire &i2c, bme68x_delay_us_fptr_t idleTask) +{ + comm.i2c.i2cAddr = i2cAddr; + comm.i2c.wireobj = &i2c; + bme6.intf = BME68X_I2C_INTF; + bme6.read = bme68xI2cRead; + bme6.write = bme68xI2cWrite; + bme6.delay_us = idleTask; + bme6.intf_ptr = &comm; + bme6.amb_temp = 25; + + status = bme68x_init(&bme6); +} + +/** + * @brief Function to initialize the sensor based on the SPI library + */ +void MyLibs::Bme68x::begin(uint8_t chipSelect, SPIClass &spi, bme68x_delay_us_fptr_t idleTask) +{ + pinMode(chipSelect, OUTPUT); + digitalWrite(chipSelect, HIGH); + delay(1); + digitalWrite(chipSelect, LOW); /* Switch to SPI with a dummy transaction */ + delay(1); + digitalWrite(chipSelect, HIGH); + comm.spi.cs = chipSelect; + comm.spi.spiobj = &spi; + bme6.intf = BME68X_SPI_INTF; + bme6.read = bme68xSpiRead; + bme6.write = bme68xSpiWrite; + bme6.delay_us = idleTask; + bme6.intf_ptr = &comm; + bme6.amb_temp = 25; + + status = bme68x_init(&bme6); +} + +/** + * @brief Function to read a register + */ +uint8_t MyLibs::Bme68x::readReg(uint8_t regAddr) +{ + uint8_t regData; + readReg(regAddr, ®Data, 1); + return regData; +} + +/** + * @brief Function to read multiple registers + */ +void MyLibs::Bme68x::readReg(uint8_t regAddr, uint8_t *regData, uint32_t length) +{ + status = bme68x_get_regs(regAddr, regData, length, &bme6); +} + +/** + * @brief Function to write data to a register + */ +void MyLibs::Bme68x::writeReg(uint8_t regAddr, uint8_t regData) +{ + status = bme68x_set_regs(®Addr, ®Data, 1, &bme6); +} + +/** + * @brief Function to write multiple registers + */ +void MyLibs::Bme68x::writeReg(uint8_t *regAddr, const uint8_t *regData, uint32_t length) +{ + status = bme68x_set_regs(regAddr, regData, length, &bme6); +} + +/** + * @brief Function to trigger a soft reset + */ +void MyLibs::Bme68x::softReset(void) +{ + status = bme68x_soft_reset(&bme6); +} + +/** + * @brief Function to set the ambient temperature for better configuration + */ +void MyLibs::Bme68x::setAmbientTemp(int8_t temp) +{ + bme6.amb_temp = temp; +} + +/** + * @brief Function to get the measurement duration in microseconds + */ +uint32_t MyLibs::Bme68x::getMeasDur(uint8_t opMode) +{ + if (opMode == BME68X_SLEEP_MODE) + opMode = lastOpMode; + + return bme68x_get_meas_dur(opMode, &conf, &bme6); +} + +/** + * @brief Function to set the operation mode + */ +void MyLibs::Bme68x::setOpMode(uint8_t opMode) +{ + status = bme68x_set_op_mode(opMode, &bme6); + if ((status == BME68X_OK) && (opMode != BME68X_SLEEP_MODE)) + lastOpMode = opMode; +} + +/** + * @brief Function to get the operation mode + */ +uint8_t MyLibs::Bme68x::getOpMode(void) +{ + uint8_t opMode; + status = bme68x_get_op_mode(&opMode, &bme6); + return opMode; +} + +/** + * @brief Function to get the Temperature, Pressure and Humidity over-sampling + */ +void MyLibs::Bme68x::getTPH(uint8_t &osHum, uint8_t &osTemp, uint8_t &osPres) +{ + status = bme68x_get_conf(&conf, &bme6); + + if (status == BME68X_OK) + { + osHum = conf.os_hum; + osTemp = conf.os_temp; + osPres = conf.os_pres; + } +} + +/** + * @brief Function to set the Temperature, Pressure and Humidity over-sampling + */ +void MyLibs::Bme68x::setTPH(uint8_t osTemp, uint8_t osPres, uint8_t osHum) +{ + status = bme68x_get_conf(&conf, &bme6); + + if (status == BME68X_OK) + { + conf.os_hum = osHum; + conf.os_temp = osTemp; + conf.os_pres = osPres; + + status = bme68x_set_conf(&conf, &bme6); + } +} + +/** + * @brief Function to get the filter configuration + */ +uint8_t MyLibs::Bme68x::getFilter(void) +{ + status = bme68x_get_conf(&conf, &bme6); + + return conf.filter; +} + +/** + * @brief Function to set the filter configuration + */ +void MyLibs::Bme68x::setFilter(uint8_t filter) +{ + status = bme68x_get_conf(&conf, &bme6); + + if (status == BME68X_OK) + { + conf.filter = filter; + + status = bme68x_set_conf(&conf, &bme6); + } +} + +/** + * @brief Function to get the sleep duration during Sequential mode + */ +uint8_t MyLibs::Bme68x::getSeqSleep(void) +{ + status = bme68x_get_conf(&conf, &bme6); + + return conf.odr; +} + +/** + * @brief Function to set the sleep duration during Sequential mode + */ +void MyLibs::Bme68x::setSeqSleep(uint8_t odr) +{ + status = bme68x_get_conf(&conf, &bme6); + + if (status == BME68X_OK) + { + conf.odr = odr; + + status = bme68x_set_conf(&conf, &bme6); + } +} + +/** + * @brief Function to set the heater profile for Forced mode + */ +void MyLibs::Bme68x::setHeaterProf(uint16_t temp, uint16_t dur) +{ + heatrConf.enable = BME68X_ENABLE; + heatrConf.heatr_temp = temp; + heatrConf.heatr_dur = dur; + + status = bme68x_set_heatr_conf(BME68X_FORCED_MODE, &heatrConf, &bme6); +} + +/** + * @brief Function to set the heater profile for Sequential mode + */ +void MyLibs::Bme68x::setHeaterProf(uint16_t *temp, uint16_t *dur, uint8_t profileLen) +{ + heatrConf.enable = BME68X_ENABLE; + heatrConf.heatr_temp_prof = temp; + heatrConf.heatr_dur_prof = dur; + heatrConf.profile_len = profileLen; + + status = bme68x_set_heatr_conf(BME68X_SEQUENTIAL_MODE, &heatrConf, &bme6); + +} + +/** + * @brief Function to set the heater profile for Parallel mode + */ +void MyLibs::Bme68x::setHeaterProf(uint16_t *temp, uint16_t *mul, uint16_t sharedHeatrDur, uint8_t profileLen) +{ + heatrConf.enable = BME68X_ENABLE; + heatrConf.heatr_temp_prof = temp; + heatrConf.heatr_dur_prof = mul; + heatrConf.shared_heatr_dur = sharedHeatrDur; + heatrConf.profile_len = profileLen; + + status = bme68x_set_heatr_conf(BME68X_PARALLEL_MODE, &heatrConf, &bme6); +} + +/** + * @brief Function to fetch data from the sensor into the local buffer + */ +uint8_t MyLibs::Bme68x::fetchData(void) +{ + nFields = 0; + status = bme68x_get_data(lastOpMode, sensorData, &nFields, &bme6); + iFields = 0; + + return nFields; +} + +/** + * @brief Function to get a single data field + */ +uint8_t MyLibs::Bme68x::getData(bme68xData &data) +{ + if (lastOpMode == BME68X_FORCED_MODE) + { + data = sensorData[0]; + } else + { + if (nFields) + { + /* iFields spans from 0-2 while nFields spans from + * 0-3, where 0 means that there is no new data + */ + data = sensorData[iFields]; + iFields++; + + /* Limit reading continuously to the last fields read */ + if (iFields >= nFields) + { + iFields = nFields - 1; + return 0; + } + + /* Indicate if there is something left to read */ + return nFields - iFields; + } + } + + return 0; +} + +/** + * @brief Function to get whole sensor data + */ +MyLibs::bme68xData* MyLibs::Bme68x::getAllData(void) +{ + return sensorData; +} + +/** + * @brief Function to get the BME68x heater configuration + */ +const MyLibs::bme68xHeatrConf& MyLibs::Bme68x::getHeaterConfiguration(void) +{ + return heatrConf; +} + +/** + * @brief Function to retrieve the sensor's unique ID + */ +uint32_t MyLibs::Bme68x::getUniqueId(void) +{ + uint8_t id_regs[4]; + uint32_t uid; + readReg(BME68X_REG_UNIQUE_ID, id_regs, 4); + + uint32_t id1 = ((uint32_t) id_regs[3] + ((uint32_t) id_regs[2] << 8)) & 0x7fff; + uid = (id1 << 16) + (((uint32_t) id_regs[1]) << 8) + (uint32_t) id_regs[0]; + + return uid; +} + +/** + * @brief Function to get the error code of the interface functions + */ +BME68X_INTF_RET_TYPE MyLibs::Bme68x::intfError(void) +{ + return bme6.intf_rslt; +} + +/** + * @brief Function to check if an error / warning has occurred + */ +int8_t MyLibs::Bme68x::checkStatus(void) +{ + if (status < BME68X_OK) + { + return BME68X_ERROR; + } + else if(status > BME68X_OK) + { + return BME68X_WARNING; + } + else + { + return BME68X_OK; + } +} + +/** + * @brief Function to get a brief text description of the error + */ +String MyLibs::Bme68x::statusString(void) +{ + String ret = ""; + switch (status) + { + case BME68X_OK: + /* Don't return a text for OK */ + break; + case BME68X_E_NULL_PTR: + ret = "Null pointer"; + break; + case BME68X_E_COM_FAIL: + ret = "Communication failure"; + break; + case BME68X_E_DEV_NOT_FOUND: + ret = "Sensor not found"; + break; + case BME68X_E_INVALID_LENGTH: + ret = "Invalid length"; + break; + case BME68X_W_DEFINE_OP_MODE: + ret = "Set the operation mode"; + break; + case BME68X_W_NO_NEW_DATA: + ret = "No new data"; + break; + case BME68X_W_DEFINE_SHD_HEATR_DUR: + ret = "Set the shared heater duration"; + break; + default: + ret = "Undefined error code"; + } + + return ret; +} + +namespace MyLibs +{ + +/** + * @brief Function that implements the default microsecond delay callback + */ +void bme68xDelayUs(uint32_t periodUs, void *intfPtr) { + (void) intfPtr; + delayMicroseconds(periodUs); +} + +/** + * @brief Function that implements the default SPI write transaction + */ +int8_t bme68xSpiWrite(uint8_t regAddr, const uint8_t *regData, + uint32_t length, void *intfPtr) { + MyLibs::bme68xScommT *comm = NULL; + + if (intfPtr) { + comm = (MyLibs::bme68xScommT *) intfPtr; + + if (comm->spi.spiobj) { + digitalWrite(comm->spi.cs, LOW); + + comm->spi.spiobj->transfer(regAddr); +#ifdef BME68X_BURST_SPI_TRANSFER + comm->spi.spiobj->transfer((uint8_t *)regData, length); +#else + for(uint32_t i = 0; i < length; i++) { + comm->spi.spiobj->transfer(regData[i]); + } +#endif + + digitalWrite(comm->spi.cs, HIGH); + } else { + return BME68X_E_NULL_PTR; + } + } else { + return BME68X_E_NULL_PTR; + } + + return BME68X_OK; +} + +/** + * @brief Function that implements the default SPI read transaction + */ +int8_t bme68xSpiRead(uint8_t regAddr, uint8_t *regData, uint32_t length, + void *intfPtr) { + MyLibs::bme68xScommT *comm = NULL; + + if (intfPtr) { + comm = (MyLibs::bme68xScommT *) intfPtr; + + if (comm->spi.spiobj) { + digitalWrite(comm->spi.cs, LOW); + + comm->spi.spiobj->transfer(regAddr); + memset(regData, 0xFF, length); +#ifdef BME68X_BURST_SPI_TRANSFER + comm->spi.spiobj->transfer(regData, length); +#else + for(uint32_t i = 0; i < length; i++) { + regData[i] = comm->spi.spiobj->transfer(0xFF); + } +#endif + + digitalWrite(comm->spi.cs, HIGH); + } else { + return BME68X_E_NULL_PTR; + } + } else { + return BME68X_E_NULL_PTR; + } + + return BME68X_OK; +} + +/** + * @brief Function that implements the default I2C write transaction + */ +int8_t bme68xI2cWrite(uint8_t regAddr, const uint8_t *regData, + uint32_t length, void *intfPtr) { + uint32_t i; + int8_t rslt = BME68X_OK; + MyLibs::bme68xScommT *comm = NULL; + +#ifdef BME68X_I2C_BUFFER_SIZE + if (length + 1 > BME68X_I2C_BUFFER_SIZE) + return BME68X_E_COM_FAIL; +#endif + + if (intfPtr) { + comm = (MyLibs::bme68xScommT *) intfPtr; + if (comm->i2c.wireobj) { + comm->i2c.wireobj->beginTransmission(comm->i2c.i2cAddr); + comm->i2c.wireobj->write(regAddr); + for (i = 0; i < length; i++) { + comm->i2c.wireobj->write(regData[i]); + } + if (comm->i2c.wireobj->endTransmission()) { + rslt = BME68X_E_COM_FAIL; + } + } else { + rslt = BME68X_E_NULL_PTR; + } + } else { + rslt = BME68X_E_NULL_PTR; + } + + return rslt; +} + +/** + * @brief Function that implements the default I2C read transaction + */ +int8_t bme68xI2cRead(uint8_t regAddr, uint8_t *regData, uint32_t length, + void *intfPtr) { + uint32_t i; + int8_t rslt = BME68X_OK; + MyLibs::bme68xScommT *comm = NULL; + +#ifdef BME68X_I2C_BUFFER_SIZE + if (length > BME68X_I2C_BUFFER_SIZE) + return BME68X_E_COM_FAIL; +#endif + + if (intfPtr) { + comm = (MyLibs::bme68xScommT *) intfPtr; + if (comm->i2c.wireobj) { + comm->i2c.wireobj->beginTransmission(comm->i2c.i2cAddr); + comm->i2c.wireobj->write(regAddr); + if (comm->i2c.wireobj->endTransmission()) { + return BME68X_E_COM_FAIL; + } + comm->i2c.wireobj->requestFrom((int) comm->i2c.i2cAddr, + (int) length); + for (i = 0; (i < length) && comm->i2c.wireobj->available(); i++) { + regData[i] = comm->i2c.wireobj->read(); + } + } else { + rslt = BME68X_E_NULL_PTR; + } + } else { + rslt = BME68X_E_NULL_PTR; + } + + return rslt; +} +} \ No newline at end of file diff --git a/components/BME68x/src/bme68xLibrary.h b/components/BME68x/src/bme68xLibrary.h new file mode 100755 index 0000000..43fa565 --- /dev/null +++ b/components/BME68x/src/bme68xLibrary.h @@ -0,0 +1,350 @@ +/** + * Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved. + * + * BSD-3-Clause + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @file bme68xLibrary.h + * @date 8 Feb 2022 + * @version 1.1.40407 + * + */ + +#ifndef BME68X_LIBRARY_H +#define BME68X_LIBRARY_H + +#include +#include "Arduino.h" +#include "Wire.h" +#include "SPI.h" + +#include "bme68x/bme68x.h" + +#define BME68X_ERROR INT8_C(-1) +#define BME68X_WARNING INT8_C(1) + +namespace MyLibs +{ + +/** + * Datatype working as an interface descriptor + */ +typedef union +{ + struct + { + TwoWire *wireobj; + uint8_t i2cAddr; + } i2c; + struct + { + SPIClass *spiobj; + uint8_t cs; + } spi; +} bme68xScommT; + +/** Datatype to keep consistent with camel casing */ +typedef struct bme68x_data bme68xData; +typedef struct bme68x_dev bme68xDev; +typedef enum bme68x_intf bme68xIntf; +typedef struct bme68x_conf bme68xConf; +typedef struct bme68x_heatr_conf bme68xHeatrConf; + +/** + * @brief Function that implements the default microsecond delay callback + * @param periodUs : Duration of the delay in microseconds + * @param intfPtr : Pointer to the interface descriptor + */ +void bme68xDelayUs(uint32_t periodUs, void *intfPtr); + +/** + * @brief Function that implements the default SPI write transaction + * @param regAddr : Register address of the sensor + * @param regData : Pointer to the data to be written to the sensor + * @param length : Length of the transfer + * @param intfPtr : Pointer to the interface descriptor + * @return 0 if successful, non-zero otherwise + */ +int8_t bme68xSpiWrite(uint8_t regAddr, const uint8_t *regData, uint32_t length, void *intfPtr); + +/** + * @brief Function that implements the default SPI read transaction + * @param regAddr : Register address of the sensor + * @param regData : Pointer to the data to be read from the sensor + * @param length : Length of the transfer + * @param intfPtr : Pointer to the interface descriptor + * @return 0 if successful, non-zero otherwise + */ +int8_t bme68xSpiRead(uint8_t regAddr, uint8_t *regData, uint32_t length, void *intfPtr); + +/** + * @brief Function that implements the default I2C write transaction + * @param regAddr : Register address of the sensor + * @param regData : Pointer to the data to be written to the sensor + * @param length : Length of the transfer + * @param intfPtr : Pointer to the interface descriptor + * @return 0 if successful, non-zero otherwise + */ +int8_t bme68xI2cWrite(uint8_t regAddr, const uint8_t *regData, uint32_t length, void *intfPtr); + +/** + * @brief Function that implements the default I2C read transaction + * @param regAddr : Register address of the sensor + * @param regData : Pointer to the data to be written to the sensor + * @param length : Length of the transfer + * @param intfPtr : Pointer to the interface descriptor + * @return 0 if successful, non-zero otherwise + */ +int8_t bme68xI2cRead(uint8_t regAddr, uint8_t *regData, uint32_t length, void *intfPtr); + +class Bme68x +{ +public: + /** Stores the BME68x sensor APIs error code after an execution */ + int8_t status; + + /** + * Class constructor + */ + Bme68x(void); + + /** + * @brief Function to initialize the sensor based on custom callbacks + * @param intf : BME68X_SPI_INTF or BME68X_I2C_INTF interface + * @param read : Read callback + * @param write : Write callback + * @param idleTask : Delay or Idle function + * @param intfPtr : Pointer to the interface descriptor + */ + void begin(bme68xIntf intf, bme68x_read_fptr_t read, bme68x_write_fptr_t write, + bme68x_delay_us_fptr_t idleTask, void *intfPtr); + + /** + * @brief Function to initialize the sensor based on the Wire library + * @param i2cAddr : The I2C address the sensor is at + * @param i2c : The TwoWire object + * @param idleTask : Delay or Idle function + */ + void begin(uint8_t i2cAddr, TwoWire &i2c, bme68x_delay_us_fptr_t idleTask = bme68xDelayUs); + + /** + * @brief Function to initialize the sensor based on the SPI library + * @param chipSelect : The chip select pin for SPI communication + * @param spi : The SPIClass object + * @param idleTask : Delay or Idle function + */ + void begin(uint8_t chipSelect, SPIClass &spi, bme68x_delay_us_fptr_t idleTask = bme68xDelayUs); + + /** + * @brief Function to read a register + * @param regAddr : Register address + * @return Data at that register + */ + uint8_t readReg(uint8_t regAddr); + + /** + * @brief Function to read multiple registers + * @param regAddr : Start register address + * @param regData : Pointer to store the data + * @param length : Number of registers to read + */ + void readReg(uint8_t regAddr, uint8_t *regData, uint32_t length); + + /** + * @brief Function to write data to a register + * @param regAddr : Register addresses + * @param regData : Data for that register + */ + void writeReg(uint8_t regAddr, uint8_t regData); + + /** + * @brief Function to write multiple registers + * @param regAddr : Pointer to the register addresses + * @param regData : Pointer to the data for those registers + * @param length : Number of register to write + */ + void writeReg(uint8_t *regAddr, const uint8_t *regData, uint32_t length); + + /** + * @brief Function to trigger a soft reset + */ + void softReset(void); + + /** + * @brief Function to set the ambient temperature for better configuration + * @param temp : Temperature in degree Celsius. Default is 25 deg C + */ + void setAmbientTemp(int8_t temp = 25); + + /** + * @brief Function to get the measurement duration in microseconds + * @param opMode : Operation mode of the sensor. Attempts to use the last one if nothing is set + * @return Temperature, Pressure, Humidity measurement time in microseconds + */ + uint32_t getMeasDur(uint8_t opMode = BME68X_SLEEP_MODE); + + /** + * @brief Function to set the operation mode + * @param opMode : BME68X_SLEEP_MODE, BME68X_FORCED_MODE, BME68X_PARALLEL_MODE, BME68X_SEQUENTIAL_MODE + */ + void setOpMode(uint8_t opMode); + + /** + * @brief Function to get the operation mode + * @return Operation mode : BME68X_SLEEP_MODE, BME68X_FORCED_MODE, BME68X_PARALLEL_MODE, BME68X_SEQUENTIAL_MODE + */ + uint8_t getOpMode(void); + + /** + * @brief Function to get the Temperature, Pressure and Humidity over-sampling + * @param osHum : BME68X_OS_NONE to BME68X_OS_16X + * @param osTemp : BME68X_OS_NONE to BME68X_OS_16X + * @param osPres : BME68X_OS_NONE to BME68X_OS_16X + */ + void getTPH(uint8_t &osHum, uint8_t &osTemp, uint8_t &osPres); + + /** + * @brief Function to set the Temperature, Pressure and Humidity over-sampling. + * Passing no arguments sets the defaults. + * @param osTemp : BME68X_OS_NONE to BME68X_OS_16X + * @param osPres : BME68X_OS_NONE to BME68X_OS_16X + * @param osHum : BME68X_OS_NONE to BME68X_OS_16X + */ + void setTPH(uint8_t osTemp = BME68X_OS_2X, uint8_t osPres = BME68X_OS_16X, uint8_t osHum = BME68X_OS_1X); + + /** + * @brief Function to get the filter configuration + * @return BME68X_FILTER_OFF to BME68X_FILTER_SIZE_127 + */ + uint8_t getFilter(void); + + /** + * @brief Function to set the filter configuration + * @param filter : BME68X_FILTER_OFF to BME68X_FILTER_SIZE_127 + */ + void setFilter(uint8_t filter = BME68X_FILTER_OFF); + + /** + * @brief Function to get the sleep duration during Sequential mode + * @return BME68X_ODR_NONE to BME68X_ODR_1000_MS + */ + uint8_t getSeqSleep(void); + + /** + * @brief Function to set the sleep duration during Sequential mode + * @param odr : BME68X_ODR_NONE to BME68X_ODR_1000_MS + */ + void setSeqSleep(uint8_t odr = BME68X_ODR_0_59_MS); + + /** + * @brief Function to set the heater profile for Forced mode + * @param temp : Heater temperature in degree Celsius + * @param dur : Heating duration in milliseconds + */ + void setHeaterProf(uint16_t temp, uint16_t dur); + + /** + * @brief Function to set the heater profile for Sequential mode + * @param temp : Heater temperature profile in degree Celsius + * @param dur : Heating duration profile in milliseconds + * @param profileLen : Length of the profile + */ + void setHeaterProf(uint16_t *temp, uint16_t *dur, uint8_t profileLen); + + /** + * @brief Function to set the heater profile for Parallel mode + * @param temp : Heater temperature profile in degree Celsius + * @param mul : Profile of number of repetitions + * @param sharedHeatrDur : Shared heating duration in milliseconds + * @param profileLen : Length of the profile + */ + void setHeaterProf(uint16_t *temp, uint16_t *mul, uint16_t sharedHeatrDur, uint8_t profileLen); + + /** + * @brief Function to fetch data from the sensor into the local buffer + * @return Number of new data fields + */ + uint8_t fetchData(void); + + /** + * @brief Function to get a single data field + * @param data : Structure where the data is to be stored + * @return Number of new fields remaining + */ + uint8_t getData(bme68xData &data); + + /** + * @brief Function to get whole sensor data + * @return Sensor data + */ + bme68xData* getAllData(void); + + /** + * @brief Function to get the BME68x heater configuration + */ + const bme68xHeatrConf& getHeaterConfiguration(void); + + /** + * @brief Function to retrieve the sensor's unique ID + * @return Unique ID + */ + uint32_t getUniqueId(void); + + /** + * @brief Function to get the error code of the interface functions + * @return Interface return code + */ + BME68X_INTF_RET_TYPE intfError(void); + + /** + * @brief Function to check if an error / warning has occurred + * @return -1 if an error occurred, 1 if warning occured else 0 + */ + int8_t checkStatus(void); + + /** + * @brief Function to get a brief text description of the error + * @return Returns a string describing the error code + */ + String statusString(void); + +private: + /** Datatype to keep consistent with camel casing + * Datastructure to hold sensor settings + */ + bme68xScommT comm; + bme68xDev bme6; + bme68xConf conf; + bme68xHeatrConf heatrConf; + bme68xData sensorData[3]; + uint8_t nFields, iFields; + uint8_t lastOpMode; +}; +} +#endif /* BME68X_CLASS_H */ diff --git a/main/App.cpp b/main/App.cpp index bc0daaf..890817a 100644 --- a/main/App.cpp +++ b/main/App.cpp @@ -5,7 +5,6 @@ #include #include "Settings.h" #include "errors.h" -#include #include "Ota.h" #include "ProvisionSoftAP.h" @@ -73,15 +72,10 @@ void App::init() m_ble->start(); #endif -#if 0 - m_bmp280 = new Bmp280(Wire); - while(true) - { - m_bmp280->test(); - delay(10); - } -#endif + m_sensors = new Sensors(); + m_sensors->start(); + } void App::otaCheck() diff --git a/main/App.h b/main/App.h index 9860ec0..81e8a0a 100644 --- a/main/App.h +++ b/main/App.h @@ -10,7 +10,7 @@ #include "Wifi.h" #include "Mqtt.h" #include "Ble.h" -#include "Bmp280.h" +#include "sensors/Sensors.h" class App { @@ -18,7 +18,7 @@ protected: Wifi * m_wifi = nullptr; Mqtt * m_mqtt = nullptr; Ble * m_ble = nullptr; - Bmp280 * m_bmp280 = nullptr; + Sensors * m_sensors = nullptr; public: Led * m_led = nullptr; diff --git a/main/Bmp280.cpp b/main/Bmp280.cpp deleted file mode 100644 index 4b1fa17..0000000 --- a/main/Bmp280.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/// © MiroZ 2024 - -#include "Bmp280.h" - -#include - -static const char *TAG = "bme280"; - -Bmp280::Bmp280(TwoWire & wire) : m_wire(wire) -{ - m_sensor = new BMP280_DEV(wire); - m_sensor->begin(0x76); - m_sensor->setPresOversampling(OVERSAMPLING_X4); // Set the pressure oversampling to X4 - m_sensor->setTempOversampling(OVERSAMPLING_X1); // Set the temperature oversampling to X1 - m_sensor->setIIRFilter(IIR_FILTER_4); // Set the IIR filter to setting 4 - m_sensor->setTimeStandby(TIME_STANDBY_62MS); - m_sensor->startNormalConversion(); // Start BMP280 continuous conversion in NORMAL_MODE -} - -bool Bmp280::test() -{ - float temp, pressure, alt; - m_sensor->getCurrentMeasurements(temp, pressure, alt); - ESP_LOGI(TAG, "temp: %0.3f, pressure: %0.3f, alt: %0.3f", temp*1.8+32, pressure, alt); - - return true; -} \ No newline at end of file diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index d0ccd7a..0cc4f41 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,5 +1,6 @@ idf_component_register(SRCS main.cpp App.cpp Settings.cpp Led.cpp TaskMgr.cpp Wifi.cpp utilities.cpp - ProvisionSoftAP.cpp ReaderWriter.cpp Ota.cpp Mqtt.cpp Ble.cpp Bmp280.cpp + ProvisionSoftAP.cpp ReaderWriter.cpp Ota.cpp Mqtt.cpp Ble.cpp sensors/Bmp280.cpp + sensors/Bme68x.cpp sensors/Sensors.cpp INCLUDE_DIRS "." EMBED_TXTFILES ../html/logo.png ../html/provision.html EMBED_TXTFILES ../certs/eventgrid.azure.pem ../certs/client1-authn-ID.key ../certs/client1-authn-ID.pem ../certs/bigfoot-inc.pem diff --git a/main/Led.cpp b/main/Led.cpp index b155508..76866eb 100644 --- a/main/Led.cpp +++ b/main/Led.cpp @@ -109,7 +109,8 @@ Led::Led(uint32_t pin) assert(m_queue = xQueueCreate(5, sizeof(struct LED_QUEUE))); // create the led task - m_task = TaskMgr::getInstance().createTask(std::bind(&Led::run, this), LED_TASK_NAME, LED_TASK_STACK_SIZE, LED_TASK_PRIORITY, LED_TASK_CORE); + m_task = TaskMgr::getInstance().createTask(std::bind(&Led::run, this), + LED_TASK_NAME, LED_TASK_STACK_SIZE, LED_TASK_PRIORITY, LED_TASK_CORE); } Led::~Led() diff --git a/main/Ota.cpp b/main/Ota.cpp index fc3a71b..4696c1b 100644 --- a/main/Ota.cpp +++ b/main/Ota.cpp @@ -22,11 +22,12 @@ #include -#define OTA_URL "https://bigfoot-inc.com/fw/wellhub.enc.bin" +#define OTA_URL "http://bigfoot-inc.com/fw/wellhub.enc.bin" extern const uint8_t server_cert[] asm("_binary_bigfoot_inc_pem_start"); static const char *TAG = "OTA"; +#define FW_HEADER 32 Ota::Ota(App & app) : m_app(app) { @@ -55,7 +56,8 @@ void Ota::start() HTTPClient client; - client.begin(OTA_URL, (const char *)server_cert); + //client.begin(OTA_URL, (const char *)server_cert); + client.begin(OTA_URL); int http_code = client.GET(); if(http_code != HTTP_CODE_OK) @@ -68,7 +70,10 @@ void Ota::start() ESP_LOGI(TAG, "remote file len %d", remote_len); if(remote_len < 4096) + { + client.end(); return; + } WiFiClient* stream = client.getStreamPtr(); @@ -94,9 +99,9 @@ void Ota::start() int binary_file_length = 0; bool image_header_was_checked = false; - // ready header - int data_read = stream->readBytes(otaWriteData, 32); - if (data_read != 32) + // read the header + int data_read = stream->readBytes(otaWriteData, FW_HEADER); + if (data_read != FW_HEADER) { ESP_LOGE(TAG, "Error: SSL data read error"); return; @@ -115,12 +120,19 @@ void Ota::start() { ESP_LOGE(TAG, "Invalid image!"); esp_aes_free(&m_dec_ctx); + client.end(); return; } + int left = remote_len-FW_HEADER; // encryption header + while (1) { - int data_read = stream->readBytes(otaWriteData, BUFFSIZE); + int chunk = left > BUFFSIZE ? BUFFSIZE : left; + + int data_read = stream->readBytes(otaWriteData, chunk); + left -= data_read; + esp_aes_crypt_cbc(&m_dec_ctx, ESP_AES_DECRYPT, data_read, m_dec_iv, (const uint8_t*)otaWriteData, (uint8_t*)&otaWriteData[0]); if (data_read < 0) @@ -177,7 +189,9 @@ void Ota::start() ESP_LOGW(TAG, "Previously, there was an attempt to launch the firmware with %s version, but it failed.", invalid_app_info.version); ESP_LOGW(TAG, "The firmware has been rolled back to the previous version."); - // httpCleanup(client); + + client.end(); + return; } } @@ -186,6 +200,7 @@ void Ota::start() if (memcmp(new_app_info.version, running_app_info.version, sizeof(new_app_info.version) + sizeof(new_app_info.project_name) + sizeof(new_app_info.time) + sizeof(new_app_info.date)) == 0) { ESP_LOGI(TAG, "Current running version is the same as a remote. No need for update."); + client.end(); return; } @@ -193,6 +208,7 @@ void Ota::start() image_header_was_checked = true; + ESP_LOGI(TAG, "Starting..."); err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle); if (err != ESP_OK) @@ -225,15 +241,18 @@ void Ota::start() { last_reported = progress; ESP_LOGI(TAG, "%d%%", last_reported); + delay(1); } } - else if (data_read == 0) + else if (left == 0) { ESP_LOGI(TAG, "All data received"); break; } } + client.end(); + ESP_LOGI(TAG, "Total Write binary data length : %d", binary_file_length); esp_aes_free(&m_dec_ctx); diff --git a/main/app_config.h b/main/app_config.h index 671502c..e0fed27 100644 --- a/main/app_config.h +++ b/main/app_config.h @@ -28,4 +28,16 @@ #define TASKMGR_TASK_CORE 0 #define TASKMGR_TASK_DELAY 60000 +// i2cbus_1 task +#define I2C1_TASK_NAME "i2cbus_1" +#define I2C1_TASK_STACK_SIZE 3000 +#define I2C1_TASK_PRIORITY 5 +#define I2C1_TASK_CORE 0 + +// i2cbus_2 task +#define I2C2_TASK_NAME "i2cbus_2" +#define I2C2_TASK_STACK_SIZE 3000 +#define I2C2_TASK_PRIORITY 5 +#define I2C2_TASK_CORE 0 + #endif \ No newline at end of file diff --git a/main/sensors/Bme68x.cpp b/main/sensors/Bme68x.cpp new file mode 100644 index 0000000..5b8b359 --- /dev/null +++ b/main/sensors/Bme68x.cpp @@ -0,0 +1,60 @@ +/// © MiroZ 2024 +#include + +#include "Bme68x.h" + + +static const char *TAG = "Bme68x"; + + +#define MEAS_DUR 140 +#define NEW_GAS_MEAS (BME68X_GASM_VALID_MSK | BME68X_HEAT_STAB_MSK | BME68X_NEW_DATA_MSK) + +Bme68x::Bme68x(TwoWire & bus) : m_bus(bus) +{ + m_sensor = new MyLibs::Bme68x(); +} + +bool Bme68x::init() +{ + m_sensor->begin(0x77, m_bus); + + m_sensor->setTPH(); + + uint16_t tempProf[10] = { 320, 100, 100, 100, 200, 200, 200, 320, 320, 320 }; + /* Multiplier to the shared heater duration */ + uint16_t mulProf[10] = { 5, 2, 10, 30, 5, 5, 5, 5, 5, 5 }; + /* Shared heating duration in milliseconds */ + uint16_t sharedHeatrDur = MEAS_DUR - (m_sensor->getMeasDur(BME68X_PARALLEL_MODE) / 1000); + + ESP_LOGI(TAG, "sharedHeatrDur:%d", sharedHeatrDur); + + m_sensor->setHeaterProf(tempProf, mulProf, sharedHeatrDur, 10); + m_sensor->setOpMode(BME68X_PARALLEL_MODE); + + + return m_sensor->checkStatus() == BME68X_OK; +} + + +void Bme68x::read() +{ + MyLibs::bme68xData bdata; + uint8_t left; + + if(m_sensor->fetchData() > 0) + { + do + { + left = m_sensor->getData(bdata); + + if (bdata.status == NEW_GAS_MEAS) + { + ESP_LOGI(TAG, "temp: %f", bdata.temperature); + ESP_LOGI(TAG, " hum: %f", bdata.humidity); + ESP_LOGI(TAG, "gres: %f", bdata.gas_resistance); + ESP_LOGI(TAG, " ix: %d", bdata.gas_index); + } + } while(left > 0); + } +} \ No newline at end of file diff --git a/main/sensors/Bme68x.h b/main/sensors/Bme68x.h new file mode 100644 index 0000000..43b0fc4 --- /dev/null +++ b/main/sensors/Bme68x.h @@ -0,0 +1,23 @@ +/// © MiroZ 2024 + +#ifndef __BME68X_h__ +#define __BME68X_h__ + +#include + +#include + +class Bme68x +{ +protected: + MyLibs::Bme68x * m_sensor = nullptr; + TwoWire & m_bus; + +public: + Bme68x(TwoWire & bus); + bool init(); + + void read(); +}; + +#endif \ No newline at end of file diff --git a/main/sensors/Bmp280.cpp b/main/sensors/Bmp280.cpp new file mode 100644 index 0000000..be0822e --- /dev/null +++ b/main/sensors/Bmp280.cpp @@ -0,0 +1,43 @@ +/// © MiroZ 2024 + +#include "Bmp280.h" + +#include + +static const char *TAG = "bme280"; + +Bmp280::Bmp280(TwoWire & bus) : m_bus(bus) +{ + m_sensor = new BMP280_DEV(bus); +} + +bool Bmp280::init() +{ + uint8_t status = m_sensor->begin(0x76); + m_sensor->setPresOversampling(OVERSAMPLING_X4); // Set the pressure oversampling to X4 + m_sensor->setTempOversampling(OVERSAMPLING_X1); // Set the temperature oversampling to X1 + m_sensor->setIIRFilter(IIR_FILTER_2); // Set the IIR filter to setting 4 + m_sensor->setTimeStandby(TIME_STANDBY_62MS); + m_sensor->startNormalConversion(); // Start BMP280 continuous conversion in NORMAL_MODE + + return status == 1; +} + +bool Bmp280::read() +{ + float temp, pressure; + + if(m_sensor->getTempPres(temp, pressure)) + { + char buffer[64]; + + static float prev = 1000; + prev = pressure*0.1+prev*0.9; + + sprintf(buffer, "%0.3f,%0.3f\n", pressure, prev); + printf(buffer); + } + //ESP_LOGI(TAG, "temp: %0.3f, pressure: %0.3f", temp*1.8+32, pressure); + + return true; +} \ No newline at end of file diff --git a/main/Bmp280.h b/main/sensors/Bmp280.h similarity index 71% rename from main/Bmp280.h rename to main/sensors/Bmp280.h index 9c5fc15..3603906 100644 --- a/main/Bmp280.h +++ b/main/sensors/Bmp280.h @@ -10,12 +10,13 @@ class Bmp280 { protected: BMP280_DEV * m_sensor; - TwoWire & m_wire; + TwoWire & m_bus; public: - Bmp280(TwoWire & wire); + Bmp280(TwoWire & bus); + bool init(); - bool test(); + bool read(); }; #endif \ No newline at end of file diff --git a/main/sensors/Sensors.cpp b/main/sensors/Sensors.cpp new file mode 100644 index 0000000..5bc5c79 --- /dev/null +++ b/main/sensors/Sensors.cpp @@ -0,0 +1,49 @@ +#include "app_config.h" +#include "TaskMgr.h" +#include "Sensors.h" + +static const char *TAG = "sensors"; + +Sensors::Sensors() +{ + +} + +void Sensors::start() +{ + m_bmp280 = new Bmp280(Wire); + m_bme68x = new Bme68x(Wire); + + if(!m_bmp280->init()) + ESP_LOGE(TAG, "bmp280 sensor error"); + + if(!m_bme68x->init()) + ESP_LOGE(TAG, "bme68x sensor error"); + + + assert(m_i2c1_task = TaskMgr::getInstance().createTask(std::bind(&Sensors::run_i2c_1, this), + I2C1_TASK_NAME, I2C1_TASK_STACK_SIZE, I2C1_TASK_PRIORITY, I2C1_TASK_CORE)); + + assert(m_i2c2_task = TaskMgr::getInstance().createTask(std::bind(&Sensors::run_i2c_2, this), + I2C2_TASK_NAME, I2C2_TASK_STACK_SIZE, I2C2_TASK_PRIORITY, I2C2_TASK_CORE)); +} + +void Sensors::run_i2c_1() +{ + while(true) + { + m_bmp280->read(); + m_bme68x->read(); + + delay(10); + } +} + +void Sensors::run_i2c_2() +{ + while(true) + { + + delay(1000); + } +} \ No newline at end of file diff --git a/main/sensors/Sensors.h b/main/sensors/Sensors.h new file mode 100644 index 0000000..2c46eee --- /dev/null +++ b/main/sensors/Sensors.h @@ -0,0 +1,24 @@ +#include +#include +#include + +#include "Bme68x.h" +#include "Bmp280.h" + +class Sensors +{ +protected: + TaskHandle_t m_i2c1_task = nullptr; + TaskHandle_t m_i2c2_task = nullptr; + + void run_i2c_1(); + void run_i2c_2(); + + Bmp280 * m_bmp280 = nullptr; + Bme68x * m_bme68x = nullptr; + +public: + Sensors(); + void start(); + +}; \ No newline at end of file diff --git a/make.sh b/make.sh index 3dd24cf..b74c7dc 100755 --- a/make.sh +++ b/make.sh @@ -10,8 +10,6 @@ if (($ret_val != 0)); then exit fi -cp build/wellhub.bin /var/www/esp_ota - if [$1 == '']; then idf.py -p /dev/ttyUSB1 -b 2000000 flash && idf.py -p /dev/ttyUSB1 monitor -B 450000 else diff --git a/ota.sh b/ota.sh index 4839f38..8dd480d 100755 --- a/ota.sh +++ b/ota.sh @@ -5,16 +5,15 @@ idf.py clean idf.py -DROLE=SENDER build -rm build/wellhub.enc.bin - ret_val=$? if (($ret_val != 0)); then exit fi +rm build/wellhub.enc.bin 2> /dev/null +echo "Encrypting image..." image_enc/encrypt.py build/wellhub.bin build/wellhub.enc.bin - -cp build/wellhub.enc.bin /var/www/esp_ota +echo "Uploading..." lftp -c "open -u mirozmrzli@bigfoot-inc.com,3445trGGDSa9 ftp.bigfoot-inc.com; put build/wellhub.enc.bin" diff --git a/partitions.csv b/partitions.csv index 60bb536..391481d 100644 --- a/partitions.csv +++ b/partitions.csv @@ -5,5 +5,4 @@ otadata,data,ota,0xe000,0x2000 app0,app,ota_0,0x10000,0x1E0000 app1,app,ota_1,0x1F0000,0x1E0000 #eeprom,data,0x99,0x3F0000,0x1000 -spiffs,data,spiffs,0x3F1000,0xF000 - +spiffs,data,spiffs,0x3F1000,0xF000 \ No newline at end of file diff --git a/plot/plot.py b/plot/plot.py new file mode 100755 index 0000000..bd40194 --- /dev/null +++ b/plot/plot.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python + +import sys +import serial +import matplotlib +matplotlib.use("tkAgg") +import matplotlib.pyplot as plt +import numpy as np + +#sudo apt-get install python3-tk +#pip install numpi +#pip install matplotlib + +ser = serial.Serial('/dev/ttyUSB1', 450000) +ser.flushInput() + +plot_window = 1000 + +ser_bytes = ser.readline() +str = ser_bytes[:-2].decode("utf-8") +spl = str.split(",") +f2 = float(spl[1]) +y_var = np.array(plot_window * [f2]) + +y_var_1 = np.array(plot_window * [f2]) + +plt.ion() +fig = plt.figure() + +ax1 = fig.add_subplot(111, label="1") +line, = ax1.plot(y_var, color="#ff0000") + +ax2 = ax1 +line2, = ax2.plot(y_var_1, color="#0000ff") + +plt.show() + +count = 0 +while True: + ser_bytes = ser.readline() + str = ser_bytes[:-2].decode("utf-8") + spl = str.split(",") + f1 = float(spl[0]) + f2 = float(spl[1]) + + y_var = np.append(y_var, f2) + y_var = y_var[1:plot_window+1] + line.set_ydata(y_var) + + y_var_1 = np.append(y_var_1, f1) + y_var_1 = y_var_1[1:plot_window+1] + line2.set_ydata(y_var_1) + + if count == 2: + ax1.relim() + ax1.autoscale_view() + + fig.canvas.draw() + fig.canvas.flush_events() + count = 0 + + count += 1 + +def main() -> None: + ... + +if __name__ == "__main__": + main() + \ No newline at end of file diff --git a/wellhub.code-workspace b/wellhub.code-workspace index 3552197..8672bf9 100644 --- a/wellhub.code-workspace +++ b/wellhub.code-workspace @@ -74,7 +74,8 @@ "netfwd": "cpp", "numbers": "cpp", "semaphore": "cpp", - "stop_token": "cpp" + "stop_token": "cpp", + "*.ipp": "cpp" } } } \ No newline at end of file From 8dfc3edbb215529b476e2c3016abe31ef7e679de Mon Sep 17 00:00:00 2001 From: MiroZ Date: Sun, 9 Jun 2024 14:27:26 -0700 Subject: [PATCH 2/5] working radar --- components/ld2410/.gitignore | 35 + components/ld2410/.piopm | 1 + components/ld2410/CMakeLists.txt | 15 + components/ld2410/LICENSE | 504 +++++++ components/ld2410/README.md | 89 ++ .../examples/basicSensor/basicSensor.ino | 59 + .../examples/setupSensor/setupSensor.ino | 277 ++++ components/ld2410/keywords.txt | 25 + components/ld2410/library.properties | 11 + components/ld2410/src/ld2410.cpp | 1338 +++++++++++++++++ components/ld2410/src/ld2410.h | 99 ++ main/App.cpp | 5 +- main/App.h | 2 + main/Buffers.cpp | 1 + main/Buffers.h | 100 ++ main/CMakeLists.txt | 2 +- main/TaskMgr.cpp | 5 + main/app_config.h | 16 +- main/sensors/Bme68x.cpp | 3 +- main/sensors/Bme68x.h | 1 + main/sensors/Bmp280.cpp | 4 +- main/sensors/Bmp280.h | 1 + main/sensors/LD2410.cpp | 18 + main/sensors/LD2410.h | 16 + main/sensors/Sensors.cpp | 60 +- main/sensors/Sensors.h | 6 +- sdkconfig.old | 130 +- 27 files changed, 2739 insertions(+), 84 deletions(-) create mode 100755 components/ld2410/.gitignore create mode 100755 components/ld2410/.piopm create mode 100755 components/ld2410/CMakeLists.txt create mode 100755 components/ld2410/LICENSE create mode 100755 components/ld2410/README.md create mode 100755 components/ld2410/examples/basicSensor/basicSensor.ino create mode 100755 components/ld2410/examples/setupSensor/setupSensor.ino create mode 100755 components/ld2410/keywords.txt create mode 100755 components/ld2410/library.properties create mode 100755 components/ld2410/src/ld2410.cpp create mode 100755 components/ld2410/src/ld2410.h create mode 100644 main/Buffers.cpp create mode 100644 main/Buffers.h create mode 100644 main/sensors/LD2410.cpp create mode 100644 main/sensors/LD2410.h diff --git a/components/ld2410/.gitignore b/components/ld2410/.gitignore new file mode 100755 index 0000000..2795dac --- /dev/null +++ b/components/ld2410/.gitignore @@ -0,0 +1,35 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Arduino +.development \ No newline at end of file diff --git a/components/ld2410/.piopm b/components/ld2410/.piopm new file mode 100755 index 0000000..0847ce8 --- /dev/null +++ b/components/ld2410/.piopm @@ -0,0 +1 @@ +{"type": "library", "name": "ld2410", "version": "0.1.3", "spec": {"owner": "ncmreynolds", "id": 14567, "name": "ld2410", "requirements": null, "uri": null}} \ No newline at end of file diff --git a/components/ld2410/CMakeLists.txt b/components/ld2410/CMakeLists.txt new file mode 100755 index 0000000..13a3054 --- /dev/null +++ b/components/ld2410/CMakeLists.txt @@ -0,0 +1,15 @@ +set(COMPONENT_SRCDIRS + "src" +) + +set(COMPONENT_ADD_INCLUDEDIRS + "src" +) + +set(COMPONENT_REQUIRES + "arduino" +) + +register_component() + +target_compile_options(${COMPONENT_TARGET} PRIVATE -fno-rtti) diff --git a/components/ld2410/LICENSE b/components/ld2410/LICENSE new file mode 100755 index 0000000..8000a6f --- /dev/null +++ b/components/ld2410/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/components/ld2410/README.md b/components/ld2410/README.md new file mode 100755 index 0000000..030b2bc --- /dev/null +++ b/components/ld2410/README.md @@ -0,0 +1,89 @@ +# LD2410 +## Introduction + +An Arduino library for the Hi-Link LD2410 24Ghz FMCW radar sensor. This sensor is a Frequency Modulated Continuous Wave radar, which makes it good for presence detection and its sensitivity at different ranges to both static and moving targets can be configured. + +![](ld2410andbreakout.jpg) + +The code in this library is based heavily off this [piece of work for ESPHome](https://github.com/rain931215/ESPHome-LD2410) and the manufacturer datasheet. + +The LD2410, as sold for configuration with the common breakout boards shown above communicates over serial at 256000 baud by default. This library allows you to configure and use the sensor over this serial connection. As the LD2410 is a device that uses a high baud rate, a microcontroller with a spare hardware UART for this communication is preferable to bit-banged software serial. + +The modules also provide an 'active high' output on the 'OUT' pin which can be used to signal presence, based off the settings configured. Once the modules are configured it is not necessary to use their UART, but it provides much more information. + +## Connections + +The module must be powered by 5V or higher, but does 3.3v I/O, please consider this when working with the module. + +![](ld2410pinout.jpg) + +The default header pitch is 1.27mm, half the size of the usual 0.1" hobbyist pin headers so you may need to buy some, or carefully de-solder the existing pins to use the module. + +![](ld2410pcb.jpg) + +If you have the breakout board, you can use the VCC, GND, TX and RX pins to work with the module. + +## Reading distances + +The LD2410 has a number of 'gates', each of which correspond to a distance of about 0.75m and many of the settings/measurements are calculated from this. + +You set the sensitivity at each 'gate' on a scale 0-100, any object that doesn't register above this scale is not reported on. The defaults do a good job of spotting an adult person and estimating distance. + +Both moving and stationary targets are detected separately, with a value for each in centimetres. The accuracy of this distance isn't amazing but given this sensor is targeted as a replacement for something like a passive infrared sensor it's a very big improvement. + +The minimal sketch to read distances is in the example 'basicSensor.ino'. + +## Configuring the sensor + +Each 'gate' has a sensitivity value for stationary and moving targets. You can also set a maximum gate that ignores readings beyond a certain gate for both stationary and moving targets and an 'idle timeout' for how long it reports on something after moving away. + +A sketch to configure the sensor is in the example 'setupSensor.ino' it's an interactive sketch that will take commands sent over the Serial monitor. It should demonstrate all the various bits of the configuration you can change. + +## Methods/variables + +Many of the configuration methods return a boolean value. This is because the protocol between the LD2410 and the microcontroller involves requesting the change and the LD2410 acknowledges this with success or failure. This means these methods are synchronous, they will block until the LD2410 responds with succeed/fail or the transaction times out after 100ms. + +The presence/distance readings report the most recent values as the LD2410 continuously streams data, which is processed by calling *read()* as often as is practical. + +``` +bool ld2410::begin(Stream &radarStream, bool waitForRadar = true) - You must supply a Stream for the UART (eg. Serial1 that the LD2410 is connected to) and by default it waits for the radar to respond so it feeds back if it is connected +void debug(Stream &debugStream) - Enables debugging output of the library on a Stream you pass it (eg. Serial) +void read() - You must call this frequently in your main loop to process incoming frames from the LD2410 +bool isConnected() - Is the LD2410 connected and sending data regularly +bool presenceDetected() - Is a presence detected. Nice and simple +bool stationaryTargetDetected() - Is a stationary target detected. +uint16_t stationaryTargetDistance() - Distance to the stationary target in centimetres. +uint8_t stationaryTargetEnergy() - The 'energy'of the target on a scale 0-100, which also a kind of confidence value. +bool movingTargetDetected() - Is a moving target detected. +uint16_t movingTargetDistance() - Distance to the moving target in centimetres. +uint8_t movingTargetEnergy() - The 'energy'of the target on a scale 0-100, which also a kind of confidence value. +bool requestFirmwareVersion() - Request the firmware version, which is then available on the values below. +uint8_t firmware_major_version +uint8_t firmware_minor_version +uint32_t firmware_bugfix_version - This is coded as HEX +bool requestCurrentConfiguration() - Request the full current configuration, which you can then read with the variable & methods below. +uint8_t max_gate - The max gate ID reported by the sensor +uint8_t max_moving_gate - The highest gate ID that will report moving targets +uint8_t max_stationary_gate - The highers gate ID that will report stationary targets +uint8_t motion_sensitivity[max_gate + 1] - One value 0-100 per gate +uint8_t stationary_sensitivity[max_gate + 1] - One value 0-100 per gate +bool setMaxValues(uint8_t moving, uint8_t stationary, uint16_t inactivityTimer) - Set furthest gates and inactivitity timer for targets +bool setGateSensitivity(uint8_t gate, uint8_t moving, uint8_t stationary) - Set gate sensitivites 0-100 +bool requestRestart() - Request a restart of the LD2410. Which is needed to apply some settings. +bool requestFactoryReset() - Request a factory reset of the LD2410. You need to restart afterwards to take effect. +bool requestStartEngineeringMode() - Request engineering mode, which sends more data on targets. +bool requestEndEngineeringMode() - Request the end of engineering mode. +``` + +## Changelog + +- v0.1.1 - Readings for stationary and moving targets were transposed, now fixed. Fixes #1 - stationaryTargetDetected() always true. Many improvements to parsing of commands/acks from the LD2410 and better debug logging. +- v0.1.0 - Initial release + +## Known issues/to-do list + +The code is somewhat verbose/inefficient. + +No support for engineering mode data yet. + +Feel free to contact me with PRs, suggestions and improvements. diff --git a/components/ld2410/examples/basicSensor/basicSensor.ino b/components/ld2410/examples/basicSensor/basicSensor.ino new file mode 100755 index 0000000..a2986b0 --- /dev/null +++ b/components/ld2410/examples/basicSensor/basicSensor.ino @@ -0,0 +1,59 @@ +/* + * Example sketch for reporting on readings from the LD2410 using whatever settings are currently configured. + * + * The sketch assumes an ESP32 board with the LD2410 connected as Serial1 to pins 8 & 9, the serial configuration for other boards may vary + * + */ + +#include + +ld2410 radar; + +uint32_t lastReading = 0; + +void setup(void) +{ + Serial.begin(115200); //Feedback over Serial Monitor + //radar.debug(Serial); //Uncomment to show debug information from the library on the Serial Monitor. By default this does not show sensor reads as they are very frequent. + Serial1.begin (256000, SERIAL_8N1, 9, 8); //UART for monitoring the radar + delay(500); + Serial.print(F("\nLD2410 radar sensor initialising: ")); + if(radar.begin(Serial1)) + { + Serial.println(F("OK")); + } + else + { + Serial.println(F("not connected")); + } +} + +void loop() +{ + radar.read(); + if(radar.isConnected() && millis() - lastReading > 1000) //Report every 1000ms + { + lastReading = millis(); + if(radar.presenceDetected()) + { + if(radar.stationaryTargetDetected()) + { + Serial.print(F("Stationary target: ")); + Serial.print(radar.stationaryTargetDistance()); + Serial.print(F("cm energy:")); + Serial.println(radar.stationaryTargetEnergy()); + } + if(radar.movingTargetDetected()) + { + Serial.print(F("Moving target: ")); + Serial.print(radar.movingTargetDistance()); + Serial.print(F("cm energy:")); + Serial.println(radar.movingTargetEnergy()); + } + } + else + { + Serial.println(F("No target")); + } + } +} diff --git a/components/ld2410/examples/setupSensor/setupSensor.ino b/components/ld2410/examples/setupSensor/setupSensor.ino new file mode 100755 index 0000000..f791639 --- /dev/null +++ b/components/ld2410/examples/setupSensor/setupSensor.ino @@ -0,0 +1,277 @@ +/* + * Example sketch to show using configuration commands on the LD2410. + * + * The sketch assumes an ESP32 board with the LD2410 connected as Serial1 to pins 8 & 9, the serial configuration for other boards may vary + * + */ + +#include + +ld2410 radar; +bool engineeringMode = false; +String command; + +void setup(void) +{ + Serial.begin(115200); //Feedback over Serial Monitor + delay(500); //Give a while for Serial Monitor to wake up + //radar.debug(Serial); //Uncomment to show debug information from the library on the Serial Monitor. By default this does not show sensor reads as they are very frequent. + Serial1.begin (256000, SERIAL_8N1, 9, 8); //UART for monitoring the radar + delay(500); + Serial.print(F("\nLD2410 radar sensor initialising: ")); + if(radar.begin(Serial1)) + { + Serial.println(F("OK")); + } + else + { + Serial.println(F("not connected")); + } + Serial.println(F("Supported commands\nread: read current values from the sensor\nreadconfig: read the configuration from the sensor\nsetmaxvalues \nsetsensitivity \nenableengineeringmode: enable engineering mode\ndisableengineeringmode: disable engineering mode\nrestart: restart the sensor\nreadversion: read firmware version\nfactoryreset: factory reset the sensor\n")); +} + +void loop() +{ + radar.read(); //Always read frames from the sensor + if(Serial.available()) + { + char typedCharacter = Serial.read(); + if(typedCharacter == '\r' || typedCharacter == '\n') + { + command.trim(); + if(command.equals("read")) + { + command = ""; + Serial.print(F("Reading from sensor: ")); + if(radar.isConnected()) + { + Serial.println(F("OK")); + if(radar.presenceDetected()) + { + if(radar.stationaryTargetDetected()) + { + Serial.print(F("Stationary target: ")); + Serial.print(radar.stationaryTargetDistance()); + Serial.print(F("cm energy: ")); + Serial.println(radar.stationaryTargetEnergy()); + } + if(radar.movingTargetDetected()) + { + Serial.print(F("Moving target: ")); + Serial.print(radar.movingTargetDistance()); + Serial.print(F("cm energy: ")); + Serial.println(radar.movingTargetEnergy()); + } + } + else + { + Serial.println(F("nothing detected")); + } + } + else + { + Serial.println(F("failed to read")); + } + } + else if(command.equals("readconfig")) + { + command = ""; + Serial.print(F("Reading configuration from sensor: ")); + if(radar.requestCurrentConfiguration()) + { + Serial.println(F("OK")); + Serial.print(F("Maximum gate ID: ")); + Serial.println(radar.max_gate); + Serial.print(F("Maximum gate for moving targets: ")); + Serial.println(radar.max_moving_gate); + Serial.print(F("Maximum gate for stationary targets: ")); + Serial.println(radar.max_stationary_gate); + Serial.print(F("Idle time for targets: ")); + Serial.println(radar.sensor_idle_time); + Serial.println(F("Gate sensitivity")); + for(uint8_t gate = 0; gate <= radar.max_gate; gate++) + { + Serial.print(F("Gate ")); + Serial.print(gate); + Serial.print(F(" moving targets: ")); + Serial.print(radar.motion_sensitivity[gate]); + Serial.print(F(" stationary targets: ")); + Serial.println(radar.stationary_sensitivity[gate]); + } + } + else + { + Serial.println(F("Failed")); + } + } + else if(command.startsWith("setmaxvalues")) + { + uint8_t firstSpace = command.indexOf(' '); + uint8_t secondSpace = command.indexOf(' ',firstSpace + 1); + uint8_t thirdSpace = command.indexOf(' ',secondSpace + 1); + uint8_t newMovingMaxDistance = (command.substring(firstSpace,secondSpace)).toInt(); + uint8_t newStationaryMaxDistance = (command.substring(secondSpace,thirdSpace)).toInt(); + uint16_t inactivityTimer = (command.substring(thirdSpace,command.length())).toInt(); + if(newMovingMaxDistance > 0 && newStationaryMaxDistance > 0 && newMovingMaxDistance <= 8 && newStationaryMaxDistance <= 8) + { + Serial.print(F("Setting max values to gate ")); + Serial.print(newMovingMaxDistance); + Serial.print(F(" moving targets, gate ")); + Serial.print(newStationaryMaxDistance); + Serial.print(F(" stationary targets, ")); + Serial.print(inactivityTimer); + Serial.print(F("s inactivity timer: ")); + command = ""; + if(radar.setMaxValues(newMovingMaxDistance, newStationaryMaxDistance, inactivityTimer)) + { + Serial.println(F("OK, now restart to apply settings")); + } + else + { + Serial.println(F("failed")); + } + } + else + { + Serial.print(F("Can't set distances to ")); + Serial.print(newMovingMaxDistance); + Serial.print(F(" moving ")); + Serial.print(newStationaryMaxDistance); + Serial.println(F(" stationary, try again")); + command = ""; + } + } + else if(command.startsWith("setsensitivity")) + { + uint8_t firstSpace = command.indexOf(' '); + uint8_t secondSpace = command.indexOf(' ',firstSpace + 1); + uint8_t thirdSpace = command.indexOf(' ',secondSpace + 1); + uint8_t gate = (command.substring(firstSpace,secondSpace)).toInt(); + uint8_t motionSensitivity = (command.substring(secondSpace,thirdSpace)).toInt(); + uint8_t stationarySensitivity = (command.substring(thirdSpace,command.length())).toInt(); + if(motionSensitivity >= 0 && stationarySensitivity >= 0 && motionSensitivity <= 100 && stationarySensitivity <= 100) + { + Serial.print(F("Setting gate ")); + Serial.print(gate); + Serial.print(F(" motion sensitivity to ")); + Serial.print(motionSensitivity); + Serial.print(F(" & stationary sensitivity to ")); + Serial.print(stationarySensitivity); + Serial.println(F(": ")); + command = ""; + if(radar.setGateSensitivityThreshold(gate, motionSensitivity, stationarySensitivity)) + { + Serial.println(F("OK, now restart to apply settings")); + } + else + { + Serial.println(F("failed")); + } + } + else + { + Serial.print(F("Can't set gate ")); + Serial.print(gate); + Serial.print(F(" motion sensitivity to ")); + Serial.print(motionSensitivity); + Serial.print(F(" & stationary sensitivity to ")); + Serial.print(stationarySensitivity); + Serial.println(F(", try again")); + command = ""; + } + } + else if(command.equals("enableengineeringmode")) + { + command = ""; + Serial.print(F("Enabling engineering mode: ")); + if(radar.requestStartEngineeringMode()) + { + Serial.println(F("OK")); + } + else + { + Serial.println(F("failed")); + } + } + else if(command.equals("disableengineeringmode")) + { + command = ""; + Serial.print(F("Disabling engineering mode: ")); + if(radar.requestEndEngineeringMode()) + { + Serial.println(F("OK")); + } + else + { + Serial.println(F("failed")); + } + } + else if(command.equals("restart")) + { + command = ""; + Serial.print(F("Restarting sensor: ")); + if(radar.requestRestart()) + { + Serial.println(F("OK")); + } + else + { + Serial.println(F("failed")); + } + } + else if(command.equals("readversion")) + { + command = ""; + Serial.print(F("Requesting firmware version: ")); + if(radar.requestFirmwareVersion()) + { + Serial.print('v'); + Serial.print(radar.firmware_major_version); + Serial.print('.'); + Serial.print(radar.firmware_minor_version); + Serial.print('.'); + Serial.println(radar.firmware_bugfix_version,HEX); + } + else + { + Serial.println(F("Failed")); + } + } + else if(command.equals("factoryreset")) + { + command = ""; + Serial.print(F("Factory resetting sensor: ")); + if(radar.requestFactoryReset()) + { + Serial.println(F("OK, now restart sensor to take effect")); + } + else + { + Serial.println(F("failed")); + } + } + else + { + Serial.print(F("Unknown command: ")); + Serial.println(command); + command = ""; + } + } + else + { + command += typedCharacter; + } + } + /* + if() //Some data has been received from the radar + { + if(radar.presenceDetected()) + { + Serial.print(F("Stationary target: ")); + Serial.println(radar.stationaryTargetDistance()); + Serial.print(F("Moving target: ")); + Serial.println(radar.movingTargetDistance()); + } + } + */ +} diff --git a/components/ld2410/keywords.txt b/components/ld2410/keywords.txt new file mode 100755 index 0000000..376ef1d --- /dev/null +++ b/components/ld2410/keywords.txt @@ -0,0 +1,25 @@ +ld2410 KEYWORD1 + +begin KEYWORD2 +debug KEYWORD2 +isConnected KEYWORD2 +read KEYWORD2 +presenceDetected KEYWORD2 +stationaryTargetDetected KEYWORD2 +stationaryTargetDistance KEYWORD2 +stationaryTargetEnergy KEYWORD2 +movingTargetDetected KEYWORD2 +movingTargetDistance KEYWORD2 +movingTargetEnergy KEYWORD2 +requestFirmwareVersion +requestCurrentConfiguration +requestRestart KEYWORD2 +requestFactoryReset KEYWORD2 +requestStartEngineeringMode KEYWORD2 +requestEndEngineeringMode KEYWORD2 +setMaxValues KEYWORD2 +setGateSensitivityThreshold KEYWORD2 + +firmware_major_version LITERAL1 +firmware_minor_version LITERAL1 +firmware_bugfix_version LITERAL1 \ No newline at end of file diff --git a/components/ld2410/library.properties b/components/ld2410/library.properties new file mode 100755 index 0000000..aba1149 --- /dev/null +++ b/components/ld2410/library.properties @@ -0,0 +1,11 @@ +name=ld2410 +version=0.1.3 +author=Nick Reynolds +maintainer=Nick Reynolds +sentence=An Arduino library for the Hi-Link LD2410 24Ghz FMCW radar sensor. +paragraph= This sensor is a Frequency Modulated Continuous Wave radar, which makes it good for presence detection and its sensitivity at different ranges to both static and moving targets can be configured. +category=Sensors +url=https://github.com/ncmreynolds/ld2410 +depends= +includes=ld2410.h +architectures=* \ No newline at end of file diff --git a/components/ld2410/src/ld2410.cpp b/components/ld2410/src/ld2410.cpp new file mode 100755 index 0000000..e37db02 --- /dev/null +++ b/components/ld2410/src/ld2410.cpp @@ -0,0 +1,1338 @@ +/* + * An Arduino library for the Hi-Link LD2410 24Ghz FMCW radar sensor. + * + * This sensor is a Frequency Modulated Continuous Wave radar, which makes it good for presence detection and its sensitivity at different ranges to both static and moving targets can be configured. + * + * The code in this library is based off the manufacturer datasheet and reading of this initial piece of work for ESPHome https://github.com/rain931215/ESPHome-LD2410. + * + * https://github.com/ncmreynolds/ld2410 + * + * Released under LGPL-2.1 see https://github.com/ncmreynolds/ld2410/LICENSE for full license + * Modified by Robert Zmrzli + */ +#ifndef ld2410_cpp +#define ld2410_cpp +#include "ld2410.h" + + +ld2410::ld2410() //Constructor function +{ +} + +ld2410::~ld2410() //Destructor function +{ +} + +bool ld2410::begin(Stream &radarStream, bool waitForRadar) { + radar_uart_ = &radarStream; //Set the stream used for the LD2410 + if(debug_uart_ != nullptr) + { + debug_uart_->println(F("ld2410 started")); + } + if(waitForRadar) + { + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nLD2410 firmware: ")); + } + if(requestFirmwareVersion()) + { + if(debug_uart_ != nullptr) + { + debug_uart_->print(F(" v")); + debug_uart_->print(firmware_major_version); + debug_uart_->print('.'); + debug_uart_->print(firmware_minor_version); + debug_uart_->print('.'); + debug_uart_->print(firmware_bugfix_version); + debug_uart_->print(F("\nEnabling engineering mode: ")); + } + } + if(requestStartEngineeringMode()) { + if(debug_uart_ != nullptr) { + debug_uart_->print(F(" E OK")); + } + return true; + } + else + { + if(debug_uart_ != nullptr) + { + debug_uart_->print(F(" E no response")); + } + } + } + else + { + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nLD2410 library configured")); + } + return true; + } + return false; +} + +void ld2410::debug(Stream &terminalStream) +{ + debug_uart_ = &terminalStream; //Set the stream used for the terminal + #if defined(ESP8266) + if(&terminalStream == &Serial) + { + debug_uart_->write(17); //Send an XON to stop the hung terminal after reset on ESP8266 + } + #endif +} + +bool ld2410::isConnected() +{ + if(millis() - radar_uart_last_packet_ < radar_uart_timeout) //Use the last reading + { + return true; + } + if(read_frame_()) //Try and read a frame if the current reading is too old + { + return true; + } + return false; +} + +bool ld2410::read() +{ + return read_frame_(); +} + +bool ld2410::presenceDetected() +{ + return target_type_ != 0; +} + +bool ld2410::stationaryTargetDetected() +{ + if((target_type_ & 0x02) && stationary_target_distance_ > 0 && stationary_target_energy_ > 0) + { + return true; + } + return false; +} + +uint16_t ld2410::stationaryTargetDistance() +{ + //if(stationary_target_energy_ > 0) + { + return stationary_target_distance_; + } + //return 0; +} + +uint8_t ld2410::stationaryTargetEnergy() +{ + //if(stationary_target_distance_ > 0) + { + return stationary_target_energy_; + } + //return 0; +} + +bool ld2410::movingTargetDetected() +{ + if((target_type_ & 0x01) && moving_target_distance_ > 0 && moving_target_energy_ > 0) + { + return true; + } + return false; +} + +uint16_t ld2410::movingTargetDistance() +{ + //if(moving_target_energy_ > 0) + { + return moving_target_distance_; + } + //return 0; +} + +uint8_t ld2410::movingTargetEnergy() +{ + //if(moving_target_distance_ > 0) + { + return moving_target_energy_; + } + //return 0; +} + +bool ld2410::read_frame_() +{ + uint8_t byte_read_ = 0; + if(radar_uart_ -> available()) + { + byte_read_ = radar_uart_ -> read(); + + #ifdef LD2410_DEBUG_RAW + if(debug_uart_ != nullptr) + { + if(byte_read_ < 0x10) + { + debug_uart_->print('0'); + } + debug_uart_->print(byte_read_, HEX); + debug_uart_->print(' '); + } + #endif + + if(frame_started_ == false) + { + radar_data_frame_position_ = 0; + //if(byte_read_ == 0xF4 && getting_response == 0) + if(byte_read_ == 0xF4) + { + #ifdef LD2410_DEBUG_DATA + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\n< : F4 ")); + } + #endif + radar_data_frame_[radar_data_frame_position_++] = byte_read_; + frame_started_ = true; + ack_frame_ = false; + } + else if(byte_read_ == 0xFD) + { + // #ifdef LD2410_DEBUG_COMMANDS + // if(debug_uart_ != nullptr) + // { + // debug_uart_->print(F("\n< : FD ")); + // } + // #endif + radar_data_frame_[radar_data_frame_position_++] = byte_read_; + frame_started_ = true; + ack_frame_ = true; + } + } + else + { + + if(radar_data_frame_position_ < LD2410_MAX_FRAME_LENGTH) + { + + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr && ack_frame_ == true) + { + if(radar_data_frame_position_ < 0x10) + { + debug_uart_->print('0'); + } + debug_uart_->print(radar_data_frame_position_, HEX); + debug_uart_->print(' '); + } + #endif + radar_data_frame_[radar_data_frame_position_++] = byte_read_; + //print_frame_(); + if(radar_data_frame_position_ > 7) //Can check for start and end + { + if( radar_data_frame_[0] == 0xF4 && //Data frame end state + radar_data_frame_[1] == 0xF3 && + radar_data_frame_[2] == 0xF2 && + radar_data_frame_[3] == 0xF1 && + radar_data_frame_[radar_data_frame_position_ - 4] == 0xF8 && + radar_data_frame_[radar_data_frame_position_ - 3] == 0xF7 && + radar_data_frame_[radar_data_frame_position_ - 2] == 0xF6 && + radar_data_frame_[radar_data_frame_position_ - 1] == 0xF5 + ) + { + //debug_uart_->print(F("\ndata frame found!")); + if(parse_data_frame_()) + { + #ifdef LD2410_DEBUG_DATA + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("parsed data OK")); + } + #endif + frame_started_ = false; + radar_data_frame_position_ = 0; + return true; + } + else + { + #ifdef LD2410_DEBUG_DATA + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("failed to parse data")); + } + #endif + frame_started_ = false; + radar_data_frame_position_ = 0; + } + } + else if(radar_data_frame_[0] == 0xFD && //Command frame end state + radar_data_frame_[1] == 0xFC && + radar_data_frame_[2] == 0xFB && + radar_data_frame_[3] == 0xFA && + radar_data_frame_[radar_data_frame_position_ - 4] == 0x04 && + radar_data_frame_[radar_data_frame_position_ - 3] == 0x03 && + radar_data_frame_[radar_data_frame_position_ - 2] == 0x02 && + radar_data_frame_[radar_data_frame_position_ - 1] == 0x01 + ) + { + if(parse_command_frame_()) + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("parsed command OK")); + } + #endif + frame_started_ = false; + radar_data_frame_position_ = 0; + getting_response = 0; + return true; + } + else + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("failed to parse command")); + } + #endif + frame_started_ = false; + radar_data_frame_position_ = 0; + getting_response = 0; + } + } + } + } + else + { + #if defined(LD2410_DEBUG_DATA) || defined(LD2410_DEBUG_COMMANDS) + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nLD2410 frame overran")); + } + #endif + frame_started_ = false; + radar_data_frame_position_ = 0; + } + } + } + return false; +} + +void ld2410::print_frame_() +{ + if(debug_uart_ != nullptr) + { + if(ack_frame_ == true) + { + debug_uart_->print(F("\n < Cmnd : ")); + } + else + { + debug_uart_->print(F("\n < Data: ")); + } + uint8_t frame_length = radar_data_frame_position_; + for(uint8_t i = 0; i < frame_length; i ++) + { + if(radar_data_frame_[i] < 0x10) + { + debug_uart_->print('0'); + } + debug_uart_->print(radar_data_frame_[i],HEX); + debug_uart_->print(' '); + } + // + debug_uart_->println(""); + } +} + +void ld2410::resetGates() { + + for(uint8_t i = 0; i < 10 ; i ++) + { + motion_energy[i] = 0; + stationary_energy[i] = 0; + } + for(uint8_t i = 10; i < 14 ; i ++) + { + motion_energy[i] = 0; + } +} + +bool ld2410::parse_data_frame_() +{ + uint16_t intra_frame_data_length_ = radar_data_frame_[4] + (radar_data_frame_[5] << 8); + if(radar_data_frame_position_ == intra_frame_data_length_ + 10) + { + #ifdef LD2410_DEBUG_DATA + if(debug_uart_ != nullptr && ack_frame_ == false) + { + debug_uart_->print(F("\n @1 : ")); + print_frame_(); + } + else if(debug_uart_ != nullptr){ + debug_uart_->print(F("\n @2 : ")); + } + + #endif + + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr && ack_frame_ == true) + { + print_frame_(); + } + #endif + if(radar_data_frame_[6] == 0x01 && radar_data_frame_[7] == 0xAA) //Engineering mode data + { //engineering report + target_type_ = radar_data_frame_[8]; + #ifdef LD2410_DEBUG_PARSE + if(debug_uart_ != nullptr) + { + //debug_uart_->print(F("\nEngineering data - ")); + if(target_type_ == 0x00) + { + //debug_uart_->print(F("no target")); + } + else if(target_type_ == 0x01) + { + debug_uart_->println(F("moving target:")); + } + else if(target_type_ == 0x02) + { + //debug_uart_->print(F("stationary target:")); + } + else if(target_type_ == 0x03) + { + //debug_uart_->println(F("moving & stationary targets:")); + } + } + #endif + motion_energy[0] = motion_energy[0] + 1; + #ifdef LD2410_DEBUG_PARSE + if(debug_uart_ != nullptr){ + debug_uart_->print("ME: "); + debug_uart_->print( motion_energy[0]); + } + #endif + motion_energy[1+target_type_] = motion_energy[1+target_type_] + 1; + for(uint8_t gate = 1; gate <= 9; gate++) { + motion_energy[gate+4] = motion_energy[gate+4] + radar_data_frame_[18+gate]; + } + stationary_energy[0] = stationary_energy[0] + 1; + for(uint8_t gate = 1; gate <= 9; gate++) { + stationary_energy[gate] = stationary_energy[gate] + radar_data_frame_[27+gate]; + } + + radar_uart_last_packet_ = millis(); + return true; + + } + else if(intra_frame_data_length_ == 13 && radar_data_frame_[6] == 0x02 && radar_data_frame_[7] == 0xAA && radar_data_frame_[17] == 0x55 && radar_data_frame_[18] == 0x00) //Normal target data + { //normal report + target_type_ = radar_data_frame_[8]; + //moving_target_distance_ = radar_data_frame_[9] + (radar_data_frame_[10] << 8); + stationary_target_distance_ = radar_data_frame_[9] + (radar_data_frame_[10] << 8); + stationary_target_energy_ = radar_data_frame_[14]; + moving_target_energy_ = radar_data_frame_[11]; + //stationary_target_distance_ = radar_data_frame_[12] + (radar_data_frame_[13] << 8); + moving_target_distance_ = radar_data_frame_[15] + (radar_data_frame_[16] << 8); + #ifdef LD2410_DEBUG_PARSE + if(debug_uart_ != nullptr) + { + //debug_uart_->print(F("\nNormal data - ")); + if(target_type_ == 0x00) + { + debug_uart_->println(F("\nno target")); + } + else if(target_type_ == 0x01) + { + debug_uart_->println(F("\nmoving target:")); + } + else if(target_type_ == 0x02) + { + //debug_uart_->print(F("stationary target:")); + } + else if(target_type_ == 0x03) + { + //debug_uart_->println(F("\nmoving & stationary targets:")); + } + if(radar_data_frame_[8] & 0x01) + { + //debug_uart_->print(F(" moving at ")); + //debug_uart_->print(moving_target_distance_); + //debug_uart_->print(F("cm power ")); + //debug_uart_->print(moving_target_energy_); + } + if(radar_data_frame_[8] & 0x02) + { + //debug_uart_->print(F(" stationary at ")); + //debug_uart_->print(stationary_target_distance_); + //debug_uart_->print(F("cm power ")); + //debug_uart_->print(stationary_target_energy_); + } + } + #endif + radar_uart_last_packet_ = millis(); + return true; + } + else + { + #ifdef LD2410_DEBUG_DATA + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nUnknown frame type")); + } + #endif + //print_frame_(); + } + } + else + { + #ifdef LD2410_DEBUG_DATA + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nFrame length unexpected: ")); + debug_uart_->print(radar_data_frame_position_); + debug_uart_->print(F(" not ")); + debug_uart_->print(intra_frame_data_length_ + 10); + } + #endif + } + return false; +} + +bool ld2410::parse_command_frame_() +{ + uint16_t intra_frame_data_length_ = radar_data_frame_[4] + (radar_data_frame_[5] << 8); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + //print_frame_(); + debug_uart_->print(F("\nACK frame payload: ")); + debug_uart_->print(intra_frame_data_length_); + debug_uart_->print(F(" bytes")); + debug_uart_->print(F("\nparsed command ")); + } + #endif + + //print_frame_(); + latest_ack_ = radar_data_frame_[6]; + latest_command_success_ = (radar_data_frame_[8] == 0x00 && radar_data_frame_[9] == 0x00); + if(intra_frame_data_length_ == 8 && latest_ack_ == 0xFF) + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nACK for entering configuration mode: ")); + } + #endif + if(latest_command_success_) + { + radar_uart_last_packet_ = millis(); + if(debug_uart_ != nullptr) + { + debug_uart_->print(F(" OK")); + } + return true; + } + else + { + if(debug_uart_ != nullptr) + { + debug_uart_->print(F(" failed")); + } + return false; + } + } + else if(intra_frame_data_length_ == 4 && latest_ack_ == 0xFE) + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nACK for leaving configuration mode: ")); + } + #endif + if(latest_command_success_) + { + radar_uart_last_packet_ = millis(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("OK")); + } + #endif + return true; + } + else + { + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("failed")); + } + return false; + } + } + else if(intra_frame_data_length_ == 4 && latest_ack_ == 0x60) + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nACK for setting max values: ")); + } + #endif + if(latest_command_success_) + { + radar_uart_last_packet_ = millis(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("OK")); + } + #endif + return true; + } + else + { + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("failed")); + } + return false; + } + } + else if(intra_frame_data_length_ == 28 && latest_ack_ == 0x61) + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nACK for current configuration: ")); + } + #endif + if(latest_command_success_) + { + radar_uart_last_packet_ = millis(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("OK")); + } + #endif + max_gate = radar_data_frame_[11]; + max_moving_gate = radar_data_frame_[12]; + max_stationary_gate = radar_data_frame_[13]; + motion_sensitivity[0] = radar_data_frame_[14]; + motion_sensitivity[1] = radar_data_frame_[15]; + motion_sensitivity[2] = radar_data_frame_[16]; + motion_sensitivity[3] = radar_data_frame_[17]; + motion_sensitivity[4] = radar_data_frame_[18]; + motion_sensitivity[5] = radar_data_frame_[19]; + motion_sensitivity[6] = radar_data_frame_[20]; + motion_sensitivity[7] = radar_data_frame_[21]; + motion_sensitivity[8] = radar_data_frame_[22]; + stationary_sensitivity[0] = radar_data_frame_[23]; + stationary_sensitivity[1] = radar_data_frame_[24]; + stationary_sensitivity[2] = radar_data_frame_[25]; + stationary_sensitivity[3] = radar_data_frame_[26]; + stationary_sensitivity[4] = radar_data_frame_[27]; + stationary_sensitivity[5] = radar_data_frame_[28]; + stationary_sensitivity[6] = radar_data_frame_[29]; + stationary_sensitivity[7] = radar_data_frame_[30]; + stationary_sensitivity[8] = radar_data_frame_[31]; + sensor_idle_time = radar_data_frame_[32]; + sensor_idle_time += (radar_data_frame_[33] << 8); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nMax gate distance: ")); + debug_uart_->print(max_gate); + debug_uart_->print(F("\nMax motion detecting gate distance: ")); + debug_uart_->print(max_moving_gate); + debug_uart_->print(F("\nMax stationary detecting gate distance: ")); + debug_uart_->print(max_stationary_gate); + debug_uart_->print(F("\nSensitivity per gate")); + for(uint8_t i = 0; i < 9; i++) + { + debug_uart_->print(F("\nGate ")); + debug_uart_->print(i); + debug_uart_->print(F(" (")); + debug_uart_->print(i * 0.75); + debug_uart_->print('-'); + debug_uart_->print((i+1) * 0.75); + debug_uart_->print(F(" metres) Motion: ")); + debug_uart_->print(motion_sensitivity[i]); + debug_uart_->print(F(" Stationary: ")); + debug_uart_->print(stationary_sensitivity[i]); + + } + debug_uart_->print(F("\nSensor idle timeout: ")); + debug_uart_->print(sensor_idle_time); + debug_uart_->print('s'); + } + #endif + return true; + } + else + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("failed")); + } + #endif + return false; + } + } + else if(intra_frame_data_length_ == 4 && latest_ack_ == 0x64) + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nACK for setting sensitivity values: ")); + } + #endif + if(latest_command_success_) + { + radar_uart_last_packet_ = millis(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("OK")); + } + #endif + return true; + } + else + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("failed")); + } + #endif + return false; + } + } + else if(intra_frame_data_length_ == 12 && latest_ack_ == 0xA0) + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nACK for firmware version: ")); + } + #endif + if(latest_command_success_) + { + firmware_major_version = radar_data_frame_[13]; + firmware_minor_version = radar_data_frame_[12]; + firmware_bugfix_version = radar_data_frame_[14]; + firmware_bugfix_version += radar_data_frame_[15]<<8; + firmware_bugfix_version += radar_data_frame_[16]<<16; + firmware_bugfix_version += radar_data_frame_[17]<<24; + radar_uart_last_packet_ = millis(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("OK")); + } + #endif + return true; + } + else + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("failed")); + } + #endif + return false; + } + } + else if(intra_frame_data_length_ == 4 && latest_ack_ == 0xA2) + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nACK for factory reset: ")); + } + #endif + if(latest_command_success_) + { + radar_uart_last_packet_ = millis(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("OK")); + } + #endif + return true; + } + else + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("failed")); + } + #endif + return false; + } + } + else if(intra_frame_data_length_ == 4 && latest_ack_ == 0xA3) + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nACK for restart: ")); + } + #endif + if(latest_command_success_) + { + radar_uart_last_packet_ = millis(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("OK")); + } + #endif + return true; + } + else + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("failed")); + } + #endif + return false; + } + } + else if(intra_frame_data_length_ == 4 && latest_ack_ == 0x62) + { + return true; + } + else + { + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\nUnknown ACK")); + } + #endif + } + return false; +} + +void ld2410::SendToRadar(uint8_t to_send) { + radar_uart_->write((byte)to_send); + + // #ifdef LD2410_DEBUG_COMMANDS + // if(debug_uart_ != nullptr) + // { + // if(to_send < 0x10) + // { + // debug_uart_->print('0'); + // } + // debug_uart_->print(to_send, HEX); + // debug_uart_->print(' '); + // } + // #endif +} + +void ld2410::send_command_preamble_() +{ + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + debug_uart_->print("Sending: "); + #endif + //Command preamble + radar_uart_->write((byte)0xFD); + + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(" FD"); + } + #endif + + radar_uart_->write((byte)0xFC); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(" FC"); + } + #endif + radar_uart_->write((byte)0xFB); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(" FB"); + } + #endif + radar_uart_->write((byte)0xFA); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(" FA"); + } + #endif +} + +void ld2410::send_command_postamble_() +{ + //Command end + radar_uart_->write((byte)0x04); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 04"); + } + #endif + radar_uart_->write((byte)0x03); + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 03"); + } + + radar_uart_->write((byte)0x02); + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 02"); + } + + radar_uart_->write((byte)0x01); + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 01"); + } +} + + +bool ld2410::enter_configuration_mode_() +{ + //Serial.print(F("\nenter_configuration_mode_")); + send_command_preamble_(); + //Request firmware + radar_uart_->write((byte) 0x04); //Command is four bytes long + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 04"); + } + radar_uart_->write((byte) 0x00); + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 00"); + } + radar_uart_->write((byte) 0xFF); //Request enter command mode + if(debug_uart_ != nullptr) + { + debug_uart_->print(" FF"); + } + radar_uart_->write((byte) 0x00); + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 00"); + } + radar_uart_->write((byte) 0x01); + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 01"); + } + radar_uart_->write((byte) 0x00); + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 00"); + } + send_command_postamble_(); + frame_started_ = false; + radar_data_frame_position_ = 0; + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if(read_frame_()) + { + //debug_uart_->print(F("\nFrame read!")); + if(latest_ack_ == 0xFF && latest_command_success_) + { + //Serial.println(" OK"); + return true; + } + } + } + + //Serial.println(" NOK"); + return false; +} + +bool ld2410::leave_configuration_mode_() +{ + //Serial.print(F("\nleave_configuration_mode_")); + send_command_preamble_(); + //Request firmware + radar_uart_->write((byte) 0x02); //Command is four bytes long + radar_uart_->write((byte) 0x00); + radar_uart_->write((byte) 0xFE); //Request leave command mode + radar_uart_->write((byte) 0x00); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if(read_frame_()) + { + if(latest_ack_ == 0xFE && latest_command_success_) + { + //Serial.println(" OK"); + return true; + } + } + } + //Serial.println(" NOK"); + return false; +} + +bool ld2410::requestStartEngineeringMode() +{ + + if(enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + //Request firmware + radar_uart_->write((byte) 0x02); //Command is four bytes long + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 02"); + } + radar_uart_->write((byte) 0x00); + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 00"); + } + radar_uart_->write((byte) 0x62); //Request enter command mode + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 62"); + } + radar_uart_->write((byte) 0x00); + if(debug_uart_ != nullptr) + { + debug_uart_->print(" 00"); + } + send_command_postamble_(); + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if(read_frame_()) + { + if(latest_ack_ == 0x62 && latest_command_success_) + { + delay(50); + leave_configuration_mode_(); + return true; + } + } + } + } + else { + delay(50); + leave_configuration_mode_(); + return false; + } + + delay(50); + leave_configuration_mode_(); + return false; +} + +bool ld2410::requestEndEngineeringMode() +{ + send_command_preamble_(); + //Request firmware + radar_uart_->write((byte) 0x02); //Command is four bytes long + radar_uart_->write((byte) 0x00); + radar_uart_->write((byte) 0x63); //Request leave command mode + radar_uart_->write((byte) 0x00); + send_command_postamble_(); + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if(read_frame_()) + { + if(latest_ack_ == 0x63 && latest_command_success_) + { + return true; + } + } + } + return false; +} + +void ld2410::Marker(uint8_t state) +{ + radar_uart_->write((byte)0xAA); + radar_uart_->write((byte)state); + radar_uart_->write((byte)0x55); +} + + +bool ld2410::requestCurrentConfiguration() +{ + if(enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + //Request firmware + SendToRadar(0x02); //Command is two bytes long + SendToRadar(0x00); + SendToRadar(0x61); //Request current configuration + SendToRadar(0x00); + send_command_postamble_(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\n> Out : FDFCFBFA 02 00 61 00 04030201")); + } + #endif + + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if(read_frame_()) + { + if(latest_ack_ == 0x61 && latest_command_success_) + { + delay(50); + leave_configuration_mode_(); + return true; + } + } + } + } + delay(50); + leave_configuration_mode_(); + return false; +} + +bool ld2410::requestFirmwareVersion() +{ + if(enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + //Request firmware + SendToRadar(0x02); //Command is two bytes long + SendToRadar(0x00); + SendToRadar(0xA0); //Request firmware version + SendToRadar(0x00); + send_command_postamble_(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\n> Out : FDFCFBFA 02 00 A0 00 04030201")); + } + #endif + + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + read_frame_(); + if(latest_ack_ == 0xA0 && latest_command_success_) + { + delay(50); + leave_configuration_mode_(); + return true; + } + } + } + delay(50); + leave_configuration_mode_(); + return false; +} + +bool ld2410::requestRestart() +{ + if(enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + //Request firmware + SendToRadar(0x02); //Command is two bytes long + SendToRadar(0x00); + SendToRadar(0xA3); //Request restart + SendToRadar(0x00); + send_command_postamble_(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\n> Out : FDFCFBFA 02 00 A3 00 04030201")); + } + #endif + + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if(read_frame_()) + { + if(latest_ack_ == 0xA3 && latest_command_success_) + { + delay(50); + leave_configuration_mode_(); + return true; + } + } + } + } + delay(50); + leave_configuration_mode_(); + return false; +} + +bool ld2410::requestFactoryReset() +{ + if(enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + //Request firmware + SendToRadar(0x02); //Command is two bytes long + SendToRadar(0x00); + SendToRadar(0xA2); //Request factory reset + SendToRadar(0x00); + send_command_postamble_(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\n> Out : FDFCFBFA 02 00 A2 00 04030201")); + } + #endif + + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if(read_frame_()) + { + if(latest_ack_ == 0xA2 && latest_command_success_) + { + delay(50); + leave_configuration_mode_(); + return true; + } + } + } + } + delay(50); + leave_configuration_mode_(); + return false; +} + +bool ld2410::setMaxValues(uint16_t moving, uint16_t stationary, uint16_t inactivityTimer) +{ + if(enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + SendToRadar(0x14); //Command is 20 bytes long + SendToRadar(0x00); + SendToRadar(0x60); //Request set max values + SendToRadar(0x00); + SendToRadar(0x00); //Moving gate command + SendToRadar(0x00); + SendToRadar(char(moving & 0x00FF)); //Moving gate value + SendToRadar(char((moving & 0xFF00)>>8)); + SendToRadar(0x00); //Spacer + SendToRadar(0x00); + SendToRadar(0x01); //Stationary gate command + SendToRadar(0x00); + SendToRadar(char(stationary & 0x00FF)); //Stationary gate value + SendToRadar(char((stationary & 0xFF00)>>8)); + SendToRadar(0x00); //Spacer + SendToRadar(0x00); + SendToRadar(0x02); //Inactivity timer command + SendToRadar(0x00); + SendToRadar(char(inactivityTimer & 0x00FF)); //Inactivity timer + SendToRadar(char((inactivityTimer & 0xFF00)>>8)); + SendToRadar(0x00); //Spacer + SendToRadar(0x00); + send_command_postamble_(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\n> Out : A lot!!!")); + } + #endif + + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if(read_frame_()) + { + if(latest_ack_ == 0x60 && latest_command_success_) + { + delay(50); + leave_configuration_mode_(); + return true; + } + } + } + } + delay(50); + leave_configuration_mode_(); + return false; +} + +bool ld2410::setGateSensitivityThreshold(uint8_t gate, uint8_t moving, uint8_t stationary) +{ + if(enter_configuration_mode_()) + { + delay(50); + send_command_preamble_(); + SendToRadar(0x14); //Command is 20 bytes long + SendToRadar(0x00); + SendToRadar(0x64); //Request set sensitivity values + SendToRadar(0x00); + SendToRadar(0x00); //Gate command + SendToRadar(0x00); + SendToRadar(char(gate)); //Gate value + SendToRadar(0x00); + SendToRadar(0x00); //Spacer + SendToRadar(0x00); + SendToRadar(0x01); //Motion sensitivity command + SendToRadar(0x00); + SendToRadar(char(moving)); //Motion sensitivity value + SendToRadar(0x00); + SendToRadar(0x00); //Spacer + SendToRadar(0x00); + SendToRadar(0x02); //Stationary sensitivity command + SendToRadar(0x00); + SendToRadar(char(stationary)); //Stationary sensitivity value + SendToRadar(0x00); + SendToRadar(0x00); //Spacer + SendToRadar(0x00); + send_command_postamble_(); + #ifdef LD2410_DEBUG_COMMANDS + if(debug_uart_ != nullptr) + { + debug_uart_->print(F("\n> Out : Also a lot!!!")); + } + #endif + + radar_uart_last_command_ = millis(); + while(millis() - radar_uart_last_command_ < radar_uart_command_timeout_) + { + if(read_frame_()) + { + if(latest_ack_ == 0x64 && latest_command_success_) + { + delay(50); + leave_configuration_mode_(); + return true; + } + } + } + } + delay(50); + leave_configuration_mode_(); + return false; +} +#endif \ No newline at end of file diff --git a/components/ld2410/src/ld2410.h b/components/ld2410/src/ld2410.h new file mode 100755 index 0000000..fae96ff --- /dev/null +++ b/components/ld2410/src/ld2410.h @@ -0,0 +1,99 @@ +/* + * An Arduino library for the Hi-Link LD2410 24Ghz FMCW radar sensor. + * + * This sensor is a Frequency Modulated Continuous Wave radar, which makes it good for presence detection and its sensitivity at different ranges to both static and moving targets can be configured. + * + * The code in this library is based off the manufacturer datasheet and reading of this initial piece of work for ESPHome https://github.com/rain931215/ESPHome-LD2410. + * + * https://github.com/ncmreynolds/ld2410 + * + * Released under LGPL-2.1 see https://github.com/ncmreynolds/ld2410/LICENSE for full license + * Modified by Robert Zmrzli + */ +#ifndef ld2410_h +#define ld2410_h +#include +#define LD2410_MAX_FRAME_LENGTH 50 +#define LD2410_DEBUG_DATA +//#define LD2410_DEBUG_RAW +//#define LD2410_DEBUG_COMMANDS +//#define LD2410_DEBUG_PARSE + + + +class ld2410 { + + public: + ld2410(); //Constructor function + ~ld2410(); //Destructor function + bool begin(Stream &, bool waitForRadar = true); //Start the ld2410 + void SendToRadar(uint8_t to_send); + void debug(Stream &); //Start debugging on a stream + bool isConnected(); + bool read(); + bool presenceDetected(); + bool stationaryTargetDetected(); + uint16_t stationaryTargetDistance(); + uint8_t stationaryTargetEnergy(); + bool movingTargetDetected(); + uint16_t movingTargetDistance(); + uint8_t movingTargetEnergy(); + bool requestFirmwareVersion(); //Request the firmware version + uint8_t firmware_major_version = 0; //Reported major version + uint8_t firmware_minor_version = 0; //Reported minor version + uint32_t firmware_bugfix_version = 0; //Reported bugfix version (coded as hex) + bool requestCurrentConfiguration(); //Request current configuration + uint8_t max_gate = 0; + uint8_t max_moving_gate = 0; + uint8_t max_stationary_gate = 0; + uint16_t sensor_idle_time = 0; + uint8_t motion_sensitivity[9] = {0,0,0,0,0,0,0,0,0}; + uint8_t stationary_sensitivity[9] = {0,0,0,0,0,0,0,0,0}; + + float motion_energy[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //index 0 is counter 1-4 are target type + float stationary_energy[10] = {0,0,0,0,0,0,0,0,0,0}; + + bool requestRestart(); + bool requestFactoryReset(); + bool requestStartEngineeringMode(); + void Marker(uint8_t state); + bool requestEndEngineeringMode(); + bool setMaxValues(uint16_t moving, uint16_t stationary, uint16_t inactivityTimer); //Realistically gate values are 0-8 but sent as uint16_t + bool setGateSensitivityThreshold(uint8_t gate, uint8_t moving, uint8_t stationary); + uint8_t readByte(); + bool available(); + void resetGates(); + uint8_t getting_response = 0; + + protected: + private: + Stream *radar_uart_ = nullptr; + Stream *debug_uart_ = nullptr; //The stream used for the debugging + uint32_t radar_uart_timeout = 100; //How long to give up on receiving some useful data from the LD2410 [ms] + uint32_t radar_uart_last_packet_ = 0; //Time of the last packet from the radar + uint32_t radar_uart_last_command_ = 0; //Time of the last command sent to the radar + uint32_t radar_uart_command_timeout_ = 500; //Timeout for sending commands [ms] + uint8_t latest_ack_ = 0; + bool latest_command_success_ = false; + uint8_t radar_data_frame_[LD2410_MAX_FRAME_LENGTH]; //Store the incoming data from the radar, to check it's in a valid format + uint8_t radar_data_frame_position_ = 0; //Where in the frame we are currently writing + bool frame_started_ = false; //Whether a frame is currently being read + bool ack_frame_ = false; //Whether the incoming frame is LIKELY an ACK frame + bool waiting_for_ack_ = false; //Whether a command has just been sent + uint8_t target_type_ = 0; + uint16_t moving_target_distance_ = 0; + uint8_t moving_target_energy_ = 0; + uint16_t stationary_target_distance_ = 0; + uint8_t stationary_target_energy_ = 0; + uint8_t byte_read_ = 0; + + bool read_frame_(); //Try to read a frame from the UART + bool parse_data_frame_(); //Is the current data frame valid? + bool parse_command_frame_(); //Is the current command frame valid? + void print_frame_(); //Print the frame for debugging + void send_command_preamble_(); //Commands have the same preamble + void send_command_postamble_(); //Commands have the same postamble + bool enter_configuration_mode_(); //Necessary before sending any command + bool leave_configuration_mode_(); //Will not read values without leaving command mode +}; +#endif \ No newline at end of file diff --git a/main/App.cpp b/main/App.cpp index 890817a..4890eef 100644 --- a/main/App.cpp +++ b/main/App.cpp @@ -25,7 +25,7 @@ void App::init() m_led = new Led(LED_PIN); m_wifi = new Wifi(); - + #if 1 bool needs_provision = true; @@ -73,9 +73,10 @@ void App::init() #endif + // Serial.begin(450000); + m_sensors = new Sensors(); m_sensors->start(); - } void App::otaCheck() diff --git a/main/App.h b/main/App.h index 81e8a0a..07454a4 100644 --- a/main/App.h +++ b/main/App.h @@ -10,6 +10,7 @@ #include "Wifi.h" #include "Mqtt.h" #include "Ble.h" +#include "Buffers.h" #include "sensors/Sensors.h" class App @@ -19,6 +20,7 @@ protected: Mqtt * m_mqtt = nullptr; Ble * m_ble = nullptr; Sensors * m_sensors = nullptr; + CircBuffer m_buffer; public: Led * m_led = nullptr; diff --git a/main/Buffers.cpp b/main/Buffers.cpp new file mode 100644 index 0000000..1ef55e9 --- /dev/null +++ b/main/Buffers.cpp @@ -0,0 +1 @@ +/// © MiroZ 2024 diff --git a/main/Buffers.h b/main/Buffers.h new file mode 100644 index 0000000..f345c46 --- /dev/null +++ b/main/Buffers.h @@ -0,0 +1,100 @@ +/// © MiroZ 2024 + +#include +#include + +static uint8_t mem[30000]; + + +// template +class CircBuffer +{ +protected: + uint16_t * m_buffer = (uint16_t *)mem; + size_t head_ = 0; + size_t tail_ = 0; + bool full_ = false; + uint32_t m_size = 0; + +public: + CircBuffer() + { + // assert(m_buffer = (T*)calloc(size, sizeof(T))); + m_size = 30000/2; + } + + ~CircBuffer() + { + // free(m_buffer); + } + + bool put(uint16_t item) + { + //std::lock_guard lock(mutex_); + + if (full_) + return false; + + m_buffer[head_] = item; + + head_ = (head_ + 1) % m_size; + full_ = head_ == tail_; + return true; + } + + bool get(uint16_t & val) + { + //std::lock_guard lock(mutex_); + + if (empty()) + return false; + + // Read data and advance the tail (we now have a free space) + val = m_buffer[tail_]; + full_ = false; + tail_ = (tail_ + 1) % m_size; + + return true; + } + + void reset() + { + //std::lock_guard lock(mutex_); + head_ = tail_ = 0; + full_ = false; + } + + bool empty() + { + //std::lock_guard lock(mutex_); + // if head and tail are equal, we are empty + return (!full_ && (head_ == tail_)); + } + + bool full() + { + return full_; + } + + size_t capacity() + { + return m_size; + } + + size_t size() + { + //std::lock_guard lock(mutex_); + + size_t size = m_size; + + if (!full_) + { + if (head_ >= tail_) + size = head_ - tail_; + else + size = m_size + head_ - tail_; + } + + return size; + } +}; \ No newline at end of file diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 0cc4f41..1894fc5 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -1,6 +1,6 @@ idf_component_register(SRCS main.cpp App.cpp Settings.cpp Led.cpp TaskMgr.cpp Wifi.cpp utilities.cpp ProvisionSoftAP.cpp ReaderWriter.cpp Ota.cpp Mqtt.cpp Ble.cpp sensors/Bmp280.cpp - sensors/Bme68x.cpp sensors/Sensors.cpp + sensors/Bme68x.cpp sensors/Sensors.cpp sensors/LD2410.cpp Buffers.cpp INCLUDE_DIRS "." EMBED_TXTFILES ../html/logo.png ../html/provision.html EMBED_TXTFILES ../certs/eventgrid.azure.pem ../certs/client1-authn-ID.key ../certs/client1-authn-ID.pem ../certs/bigfoot-inc.pem diff --git a/main/TaskMgr.cpp b/main/TaskMgr.cpp index 202656c..9591662 100644 --- a/main/TaskMgr.cpp +++ b/main/TaskMgr.cpp @@ -85,6 +85,11 @@ void TaskMgr::getInfo() else ESP_LOGI(TAG, "%10s (%d)", name, hwm); } + ESP_LOGI(TAG, "Free heap: %d", esp_get_free_heap_size()); + xSemaphoreGive(m_xMutex); + // char buf[512]; + // vTaskGetRunTimeStats(buf); + // printf(buf); } } \ No newline at end of file diff --git a/main/app_config.h b/main/app_config.h index e0fed27..900ab1a 100644 --- a/main/app_config.h +++ b/main/app_config.h @@ -6,7 +6,7 @@ // LED task #define LED_TASK_NAME "led" #define LED_TASK_STACK_SIZE 2096 -#define LED_TASK_PRIORITY 5 +#define LED_TASK_PRIORITY 3 #define LED_TASK_CORE 0 // WIFI task @@ -19,13 +19,13 @@ #define MQTT_TASK_NAME "mqtt" #define MQTT_TASK_STACK_SIZE 6144 #define MQTT_TASK_PRIORITY 5 -#define MQTT_TASK_CORE 0 +#define MQTT_TASK_CORE 1 // task mgr task #define TASKMGR_TASK_NAME "task mgr" #define TASKMGR_TASK_STACK_SIZE 2048 #define TASKMGR_TASK_PRIORITY 5 -#define TASKMGR_TASK_CORE 0 +#define TASKMGR_TASK_CORE 1 #define TASKMGR_TASK_DELAY 60000 // i2cbus_1 task @@ -34,10 +34,10 @@ #define I2C1_TASK_PRIORITY 5 #define I2C1_TASK_CORE 0 -// i2cbus_2 task -#define I2C2_TASK_NAME "i2cbus_2" -#define I2C2_TASK_STACK_SIZE 3000 -#define I2C2_TASK_PRIORITY 5 -#define I2C2_TASK_CORE 0 +// uart task +#define UART_TASK_NAME "uart" +#define UART_TASK_STACK_SIZE 3000 +#define UART_TASK_PRIORITY 5 +#define UART_TASK_CORE 1 #endif \ No newline at end of file diff --git a/main/sensors/Bme68x.cpp b/main/sensors/Bme68x.cpp index 5b8b359..8608cae 100644 --- a/main/sensors/Bme68x.cpp +++ b/main/sensors/Bme68x.cpp @@ -32,8 +32,9 @@ bool Bme68x::init() m_sensor->setHeaterProf(tempProf, mulProf, sharedHeatrDur, 10); m_sensor->setOpMode(BME68X_PARALLEL_MODE); + m_operational = m_sensor->checkStatus() == BME68X_OK; - return m_sensor->checkStatus() == BME68X_OK; + return m_operational; } diff --git a/main/sensors/Bme68x.h b/main/sensors/Bme68x.h index 43b0fc4..8ca9179 100644 --- a/main/sensors/Bme68x.h +++ b/main/sensors/Bme68x.h @@ -12,6 +12,7 @@ class Bme68x protected: MyLibs::Bme68x * m_sensor = nullptr; TwoWire & m_bus; + bool m_operational = false; public: Bme68x(TwoWire & bus); diff --git a/main/sensors/Bmp280.cpp b/main/sensors/Bmp280.cpp index be0822e..57b81e3 100644 --- a/main/sensors/Bmp280.cpp +++ b/main/sensors/Bmp280.cpp @@ -20,7 +20,9 @@ bool Bmp280::init() m_sensor->setTimeStandby(TIME_STANDBY_62MS); m_sensor->startNormalConversion(); // Start BMP280 continuous conversion in NORMAL_MODE - return status == 1; + m_operational = status == 1; + + return m_operational; } bool Bmp280::read() diff --git a/main/sensors/Bmp280.h b/main/sensors/Bmp280.h index 3603906..b6226fe 100644 --- a/main/sensors/Bmp280.h +++ b/main/sensors/Bmp280.h @@ -11,6 +11,7 @@ class Bmp280 protected: BMP280_DEV * m_sensor; TwoWire & m_bus; + bool m_operational = false; public: Bmp280(TwoWire & bus); diff --git a/main/sensors/LD2410.cpp b/main/sensors/LD2410.cpp new file mode 100644 index 0000000..f0ec6df --- /dev/null +++ b/main/sensors/LD2410.cpp @@ -0,0 +1,18 @@ +/// © MiroZ 2024 + +#include "LD2410.h" + +#define RADAR_RX_PIN 25 +#define RADAR_TX_PIN 19 + +LD2410::LD2410() +{ + //debug(Serial); +} + +bool LD2410::init() +{ + Serial1.begin(256000, SERIAL_8N1, RADAR_RX_PIN, RADAR_TX_PIN); + m_operational = begin(Serial1, true); + return m_operational; +} \ No newline at end of file diff --git a/main/sensors/LD2410.h b/main/sensors/LD2410.h new file mode 100644 index 0000000..971b22f --- /dev/null +++ b/main/sensors/LD2410.h @@ -0,0 +1,16 @@ +/// © MiroZ 2024 + +#include +#include + +#include + +class LD2410 : public ld2410 +{ +protected: + bool m_operational = false; + +public: + LD2410(); + bool init(); +}; diff --git a/main/sensors/Sensors.cpp b/main/sensors/Sensors.cpp index 5bc5c79..46becf3 100644 --- a/main/sensors/Sensors.cpp +++ b/main/sensors/Sensors.cpp @@ -1,9 +1,13 @@ +/// © MiroZ 2024 + #include "app_config.h" #include "TaskMgr.h" #include "Sensors.h" static const char *TAG = "sensors"; +#define ms_to_us(ms)(ms*1000) + Sensors::Sensors() { @@ -13,6 +17,7 @@ void Sensors::start() { m_bmp280 = new Bmp280(Wire); m_bme68x = new Bme68x(Wire); + m_ld2410 = new LD2410(); if(!m_bmp280->init()) ESP_LOGE(TAG, "bmp280 sensor error"); @@ -20,30 +25,73 @@ void Sensors::start() if(!m_bme68x->init()) ESP_LOGE(TAG, "bme68x sensor error"); + if(!m_ld2410->init()) + ESP_LOGE(TAG, "ld2410 sensor error"); assert(m_i2c1_task = TaskMgr::getInstance().createTask(std::bind(&Sensors::run_i2c_1, this), I2C1_TASK_NAME, I2C1_TASK_STACK_SIZE, I2C1_TASK_PRIORITY, I2C1_TASK_CORE)); - assert(m_i2c2_task = TaskMgr::getInstance().createTask(std::bind(&Sensors::run_i2c_2, this), - I2C2_TASK_NAME, I2C2_TASK_STACK_SIZE, I2C2_TASK_PRIORITY, I2C2_TASK_CORE)); + assert(m_i2c2_task = TaskMgr::getInstance().createTask(std::bind(&Sensors::run_uart, this), + UART_TASK_NAME, UART_TASK_STACK_SIZE, UART_TASK_PRIORITY, UART_TASK_CORE)); } +// handles pressure and voc sensor void Sensors::run_i2c_1() { while(true) { - m_bmp280->read(); - m_bme68x->read(); + // m_bmp280->read(); + // m_bme68x->read(); delay(10); } } -void Sensors::run_i2c_2() +// handles radar only +void Sensors::run_uart() { + int64_t last_read = esp_timer_get_time(); + while(true) { + bool has_read = m_ld2410->read(); - delay(1000); + if(has_read && esp_timer_get_time() - last_read >= ms_to_us(990)) + { + int64_t now = esp_timer_get_time(); + ESP_LOGI(TAG, "count %d", (int)m_ld2410->stationary_energy[0]); + + if(m_ld2410->stationary_energy[0] != 0) + { + ESP_LOGI(TAG, "delta t: %lld", (now - last_read)/1000); + last_read = now; + + ESP_LOGI("stationary energy", "%0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f", + m_ld2410->stationary_energy[3]/m_ld2410->stationary_energy[0], + m_ld2410->stationary_energy[4]/m_ld2410->stationary_energy[0], + m_ld2410->stationary_energy[5]/m_ld2410->stationary_energy[0], + m_ld2410->stationary_energy[6]/m_ld2410->stationary_energy[0], + m_ld2410->stationary_energy[7]/m_ld2410->stationary_energy[0], + m_ld2410->stationary_energy[8]/m_ld2410->stationary_energy[0], + m_ld2410->stationary_energy[9]/m_ld2410->stationary_energy[0]); + + + ESP_LOGW("motion energy", "%0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f %0.0f", + m_ld2410->motion_energy[5]/m_ld2410->motion_energy[0], + m_ld2410->motion_energy[6]/m_ld2410->motion_energy[0], + m_ld2410->motion_energy[7]/m_ld2410->motion_energy[0], + m_ld2410->motion_energy[8]/m_ld2410->motion_energy[0], + m_ld2410->motion_energy[9]/m_ld2410->motion_energy[0], + m_ld2410->motion_energy[10]/m_ld2410->motion_energy[0], + m_ld2410->motion_energy[11]/m_ld2410->motion_energy[0], + m_ld2410->motion_energy[12]/m_ld2410->motion_energy[0], + m_ld2410->motion_energy[13]/m_ld2410->motion_energy[0]); + + m_ld2410->resetGates(); + } + } + if(has_read) + // next read will happen in 100ms. sleep untill just before then. + delay(95); } } \ No newline at end of file diff --git a/main/sensors/Sensors.h b/main/sensors/Sensors.h index 2c46eee..d60afa4 100644 --- a/main/sensors/Sensors.h +++ b/main/sensors/Sensors.h @@ -1,9 +1,12 @@ +/// © MiroZ 2024 + #include #include #include #include "Bme68x.h" #include "Bmp280.h" +#include "LD2410.h" class Sensors { @@ -12,10 +15,11 @@ protected: TaskHandle_t m_i2c2_task = nullptr; void run_i2c_1(); - void run_i2c_2(); + void run_uart(); Bmp280 * m_bmp280 = nullptr; Bme68x * m_bme68x = nullptr; + LD2410 * m_ld2410 = nullptr; public: Sensors(); diff --git a/sdkconfig.old b/sdkconfig.old index 549de33..4c51ae1 100644 --- a/sdkconfig.old +++ b/sdkconfig.old @@ -333,172 +333,172 @@ CONFIG_BT_BLE_SMP_ENABLE=y # # CONFIG_BT_LOG_HCI_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_HCI_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_HCI_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_HCI_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_HCI_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_HCI_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_HCI_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_HCI_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_HCI_TRACE_LEVEL=6 +# CONFIG_BT_LOG_HCI_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_HCI_TRACE_LEVEL=2 # CONFIG_BT_LOG_BTM_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_BTM_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_BTM_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_BTM_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_BTM_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_BTM_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_BTM_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_BTM_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_BTM_TRACE_LEVEL=6 +# CONFIG_BT_LOG_BTM_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_BTM_TRACE_LEVEL=2 # CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_L2CAP_TRACE_LEVEL=6 +# CONFIG_BT_LOG_L2CAP_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_L2CAP_TRACE_LEVEL=2 # CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL=6 +# CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_RFCOMM_TRACE_LEVEL=2 # CONFIG_BT_LOG_SDP_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_SDP_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_SDP_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_SDP_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_SDP_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_SDP_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_SDP_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_SDP_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_SDP_TRACE_LEVEL=6 +# CONFIG_BT_LOG_SDP_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_SDP_TRACE_LEVEL=2 # CONFIG_BT_LOG_GAP_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_GAP_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_GAP_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_GAP_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_GAP_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_GAP_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_GAP_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_GAP_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_GAP_TRACE_LEVEL=6 +# CONFIG_BT_LOG_GAP_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_GAP_TRACE_LEVEL=2 # CONFIG_BT_LOG_BNEP_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_BNEP_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_BNEP_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_BNEP_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_BNEP_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_BNEP_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_BNEP_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_BNEP_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_BNEP_TRACE_LEVEL=6 +# CONFIG_BT_LOG_BNEP_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_BNEP_TRACE_LEVEL=2 # CONFIG_BT_LOG_PAN_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_PAN_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_PAN_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_PAN_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_PAN_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_PAN_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_PAN_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_PAN_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_PAN_TRACE_LEVEL=6 +# CONFIG_BT_LOG_PAN_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_PAN_TRACE_LEVEL=2 # CONFIG_BT_LOG_A2D_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_A2D_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_A2D_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_A2D_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_A2D_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_A2D_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_A2D_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_A2D_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_A2D_TRACE_LEVEL=6 +# CONFIG_BT_LOG_A2D_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_A2D_TRACE_LEVEL=2 # CONFIG_BT_LOG_AVDT_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_AVDT_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_AVDT_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_AVDT_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_AVDT_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_AVDT_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_AVDT_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_AVDT_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_AVDT_TRACE_LEVEL=6 +# CONFIG_BT_LOG_AVDT_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_AVDT_TRACE_LEVEL=2 # CONFIG_BT_LOG_AVCT_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_AVCT_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_AVCT_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_AVCT_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_AVCT_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_AVCT_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_AVCT_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_AVCT_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_AVCT_TRACE_LEVEL=6 +# CONFIG_BT_LOG_AVCT_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_AVCT_TRACE_LEVEL=2 # CONFIG_BT_LOG_AVRC_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_AVRC_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_AVRC_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_AVRC_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_AVRC_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_AVRC_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_AVRC_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_AVRC_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_AVRC_TRACE_LEVEL=6 +# CONFIG_BT_LOG_AVRC_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_AVRC_TRACE_LEVEL=2 # CONFIG_BT_LOG_MCA_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_MCA_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_MCA_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_MCA_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_MCA_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_MCA_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_MCA_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_MCA_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_MCA_TRACE_LEVEL=6 +# CONFIG_BT_LOG_MCA_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_MCA_TRACE_LEVEL=2 # CONFIG_BT_LOG_HID_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_HID_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_HID_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_HID_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_HID_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_HID_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_HID_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_HID_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_HID_TRACE_LEVEL=6 +# CONFIG_BT_LOG_HID_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_HID_TRACE_LEVEL=2 # CONFIG_BT_LOG_APPL_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_APPL_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_APPL_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_APPL_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_APPL_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_APPL_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_APPL_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_APPL_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_APPL_TRACE_LEVEL=6 +# CONFIG_BT_LOG_APPL_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_APPL_TRACE_LEVEL=2 # CONFIG_BT_LOG_GATT_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_GATT_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_GATT_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_GATT_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_GATT_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_GATT_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_GATT_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_GATT_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_GATT_TRACE_LEVEL=6 +# CONFIG_BT_LOG_GATT_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_GATT_TRACE_LEVEL=2 # CONFIG_BT_LOG_SMP_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_SMP_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_SMP_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_SMP_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_SMP_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_SMP_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_SMP_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_SMP_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_SMP_TRACE_LEVEL=6 +# CONFIG_BT_LOG_SMP_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_SMP_TRACE_LEVEL=2 # CONFIG_BT_LOG_BTIF_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_BTIF_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_BTIF_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_BTIF_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_BTIF_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_BTIF_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_BTIF_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_BTIF_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_BTIF_TRACE_LEVEL=6 +# CONFIG_BT_LOG_BTIF_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_BTIF_TRACE_LEVEL=2 # CONFIG_BT_LOG_BTC_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_BTC_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_BTC_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_BTC_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_BTC_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_BTC_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_BTC_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_BTC_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_BTC_TRACE_LEVEL=6 +# CONFIG_BT_LOG_BTC_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_BTC_TRACE_LEVEL=2 # CONFIG_BT_LOG_OSI_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_OSI_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_OSI_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_OSI_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_OSI_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_OSI_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_OSI_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_OSI_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_OSI_TRACE_LEVEL=6 +# CONFIG_BT_LOG_OSI_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_OSI_TRACE_LEVEL=2 # CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_NONE is not set # CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_ERROR is not set -# CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_WARNING is not set +CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_WARNING=y # CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_API is not set # CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_EVENT is not set # CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_DEBUG is not set -CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_VERBOSE=y -CONFIG_BT_LOG_BLUFI_TRACE_LEVEL=6 +# CONFIG_BT_LOG_BLUFI_TRACE_LEVEL_VERBOSE is not set +CONFIG_BT_LOG_BLUFI_TRACE_LEVEL=2 # end of BT DEBUG LOG LEVEL CONFIG_BT_ACL_CONNECTIONS=4 @@ -1040,7 +1040,9 @@ CONFIG_FREERTOS_TIMER_TASK_PRIORITY=1 CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=2048 CONFIG_FREERTOS_TIMER_QUEUE_LENGTH=10 CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE=0 -# CONFIG_FREERTOS_USE_TRACE_FACILITY is not set +CONFIG_FREERTOS_USE_TRACE_FACILITY=y +CONFIG_FREERTOS_USE_STATS_FORMATTING_FUNCTIONS=y +# CONFIG_FREERTOS_VTASKLIST_INCLUDE_COREID is not set # CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS is not set CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=y # CONFIG_FREERTOS_CHECK_PORT_CRITICAL_COMPLIANCE is not set From 4e9c6d9f0c9b880e6bf13d828c8cf9930374379e Mon Sep 17 00:00:00 2001 From: MiroZ Date: Tue, 11 Jun 2024 22:07:03 -0700 Subject: [PATCH 3/5] working circular buffer with radar --- components/NimBLE/.github/workflows/build.yml | 146 + .../NimBLE/.github/workflows/release.yml | 22 + components/NimBLE/.gitignore | 1 + components/NimBLE/CHANGELOG.md | 311 + components/NimBLE/CMakeLists.txt | 17 + components/NimBLE/LICENSE | 219 + components/NimBLE/README.md | 72 + .../NimBLE/docs/Bluetooth 5 features.md | 28 + components/NimBLE/docs/Command_line_config.md | 180 + components/NimBLE/docs/Doxyfile | 2777 +++++++ .../NimBLE/docs/Improvements_and_updates.md | 148 + components/NimBLE/docs/Migration_guide.md | 379 + components/NimBLE/docs/New_user_guide.md | 339 + components/NimBLE/docs/Usage_tips.md | 41 + components/NimBLE/docs/index.md | 70 + .../BLE_Beacon_Scanner/BLE_Beacon_Scanner.ino | 153 + .../BLE_Beacon_Scanner/BLE_Beacon_Scanner.md | 9 + .../BLE_EddystoneTLM_Beacon.ino | 113 + .../BLE_EddystoneTLM_Beacon.md | 14 + .../BLE_EddystoneURL_Beacon.ino | 185 + .../BLE_EddystoneURL_Beacon.md | 14 + .../NimBLE_extended_client.ino | 171 + .../NimBLE_extended_server.ino | 150 + .../NimBLE_multi_advertiser.ino | 181 + .../examples/NimBLE_Client/NimBLE_Client.ino | 396 + .../NimBLE_Scan_Continuous.ino | 71 + .../NimBLE_Scan_whitelist.ino | 67 + .../NimBLE_Secure_Client.ino | 95 + .../NimBLE_Secure_Server.ino | 41 + .../examples/NimBLE_Server/NimBLE_Server.ino | 260 + .../NimBLE_Server_Whitelist.ino | 105 + .../NimBLE_Service_Data_Advertiser.ino | 34 + .../BLE_client/BLE_client.ino | 194 + .../BLE_iBeacon/BLE_iBeacon.ino | 118 + .../BLE_notify/BLE_notify.ino | 146 + .../BLE_scan/BLE_scan.ino | 49 + .../BLE_server/BLE_server.ino | 57 + .../BLE_server_multiconnect.ino | 150 + .../BLE_uart/BLE_uart.ino | 163 + .../BLE_write/BLE_write.ino | 75 + components/NimBLE/library.properties | 10 + components/NimBLE/src/HIDKeyboardTypes.h | 402 + components/NimBLE/src/HIDTypes.h | 91 + components/NimBLE/src/NimBLE2904.cpp | 86 + components/NimBLE/src/NimBLE2904.h | 83 + components/NimBLE/src/NimBLEAddress.cpp | 197 + components/NimBLE/src/NimBLEAddress.h | 62 + .../NimBLE/src/NimBLEAdvertisedDevice.cpp | 920 +++ .../NimBLE/src/NimBLEAdvertisedDevice.h | 202 + components/NimBLE/src/NimBLEAdvertising.cpp | 1075 +++ components/NimBLE/src/NimBLEAdvertising.h | 144 + components/NimBLE/src/NimBLEAttValue.h | 447 ++ components/NimBLE/src/NimBLEBeacon.cpp | 157 + components/NimBLE/src/NimBLEBeacon.h | 51 + .../NimBLE/src/NimBLECharacteristic.cpp | 667 ++ components/NimBLE/src/NimBLECharacteristic.h | 231 + components/NimBLE/src/NimBLEClient.cpp | 1299 ++++ components/NimBLE/src/NimBLEClient.h | 169 + components/NimBLE/src/NimBLEConnInfo.h | 55 + components/NimBLE/src/NimBLEDescriptor.cpp | 304 + components/NimBLE/src/NimBLEDescriptor.h | 119 + components/NimBLE/src/NimBLEDevice.cpp | 1213 +++ components/NimBLE/src/NimBLEDevice.h | 241 + components/NimBLE/src/NimBLEEddystoneTLM.cpp | 227 + components/NimBLE/src/NimBLEEddystoneTLM.h | 61 + components/NimBLE/src/NimBLEEddystoneURL.cpp | 204 + components/NimBLE/src/NimBLEEddystoneURL.h | 52 + .../NimBLE/src/NimBLEExtAdvertising.cpp | 870 +++ components/NimBLE/src/NimBLEExtAdvertising.h | 152 + components/NimBLE/src/NimBLEHIDDevice.cpp | 265 + components/NimBLE/src/NimBLEHIDDevice.h | 87 + components/NimBLE/src/NimBLELog.h | 80 + .../NimBLE/src/NimBLERemoteCharacteristic.cpp | 865 +++ .../NimBLE/src/NimBLERemoteCharacteristic.h | 190 + .../NimBLE/src/NimBLERemoteDescriptor.cpp | 365 + .../NimBLE/src/NimBLERemoteDescriptor.h | 108 + components/NimBLE/src/NimBLERemoteService.cpp | 413 + components/NimBLE/src/NimBLERemoteService.h | 85 + components/NimBLE/src/NimBLEScan.cpp | 585 ++ components/NimBLE/src/NimBLEScan.h | 103 + components/NimBLE/src/NimBLESecurity.cpp | 158 + components/NimBLE/src/NimBLESecurity.h | 131 + components/NimBLE/src/NimBLEServer.cpp | 921 +++ components/NimBLE/src/NimBLEServer.h | 193 + components/NimBLE/src/NimBLEService.cpp | 437 ++ components/NimBLE/src/NimBLEService.h | 87 + components/NimBLE/src/NimBLEUUID.cpp | 360 + components/NimBLE/src/NimBLEUUID.h | 64 + components/NimBLE/src/NimBLEUtils.cpp | 518 ++ components/NimBLE/src/NimBLEUtils.h | 51 + .../NimBLE/src/nimble/CODING_STANDARDS.md | 267 + components/NimBLE/src/nimble/LICENSE | 217 + components/NimBLE/src/nimble/NOTICE | 9 + components/NimBLE/src/nimble/README.md | 170 + components/NimBLE/src/nimble/RELEASE_NOTES.md | 22 + .../NimBLE/src/nimble/console/console.h | 16 + .../esp_port/esp-hci/include/esp_compiler.h | 59 + .../esp_port/esp-hci/include/esp_nimble_hci.h | 125 + .../esp_port/esp-hci/src/esp_nimble_hci.c | 585 ++ .../esp_port/port/include/esp_nimble_cfg.h | 1478 ++++ .../esp_port/port/include/esp_nimble_mem.h | 24 + .../nimble/esp_port/port/src/esp_nimble_mem.c | 44 + .../NimBLE/src/nimble/ext/tinycrypt/AUTHORS | 15 + .../NimBLE/src/nimble/ext/tinycrypt/LICENSE | 61 + .../NimBLE/src/nimble/ext/tinycrypt/README | 71 + .../NimBLE/src/nimble/ext/tinycrypt/VERSION | 1 + .../ext/tinycrypt/documentation/tinycrypt.rst | 352 + .../ext/tinycrypt/include/tinycrypt/aes.h | 130 + .../tinycrypt/include/tinycrypt/cbc_mode.h | 151 + .../tinycrypt/include/tinycrypt/ccm_mode.h | 211 + .../tinycrypt/include/tinycrypt/cmac_mode.h | 194 + .../tinycrypt/include/tinycrypt/constants.h | 61 + .../tinycrypt/include/tinycrypt/ctr_mode.h | 108 + .../tinycrypt/include/tinycrypt/ctr_prng.h | 166 + .../ext/tinycrypt/include/tinycrypt/ecc.h | 545 ++ .../ext/tinycrypt/include/tinycrypt/ecc_dh.h | 131 + .../ext/tinycrypt/include/tinycrypt/ecc_dsa.h | 139 + .../include/tinycrypt/ecc_platform_specific.h | 81 + .../ext/tinycrypt/include/tinycrypt/hmac.h | 139 + .../tinycrypt/include/tinycrypt/hmac_prng.h | 164 + .../ext/tinycrypt/include/tinycrypt/sha256.h | 129 + .../ext/tinycrypt/include/tinycrypt/utils.h | 95 + .../nimble/ext/tinycrypt/src/aes_decrypt.c | 164 + .../nimble/ext/tinycrypt/src/aes_encrypt.c | 191 + .../src/nimble/ext/tinycrypt/src/cbc_mode.c | 114 + .../src/nimble/ext/tinycrypt/src/ccm_mode.c | 266 + .../src/nimble/ext/tinycrypt/src/cmac_mode.c | 254 + .../src/nimble/ext/tinycrypt/src/ctr_mode.c | 85 + .../src/nimble/ext/tinycrypt/src/ctr_prng.c | 283 + .../NimBLE/src/nimble/ext/tinycrypt/src/ecc.c | 942 +++ .../src/nimble/ext/tinycrypt/src/ecc_dh.c | 200 + .../src/nimble/ext/tinycrypt/src/ecc_dsa.c | 295 + .../ext/tinycrypt/src/ecc_platform_specific.c | 105 + .../src/nimble/ext/tinycrypt/src/hmac.c | 148 + .../src/nimble/ext/tinycrypt/src/hmac_prng.c | 212 + .../src/nimble/ext/tinycrypt/src/sha256.c | 217 + .../src/nimble/ext/tinycrypt/src/utils.c | 74 + .../controller/include/controller/ble_hw.h | 116 + .../controller/include/controller/ble_ll.h | 622 ++ .../include/controller/ble_ll_adv.h | 209 + .../include/controller/ble_ll_conn.h | 432 ++ .../include/controller/ble_ll_ctrl.h | 332 + .../include/controller/ble_ll_hci.h | 75 + .../include/controller/ble_ll_iso.h | 53 + .../include/controller/ble_ll_resolv.h | 116 + .../include/controller/ble_ll_rfmgmt.h | 63 + .../include/controller/ble_ll_scan.h | 293 + .../include/controller/ble_ll_sched.h | 216 + .../include/controller/ble_ll_sync.h | 74 + .../include/controller/ble_ll_test.h | 35 + .../include/controller/ble_ll_trace.h | 96 + .../include/controller/ble_ll_utils.h | 29 + .../include/controller/ble_ll_whitelist.h | 52 + .../controller/include/controller/ble_phy.h | 244 + .../include/controller/ble_phy_trace.h | 96 + .../src/nimble/nimble/controller/src/ble_ll.c | 1733 +++++ .../nimble/nimble/controller/src/ble_ll_adv.c | 5151 +++++++++++++ .../nimble/controller/src/ble_ll_conn.c | 4515 +++++++++++ .../nimble/controller/src/ble_ll_conn_hci.c | 1921 +++++ .../nimble/controller/src/ble_ll_conn_priv.h | 237 + .../nimble/controller/src/ble_ll_ctrl.c | 2879 +++++++ .../nimble/nimble/controller/src/ble_ll_dtm.c | 728 ++ .../nimble/controller/src/ble_ll_dtm_priv.h | 40 + .../nimble/nimble/controller/src/ble_ll_hci.c | 1787 +++++ .../nimble/controller/src/ble_ll_hci_ev.c | 557 ++ .../nimble/nimble/controller/src/ble_ll_iso.c | 147 + .../nimble/controller/src/ble_ll_priv.h | 51 + .../nimble/controller/src/ble_ll_rand.c | 206 + .../nimble/controller/src/ble_ll_resolv.c | 755 ++ .../nimble/controller/src/ble_ll_rfmgmt.c | 349 + .../nimble/controller/src/ble_ll_scan.c | 3987 ++++++++++ .../nimble/controller/src/ble_ll_sched.c | 1838 +++++ .../nimble/controller/src/ble_ll_supp_cmd.c | 546 ++ .../nimble/controller/src/ble_ll_sync.c | 2346 ++++++ .../nimble/controller/src/ble_ll_trace.c | 56 + .../nimble/controller/src/ble_ll_utils.c | 302 + .../nimble/controller/src/ble_ll_whitelist.c | 297 + .../nimble/drivers/nrf51/include/ble/xcvr.h | 51 + .../nimble/nimble/drivers/nrf51/src/ble_hw.c | 491 ++ .../nimble/nimble/drivers/nrf51/src/ble_phy.c | 1535 ++++ .../nimble/drivers/nrf52/include/ble/xcvr.h | 55 + .../nimble/nimble/drivers/nrf52/src/ble_hw.c | 491 ++ .../nimble/nimble/drivers/nrf52/src/ble_phy.c | 2128 ++++++ .../nimble/drivers/nrf52/src/ble_phy_trace.c | 47 + .../nimble/nimble/host/include/host/ble_att.h | 194 + .../nimble/host/include/host/ble_eddystone.h | 117 + .../nimble/nimble/host/include/host/ble_gap.h | 2367 ++++++ .../nimble/host/include/host/ble_gatt.h | 923 +++ .../nimble/nimble/host/include/host/ble_hs.h | 394 + .../nimble/host/include/host/ble_hs_adv.h | 177 + .../nimble/host/include/host/ble_hs_hci.h | 98 + .../nimble/host/include/host/ble_hs_id.h | 132 + .../nimble/host/include/host/ble_hs_log.h | 53 + .../nimble/host/include/host/ble_hs_mbuf.h | 82 + .../nimble/host/include/host/ble_hs_pvcy.h | 73 + .../nimble/host/include/host/ble_hs_stop.h | 70 + .../nimble/host/include/host/ble_ibeacon.h | 34 + .../nimble/host/include/host/ble_l2cap.h | 266 + .../nimble/host/include/host/ble_monitor.h | 41 + .../nimble/nimble/host/include/host/ble_sm.h | 124 + .../nimble/host/include/host/ble_store.h | 304 + .../nimble/host/include/host/ble_uuid.h | 188 + .../nimble/host/mesh/include/mesh/access.h | 681 ++ .../nimble/host/mesh/include/mesh/atomic.h | 409 + .../nimble/host/mesh/include/mesh/cdb.h | 267 + .../nimble/host/mesh/include/mesh/cfg.h | 485 ++ .../nimble/host/mesh/include/mesh/cfg_cli.h | 278 + .../nimble/host/mesh/include/mesh/cfg_srv.h | 40 + .../nimble/host/mesh/include/mesh/glue.h | 591 ++ .../host/mesh/include/mesh/health_cli.h | 79 + .../host/mesh/include/mesh/health_srv.h | 100 + .../nimble/host/mesh/include/mesh/heartbeat.h | 123 + .../nimble/host/mesh/include/mesh/main.h | 559 ++ .../nimble/host/mesh/include/mesh/mesh.h | 31 + .../nimble/host/mesh/include/mesh/model_cli.h | 49 + .../nimble/host/mesh/include/mesh/model_srv.h | 67 + .../nimble/host/mesh/include/mesh/porting.h | 27 + .../nimble/host/mesh/include/mesh/proxy.h | 43 + .../nimble/host/mesh/include/mesh/slist.h | 468 ++ .../nimble/host/mesh/include/mesh/testing.h | 105 + .../src/nimble/nimble/host/mesh/src/access.c | 851 +++ .../src/nimble/nimble/host/mesh/src/access.h | 64 + .../src/nimble/nimble/host/mesh/src/adv.c | 456 ++ .../src/nimble/nimble/host/mesh/src/adv.h | 74 + .../src/nimble/nimble/host/mesh/src/aes-ccm.c | 229 + .../nimble/nimble/host/mesh/src/app_keys.c | 512 ++ .../nimble/nimble/host/mesh/src/app_keys.h | 86 + .../src/nimble/nimble/host/mesh/src/atomic.h | 409 + .../src/nimble/nimble/host/mesh/src/beacon.c | 475 ++ .../src/nimble/nimble/host/mesh/src/beacon.h | 27 + .../src/nimble/nimble/host/mesh/src/cdb.c | 393 + .../src/nimble/nimble/host/mesh/src/cfg.c | 272 + .../src/nimble/nimble/host/mesh/src/cfg.h | 9 + .../src/nimble/nimble/host/mesh/src/cfg_cli.c | 2120 +++++ .../src/nimble/nimble/host/mesh/src/cfg_srv.c | 2509 ++++++ .../src/nimble/nimble/host/mesh/src/crypto.c | 607 ++ .../src/nimble/nimble/host/mesh/src/crypto.h | 171 + .../nimble/nimble/host/mesh/src/foundation.h | 137 + .../src/nimble/nimble/host/mesh/src/friend.c | 1745 +++++ .../src/nimble/nimble/host/mesh/src/friend.h | 56 + .../src/nimble/nimble/host/mesh/src/glue.c | 979 +++ .../nimble/nimble/host/mesh/src/health_cli.c | 551 ++ .../nimble/nimble/host/mesh/src/health_srv.c | 452 ++ .../nimble/nimble/host/mesh/src/heartbeat.c | 356 + .../nimble/nimble/host/mesh/src/heartbeat.h | 40 + .../nimble/nimble/host/mesh/src/light_model.c | 59 + .../nimble/nimble/host/mesh/src/light_model.h | 19 + .../src/nimble/nimble/host/mesh/src/lpn.c | 1104 +++ .../src/nimble/nimble/host/mesh/src/lpn.h | 68 + .../src/nimble/nimble/host/mesh/src/mesh.c | 405 + .../nimble/nimble/host/mesh/src/mesh_priv.h | 53 + .../nimble/nimble/host/mesh/src/model_cli.c | 303 + .../nimble/nimble/host/mesh/src/model_srv.c | 269 + .../src/nimble/nimble/host/mesh/src/net.c | 864 +++ .../src/nimble/nimble/host/mesh/src/net.h | 317 + .../src/nimble/nimble/host/mesh/src/nodes.c | 164 + .../src/nimble/nimble/host/mesh/src/nodes.h | 10 + .../src/nimble/nimble/host/mesh/src/pb_adv.c | 891 +++ .../src/nimble/nimble/host/mesh/src/pb_gatt.c | 163 + .../src/nimble/nimble/host/mesh/src/prov.c | 379 + .../src/nimble/nimble/host/mesh/src/prov.h | 154 + .../nimble/nimble/host/mesh/src/prov_bearer.h | 116 + .../nimble/nimble/host/mesh/src/prov_device.c | 573 ++ .../nimble/nimble/host/mesh/src/provisioner.c | 750 ++ .../nimble/nimble/host/mesh/src/provisioner.h | 10 + .../src/nimble/nimble/host/mesh/src/proxy.c | 1579 ++++ .../src/nimble/nimble/host/mesh/src/proxy.h | 52 + .../src/nimble/nimble/host/mesh/src/rpl.c | 167 + .../src/nimble/nimble/host/mesh/src/rpl.h | 30 + .../nimble/nimble/host/mesh/src/settings.c | 2467 ++++++ .../nimble/nimble/host/mesh/src/settings.h | 32 + .../src/nimble/nimble/host/mesh/src/shell.c | 3690 +++++++++ .../src/nimble/nimble/host/mesh/src/shell.h | 6 + .../src/nimble/nimble/host/mesh/src/subnet.c | 670 ++ .../src/nimble/nimble/host/mesh/src/subnet.h | 197 + .../nimble/nimble/host/mesh/src/transport.c | 1761 +++++ .../nimble/nimble/host/mesh/src/transport.h | 113 + .../ans/include/services/ans/ble_svc_ans.h | 85 + .../host/services/ans/src/ble_svc_ans.c | 463 ++ .../bas/include/services/bas/ble_svc_bas.h | 33 + .../host/services/bas/src/ble_svc_bas.c | 127 + .../dis/include/services/dis/ble_svc_dis.h | 113 + .../host/services/dis/src/ble_svc_dis.c | 331 + .../gap/include/services/gap/ble_svc_gap.h | 55 + .../host/services/gap/src/ble_svc_gap.c | 304 + .../gatt/include/services/gatt/ble_svc_gatt.h | 40 + .../host/services/gatt/src/ble_svc_gatt.c | 108 + .../ias/include/services/ias/ble_svc_ias.h | 38 + .../host/services/ias/src/ble_svc_ias.c | 149 + .../ipss/include/services/ipss/ble_svc_ipss.h | 38 + .../host/services/ipss/src/ble_svc_ipss.c | 51 + .../lls/include/services/lls/ble_svc_lls.h | 51 + .../host/services/lls/src/ble_svc_lls.c | 192 + .../src/nimble/nimble/host/src/ble_att.c | 601 ++ .../src/nimble/nimble/host/src/ble_att_clt.c | 968 +++ .../src/nimble/nimble/host/src/ble_att_cmd.c | 639 ++ .../nimble/nimble/host/src/ble_att_cmd_priv.h | 449 ++ .../src/nimble/nimble/host/src/ble_att_priv.h | 301 + .../src/nimble/nimble/host/src/ble_att_svr.c | 2753 +++++++ .../nimble/nimble/host/src/ble_eddystone.c | 178 + .../src/nimble/nimble/host/src/ble_gap.c | 6793 +++++++++++++++++ .../src/nimble/nimble/host/src/ble_gap_priv.h | 162 + .../nimble/nimble/host/src/ble_gatt_priv.h | 199 + .../src/nimble/nimble/host/src/ble_gattc.c | 4860 ++++++++++++ .../src/nimble/nimble/host/src/ble_gatts.c | 2222 ++++++ .../nimble/nimble/host/src/ble_gatts_lcl.c | 213 + .../src/nimble/nimble/host/src/ble_hs.c | 897 +++ .../src/nimble/nimble/host/src/ble_hs_adv.c | 803 ++ .../nimble/nimble/host/src/ble_hs_adv_priv.h | 36 + .../nimble/nimble/host/src/ble_hs_atomic.c | 120 + .../nimble/host/src/ble_hs_atomic_priv.h | 41 + .../src/nimble/nimble/host/src/ble_hs_cfg.c | 33 + .../src/nimble/nimble/host/src/ble_hs_conn.c | 603 ++ .../nimble/nimble/host/src/ble_hs_conn_priv.h | 148 + .../src/nimble/nimble/host/src/ble_hs_flow.c | 304 + .../nimble/nimble/host/src/ble_hs_flow_priv.h | 36 + .../src/nimble/nimble/host/src/ble_hs_hci.c | 665 ++ .../nimble/nimble/host/src/ble_hs_hci_cmd.c | 164 + .../nimble/nimble/host/src/ble_hs_hci_evt.c | 1079 +++ .../nimble/nimble/host/src/ble_hs_hci_priv.h | 126 + .../nimble/nimble/host/src/ble_hs_hci_util.c | 277 + .../src/nimble/nimble/host/src/ble_hs_id.c | 401 + .../nimble/nimble/host/src/ble_hs_id_priv.h | 45 + .../src/nimble/nimble/host/src/ble_hs_log.c | 47 + .../src/nimble/nimble/host/src/ble_hs_mbuf.c | 169 + .../nimble/nimble/host/src/ble_hs_mbuf_priv.h | 38 + .../src/nimble/nimble/host/src/ble_hs_misc.c | 149 + .../nimble/nimble/host/src/ble_hs_mqueue.c | 88 + .../nimble/host/src/ble_hs_periodic_sync.c | 157 + .../host/src/ble_hs_periodic_sync_priv.h | 55 + .../src/nimble/nimble/host/src/ble_hs_priv.h | 160 + .../src/nimble/nimble/host/src/ble_hs_pvcy.c | 334 + .../nimble/nimble/host/src/ble_hs_pvcy_priv.h | 46 + .../nimble/nimble/host/src/ble_hs_resolv.c | 786 ++ .../nimble/host/src/ble_hs_resolv_priv.h | 111 + .../nimble/nimble/host/src/ble_hs_shutdown.c | 69 + .../nimble/nimble/host/src/ble_hs_startup.c | 387 + .../nimble/host/src/ble_hs_startup_priv.h | 33 + .../src/nimble/nimble/host/src/ble_hs_stop.c | 289 + .../src/nimble/nimble/host/src/ble_ibeacon.c | 82 + .../src/nimble/nimble/host/src/ble_l2cap.c | 509 ++ .../nimble/nimble/host/src/ble_l2cap_coc.c | 639 ++ .../nimble/host/src/ble_l2cap_coc_priv.h | 106 + .../nimble/nimble/host/src/ble_l2cap_priv.h | 145 + .../nimble/nimble/host/src/ble_l2cap_sig.c | 1966 +++++ .../nimble/host/src/ble_l2cap_sig_cmd.c | 117 + .../nimble/host/src/ble_l2cap_sig_priv.h | 184 + .../src/nimble/nimble/host/src/ble_monitor.c | 482 ++ .../nimble/nimble/host/src/ble_monitor_priv.h | 100 + .../src/nimble/nimble/host/src/ble_sm.c | 2869 +++++++ .../src/nimble/nimble/host/src/ble_sm_alg.c | 772 ++ .../src/nimble/nimble/host/src/ble_sm_cmd.c | 71 + .../src/nimble/nimble/host/src/ble_sm_lgcy.c | 256 + .../src/nimble/nimble/host/src/ble_sm_priv.h | 428 ++ .../src/nimble/nimble/host/src/ble_sm_sc.c | 918 +++ .../src/nimble/nimble/host/src/ble_store.c | 420 + .../nimble/nimble/host/src/ble_store_util.c | 276 + .../src/nimble/nimble/host/src/ble_uuid.c | 263 + .../nimble/nimble/host/src/ble_uuid_priv.h | 45 + .../include/store/config/ble_store_config.h | 39 + .../host/store/config/src/ble_store_config.c | 531 ++ .../store/config/src/ble_store_config_conf.c | 296 + .../store/config/src/ble_store_config_priv.h | 62 + .../host/store/config/src/ble_store_nvs.c | 653 ++ .../nimble/host/util/include/host/util/util.h | 46 + .../src/nimble/nimble/host/util/src/addr.c | 105 + .../src/nimble/nimble/include/nimble/ble.h | 311 + .../nimble/include/nimble/ble_hci_trans.h | 407 + .../nimble/nimble/include/nimble/hci_common.h | 1978 +++++ .../nimble/nimble/include/nimble/nimble_npl.h | 180 + .../nimble/nimble/include/nimble/nimble_opt.h | 34 + .../nimble/include/nimble/nimble_opt_auto.h | 117 + .../ram/include/transport/ram/ble_hci_ram.h | 35 + .../nimble/transport/ram/src/ble_hci_ram.c | 241 + .../porting/nimble/include/hal/hal_timer.h | 173 + .../nimble/porting/nimble/include/log/log.h | 34 + .../nimble/include/log_common/ignore.h | 64 + .../nimble/include/log_common/log_common.h | 145 + .../porting/nimble/include/logcfg/logcfg.h | 176 + .../nimble/porting/nimble/include/mem/mem.h | 107 + .../porting/nimble/include/modlog/modlog.h | 102 + .../nimble/include/nimble/nimble_port.h | 92 + .../nimble/porting/nimble/include/os/endian.h | 289 + .../src/nimble/porting/nimble/include/os/os.h | 59 + .../porting/nimble/include/os/os_cputime.h | 240 + .../porting/nimble/include/os/os_error.h | 62 + .../porting/nimble/include/os/os_mbuf.h | 1145 +++ .../porting/nimble/include/os/os_mempool.h | 414 + .../porting/nimble/include/os/os_trace_api.h | 277 + .../nimble/porting/nimble/include/os/queue.h | 218 + .../nimble/porting/nimble/include/os/util.h | 38 + .../porting/nimble/include/stats/stats.h | 80 + .../porting/nimble/include/syscfg/syscfg.h | 1505 ++++ .../nimble/include/sysflash/sysflash.h | 24 + .../porting/nimble/include/sysinit/sysinit.h | 37 + .../src/nimble/porting/nimble/src/endian.c | 268 + .../src/nimble/porting/nimble/src/hal_timer.c | 952 +++ .../src/nimble/porting/nimble/src/hal_uart.c | 388 + .../src/nimble/porting/nimble/src/mem.c | 345 + .../nimble/porting/nimble/src/nimble_port.c | 343 + .../nimble/porting/nimble/src/os_cputime.c | 126 + .../porting/nimble/src/os_cputime_pwr2.c | 95 + .../src/nimble/porting/nimble/src/os_mbuf.c | 1260 +++ .../nimble/porting/nimble/src/os_mempool.c | 486 ++ .../nimble/porting/nimble/src/os_msys_init.c | 218 + .../freertos/include/nimble/nimble_npl_os.h | 760 ++ .../include/nimble/nimble_port_freertos.h | 70 + .../freertos/include/nimble/npl_freertos.h | 124 + .../npl/freertos/src/nimble_port_freertos.c | 135 + .../npl/freertos/src/npl_os_freertos.c | 1941 +++++ components/NimBLE/src/nimconfig.h | 332 + components/NimBLE/src/nimconfig_rename.h | 61 + components/system/Mutex.cpp | 25 - components/system/Mutex.h | 22 - components/system/System.cpp | 1 + components/system/System.h | 52 + main/App.cpp | 33 +- main/App.h | 9 +- main/AppIF.h | 14 + main/Ble.cpp | 2 +- main/Buffers.h | 122 +- main/CMakeLists.txt | 2 +- main/Led.cpp | 11 +- main/Led.h | 8 +- main/Mqtt.cpp | 73 +- main/Mqtt.h | 3 + main/Ota.cpp | 4 +- main/Ota.h | 6 +- main/SensorData.cpp | 18 + main/SensorData.h | 112 + main/app_config.h | 6 +- main/sensors/Bme68x.cpp | 2 +- main/sensors/LD2410.h | 5 + main/sensors/Sensors.cpp | 37 +- main/sensors/Sensors.h | 16 +- wellhub.code-workspace | 3 +- 436 files changed, 173086 insertions(+), 141 deletions(-) create mode 100755 components/NimBLE/.github/workflows/build.yml create mode 100755 components/NimBLE/.github/workflows/release.yml create mode 100755 components/NimBLE/.gitignore create mode 100755 components/NimBLE/CHANGELOG.md create mode 100755 components/NimBLE/CMakeLists.txt create mode 100755 components/NimBLE/LICENSE create mode 100755 components/NimBLE/README.md create mode 100755 components/NimBLE/docs/Bluetooth 5 features.md create mode 100755 components/NimBLE/docs/Command_line_config.md create mode 100755 components/NimBLE/docs/Doxyfile create mode 100755 components/NimBLE/docs/Improvements_and_updates.md create mode 100755 components/NimBLE/docs/Migration_guide.md create mode 100755 components/NimBLE/docs/New_user_guide.md create mode 100755 components/NimBLE/docs/Usage_tips.md create mode 100755 components/NimBLE/docs/index.md create mode 100755 components/NimBLE/examples/BLE_Beacon_Scanner/BLE_Beacon_Scanner.ino create mode 100755 components/NimBLE/examples/BLE_Beacon_Scanner/BLE_Beacon_Scanner.md create mode 100755 components/NimBLE/examples/BLE_EddystoneTLM_Beacon/BLE_EddystoneTLM_Beacon.ino create mode 100755 components/NimBLE/examples/BLE_EddystoneTLM_Beacon/BLE_EddystoneTLM_Beacon.md create mode 100755 components/NimBLE/examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.ino create mode 100755 components/NimBLE/examples/BLE_EddystoneURL_Beacon/BLE_EddystoneURL_Beacon.md create mode 100755 components/NimBLE/examples/Bluetooth_5/NimBLE_extended_client/NimBLE_extended_client.ino create mode 100755 components/NimBLE/examples/Bluetooth_5/NimBLE_extended_server/NimBLE_extended_server.ino create mode 100755 components/NimBLE/examples/Bluetooth_5/NimBLE_multi_advertiser/NimBLE_multi_advertiser.ino create mode 100755 components/NimBLE/examples/NimBLE_Client/NimBLE_Client.ino create mode 100755 components/NimBLE/examples/NimBLE_Scan_Continuous/NimBLE_Scan_Continuous.ino create mode 100755 components/NimBLE/examples/NimBLE_Scan_Whitelist/NimBLE_Scan_whitelist.ino create mode 100755 components/NimBLE/examples/NimBLE_Secure_Client/NimBLE_Secure_Client.ino create mode 100755 components/NimBLE/examples/NimBLE_Secure_Server/NimBLE_Secure_Server.ino create mode 100755 components/NimBLE/examples/NimBLE_Server/NimBLE_Server.ino create mode 100755 components/NimBLE/examples/NimBLE_Server_Whitelist/NimBLE_Server_Whitelist.ino create mode 100755 components/NimBLE/examples/NimBLE_Service_Data_Advertiser/NimBLE_Service_Data_Advertiser.ino create mode 100755 components/NimBLE/examples/Refactored_original_examples/BLE_client/BLE_client.ino create mode 100755 components/NimBLE/examples/Refactored_original_examples/BLE_iBeacon/BLE_iBeacon.ino create mode 100755 components/NimBLE/examples/Refactored_original_examples/BLE_notify/BLE_notify.ino create mode 100755 components/NimBLE/examples/Refactored_original_examples/BLE_scan/BLE_scan.ino create mode 100755 components/NimBLE/examples/Refactored_original_examples/BLE_server/BLE_server.ino create mode 100755 components/NimBLE/examples/Refactored_original_examples/BLE_server_multiconnect/BLE_server_multiconnect.ino create mode 100755 components/NimBLE/examples/Refactored_original_examples/BLE_uart/BLE_uart.ino create mode 100755 components/NimBLE/examples/Refactored_original_examples/BLE_write/BLE_write.ino create mode 100755 components/NimBLE/library.properties create mode 100755 components/NimBLE/src/HIDKeyboardTypes.h create mode 100755 components/NimBLE/src/HIDTypes.h create mode 100755 components/NimBLE/src/NimBLE2904.cpp create mode 100755 components/NimBLE/src/NimBLE2904.h create mode 100755 components/NimBLE/src/NimBLEAddress.cpp create mode 100755 components/NimBLE/src/NimBLEAddress.h create mode 100755 components/NimBLE/src/NimBLEAdvertisedDevice.cpp create mode 100755 components/NimBLE/src/NimBLEAdvertisedDevice.h create mode 100755 components/NimBLE/src/NimBLEAdvertising.cpp create mode 100755 components/NimBLE/src/NimBLEAdvertising.h create mode 100755 components/NimBLE/src/NimBLEAttValue.h create mode 100755 components/NimBLE/src/NimBLEBeacon.cpp create mode 100755 components/NimBLE/src/NimBLEBeacon.h create mode 100755 components/NimBLE/src/NimBLECharacteristic.cpp create mode 100755 components/NimBLE/src/NimBLECharacteristic.h create mode 100755 components/NimBLE/src/NimBLEClient.cpp create mode 100755 components/NimBLE/src/NimBLEClient.h create mode 100755 components/NimBLE/src/NimBLEConnInfo.h create mode 100755 components/NimBLE/src/NimBLEDescriptor.cpp create mode 100755 components/NimBLE/src/NimBLEDescriptor.h create mode 100755 components/NimBLE/src/NimBLEDevice.cpp create mode 100755 components/NimBLE/src/NimBLEDevice.h create mode 100755 components/NimBLE/src/NimBLEEddystoneTLM.cpp create mode 100755 components/NimBLE/src/NimBLEEddystoneTLM.h create mode 100755 components/NimBLE/src/NimBLEEddystoneURL.cpp create mode 100755 components/NimBLE/src/NimBLEEddystoneURL.h create mode 100755 components/NimBLE/src/NimBLEExtAdvertising.cpp create mode 100755 components/NimBLE/src/NimBLEExtAdvertising.h create mode 100755 components/NimBLE/src/NimBLEHIDDevice.cpp create mode 100755 components/NimBLE/src/NimBLEHIDDevice.h create mode 100755 components/NimBLE/src/NimBLELog.h create mode 100755 components/NimBLE/src/NimBLERemoteCharacteristic.cpp create mode 100755 components/NimBLE/src/NimBLERemoteCharacteristic.h create mode 100755 components/NimBLE/src/NimBLERemoteDescriptor.cpp create mode 100755 components/NimBLE/src/NimBLERemoteDescriptor.h create mode 100755 components/NimBLE/src/NimBLERemoteService.cpp create mode 100755 components/NimBLE/src/NimBLERemoteService.h create mode 100755 components/NimBLE/src/NimBLEScan.cpp create mode 100755 components/NimBLE/src/NimBLEScan.h create mode 100755 components/NimBLE/src/NimBLESecurity.cpp create mode 100755 components/NimBLE/src/NimBLESecurity.h create mode 100755 components/NimBLE/src/NimBLEServer.cpp create mode 100755 components/NimBLE/src/NimBLEServer.h create mode 100755 components/NimBLE/src/NimBLEService.cpp create mode 100755 components/NimBLE/src/NimBLEService.h create mode 100755 components/NimBLE/src/NimBLEUUID.cpp create mode 100755 components/NimBLE/src/NimBLEUUID.h create mode 100755 components/NimBLE/src/NimBLEUtils.cpp create mode 100755 components/NimBLE/src/NimBLEUtils.h create mode 100755 components/NimBLE/src/nimble/CODING_STANDARDS.md create mode 100755 components/NimBLE/src/nimble/LICENSE create mode 100755 components/NimBLE/src/nimble/NOTICE create mode 100755 components/NimBLE/src/nimble/README.md create mode 100755 components/NimBLE/src/nimble/RELEASE_NOTES.md create mode 100755 components/NimBLE/src/nimble/console/console.h create mode 100755 components/NimBLE/src/nimble/esp_port/esp-hci/include/esp_compiler.h create mode 100755 components/NimBLE/src/nimble/esp_port/esp-hci/include/esp_nimble_hci.h create mode 100755 components/NimBLE/src/nimble/esp_port/esp-hci/src/esp_nimble_hci.c create mode 100755 components/NimBLE/src/nimble/esp_port/port/include/esp_nimble_cfg.h create mode 100755 components/NimBLE/src/nimble/esp_port/port/include/esp_nimble_mem.h create mode 100755 components/NimBLE/src/nimble/esp_port/port/src/esp_nimble_mem.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/AUTHORS create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/LICENSE create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/README create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/VERSION create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/documentation/tinycrypt.rst create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/aes.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/cbc_mode.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/ccm_mode.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/cmac_mode.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/constants.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/ctr_mode.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/ctr_prng.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/ecc.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/ecc_dh.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/ecc_dsa.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/ecc_platform_specific.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/hmac.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/hmac_prng.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/sha256.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/include/tinycrypt/utils.h create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/aes_decrypt.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/aes_encrypt.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/cbc_mode.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/ccm_mode.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/cmac_mode.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/ctr_mode.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/ctr_prng.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/ecc.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/ecc_dh.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/ecc_dsa.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/ecc_platform_specific.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/hmac.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/hmac_prng.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/sha256.c create mode 100755 components/NimBLE/src/nimble/ext/tinycrypt/src/utils.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_hw.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_adv.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_conn.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_ctrl.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_hci.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_iso.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_resolv.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_rfmgmt.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_scan.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_sched.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_sync.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_test.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_trace.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_utils.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_ll_whitelist.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_phy.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/include/controller/ble_phy_trace.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_adv.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_conn.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_conn_hci.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_conn_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_ctrl.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_dtm.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_dtm_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_hci.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_hci_ev.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_iso.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_rand.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_resolv.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_rfmgmt.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_scan.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_sched.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_supp_cmd.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_sync.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_trace.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_utils.c create mode 100755 components/NimBLE/src/nimble/nimble/controller/src/ble_ll_whitelist.c create mode 100755 components/NimBLE/src/nimble/nimble/drivers/nrf51/include/ble/xcvr.h create mode 100755 components/NimBLE/src/nimble/nimble/drivers/nrf51/src/ble_hw.c create mode 100755 components/NimBLE/src/nimble/nimble/drivers/nrf51/src/ble_phy.c create mode 100755 components/NimBLE/src/nimble/nimble/drivers/nrf52/include/ble/xcvr.h create mode 100755 components/NimBLE/src/nimble/nimble/drivers/nrf52/src/ble_hw.c create mode 100755 components/NimBLE/src/nimble/nimble/drivers/nrf52/src/ble_phy.c create mode 100755 components/NimBLE/src/nimble/nimble/drivers/nrf52/src/ble_phy_trace.c create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_att.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_eddystone.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_gap.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_gatt.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_hs.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_hs_adv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_hs_hci.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_hs_id.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_hs_log.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_hs_mbuf.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_hs_pvcy.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_hs_stop.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_ibeacon.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_l2cap.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_monitor.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_sm.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_store.h create mode 100755 components/NimBLE/src/nimble/nimble/host/include/host/ble_uuid.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/access.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/atomic.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/cdb.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/cfg.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/cfg_cli.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/cfg_srv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/glue.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/health_cli.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/health_srv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/heartbeat.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/main.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/mesh.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/model_cli.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/model_srv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/porting.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/proxy.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/slist.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/include/mesh/testing.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/access.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/access.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/adv.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/adv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/aes-ccm.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/app_keys.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/app_keys.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/atomic.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/beacon.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/beacon.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/cdb.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/cfg.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/cfg.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/cfg_cli.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/cfg_srv.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/crypto.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/crypto.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/foundation.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/friend.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/friend.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/glue.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/health_cli.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/health_srv.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/heartbeat.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/heartbeat.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/light_model.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/light_model.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/lpn.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/lpn.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/mesh.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/mesh_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/model_cli.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/model_srv.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/net.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/net.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/nodes.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/nodes.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/pb_adv.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/pb_gatt.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/prov.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/prov.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/prov_bearer.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/prov_device.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/provisioner.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/provisioner.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/proxy.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/proxy.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/rpl.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/rpl.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/settings.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/settings.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/shell.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/shell.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/subnet.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/subnet.h create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/transport.c create mode 100755 components/NimBLE/src/nimble/nimble/host/mesh/src/transport.h create mode 100755 components/NimBLE/src/nimble/nimble/host/services/ans/include/services/ans/ble_svc_ans.h create mode 100755 components/NimBLE/src/nimble/nimble/host/services/ans/src/ble_svc_ans.c create mode 100755 components/NimBLE/src/nimble/nimble/host/services/bas/include/services/bas/ble_svc_bas.h create mode 100755 components/NimBLE/src/nimble/nimble/host/services/bas/src/ble_svc_bas.c create mode 100755 components/NimBLE/src/nimble/nimble/host/services/dis/include/services/dis/ble_svc_dis.h create mode 100755 components/NimBLE/src/nimble/nimble/host/services/dis/src/ble_svc_dis.c create mode 100755 components/NimBLE/src/nimble/nimble/host/services/gap/include/services/gap/ble_svc_gap.h create mode 100755 components/NimBLE/src/nimble/nimble/host/services/gap/src/ble_svc_gap.c create mode 100755 components/NimBLE/src/nimble/nimble/host/services/gatt/include/services/gatt/ble_svc_gatt.h create mode 100755 components/NimBLE/src/nimble/nimble/host/services/gatt/src/ble_svc_gatt.c create mode 100755 components/NimBLE/src/nimble/nimble/host/services/ias/include/services/ias/ble_svc_ias.h create mode 100755 components/NimBLE/src/nimble/nimble/host/services/ias/src/ble_svc_ias.c create mode 100755 components/NimBLE/src/nimble/nimble/host/services/ipss/include/services/ipss/ble_svc_ipss.h create mode 100755 components/NimBLE/src/nimble/nimble/host/services/ipss/src/ble_svc_ipss.c create mode 100755 components/NimBLE/src/nimble/nimble/host/services/lls/include/services/lls/ble_svc_lls.h create mode 100755 components/NimBLE/src/nimble/nimble/host/services/lls/src/ble_svc_lls.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_att.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_att_clt.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_att_cmd.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_att_cmd_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_att_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_att_svr.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_eddystone.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_gap.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_gap_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_gatt_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_gattc.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_gatts.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_gatts_lcl.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_adv.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_adv_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_atomic.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_atomic_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_cfg.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_conn.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_conn_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_flow.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_flow_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_hci.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_hci_cmd.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_hci_evt.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_hci_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_hci_util.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_id.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_id_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_log.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_mbuf.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_mbuf_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_misc.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_mqueue.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_periodic_sync.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_periodic_sync_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_pvcy.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_pvcy_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_resolv.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_resolv_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_shutdown.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_startup.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_startup_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_hs_stop.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_ibeacon.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_l2cap.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_l2cap_coc.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_l2cap_coc_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_l2cap_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_l2cap_sig.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_l2cap_sig_cmd.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_l2cap_sig_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_monitor.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_monitor_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_sm.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_sm_alg.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_sm_cmd.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_sm_lgcy.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_sm_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_sm_sc.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_store.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_store_util.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_uuid.c create mode 100755 components/NimBLE/src/nimble/nimble/host/src/ble_uuid_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/store/config/include/store/config/ble_store_config.h create mode 100755 components/NimBLE/src/nimble/nimble/host/store/config/src/ble_store_config.c create mode 100755 components/NimBLE/src/nimble/nimble/host/store/config/src/ble_store_config_conf.c create mode 100755 components/NimBLE/src/nimble/nimble/host/store/config/src/ble_store_config_priv.h create mode 100755 components/NimBLE/src/nimble/nimble/host/store/config/src/ble_store_nvs.c create mode 100755 components/NimBLE/src/nimble/nimble/host/util/include/host/util/util.h create mode 100755 components/NimBLE/src/nimble/nimble/host/util/src/addr.c create mode 100755 components/NimBLE/src/nimble/nimble/include/nimble/ble.h create mode 100755 components/NimBLE/src/nimble/nimble/include/nimble/ble_hci_trans.h create mode 100755 components/NimBLE/src/nimble/nimble/include/nimble/hci_common.h create mode 100755 components/NimBLE/src/nimble/nimble/include/nimble/nimble_npl.h create mode 100755 components/NimBLE/src/nimble/nimble/include/nimble/nimble_opt.h create mode 100755 components/NimBLE/src/nimble/nimble/include/nimble/nimble_opt_auto.h create mode 100755 components/NimBLE/src/nimble/nimble/transport/ram/include/transport/ram/ble_hci_ram.h create mode 100755 components/NimBLE/src/nimble/nimble/transport/ram/src/ble_hci_ram.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/hal/hal_timer.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/log/log.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/log_common/ignore.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/log_common/log_common.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/logcfg/logcfg.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/mem/mem.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/modlog/modlog.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/nimble/nimble_port.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/os/endian.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/os/os.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/os/os_cputime.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/os/os_error.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/os/os_mbuf.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/os/os_mempool.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/os/os_trace_api.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/os/queue.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/os/util.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/stats/stats.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/syscfg/syscfg.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/sysflash/sysflash.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/include/sysinit/sysinit.h create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/endian.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/hal_timer.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/hal_uart.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/mem.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/nimble_port.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/os_cputime.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/os_cputime_pwr2.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/os_mbuf.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/os_mempool.c create mode 100755 components/NimBLE/src/nimble/porting/nimble/src/os_msys_init.c create mode 100755 components/NimBLE/src/nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h create mode 100755 components/NimBLE/src/nimble/porting/npl/freertos/include/nimble/nimble_port_freertos.h create mode 100755 components/NimBLE/src/nimble/porting/npl/freertos/include/nimble/npl_freertos.h create mode 100755 components/NimBLE/src/nimble/porting/npl/freertos/src/nimble_port_freertos.c create mode 100755 components/NimBLE/src/nimble/porting/npl/freertos/src/npl_os_freertos.c create mode 100755 components/NimBLE/src/nimconfig.h create mode 100755 components/NimBLE/src/nimconfig_rename.h delete mode 100644 components/system/Mutex.cpp delete mode 100644 components/system/Mutex.h create mode 100644 components/system/System.cpp create mode 100644 components/system/System.h create mode 100644 main/AppIF.h create mode 100644 main/SensorData.cpp create mode 100644 main/SensorData.h diff --git a/components/NimBLE/.github/workflows/build.yml b/components/NimBLE/.github/workflows/build.yml new file mode 100755 index 0000000..5d4afab --- /dev/null +++ b/components/NimBLE/.github/workflows/build.yml @@ -0,0 +1,146 @@ +name: Build + +on: [push, pull_request] + +jobs: + build_esp_pio: + strategy: + fail-fast: false + matrix: + example: + - "examples/NimBLE_Client" + - "examples/NimBLE_Server" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install platformio + run: | + python -m pip install --upgrade pip + pip install platformio + - name: Build esp PIO + run: | + mkdir -p example/lib + rsync -Rr . example/lib/ + mkdir example/src + cat > example/platformio.ini << EOF + [env] + platform = espressif32 + framework = arduino + + [env:esp32dev] + board = esp32dev + + [env:esp32c3] + board = esp32-c3-devkitm-1 + + [env:esp32s3] + board = esp32-s3-devkitc-1 + EOF + cp ${{ matrix.example }}/* example/src/ + platformio run -d example + + build_arduino-esp32: + strategy: + fail-fast: false + matrix: + example: + - "examples/NimBLE_Client" + - "examples/NimBLE_Server" + variant: + - esp32 + - esp32c3 + - esp32s3 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build arduino-esp32 + uses: arduino/compile-sketches@v1.1.0 + with: + cli-version: latest + platforms: | + - name: "esp32:esp32" + source-url: "https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json" + version: latest + fqbn: "esp32:esp32:${{ matrix.variant }}" + sketch-paths: ${{ matrix.example }} + + build_n-able-Arduino: + strategy: + fail-fast: false + matrix: + example: + - "examples/NimBLE_Client" + - "examples/NimBLE_Server" + variant: + - Generic_nRF51822:chip=xxaa + - Generic_nRF52832 + - Generic_nRF52833 + - Generic_nRF52840 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build n-able Arduino + uses: arduino/compile-sketches@v1.1.0 + with: + cli-version: latest + platforms: | + - name: "h2zero:arm-ble" + source-url: "https://h2zero.github.io/n-able-Arduino/package_n-able_boards_index.json" + version: latest + fqbn: "h2zero:arm-ble:${{ matrix.variant }}" + sketch-paths: ${{ matrix.example }} + + build_n-able-pio: + strategy: + fail-fast: false + matrix: + example: + - "examples/NimBLE_Client" + - "examples/NimBLE_Server" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install platformio + run: | + python -m pip install --upgrade pip + pip install platformio + - name: Build esp PIO + run: | + mkdir -p example/lib + rsync -Rr . example/lib/ + mkdir example/src + cat > example/platformio.ini << EOF + [env] + platform = https://github.com/h2zero/platform-n-able.git#1.0.0 + framework = arduino + + [env:generic_nrf51822_xxaa + board = generic_nrf51822_xxaa + + [env:generic_nrf52832] + board = generic_nrf52832 + + [env:generic_nrf52833] + board = generic_nrf52833 + + [env:generic_nrf52840] + board = generic_nrf52840 + EOF + cp ${{ matrix.example }}/* example/src/ + platformio run -d example + build_docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Doxygen Action + uses: mattnotmitt/doxygen-action@v1.9.5 + with: + working-directory: 'docs/' diff --git a/components/NimBLE/.github/workflows/release.yml b/components/NimBLE/.github/workflows/release.yml new file mode 100755 index 0000000..5b5c955 --- /dev/null +++ b/components/NimBLE/.github/workflows/release.yml @@ -0,0 +1,22 @@ +name: Release + +on: + release: + types: [published] + workflow_dispatch: + +jobs: + build_docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Doxygen Action + uses: mattnotmitt/doxygen-action@v1.9.5 + with: + working-directory: 'docs/' + + - name: Deploy + uses: peaceiris/actions-gh-pages@v3.9.3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/doxydocs/html \ No newline at end of file diff --git a/components/NimBLE/.gitignore b/components/NimBLE/.gitignore new file mode 100755 index 0000000..111405a --- /dev/null +++ b/components/NimBLE/.gitignore @@ -0,0 +1 @@ +docs/doxydocs diff --git a/components/NimBLE/CHANGELOG.md b/components/NimBLE/CHANGELOG.md new file mode 100755 index 0000000..43fbc62 --- /dev/null +++ b/components/NimBLE/CHANGELOG.md @@ -0,0 +1,311 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## [1.4.1] - 2022-10-23 + +### Fixed + - Compile warning removed for esp32c3 + - NimBLEDevice::getPower incorrect value when power level is -3db. + - Failed pairing when already in progress. + +### Changed + - Revert previous change that forced writing with response when subscribing in favor of allowing the application to decide. + +### Added + - Added NimBLEHIDDevice::batteryLevel. + - Added NimBLEDevice::setDeviceName allowing for changing the device name while the BLE stack is active. + - CI build tests. + - Missing items in CHANGELOG that were not recorded correctly + +## [1.4.0] - 2022-07-10 + +### Fixed +- Fixed missing data from long notification values. +- Fixed NimbleCharacteristicCallbacks::onRead not being called when a non-long read command is received. + +### Changed +- Updated NimBLE core to use the v1.4.0 branch of esp-nimble. +- AD flags are no longer set in the advertisements of non-connectable beacons, freeing up 3 bytes of advertisement room. +- Config option CONFIG_BT_NIMBLE_DEBUG replaced with CONFIG_BT_NIMBLE_LOG_LEVEL (see src/nimconfig.h for usage) +- Config option CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT renamed to CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT +- Config option CONFIG_BT_NIMBLE_TASK_STACK_SIZE renamed to CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE + +### Added +- Preliminary support for non-esp devices, NRF51 and NRF52 devices supported with [n-able arduino core](https://github.com/h2zero/n-able-Arduino) +- Alias added for `NimBLEServerCallbacks::onMTUChange` to `onMtuChanged` in order to support porting code from original library. +- `NimBLEAttValue` Class added to reduce and control RAM footprint of characteristic/descriptor values and support conversions from Arduino Strings and many other data types. +- Bluetooth 5 extended advertising support for capable devices. CODED Phy, 2M Phy, extended advertising data, and multi-advertising are supported, periodic advertising will be implemented in the future. + +## [1.3.8] - 2022-04-27 + +### Fixed +- Fix compile error with ESP32S3. +- Prevent a potential crash when retrieving characteristics from a service if the result was successful but no characteristics found. + +### Changed +- Save resources when retrieving descriptors if the characteristic handle is the same as the end handle (no descriptors). +- Subscribing to characteristic notifications/indications will now always use write with response, as per BLE specifications. +- `NimBLEClient::discoverAttributes` now returns a bool value to indicate success/failure + +## [1.3.7] - 2022-02-15 + +### Fixed + +- Crash when retrieving an attribute that does not exist on the peer. +- Memory leak when deleting client instances. +- Compilation errors for esp32s3 + +## [1.3.6] - 2022-01-18 + +### Changed +- When retrieving attributes from a server fails with a 128bit UUID containing the ble base UUID another attempt will be made with the 16bit version of the UUID. + +### Fixed +- Memory leak when services are changed on server devices. +- Rare crashing that occurs when BLE commands are sent from ISR context using IPC. +- Crashing caused by uninitialized disconnect timer in client. +- Potential crash due to uninitialized advertising callback pointer. + +## [1.3.5] - 2022-01-14 + +### Added +- CONFIG_NIMBLE_CPP_DEBUG_LEVEL macro in nimconfig.h to allow setting the log level separately from the Arduino core log level. + +### Fixed +- Memory leak when initializing/deinitializing the BLE stack caused by new FreeRTOS timers be created on each initialization. + +## [1.3.4] - 2022-01-09 + +### Fixed +- Workaround for latest Arduino-esp32 core that causes tasks not to block when required, which caused functions to return prematurely resulting in exceptions/crashing. +- The wrong length value was being used to set the values read from peer attributes. This has been corrected to use the proper value size. + +## [1.3.3] - 2021-11-24 + +### Fixed +- Workaround added for FreeRTOS bug that affected timers, causing scan and advertising timer expirations to not correctly trigger callbacks. + +## [1.3.2] - 2021-11-20 + +### Fixed +- Added missing macros for scan filter. + +### Added +- `NimBLEClient::getLastError` : Gets the error code of the last function call that produces a return code from the stack. + +## [1.3.1] - 2021-08-04 + +### Fixed +- Corrected a compiler/linker error when an application or a library uses bluetooth classic due to the redefinition of `btInUse`. + +## [1.3.0] - 2021-08-02 + +### Added +- `NimBLECharacteristic::removeDescriptor`: Dynamically remove a descriptor from a characteristic. Takes effect after all connections are closed and sends a service changed indication. +- `NimBLEService::removeCharacteristic`: Dynamically remove a characteristic from a service. Takes effect after all connections are closed and sends a service changed indication +- `NimBLEServerCallbacks::onMTUChange`: This is callback is called when the MTU is updated after connection with a client. +- ESP32C3 support + +- Whitelist API: + - `NimBLEDevice::whiteListAdd`: Add a device to the whitelist. + - `NimBLEDevice::whiteListRemove`: Remove a device from the whitelist. + - `NimBLEDevice::onWhiteList`: Check if the device is on the whitelist. + - `NimBLEDevice::getWhiteListCount`: Gets the size of the whitelist + - `NimBLEDevice::getWhiteListAddress`: Get the address of a device on the whitelist by index value. + +- Bond management API: + - `NimBLEDevice::getNumBonds`: Gets the number of bonds stored. + - `NimBLEDevice::isBonded`: Checks if the device is bonded. + - `NimBLEDevice::deleteAllBonds`: Deletes all bonds. + - `NimBLEDevice::getBondedAddress`: Gets the address of a bonded device by the index value. + +- `NimBLECharacteristic::getCallbacks` to retrieve the current callback handler. +- Connection Information class: `NimBLEConnInfo`. +- `NimBLEScan::clearDuplicateCache`: This can be used to reset the cache of advertised devices so they will be immediately discovered again. + +### Changed +- FreeRTOS files have been removed as they are not used by the library. +- Services, characteristics and descriptors can now be created statically and added after. +- Excess logging and some asserts removed. +- Use ESP_LOGx macros to enable using local log level filtering. + +### Fixed +- `NimBLECharacteristicCallbacks::onSubscribe` Is now called after the connection is added to the vector. +- Corrected bonding failure when reinitializing the BLE stack. +- Writing to a characteristic with a std::string value now correctly writes values with null characters. +- Retrieving remote descriptors now uses the characteristic end handle correctly. +- Missing data in long writes to remote descriptors. +- Hanging on task notification when sending an indication from the characteristic callback. +- BLE controller memory could be released when using Arduino as a component. +- Compile errors with NimBLE release 1.3.0. + +## [1.2.0] - 2021-02-08 + +### Added +- `NimBLECharacteristic::getDescriptorByHandle`: Return the BLE Descriptor for the given handle. + +- `NimBLEDescriptor::getStringValue`: Get the value of this descriptor as a string. + +- `NimBLEServer::getServiceByHandle`: Get a service by its handle. + +- `NimBLEService::getCharacteristicByHandle`: Get a pointer to the characteristic object with the specified handle. + +- `NimBLEService::getCharacteristics`: Get the vector containing pointers to each characteristic associated with this service. +Overloads to get a vector containing pointers to all the characteristics in a service with the UUID. (supports multiple same UUID's in a service) + - `NimBLEService::getCharacteristics(const char *uuid)` + - `NimBLEService::getCharacteristics(const NimBLEUUID &uuid)` + +- `NimBLEAdvertisementData` New methods: + - `NimBLEAdvertisementData::addTxPower`: Adds transmission power to the advertisement. + - `NimBLEAdvertisementData::setPreferredParams`: Adds connection parameters to the advertisement. + - `NimBLEAdvertisementData::setURI`: Adds URI data to the advertisement. + +- `NimBLEAdvertising` New methods: + - `NimBLEAdvertising::setName`: Set the name advertised. + - `NimBLEAdvertising::setManufacturerData`: Adds manufacturer data to the advertisement. + - `NimBLEAdvertising::setURI`: Adds URI data to the advertisement. + - `NimBLEAdvertising::setServiceData`: Adds service data to the advertisement. + - `NimBLEAdvertising::addTxPower`: Adds transmission power to the advertisement. + - `NimBLEAdvertising::reset`: Stops the current advertising and resets the advertising data to the default values. + +- `NimBLEDevice::setScanFilterMode`: Set the controller duplicate filter mode for filtering scanned devices. + +- `NimBLEDevice::setScanDuplicateCacheSize`: Sets the number of advertisements filtered before the cache is reset. + +- `NimBLEScan::setMaxResults`: This allows for setting a maximum number of advertised devices stored in the results vector. + +- `NimBLEAdvertisedDevice` New data retrieval methods added: + - `haveAdvInterval/getAdvInterval`: checks if the interval is advertised / gets the advertisement interval value. + + - `haveConnParams/getMinInterval/getMaxInterval`: checks if the parameters are advertised / get min value / get max value. + + - `haveURI/getURI`: checks if a URI is advertised / gets the URI data. + + - `haveTargetAddress/getTargetAddressCount/getTargetAddress(index)`: checks if a target address is present / gets a count of the addresses targeted / gets the address of the target at index. + +### Changed +- `nimconfig.h` (Arduino) is now easier to use. + +- `NimBLEServer::getServiceByUUID` Now takes an extra parameter of instanceID to support multiple services with the same UUID. + +- `NimBLEService::getCharacteristic` Now takes an extra parameter of instanceID to support multiple characteristics with the same UUID. + +- `NimBLEAdvertising` Transmission power is no longer advertised by default and can be added to the advertisement by calling `NimBLEAdvertising::addTxPower` + +- `NimBLEAdvertising` Custom scan response data can now be used without custom advertisement. + +- `NimBLEScan` Now uses the controller duplicate filter. + +- `NimBLEAdvertisedDevice` Has been refactored to store the complete advertisement payload and no longer parses the data from each advertisement. +Instead the data will be parsed on-demand when the user application asks for specific data. + +### Fixed +- `NimBLEHIDDevice` Characteristics now use encryption, this resolves an issue with communicating with devices requiring encryption for HID devices. + + +## [1.1.0] - 2021-01-20 + +### Added +- `NimBLEDevice::setOwnAddrType` added to enable the use of random and random-resolvable addresses, by asukiaaa + +- New examples for securing and authenticating client/server connections, by mblasee. + +- `NimBLEAdvertising::SetMinPreferred` and `NimBLEAdvertising::SetMinPreferred` re-added. + +- Conditional checks added for command line config options in `nimconfig.h` to support custom configuration in platformio. + +- `NimBLEClient::setValue` Now takes an extra bool parameter `response` to enable the use of write with response (default = false). + +- `NimBLEClient::getCharacteristic(uint16_t handle)` Enabling the use of the characteristic handle to be used to find +the NimBLERemoteCharacteristic object. + +- `NimBLEHIDDevice` class added by wakwak-koba. + +- `NimBLEServerCallbacks::onDisconnect` overloaded callback added to provide a ble_gap_conn_desc parameter for the application +to obtain information about the disconnected client. + +- Conditional checks in `nimconfig.h` for command line defined macros to support platformio config settings. + +### Changed +- `NimBLEAdvertising::start` now returns a bool value to indicate success/failure. + +- Some asserts were removed in `NimBLEAdvertising::start` and replaced with better return code handling and logging. + +- If a host reset event occurs, scanning and advertising will now only be restarted if their previous duration was indefinite. + +- `NimBLERemoteCharacteristic::subscribe` and `NimBLERemoteCharacteristic::registerForNotify` will now set the callback +regardless of the existence of the CCCD and return true unless the descriptor write operation failed. + +- Advertising tx power level is now sent in the advertisement packet instead of scan response. + +- `NimBLEScan` When the scan ends the scan stopped flag is now set before calling the scan complete callback (if used) +this allows the starting of a new scan from the callback function. + +### Fixed +- Sometimes `NimBLEClient::connect` would hang on the task block if no event arrived to unblock. +A time limit has been added to timeout appropriately. + +- When getting descriptors for a characteristic the end handle of the service was used as a proxy for the characteristic end +handle. This would be rejected by some devices and has been changed to use the next characteristic handle as the end when possible. + +- An exception could occur when deleting a client instance if a notification arrived while the attribute vectors were being +deleted. A flag has been added to prevent this. + +- An exception could occur after a host reset event when the host re-synced if the tasks that were stopped during the event did +not finish processing. A yield has been added after re-syncing to allow tasks to finish before proceeding. + +- Occasionally the controller would fail to send a disconnected event causing the client to indicate it is connected +and would be unable to reconnect. A timer has been added to reset the host/controller if it expires. + +- Occasionally the call to start scanning would get stuck in a loop on BLE_HS_EBUSY, this loop has been removed. + +- 16bit and 32bit UUID's in some cases were not discovered or compared correctly if the device +advertised them as 16/32bit but resolved them to 128bits. Both are now checked. + +- `FreeRTOS` compile errors resolved in latest Arduino core and IDF v3.3. + +- Multiple instances of `time()` called inside critical sections caused sporadic crashes, these have been moved out of critical regions. + +- Advertisement type now correctly set when using non-connectable (advertiser only) mode. + +- Advertising payload length correction, now accounts for appearance. + +- (Arduino) Ensure controller mode is set to BLE Only. + + +## [1.0.2] - 2020-09-13 + +### Changed + +- `NimBLEAdvertising::start` Now takes 2 optional parameters, the first is the duration to advertise for (in seconds), the second is a +callback that is invoked when advertising ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API). + +- (Arduino) Maximum BLE connections can now be altered by only changing the value of `CONFIG_BT_NIMBLE_MAX_CONNECTIONS` in `nimconfig.h`. +Any changes to the controller max connection settings in `sdkconfig.h` will now have no effect when using this library. + +- (Arduino) Revert the previous change to fix the advertising start delay. Instead a replacement fix that routes all BLE controller commands from +a task running on core 0 (same as the controller) has been implemented. This improves response times and reliability for all BLE functions. + + +## [1.0.1] - 2020-09-02 + +### Added + +- Empty `NimBLEAddress` constructor: `NimBLEAddress()` produces an address of 00:00:00:00:00:00 type 0. +- Documentation of the difference of NimBLEAddress::getNative vs the original bluedroid library. + +### Changed + +- notify_callback typedef is now defined as std::function to enable the use of std::bind to call a class member function. + +### Fixed + +- Fix advertising start delay when first called. + + +## [1.0.0] - 2020-08-22 + +First stable release. + +All the original library functionality is complete and many extras added with full documentation. diff --git a/components/NimBLE/CMakeLists.txt b/components/NimBLE/CMakeLists.txt new file mode 100755 index 0000000..0bc50c2 --- /dev/null +++ b/components/NimBLE/CMakeLists.txt @@ -0,0 +1,17 @@ +set(COMPONENT_SRCDIRS + "src" +) + +set(COMPONENT_ADD_INCLUDEDIRS + "src" +) + +set(COMPONENT_REQUIRES + "arduino" + "AsyncTCP" +) + +register_component() + +target_compile_definitions(${COMPONENT_TARGET} PUBLIC -DESP32) +target_compile_options(${COMPONENT_TARGET} PRIVATE -fno-rtti) diff --git a/components/NimBLE/LICENSE b/components/NimBLE/LICENSE new file mode 100755 index 0000000..4abe696 --- /dev/null +++ b/components/NimBLE/LICENSE @@ -0,0 +1,219 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {2020} {Ryan Powell} + + Licensed 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. + +This product bundles queue.h 8.5, which is available under the "3-clause BSD" +license. For details, see porting/nimble/include/os/queue.h + +This product partly derives from FreeBSD, which is available under the +"3-clause BSD" license. For details, see: + * porting/nimble/src/os_mbuf.c + +This product bundles Gary S. Brown's CRC32 implementation, which is available +under the following license: + COPYRIGHT (C) 1986 Gary S. Brown. You may use this program, or + code or tables extracted from it, as desired without restriction. + +This product bundles tinycrypt, which is available under the "3-clause BSD" +license. For details, and bundled files see: + * ext/tinycrypt/LICENSE + +This product partly derives from esp32-snippets; Copyright 2017 Neil Kolban. \ No newline at end of file diff --git a/components/NimBLE/README.md b/components/NimBLE/README.md new file mode 100755 index 0000000..42e58fd --- /dev/null +++ b/components/NimBLE/README.md @@ -0,0 +1,72 @@ +[Latest release ![Release Version](https://img.shields.io/github/release/h2zero/NimBLE-Arduino.svg?style=plastic) +![Release Date](https://img.shields.io/github/release-date/h2zero/NimBLE-Arduino.svg?style=plastic)](https://github.com/h2zero/NimBLE-Arduino/releases/latest/) + +Need help? Have questions or suggestions? Join the [![Gitter](https://badges.gitter.im/NimBLE-Arduino/community.svg)](https://gitter.im/NimBLE-Arduino/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +
+ +# NimBLE-Arduino +A fork of the NimBLE stack refactored for compilation in the Arduino IDE. + +**As of release 1.4.0 Nordic Semiconductor nRF51 and nRF52 series devices are now supported** + +## Supported MCU's + - Espressif: ESP32, ESP32C3, ESP32S3 + - Nordic: nRF51, nRF52 series (**Requires** using [n-able arduino core](https://github.com/h2zero/n-able-Arduino)) + +**Note for ESP-IDF users: This repo will not compile correctly in ESP-IDF. An ESP-IDF component version of this library can be [found here.](https://github.com/h2zero/esp-nimble-cpp)** + +This library **significantly** reduces resource usage and improves performance for ESP32 BLE applications as compared with the bluedroid based library. The goal is to maintain, as much as reasonable, compatibility with the original library but refactored to use the NimBLE stack. In addition, this library will be more actively developed and maintained to provide improved capabilities and stability over the original. +
+ +For Nordic devices, this library provides access to a completely open source and configurable BLE stack. No softdevice to work around, allowing for full debugging and resource management, continuous updates, with a cross platform API. + +# Arduino installation +**Arduino Library manager:** Go to `sketch` -> `Include Library` -> `Manage Libraries`, search for NimBLE and install. + +**Alternatively:** Download as .zip and extract to Arduino/libraries folder, or in Arduino IDE from Sketch menu -> Include library -> Add .Zip library. + +`#include "NimBLEDevice.h"` at the beginning of your sketch. + +# Platformio installation +* Open platformio.ini, a project configuration file located in the root of PlatformIO project. +* Add the following line to the lib_deps option of [env:] section: +``` +h2zero/NimBLE-Arduino@^1.4.0 +``` +* Build a project, PlatformIO will automatically install dependencies. + +# Using +This library is intended to be compatible with the original ESP32 BLE functions and types with minor changes. + +If you have not used the original Bluedroid library please refer to the [New user guide](docs/New_user_guide.md). + +If you are familiar with the original library, see: [The migration guide](docs/Migration_guide.md) for details about breaking changes and migration. + +Also see [Improvements_and_updates](docs/Improvements_and_updates.md) for information about non-breaking changes. + +[Full API documentation and class list can be found here.](https://h2zero.github.io/NimBLE-Arduino/) + +For added performance and optimizations see [Usage tips](docs/Usage_tips.md). + +Check the Refactored_original_examples in the examples folder for highlights of the differences with the original library. + +More advanced examples highlighting many available features are in examples/ NimBLE_Server, NimBLE_Client. + +Beacon examples provided by @beegee-tokyo are in examples/ BLE_Beacon_Scanner, BLE_EddystoneTLM_Beacon, BLE_EddystoneURL_Beacon. + +Change the settings in the `src/nimconfig.h` file to customize NimBLE to your project, +such as increasing max connections, default is 3, absolute maximum connections is 9. +
+ +# Development Status +This Library is tracking the esp-nimble repo, nimble-1.4.0-idf branch, currently [@3df0d20.](https://github.com/espressif/esp-nimble) + +Also tracking the NimBLE related changes in ESP-IDF, master branch, currently [@95db4bb.](https://github.com/espressif/esp-idf/tree/master/components/bt/host/nimble) +
+ +# Acknowledgments +* [nkolban](https://github.com/nkolban) and [chegewara](https://github.com/chegewara) for the [original esp32 BLE library](https://github.com/nkolban/esp32-snippets/tree/master/cpp_utils) this project was derived from. +* [beegee-tokyo](https://github.com/beegee-tokyo) for contributing your time to test/debug and contributing the beacon examples. +* [Jeroen88](https://github.com/Jeroen88) for the amazing help debugging and improving the client code. +
+ diff --git a/components/NimBLE/docs/Bluetooth 5 features.md b/components/NimBLE/docs/Bluetooth 5 features.md new file mode 100755 index 0000000..3737b0d --- /dev/null +++ b/components/NimBLE/docs/Bluetooth 5 features.md @@ -0,0 +1,28 @@ +# Bluetooth 5.x features + +## About extended advertising +Extended advertising allows for much more capability and flexibility. + +* Allows for 251 bytes of advertisement data and up to 1650 bytes when chained (configuration dependant) vs 31. + +* New PHY's (physical layers) that allow for faster data rate (2M PHY) or long range/slower data rates (CODED PHY) as well as the original 1M PHY. + +* New periodic advertising, allowing the scanning device to sync with the advertisements of a beacon. This allows for the scanning device to sleep or perform other tasks before the next expected advertisement is sent, preserving cpu cycles and power (To be implemented). +
+ +## Enabling extended advertising +Extended advertising is supported when enabled with the config option `CONFIG_BT_NIMBLE_EXT_ADV` set to a value of 1. This is done in menuconfig under `Component config > Bluetooth > NimBLE options > Enable extended advertising`, or set in `nimconfig.h` for Arduino, or in `build_flags` in PlatformIO. + +When enabled the following will occur: +* `NimBLEScan::start` method will scan on both the 1M PHY and the coded PHY standards automatically. + +* `NimBLEClient::connect` will use the primary PHY the device is listening on, unless specified (see below). + +* `NimBLEClient::setConnectPhy` becomes available to specify the PHY's to connect with (default is all). + +* `NimBLEAdvertising` is no longer available for use and is replaced by `NimBLEExtAdvertising`. `NimBLEDevice::getAdvertising` will now return an instance of `NimBLEExtAdvertising`. + +* `NimBLEAdvertisementData` is no longer available for use and is replaced by `NimBLEExtAdvertisement`. This new class is where everything about the advertisement is configured, including the advertisement intervals and advertisement ended callback. + + + diff --git a/components/NimBLE/docs/Command_line_config.md b/components/NimBLE/docs/Command_line_config.md new file mode 100755 index 0000000..f6f6b5a --- /dev/null +++ b/components/NimBLE/docs/Command_line_config.md @@ -0,0 +1,180 @@ +# Arduino command line and platformio config options + +`CONFIG_BT_NIMBLE_MAX_CONNECTIONS` + +Sets the number of simultaneous connections (esp controller max is 9) +- Default value is 3 +
+ +`CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED` + +Enable/disable storing the timestamp when an attribute value is updated +This allows for checking the last update time using getTimeStamp() or getValue(time_t*) +If disabled, the timestamp returned from these functions will be 0. +Disabling timestamps will reduce the memory used for each value. +1 = Enabled, 0 = Disabled; Default = Disabled +
+ +`CONFIG_NIMBLE_CPP_ATT_VALUE_INIT_LENGTH` + +Set the default allocation size (bytes) for each attribute. +If not specified when the constructor is called. This is also the size used when a remote +characteristic or descriptor is constructed before a value is read/notifed. +Increasing this will reduce reallocations but increase memory footprint. +Default value is 20. Range: 1 : 512 (BLE_ATT_ATTR_MAX_LEN) +
+ +`CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU` + +Sets the default MTU size. +- Default value is 255 +
+ +`CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME` + +Set the default device name +- Default value is "nimble" +
+ +`CONFIG_BT_NIMBLE_DEBUG` + +If defined, enables debug log messages from the NimBLE host +- Uses approx. 32kB of flash memory. +
+ +`CONFIG_NIMBLE_CPP_LOG_LEVEL` + +Define to set the debug log message level from the NimBLE CPP Wrapper. +If not defined it will use the same value as the Arduino core debug level. +Values: 0 = NONE, 1 = ERROR, 2 = WARNING, 3 = INFO, 4+ = DEBUG +
+ +`CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT` + +If defined, NimBLE host return codes will be printed as text in debug log messages. +- Uses approx. 7kB of flash memory. +
+ +`CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT` + +If defined, GAP event codes will be printed as text in debug log messages. +- Uses approx. 1kB of flash memory. +
+ +`CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT` + +If defined, advertisment types will be printed as text while scanning in debug log messages. +- Uses approx. 250 bytes of flash memory. +
+ +`CONFIG_BT_NIMBLE_SVC_GAP_APPEARANCE` + +Set the default appearance. +- Default value is 0x00 +
+ +`CONFIG_BT_NIMBLE_ROLE_CENTRAL_DISABLED` + +If defined, NimBLE Client functions will not be included. +- Reduces flash size by approx. 7kB. +
+ +`CONFIG_BT_NIMBLE_ROLE_OBSERVER_DISABLED` + +If defined, NimBLE Scan functions will not be included. +- Reduces flash size by approx. 26kB. +
+ +`CONFIG_BT_NIMBLE_ROLE_PERIPHERAL_DISABLED` + +If defined NimBLE Server functions will not be included. +- Reduces flash size by approx. 16kB. +
+ +`CONFIG_BT_NIMBLE_ROLE_BROADCASTER_DISABLED` + +If defined, NimBLE Advertising functions will not be included. +- Reduces flash size by approx. 5kB. +
+ +`CONFIG_BT_NIMBLE_MAX_BONDS` + +Sets the number of devices allowed to store/bond with +- Default value is 3 +
+ +`CONFIG_BT_NIMBLE_MAX_CCCDS` + +Sets the maximum number of CCCD subscriptions to store +- Default value is 8 +
+ +`CONFIG_BT_NIMBLE_RPA_TIMEOUT` + +Sets the random address refresh time in seconds. +- Default value is 900 +
+ +`CONFIG_BT_NIMBLE_MSYS1_BLOCK_COUNT` + +Set the number of msys blocks For prepare write & prepare responses. This may need to be increased if +you are sending large blocks of data with a low MTU. E.g: 512 bytes with 23 MTU will fail. +- Default value is 12 +
+ +`CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL` + +Sets the NimBLE stack to use external PSRAM will be loaded +- Must be defined with a value of 1; Default is CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL 1 +
+ +`CONFIG_BT_NIMBLE_PINNED_TO_CORE` + +Sets the core the NimBLE host stack will run on +- Options: 0 or 1 +
+ +`CONFIG_BT_NIMBLE_TASK_STACK_SIZE` + +Set the task stack size for the NimBLE core. +- Default is 4096 +
+ +`CONFIG_NIMBLE_STACK_USE_MEM_POOLS` + + Enable the use of memory pools for stack operations. This will use slightly more RAM but may provide more stability. + +- Options: 0 or 1, default is disabled (0) +
+ +### Extended advertising settings, For use with ESP32C3, ESP32S3, ESP32H2 ONLY! + +`CONFIG_BT_NIMBLE_EXT_ADV` + +Set to 1 to enable extended advertising features. +
+ +`CONFIG_BT_NIMBLE_MAX_EXT_ADV_INSTANCES` + +Sets the max number of extended advertising instances +- Range: 0 - 4 +- Default is 1 +
+ +`CONFIG_BT_NIMBLE_MAX_EXT_ADV_DATA_LEN` + +Set the max extended advertising data size, +- Range: 31 - 1650 +- Default is 255 +
+ +`CONFIG_BT_NIMBLE_ENABLE_PERIODIC_ADV` + +Set to 1 to enable periodic advertising. +
+ +`CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS` + +Set the maximum number of periodically synced devices. +- Range: 1 - 8 +- Default is 1 diff --git a/components/NimBLE/docs/Doxyfile b/components/NimBLE/docs/Doxyfile new file mode 100755 index 0000000..4b14524 --- /dev/null +++ b/components/NimBLE/docs/Doxyfile @@ -0,0 +1,2777 @@ +# Doxyfile 1.9.5 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). +# +# Note: +# +# Use doxygen to compare the used configuration file with the template +# configuration file: +# doxygen -x [configFile] +# Use doxygen to compare the used configuration file with the template +# configuration file without replacing the environment variables or CMake type +# replacement variables: +# doxygen -x_noenv [configFile] + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the configuration +# file that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# https://www.gnu.org/software/libiconv/ for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = NimBLE-Arduino + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = 1.4.1 + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = doxydocs + +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create up to 4096 +# sub-directories (in 2 levels) under the output directory of each output format +# and will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. Adapt CREATE_SUBDIRS_LEVEL to +# control the number of sub-directories. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# Controls the number of sub-directories that will be created when +# CREATE_SUBDIRS tag is set to YES. Level 0 represents 16 directories, and every +# level increment doubles the number of directories, resulting in 4096 +# directories at level 8 which is the default and also the maximum value. The +# sub-directories are organized in 2 levels, the first level always has a fixed +# numer of 16 directories. +# Minimum value: 0, maximum value: 8, default value: 8. +# This tag requires that the tag CREATE_SUBDIRS is set to YES. + +CREATE_SUBDIRS_LEVEL = 8 + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Bulgarian, +# Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, Dutch, English +# (United States), Esperanto, Farsi (Persian), Finnish, French, German, Greek, +# Hindi, Hungarian, Indonesian, Italian, Japanese, Japanese-en (Japanese with +# English messages), Korean, Korean-en (Korean with English messages), Latvian, +# Lithuanian, Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, +# Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, +# Swedish, Turkish, Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line +# such as +# /*************** +# as being the beginning of a Javadoc-style comment "banner". If set to NO, the +# Javadoc-style will behave just like regular comments and it will not be +# interpreted by doxygen. +# The default value is: NO. + +JAVADOC_BANNER = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# By default Python docstrings are displayed as preformatted text and doxygen's +# special commands cannot be used. By setting PYTHON_DOCSTRING to NO the +# doxygen's special commands can be used and the contents of the docstring +# documentation blocks is shown as doxygen documentation. +# The default value is: YES. + +PYTHON_DOCSTRING = YES + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:^^" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". Note that you cannot put \n's in the value part of an alias +# to insert newlines (in the resulting output). You can put ^^ in the value part +# of an alias to insert a newline as if a physical newline was in the original +# file. When you need a literal { or } or , in the value part of an alias you +# have to escape them by means of a backslash (\), this can lead to conflicts +# with the commands \{ and \} for these it is advised to use the version @{ and +# @} or use a double escape (\\{ and \\}) + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Set the OPTIMIZE_OUTPUT_SLICE tag to YES if your project consists of Slice +# sources only. Doxygen will then generate output that is more tailored for that +# language. For instance, namespaces will be presented as modules, types will be +# separated into more groups, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_SLICE = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, JavaScript, +# Csharp (C#), C, C++, Lex, D, PHP, md (Markdown), Objective-C, Python, Slice, +# VHDL, Fortran (fixed format Fortran: FortranFixed, free formatted Fortran: +# FortranFree, unknown formatted Fortran: Fortran. In the later case the parser +# tries to guess whether the code is fixed or free formatted code, this is the +# default for Fortran type files). For instance to make doxygen treat .inc files +# as Fortran files (default is PHP), and .f files as C (default is Fortran), +# use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. When specifying no_extension you should add +# * to the FILE_PATTERNS. +# +# Note see also the list of default file extension mappings. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See https://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When the TOC_INCLUDE_HEADINGS tag is set to a non-zero value, all headings up +# to that level are automatically included in the table of contents, even if +# they do not have an id attribute. +# Note: This feature currently applies only to Markdown headings. +# Minimum value: 0, maximum value: 99, default value: 5. +# This tag requires that the tag MARKDOWN_SUPPORT is set to YES. + +TOC_INCLUDE_HEADINGS = 5 + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# https://www.riverbankcomputing.com/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +# The NUM_PROC_THREADS specifies the number of threads doxygen is allowed to use +# during processing. When set to 0 doxygen will based this on the number of +# cores available in the system. You can set it explicitly to a value larger +# than 0 to get more control over the balance between CPU load and processing +# speed. At this moment only the input processing can be done using multiple +# threads. Since this is still an experimental feature the default is set to 1, +# which effectively disables parallel processing. Please report any issues you +# encounter. Generating dot graphs in parallel is controlled by the +# DOT_NUM_THREADS setting. +# Minimum value: 0, maximum value: 32, default value: 1. + +NUM_PROC_THREADS = 1 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PRIV_VIRTUAL tag is set to YES, documented private virtual +# methods of a class will be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIV_VIRTUAL = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If this flag is set to YES, the name of an unnamed parameter in a declaration +# will be determined by the corresponding definition. By default unnamed +# parameters remain unnamed in the output. +# The default value is: YES. + +RESOLVE_UNNAMED_PARAMS = YES + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = YES + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = YES + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# declarations. If set to NO, these declarations will be included in the +# documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = YES + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = YES + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# With the correct setting of option CASE_SENSE_NAMES doxygen will better be +# able to match the capabilities of the underlying filesystem. In case the +# filesystem is case sensitive (i.e. it supports files in the same directory +# whose names only differ in casing), the option must be set to YES to properly +# deal with such files in case they appear in the input. For filesystems that +# are not case sensitive the option should be set to NO to properly deal with +# output files written for symbols that only differ in casing, such as for two +# classes, one named CLASS and the other named Class, and to also support +# references to files without having to specify the exact matching casing. On +# Windows (including Cygwin) and MacOS, users should typically set this option +# to NO, whereas on Linux or other Unix flavors it should typically be set to +# YES. +# Possible values are: SYSTEM, NO and YES. +# The default value is: SYSTEM. + +CASE_SENSE_NAMES = NO + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = NO + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_HEADERFILE tag is set to YES then the documentation for a class +# will show which file needs to be included to use the class. +# The default value is: YES. + +SHOW_HEADERFILE = YES + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = NO + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = NO + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = NO + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. See also section "Changing the +# layout of pages" for information. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also https://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = YES + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as documenting some parameters in +# a documented function twice, or documenting parameters that don't exist or +# using markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# If WARN_IF_INCOMPLETE_DOC is set to YES, doxygen will warn about incomplete +# function parameter documentation. If set to NO, doxygen will accept that some +# parameters have no documentation without warning. +# The default value is: YES. + +WARN_IF_INCOMPLETE_DOC = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong parameter +# documentation, but not about the absence of documentation. If EXTRACT_ALL is +# set to YES then this flag will automatically be disabled. See also +# WARN_IF_INCOMPLETE_DOC +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# If the WARN_AS_ERROR tag is set to YES then doxygen will immediately stop when +# a warning is encountered. If the WARN_AS_ERROR tag is set to FAIL_ON_WARNINGS +# then doxygen will continue running as if WARN_AS_ERROR tag is set to NO, but +# at the end of the doxygen process doxygen will return with a non-zero status. +# Possible values are: NO, YES and FAIL_ON_WARNINGS. +# The default value is: NO. + +WARN_AS_ERROR = YES + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# See also: WARN_LINE_FORMAT +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# In the $text part of the WARN_FORMAT command it is possible that a reference +# to a more specific place is given. To make it easier to jump to this place +# (outside of doxygen) the user can define a custom "cut" / "paste" string. +# Example: +# WARN_LINE_FORMAT = "'vi $file +$line'" +# See also: WARN_FORMAT +# The default value is: at line $line of file $file. + +WARN_LINE_FORMAT = "at line $line of file $file" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). In case the file specified cannot be opened for writing the +# warning and error messages are written to standard error. When as file - is +# specified the warning and error messages are written to standard output +# (stdout). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. + +INPUT = . \ + ../src + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: +# https://www.gnu.org/software/libiconv/) for the list of possible encodings. +# See also: INPUT_FILE_ENCODING +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses The INPUT_FILE_ENCODING tag can be used to specify +# character encoding on a per file pattern basis. Doxygen will compare the file +# name with each pattern and apply the encoding instead of the default +# INPUT_ENCODING) if there is a match. The character encodings are a list of the +# form: pattern=encoding (like *.php=ISO-8859-1). See cfg_input_encoding +# "INPUT_ENCODING" for further information on supported encodings. + +INPUT_FILE_ENCODING = + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# Note the list of default checked file patterns might differ from the list of +# default file extension mappings. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.l, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, +# *.inc, *.m, *.markdown, *.md, *.mm, *.dox (to be provided as doxygen C +# comment), *.py, *.pyw, *.f90, *.f95, *.f03, *.f08, *.f18, *.f, *.for, *.vhd, +# *.vhdl, *.ucf, *.qsf and *.ice. + +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.idl \ + *.ddl \ + *.odl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.cs \ + *.d \ + *.php \ + *.php4 \ + *.php5 \ + *.phtml \ + *.inc \ + *.m \ + *.markdown \ + *.md \ + *.mm \ + *.dox \ + *.doc \ + *.txt \ + *.py \ + *.pyw \ + *.f90 \ + *.f95 \ + *.f03 \ + *.f08 \ + *.f18 \ + *.f \ + *.for \ + *.vhd \ + *.vhdl \ + *.ucf \ + *.qsf \ + *.ice + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = ./README.md \ + ./examples \ + ./CMakelists.txt \ + ../src/nimconfig_rename.h \ + ../src/nimble + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# ANamespace::AClass, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = * + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. +# +# Note that doxygen will use the data processed and written to standard output +# for further processing, therefore nothing else, like debug statements or used +# commands (so in case of a Windows batch file always use @echo OFF), should be +# written to standard output. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# properly processed by doxygen. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = index.md + +# The Fortran standard specifies that for fixed formatted Fortran code all +# characters from position 72 are to be considered as comment. A common +# extension is to allow longer lines before the automatic comment starts. The +# setting FORTRAN_COMMENT_AFTER will also make it possible that longer lines can +# be processed before the automatic comment starts. +# Minimum value: 7, maximum value: 10000, default value: 72. + +FORTRAN_COMMENT_AFTER = 72 + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# entity all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see https://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the configuration file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +# If the CLANG_ASSISTED_PARSING tag is set to YES then doxygen will use the +# clang parser (see: +# http://clang.llvm.org/) for more accurate parsing at the cost of reduced +# performance. This can be particularly helpful with template rich C++ code for +# which doxygen's built-in parser lacks the necessary type information. +# Note: The availability of this option depends on whether or not doxygen was +# generated with the -Duse_libclang=ON option for CMake. +# The default value is: NO. + +CLANG_ASSISTED_PARSING = NO + +# If the CLANG_ASSISTED_PARSING tag is set to YES and the CLANG_ADD_INC_PATHS +# tag is set to YES then doxygen will add the directory of each input to the +# include path. +# The default value is: YES. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_ADD_INC_PATHS = YES + +# If clang assisted parsing is enabled you can provide the compiler with command +# line options that you would normally use when invoking the compiler. Note that +# the include paths will already be set by doxygen for the files and directories +# specified with INPUT and INCLUDE_PATH. +# This tag requires that the tag CLANG_ASSISTED_PARSING is set to YES. + +CLANG_OPTIONS = + +# If clang assisted parsing is enabled you can provide the clang parser with the +# path to the directory containing a file called compile_commands.json. This +# file is the compilation database (see: +# http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html) containing the +# options used when the source files were built. This is equivalent to +# specifying the -p option to a clang tool, such as clang-check. These options +# will then be passed to the parser. Any options specified with CLANG_OPTIONS +# will be added as well. +# Note: The availability of this option depends on whether or not doxygen was +# generated with the -Duse_libclang=ON option for CMake. + +CLANG_DATABASE_PATH = + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE tag can be used to specify if the generated HTML output +# should be rendered with a dark or light theme. Default setting AUTO_LIGHT +# enables light output unless the user preference is dark output. Other options +# are DARK to always use dark mode, LIGHT to always use light mode, AUTO_DARK to +# default to dark mode unless the user prefers light mode, and TOGGLE to let the +# user toggle between dark and light mode via a button. +# Possible values are: LIGHT Always generate light output., DARK Always generate +# dark output., AUTO_LIGHT Automatically set the mode according to the user +# preference, use light mode if no preference is set (the default)., AUTO_DARK +# Automatically set the mode according to the user preference, use dark mode if +# no preference is set. and TOGGLE Allow to user to switch between light and +# dark mode via a button.. +# The default value is: AUTO_LIGHT. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE = AUTO_LIGHT + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a color-wheel, see +# https://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use gray-scales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = NO + +# If the HTML_DYNAMIC_MENUS tag is set to YES then the generated HTML +# documentation will contain a main index with vertical navigation menus that +# are dynamically created via JavaScript. If disabled, the navigation index will +# consists of multiple levels of tabs that are statically embedded in every HTML +# page. Disable this option to support browsers that do not have JavaScript, +# like the Qt help browser. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_MENUS = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: +# https://developer.apple.com/xcode/), introduced with OSX 10.5 (Leopard). To +# create a documentation set, doxygen will generate a Makefile in the HTML +# output directory. Running make will produce the docset in that directory and +# running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See https://developer.apple.com/library/archive/featuredarticles/Doxy +# genXcode/_index.html for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag determines the URL of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDURL = + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# on Windows. In the beginning of 2021 Microsoft took the original page, with +# a.o. the download links, offline the HTML help workshop was already many years +# in maintenance mode). You can download the HTML help workshop from the web +# archives at Installation executable (see: +# http://web.archive.org/web/20160201063255/http://download.microsoft.com/downlo +# ad/0/A/9/0A939EF6-E31C-430F-A3DF-DFAE7960D564/htmlhelp.exe). +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the main .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#virtual-folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = doc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#custom-filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# https://doc.qt.io/archives/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location (absolute path +# including file name) of Qt's qhelpgenerator. If non-empty doxygen will try to +# run qhelpgenerator on the generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine tune the look of the index (see "Fine-tuning the output"). As an +# example, the default style sheet generated by doxygen has an example that +# shows how to put an image at the root of the tree instead of the PROJECT_NAME. +# Since the tree basically has the same information as the tab index, you could +# consider setting DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = YES + +# When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the +# FULL_SIDEBAR option determines if the side bar is limited to only the treeview +# area (value NO) or if it should extend to the full height of the window (value +# YES). Setting this to YES gives a layout similar to +# https://docs.readthedocs.io with more room for contents, but less room for the +# project logo, title, and description. If either GENERATE_TREEVIEW or +# DISABLE_INDEX is set to NO, this option has no effect. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FULL_SIDEBAR = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# If the OBFUSCATE_EMAILS tag is set to YES, doxygen will obfuscate email +# addresses. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +OBFUSCATE_EMAILS = YES + +# If the HTML_FORMULA_FORMAT option is set to svg, doxygen will use the pdf2svg +# tool (see https://github.com/dawbarton/pdf2svg) or inkscape (see +# https://inkscape.org) to generate formulas as SVG images instead of PNGs for +# the HTML output. These images will generally look nicer at scaled resolutions. +# Possible values are: png (the default) and svg (looks nicer but requires the +# pdf2svg or inkscape tool). +# The default value is: png. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FORMULA_FORMAT = png + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# The FORMULA_MACROFILE can contain LaTeX \newcommand and \renewcommand commands +# to create new LaTeX commands to be used in formulas as building blocks. See +# the section "Including formulas" for details. + +FORMULA_MACROFILE = + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# https://www.mathjax.org) which uses client side JavaScript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# With MATHJAX_VERSION it is possible to specify the MathJax version to be used. +# Note that the different versions of MathJax have different requirements with +# regards to the different settings, so it is possible that also other MathJax +# settings have to be changed when switching between the different MathJax +# versions. +# Possible values are: MathJax_2 and MathJax_3. +# The default value is: MathJax_2. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_VERSION = MathJax_2 + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. For more details about the output format see MathJax +# version 2 (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) and MathJax version 3 +# (see: +# http://docs.mathjax.org/en/latest/web/components/output.html). +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility. This is the name for Mathjax version 2, for MathJax version 3 +# this will be translated into chtml), NativeMML (i.e. MathML. Only supported +# for NathJax 2. For MathJax version 3 chtml will be used instead.), chtml (This +# is the name for Mathjax version 3, for MathJax version 2 this will be +# translated into HTML-CSS) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from https://www.mathjax.org before deployment. The default value is: +# - in case of MathJax version 2: https://cdn.jsdelivr.net/npm/mathjax@2 +# - in case of MathJax version 3: https://cdn.jsdelivr.net/npm/mathjax@3 +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = https://cdn.jsdelivr.net/npm/mathjax@2 + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# for MathJax version 2 (see https://docs.mathjax.org/en/v2.7-latest/tex.html +# #tex-and-latex-extensions): +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# For example for MathJax version 3 (see +# http://docs.mathjax.org/en/latest/input/tex/extensions/index.html): +# MATHJAX_EXTENSIONS = ams +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: +# http://docs.mathjax.org/en/v2.7-latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /