ota download is now not using tls to download image, added Bme68x and sensors task
This commit is contained in:
parent
1adf9a477a
commit
dd17eb61e3
@ -10,6 +10,8 @@ MQTT server:
|
|||||||
|
|
||||||
This produces eventgrid.azure.pem certificate file.
|
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 www.bigfoot-inc.com:443
|
||||||
|
|
||||||
|
openssl s_client -showcerts -connect mqtt-dev-server.westus2-1.ts.eventgrid.azure.net:8883
|
||||||
28
Wifi.md
28
Wifi.md
@ -1,17 +1,27 @@
|
|||||||
```mermaid
|
```mermaid
|
||||||
graph
|
graph
|
||||||
A(Wifi start)
|
A(<b>Wifi start</b>)
|
||||||
|
A-->AA
|
||||||
|
AA[start wifi service]
|
||||||
B[Start provision]
|
B[Start provision]
|
||||||
A-->|not provisioned
|
AA-->|<b>not provisioned</b>
|
||||||
SETTINGS.wifi.num = 0|B
|
SETTINGS.wifi.num == 0|B
|
||||||
C{{single
|
C{{single
|
||||||
or
|
or
|
||||||
multiple}}
|
multiple}}
|
||||||
A-->|provisioned
|
AA-->|<b>provisioned</b>
|
||||||
SETTINGS.wifi.num > 0|C
|
SETTINGS.wifi.num > 0|C
|
||||||
D[connect]
|
D[try 3 times:
|
||||||
C-->|single
|
connect]
|
||||||
SETTINGS.wifi.num = 1|D
|
C-->|<b>single</b>
|
||||||
|
SETTINGS.wifi.num == 1|D
|
||||||
|
E[try 3 times:
|
||||||
|
connect to known SSID
|
||||||
|
with highest rssi]
|
||||||
|
C-->|<b>multiple</b>
|
||||||
|
SETTINGS.wifi.num > 1|E
|
||||||
|
F[try 3 times:
|
||||||
|
connect round robin]
|
||||||
|
E-->|failed|F
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@ -1,22 +1,20 @@
|
|||||||
-----BEGIN CERTIFICATE-----
|
-----BEGIN CERTIFICATE-----
|
||||||
MIIDqDCCAy6gAwIBAgIQDo2+XqYQ5su1acc29tcASzAKBggqhkjOPQQDAzBhMQsw
|
MIIDXDCCAuOgAwIBAgIQDvLl2DaBUgJV6Sxgj7wv9DAKBggqhkjOPQQDAzBhMQsw
|
||||||
CQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cu
|
CQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cu
|
||||||
ZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBHMzAe
|
ZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBHMzAe
|
||||||
Fw0yMDA4MTIwMDAwMDBaFw0yNDA2MjcyMzU5NTlaMF0xCzAJBgNVBAYTAlVTMR4w
|
Fw0yMzA2MDgwMDAwMDBaFw0yNjA4MjUyMzU5NTlaMF0xCzAJBgNVBAYTAlVTMR4w
|
||||||
HAYDVQQKExVNaWNyb3NvZnQgQ29ycG9yYXRpb24xLjAsBgNVBAMTJU1pY3Jvc29m
|
HAYDVQQKExVNaWNyb3NvZnQgQ29ycG9yYXRpb24xLjAsBgNVBAMTJU1pY3Jvc29m
|
||||||
dCBBenVyZSBFQ0MgVExTIElzc3VpbmcgQ0EgMDIwdjAQBgcqhkjOPQIBBgUrgQQA
|
dCBBenVyZSBFQ0MgVExTIElzc3VpbmcgQ0EgMDgwdjAQBgcqhkjOPQIBBgUrgQQA
|
||||||
IgNiAATlxJr7ThHOTChFtITU0Taop1bFSVf3h9toLKI7bi0GVWd3a3uQVIImulk4
|
IgNiAATlQzoKIJQIe8bd4sX2x9XBtFvoh5m7Neph3MYORvv/rg2Ew7Cfb00eZ+zS
|
||||||
pdVuOkoCI+wEIBkrsEnNUrH28+uUXb48SnwzdhArFcG3zygvZEnBYdcWNlOLKZ5X
|
njUosyOUCspenehe0PyKtmq6pPshLu5Ww/hLEoQT3drwxZ5PaYHmGEGoy2aPBeXa
|
||||||
ZhqUZKKjggGtMIIBqTAdBgNVHQ4EFgQUneUOdzdHngkz2ZC+KgnCEn9O0qMwHwYD
|
23k5ruijggFiMIIBXjASBgNVHRMBAf8ECDAGAQH/AgEAMB0GA1UdDgQWBBStVB0D
|
||||||
VR0jBBgwFoAUs9tIpPmhxdiuNkHMEWNpYim8S8YwDgYDVR0PAQH/BAQDAgGGMB0G
|
VHHGL17WWxhYzm4kxdaiCjAfBgNVHSMEGDAWgBSz20ik+aHF2K42QcwRY2liKbxL
|
||||||
A1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjASBgNVHRMBAf8ECDAGAQH/AgEA
|
xjAOBgNVHQ8BAf8EBAMCAYYwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMC
|
||||||
MHYGCCsGAQUFBwEBBGowaDAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNl
|
MHYGCCsGAQUFBwEBBGowaDAkBggrBgEFBQcwAYYYaHR0cDovL29jc3AuZGlnaWNl
|
||||||
cnQuY29tMEAGCCsGAQUFBzAChjRodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20v
|
cnQuY29tMEAGCCsGAQUFBzAChjRodHRwOi8vY2FjZXJ0cy5kaWdpY2VydC5jb20v
|
||||||
RGlnaUNlcnRHbG9iYWxSb290RzMuY3J0MHsGA1UdHwR0MHIwN6A1oDOGMWh0dHA6
|
RGlnaUNlcnRHbG9iYWxSb290RzMuY3J0MEIGA1UdHwQ7MDkwN6A1oDOGMWh0dHA6
|
||||||
Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RHMy5jcmwwN6A1
|
Ly9jcmwzLmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RHMy5jcmwwHQYD
|
||||||
oDOGMWh0dHA6Ly9jcmw0LmRpZ2ljZXJ0LmNvbS9EaWdpQ2VydEdsb2JhbFJvb3RH
|
VR0gBBYwFDAIBgZngQwBAgEwCAYGZ4EMAQICMAoGCCqGSM49BAMDA2cAMGQCMD+q
|
||||||
My5jcmwwHQYDVR0gBBYwFDAIBgZngQwBAgEwCAYGZ4EMAQICMBAGCSsGAQQBgjcV
|
5Uq1fSGZSKRhrnWKKXlp4DvfZCEU/MF3rbdwAaXI/KVM65YRO9HvRbfDpV3x1wIw
|
||||||
AQQDAgEAMAoGCCqGSM49BAMDA2gAMGUCMCIdzL1WliSNxC+uX8IzgfyxdmELlX0I
|
CHvqqpg/8YJPDn8NJIS/Rg+lYraOseXeuNYzkjeY6RLxIDB+nLVDs9QJ3/co89Cd
|
||||||
7TtWowrKUov8QSfi57irRIGpHvmxoFW7XQIxAPdJJZ/jAbKJ5lS21mLnKcdsctXO
|
|
||||||
tl2eFVqGSfIFWbJUihZCKesfoSMThZ4fa/Ir8g==
|
|
||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
|
|||||||
1
components/BME68x/.piopm
Executable file
1
components/BME68x/.piopm
Executable file
@ -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}}
|
||||||
16
components/BME68x/CMakeLists.txt
Executable file
16
components/BME68x/CMakeLists.txt
Executable file
@ -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)
|
||||||
34
components/BME68x/LICENSE
Executable file
34
components/BME68x/LICENSE
Executable file
@ -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.
|
||||||
11
components/BME68x/README.md
Executable file
11
components/BME68x/README.md
Executable file
@ -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
|
||||||
228
components/BME68x/examples/bme688_dev_kit/bme688_dev_kit.ino
Executable file
228
components/BME68x/examples/bme688_dev_kit/bme688_dev_kit.ino
Executable file
@ -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 <SD.h>
|
||||||
|
|
||||||
|
/* 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();
|
||||||
|
}
|
||||||
155
components/BME68x/examples/bme688_dev_kit/commMux.cpp
Executable file
155
components/BME68x/examples/bme688_dev_kit/commMux.cpp
Executable file
@ -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);
|
||||||
|
}
|
||||||
98
components/BME68x/examples/bme688_dev_kit/commMux.h
Executable file
98
components/BME68x/examples/bme688_dev_kit/commMux.h
Executable file
@ -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 */
|
||||||
70
components/BME68x/examples/forced_mode/forced_mode.ino
Executable file
70
components/BME68x/examples/forced_mode/forced_mode.ino
Executable file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
89
components/BME68x/examples/parallel_mode/parallel_mode.ino
Executable file
89
components/BME68x/examples/parallel_mode/parallel_mode.ino
Executable file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
87
components/BME68x/examples/sequential_mode/sequential_mode.ino
Executable file
87
components/BME68x/examples/sequential_mode/sequential_mode.ino
Executable file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
58
components/BME68x/keywords.txt
Executable file
58
components/BME68x/keywords.txt
Executable file
@ -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
|
||||||
10
components/BME68x/library.properties
Executable file
10
components/BME68x/library.properties
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
name=BME68x Sensor library
|
||||||
|
version=1.1.40407
|
||||||
|
author=Bosch Sensortec
|
||||||
|
maintainer=Bosch Sensortec <contact@bosch-sensortec.com>
|
||||||
|
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
|
||||||
30
components/BME68x/src/bme68x/LICENSE
Executable file
30
components/BME68x/src/bme68x/LICENSE
Executable file
@ -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.
|
||||||
30
components/BME68x/src/bme68x/README.md
Executable file
30
components/BME68x/src/bme68x/README.md
Executable file
@ -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)
|
||||||
|
|
||||||
|
---
|
||||||
1848
components/BME68x/src/bme68x/bme68x.c
Executable file
1848
components/BME68x/src/bme68x/bme68x.c
Executable file
File diff suppressed because it is too large
Load Diff
323
components/BME68x/src/bme68x/bme68x.h
Executable file
323
components/BME68x/src/bme68x/bme68x.h
Executable file
@ -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 <a href="https://www.bosch-sensortec.com/bst/products/all_products/bme680">Product Overview</a>
|
||||||
|
* and <a href="https://github.com/BoschSensortec/BME68x-Sensor-API">Sensor API Source Code</a>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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_ */
|
||||||
972
components/BME68x/src/bme68x/bme68x_defs.h
Executable file
972
components/BME68x/src/bme68x/bme68x_defs.h
Executable file
@ -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 <linux/types.h>
|
||||||
|
#include <linux/kernel.h>
|
||||||
|
#else
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#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 */
|
||||||
668
components/BME68x/src/bme68xLibrary.cpp
Executable file
668
components/BME68x/src/bme68xLibrary.cpp
Executable file
@ -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 <string.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
350
components/BME68x/src/bme68xLibrary.h
Executable file
350
components/BME68x/src/bme68xLibrary.h
Executable file
@ -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 <string.h>
|
||||||
|
#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 */
|
||||||
12
main/App.cpp
12
main/App.cpp
@ -5,7 +5,6 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
#include <Wire.h>
|
|
||||||
|
|
||||||
#include "Ota.h"
|
#include "Ota.h"
|
||||||
#include "ProvisionSoftAP.h"
|
#include "ProvisionSoftAP.h"
|
||||||
@ -73,15 +72,10 @@ void App::init()
|
|||||||
m_ble->start();
|
m_ble->start();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if 0
|
|
||||||
m_bmp280 = new Bmp280(Wire);
|
|
||||||
|
|
||||||
while(true)
|
m_sensors = new Sensors();
|
||||||
{
|
m_sensors->start();
|
||||||
m_bmp280->test();
|
|
||||||
delay(10);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::otaCheck()
|
void App::otaCheck()
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
#include "Wifi.h"
|
#include "Wifi.h"
|
||||||
#include "Mqtt.h"
|
#include "Mqtt.h"
|
||||||
#include "Ble.h"
|
#include "Ble.h"
|
||||||
#include "Bmp280.h"
|
#include "sensors/Sensors.h"
|
||||||
|
|
||||||
class App
|
class App
|
||||||
{
|
{
|
||||||
@ -18,7 +18,7 @@ protected:
|
|||||||
Wifi * m_wifi = nullptr;
|
Wifi * m_wifi = nullptr;
|
||||||
Mqtt * m_mqtt = nullptr;
|
Mqtt * m_mqtt = nullptr;
|
||||||
Ble * m_ble = nullptr;
|
Ble * m_ble = nullptr;
|
||||||
Bmp280 * m_bmp280 = nullptr;
|
Sensors * m_sensors = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Led * m_led = nullptr;
|
Led * m_led = nullptr;
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
/// © MiroZ 2024
|
|
||||||
|
|
||||||
#include "Bmp280.h"
|
|
||||||
|
|
||||||
#include <esp_log.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
@ -1,5 +1,6 @@
|
|||||||
idf_component_register(SRCS main.cpp App.cpp Settings.cpp Led.cpp TaskMgr.cpp Wifi.cpp utilities.cpp
|
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 "."
|
INCLUDE_DIRS "."
|
||||||
EMBED_TXTFILES ../html/logo.png ../html/provision.html
|
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
|
EMBED_TXTFILES ../certs/eventgrid.azure.pem ../certs/client1-authn-ID.key ../certs/client1-authn-ID.pem ../certs/bigfoot-inc.pem
|
||||||
|
|||||||
@ -109,7 +109,8 @@ Led::Led(uint32_t pin)
|
|||||||
assert(m_queue = xQueueCreate(5, sizeof(struct LED_QUEUE)));
|
assert(m_queue = xQueueCreate(5, sizeof(struct LED_QUEUE)));
|
||||||
|
|
||||||
// create the led task
|
// 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()
|
Led::~Led()
|
||||||
|
|||||||
35
main/Ota.cpp
35
main/Ota.cpp
@ -22,11 +22,12 @@
|
|||||||
|
|
||||||
#include <HTTPClient.h>
|
#include <HTTPClient.h>
|
||||||
|
|
||||||
#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");
|
extern const uint8_t server_cert[] asm("_binary_bigfoot_inc_pem_start");
|
||||||
|
|
||||||
static const char *TAG = "OTA";
|
static const char *TAG = "OTA";
|
||||||
|
|
||||||
|
#define FW_HEADER 32
|
||||||
|
|
||||||
Ota::Ota(App & app) : m_app(app)
|
Ota::Ota(App & app) : m_app(app)
|
||||||
{
|
{
|
||||||
@ -55,7 +56,8 @@ void Ota::start()
|
|||||||
|
|
||||||
HTTPClient client;
|
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();
|
int http_code = client.GET();
|
||||||
|
|
||||||
if(http_code != HTTP_CODE_OK)
|
if(http_code != HTTP_CODE_OK)
|
||||||
@ -68,7 +70,10 @@ void Ota::start()
|
|||||||
ESP_LOGI(TAG, "remote file len %d", remote_len);
|
ESP_LOGI(TAG, "remote file len %d", remote_len);
|
||||||
|
|
||||||
if(remote_len < 4096)
|
if(remote_len < 4096)
|
||||||
|
{
|
||||||
|
client.end();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
WiFiClient* stream = client.getStreamPtr();
|
WiFiClient* stream = client.getStreamPtr();
|
||||||
|
|
||||||
@ -94,9 +99,9 @@ void Ota::start()
|
|||||||
int binary_file_length = 0;
|
int binary_file_length = 0;
|
||||||
bool image_header_was_checked = false;
|
bool image_header_was_checked = false;
|
||||||
|
|
||||||
// ready header
|
// read the header
|
||||||
int data_read = stream->readBytes(otaWriteData, 32);
|
int data_read = stream->readBytes(otaWriteData, FW_HEADER);
|
||||||
if (data_read != 32)
|
if (data_read != FW_HEADER)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "Error: SSL data read error");
|
ESP_LOGE(TAG, "Error: SSL data read error");
|
||||||
return;
|
return;
|
||||||
@ -115,12 +120,19 @@ void Ota::start()
|
|||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "Invalid image!");
|
ESP_LOGE(TAG, "Invalid image!");
|
||||||
esp_aes_free(&m_dec_ctx);
|
esp_aes_free(&m_dec_ctx);
|
||||||
|
client.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int left = remote_len-FW_HEADER; // encryption header
|
||||||
|
|
||||||
while (1)
|
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]);
|
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)
|
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.",
|
ESP_LOGW(TAG, "Previously, there was an attempt to launch the firmware with %s version, but it failed.",
|
||||||
invalid_app_info.version);
|
invalid_app_info.version);
|
||||||
ESP_LOGW(TAG, "The firmware has been rolled back to the previous version.");
|
ESP_LOGW(TAG, "The firmware has been rolled back to the previous version.");
|
||||||
// httpCleanup(client);
|
|
||||||
|
client.end();
|
||||||
|
|
||||||
return;
|
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)
|
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.");
|
ESP_LOGI(TAG, "Current running version is the same as a remote. No need for update.");
|
||||||
|
client.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +208,7 @@ void Ota::start()
|
|||||||
|
|
||||||
image_header_was_checked = true;
|
image_header_was_checked = true;
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Starting...");
|
||||||
err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
|
err = esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
|
||||||
|
|
||||||
if (err != ESP_OK)
|
if (err != ESP_OK)
|
||||||
@ -225,15 +241,18 @@ void Ota::start()
|
|||||||
{
|
{
|
||||||
last_reported = progress;
|
last_reported = progress;
|
||||||
ESP_LOGI(TAG, "%d%%", last_reported);
|
ESP_LOGI(TAG, "%d%%", last_reported);
|
||||||
|
delay(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (data_read == 0)
|
else if (left == 0)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "All data received");
|
ESP_LOGI(TAG, "All data received");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
client.end();
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Total Write binary data length : %d", binary_file_length);
|
ESP_LOGI(TAG, "Total Write binary data length : %d", binary_file_length);
|
||||||
|
|
||||||
esp_aes_free(&m_dec_ctx);
|
esp_aes_free(&m_dec_ctx);
|
||||||
|
|||||||
@ -28,4 +28,16 @@
|
|||||||
#define TASKMGR_TASK_CORE 0
|
#define TASKMGR_TASK_CORE 0
|
||||||
#define TASKMGR_TASK_DELAY 60000
|
#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
|
#endif
|
||||||
60
main/sensors/Bme68x.cpp
Normal file
60
main/sensors/Bme68x.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
|
}
|
||||||
23
main/sensors/Bme68x.h
Normal file
23
main/sensors/Bme68x.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#ifndef __BME68X_h__
|
||||||
|
#define __BME68X_h__
|
||||||
|
|
||||||
|
#include <bme68xLibrary.h>
|
||||||
|
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
class Bme68x
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
MyLibs::Bme68x * m_sensor = nullptr;
|
||||||
|
TwoWire & m_bus;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Bme68x(TwoWire & bus);
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
void read();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
43
main/sensors/Bmp280.cpp
Normal file
43
main/sensors/Bmp280.cpp
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/// © MiroZ 2024
|
||||||
|
|
||||||
|
#include "Bmp280.h"
|
||||||
|
|
||||||
|
#include <esp_log.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
@ -10,12 +10,13 @@ class Bmp280
|
|||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
BMP280_DEV * m_sensor;
|
BMP280_DEV * m_sensor;
|
||||||
TwoWire & m_wire;
|
TwoWire & m_bus;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Bmp280(TwoWire & wire);
|
Bmp280(TwoWire & bus);
|
||||||
|
bool init();
|
||||||
|
|
||||||
bool test();
|
bool read();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
49
main/sensors/Sensors.cpp
Normal file
49
main/sensors/Sensors.cpp
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
24
main/sensors/Sensors.h
Normal file
24
main/sensors/Sensors.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
#include <stdint.h>
|
||||||
|
#include <esp_log.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
|
#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();
|
||||||
|
|
||||||
|
};
|
||||||
2
make.sh
2
make.sh
@ -10,8 +10,6 @@ if (($ret_val != 0)); then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cp build/wellhub.bin /var/www/esp_ota
|
|
||||||
|
|
||||||
if [$1 == '']; then
|
if [$1 == '']; then
|
||||||
idf.py -p /dev/ttyUSB1 -b 2000000 flash && idf.py -p /dev/ttyUSB1 monitor -B 450000
|
idf.py -p /dev/ttyUSB1 -b 2000000 flash && idf.py -p /dev/ttyUSB1 monitor -B 450000
|
||||||
else
|
else
|
||||||
|
|||||||
7
ota.sh
7
ota.sh
@ -5,16 +5,15 @@
|
|||||||
idf.py clean
|
idf.py clean
|
||||||
idf.py -DROLE=SENDER build
|
idf.py -DROLE=SENDER build
|
||||||
|
|
||||||
rm build/wellhub.enc.bin
|
|
||||||
|
|
||||||
ret_val=$?
|
ret_val=$?
|
||||||
|
|
||||||
if (($ret_val != 0)); then
|
if (($ret_val != 0)); then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm build/wellhub.enc.bin 2> /dev/null
|
||||||
|
echo "Encrypting image..."
|
||||||
image_enc/encrypt.py build/wellhub.bin build/wellhub.enc.bin
|
image_enc/encrypt.py build/wellhub.bin build/wellhub.enc.bin
|
||||||
|
echo "Uploading..."
|
||||||
cp build/wellhub.enc.bin /var/www/esp_ota
|
|
||||||
lftp -c "open -u mirozmrzli@bigfoot-inc.com,3445trGGDSa9 ftp.bigfoot-inc.com; put build/wellhub.enc.bin"
|
lftp -c "open -u mirozmrzli@bigfoot-inc.com,3445trGGDSa9 ftp.bigfoot-inc.com; put build/wellhub.enc.bin"
|
||||||
|
|
||||||
|
|||||||
@ -5,5 +5,4 @@ otadata,data,ota,0xe000,0x2000
|
|||||||
app0,app,ota_0,0x10000,0x1E0000
|
app0,app,ota_0,0x10000,0x1E0000
|
||||||
app1,app,ota_1,0x1F0000,0x1E0000
|
app1,app,ota_1,0x1F0000,0x1E0000
|
||||||
#eeprom,data,0x99,0x3F0000,0x1000
|
#eeprom,data,0x99,0x3F0000,0x1000
|
||||||
spiffs,data,spiffs,0x3F1000,0xF000
|
spiffs,data,spiffs,0x3F1000,0xF000
|
||||||
|
|
||||||
|
69
plot/plot.py
Executable file
69
plot/plot.py
Executable file
@ -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()
|
||||||
|
|
||||||
@ -74,7 +74,8 @@
|
|||||||
"netfwd": "cpp",
|
"netfwd": "cpp",
|
||||||
"numbers": "cpp",
|
"numbers": "cpp",
|
||||||
"semaphore": "cpp",
|
"semaphore": "cpp",
|
||||||
"stop_token": "cpp"
|
"stop_token": "cpp",
|
||||||
|
"*.ipp": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user