initial commit

This commit is contained in:
2026-02-10 01:30:42 +01:00
commit c4f018310f
21 changed files with 5506 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
+10
View File
@@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
+3
View File
@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(sen66_i2c_master)
+37
View File
@@ -0,0 +1,37 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the convention is to give header files names that end with `.h'.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
+46
View File
@@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into the executable file.
The source code of each library should be placed in a separate directory
("lib/your_library_name/[Code]").
For example, see the structure of the following example libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
Example contents of `src/main.c` using Foo and Bar:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
The PlatformIO Library Dependency Finder will find automatically dependent
libraries by scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
+14
View File
@@ -0,0 +1,14 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-c6-devkitc-1]
platform = espressif32
board = esp32-c6-devkitc-1
framework = espidf
File diff suppressed because it is too large Load Diff
+6
View File
@@ -0,0 +1,6 @@
# This file was automatically generated for projects
# without default 'CMakeLists.txt' file.
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
idf_component_register(SRCS ${app_sources})
+101
View File
@@ -0,0 +1,101 @@
/*
* Copyright (c) 2019 Tomoyuki Sakurai <y@trombik.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#if !defined(__ESP_IDF_LIB_HELPERS__H__)
#define __ESP_IDF_LIB_HELPERS__H__
/* XXX this header file does not need to include freertos/FreeRTOS.h.
* but without it, ESP8266 RTOS SDK does not include `sdkconfig.h` in correct
* order. as this header depends on sdkconfig.h, sdkconfig.h must be included
* first. however, the SDK includes this header first, then includes
* `sdkconfig.h` when freertos/FreeRTOS.h is not explicitly included. an
* evidence can be found in `build/${COMPONENT}/${COMPONENT}.d` in a failed
* build.
*/
#include <freertos/FreeRTOS.h>
#include <esp_idf_version.h>
#if !defined(ESP_IDF_VERSION) || !defined(ESP_IDF_VERSION_VAL)
#error Unknown ESP-IDF/ESP8266 RTOS SDK version
#endif
/* Minimal supported version for ESP32, ESP32S2 */
#define HELPER_ESP32_MIN_VER ESP_IDF_VERSION_VAL(3, 3, 5)
/* Minimal supported version for ESP8266 */
#define HELPER_ESP8266_MIN_VER ESP_IDF_VERSION_VAL(3, 3, 0)
/* HELPER_TARGET_IS_ESP32
* 1 when the target is esp32
*/
#if defined(CONFIG_IDF_TARGET_ESP32) \
|| defined(CONFIG_IDF_TARGET_ESP32S2) \
|| defined(CONFIG_IDF_TARGET_ESP32S3) \
|| defined(CONFIG_IDF_TARGET_ESP32C2) \
|| defined(CONFIG_IDF_TARGET_ESP32C3) \
|| defined(CONFIG_IDF_TARGET_ESP32C5) \
|| defined(CONFIG_IDF_TARGET_ESP32C6) \
|| defined(CONFIG_IDF_TARGET_ESP32P4) \
|| defined(CONFIG_IDF_TARGET_ESP32C61) \
|| defined(CONFIG_IDF_TARGET_ESP32H2)
#define HELPER_TARGET_IS_ESP32 (1)
/* HELPER_TARGET_IS_ESP8266
* 1 when the target is esp8266
*/
#elif defined(CONFIG_IDF_TARGET_ESP8266)
#define HELPER_TARGET_IS_ESP8266 (1)
#else
#error BUG: cannot determine the target
#endif
#if HELPER_TARGET_IS_ESP32 && ESP_IDF_VERSION < HELPER_ESP32_MIN_VER
#error Unsupported ESP-IDF version. Please update!
#endif
#if HELPER_TARGET_IS_ESP8266 && ESP_IDF_VERSION < HELPER_ESP8266_MIN_VER
#error Unsupported ESP8266 RTOS SDK version. Please update!
#endif
/* HELPER_SPI_HOST_DEFAULT
*
* The default SPI_HOST for spi_host_device_t
*/
#if CONFIG_IDF_TARGET_ESP32
#define HELPER_SPI_HOST_DEFAULT HSPI_HOST
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
#define HELPER_SPI_HOST_DEFAULT SPI2_HOST
#elif CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32C61
#define HELPER_SPI_HOST_DEFAULT SPI1_HOST
#elif CONFIG_IDF_TARGET_ESP32H2
#define HELPER_SPI_HOST_DEFAULT SPI1_HOST
#elif CONFIG_IDF_TARGET_ESP32P4
#define HELPER_SPI_HOST_DEFAULT SPI1_HOST
#endif
/* show the actual values for debugging */
#if DEBUG
#define VALUE_TO_STRING(x) #x
#define VALUE(x) VALUE_TO_STRING(x)
#define VAR_NAME_VALUE(var) #var "=" VALUE(var)
#pragma message(VAR_NAME_VALUE(CONFIG_IDF_TARGET_ESP32C3))
#pragma message(VAR_NAME_VALUE(CONFIG_IDF_TARGET_ESP32H2))
#pragma message(VAR_NAME_VALUE(CONFIG_IDF_TARGET_ESP32S2))
#pragma message(VAR_NAME_VALUE(CONFIG_IDF_TARGET_ESP32))
#pragma message(VAR_NAME_VALUE(CONFIG_IDF_TARGET_ESP8266))
#pragma message(VAR_NAME_VALUE(ESP_IDF_VERSION_MAJOR))
#endif
#endif
+73
View File
@@ -0,0 +1,73 @@
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
#include "sensirion_i2c_hal.h"
#include "sen66_i2c.h"
static const char *TAG = "SEN66_APP";
#ifndef SEN66_ADDR
#define SEN66_ADDR 0x6B
#endif
static void print_values(uint16_t pm1, uint16_t pm25, uint16_t pm4, uint16_t pm10,
int16_t rh, int16_t t, int16_t voc, int16_t nox, uint16_t co2) {
// Skalierung laut Datenblatt :contentReference[oaicite:1]{index=1}
float pm1_f = (pm1 == 0xFFFF) ? -1.0f : (pm1 / 10.0f);
float pm25_f = (pm25 == 0xFFFF) ? -1.0f : (pm25 / 10.0f);
float pm4_f = (pm4 == 0xFFFF) ? -1.0f : (pm4 / 10.0f);
float pm10_f = (pm10 == 0xFFFF) ? -1.0f : (pm10 / 10.0f);
float rh_f = (rh == 0x7FFF) ? -1.0f : (rh / 100.0f);
float t_f = (t == 0x7FFF) ? -1000.0f : (t / 200.0f);
float voc_f = (voc == 0x7FFF) ? -1.0f : (voc / 10.0f);
float nox_f = (nox == 0x7FFF) ? -1.0f : (nox / 10.0f);
ESP_LOGI(TAG,
"PM1=%.1f PM2.5=%.1f PM4=%.1f PM10=%.1f [ug/m3] | RH=%.2f%% | T=%.2fC | VOC=%.1f | NOx=%.1f | CO2=%u ppm",
pm1_f, pm25_f, pm4_f, pm10_f, rh_f, t_f, voc_f, nox_f, co2);
}
void app_main(void) {
sensirion_i2c_hal_init();
sen66_init(SEN66_ADDR);
int16_t err = sen66_start_continuous_measurement();
if (err) {
ESP_LOGE(TAG, "sen66_start_continuous_measurement failed: %d", err);
return;
}
ESP_LOGI(TAG, "SEN66 measurement started.");
while (1) {
uint8_t padding = 0;
bool ready = false;
err = sen66_get_data_ready(&padding, &ready);
if (err) {
ESP_LOGE(TAG, "sen66_get_data_ready failed: %d", err);
vTaskDelay(pdMS_TO_TICKS(1000));
continue;
}
if (ready) {
uint16_t pm1, pm25, pm4, pm10, co2;
int16_t rh, t, voc, nox;
err = sen66_read_measured_values_as_integers(&pm1, &pm25, &pm4, &pm10,
&rh, &t, &voc, &nox, &co2);
if (err) {
ESP_LOGE(TAG, "sen66_read_measured_values_as_integers failed: %d", err);
} else {
print_values(pm1, pm25, pm4, pm10, rh, t, voc, nox, co2);
}
}
vTaskDelay(pdMS_TO_TICKS(1000));
}
}
+723
View File
@@ -0,0 +1,723 @@
/*
* THIS FILE IS AUTOMATICALLY GENERATED
*
* Generator: sensirion-driver-generator 1.1.2
* Product: sen66
* Model-Version: 1.6.0
*/
/*
* Copyright (c) 2025, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of Sensirion AG 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.
*/
#include "sen66_i2c.h"
#include "sensirion_common.h"
#include "sensirion_i2c.h"
#include "sensirion_i2c_hal.h"
#define sensirion_hal_sleep_us sensirion_i2c_hal_sleep_usec
static uint8_t communication_buffer[48] = {0};
static uint8_t _i2c_address;
void sen66_init(uint8_t i2c_address) {
_i2c_address = i2c_address;
}
uint16_t sen66_signal_co2(uint16_t co2_raw) {
uint16_t co2 = 0;
co2 = co2_raw;
return co2;
}
int16_t sen66_start_continuous_measurement() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x21);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(50 * 1000);
return local_error;
}
int16_t sen66_stop_measurement() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x104);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(1000 * 1000);
return local_error;
}
int16_t sen66_get_data_ready(uint8_t* padding, bool* data_ready) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x202);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*padding = (uint8_t)buffer_ptr[0];
*data_ready = (bool)buffer_ptr[1];
return local_error;
}
int16_t sen66_read_measured_values_as_integers(
uint16_t* mass_concentration_pm1p0, uint16_t* mass_concentration_pm2p5,
uint16_t* mass_concentration_pm4p0, uint16_t* mass_concentration_pm10p0,
int16_t* ambient_humidity, int16_t* ambient_temperature, int16_t* voc_index,
int16_t* nox_index, uint16_t* co2) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x300);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 18);
if (local_error != NO_ERROR) {
return local_error;
}
*mass_concentration_pm1p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
*mass_concentration_pm2p5 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[2]);
*mass_concentration_pm4p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[4]);
*mass_concentration_pm10p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[6]);
*ambient_humidity = sensirion_common_bytes_to_int16_t(&buffer_ptr[8]);
*ambient_temperature = sensirion_common_bytes_to_int16_t(&buffer_ptr[10]);
*voc_index = sensirion_common_bytes_to_int16_t(&buffer_ptr[12]);
*nox_index = sensirion_common_bytes_to_int16_t(&buffer_ptr[14]);
*co2 = sensirion_common_bytes_to_uint16_t(&buffer_ptr[16]);
return local_error;
}
int16_t sen66_read_number_concentration_values_as_integers(
uint16_t* number_concentration_pm0p5, uint16_t* number_concentration_pm1p0,
uint16_t* number_concentration_pm2p5, uint16_t* number_concentration_pm4p0,
uint16_t* number_concentration_pm10p0) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x316);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 10);
if (local_error != NO_ERROR) {
return local_error;
}
*number_concentration_pm0p5 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
*number_concentration_pm1p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[2]);
*number_concentration_pm2p5 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[4]);
*number_concentration_pm4p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[6]);
*number_concentration_pm10p0 =
sensirion_common_bytes_to_uint16_t(&buffer_ptr[8]);
return local_error;
}
int16_t sen66_read_measured_raw_values(int16_t* raw_humidity,
int16_t* raw_temperature,
uint16_t* raw_voc, uint16_t* raw_nox,
uint16_t* raw_co2) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x405);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 10);
if (local_error != NO_ERROR) {
return local_error;
}
*raw_humidity = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
*raw_temperature = sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
*raw_voc = sensirion_common_bytes_to_uint16_t(&buffer_ptr[4]);
*raw_nox = sensirion_common_bytes_to_uint16_t(&buffer_ptr[6]);
*raw_co2 = sensirion_common_bytes_to_uint16_t(&buffer_ptr[8]);
return local_error;
}
int16_t sen66_start_fan_cleaning() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x5607);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_set_temperature_offset_parameters(int16_t offset, int16_t slope,
uint16_t time_constant,
uint16_t slot) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60b2);
local_offset =
sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset, offset);
local_offset =
sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset, slope);
local_offset = sensirion_i2c_add_uint16_t_to_buffer(
buffer_ptr, local_offset, time_constant);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, slot);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_set_voc_algorithm_tuning_parameters(
int16_t index_offset, int16_t learning_time_offset_hours,
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
int16_t std_initial, int16_t gain_factor) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60d0);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
index_offset);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, learning_time_offset_hours);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, learning_time_gain_hours);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, gating_max_duration_minutes);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
std_initial);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
gain_factor);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_voc_algorithm_tuning_parameters(
int16_t* index_offset, int16_t* learning_time_offset_hours,
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
int16_t* std_initial, int16_t* gain_factor) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60d0);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 12);
if (local_error != NO_ERROR) {
return local_error;
}
*index_offset = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
*learning_time_offset_hours =
sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
*learning_time_gain_hours =
sensirion_common_bytes_to_int16_t(&buffer_ptr[4]);
*gating_max_duration_minutes =
sensirion_common_bytes_to_int16_t(&buffer_ptr[6]);
*std_initial = sensirion_common_bytes_to_int16_t(&buffer_ptr[8]);
*gain_factor = sensirion_common_bytes_to_int16_t(&buffer_ptr[10]);
return local_error;
}
int16_t sen66_set_nox_algorithm_tuning_parameters(
int16_t index_offset, int16_t learning_time_offset_hours,
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
int16_t std_initial, int16_t gain_factor) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60e1);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
index_offset);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, learning_time_offset_hours);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, learning_time_gain_hours);
local_offset = sensirion_i2c_add_int16_t_to_buffer(
buffer_ptr, local_offset, gating_max_duration_minutes);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
std_initial);
local_offset = sensirion_i2c_add_int16_t_to_buffer(buffer_ptr, local_offset,
gain_factor);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_nox_algorithm_tuning_parameters(
int16_t* index_offset, int16_t* learning_time_offset_hours,
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
int16_t* std_initial, int16_t* gain_factor) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x60e1);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 12);
if (local_error != NO_ERROR) {
return local_error;
}
*index_offset = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
*learning_time_offset_hours =
sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
*learning_time_gain_hours =
sensirion_common_bytes_to_int16_t(&buffer_ptr[4]);
*gating_max_duration_minutes =
sensirion_common_bytes_to_int16_t(&buffer_ptr[6]);
*std_initial = sensirion_common_bytes_to_int16_t(&buffer_ptr[8]);
*gain_factor = sensirion_common_bytes_to_int16_t(&buffer_ptr[10]);
return local_error;
}
int16_t sen66_set_temperature_acceleration_parameters(uint16_t k, uint16_t p,
uint16_t t1,
uint16_t t2) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6100);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, k);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, p);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, t1);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, t2);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_set_voc_algorithm_state(const uint8_t* state,
uint16_t state_size) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6181);
sensirion_i2c_add_bytes_to_buffer(buffer_ptr, local_offset, state,
state_size);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
return local_error;
}
int16_t sen66_get_voc_algorithm_state(uint8_t* state, uint16_t state_size) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6181);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 8);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)state, state_size);
return local_error;
}
int16_t
sen66_perform_forced_co2_recalibration(uint16_t target_co2_concentration,
uint16_t* correction) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6707);
local_offset = sensirion_i2c_add_uint16_t_to_buffer(
buffer_ptr, local_offset, target_co2_concentration);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(500 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*correction = sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_set_co2_sensor_automatic_self_calibration(uint16_t status) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6711);
local_offset =
sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr, local_offset, status);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_co2_sensor_automatic_self_calibration(uint8_t* padding,
bool* status) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6711);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*padding = (uint8_t)buffer_ptr[0];
*status = (bool)buffer_ptr[1];
return local_error;
}
int16_t sen66_set_ambient_pressure(uint16_t ambient_pressure) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6720);
local_offset = sensirion_i2c_add_uint16_t_to_buffer(
buffer_ptr, local_offset, ambient_pressure);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_ambient_pressure(uint16_t* ambient_pressure) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6720);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*ambient_pressure = sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_set_sensor_altitude(uint16_t altitude) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6736);
local_offset = sensirion_i2c_add_uint16_t_to_buffer(buffer_ptr,
local_offset, altitude);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_sensor_altitude(uint16_t* altitude) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6736);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*altitude = sensirion_common_bytes_to_uint16_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_activate_sht_heater() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6765);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
return local_error;
}
int16_t sen66_get_sht_heater_measurements(int16_t* humidity,
int16_t* temperature) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0x6790);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 4);
if (local_error != NO_ERROR) {
return local_error;
}
*humidity = sensirion_common_bytes_to_int16_t(&buffer_ptr[0]);
*temperature = sensirion_common_bytes_to_int16_t(&buffer_ptr[2]);
return local_error;
}
int16_t sen66_get_product_name(int8_t* product_name,
uint16_t product_name_size) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd014);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 32);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)product_name,
product_name_size);
return local_error;
}
int16_t sen66_get_serial_number(int8_t* serial_number,
uint16_t serial_number_size) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd033);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 32);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_common_copy_bytes(&buffer_ptr[0], (uint8_t*)serial_number,
serial_number_size);
return local_error;
}
int16_t sen66_get_version(uint8_t* firmware_major, uint8_t* firmware_minor) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd100);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 2);
if (local_error != NO_ERROR) {
return local_error;
}
*firmware_major = (uint8_t)buffer_ptr[0];
*firmware_minor = (uint8_t)buffer_ptr[1];
return local_error;
}
int16_t sen66_read_device_status(sen66_device_status* device_status) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd206);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 4);
if (local_error != NO_ERROR) {
return local_error;
}
(*device_status).value = sensirion_common_bytes_to_uint32_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_read_and_clear_device_status(sen66_device_status* device_status) {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd210);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(20 * 1000);
local_error = sensirion_i2c_read_data_inplace(_i2c_address, buffer_ptr, 4);
if (local_error != NO_ERROR) {
return local_error;
}
(*device_status).value = sensirion_common_bytes_to_uint32_t(&buffer_ptr[0]);
return local_error;
}
int16_t sen66_device_reset() {
int16_t local_error = NO_ERROR;
uint8_t* buffer_ptr = communication_buffer;
uint16_t local_offset = 0;
local_offset =
sensirion_i2c_add_command16_to_buffer(buffer_ptr, local_offset, 0xd304);
local_error =
sensirion_i2c_write_data(_i2c_address, buffer_ptr, local_offset);
if (local_error != NO_ERROR) {
return local_error;
}
sensirion_i2c_hal_sleep_usec(1200 * 1000);
return local_error;
}
+859
View File
@@ -0,0 +1,859 @@
/*
* THIS FILE IS AUTOMATICALLY GENERATED
*
* Generator: sensirion-driver-generator 1.1.2
* Product: sen66
* Model-Version: 1.6.0
*/
/*
* Copyright (c) 2025, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of Sensirion AG 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.
*/
#ifndef SEN66_I2C_H
#define SEN66_I2C_H
#ifdef __cplusplus
extern "C" {
#endif
#include "sensirion_config.h"
#define SEN66_I2C_ADDR_6B 0x6b
typedef enum {
SEN66_START_CONTINUOUS_MEASUREMENT_CMD_ID = 0x21,
SEN66_STOP_MEASUREMENT_CMD_ID = 0x104,
SEN66_GET_DATA_READY_CMD_ID = 0x202,
SEN66_READ_MEASURED_VALUES_AS_INTEGERS_CMD_ID = 0x300,
SEN66_READ_NUMBER_CONCENTRATION_VALUES_AS_INTEGERS_CMD_ID = 0x316,
SEN66_READ_MEASURED_RAW_VALUES_CMD_ID = 0x405,
SEN66_START_FAN_CLEANING_CMD_ID = 0x5607,
SEN66_SET_TEMPERATURE_OFFSET_PARAMETERS_CMD_ID = 0x60b2,
SEN66_SET_VOC_ALGORITHM_TUNING_PARAMETERS_CMD_ID = 0x60d0,
SEN66_GET_VOC_ALGORITHM_TUNING_PARAMETERS_CMD_ID = 0x60d0,
SEN66_SET_NOX_ALGORITHM_TUNING_PARAMETERS_CMD_ID = 0x60e1,
SEN66_GET_NOX_ALGORITHM_TUNING_PARAMETERS_CMD_ID = 0x60e1,
SEN66_SET_TEMPERATURE_ACCELERATION_PARAMETERS_CMD_ID = 0x6100,
SEN66_SET_VOC_ALGORITHM_STATE_CMD_ID = 0x6181,
SEN66_GET_VOC_ALGORITHM_STATE_CMD_ID = 0x6181,
SEN66_PERFORM_FORCED_CO2_RECALIBRATION_CMD_ID = 0x6707,
SEN66_SET_CO2_SENSOR_AUTOMATIC_SELF_CALIBRATION_CMD_ID = 0x6711,
SEN66_GET_CO2_SENSOR_AUTOMATIC_SELF_CALIBRATION_CMD_ID = 0x6711,
SEN66_SET_AMBIENT_PRESSURE_CMD_ID = 0x6720,
SEN66_GET_AMBIENT_PRESSURE_CMD_ID = 0x6720,
SEN66_SET_SENSOR_ALTITUDE_CMD_ID = 0x6736,
SEN66_GET_SENSOR_ALTITUDE_CMD_ID = 0x6736,
SEN66_ACTIVATE_SHT_HEATER_CMD_ID = 0x6765,
SEN66_GET_SHT_HEATER_MEASUREMENTS_CMD_ID = 0x6790,
SEN66_GET_PRODUCT_NAME_CMD_ID = 0xd014,
SEN66_GET_SERIAL_NUMBER_CMD_ID = 0xd033,
SEN66_GET_VERSION_CMD_ID = 0xd100,
SEN66_READ_DEVICE_STATUS_CMD_ID = 0xd206,
SEN66_READ_AND_CLEAR_DEVICE_STATUS_CMD_ID = 0xd210,
SEN66_DEVICE_RESET_CMD_ID = 0xd304,
} SEN66_CMD_ID;
typedef union {
struct {
uint32_t reserved1 : 4;
uint32_t fan_error : 1;
uint32_t reserved2 : 1;
uint32_t rht_error : 1;
uint32_t gas_error : 1;
uint32_t reserved3 : 1;
uint32_t co2_2_error : 1;
uint32_t reserved4 : 1;
uint32_t pm_error : 1;
uint32_t reserved5 : 1;
uint32_t reserved6 : 8;
uint32_t fan_speed_warning : 1;
};
uint32_t value;
} sen66_device_status;
/**
* @brief Initialize i2c address of driver
*
* @param[in] i2c_address Used i2c address
*
*/
void sen66_init(uint8_t i2c_address);
/**
* @brief sen66_signal_co2
*
* @param[in] co2_raw
*
* @return Measured CO2 in ppm.
*/
uint16_t sen66_signal_co2(uint16_t co2_raw);
/**
* @brief Start a continuous measurement (interval 1s)
*
* Starts a continuous measurement. After starting the measurement, it takes
* some time (~1.1s) until the first measurement results are available. You
* could poll with the command "Get Data Ready" to check when the results are
* ready to read. This command is only available in idle mode. If the device is
* already in any measure mode, this command has no effect.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_start_continuous_measurement();
/**
* @brief Stop the continuous measurement
*
* Stops the measurement and returns to idle mode. After sending this command,
* wait at least 1000 ms before starting a new measurement. If the device is
* already in idle mode, this command has no effect.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_stop_measurement();
/**
* @brief Check if data is ready to be read out from the sensor
*
* This command can be used to check if new measurement results are ready to
* read. The data ready flag is automatically reset after reading the
* measurement values.
*
* @param[out] padding Padding byte, always 0x00.
* @param[out] data_ready True (0x01) if data is ready, False (0x00) if not.
* When no measurement is running, False will be returned.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_data_ready(uint8_t* padding, bool* data_ready);
/**
* @brief read measured values as integers.
*
* Returns the measured values. The command "Get Data Ready" can be used to
* check if new data is available since the last read operation. If no new data
* is available, the previous values will be returned again. If no data is
* available at all (e.g. measurement not running for at least one second), all
* values will be at their upper limit (0xFFFF for uint16, 0x7FFF for int16).
*
* @param[out] mass_concentration_pm1p0 Value is scaled with factor 10: PM1.0
* [µg/m³] = value / 10 *Note: If this value is unknown, 0xFFFF is returned.*
* @param[out] mass_concentration_pm2p5 Value is scaled with factor 10: PM2.5
* [µg/m³] = value / 10 *Note: If this value is unknown, 0xFFFF is returned.*
* @param[out] mass_concentration_pm4p0 Value is scaled with factor 10: PM4.0
* [µg/m³] = value / 10 *Note: If this value is unknown, 0xFFFF is returned.*
* @param[out] mass_concentration_pm10p0 Value is scaled with factor 10: PM10.0
* [µg/m³] = value / 10 *Note: If this value is unknown, 0xFFFF is returned.*
* @param[out] ambient_humidity Value is scaled with factor 100: RH [%] = value
* / 100 *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] ambient_temperature Value is scaled with factor 200: T [°C] =
* value / 200 *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] voc_index Value is scaled with factor 10: VOC Index = value / 10
* *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] nox_index Value is scaled with factor 10: NOx Index = value / 10
* *Note: If this value is unknown, 0x7FFF is returned. During the first 10..11
* seconds after power-on or device reset, this value will be 0x7FFF as well.*
* @param[out] co2 CO₂ concentration [ppm] *Note: If this value is unknown,
* 0xFFFF is returned. During the first 5..6 seconds after power-on or device
* reset, this value will be 0xFFFF as well.*
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_read_measured_values_as_integers(
uint16_t* mass_concentration_pm1p0, uint16_t* mass_concentration_pm2p5,
uint16_t* mass_concentration_pm4p0, uint16_t* mass_concentration_pm10p0,
int16_t* ambient_humidity, int16_t* ambient_temperature, int16_t* voc_index,
int16_t* nox_index, uint16_t* co2);
/**
* @brief sen66_read_number_concentration_values_as_integers
*
* Returns the measured number concentration values. The command "Get Data
* Ready" can be used to check if new data is available since the last read
* operation. If no new data is available, the previous values will be returned
* again. If no data is available at all (e.g. measurement not running for at
* least one second), all values will be at their upper limit (0xFFFF for
* uint16).
*
* @param[out] number_concentration_pm0p5 Value is scaled with factor 10: PM0.5
* [particles/cm³] = value / 10 *Note: If this value is unknown, 0xFFFF is
* returned.*
* @param[out] number_concentration_pm1p0 Value is scaled with factor 10: PM1.0
* [particles/cm³] = value / 10 *Note: If this value is unknown, 0xFFFF is
* returned.*
* @param[out] number_concentration_pm2p5 Value is scaled with factor 10: PM2.5
* [particles/cm³] = value / 10 *Note: If this value is unknown, 0xFFFF is
* returned.*
* @param[out] number_concentration_pm4p0 Value is scaled with factor 10: PM4.0
* [particles/cm³] = value / 10 *Note: If this value is unknown, 0xFFFF is
* returned.*
* @param[out] number_concentration_pm10p0 Value is scaled with factor 10:
* PM10.0 [particles/cm³] = value / 10 *Note: If this value is unknown, 0xFFFF
* is returned.*
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_read_number_concentration_values_as_integers(
uint16_t* number_concentration_pm0p5, uint16_t* number_concentration_pm1p0,
uint16_t* number_concentration_pm2p5, uint16_t* number_concentration_pm4p0,
uint16_t* number_concentration_pm10p0);
/**
* @brief sen66_read_measured_raw_values
*
* Returns the measured raw values. The command "Get Data Ready" can be used to
* check if new data is available since the last read operation. If no new data
* is available, the previous values will be returned again. If no data is
* available at all (e.g. measurement not running for at least one second), all
* values will be at their upper limit (0xFFFF for uint16, 0x7FFF for int16).
*
* @param[out] raw_humidity Value is scaled with factor 100: RH [%] = value /
* 100 *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] raw_temperature Value is scaled with factor 200: T [°C] = value /
* 200 *Note: If this value is unknown, 0x7FFF is returned.*
* @param[out] raw_voc Raw measured VOC ticks without scale factor. *Note: If
* this value is unknown, 0xFFFF is returned.*
* @param[out] raw_nox Raw measured NOx ticks without scale factor. *Note: If
* this value is unknown, 0xFFFF is returned. During the first 10..11 seconds
* after power-on or device reset, this value will be 0xFFFF as well.*
* @param[out] raw_co2 Not interpolated CO₂ concentration [ppm] updated every
* five seconds. *Note: If this value is unknown, 0xFFFF is returned. During the
* first 5..6 seconds after power-on or device reset, this value will be 0xFFFF
* as well.*
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_read_measured_raw_values(int16_t* raw_humidity,
int16_t* raw_temperature,
uint16_t* raw_voc, uint16_t* raw_nox,
uint16_t* raw_co2);
/**
* @brief sen66_start_fan_cleaning
*
* This command triggers fan cleaning. The fan is set to the maximum speed for
* 10 seconds and then automatically stopped. Wait at least 10s after this
* command before starting a measurement.
*
* @note This command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_start_fan_cleaning();
/**
* @brief sen66_set_temperature_offset_parameters
*
* This command allows to compensate temperature effects of the design-in at
* customer side by applying custom temperature offsets to the ambient
* temperature. The compensated ambient temperature is calculated as follows:
* T_Ambient_Compensated = T_Ambient + (slope * T_Ambient) + offset Where slope
* and offset are the values set with this command, smoothed with the specified
* time constant. All temperatures (T_Ambient_Compensated, T_Ambient and offset)
* are represented in °C. There are 5 temperature offset slots available that
* all contribute additively to T_Ambient_Compensated. The default values for
* the temperature offset parameters are all zero, meaning that
* T_Ambient_Compensated is equal to T_Ambient by default. The parameters can be
* changed in any state of the device, i.e. both in idle mode and in measure
* mode.
*
* @param[in] offset Constant temperature offset scaled with factor 200 (T [°C]
* = value / 200).
* @param[in] slope Normalized temperature offset slope scaled with factor 10000
* (applied factor = value / 10000).
* @param[in] time_constant The time constant determines how fast the new slope
* and offset will be applied. After the specified value in seconds, 63% of the
* new slope and offset are applied. A time constant of zero means the new
* values will be applied immediately (within the next measure interval of 1
* second).
* @param[in] slot The temperature offset slot to be modified. Valid values are
* 0 .. 4. If the value is outside this range, the parameters will not be
* applied.
*
* @note This configuration is volatile, i.e. the parameters will be reverted to
* their default value of zero after a device reset.
*
* @return error_code 0 on success, an error code otherwise.
*
* Example:
* --------
*
* @code{.c}
*
* int16_t local_error = 0;
* local_error = sen66_set_temperature_offset_parameters(1, 10, 1, 0);
* if (local_error != NO_ERROR) {
* return local_error;
* }
*
* @endcode
*
*/
int16_t sen66_set_temperature_offset_parameters(int16_t offset, int16_t slope,
uint16_t time_constant,
uint16_t slot);
/**
* @brief sen66_set_voc_algorithm_tuning_parameters
*
* Sets the parameters to customize the VOC algorithm. This configuration is
* volatile, i.e. the parameters will be reverted to their default values after
* a device reset.
*
* @param[in] index_offset VOC index representing typical (average) conditions.
* Allowed values are in range 1..250. The default value is 100.
* @param[in] learning_time_offset_hours Time constant to estimate the VOC
* algorithm offset from the history in hours. Past events will be forgotten
* after about twice the learning time. Allowed values are in range 1..1000. The
* default value is 12 hours.
* @param[in] learning_time_gain_hours Time constant to estimate the VOC
* algorithm gain from the history in hours. Past events will be forgotten after
* about twice the learning time. Allowed values are in range 1..1000. The
* default value is 12 hours.
* @param[in] gating_max_duration_minutes Maximum duration of gating in minutes
* (freeze of estimator during high VOC index signal). Set to zero to disable
* the gating. Allowed values are in range 0..3000. The default value is 180
* minutes
* @param[in] std_initial Initial estimate for standard deviation. Lower value
* boosts events during initial learning period, but may result in larger
* device-to-device variations. Allowed values are in range 10..5000. The
* default value is 50.
* @param[in] gain_factor Gain factor to amplify or to attenuate the VOC index
* output. Allowed values are in range 1..1000. The default value is 230.
*
* @note This command is available only in idle mode. In measure mode, this
* command has no effect. In addition, it has no effect if at least one
* parameter is outside the specified range.
*
* @return error_code 0 on success, an error code otherwise.
*
* Example:
* --------
*
* @code{.c}
*
* int16_t local_error = 0;
* local_error = sen66_set_voc_algorithm_tuning_parameters(100, 12, 12, 180,
* 50, 230); if (local_error != NO_ERROR) { return local_error;
* }
*
* @endcode
*
*/
int16_t sen66_set_voc_algorithm_tuning_parameters(
int16_t index_offset, int16_t learning_time_offset_hours,
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
int16_t std_initial, int16_t gain_factor);
/**
* @brief sen66_get_voc_algorithm_tuning_parameters
*
* Gets the parameters to customize the VOC algorithm.
*
* @param[out] index_offset VOC index representing typical (average) conditions.
* @param[out] learning_time_offset_hours Time constant to estimate the VOC
* algorithm offset from the history in hours. Past events will be forgotten
* after about twice the learning time.
* @param[out] learning_time_gain_hours Time constant to estimate the VOC
* algorithm gain from the history in hours. Past events will be forgotten after
* about twice the learning time.
* @param[out] gating_max_duration_minutes Maximum duration of gating in minutes
* (freeze of estimator during high VOC index signal). Zero disables the gating.
* @param[out] std_initial Initial estimate for standard deviation. Lower value
* boosts events during initial learning period, but may result in larger
* device-to-device variations.
* @param[out] gain_factor Gain factor to amplify or to attenuate the VOC index
* output.
*
* @note This command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_voc_algorithm_tuning_parameters(
int16_t* index_offset, int16_t* learning_time_offset_hours,
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
int16_t* std_initial, int16_t* gain_factor);
/**
* @brief sen66_set_nox_algorithm_tuning_parameters
*
* Sets the parameters to customize the NOx algorithm. This configuration is
* volatile, i.e. the parameters will be reverted to their default values after
* a device reset.
*
* @param[in] index_offset NOx index representing typical (average) conditions.
* Allowed values are in range 1..250. The default value is 1.
* @param[in] learning_time_offset_hours Time constant to estimate the NOx
* algorithm offset from the history in hours. Past events will be forgotten
* after about twice the learning time. Allowed values are in range 1..1000. The
* default value is 12 hours.
* @param[in] learning_time_gain_hours The time constant to estimate the NOx
* algorithm gain from the history has no impact for NOx. This parameter is
* still in place for consistency reasons with the VOC tuning parameters
* command. This parameter must always be set to 12 hours.
* @param[in] gating_max_duration_minutes Maximum duration of gating in minutes
* (freeze of estimator during high NOx index signal). Set to zero to disable
* the gating. Allowed values are in range 0..3000. The default value is 720
* minutes.
* @param[in] std_initial The initial estimate for standard deviation parameter
* has no impact for NOx. This parameter is still in place for consistency
* reasons with the VOC tuning parameters command. This parameter must always be
* set to 50.
* @param[in] gain_factor Gain factor to amplify or to attenuate the NOx index
* output. Allowed values are in range 1..1000. The default value is 230.
*
* @note This command is available only in idle mode. In measure mode, this
* command has no effect. In addition, it has no effect if at least one
* parameter is outside the specified range.
*
* @return error_code 0 on success, an error code otherwise.
*
* Example:
* --------
*
* @code{.c}
*
* int16_t local_error = 0;
* local_error = sen66_set_nox_algorithm_tuning_parameters(1, 12, 12, 720,
* 50, 230); if (local_error != NO_ERROR) { return local_error;
* }
*
* @endcode
*
*/
int16_t sen66_set_nox_algorithm_tuning_parameters(
int16_t index_offset, int16_t learning_time_offset_hours,
int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes,
int16_t std_initial, int16_t gain_factor);
/**
* @brief sen66_get_nox_algorithm_tuning_parameters
*
* Gets the parameters to customize the NOx algorithm.
*
* @param[out] index_offset NOx index representing typical (average) conditions.
* @param[out] learning_time_offset_hours Time constant to estimate the NOx
* algorithm offset from the history in hours. Past events will be forgotten
* after about twice the learning time.
* @param[out] learning_time_gain_hours The time constant to estimate the NOx
* algorithm gain from the history has no impact for NOx. This parameter is
* still in place for consistency reasons with the VOC tuning parameters
* command.
* @param[out] gating_max_duration_minutes Maximum duration of gating in minutes
* (freeze of estimator during high NOx index signal). Zero disables the gating.
* @param[out] std_initial The initial estimate for standard deviation has no
* impact for NOx. This parameter is still in place for consistency reasons with
* the VOC tuning parameters command.
* @param[out] gain_factor Gain factor to amplify or to attenuate the NOx index
* output.
*
* @note This command is available only in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_nox_algorithm_tuning_parameters(
int16_t* index_offset, int16_t* learning_time_offset_hours,
int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes,
int16_t* std_initial, int16_t* gain_factor);
/**
* @brief sen66_set_temperature_acceleration_parameters
*
* This command allows to set custom temperature acceleration parameters of the
* RH/T engine. It overwrites the default temperature acceleration parameters of
* the RH/T engine with custom values. This configuration is volatile, i.e. the
* parameters will be reverted to their default values after a device reset.
*
* @param[in] k Filter constant K scaled with factor 10 (K = value / 10).
* @param[in] p Filter constant P scaled with factor 10 (P = value / 10).
* @param[in] t1 Time constant T1 scaled with factor 10 (T1 [s] = value / 10).
* @param[in] t2 Time constant T2 scaled with factor 10 (T2 [s] = value / 10).
*
* @note The command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*
* Example:
* --------
*
* @code{.c}
*
* int16_t local_error = 0;
* local_error = sen66_set_temperature_acceleration_parameters(1, 1, 1, 1);
* if (local_error != NO_ERROR) {
* return local_error;
* }
*
* @endcode
*
*/
int16_t sen66_set_temperature_acceleration_parameters(uint16_t k, uint16_t p,
uint16_t t1, uint16_t t2);
/**
* @brief sen66_set_voc_algorithm_state
*
* Sets the VOC algorithm state previously received with "Get VOC Algorithm
* State" command. Allows restoration of the VOC algorithm state to resume
* operation after a power cycle or device reset, skipping initial learning
* phase. By default, the VOC Engine is reset, and the algorithm state is
* retained if a measurement is stopped and started again. If the VOC algorithm
* state shall be reset, a device reset, or a power cycle can be executed.
*
* @param[in] state VOC algorithm state to restore.
*
* @note This command is only available in idle mode and the state will be
* applied only once when starting the next measurement. In measure mode, this
* command has no effect.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_set_voc_algorithm_state(const uint8_t* state,
uint16_t state_size);
/**
* @brief sen66_get_voc_algorithm_state
*
* Gets the current VOC algorithm state. Allows to backup and restore the VOC
* algorithm state to resume operation after a power cycle or device reset,
* skipping initial learning phase. By default, the VOC Engine is reset and the
* algorithm state is retained if a measurement is stopped and started again.
* If the VOC algorithm state shall be reset, a device reset or a power cycle
* can be executed.
*
* @param[out] state Current VOC algorithm state.
*
* @note This command can be used either in measure mode or in idle mode (which
* will then return the state at the time when the measurement was stopped). In
* measure mode, the state can be read each measure interval to always have the
* latest state available, even in case of a sudden power loss.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_voc_algorithm_state(uint8_t* state, uint16_t state_size);
/**
* @brief Perform Forced CO₂ Recalibration
*
* Execute the forced recalibration (FRC) of the CO₂. See the datasheet of the
* SCD4x sensor for details how the forced recalibration shall be used.
*
* @param[in] target_co2_concentration Target CO₂ concentration [ppm] of the
* test setup.
* @param[out] correction Correction value as received from the SCD [ppm CO₂].
* FRC correction [ppm CO₂] is calculated as follows: FRC = return_value -
* 0x8000 If the recalibration has failed this returned value is 0xFFFF.
*
* @note After power-on wait at least 1000 ms and after stopping a measurement
* 600 ms before sending this command. This command is not available in measure
* mode. The recalibration procedure will take about 500 ms to complete, during
* which time no other functions can be executed.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t
sen66_perform_forced_co2_recalibration(uint16_t target_co2_concentration,
uint16_t* correction);
/**
* @brief sen66_set_co2_sensor_automatic_self_calibration
*
* Sets the status of the CO₂ sensor automatic self-calibration (ASC). The CO₂
* sensor supports automatic self calibration (ASC) for long-term stability of
* the CO₂ output. This feature can be enabled or disabled. By default it is
* enabled. This configuration is volatile, i.e. the parameter will be reverted
* to its default value after a device restart.
*
* @param[in] status Set to true (0x0001) to enable or false (0x0000) to disable
* the automatic CO₂ measurement self calibration feature. High byte of uint16
* is padding and always 0x00.
*
* @note This command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*
* Example:
* --------
*
* @code{.c}
*
* int16_t local_error = 0;
* local_error = sen66_set_co2_sensor_automatic_self_calibration(0);
* if (local_error != NO_ERROR) {
* return local_error;
* }
*
* @endcode
*
*/
int16_t sen66_set_co2_sensor_automatic_self_calibration(uint16_t status);
/**
* @brief sen66_get_co2_sensor_automatic_self_calibration
*
* The CO₂ sensor supports automatic self calibration (ASC) for long-term
* stability of the CO₂ output. This feature can be enabled or disabled. By
* default it is enabled. This configuration is volatile, i.e. the parameter
* will be reverted to its default value after a device restart.
*
* @param[out] padding Padding byte, always 0x00.
* @param[out] status Is set true (0x01) if the automatic self calibration is
* enabled or false (0x00) if the automatic self calibration is disabled.
*
* @note This command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_co2_sensor_automatic_self_calibration(uint8_t* padding,
bool* status);
/**
* @brief sen66_set_ambient_pressure
*
* The ambient pressure can be used for pressure compensation in the CO₂ sensor.
* Setting an ambient pressure overrides any pressure compensation based on a
* previously set sensor altitude. Use of this command is recommended for
* applications experiencing significant ambient pressure changes to ensure CO₂
* sensor accuracy. Valid input values are between 700 to 1'200 hPa. The default
* value is 1013 hPa. This configuration is volatile, i.e. the parameter will be
* reverted to its default value after a device restart.
*
* @param[in] ambient_pressure Ambient pressure [hPa] to be used for pressure
* compensation.
*
* @note This command can be used in any state of the device, i.e. both in idle
* mode and in measure mode.
*
* @return error_code 0 on success, an error code otherwise.
*
* Example:
* --------
*
* @code{.c}
*
* int16_t local_error = 0;
* local_error = sen66_set_ambient_pressure(1013);
* if (local_error != NO_ERROR) {
* return local_error;
* }
*
* @endcode
*
*/
int16_t sen66_set_ambient_pressure(uint16_t ambient_pressure);
/**
* @brief sen66_get_ambient_pressure
*
* Gets the ambient pressure value. The ambient pressure can be used for
* pressure compensation in the CO₂ sensor.
*
* @param[out] ambient_pressure Currently used ambient pressure [hPa] for
* pressure compensation.
*
* @note This command can be used in any state of the device, i.e. both in idle
* mode and in measure mode.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_ambient_pressure(uint16_t* ambient_pressure);
/**
* @brief sen66_set_sensor_altitude
*
* The sensor altitude can be used for pressure compensation in the CO₂ sensor.
* The default sensor altitude value is set to 0 meters above sea level. Valid
* input values are between 0 and 3000m. This configuration is volatile, i.e.
* the parameter will be reverted to its default value after a device reset.
*
* @param[in] altitude Sensor altitude [m], valid input between 0 and 3000m.
*
* @return error_code 0 on success, an error code otherwise.
*
* Example:
* --------
*
* @code{.c}
*
* int16_t local_error = 0;
* local_error = sen66_set_sensor_altitude(0);
* if (local_error != NO_ERROR) {
* return local_error;
* }
*
* @endcode
*
*/
int16_t sen66_set_sensor_altitude(uint16_t altitude);
/**
* @brief sen66_get_sensor_altitude
*
* Gets the current sensor altitude. The sensor altitude can be used for
* pressure compensation in the CO₂ sensor.
*
* @param[out] altitude Current sensor altitude [m].
*
* @note This command is only available in idle mode.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_sensor_altitude(uint16_t* altitude);
/**
* @brief Activate SHT Heater
*
* This command allows to use the inbuilt heater in SHT sensor to reverse creep
* at high humidity. This command activates the SHT sensor heater with 200mW for
* 1s. The heater is then automatically deactivated again. The
* "get_sht_heater_measurements" command can be used to check if the heater has
* finished (firmware version >= 4.0). Wait at least 20s after this command
* before starting a measurement to get coherent temperature values (heating
* consequence to disappear).
*
* @note This command is only available in idle mode. For firmware version <
* 4.0, wait for at least 1300ms before sending another command, to ensure
* heating is finsihed.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_activate_sht_heater();
/**
* @brief Get the measurement values when the SHT sensor heating is finished.
*
* Get the measured values when the SHT sensor heating is triggerd. If the
* heating is not finished, the returned humidity and temperature values are
* 0x7FFF.
*
* @param[out] humidity Value is scaled with factor 100: RH [%] = value / 100
* *Note: If this value is not available, 0x7FFF is returned.*
* @param[out] temperature Value is scaled with factor 200: T [°C] = value / 200
* *Note: If this value is not available, 0x7FFF is returned.*
*
* @note This command is only availble in idle mode. This command is only
* available for firmware version >= 4.0. This command must be used after the
* "activate_sht_heater" command. The get_sht_heater_measurements command can be
* queried every 0.05s to get the measurements.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_sht_heater_measurements(int16_t* humidity,
int16_t* temperature);
/**
* @brief sen66_get_product_name
*
* Gets the product name from the device.
*
* @param[out] product_name Null-terminated ASCII string containing the product
* name. Up to 32 characters can be read from the device.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_product_name(int8_t* product_name,
uint16_t product_name_size);
/**
* @brief sen66_get_serial_number
*
* Gets the serial number from the device.
*
* @param[out] serial_number Null-terminated ASCII string containing the serial
* number. Up to 32 characters can be read from the device.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_serial_number(int8_t* serial_number,
uint16_t serial_number_size);
/**
* @brief sen66_get_version
*
* Gets the version information for the hardware, firmware and communication
* protocol.
*
* @param[out] firmware_major Firmware major version number.
* @param[out] firmware_minor Firmware minor version number.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_get_version(uint8_t* firmware_major, uint8_t* firmware_minor);
/**
* @brief sen66_read_device_status
*
* Reads the current device status. Use this command to get detailed information
* about the device status. The device status is encoded in flags. Each device
* status flag represents a single bit in a 32-bit integer value. If more than
* one error is present, the device status register value is the sum of the
* corresponding flag values. For details about the available flags, refer to
* the device status flags documentation in the data sheet.
*
* @param[out] device_status Device status (32 flags as an integer value). For
* details, please refer to the device status flags documentation in the
* datasheet.
*
* @note The status flags of type "Error" are sticky, i.e. they are not cleared
* automatically even if the error condition no longer exists. So they can only
* be cleared manually with the command "Read And Clear Device Status" or with a
* device reset. All other flags are not sticky, i.e. they are cleared
* automatically if the trigger condition disappears.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_read_device_status(sen66_device_status* device_status);
/**
* @brief sen66_read_and_clear_device_status
*
* Reads the current device status (like command 0xD206 "Read Device Status")
* and afterwards clears all flags.
*
* @param[out] device_status Device status (32 flags as an integer value)
* **before** clearing it. For details, please refer to the device status flags
* documentation.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_read_and_clear_device_status(sen66_device_status* device_status);
/**
* @brief sen66_device_reset
*
* Executes a reset on the device. This has the same effect as a power cycle.
*
* @return error_code 0 on success, an error code otherwise.
*/
int16_t sen66_device_reset();
#ifdef __cplusplus
}
#endif
#endif // SEN66_I2C_H
+120
View File
@@ -0,0 +1,120 @@
/*
* Copyright (c) 2018, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of Sensirion AG 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.
*/
#include "sensirion_common.h"
#include "sensirion_config.h"
uint16_t sensirion_common_bytes_to_uint16_t(const uint8_t* bytes) {
return (uint16_t)bytes[0] << 8 | (uint16_t)bytes[1];
}
uint32_t sensirion_common_bytes_to_uint32_t(const uint8_t* bytes) {
return (uint32_t)bytes[0] << 24 | (uint32_t)bytes[1] << 16 |
(uint32_t)bytes[2] << 8 | (uint32_t)bytes[3];
}
int16_t sensirion_common_bytes_to_int16_t(const uint8_t* bytes) {
return (int16_t)sensirion_common_bytes_to_uint16_t(bytes);
}
int32_t sensirion_common_bytes_to_int32_t(const uint8_t* bytes) {
return (int32_t)sensirion_common_bytes_to_uint32_t(bytes);
}
float sensirion_common_bytes_to_float(const uint8_t* bytes) {
union {
uint32_t u32_value;
float float32;
} tmp;
tmp.u32_value = sensirion_common_bytes_to_uint32_t(bytes);
return tmp.float32;
}
void sensirion_common_uint32_t_to_bytes(const uint32_t value, uint8_t* bytes) {
bytes[0] = (uint8_t)(value >> 24);
bytes[1] = (uint8_t)(value >> 16);
bytes[2] = (uint8_t)(value >> 8);
bytes[3] = (uint8_t)(value);
}
void sensirion_common_uint16_t_to_bytes(const uint16_t value, uint8_t* bytes) {
bytes[0] = (uint8_t)(value >> 8);
bytes[1] = (uint8_t)value;
}
void sensirion_common_int32_t_to_bytes(const int32_t value, uint8_t* bytes) {
bytes[0] = (uint8_t)(value >> 24);
bytes[1] = (uint8_t)(value >> 16);
bytes[2] = (uint8_t)(value >> 8);
bytes[3] = (uint8_t)value;
}
void sensirion_common_int16_t_to_bytes(const int16_t value, uint8_t* bytes) {
bytes[0] = (uint8_t)(value >> 8);
bytes[1] = (uint8_t)value;
}
void sensirion_common_float_to_bytes(const float value, uint8_t* bytes) {
union {
uint32_t u32_value;
float float32;
} tmp;
tmp.float32 = value;
sensirion_common_uint32_t_to_bytes(tmp.u32_value, bytes);
}
void sensirion_common_copy_bytes(const uint8_t* source, uint8_t* destination,
uint16_t data_length) {
uint16_t i;
for (i = 0; i < data_length; i++) {
destination[i] = source[i];
}
}
void sensirion_common_to_integer(const uint8_t* source, uint8_t* destination,
INT_TYPE int_type, uint8_t data_length) {
if (data_length > int_type) {
data_length = 0; // we do not read at all if data_length is bigger than
// the provided integer!
}
// pad missing bytes
uint8_t offset = int_type - data_length;
for (uint8_t i = 0; i < offset; i++) {
destination[int_type - i - 1] = 0;
}
for (uint8_t i = 1; i <= data_length; i++) {
destination[int_type - offset - i] = source[i - 1];
}
}
+197
View File
@@ -0,0 +1,197 @@
/*
* Copyright (c) 2018, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of Sensirion AG 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.
*/
#ifndef SENSIRION_COMMON_H
#define SENSIRION_COMMON_H
#include "sensirion_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#define NO_ERROR 0
#define NOT_IMPLEMENTED_ERROR 31
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
#endif
#define SENSIRION_COMMAND_SIZE 2
#define SENSIRION_WORD_SIZE 2
#define SENSIRION_NUM_WORDS(x) (sizeof(x) / SENSIRION_WORD_SIZE)
#define SENSIRION_MAX_BUFFER_WORDS 32
/**
* Enum to describe the type of an integer
*/
typedef enum { BYTE = 1, SHORT = 2, INTEGER = 4, LONG_INTEGER = 8 } INT_TYPE;
/**
* sensirion_common_bytes_to_int16_t() - Convert an array of bytes to an int16_t
*
* Convert an array of bytes received from the sensor in big-endian/MSB-first
* format to an int16_t value in the correct system-endianness.
*
* @param bytes An array of at least two bytes (MSB first)
* @return The byte array represented as int16_t
*/
int16_t sensirion_common_bytes_to_int16_t(const uint8_t* bytes);
/**
* sensirion_common_bytes_to_int32_t() - Convert an array of bytes to an int32_t
*
* Convert an array of bytes received from the sensor in big-endian/MSB-first
* format to an int32_t value in the correct system-endianness.
*
* @param bytes An array of at least four bytes (MSB first)
* @return The byte array represented as int32_t
*/
int32_t sensirion_common_bytes_to_int32_t(const uint8_t* bytes);
/**
* sensirion_common_bytes_to_uint16_t() - Convert an array of bytes to an
* uint16_t
*
* Convert an array of bytes received from the sensor in big-endian/MSB-first
* format to an uint16_t value in the correct system-endianness.
*
* @param bytes An array of at least two bytes (MSB first)
* @return The byte array represented as uint16_t
*/
uint16_t sensirion_common_bytes_to_uint16_t(const uint8_t* bytes);
/**
* sensirion_common_bytes_to_uint32_t() - Convert an array of bytes to an
* uint32_t
*
* Convert an array of bytes received from the sensor in big-endian/MSB-first
* format to an uint32_t value in the correct system-endianness.
*
* @param bytes An array of at least four bytes (MSB first)
* @return The byte array represented as uint32_t
*/
uint32_t sensirion_common_bytes_to_uint32_t(const uint8_t* bytes);
/**
* sensirion_common_bytes_to_float() - Convert an array of bytes to a float
*
* Convert an array of bytes received from the sensor in big-endian/MSB-first
* format to an float value in the correct system-endianness.
*
* @param bytes An array of at least four bytes (MSB first)
* @return The byte array represented as float
*/
float sensirion_common_bytes_to_float(const uint8_t* bytes);
/**
* sensirion_common_uint32_t_to_bytes() - Convert an uint32_t to an array of
* bytes
*
* Convert an uint32_t value in system-endianness to big-endian/MBS-first
* format to send to the sensor.
*
* @param value Value to convert
* @param bytes An array of at least four bytes
*/
void sensirion_common_uint32_t_to_bytes(const uint32_t value, uint8_t* bytes);
/**
* sensirion_common_uint16_t_to_bytes() - Convert an uint16_t to an array of
* bytes
*
* Convert an uint16_t value in system-endianness to big-endian/MBS-first
* format to send to the sensor.
*
* @param value Value to convert
* @param bytes An array of at least two bytes
*/
void sensirion_common_uint16_t_to_bytes(const uint16_t value, uint8_t* bytes);
/**
* sensirion_common_int32_t_to_bytes() - Convert an int32_t to an array of bytes
*
* Convert an int32_t value in system-endianness to big-endian/MBS-first
* format to send to the sensor.
*
* @param value Value to convert
* @param bytes An array of at least four bytes
*/
void sensirion_common_int32_t_to_bytes(const int32_t value, uint8_t* bytes);
/**
* sensirion_common_int16_t_to_bytes() - Convert an int16_t to an array of bytes
*
* Convert an int16_t value in system-endianness to big-endian/MBS-first
* format to send to the sensor.
*
* @param value Value to convert
* @param bytes An array of at least two bytes
*/
void sensirion_common_int16_t_to_bytes(const int16_t value, uint8_t* bytes);
/**
* sensirion_common_float_to_bytes() - Convert an float to an array of bytes
*
* Convert an float value in system-endianness to big-endian/MBS-first
* format to send to the sensor.
*
* @param value Value to convert
* @param bytes An array of at least four bytes
*/
void sensirion_common_float_to_bytes(const float value, uint8_t* bytes);
/**
* sensirion_common_copy_bytes() - Copy bytes from one array to the other.
*
* @param source Array of bytes to be copied.
* @param destination Array of bytes to be copied to.
* @param data_length Number of bytes to copy.
*/
void sensirion_common_copy_bytes(const uint8_t* source, uint8_t* destination,
uint16_t data_length);
/**
* sensirion_common_to_integer() - Copy bytes from byte array to integer.
*
* @param source Array of bytes to be copied.
* @param int_value Pointer to integer of bytes to be copied to.
* @param int_type Type (size) of the integer to be copied.
* @param data_length Number of bytes to copy.
*/
void sensirion_common_to_integer(const uint8_t* source, uint8_t* destination,
INT_TYPE int_type, uint8_t data_length);
#ifdef __cplusplus
}
#endif
#endif /* SENSIRION_COMMON_H */
+88
View File
@@ -0,0 +1,88 @@
/*
* Copyright (c) 2019, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of Sensirion AG 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.
*/
#ifndef SENSIRION_CONFIG_H
#define SENSIRION_CONFIG_H
/**
* If your platform does not provide the library stdlib.h you have to remove the
* include and define NULL yourself (see below).
*/
#include <stdlib.h>
/**
* #ifndef NULL
* #define NULL ((void *)0)
* #endif
*/
/**
* If your platform does not provide the library stdint.h you have to
* define the integral types yourself (see below).
*/
#include <stdint.h>
/**
* Typedef section for types commonly defined in <stdint.h>
* If your system does not provide stdint headers, please define them
* accordingly. Please make sure to define int64_t and uint64_t.
*/
/* typedef unsigned long long int uint64_t;
* typedef long long int int64_t;
* typedef long int32_t;
* typedef unsigned long uint32_t;
* typedef short int16_t;
* typedef unsigned short uint16_t;
* typedef char int8_t;
* typedef unsigned char uint8_t;
*/
#ifndef __cplusplus
/**
* If your platform doesn't define the bool type we define it as int. Depending
* on your system update the definition below.
*/
#if __STDC_VERSION__ >= 199901L
#include <stdbool.h>
#else
#ifndef bool
#define bool int
#define true 1
#define false 0
#endif /* bool */
#endif /* __STDC_VERSION__ */
#endif /* __cplusplus */
#endif /* SENSIRION_CONFIG_H */
+313
View File
@@ -0,0 +1,313 @@
/*
* Copyright (c) 2018, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of Sensirion AG 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.
*/
#include "sensirion_i2c.h"
#include "sensirion_common.h"
#include "sensirion_config.h"
#include "sensirion_i2c_hal.h"
#include "esp_log.h"
uint8_t sensirion_i2c_generate_crc(const uint8_t* data, uint16_t count) {
uint16_t current_byte;
uint8_t crc = CRC8_INIT;
uint8_t crc_bit;
/* calculates 8-Bit checksum with given polynomial */
for (current_byte = 0; current_byte < count; ++current_byte) {
crc ^= (data[current_byte]);
for (crc_bit = 8; crc_bit > 0; --crc_bit) {
if (crc & 0x80)
crc = (crc << 1) ^ CRC8_POLYNOMIAL;
else
crc = (crc << 1);
}
}
return crc;
}
int8_t sensirion_i2c_check_crc(const uint8_t* data, uint16_t count,
uint8_t checksum) {
if (sensirion_i2c_generate_crc(data, count) != checksum)
return CRC_ERROR;
return NO_ERROR;
}
int16_t sensirion_i2c_general_call_reset(void) {
const uint8_t data = 0x06;
return sensirion_i2c_hal_write(0, &data, (uint16_t)sizeof(data));
}
uint16_t sensirion_i2c_fill_cmd_send_buf(uint8_t* buf, uint16_t cmd,
const uint16_t* args,
uint8_t num_args) {
uint8_t i;
uint16_t idx = 0;
buf[idx++] = (uint8_t)((cmd & 0xFF00) >> 8);
buf[idx++] = (uint8_t)((cmd & 0x00FF) >> 0);
for (i = 0; i < num_args; ++i) {
buf[idx++] = (uint8_t)((args[i] & 0xFF00) >> 8);
buf[idx++] = (uint8_t)((args[i] & 0x00FF) >> 0);
uint8_t crc = sensirion_i2c_generate_crc((uint8_t*)&buf[idx - 2],
SENSIRION_WORD_SIZE);
buf[idx++] = crc;
}
return idx;
}
int16_t sensirion_i2c_read_words_as_bytes(uint8_t address, uint8_t* data,
uint16_t num_words) {
int16_t ret;
uint16_t i, j;
uint16_t size = num_words * (SENSIRION_WORD_SIZE + CRC8_LEN);
uint16_t word_buf[SENSIRION_MAX_BUFFER_WORDS];
uint8_t* const buf8 = (uint8_t*)word_buf;
ret = sensirion_i2c_hal_read(address, buf8, size);
if (ret != NO_ERROR)
return ret;
/* check the CRC for each word */
for (i = 0, j = 0; i < size; i += SENSIRION_WORD_SIZE + CRC8_LEN) {
ret = sensirion_i2c_check_crc(&buf8[i], SENSIRION_WORD_SIZE,
buf8[i + SENSIRION_WORD_SIZE]);
if (ret != NO_ERROR)
return ret;
data[j++] = buf8[i];
data[j++] = buf8[i + 1];
}
return NO_ERROR;
}
int16_t sensirion_i2c_read_words(uint8_t address, uint16_t* data_words,
uint16_t num_words) {
int16_t ret;
uint8_t i;
ret = sensirion_i2c_read_words_as_bytes(address, (uint8_t*)data_words,
num_words);
if (ret != NO_ERROR)
return ret;
for (i = 0; i < num_words; ++i) {
const uint8_t* word_bytes = (uint8_t*)&data_words[i];
data_words[i] = ((uint16_t)word_bytes[0] << 8) | word_bytes[1];
}
return NO_ERROR;
}
int16_t sensirion_i2c_write_cmd(uint8_t address, uint16_t command) {
uint8_t buf[SENSIRION_COMMAND_SIZE];
sensirion_i2c_fill_cmd_send_buf(buf, command, NULL, 0);
return sensirion_i2c_hal_write(address, buf, SENSIRION_COMMAND_SIZE);
}
int16_t sensirion_i2c_write_cmd_with_args(uint8_t address, uint16_t command,
const uint16_t* data_words,
uint16_t num_words) {
uint8_t buf[SENSIRION_MAX_BUFFER_WORDS];
uint16_t buf_size;
buf_size =
sensirion_i2c_fill_cmd_send_buf(buf, command, data_words, num_words);
return sensirion_i2c_hal_write(address, buf, buf_size);
}
int16_t sensirion_i2c_delayed_read_cmd(uint8_t address, uint16_t cmd,
uint32_t delay_us, uint16_t* data_words,
uint16_t num_words) {
int16_t ret;
uint8_t buf[SENSIRION_COMMAND_SIZE];
sensirion_i2c_fill_cmd_send_buf(buf, cmd, NULL, 0);
ret = sensirion_i2c_hal_write(address, buf, SENSIRION_COMMAND_SIZE);
if (ret != NO_ERROR)
return ret;
if (delay_us)
sensirion_i2c_hal_sleep_usec(delay_us);
return sensirion_i2c_read_words(address, data_words, num_words);
}
int16_t sensirion_i2c_read_cmd(uint8_t address, uint16_t cmd,
uint16_t* data_words, uint16_t num_words) {
return sensirion_i2c_delayed_read_cmd(address, cmd, 0, data_words,
num_words);
}
uint16_t sensirion_i2c_add_command_to_buffer(uint8_t* buffer, uint16_t offset,
uint16_t command) {
buffer[offset++] = (uint8_t)((command & 0xFF00) >> 8);
buffer[offset++] = (uint8_t)((command & 0x00FF) >> 0);
return offset;
}
uint16_t sensirion_i2c_add_command16_to_buffer(uint8_t* buffer, uint16_t offset,
uint16_t command) {
buffer[offset++] = (uint8_t)((command & 0xFF00) >> 8);
buffer[offset++] = (uint8_t)((command & 0x00FF) >> 0);
return offset;
}
uint16_t sensirion_i2c_add_command8_to_buffer(uint8_t* buffer, uint16_t offset,
uint8_t command) {
buffer[offset++] = command;
return offset;
}
uint16_t sensirion_i2c_add_uint32_t_to_buffer(uint8_t* buffer, uint16_t offset,
uint32_t data) {
buffer[offset++] = (uint8_t)((data & 0xFF000000) >> 24);
buffer[offset++] = (uint8_t)((data & 0x00FF0000) >> 16);
buffer[offset] = sensirion_i2c_generate_crc(
&buffer[offset - SENSIRION_WORD_SIZE], SENSIRION_WORD_SIZE);
offset++;
buffer[offset++] = (uint8_t)((data & 0x0000FF00) >> 8);
buffer[offset++] = (uint8_t)((data & 0x000000FF) >> 0);
buffer[offset] = sensirion_i2c_generate_crc(
&buffer[offset - SENSIRION_WORD_SIZE], SENSIRION_WORD_SIZE);
offset++;
return offset;
}
uint16_t sensirion_i2c_add_int32_t_to_buffer(uint8_t* buffer, uint16_t offset,
int32_t data) {
return sensirion_i2c_add_uint32_t_to_buffer(buffer, offset, (uint32_t)data);
}
uint16_t sensirion_i2c_add_uint16_t_to_buffer(uint8_t* buffer, uint16_t offset,
uint16_t data) {
buffer[offset++] = (uint8_t)((data & 0xFF00) >> 8);
buffer[offset++] = (uint8_t)((data & 0x00FF) >> 0);
buffer[offset] = sensirion_i2c_generate_crc(
&buffer[offset - SENSIRION_WORD_SIZE], SENSIRION_WORD_SIZE);
offset++;
return offset;
}
uint16_t sensirion_i2c_add_int16_t_to_buffer(uint8_t* buffer, uint16_t offset,
int16_t data) {
return sensirion_i2c_add_uint16_t_to_buffer(buffer, offset, (uint16_t)data);
}
uint16_t sensirion_i2c_add_float_to_buffer(uint8_t* buffer, uint16_t offset,
float data) {
union {
uint32_t uint32_data;
float float_data;
} convert;
convert.float_data = data;
buffer[offset++] = (uint8_t)((convert.uint32_data & 0xFF000000) >> 24);
buffer[offset++] = (uint8_t)((convert.uint32_data & 0x00FF0000) >> 16);
buffer[offset] = sensirion_i2c_generate_crc(
&buffer[offset - SENSIRION_WORD_SIZE], SENSIRION_WORD_SIZE);
offset++;
buffer[offset++] = (uint8_t)((convert.uint32_data & 0x0000FF00) >> 8);
buffer[offset++] = (uint8_t)((convert.uint32_data & 0x000000FF) >> 0);
buffer[offset] = sensirion_i2c_generate_crc(
&buffer[offset - SENSIRION_WORD_SIZE], SENSIRION_WORD_SIZE);
offset++;
return offset;
}
uint16_t sensirion_i2c_add_bytes_to_buffer(uint8_t* buffer, uint16_t offset,
const uint8_t* data,
uint16_t data_length) {
uint16_t i;
if (data_length % SENSIRION_WORD_SIZE != 0) {
return BYTE_NUM_ERROR;
}
for (i = 0; i < data_length; i += 2) {
buffer[offset++] = data[i];
buffer[offset++] = data[i + 1];
buffer[offset] = sensirion_i2c_generate_crc(
&buffer[offset - SENSIRION_WORD_SIZE], SENSIRION_WORD_SIZE);
offset++;
}
return offset;
}
int16_t sensirion_i2c_write_data(uint8_t address, const uint8_t* data,
uint16_t data_length) {
return sensirion_i2c_hal_write(address, data, data_length);
}
int16_t sensirion_i2c_read_data_inplace(uint8_t address, uint8_t* buffer,
uint16_t expected_data_length) {
int16_t error;
uint16_t i, j;
uint16_t size = (expected_data_length / SENSIRION_WORD_SIZE) *
(SENSIRION_WORD_SIZE + CRC8_LEN);
if (expected_data_length % SENSIRION_WORD_SIZE != 0) {
return BYTE_NUM_ERROR;
}
error = sensirion_i2c_hal_read(address, buffer, size);
if (error) {
return error;
}
/* ===== DEBUG: Rohdaten anzeigen ===== */
ESP_LOGI("SEN66_RAW",
"addr=0x%02X size=%u bytes: %02X %02X %02X",
address, size,
buffer[0], buffer[1], buffer[2]);
/* ==================================== */
for (i = 0, j = 0; i < size; i += SENSIRION_WORD_SIZE + CRC8_LEN) {
error = sensirion_i2c_check_crc(&buffer[i], SENSIRION_WORD_SIZE,
buffer[i + SENSIRION_WORD_SIZE]);
if (error) {
return error;
}
buffer[j++] = buffer[i];
buffer[j++] = buffer[i + 1];
}
return NO_ERROR;
}
+348
View File
@@ -0,0 +1,348 @@
/*
* Copyright (c) 2018, Sensirion AG
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * 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.
*
* * Neither the name of Sensirion AG 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.
*/
#ifndef SENSIRION_I2C_H
#define SENSIRION_I2C_H
#include "sensirion_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CRC_ERROR 1
#define I2C_BUS_ERROR 2
#define I2C_NACK_ERROR 3
#define BYTE_NUM_ERROR 4
#define CRC8_POLYNOMIAL 0x31
#define CRC8_INIT 0xFF
#define CRC8_LEN 1
#define SENSIRION_COMMAND_SIZE 2
#define SENSIRION_WORD_SIZE 2
#define SENSIRION_NUM_WORDS(x) (sizeof(x) / SENSIRION_WORD_SIZE)
#define SENSIRION_MAX_BUFFER_WORDS 32
uint8_t sensirion_i2c_generate_crc(const uint8_t* data, uint16_t count);
int8_t sensirion_i2c_check_crc(const uint8_t* data, uint16_t count,
uint8_t checksum);
/**
* sensirion_i2c_general_call_reset() - Send a general call reset.
*
* @warning This will reset all attached I2C devices on the bus which support
* general call reset.
*
* @return NO_ERROR on success, an error code otherwise
*/
int16_t sensirion_i2c_general_call_reset(void);
/**
* sensirion_i2c_fill_cmd_send_buf() - create the i2c send buffer for a command
* and a set of argument words. The output buffer interleaves argument words
* with their checksums.
* @buf: The generated buffer to send over i2c. Then buffer length must
* be at least SENSIRION_COMMAND_LEN + num_args *
* (SENSIRION_WORD_SIZE + CRC8_LEN).
* @cmd: The i2c command to send. It already includes a checksum.
* @args: The arguments to the command. Can be NULL if none.
* @num_args: The number of word arguments in args.
*
* @return The number of bytes written to buf
*/
uint16_t sensirion_i2c_fill_cmd_send_buf(uint8_t* buf, uint16_t cmd,
const uint16_t* args,
uint8_t num_args);
/**
* sensirion_i2c_read_words() - read data words from sensor
*
* @address: Sensor i2c address
* @data_words: Allocated buffer to store the read words.
* The buffer may also have been modified in case of an error.
* @num_words: Number of data words to read (without CRC bytes)
*
* @return NO_ERROR on success, an error code otherwise
*/
int16_t sensirion_i2c_read_words(uint8_t address, uint16_t* data_words,
uint16_t num_words);
/**
* sensirion_i2c_read_words_as_bytes() - read data words as byte-stream from
* sensor
*
* Read bytes without adjusting values to the uP's word-order.
*
* @address: Sensor i2c address
* @data: Allocated buffer to store the read bytes.
* The buffer may also have been modified in case of an error.
* @num_words: Number of data words(!) to read (without CRC bytes)
* Since only word-chunks can be read from the sensor the size
* is still specified in sensor-words (num_words = num_bytes *
* SENSIRION_WORD_SIZE)
*
* @return NO_ERROR on success, an error code otherwise
*/
int16_t sensirion_i2c_read_words_as_bytes(uint8_t address, uint8_t* data,
uint16_t num_words);
/**
* sensirion_i2c_write_cmd() - writes a command to the sensor
* @address: Sensor i2c address
* @command: Sensor command
*
* @return NO_ERROR on success, an error code otherwise
*/
int16_t sensirion_i2c_write_cmd(uint8_t address, uint16_t command);
/**
* sensirion_i2c_write_cmd_with_args() - writes a command with arguments to the
* sensor
* @address: Sensor i2c address
* @command: Sensor command
* @data: Argument buffer with words to send
* @num_words: Number of data words to send (without CRC bytes)
*
* @return NO_ERROR on success, an error code otherwise
*/
int16_t sensirion_i2c_write_cmd_with_args(uint8_t address, uint16_t command,
const uint16_t* data_words,
uint16_t num_words);
/**
* sensirion_i2c_delayed_read_cmd() - send a command, wait for the sensor to
* process and read data back
* @address: Sensor i2c address
* @cmd: Command
* @delay: Time in microseconds to delay sending the read request
* @data_words: Allocated buffer to store the read data
* @num_words: Data words to read (without CRC bytes)
*
* @return NO_ERROR on success, an error code otherwise
*/
int16_t sensirion_i2c_delayed_read_cmd(uint8_t address, uint16_t cmd,
uint32_t delay_us, uint16_t* data_words,
uint16_t num_words);
/**
* sensirion_i2c_read_cmd() - reads data words from the sensor after a command
* is issued
* @address: Sensor i2c address
* @cmd: Command
* @data_words: Allocated buffer to store the read data
* @num_words: Data words to read (without CRC bytes)
*
* @return NO_ERROR on success, an error code otherwise
*/
int16_t sensirion_i2c_read_cmd(uint8_t address, uint16_t cmd,
uint16_t* data_words, uint16_t num_words);
/**
* sensirion_i2c_add_command_to_buffer() - Add a command to the buffer at
* offset. Adds 2 bytes to the buffer.
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param command Command to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_command_to_buffer(uint8_t* buffer, uint16_t offset,
uint16_t command);
/**
* sensirion_i2c_add_command16_to_buffer() - Add a command to the buffer at
* the specified offset. This function is equivalent to the
* function sensirion_i2c_add_command_to_buffer().
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param command Command to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_command16_to_buffer(uint8_t* buffer, uint16_t offset,
uint16_t command);
/**
* sensirion_i2c_add_command8_to_buffer() - Add a command to the buffer at
* offset. Adds one bytes command to the buffer.
* This is used for sensor that only take one command byte such as
* SHT.
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param command Command to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_command8_to_buffer(uint8_t* buffer, uint16_t offset,
uint8_t command);
/**
* sensirion_i2c_add_uint32_t_to_buffer() - Add a uint32_t to the buffer at
* offset. Adds 6 bytes to the buffer.
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param data uint32_t to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_uint32_t_to_buffer(uint8_t* buffer, uint16_t offset,
uint32_t data);
/**
* sensirion_i2c_add_int32_t_to_buffer() - Add a int32_t to the buffer at
* offset. Adds 6 bytes to the buffer.
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param data int32_t to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_int32_t_to_buffer(uint8_t* buffer, uint16_t offset,
int32_t data);
/**
* sensirion_i2c_add_uint16_t_to_buffer() - Add a uint16_t to the buffer at
* offset. Adds 3 bytes to the buffer.
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param data uint16_t to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_uint16_t_to_buffer(uint8_t* buffer, uint16_t offset,
uint16_t data);
/**
* sensirion_i2c_add_int16_t_to_buffer() - Add a int16_t to the buffer at
* offset. Adds 3 bytes to the buffer.
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param data int16_t to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_int16_t_to_buffer(uint8_t* buffer, uint16_t offset,
int16_t data);
/**
* sensirion_i2c_add_float_to_buffer() - Add a float to the buffer at offset.
* Adds 6 bytes to the buffer.
*
* @param buffer Pointer to buffer in which the write frame will be prepared.
* Caller needs to make sure that there is enough space after
* offset left to write the data into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param data float to be written into the buffer.
*
* @return Offset of next free byte in the buffer after writing the data.
*/
uint16_t sensirion_i2c_add_float_to_buffer(uint8_t* buffer, uint16_t offset,
float data);
/**
* sensirion_i2c_add_bytes_to_buffer() - Add a byte array to the buffer at
* offset.
*
* @param buffer Pointer to buffer in which the write frame will be
* prepared. Caller needs to make sure that there is
* enough space after offset left to write the data
* into the buffer.
* @param offset Offset of the next free byte in the buffer.
* @param data Pointer to data to be written into the buffer.
* @param data_length Number of bytes to be written into the buffer. Needs to
* be a multiple of SENSIRION_WORD_SIZE otherwise the
* function returns BYTE_NUM_ERROR.
*
* @return Offset of next free byte in the buffer after writing the
* data.
*/
uint16_t sensirion_i2c_add_bytes_to_buffer(uint8_t* buffer, uint16_t offset,
const uint8_t* data,
uint16_t data_length);
/**
* sensirion_i2c_write_data() - Writes data to the Sensor.
*
* @note This is just a wrapper for sensirion_i2c_hal_write() to
* not need to include the HAL in the drivers.
*
* @param address I2C address to write to.
* @param data Pointer to the buffer containing the data to write.
* @param data_length Number of bytes to send to the Sensor.
*
* @return NO_ERROR on success, error code otherwise
*/
int16_t sensirion_i2c_write_data(uint8_t address, const uint8_t* data,
uint16_t data_length);
/**
* sensirion_i2c_read_data_inplace() - Reads data from the Sensor.
*
* @param address Sensor I2C address
* @param buffer Allocated buffer to store data as bytes. Needs
* to be big enough to store the data including
* CRC. Twice the size of data should always
* suffice.
* @param expected_data_length Number of bytes to read (without CRC). Needs
* to be a multiple of SENSIRION_WORD_SIZE,
* otherwise the function returns BYTE_NUM_ERROR.
*
* @return NO_ERROR on success, an error code otherwise
*/
int16_t sensirion_i2c_read_data_inplace(uint8_t address, uint8_t* buffer,
uint16_t expected_data_length);
#ifdef __cplusplus
}
#endif
#endif /* SENSIRION_I2C_H */
+32
View File
@@ -0,0 +1,32 @@
#ifndef SENSIRION_I2C_ESP32_CONFIG_H
#define SENSIRION_I2C_ESP32_CONFIG_H
#include <stdint.h>
#include <stdbool.h>
#include "driver/i2c.h"
#include "driver/gpio.h"
#include "esp_err.h"
#ifdef __cplusplus
extern "C" {
#endif
struct esp32_i2c_config {
uint32_t freq;
uint8_t addr; // optional, kannst du auch ignorieren
i2c_port_t port;
gpio_num_t sda;
gpio_num_t scl;
bool sda_pullup;
bool scl_pullup;
};
esp_err_t sensirion_i2c_config_esp32(struct esp32_i2c_config* cfg);
esp_err_t sensirion_i2c_esp32_ok(void);
#ifdef __cplusplus
}
#endif
#endif /* SENSIRION_I2C_ESP32_CONFIG_H */
+103
View File
@@ -0,0 +1,103 @@
#include "sensirion_i2c_hal.h"
#include "driver/i2c.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
static const char *TAG = "sensirion_i2c_hal_espidf";
#ifndef I2C_MASTER_PORT
#define I2C_MASTER_PORT I2C_NUM_0
#endif
#ifndef I2C_MASTER_SDA
#define I2C_MASTER_SDA 7
#endif
#ifndef I2C_MASTER_SCL
#define I2C_MASTER_SCL 8
#endif
#ifndef I2C_MASTER_FREQ_HZ
#define I2C_MASTER_FREQ_HZ 100000
#endif
static bool s_inited = false;
int16_t sensirion_i2c_hal_select_bus(uint8_t bus_idx) {
(void)bus_idx;
// Single-bus setup -> nothing to do.
return 0;
}
void sensirion_i2c_hal_init(void) {
if (s_inited) return;
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA,
.scl_io_num = I2C_MASTER_SCL,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
.clk_flags = 0,
};
esp_err_t err = i2c_param_config(I2C_MASTER_PORT, &conf);
if (err != ESP_OK) {
ESP_LOGE(TAG, "i2c_param_config failed: %s", esp_err_to_name(err));
return;
}
err = i2c_driver_install(I2C_MASTER_PORT, conf.mode, 0, 0, 0);
if (err != ESP_OK) {
ESP_LOGE(TAG, "i2c_driver_install failed: %s", esp_err_to_name(err));
return;
}
s_inited = true;
ESP_LOGI(TAG, "I2C master init OK (port=%d sda=%d scl=%d freq=%d)",
I2C_MASTER_PORT, I2C_MASTER_SDA, I2C_MASTER_SCL, I2C_MASTER_FREQ_HZ);
}
void sensirion_i2c_hal_free(void) {
if (!s_inited) return;
i2c_driver_delete(I2C_MASTER_PORT);
s_inited = false;
}
int8_t sensirion_i2c_hal_read(uint8_t address, uint8_t* data, uint16_t count) {
if (!s_inited) return -1;
esp_err_t err = i2c_master_read_from_device(
I2C_MASTER_PORT, address, data, count, pdMS_TO_TICKS(1000)
);
if (err != ESP_OK) {
ESP_LOGE(TAG, "I2C read failed addr=0x%02X len=%u: %s",
address, count, esp_err_to_name(err));
return (int8_t)err;
}
return 0;
}
int8_t sensirion_i2c_hal_write(uint8_t address, const uint8_t* data, uint16_t count) {
if (!s_inited) return -1;
esp_err_t err = i2c_master_write_to_device(
I2C_MASTER_PORT, address, data, count, pdMS_TO_TICKS(1000)
);
if (err != ESP_OK) {
ESP_LOGE(TAG, "I2C write failed addr=0x%02X len=%u: %s",
address, count, esp_err_to_name(err));
return (int8_t)err;
}
return 0;
}
void sensirion_i2c_hal_sleep_usec(uint32_t useconds) {
// <10ms precision is sufficient per Sensirion HAL contract
vTaskDelay(pdMS_TO_TICKS((useconds + 999) / 1000));
}
+41
View File
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018, Sensirion AG
* All rights reserved.
* ...
*/
#ifndef SENSIRION_I2C_HAL_H
#define SENSIRION_I2C_HAL_H
#include "sensirion_config.h"
#include <driver/i2c_master.h>
#include "sensirion_i2c_esp32_config.h"
#include "esp_err.h" // <— empfehlenswert, weil du esp_err_t nutzt
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int16_t sensirion_i2c_hal_select_bus(uint8_t bus_idx);
void sensirion_i2c_hal_init(void);
void sensirion_i2c_hal_free(void);
int8_t sensirion_i2c_hal_read(uint8_t address, uint8_t* data, uint16_t count);
int8_t sensirion_i2c_hal_write(uint8_t address, const uint8_t* data,
uint16_t count);
void sensirion_i2c_hal_sleep_usec(uint32_t useconds);
// NEW API: register an IDF i2c_master bus handle for a bus index
esp_err_t sensirion_i2c_hal_register_bus(uint8_t bus_idx,
i2c_master_bus_handle_t bus_handle,
const struct esp32_i2c_config* cfg_opt);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* SENSIRION_I2C_HAL_H */
+11
View File
@@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html