This commit is contained in:
2025-04-04 04:48:13 +02:00
commit 2790bfa772
50 changed files with 6158 additions and 0 deletions

View File

@@ -0,0 +1 @@
2df0cb14d4425565a8745d4a96bfaa8ff7e90bbec3e208a073821406dded23c8

View File

@@ -0,0 +1,98 @@
#
# Versioning Information for ESP-IDF Components with GitHub, GitVersion and CMake
#
# Inspired by: https://www.esp32.com/viewtopic.php?f=2&t=45054&p=146150#p146150
#
# Install Git-Version via command prompt: dotnet tool install --global GitVersion.Tool
# Create a GitVersion.yml file in the root of your project with the following content:
#
# major-version-bump-message: '\+semver:\s?(breaking|major)'
# minor-version-bump-message: '\+semver:\s?(feature|minor)'
# patch-version-bump-message: '\+semver:\s?(fix|patch)'
# commit-message-incrementing: Enabled
#
# Download CMake JSON-Parser: https://github.com/sbellus/json-cmake/blob/master/JSONParser.cmake
# Copy the CMake JSONParser.cmake file to the tools/cmake directory of your ESP-IDF installation.
# i.e. C:\Users\user\.platformio\packages\framework-espidf\tools\cmake
#
include( $ENV{IDF_PATH}/tools/cmake/version.cmake )
# validate JSONParser library, version.h.in, pio_lib_sync.py, esp_cmp_sync.py,
# library.json.in, and idf_component.yml.in files are available for preprocessing
if( EXISTS "$ENV{IDF_PATH}/tools/cmake/JSONParser.cmake"
AND EXISTS "${CMAKE_SOURCE_DIR}/templates/component/include/version.h.in"
AND EXISTS "${CMAKE_SOURCE_DIR}/templates/components/${COMPONENT_NAME}/library.json.in"
AND EXISTS "${CMAKE_SOURCE_DIR}/templates/components/${COMPONENT_NAME}/idf_component.yml.in")
include( $ENV{IDF_PATH}/tools/cmake/JSONParser.cmake )
# Get latest versioning information from git repository with GitVersion
execute_process(
COMMAND dotnet-gitversion
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Instantiate json variable
sbeParseJson( GIT_VERSION_JSON GIT_VERSION_OUTPUT )
# Parse versioning variables from json output
set( GIT_VERSION_DATE ${GIT_VERSION_JSON.CommitDate} )
set( GIT_SEM_VERSION ${GIT_VERSION_JSON.MajorMinorPatch} )
set( GIT_VERSION_MAJOR ${GIT_VERSION_JSON.Major} )
set( GIT_VERSION_MINOR ${GIT_VERSION_JSON.Minor} )
set( GIT_VERSION_PATCH ${GIT_VERSION_JSON.Patch} )
set( GIT_FULL_SEM_VER ${GIT_VERSION_JSON.FullSemVer} )
set( GIT_SHORT_SHA ${GIT_VERSION_JSON.ShortSha} )
# Release json variable
sbeClearJson( GIT_VERSION_JSON )
# Components should be named as "esp_<component_name>"
string( FIND "${COMPONENT_NAME}" "esp_" ESP_PREFIX )
# Check if the component name starts with "esp_"
if(ESP_PREFIX EQUAL -1)
# Use the component name as is
string( CONCAT COMPONENT_HEADER_NAME "" "${COMPONENT_NAME}" )
else()
# Parse component file name from component name
string( REPLACE "esp_" "" COMPONENT_HEADER_NAME "${COMPONENT_NAME}" )
endif()
# Set the component header name to upper case
string( TOUPPER "${COMPONENT_HEADER_NAME}" COMPONENT_HEADER_NAME_UPPER )
# REMOVE TEMPLATE GENERATED FILES FROM COMPONENT DIRECTORY (FORCED REGENERATION)
# Remove C header versioning file from component directory
file( REMOVE "${COMPONENT_DIR}/include/${COMPONENT_HEADER_NAME}_version.h" )
# Remove json library file from component directory
file( REMOVE "${COMPONENT_DIR}/library.json" )
# Remove yml idf component file from component directory
file( REMOVE "${COMPONENT_DIR}/idf_component.yml" )
# GENERATE FILES FROM TEMPLATES FOR COMPONENT DIRECTORY
# Generate C header file from template with versioning information
configure_file( "${CMAKE_SOURCE_DIR}/templates/component/include/version.h.in" "${COMPONENT_DIR}/include/${COMPONENT_HEADER_NAME}_version.h" @ONLY )
# Generate json library file from template with versioning information
configure_file( "${CMAKE_SOURCE_DIR}/templates/components/${COMPONENT_NAME}/library.json.in" "${COMPONENT_DIR}/library.json" @ONLY )
# Generate yml idf component file from template with versioning information
configure_file( "${CMAKE_SOURCE_DIR}/templates/components/${COMPONENT_NAME}/idf_component.yml.in" "${COMPONENT_DIR}/idf_component.yml" @ONLY )
endif()
idf_component_register(
SRCS bme680.c
INCLUDE_DIRS include
REQUIRES esp_driver_i2c esp_type_utils esp_timer
)

View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,124 @@
# Bosch BME680 Sensor
[![License: MIT](https://cdn.prod.website-files.com/5e0f1144930a8bc8aace526c/65dd9eb5aaca434fac4f1c34_License-MIT-blue.svg)](/LICENSE)
[![Edited with VS Code](https://badgen.net/badge/icon/VS%20Code?icon=visualstudio&label=edited%20with)](https://visualstudio.microsoft.com)
[![Build with PlatformIO](https://img.shields.io/badge/build%20with-PlatformIO-orange?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iMjUwMCIgaGVpZ2h0PSIyNTAwIiB2aWV3Qm94PSIwIDAgMjU2IDI1NiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCI+PHBhdGggZD0iTTEyOCAwQzkzLjgxIDAgNjEuNjY2IDEzLjMxNCAzNy40OSAzNy40OSAxMy4zMTQgNjEuNjY2IDAgOTMuODEgMCAxMjhjMCAzNC4xOSAxMy4zMTQgNjYuMzM0IDM3LjQ5IDkwLjUxQzYxLjY2NiAyNDIuNjg2IDkzLjgxIDI1NiAxMjggMjU2YzM0LjE5IDAgNjYuMzM0LTEzLjMxNCA5MC41MS0zNy40OUMyNDIuNjg2IDE5NC4zMzQgMjU2IDE2Mi4xOSAyNTYgMTI4YzAtMzQuMTktMTMuMzE0LTY2LjMzNC0zNy40OS05MC41MUMxOTQuMzM0IDEzLjMxNCAxNjIuMTkgMCAxMjggMCIgZmlsbD0iI0ZGN0YwMCIvPjxwYXRoIGQ9Ik0yNDkuMzg2IDEyOGMwIDY3LjA0LTU0LjM0NyAxMjEuMzg2LTEyMS4zODYgMTIxLjM4NkM2MC45NiAyNDkuMzg2IDYuNjEzIDE5NS4wNCA2LjYxMyAxMjggNi42MTMgNjAuOTYgNjAuOTYgNi42MTQgMTI4IDYuNjE0YzY3LjA0IDAgMTIxLjM4NiA1NC4zNDYgMTIxLjM4NiAxMjEuMzg2IiBmaWxsPSIjRkZGIi8+PHBhdGggZD0iTTE2MC44NjkgNzQuMDYybDUuMTQ1LTE4LjUzN2M1LjI2NC0uNDcgOS4zOTItNC44ODYgOS4zOTItMTAuMjczIDAtNS43LTQuNjItMTAuMzItMTAuMzItMTAuMzJzLTEwLjMyIDQuNjItMTAuMzIgMTAuMzJjMCAzLjc1NSAyLjAxMyA3LjAzIDUuMDEgOC44MzdsLTUuMDUgMTguMTk1Yy0xNC40MzctMy42Ny0yNi42MjUtMy4zOS0yNi42MjUtMy4zOWwtMi4yNTggMS4wMXYxNDAuODcybDIuMjU4Ljc1M2MxMy42MTQgMCA3My4xNzctNDEuMTMzIDczLjMyMy04NS4yNyAwLTMxLjYyNC0yMS4wMjMtNDUuODI1LTQwLjU1NS01Mi4xOTd6TTE0Ni41MyAxNjQuOGMtMTEuNjE3LTE4LjU1Ny02LjcwNi02MS43NTEgMjMuNjQzLTY3LjkyNSA4LjMyLTEuMzMzIDE4LjUwOSA0LjEzNCAyMS41MSAxNi4yNzkgNy41ODIgMjUuNzY2LTM3LjAxNSA2MS44NDUtNDUuMTUzIDUxLjY0NnptMTguMjE2LTM5Ljc1MmE5LjM5OSA5LjM5OSAwIDAgMC05LjM5OSA5LjM5OSA5LjM5OSA5LjM5OSAwIDAgMCA5LjQgOS4zOTkgOS4zOTkgOS4zOTkgMCAwIDAgOS4zOTgtOS40IDkuMzk5IDkuMzk5IDAgMCAwLTkuMzk5LTkuMzk4em0yLjgxIDguNjcyYTIuMzc0IDIuMzc0IDAgMSAxIDAtNC43NDkgMi4zNzQgMi4zNzQgMCAwIDEgMCA0Ljc0OXoiIGZpbGw9IiNFNTcyMDAiLz48cGF0aCBkPSJNMTAxLjM3MSA3Mi43MDlsLTUuMDIzLTE4LjkwMWMyLjg3NC0xLjgzMiA0Ljc4Ni01LjA0IDQuNzg2LTguNzAxIDAtNS43LTQuNjItMTAuMzItMTAuMzItMTAuMzItNS42OTkgMC0xMC4zMTkgNC42Mi0xMC4zMTkgMTAuMzIgMCA1LjY4MiA0LjU5MiAxMC4yODkgMTAuMjY3IDEwLjMxN0w5NS44IDc0LjM3OGMtMTkuNjA5IDYuNTEtNDAuODg1IDIwLjc0Mi00MC44ODUgNTEuODguNDM2IDQ1LjAxIDU5LjU3MiA4NS4yNjcgNzMuMTg2IDg1LjI2N1Y2OC44OTJzLTEyLjI1Mi0uMDYyLTI2LjcyOSAzLjgxN3ptMTAuMzk1IDkyLjA5Yy04LjEzOCAxMC4yLTUyLjczNS0yNS44OC00NS4xNTQtNTEuNjQ1IDMuMDAyLTEyLjE0NSAxMy4xOS0xNy42MTIgMjEuNTExLTE2LjI4IDMwLjM1IDYuMTc1IDM1LjI2IDQ5LjM2OSAyMy42NDMgNjcuOTI2em0tMTguODItMzkuNDZhOS4zOTkgOS4zOTkgMCAwIDAtOS4zOTkgOS4zOTggOS4zOTkgOS4zOTkgMCAwIDAgOS40IDkuNCA5LjM5OSA5LjM5OSAwIDAgMCA5LjM5OC05LjQgOS4zOTkgOS4zOTkgMCAwIDAtOS4zOTktOS4zOTl6bS0yLjgxIDguNjcxYTIuMzc0IDIuMzc0IDAgMSAxIDAtNC43NDggMi4zNzQgMi4zNzQgMCAwIDEgMCA0Ljc0OHoiIGZpbGw9IiNGRjdGMDAiLz48L3N2Zz4=)](https://platformio.org/)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/k0i05/library/esp_bme680.svg)](https://registry.platformio.org/libraries/k0i05/esp_bme680)
[![ESP Component Registry](https://components.espressif.com/components/k0i05/esp_bme680/badge.svg)](https://components.espressif.com/components/k0i05/esp_bme680)
This ESP32 espressif IoT development framework (esp-idf) i2c peripheral driver was developed for the Bosch BME680 pressure, temperature, humidity and gas sensor. Information on features and functionality are documented and can be found in the `bme680.h` header file and in the `documentation` folder.
## Repository
The component is hosted on github and is located here: <https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/peripherals/i2c/esp_bme680>
## General Usage
To get started, simply copy the component to your project's `components` folder and reference the `bme680.h` header file as an include. The component includes documentation for the peripheral such as the datasheet, application notes, and/or user manual where applicable.
```text
components
└── esp_bme680
├── CMakeLists.txt
├── README.md
├── LICENSE
├── idf_component.yml
├── library.json
├── documentation
│ └── datasheets, etc.
├── include
│ └── bme680_version.h
│ └── bme680.h
└── bme680.c
```
## Basic Example
Once a driver instance is instantiated the sensor is ready for usage as shown in the below example. This basic implementation of the driver utilizes default configuration settings and makes a measurement request from the sensor at user defined interval and prints the results.
```c
#include <bme680.h>
static inline void print_registers(bme680_handle_t handle) {
/* configuration registers */
bme680_control_measurement_register_t ctrl_meas_reg;
bme680_control_humidity_register_t ctrl_humi_reg;
bme680_config_register_t config_reg;
bme680_control_gas0_register_t ctrl_gas0_reg;
bme680_control_gas1_register_t ctrl_gas1_reg;
/* attempt to read control humidity register */
bme680_get_control_humidity_register(handle, &ctrl_humi_reg);
/* attempt to read control measurement register */
bme680_get_control_measurement_register(handle, &ctrl_meas_reg);
/* attempt to read configuration register */
bme680_get_configuration_register(handle, &config_reg);
/* attempt to read control gas 0 register */
bme680_get_control_gas0_register(handle, &ctrl_gas0_reg);
/* attempt to read control gas 1 register */
bme680_get_control_gas1_register(handle, &ctrl_gas1_reg);
ESP_LOGI(APP_TAG, "Variant Id (0x%02x): %s", handle->variant_id,uint8_to_binary(handle->variant_id));
ESP_LOGI(APP_TAG, "Configuration (0x%02x): %s", config_reg.reg, uint8_to_binary(config_reg.reg));
ESP_LOGI(APP_TAG, "Control Measurement (0x%02x): %s", ctrl_meas_reg.reg, uint8_to_binary(ctrl_meas_reg.reg));
ESP_LOGI(APP_TAG, "Control Humidity (0x%02x): %s", ctrl_humi_reg.reg, uint8_to_binary(ctrl_humi_reg.reg));
ESP_LOGI(APP_TAG, "Control Gas 0 (0x%02x): %s", ctrl_gas0_reg.reg, uint8_to_binary(ctrl_gas0_reg.reg));
ESP_LOGI(APP_TAG, "Control Gas 1 (0x%02x): %s", ctrl_gas1_reg.reg, uint8_to_binary(ctrl_gas1_reg.reg));
}
void i2c0_bme680_task( void *pvParameters ) {
// initialize the xLastWakeTime variable with the current time.
TickType_t last_wake_time = xTaskGetTickCount ();
//
// initialize i2c device configuration
bme680_config_t dev_cfg = I2C_BME680_CONFIG_DEFAULT;
bme680_handle_t dev_hdl;
//
// init device
bme680_init(i2c0_bus_hdl, &dev_cfg, &dev_hdl);
if (dev_hdl == NULL) {
ESP_LOGE(APP_TAG, "bme680 handle init failed");
assert(dev_hdl);
}
print_registers(dev_hdl);
// task loop entry point
for ( ;; ) {
ESP_LOGI(APP_TAG, "######################## BME680 - START #########################");
//
// handle sensor
bme680_data_t data;
esp_err_t result = bme680_get_measurements(dev_hdl, &data);
if(result != ESP_OK) {
ESP_LOGE(APP_TAG, "bme680 device read failed (%s)", esp_err_to_name(result));
} else {
data.barometric_pressure = data.barometric_pressure / 100;
ESP_LOGI(APP_TAG, "air temperature: %.2f °C", data.air_temperature);
ESP_LOGI(APP_TAG, "dewpoint temperature:%.2f °C", data.dewpoint_temperature);
ESP_LOGI(APP_TAG, "relative humidity: %.2f %%", data.relative_humidity);
ESP_LOGI(APP_TAG, "barometric pressure: %.2f hPa", data.barometric_pressure);
ESP_LOGI(APP_TAG, "gas resistance: %.2f kOhms", data.gas_resistance/1000);
ESP_LOGI(APP_TAG, "iaq score: %u (%s)", data.iaq_score, bme680_iaq_air_quality_to_string(data.iaq_score));
}
//
ESP_LOGI(APP_TAG, "######################## BME680 - END ###########################");
//
//
// pause the task per defined wait period
vTaskDelaySecUntil( &last_wake_time, I2C0_TASK_SAMPLING_RATE );
}
//
// free resources
bme680_delete( dev_hdl );
vTaskDelete( NULL );
}
```
Copyright (c) 2024 Eric Gionet (<gionet.c.eric@gmail.com>)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,26 @@
dependencies:
idf:
version: '>5.3.0'
k0i05/esp_type_utils:
version: '>=0.0.1'
description: ESP32 espressif IoT development framework (esp-idf) compatible component
for Bosch BMP390 humidity, temperature, pressure, and gas I2C sensors.
license: MIT
maintainers:
- Eric Gionet <gionet.c.eric@gmail.com>
repository: https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS.git
tags:
- temperature
- humidity
- pressure
- gas
- iaq
- quality
- air
- bme680
- bosch
- i2c
- espidf
- esp32
url: https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/peripherals/i2c/esp_bme680
version: 1.2.5

View File

@@ -0,0 +1,713 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* @file bme680.h
* @defgroup drivers bme680
* @{
*
* https://github.com/boschsensortec/BME68x_SensorAPI/blob/master/bme68x.c
*
* ESP-IDF driver for bme680 sensor
*
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* MIT Licensed as described in the file LICENSE
*/
#ifndef __BME680_H__
#define __BME680_H__
#include <stdint.h>
#include <stdbool.h>
#include <esp_err.h>
#include <driver/i2c_master.h>
#include <type_utils.h>
#include "bme680_version.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* BME680 definitions
*/
#define I2C_BME680_DEV_CLK_SPD UINT32_C(100000) //!< bme680 I2C default clock frequency (100KHz)
/*
* supported device addresses
*/
#define I2C_BME680_DEV_ADDR_LO UINT8_C(0x76) //!< bme680 I2C address when ADDR pin floating/low
#define I2C_XFR_TIMEOUT_MS (500) //!< I2C transaction timeout in milliseconds
#define BME680_HEATER_TEMP_MIN UINT8_C(200) // min. 200 degree Celsius
#define BME680_HEATER_TEMP_MAX UINT8_C(400) // max. 200 degree Celsius
#define BME680_HEATER_PROFILE_SIZE UINT8_C(10) // max. 10 heater profiles (0..9)
/*
* BME680 macros
*/
#define I2C_BME680_CONFIG_DEFAULT { \
.i2c_address = I2C_BME680_DEV_ADDR_LO, \
.i2c_clock_speed = I2C_BME680_DEV_CLK_SPD, \
.power_mode = BME680_POWER_MODE_FORCED, \
.iir_filter = BME680_IIR_FILTER_OFF, \
.pressure_oversampling = BME680_PRESSURE_OVERSAMPLING_4X, \
.temperature_oversampling = BME680_TEMPERATURE_OVERSAMPLING_4X, \
.humidity_oversampling = BME680_HUMIDITY_OVERSAMPLING_4X, \
.gas_enabled = true, \
.heater_temperature = 300, \
.heater_duration = 300, \
.heater_profile_size = 1 \
}
/*
* BME680 enumerator and structure declarations
*/
/**
* @brief BME680 heater set-points enumerator.
*/
typedef enum bme680_heater_setpoints_e {
BME680_HEATER_SETPOINT_0 = (0b0000),
BME680_HEATER_SETPOINT_1 = (0b0001),
BME680_HEATER_SETPOINT_2 = (0b0010),
BME680_HEATER_SETPOINT_3 = (0b0011),
BME680_HEATER_SETPOINT_4 = (0b0100),
BME680_HEATER_SETPOINT_5 = (0b0101),
BME680_HEATER_SETPOINT_6 = (0b0110),
BME680_HEATER_SETPOINT_7 = (0b0111),
BME680_HEATER_SETPOINT_8 = (0b1000),
BME680_HEATER_SETPOINT_9 = (0b1001)
} bme680_heater_setpoints_t;
/**
* @brief BME680 gas wait multipliers enumerator.
*/
typedef enum bme680_gas_wait_multipliers_e {
BME680_GAS_WAIT_MULT_1 = (0b00),
BME680_GAS_WAIT_MULT_4 = (0b01),
BME680_GAS_WAIT_MULT_16 = (0b10),
BME680_GAS_WAIT_MULT_64 = (0b11)
} bme680_gas_wait_multipliers_t;
/**
* @brief BME680 IIR filters coefficient enumerator.
*/
typedef enum bme680_iir_filters_e {
BME680_IIR_FILTER_OFF = (0b000),
BME680_IIR_FILTER_1 = (0b001),
BME680_IIR_FILTER_3 = (0b010),
BME680_IIR_FILTER_7 = (0b011),
BME680_IIR_FILTER_15 = (0b100),
BME680_IIR_FILTER_31 = (0b101),
BME680_IIR_FILTER_63 = (0b110),
BME680_IIR_FILTER_127 = (0b111),
} bme680_iir_filters_t;
/**
* @brief BME680 power modes enumerator.
*/
typedef enum bme680_power_modes_e {
BME680_POWER_MODE_SLEEP = (0b00), //!< sleep mode, default after power-up
BME680_POWER_MODE_FORCED = (0b01), //!< measurement is initiated by user
BME680_POWER_MODE_PARALLEL = (0b10), //!< parallel mode, gas and TPH measurements are done in parallel
BME680_POWER_MODE_SEQUENTIAL = (0b11) //!< sequential mode, gas and TPH measurements are done in sequence
} bme680_power_modes_t;
/**
* @brief BME680 pressure oversampling enumerator.
*/
typedef enum bme680_pressure_oversampling_e {
BME680_PRESSURE_OVERSAMPLING_SKIPPED = (0b000), //!< skipped, no measurement, output set to 0x80000
BME680_PRESSURE_OVERSAMPLING_1X = (0b001), //!< ultra low power
BME680_PRESSURE_OVERSAMPLING_2X = (0b010), //!< low power
BME680_PRESSURE_OVERSAMPLING_4X = (0b011), //!< standard
BME680_PRESSURE_OVERSAMPLING_8X = (0b100), //!< high resolution
BME680_PRESSURE_OVERSAMPLING_16X = (0b101) //!< ultra high resolution
} bme680_pressure_oversampling_t;
/**
* @brief BME680 temperature oversampling enumerator.
*/
typedef enum bme680_temperature_oversampling_e {
BME680_TEMPERATURE_OVERSAMPLING_SKIPPED = (0b000), //!< skipped, no measurement, output set to 0x80000
BME680_TEMPERATURE_OVERSAMPLING_1X = (0b001), //!< ultra low power
BME680_TEMPERATURE_OVERSAMPLING_2X = (0b010), //!< low power
BME680_TEMPERATURE_OVERSAMPLING_4X = (0b011), //!< standard
BME680_TEMPERATURE_OVERSAMPLING_8X = (0b100), //!< high resolution
BME680_TEMPERATURE_OVERSAMPLING_16X = (0b101), //!< ultra high resolution
} bme680_temperature_oversampling_t;
/**
* @brief BME680 humidity oversampling enumerator.
*/
typedef enum bme680_humidity_oversampling_e {
BME680_HUMIDITY_OVERSAMPLING_SKIPPED = (0b000), //!< skipped, no measurement, output set to 0x80000
BME680_HUMIDITY_OVERSAMPLING_1X = (0b001), //!< ultra low power
BME680_HUMIDITY_OVERSAMPLING_2X = (0b010), //!< low power
BME680_HUMIDITY_OVERSAMPLING_4X = (0b011), //!< standard
BME680_HUMIDITY_OVERSAMPLING_8X = (0b100), //!< high resolution
BME680_HUMIDITY_OVERSAMPLING_16X = (0b101), //!< ultra high resolution
} bme680_humidity_oversampling_t;
/**
* @brief BME680 status 0 register (0x1d) structure. The reset state is 0x00 for this register.
* This register contains the gas measurement index, measuring status, gas measuring status, and
* new data status.
*/
typedef union __attribute__((packed)) bme680_status0_register_u {
struct {
uint8_t gas_measurement_index:4; /*!< bme680 user can program sequence of up to 10 conversions by setting nb_conv<3:0> (bit:0-3) */
uint8_t reserved:1; /*!< reserved (bit:4) */
bool measuring:1; /*!< bmp680 automatically set to 1 whenever a conversion is running and back to 0 when results transferred to data registers (bit:5) */
bool gas_measuring:1; /*!< bme680 automatically set to 1 during gas measurement and back to 0 when results transferred to data registers (bit:6) */
bool new_data:1; /*!< bme680 measured data are stored into the data registers when true (bit:7) */
} bits;
uint8_t reg;
} bme680_status0_register_t;
/**
* @brief BME680 control measurement register (0x74) structure. The reset state is 0x00 for this register.
* This register contains the power mode, pressure and temperature oversampling settings.
*/
typedef union __attribute__((packed)) bme680_control_measurement_register_u {
struct {
bme680_power_modes_t power_mode:2; /*!< bme680 power mode of the device (bit:0-1) */
bme680_pressure_oversampling_t pressure_oversampling:3; /*!< bme680 oversampling of pressure data (bit:2-4) */
bme680_temperature_oversampling_t temperature_oversampling:3; /*!< bme680 oversampling of temperature data (bit:5-7) */
} bits;
uint8_t reg;
} bme680_control_measurement_register_t;
/**
* @brief BME680 control measurement register (0x72) structure. The reset state is 0x00 for this register.
* This register contains humidity oversampling and SPI interrupt settings.
*/
typedef union __attribute__((packed)) bme680_control_humidity_register_u {
struct {
bme680_humidity_oversampling_t humidity_oversampling:3; /*!< bme680 oversampling of humidity data (bit:0-2) */
uint8_t reserved1:3; /*!< bme680 reserved (bit:3-5) */
bool spi_irq_enabled:1; /*!< bme680 3-wire SPI interrupt enabled when true (bit:6) */
uint8_t reserved2:1; /*!< bme680 reserved (bit:7) */
} bits;
uint8_t reg;
} bme680_control_humidity_register_t;
/**
* @brief BME680 control gas 0 register (0x71) structure. The reset state is 0x00 for this register.
* This register contains the heater set-point and gas conversion settings.
*/
typedef union __attribute__((packed)) bme680_control_gas1_register_u {
struct {
bme680_heater_setpoints_t heater_setpoint:4; /*!< bme680 (bit:0-3) */
bool gas_conversion_enabled:1;/*!< bme680 gas conversions are started only appropriate mode when true (bit:4) */
uint8_t reserved:3; /*!< bme680 reserved (bit:5-7) */
} bits;
uint8_t reg;
} bme680_control_gas1_register_t;
/**
* @brief BME680 control gas 1 register (0x70) structure. The reset state is 0x00 for this register.
* This register contains heater setting.
*/
typedef union __attribute__((packed)) bme680_control_gas0_register_u {
struct {
uint8_t reserved1:3; /*!< bme680 (bit:0-2) */
bool heater_disabled:1; /*!< bme680 heater is off when true (bit:3) */
uint8_t reserved2:4; /*!< bme680 reserved (bit:4-7) */
} bits;
uint8_t reg;
} bme680_control_gas0_register_t;
/**
* @brief BME680 control gas_r_lsb register (0x2b) structure. The reset state is 0x00 for this register.
* This register contains the gas resistance lsb, gas validation flag, heater stab, and gas range settings.
*/
typedef union __attribute__((packed)) bme680_gas_r_lsb_register_u {
struct {
uint8_t gas_range:4; /*!< bme680 adc range of measure gas sensor resistance (bit:0-3) */
bool heater_stable:1; /*!< bme680 heater temperature stability for target heater resistance (bit:4) */
bool gas_valid:1; /*!< bme680 gas conversion is valid when true (bit:5) */
uint8_t gas_lsb:2; /*!< bme680 gas resistance lsb (bit:6-7) */
} bits;
uint8_t reg;
} bme680_gas_lsb_register_t;
/**
* @brief BME680 configuration register (0x75) structure. The reset state is 0x00 for this register.
* This register contains SPI and IIR filter settings.
*/
typedef union __attribute__((packed)) bme680_configuration_register_u {
struct {
bool spi_enabled:1; /*!< bme680 3-wire SPI interface enabled when true (bit:0) */
uint8_t reserved1:1; /*!< bme680 reserved (bit:1) */
bme680_iir_filters_t iir_filter:3; /*!< bme680 time constant of the IIR filter (bit:2-4) */
uint8_t reserved2:3; /*!< bme680 reserved (bit:5-7) */
} bits;
uint8_t reg;
} bme680_config_register_t;
/**
* @brief BME680 calibration factors structure definition.
*/
typedef struct bme680_cal_factors_s {
/* temperature compensation */
uint16_t par_T1;
int16_t par_T2;
int8_t par_T3;
float temperature_fine;
/* humidity compensation */
uint16_t par_H1;
uint16_t par_H2;
int8_t par_H3;
int8_t par_H4;
int8_t par_H5;
uint8_t par_H6;
int8_t par_H7;
/* pressure compensation */
uint16_t par_P1;
int16_t par_P2;
int8_t par_P3;
int16_t par_P4;
int16_t par_P5;
int8_t par_P6;
int8_t par_P7;
int16_t par_P8;
int16_t par_P9;
uint8_t par_P10;
/* resistance heat compensation */
int8_t par_G1;
int16_t par_G2;
int8_t par_G3;
/* other */
uint8_t res_heat_range;
int8_t res_heat_val;
int8_t range_switching_error;
} bme680_cal_factors_t;
/**
* @brief BME680 data structure definition.
*/
typedef struct bme680_data_s {
float dewpoint_temperature; /*!< dew-point temperature in degrees celsius */
float air_temperature; /*!< air temperature in degrees celsius */
float relative_humidity; /*!< relative humidity in percent */
float barometric_pressure; /*!< barometric pressure in hecto-pascal */
bool gas_valid; /*!< indicates that the gas measurement results are valid */
float gas_resistance; /*!< gas resistance in ohms */
uint8_t gas_range; /*!< gas resistance range */
uint8_t gas_index; /*!< heater profile used (0..9) */
bool heater_stable; /*!< indicates that the heater temperature was stable */
uint16_t iaq_score; /*!< air quality index (0..500) */
float temperature_score;
float humidity_score;
float gas_score;
} bme680_data_t;
/**
* @brief BME680 ADC data structure definition.
*/
typedef struct bme680_adc_data_s {
uint32_t temperature;
uint16_t humidity;
uint32_t pressure;
uint16_t gas;
bool gas_valid;
uint8_t gas_range;
uint8_t gas_index;
bool heater_stable;
} bme680_adc_data_t;
/**
* @brief BME680 configuration structure definition.
*/
typedef struct bme680_config_s {
uint16_t i2c_address; /*!< bme680 i2c device address */
uint32_t i2c_clock_speed; /*!< bme680 i2c device scl clock speed */
bme680_power_modes_t power_mode; /*!< bme680 power mode */
bme680_iir_filters_t iir_filter;
bme680_pressure_oversampling_t pressure_oversampling;
bme680_temperature_oversampling_t temperature_oversampling;
bme680_humidity_oversampling_t humidity_oversampling;
bool gas_enabled; /*!< bme680 gas measurements enabled when true */
uint16_t heater_temperature; /*!< bme680 heater temperature for forced mode in degrees celsius */
uint16_t heater_duration; /*!< bme680 heating duration for forced mode in milliseconds */
uint16_t heater_temperature_profile[BME680_HEATER_PROFILE_SIZE]; /*!< bme680 heater temperature profile in degrees celsius */
uint16_t heater_duration_profile[BME680_HEATER_PROFILE_SIZE]; /*!< bme680 heating duration profile in milliseconds */
uint8_t heater_profile_size; /*!< bme680 size of the heating profile */
uint16_t heater_shared_duration; /*!< bme680 heating duration for parallel mode in milliseconds */
} bme680_config_t;
/**
* @brief BME680 context structure.
*/
struct bme680_context_t {
bme680_config_t dev_config; /*!< bme680 device configuration */
i2c_master_dev_handle_t i2c_handle; /*!< bme680 I2C device handle */
bme680_cal_factors_t *dev_cal_factors; /*!< bme680 device calibration factors */
uint8_t chip_id; /*!< bme680 chip identification register */
uint16_t ambient_temperature;
uint8_t variant_id;
};
/**
* @brief BME680 context structure definition.
*/
typedef struct bme680_context_t bme680_context_t;
/**
* @brief BME680 handle structure definition.
*/
typedef struct bme680_context_t *bme680_handle_t;
/**
* @brief Reads chip identification register from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] reg BME680 chip identifier.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_chip_id_register(bme680_handle_t handle, uint8_t *const reg);
/**
* @brief Reads variant identification register from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] reg BME680 variant identifier.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_variant_id_register(bme680_handle_t handle, uint8_t *const reg);
/**
* @brief Reads status register from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] reg Status 0 register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_status0_register(bme680_handle_t handle, bme680_status0_register_t *const reg);
/**
* @brief Reads gas resistance LSB register from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] reg Gas LSB register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_gas_lsb_register(bme680_handle_t handle, bme680_gas_lsb_register_t *const reg);
/**
* @brief Writes gas resistance LSB register to BME680.
*
* @param[in] handle BME680 device handle.
* @param[in] reg Gas LSB register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_gas_lsb_register(bme680_handle_t handle, const bme680_gas_lsb_register_t reg);
/**
* @brief Reads control measurement register from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] reg Control measurement register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_control_measurement_register(bme680_handle_t handle, bme680_control_measurement_register_t *const reg);
/**
* @brief Writes control measurement register to BME680.
*
* @param[in] handle BME680 device handle.
* @param[in] reg Control measurement register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_control_measurement_register(bme680_handle_t handle, const bme680_control_measurement_register_t reg);
/**
* @brief Reads control humidity register from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] reg Control humidity register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_control_humidity_register(bme680_handle_t handle, bme680_control_humidity_register_t *const reg);
/**
* @brief Writes control humidity register to BME680.
*
* @param[in] handle BME680 device handle.
* @param[in] reg Control humidity register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_control_humidity_register(bme680_handle_t handle, const bme680_control_humidity_register_t reg);
/**
* @brief Reads control gas 0 register from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] reg Control gas 0 register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_control_gas0_register(bme680_handle_t handle, bme680_control_gas0_register_t *const reg);
/**
* @brief Writes control gas 0 register to BME680.
*
* @param[in] handle BME680 device handle.
* @param[in] reg Control gas 0 register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_control_gas0_register(bme680_handle_t handle, const bme680_control_gas0_register_t reg);
/**
* @brief Reads control gas 1 register from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] reg Control gas 1 register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_control_gas1_register(bme680_handle_t handle, bme680_control_gas1_register_t *const reg);
/**
* @brief Writes control gas 1 register to BME680.
*
* @param[in] handle BME680 device handle.
* @param[in] reg Control gas 1 register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_control_gas1_register(bme680_handle_t handle, const bme680_control_gas1_register_t reg);
/**
* @brief Reads configuration register from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] reg Configuration register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_configuration_register(bme680_handle_t handle, bme680_config_register_t *const reg);
/**
* @brief Writes configuration register to BME680.
*
* @param[in] handle BME680 device handle.
* @param[in] reg Configuration register.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_configuration_register(bme680_handle_t handle, const bme680_config_register_t reg);
/**
* @brief Initializes an BME680 device onto the master bus.
*
* @param[in] master_handle I2C master bus handle.
* @param[in] bme680_config BME680 device configuration.
* @param[out] bme680_handle BME680 device handle.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_init(i2c_master_bus_handle_t master_handle, const bme680_config_t *bme680_config, bme680_handle_t *bme680_handle);
/**
* @brief Reads humidity, temperature, and pressure ADC signals from BME680
*
* @param[in] handle BME680 device handle.
* @param[out] data BME680 ADC data structure.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_adc_signals(bme680_handle_t handle, bme680_adc_data_t *const data);
/**
* @brief Reads humidity, temperature, and pressure measurements from BME680
*
* @param[in] handle BME680 device handle.
* @param[out] data BME680 data structure.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_data(bme680_handle_t handle, bme680_data_t *const data);
/**
* @brief Reads data status of the BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] ready Data is ready when asserted to true.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_data_status(bme680_handle_t handle, bool *const ready);
/**
* @brief Reads gas measurement index from the BME680.
*
* @param handle BME680 device handle.
* @param index Gas measurement index (0..9).
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_gas_measurement_index(bme680_handle_t handle, uint8_t *const index);
/**
* @brief Reads power mode setting from the BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] power_mode BME680 power mode setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_power_mode(bme680_handle_t handle, bme680_power_modes_t *const power_mode);
/**
* @brief Writes power mode setting to BME680. See datasheet, section 3.6, table 10.
*
* @param[in] handle BME680 device handle.
* @param[in] power_mode BME680 power mode setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_power_mode(bme680_handle_t handle, const bme680_power_modes_t power_mode);
/**
* @brief Reads pressure oversampling setting from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] oversampling BME680 pressure oversampling setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_pressure_oversampling(bme680_handle_t handle, bme680_pressure_oversampling_t *const oversampling);
/**
* @brief Writes pressure oversampling setting to BME680. See datasheet, section 3.3.1, table 4.
*
* @param[in] handle BME680 device handle.
* @param[in] oversampling BME680 pressure oversampling setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_pressure_oversampling(bme680_handle_t handle, const bme680_pressure_oversampling_t oversampling);
/**
* @brief Reads temperature oversampling setting from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] oversampling BME680 temperature oversampling setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_temperature_oversampling(bme680_handle_t handle, bme680_temperature_oversampling_t *const oversampling);
/**
* @brief Writes temperature oversampling setting to BME680. See datasheet, section 3.3.1, table 4.
*
* @param[in] handle BME680 device handle.
* @param[in] oversampling BME680 temperature oversampling setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_temperature_oversampling(bme680_handle_t handle, const bme680_temperature_oversampling_t oversampling);
/**
* @brief Reads humidity oversampling setting from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] oversampling BME680 humidity oversampling setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_humidity_oversampling(bme680_handle_t handle, bme680_humidity_oversampling_t *const oversampling);
/**
* @brief Writes humidity oversampling setting to BME680. See datasheet, section 3.3.1, table 4.
*
* @param[in] handle BME680 device handle.
* @param[in] oversampling BME680 humidity oversampling setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_humidity_oversampling(bme680_handle_t handle, const bme680_humidity_oversampling_t oversampling);
/**
* @brief Reads IIR filter setting from BME680.
*
* @param[in] handle BME680 device handle.
* @param[out] iir_filter BME680 IIR filter setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_get_iir_filter(bme680_handle_t handle, bme680_iir_filters_t *const iir_filter);
/**
* @brief Writes IIR filter setting to BME680. See datasheet, section 3.4, table 7.
*
* @param[in] handle BME680 device handle.
* @param[in] iir_filter BME680 IIR filter setting.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_set_iir_filter(bme680_handle_t handle, const bme680_iir_filters_t iir_filter);
/**
* @brief Issues soft-reset sensor and initializes registers for BME680.
*
* @param[in] handle BME680 device handle.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_reset(bme680_handle_t handle);
/**
* @brief Air quality as a string based on the IAQ score.
*
* @param iaq_score Index of air quality score.
* @return char* Air quality as a string.
*/
char *bme680_air_quality_to_string(float iaq_score);
/**
* @brief Removes an BME680 device from master bus.
*
* @param[in] handle BME680 device handle.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_remove(bme680_handle_t handle);
/**
* @brief Removes an BME680 device from master bus and frees handle.
*
* @param[in] handle BME680 device handle.
* @return esp_err_t ESP_OK on success.
*/
esp_err_t bme680_delete(bme680_handle_t handle);
/**
* @brief Converts BME680 firmware version numbers (major, minor, patch, build) into a string.
*
* @return char* BME680 firmware version as a string that is formatted as X.X.X (e.g. 4.0.0).
*/
const char* bme680_get_fw_version(void);
/**
* @brief Converts BME680 firmware version numbers (major, minor, patch) into an integer value.
*
* @return int32_t BME680 firmware version number.
*/
int32_t bme680_get_fw_version_number(void);
#ifdef __cplusplus
}
#endif
/**@}*/
#endif // __BME680_H__

View File

@@ -0,0 +1,108 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* MIT Licensed as described in the file LICENSE
*/
#ifndef __BME680_FW_VERSION_H__
#define __BME680_FW_VERSION_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* public constant definitions
*/
#define BME680_COMPONENT_NAME "esp_bme680"
/** Version release date */
#define BME680_FW_VERSION_DATE "2025-04-02"
/** Major version number (X.x.x) */
#define BME680_FW_VERSION_MAJOR 1
/** Minor version number (x.X.x) */
#define BME680_FW_VERSION_MINOR 2
/** Patch version number (x.x.X) */
#define BME680_FW_VERSION_PATCH 5
/** Semantic version number (X.X.X-X) */
#define BME680_FW_SEMANTIC_VERSION "1.2.5-1"
/** Git version hash */
#define BME680_FW_GIT_SHORT_SHA "82602db"
/**
* public macro definitions
*/
/**
* Macro to print x parameter as a string i.e. enclose x in double quotes.
*/
#define STR_QUOTES( x ) #x
/**
* Macro to create a string of x parameter with all macros fully expanded.
*/
#define STR( x ) STR_QUOTES( x )
/**
* Macro to generate current firmware version numbers (major, minor, patch) into a string that is formatted as X.X.X (e.g. 4.0.0).
*/
#define BME680_FW_VERSION_STR \
STR( BME680_FW_VERSION_MAJOR ) "." \
STR( BME680_FW_VERSION_MINOR ) "." \
STR( BME680_FW_VERSION_PATCH )
/**
* Macro to convert firmware version parameters (major, minor, patch numbers) into an integer (`int32_t`)
* value that can be used for comparison purposes.
*
* As an example, FW_VERSION_INT32 >= FW_VERSION_PARAMS_INT32(4, 0, 0).
*/
#define BME680_FW_VERSION_PARAMS_INT32( major, minor, patch ) \
((major << 16) | (minor << 8) | (patch))
/**
* Macro to generate current firmware version numbers (major, minor, patch) as an integer (`int32_t`) value that can
* be used for comparison purposes.
*
* As an example, FW_VERSION_INT32 >= FW_VERSION_PARAMS_INT32(4, 0, 0).
*/
#define BME680_FW_VERSION_INT32 \
BME680_FW_VERSION_PARAMS_INT32( \
BME680_FW_VERSION_MAJOR, \
BME680_FW_VERSION_MINOR, \
BME680_FW_VERSION_PATCH)
#ifdef __cplusplus
}
#endif
/**@}*/
#endif //__BME680_FW_VERSION_H__

View File

@@ -0,0 +1,25 @@
{
"name": "esp_bme680",
"keywords": "esp32, espressif, espidf, temperature, pressure, humidity, gas, iaq, bme680, i2c, bosch",
"description": "ESP32 espressif IoT development framework (esp-idf) compatible component for Bosch BMP390 humidity, temperature, pressure, and gas I2C sensors.",
"authors": [
{
"name": "Eric Gionet",
"email": "gionet.c.eric@gmail.com",
"maintainer": true
}
],
"repository": {
"type": "git",
"url": "https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/peripherals/i2c/esp_bme680"
},
"homepage": "https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS",
"version": "1.2.5",
"license": "MIT",
"frameworks": "espidf",
"platforms": "espressif32",
"headers": "bme680.h",
"dependencies": {
"k0i05/esp_type_utils": ">=1.0.0"
}
}

View File

@@ -0,0 +1 @@
dfe2feb2117ee060c085ec166b56cfd9d66cef4019216bf8722e45e43a3b562f

View File

@@ -0,0 +1,97 @@
#
# Versioning Information for ESP-IDF Components with GitHub, GitVersion and CMake
#
# Inspired by: https://www.esp32.com/viewtopic.php?f=2&t=45054&p=146150#p146150
#
# Install Git-Version via command prompt: dotnet tool install --global GitVersion.Tool
# Create a GitVersion.yml file in the root of your project with the following content:
#
# major-version-bump-message: '\+semver:\s?(breaking|major)'
# minor-version-bump-message: '\+semver:\s?(feature|minor)'
# patch-version-bump-message: '\+semver:\s?(fix|patch)'
# commit-message-incrementing: Enabled
#
# Download CMake JSON-Parser: https://github.com/sbellus/json-cmake/blob/master/JSONParser.cmake
# Copy the CMake JSONParser.cmake file to the tools/cmake directory of your ESP-IDF installation.
# i.e. C:\Users\user\.platformio\packages\framework-espidf\tools\cmake
#
include( $ENV{IDF_PATH}/tools/cmake/version.cmake )
# validate JSONParser library, version.h.in, pio_lib_sync.py, esp_cmp_sync.py,
# library.json.in, and idf_component.yml.in files are available for preprocessing
if( EXISTS "$ENV{IDF_PATH}/tools/cmake/JSONParser.cmake"
AND EXISTS "${CMAKE_SOURCE_DIR}/templates/component/include/version.h.in"
AND EXISTS "${CMAKE_SOURCE_DIR}/templates/components/${COMPONENT_NAME}/library.json.in"
AND EXISTS "${CMAKE_SOURCE_DIR}/templates/components/${COMPONENT_NAME}/idf_component.yml.in")
include( $ENV{IDF_PATH}/tools/cmake/JSONParser.cmake )
# Get latest versioning information from git repository with GitVersion
execute_process(
COMMAND dotnet-gitversion
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_VERSION_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
# Instantiate json variable
sbeParseJson( GIT_VERSION_JSON GIT_VERSION_OUTPUT )
# Parse versioning variables from json output
set( GIT_VERSION_DATE ${GIT_VERSION_JSON.CommitDate} )
set( GIT_SEM_VERSION ${GIT_VERSION_JSON.MajorMinorPatch} )
set( GIT_VERSION_MAJOR ${GIT_VERSION_JSON.Major} )
set( GIT_VERSION_MINOR ${GIT_VERSION_JSON.Minor} )
set( GIT_VERSION_PATCH ${GIT_VERSION_JSON.Patch} )
set( GIT_FULL_SEM_VER ${GIT_VERSION_JSON.FullSemVer} )
set( GIT_SHORT_SHA ${GIT_VERSION_JSON.ShortSha} )
# Release json variable
sbeClearJson( GIT_VERSION_JSON )
# Components should be named as "esp_<component_name>"
string( FIND "${COMPONENT_NAME}" "esp_" ESP_PREFIX )
# Check if the component name starts with "esp_"
if(ESP_PREFIX EQUAL -1)
# Use the component name as is
string( CONCAT COMPONENT_HEADER_NAME "" "${COMPONENT_NAME}" )
else()
# Parse component file name from component name
string( REPLACE "esp_" "" COMPONENT_HEADER_NAME "${COMPONENT_NAME}" )
endif()
# Set the component header name to upper case
string( TOUPPER "${COMPONENT_HEADER_NAME}" COMPONENT_HEADER_NAME_UPPER )
# REMOVE TEMPLATE GENERATED FILES FROM COMPONENT DIRECTORY (FORCED REGENERATION)
# Remove C header versioning file from component directory
file( REMOVE "${COMPONENT_DIR}/include/${COMPONENT_HEADER_NAME}_version.h" )
# Remove json library file from component directory
file( REMOVE "${COMPONENT_DIR}/library.json" )
# Remove yml idf component file from component directory
file( REMOVE "${COMPONENT_DIR}/idf_component.yml" )
# GENERATE FILES FROM TEMPLATES FOR COMPONENT DIRECTORY
# Generate C header file from template with versioning information
configure_file( "${CMAKE_SOURCE_DIR}/templates/component/include/version.h.in" "${COMPONENT_DIR}/include/${COMPONENT_HEADER_NAME}_version.h" @ONLY )
# Generate json library file from template with versioning information
configure_file( "${CMAKE_SOURCE_DIR}/templates/components/${COMPONENT_NAME}/library.json.in" "${COMPONENT_DIR}/library.json" @ONLY )
# Generate yml idf component file from template with versioning information
configure_file( "${CMAKE_SOURCE_DIR}/templates/components/${COMPONENT_NAME}/idf_component.yml.in" "${COMPONENT_DIR}/idf_component.yml" @ONLY )
endif()
# Register the component
idf_component_register(
SRCS type_utils.c
INCLUDE_DIRS include
)

View File

@@ -0,0 +1,63 @@
# ESP-IDF Type Utilities
[![License: MIT](https://cdn.prod.website-files.com/5e0f1144930a8bc8aace526c/65dd9eb5aaca434fac4f1c34_License-MIT-blue.svg)](/LICENSE)
[![Edited with VS Code](https://badgen.net/badge/icon/VS%20Code?icon=visualstudio&label=edited%20with)](https://visualstudio.microsoft.com)
[![Build with PlatformIO](https://img.shields.io/badge/build%20with-PlatformIO-orange?logo=data%3Aimage%2Fsvg%2Bxml%3Bbase64%2CPHN2ZyB3aWR0aD0iMjUwMCIgaGVpZ2h0PSIyNTAwIiB2aWV3Qm94PSIwIDAgMjU2IDI1NiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBwcmVzZXJ2ZUFzcGVjdFJhdGlvPSJ4TWlkWU1pZCI+PHBhdGggZD0iTTEyOCAwQzkzLjgxIDAgNjEuNjY2IDEzLjMxNCAzNy40OSAzNy40OSAxMy4zMTQgNjEuNjY2IDAgOTMuODEgMCAxMjhjMCAzNC4xOSAxMy4zMTQgNjYuMzM0IDM3LjQ5IDkwLjUxQzYxLjY2NiAyNDIuNjg2IDkzLjgxIDI1NiAxMjggMjU2YzM0LjE5IDAgNjYuMzM0LTEzLjMxNCA5MC41MS0zNy40OUMyNDIuNjg2IDE5NC4zMzQgMjU2IDE2Mi4xOSAyNTYgMTI4YzAtMzQuMTktMTMuMzE0LTY2LjMzNC0zNy40OS05MC41MUMxOTQuMzM0IDEzLjMxNCAxNjIuMTkgMCAxMjggMCIgZmlsbD0iI0ZGN0YwMCIvPjxwYXRoIGQ9Ik0yNDkuMzg2IDEyOGMwIDY3LjA0LTU0LjM0NyAxMjEuMzg2LTEyMS4zODYgMTIxLjM4NkM2MC45NiAyNDkuMzg2IDYuNjEzIDE5NS4wNCA2LjYxMyAxMjggNi42MTMgNjAuOTYgNjAuOTYgNi42MTQgMTI4IDYuNjE0YzY3LjA0IDAgMTIxLjM4NiA1NC4zNDYgMTIxLjM4NiAxMjEuMzg2IiBmaWxsPSIjRkZGIi8+PHBhdGggZD0iTTE2MC44NjkgNzQuMDYybDUuMTQ1LTE4LjUzN2M1LjI2NC0uNDcgOS4zOTItNC44ODYgOS4zOTItMTAuMjczIDAtNS43LTQuNjItMTAuMzItMTAuMzItMTAuMzJzLTEwLjMyIDQuNjItMTAuMzIgMTAuMzJjMCAzLjc1NSAyLjAxMyA3LjAzIDUuMDEgOC44MzdsLTUuMDUgMTguMTk1Yy0xNC40MzctMy42Ny0yNi42MjUtMy4zOS0yNi42MjUtMy4zOWwtMi4yNTggMS4wMXYxNDAuODcybDIuMjU4Ljc1M2MxMy42MTQgMCA3My4xNzctNDEuMTMzIDczLjMyMy04NS4yNyAwLTMxLjYyNC0yMS4wMjMtNDUuODI1LTQwLjU1NS01Mi4xOTd6TTE0Ni41MyAxNjQuOGMtMTEuNjE3LTE4LjU1Ny02LjcwNi02MS43NTEgMjMuNjQzLTY3LjkyNSA4LjMyLTEuMzMzIDE4LjUwOSA0LjEzNCAyMS41MSAxNi4yNzkgNy41ODIgMjUuNzY2LTM3LjAxNSA2MS44NDUtNDUuMTUzIDUxLjY0NnptMTguMjE2LTM5Ljc1MmE5LjM5OSA5LjM5OSAwIDAgMC05LjM5OSA5LjM5OSA5LjM5OSA5LjM5OSAwIDAgMCA5LjQgOS4zOTkgOS4zOTkgOS4zOTkgMCAwIDAgOS4zOTgtOS40IDkuMzk5IDkuMzk5IDAgMCAwLTkuMzk5LTkuMzk4em0yLjgxIDguNjcyYTIuMzc0IDIuMzc0IDAgMSAxIDAtNC43NDkgMi4zNzQgMi4zNzQgMCAwIDEgMCA0Ljc0OXoiIGZpbGw9IiNFNTcyMDAiLz48cGF0aCBkPSJNMTAxLjM3MSA3Mi43MDlsLTUuMDIzLTE4LjkwMWMyLjg3NC0xLjgzMiA0Ljc4Ni01LjA0IDQuNzg2LTguNzAxIDAtNS43LTQuNjItMTAuMzItMTAuMzItMTAuMzItNS42OTkgMC0xMC4zMTkgNC42Mi0xMC4zMTkgMTAuMzIgMCA1LjY4MiA0LjU5MiAxMC4yODkgMTAuMjY3IDEwLjMxN0w5NS44IDc0LjM3OGMtMTkuNjA5IDYuNTEtNDAuODg1IDIwLjc0Mi00MC44ODUgNTEuODguNDM2IDQ1LjAxIDU5LjU3MiA4NS4yNjcgNzMuMTg2IDg1LjI2N1Y2OC44OTJzLTEyLjI1Mi0uMDYyLTI2LjcyOSAzLjgxN3ptMTAuMzk1IDkyLjA5Yy04LjEzOCAxMC4yLTUyLjczNS0yNS44OC00NS4xNTQtNTEuNjQ1IDMuMDAyLTEyLjE0NSAxMy4xOS0xNy42MTIgMjEuNTExLTE2LjI4IDMwLjM1IDYuMTc1IDM1LjI2IDQ5LjM2OSAyMy42NDMgNjcuOTI2em0tMTguODItMzkuNDZhOS4zOTkgOS4zOTkgMCAwIDAtOS4zOTkgOS4zOTggOS4zOTkgOS4zOTkgMCAwIDAgOS40IDkuNCA5LjM5OSA5LjM5OSAwIDAgMCA5LjM5OC05LjQgOS4zOTkgOS4zOTkgMCAwIDAtOS4zOTktOS4zOTl6bS0yLjgxIDguNjcxYTIuMzc0IDIuMzc0IDAgMSAxIDAtNC43NDggMi4zNzQgMi4zNzQgMCAwIDEgMCA0Ljc0OHoiIGZpbGw9IiNGRjdGMDAiLz48L3N2Zz4=)](https://platformio.org/)
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/k0i05/library/esp_type_utils.svg)](https://registry.platformio.org/libraries/k0i05/esp_type_utils)
[![ESP Component Registry](https://components.espressif.com/components/k0i05/esp_type_utils/badge.svg)](https://components.espressif.com/components/k0i05/esp_type_utils)
This ESP32 espressif IoT development framework (esp-idf) type utilities component was developed as a helper for byte manipulation and string functionality. Information on features and functionality are documented and can be found in the `type_utils.h` header file.
## Repository
The component is hosted on github and is located here: <https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/utilities/esp_type_utils>
## General Usage
To get started, simply copy the component to your project's `components` folder and reference the `type_utils.h` header file as an include. The component includes documentation for the peripheral such as the datasheet, application notes, and/or user manual where applicable.
```text
components
└── esp_type_utils
├── CMakeLists.txt
├── README.md
├── LICENSE
├── idf_component.yml
├── library.json
├── documentation
│ └── datasheets, etc.
├── include
│ └── type_utils_version.h
│ └── type_utils.h
└── type_utils.c
```
## Basic Example
Once the component is referenced as an include, the functions should be visible and available for usage. The below example demonstrates an i2c transaction which reads the register's contents and writes the contents of the register as a binary string.
```c
#include <type_utils.h>
/* declare device registers */
ltr390uv_control_register_t c_reg;
ltr390uv_interrupt_config_register_t ic_reg;
ltr390uv_measure_register_t m_reg;
ltr390uv_gain_register_t g_reg;
/* attempt i2c read transaction from device registers */
ltr390uv_get_measure_register(dev_hdl, &m_reg);
ltr390uv_get_gain_register(dev_hdl, &g_reg);
ltr390uv_get_interrupt_config_register(dev_hdl, &ic_reg);
ltr390uv_get_control_register(dev_hdl, &c_reg);
/* print device register as a binary string */
ESP_LOGI(APP_TAG, "Control Register (0x%02x): %s", c_reg.reg, uint8_to_binary(c_reg.reg));
ESP_LOGI(APP_TAG, "Measure Register (0x%02x): %s", m_reg.reg, uint8_to_binary(m_reg.reg));
ESP_LOGI(APP_TAG, "Gain Register (0x%02x): %s", g_reg.reg, uint8_to_binary(g_reg.reg));
ESP_LOGI(APP_TAG, "IRQ Cfg Register (0x%02x): %s", ic_reg.reg, uint8_to_binary(ic_reg.reg));
```
Copyright (c) 2024 Eric Gionet (<gionet.c.eric@gmail.com>)

View File

@@ -0,0 +1,16 @@
dependencies:
idf:
version: '>5.3.0'
description: ESP32 espressif IoT development framework (esp-idf) type utilities component.
license: MIT
maintainers:
- Eric Gionet <gionet.c.eric@gmail.com>
repository: https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS.git
tags:
- espidf
- esp32
targets:
- esp32
- esp32s3
url: https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/utilities/esp_type_utils
version: 1.2.5

View File

@@ -0,0 +1,396 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* @file type_utils.h
* @defgroup utilities
* @{
*
*
*
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* MIT Licensed as described in the file LICENSE
*/
#ifndef __TYPE_UTILS_H__
#define __TYPE_UTILS_H__
#include <stdint.h>
#include <stdbool.h>
#include <esp_mac.h>
#include "type_utils_version.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* type utilities definitions
*/
#define BIT8_UINT8_BUFFER_SIZE (1)
#define BIT16_UINT8_BUFFER_SIZE (2)
#define BIT24_UINT8_BUFFER_SIZE (3)
#define BIT32_UINT8_BUFFER_SIZE (4)
#define BIT40_UINT8_BUFFER_SIZE (5)
#define BIT48_UINT8_BUFFER_SIZE (6)
#define BIT56_UINT8_BUFFER_SIZE (7)
#define BIT64_UINT8_BUFFER_SIZE (8)
#define BIT72_UINT8_BUFFER_SIZE (9)
#define BIT80_UINT8_BUFFER_SIZE (10)
#define BIT88_UINT8_BUFFER_SIZE (11)
#define BIT96_UINT8_BUFFER_SIZE (12)
#define BIT104_UINT8_BUFFER_SIZE (13)
#define BIN8_CHAR_BUFFER_SIZE (8 + 1) // 8 bytes + 1 byte for null terminator
#define BIN16_CHAR_BUFFER_SIZE (16 + 1) // 16 bytes + 1 byte for null terminator
#define BIN32_CHAR_BUFFER_SIZE (32 + 1) // 32 bytes + 1 byte for null terminator
#define BIN64_CHAR_BUFFER_SIZE (64 + 1) // 64 bytes + 1 byte for null terminator
/*
* type utilities type definition declarations
*/
typedef uint8_t bit8_uint8_buffer_t[BIT8_UINT8_BUFFER_SIZE]; // 1 uint8 sized buffer
typedef uint8_t bit16_uint8_buffer_t[BIT16_UINT8_BUFFER_SIZE]; // 2 uint8 sized buffer
typedef uint8_t bit24_uint8_buffer_t[BIT24_UINT8_BUFFER_SIZE]; // 3 uint8 sized buffer
typedef uint8_t bit32_uint8_buffer_t[BIT32_UINT8_BUFFER_SIZE]; // 4 uint8 sized buffer
typedef uint8_t bit40_uint8_buffer_t[BIT40_UINT8_BUFFER_SIZE]; // 5 uint8 sized buffer
typedef uint8_t bit48_uint8_buffer_t[BIT48_UINT8_BUFFER_SIZE]; // 6 uint8 sized buffer
typedef uint8_t bit56_uint8_buffer_t[BIT56_UINT8_BUFFER_SIZE]; // 7 uint8 sized buffer
typedef uint8_t bit64_uint8_buffer_t[BIT64_UINT8_BUFFER_SIZE]; // 8 uint8 sized buffer
typedef uint8_t bit72_uint8_buffer_t[BIT72_UINT8_BUFFER_SIZE]; // 9 uint8 sized buffer
typedef uint8_t bit80_uint8_buffer_t[BIT80_UINT8_BUFFER_SIZE]; // 10 uint8 sized buffer
typedef uint8_t bit88_uint8_buffer_t[BIT88_UINT8_BUFFER_SIZE]; // 11 uint8 sized buffer
typedef uint8_t bit96_uint8_buffer_t[BIT96_UINT8_BUFFER_SIZE]; // 12 uint8 sized buffer
typedef uint8_t bit104_uint8_buffer_t[BIT104_UINT8_BUFFER_SIZE];// 13 uint8 sized buffer
typedef char bin8_char_buffer_t[BIN8_CHAR_BUFFER_SIZE]; // 9 char sized buffer (8 bytes + 1 byte for null terminator)
typedef char bin16_char_buffer_t[BIN16_CHAR_BUFFER_SIZE]; // 17 char sized buffer (16 bytes + 1 byte for null terminator)
typedef char bin32_char_buffer_t[BIN32_CHAR_BUFFER_SIZE]; // 33 char sized buffer (32 bytes + 1 byte for null terminator)
typedef char bin64_char_buffer_t[BIN64_CHAR_BUFFER_SIZE]; // 65 char sized buffer (64 bytes + 1 byte for null terminator)
/*
* type utilities enumerator and structure declarations
*/
/* 4-byte conversion to float IEEE754 (little endian) */
typedef union {
bit32_uint8_buffer_t bytes;
float value;
} bytes_to_float_t;
/* 8-byte conversion to double (little endian) */
typedef union {
bit64_uint8_buffer_t bytes;
double value;
} bytes_to_double_t;
/* 8-byte conversion to uint64_t (little endian) */
typedef union {
bit64_uint8_buffer_t bytes;
uint64_t value;
} bytes_to_uint64_t;
/* 8-byte conversion to int64_t (little endian) */
typedef union {
bit64_uint8_buffer_t bytes;
int64_t value;
} bytes_to_int64_t;
/* 4-byte conversion to uint32_t (little endian) */
typedef union {
bit32_uint8_buffer_t bytes;
uint32_t value;
} bytes_to_uint32_t;
/* 4-byte conversion to int32_t (little endian) */
typedef union {
bit32_uint8_buffer_t bytes;
int32_t value;
} bytes_to_int32_t;
/* 2-byte conversion to uint16_t (little endian) */
typedef union {
bit16_uint8_buffer_t bytes;
uint16_t value;
} bytes_to_uint16_t;
/* 2-byte conversion to int16_t (little endian) */
typedef union {
bit16_uint8_buffer_t bytes;
int16_t value;
} bytes_to_int16_t;
/*
* function and subroutine declarations
*/
/**
* @brief Generates a unique `uint32_t` chip identifier from e-fuse mac address.
*
* @note (i.e. a 32-bit integer matching the last 3 bytes of the MAC address. This is less
* unique than the MAC address chip ID, but is helpful when you need an identifier that can
* be no more than a 32-bit integer (like for switch...case
*
* @return uint32_t
*/
uint32_t get_uint32_chip_id(void);
/**
* @brief Generates a unique `uint64_t` chip identifier from e-fuse mac address.
*
* @return uint64_t Chip identifier.
*/
uint64_t get_uint64_chip_id(void);
/**
* @brief Gets the e-fuse mac address.
*
* @return uint64_t Mac address.
*/
uint64_t get_efuse_mac(void);
/**
* @brief Converts `uint8_t` type to binary as a string.
*
* @param value `uint8_t` to transform to binary string.
* @return char* binary string representation.
*/
const char* uint8_to_binary(const uint8_t value);
/**
* @brief Converts `int8_t` type to binary as a string.
*
* @param value `int8_t` to transform to binary string.
* @return char* binary string representation.
*/
const char* int8_to_binary(const int8_t value);
/**
* @brief Converts `uint16_t` type to binary as a string.
*
* @param value `uint16_t` to transform to binary string.
* @return char* binary string representation.
*/
const char* uint16_to_binary(const uint16_t value);
/**
* @brief Converts `int16_t` type to binary as a string.
*
* @param value `int16_t` to transform to binary string.
* @return char* binary string representation.
*/
const char* int16_to_binary(const int16_t value);
/**
* @brief Converts `uint32_t` type to binary as a string.
*
* @param value `uint32_t` to transform to binary string.
* @return char* binary string representation.
*/
const char* uint32_to_binary(const uint32_t value);
/**
* @brief Converts `int32_t` type to binary as a string.
*
* @param value `int32_t` to transform to binary string.
* @return char* binary string representation.
*/
const char* int32_to_binary(const int32_t value);
/**
* @brief Converts `uint64_t` type to binary as a string.
*
* @param value `uint64_t` to transform to binary string.
* @return char* binary string representation.
*/
const char* uint64_to_binary(const uint64_t value);
/**
* @brief Converts `int64_t` type to binary as a string.
*
* @param value `int64_t` to transform to binary string.
* @return char* binary string representation.
*/
const char* int64_to_binary(const int64_t value);
/**
* @brief Converts byte array to `uint16_t` data-type.
*
* @param bytes Byte array to convert to `uint16_t` data-type.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
* @return uint16_t Converted byte array as `uint16_t` data-type.
*/
uint16_t bytes_to_uint16(const uint8_t* bytes, const bool little_endian);
/**
* @brief Converts byte array to `uint32_t` data-type.
*
* @param bytes Byte array to convert to `uint32_t` data-type.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
* @return uint32_t Converted byte array as `uint32_t` data-type.
*/
uint32_t bytes_to_uint32(const uint8_t* bytes, const bool little_endian);
/**
* @brief Converts byte array to `uint64_t` data-type.
*
* @param bytes Byte array to convert to `uint64_t` data-type.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
* @return uint64_t Converted byte array as `uint64_t` data-type.
*/
uint64_t bytes_to_uint64(const uint8_t* bytes, const bool little_endian);
/**
* @brief Converts byte array to `int16_t` data-type.
*
* @param bytes Byte array to convert to `int16_t` data-type.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
* @return int16_t Converted byte array as `int16_t` data-type.
*/
int16_t bytes_to_int16(const uint8_t* bytes, const bool little_endian);
/**
* @brief Converts byte array to `int32_t` data-type.
*
* @param bytes Byte array to convert to `int32_t` data-type.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
* @return int32_t Converted byte array as `int32_t` data-type.
*/
int32_t bytes_to_int32(const uint8_t* bytes, const bool little_endian);
/**
* @brief Converts byte array to `int64_t` data-type.
*
* @param bytes Byte array to convert to `int64_t` data-type.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
* @return int64_t Converted byte array as `int64_t` data-type.
*/
int64_t bytes_to_int64(const uint8_t* bytes, const bool little_endian);
/**
* @brief Converts `uint16_t` data-type to a byte array.
*
* @param value `uint16_t` data-type to convert to byte array.
* @param bytes Converted `uint16_t` data-type as byte array.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
*/
void uint16_to_bytes(const uint16_t value, uint8_t* bytes, const bool little_endian);
/**
* @brief Converts `uint32_t` data-type to a byte array.
*
* @param value `uint32_t` data-type to convert to byte array.
* @param bytes Converted `uint32_t` data-type as byte array.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
*/
void uint32_to_bytes(const uint32_t value, uint8_t* bytes, const bool little_endian);
/**
* @brief Converts `uint64_t` data-type to a byte array.
*
* @param value `uint64_t` data-type to convert to byte array.
* @param bytes Converted `uint64_t` data-type as byte array.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
*/
void uint64_to_bytes(const uint64_t value, uint8_t* bytes, const bool little_endian);
/**
* @brief Converts `int16_t` data-type to a byte array.
*
* @param value `int16_t` data-type to convert to byte array.
* @param bytes Converted `int16_t` data-type as byte array.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
*/
void int16_to_bytes(const int16_t value, uint8_t* bytes, const bool little_endian);
/**
* @brief Converts `int32_t` data-type to a byte array.
*
* @param value `int32_t` data-type to convert to byte array.
* @param bytes Converted `int32_t` data-type as byte array.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
*/
void int32_to_bytes(const int32_t value, uint8_t* bytes, const bool little_endian);
/**
* @brief Converts `int64_t` data-type to a byte array.
*
* @param value `int64_t` data-type to convert to byte array.
* @param bytes Converted `int64_t` data-type as byte array.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
*/
void int64_to_bytes(const int64_t value, uint8_t* bytes, const bool little_endian);
/**
* @brief Converts `float` data-type to a byte array.
*
* @param value `float` data-type to convert to byte array.
* @param bytes Converted `float` data-type as byte array.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
*/
void float_to_bytes(const float value, uint8_t* bytes, const bool little_endian);
/**
* @brief Converts `double` data-type to a byte array.
*
* @param value `double` data-type to convert to byte array.
* @param bytes Converted `double` data-type as byte array.
* @param little_endian Little endian byte order when true, otherwise, big endian byte order when false.
*/
void double_to_bytes(const double value, uint8_t* bytes, const bool little_endian);
/**
* @brief Copies bytes from source byte array to destination byte array.
*
* @param source Byte array source to copy from.
* @param destination Byte array destination to copy to.
* @param size Size of destination byte array.
*/
void copy_bytes(const uint8_t* source, uint8_t* destination, const size_t size);
/**
* @brief Converts `type_utils` firmware version numbers (major, minor, patch) into a string.
*
* @return char* `type_utils` firmware version as a string that is formatted as X.X.X (e.g. 4.0.0).
*/
const char* type_utils_get_fw_version(void);
/**
* @brief Converts `type_utils` firmware version numbers (major, minor, patch) into an integer value.
*
* @return int32_t `type_utils` firmware version number.
*/
int32_t type_utils_get_fw_version_number(void);
#ifdef __cplusplus
}
#endif
/**@}*/
#endif // __TYPE_UTILS_H__

View File

@@ -0,0 +1,108 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* MIT Licensed as described in the file LICENSE
*/
#ifndef __TYPE_UTILS_FW_VERSION_H__
#define __TYPE_UTILS_FW_VERSION_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* public constant definitions
*/
#define TYPE_UTILS_COMPONENT_NAME "esp_type_utils"
/** Version release date */
#define TYPE_UTILS_FW_VERSION_DATE "2025-04-02"
/** Major version number (X.x.x) */
#define TYPE_UTILS_FW_VERSION_MAJOR 1
/** Minor version number (x.X.x) */
#define TYPE_UTILS_FW_VERSION_MINOR 2
/** Patch version number (x.x.X) */
#define TYPE_UTILS_FW_VERSION_PATCH 5
/** Semantic version number (X.X.X-X) */
#define TYPE_UTILS_FW_SEMANTIC_VERSION "1.2.5-1"
/** Git version hash */
#define TYPE_UTILS_FW_GIT_SHORT_SHA "82602db"
/**
* public macro definitions
*/
/**
* Macro to print x parameter as a string i.e. enclose x in double quotes.
*/
#define STR_QUOTES( x ) #x
/**
* Macro to create a string of x parameter with all macros fully expanded.
*/
#define STR( x ) STR_QUOTES( x )
/**
* Macro to generate current firmware version numbers (major, minor, patch) into a string that is formatted as X.X.X (e.g. 4.0.0).
*/
#define TYPE_UTILS_FW_VERSION_STR \
STR( TYPE_UTILS_FW_VERSION_MAJOR ) "." \
STR( TYPE_UTILS_FW_VERSION_MINOR ) "." \
STR( TYPE_UTILS_FW_VERSION_PATCH )
/**
* Macro to convert firmware version parameters (major, minor, patch numbers) into an integer (`int32_t`)
* value that can be used for comparison purposes.
*
* As an example, FW_VERSION_INT32 >= FW_VERSION_PARAMS_INT32(4, 0, 0).
*/
#define TYPE_UTILS_FW_VERSION_PARAMS_INT32( major, minor, patch ) \
((major << 16) | (minor << 8) | (patch))
/**
* Macro to generate current firmware version numbers (major, minor, patch) as an integer (`int32_t`) value that can
* be used for comparison purposes.
*
* As an example, FW_VERSION_INT32 >= FW_VERSION_PARAMS_INT32(4, 0, 0).
*/
#define TYPE_UTILS_FW_VERSION_INT32 \
TYPE_UTILS_FW_VERSION_PARAMS_INT32( \
TYPE_UTILS_FW_VERSION_MAJOR, \
TYPE_UTILS_FW_VERSION_MINOR, \
TYPE_UTILS_FW_VERSION_PATCH)
#ifdef __cplusplus
}
#endif
/**@}*/
#endif //__TYPE_UTILS_FW_VERSION_H__

View File

@@ -0,0 +1,22 @@
{
"name": "esp_type_utils",
"keywords": "esp32, espressif, espidf",
"description": "ESP32 espressif IoT development framework (esp-idf) type utilities component.",
"authors": [
{
"name": "Eric Gionet",
"email": "gionet.c.eric@gmail.com",
"maintainer": true
}
],
"repository": {
"type": "git",
"url": "https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/utilities/esp_type_utils"
},
"homepage": "https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS",
"version": "1.2.5",
"license": "MIT",
"frameworks": "espidf",
"platforms": "espressif32",
"headers": "type_utils.h"
}

View File

@@ -0,0 +1,399 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* @file type_utils.c
*
* ESP-IDF type utilities (utils)
*
* Ported from esp-open-rtos
*
* Copyright (c) 2024 Eric Gionet (gionet.c.eric@gmail.com)
*
* MIT Licensed as described in the file LICENSE
*/
#include "type_utils.h"
#include <string.h>
#include <stdio.h>
/*
* macro definitions
*/
/*
* static declarations
*/
/*
* static constant declarations
*/
//static const char* TAG = "type_utils";
/*
* functions and subroutines
*/
uint32_t get_uint32_chip_id(void) {
uint32_t chipid = 0L;
for (int i = 0; i < 17; i = i + 8) {
chipid |= ((get_efuse_mac() >> (40 - i)) & 0xff) << i;
}
return chipid;
}
uint64_t get_uint64_chip_id(void) {
uint64_t chipid = 0LL;
for (int i = 0; i < 63; i = i + 8) {
chipid |= ((get_efuse_mac() >> (56 - i)) & 0xff) << i;
}
return chipid;
}
uint64_t get_efuse_mac(void) {
uint64_t chipmacid = 0LL;
esp_efuse_mac_get_default((uint8_t *)(&chipmacid));
return chipmacid;
}
const char* uint8_to_binary(const uint8_t value) {
static bin8_char_buffer_t buffer;
buffer[8] = '\0';
uint8_t n = value;
for (int i = 7; i >= 0; --i) {
buffer[i] = '0' + (n & 1); // '0' or '1'
n >>= 1; // shift to the next bit
}
return buffer;
}
const char* int8_to_binary(const int8_t value) {
static bin8_char_buffer_t buffer;
buffer[8] = '\0';
int8_t n = value;
for (int i = 7; i >= 0; --i) {
buffer[i] = '0' + (n & 1); // '0' or '1'
n >>= 1; // shift to the next bit
}
return buffer;
}
const char* uint16_to_binary(const uint16_t value) {
static bin16_char_buffer_t buffer;
buffer[16] = '\0';
uint16_t n = value;
for (int i = 15; i >= 0; --i) {
buffer[i] = '0' + (n & 1); // '0' or '1'
n >>= 1; // shift to the next bit
}
return buffer;
}
const char* int16_to_binary(const int16_t value) {
static bin16_char_buffer_t buffer;
buffer[16] = '\0';
int16_t n = value;
for (int i = 15; i >= 0; --i) {
buffer[i] = '0' + (n & 1); // '0' or '1'
n >>= 1; // shift to the next bit
}
return buffer;
}
const char* uint32_to_binary(const uint32_t value) {
static bin32_char_buffer_t buffer;
buffer[32] = '\0';
uint32_t n = value;
for (int i = 31; i >= 0; --i) {
buffer[i] = '0' + (n & 1); // '0' or '1'
n >>= 1; // shift to the next bit
}
return buffer;
}
const char* int32_to_binary(const int32_t value) {
static bin32_char_buffer_t buffer;
buffer[32] = '\0';
int32_t n = value;
for (int i = 31; i >= 0; --i) {
buffer[i] = '0' + (n & 1); // '0' or '1'
n >>= 1; // shift to the next bit
}
return buffer;
}
const char* uint64_to_binary(const uint64_t value) {
static bin64_char_buffer_t buffer;
buffer[64] = '\0';
uint64_t n = value;
for (int i = 63; i >= 0; --i) {
buffer[i] = '0' + (n & 1); // '0' or '1'
n >>= 1; // shift to the next bit
}
return buffer;
}
const char* int64_to_binary(const int64_t value) {
static bin64_char_buffer_t buffer;
buffer[64] = '\0';
int64_t n = value;
for (int i = 63; i >= 0; --i) {
buffer[i] = '0' + (n & 1); // '0' or '1'
n >>= 1; // shift to the next bit
}
return buffer;
}
uint16_t bytes_to_uint16(const uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
return (uint16_t)(bytes[0] |
((uint16_t)bytes[1] << 8));
} else {
return (uint16_t)(((uint16_t)bytes[0] << 8) |
bytes[1]);
}
}
uint32_t bytes_to_uint32(const uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
return (uint32_t)bytes[0] |
((uint32_t)bytes[1] << 8) |
((uint32_t)bytes[2] << 16) |
((uint32_t)bytes[3] << 24);
} else {
return ((uint32_t)bytes[0] << 24) |
((uint32_t)bytes[1] << 16) |
((uint32_t)bytes[2] << 8) |
(uint32_t)bytes[3];
}
}
uint64_t bytes_to_uint64(const uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
return (uint64_t)bytes[0] |
((uint64_t)bytes[1] << 8) |
((uint64_t)bytes[2] << 16) |
((uint64_t)bytes[3] << 24) |
((uint64_t)bytes[4] << 32) |
((uint64_t)bytes[5] << 40) |
((uint64_t)bytes[6] << 48) |
((uint64_t)bytes[7] << 56);
} else {
return ((uint64_t)bytes[0] << 56) |
((uint64_t)bytes[1] << 48) |
((uint64_t)bytes[2] << 40) |
((uint64_t)bytes[3] << 32) |
((uint64_t)bytes[4] << 24) |
((uint64_t)bytes[5] << 16) |
((uint64_t)bytes[6] << 8) |
(uint64_t)bytes[7];
}
}
int16_t bytes_to_int16(const uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
return (int16_t)(bytes[0] |
((int16_t)bytes[1] << 8));
} else {
return (int16_t)(((int16_t)bytes[0] << 8) | bytes[1]);
}
}
int32_t bytes_to_int32(const uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
return (int32_t)bytes[0] |
((int32_t)bytes[1] << 8) |
((int32_t)bytes[2] << 16) |
((int32_t)bytes[3] << 24);
} else {
return ((int32_t)bytes[0] << 24) |
((int32_t)bytes[1] << 16) |
((int32_t)bytes[2] << 8) |
(int32_t)bytes[3];
}
}
int64_t bytes_to_int64(const uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
return (int64_t)bytes[0] |
((int64_t)bytes[1] << 8) |
((int64_t)bytes[2] << 16) |
((int64_t)bytes[3] << 24) |
((int64_t)bytes[4] << 32) |
((int64_t)bytes[5] << 40) |
((int64_t)bytes[6] << 48) |
((int64_t)bytes[7] << 56);
} else {
return ((int64_t)bytes[0] << 56) |
((int64_t)bytes[1] << 48) |
((int64_t)bytes[2] << 40) |
((int64_t)bytes[3] << 32) |
((int64_t)bytes[4] << 24) |
((int64_t)bytes[5] << 16) |
((int64_t)bytes[6] << 8) |
(int64_t)bytes[7];
}
}
void uint16_to_bytes(const uint16_t value, uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
bytes[0] = (uint8_t)(value & 0xff); // lsb
bytes[1] = (uint8_t)((value >> 8) & 0xff); // msb
} else {
bytes[0] = (uint8_t)((value >> 8) & 0xff); // msb
bytes[1] = (uint8_t)(value & 0xff); // lsb
}
}
void uint32_to_bytes(const uint32_t value, uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
bytes[0] = (uint8_t)(value & 0xff);
bytes[1] = (uint8_t)((value >> 8) & 0xff);
bytes[2] = (uint8_t)((value >> 16) & 0xff);
bytes[3] = (uint8_t)((value >> 24) & 0xff);
} else {
bytes[0] = (uint8_t)((value >> 24) & 0xff);
bytes[1] = (uint8_t)((value >> 16) & 0xff);
bytes[2] = (uint8_t)((value >> 8) & 0xff);
bytes[3] = (uint8_t)(value & 0xff);
}
}
void uint64_to_bytes(const uint64_t value, uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
bytes[0] = (uint8_t)(value & 0xff);
bytes[1] = (uint8_t)((value >> 8) & 0xff);
bytes[2] = (uint8_t)((value >> 16) & 0xff);
bytes[3] = (uint8_t)((value >> 24) & 0xff);
bytes[4] = (uint8_t)((value >> 32) & 0xff);
bytes[5] = (uint8_t)((value >> 40) & 0xff);
bytes[6] = (uint8_t)((value >> 48) & 0xff);
bytes[7] = (uint8_t)((value >> 56) & 0xff);
} else {
bytes[0] = (uint8_t)((value >> 56) & 0xff);
bytes[1] = (uint8_t)((value >> 48) & 0xff);
bytes[2] = (uint8_t)((value >> 40) & 0xff);
bytes[3] = (uint8_t)((value >> 32) & 0xff);
bytes[4] = (uint8_t)((value >> 24) & 0xff);
bytes[5] = (uint8_t)((value >> 16) & 0xff);
bytes[6] = (uint8_t)((value >> 8) & 0xff);
bytes[7] = (uint8_t)(value & 0xff);
}
}
void int16_to_bytes(const int16_t value, uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
bytes[0] = (uint8_t)(value & 0xff); // lsb
bytes[1] = (uint8_t)((value >> 8) & 0xff); // msb
} else {
bytes[0] = (uint8_t)((value >> 8) & 0xff); // msb
bytes[1] = (uint8_t)(value & 0xff); // lsb
}
}
void int32_to_bytes(const int32_t value, uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
bytes[0] = (uint8_t)(value & 0xff);
bytes[1] = (uint8_t)((value >> 8) & 0xff);
bytes[2] = (uint8_t)((value >> 16) & 0xff);
bytes[3] = (uint8_t)((value >> 24) & 0xff);
} else {
bytes[0] = (uint8_t)((value >> 24) & 0xff);
bytes[1] = (uint8_t)((value >> 16) & 0xff);
bytes[2] = (uint8_t)((value >> 8) & 0xff);
bytes[3] = (uint8_t)(value & 0xff);
}
}
void int64_to_bytes(const int64_t value, uint8_t* bytes, const bool little_endian) {
if(little_endian == true) {
bytes[0] = (uint8_t)(value & 0xff);
bytes[1] = (uint8_t)((value >> 8) & 0xff);
bytes[2] = (uint8_t)((value >> 16) & 0xff);
bytes[3] = (uint8_t)((value >> 24) & 0xff);
bytes[4] = (uint8_t)((value >> 32) & 0xff);
bytes[5] = (uint8_t)((value >> 40) & 0xff);
bytes[6] = (uint8_t)((value >> 48) & 0xff);
bytes[7] = (uint8_t)((value >> 56) & 0xff);
} else {
bytes[0] = (uint8_t)((value >> 56) & 0xff);
bytes[1] = (uint8_t)((value >> 48) & 0xff);
bytes[2] = (uint8_t)((value >> 40) & 0xff);
bytes[3] = (uint8_t)((value >> 32) & 0xff);
bytes[4] = (uint8_t)((value >> 24) & 0xff);
bytes[5] = (uint8_t)((value >> 16) & 0xff);
bytes[6] = (uint8_t)((value >> 8) & 0xff);
bytes[7] = (uint8_t)(value & 0xff);
}
}
void float_to_bytes(const float value, uint8_t* bytes, const bool little_endian) {
const union { uint32_t u32_value; float float32; } tmp = { .float32 = value };
if(little_endian == true) {
uint32_to_bytes(tmp.u32_value, bytes, true);
} else {
uint32_to_bytes(tmp.u32_value, bytes, false);
}
}
void double_to_bytes(const double value, uint8_t* bytes, const bool little_endian) {
const union { uint64_t u64_value; double double64; } tmp = { .double64 = value };
if(little_endian == true) {
uint64_to_bytes(tmp.u64_value, bytes, true);
} else {
uint64_to_bytes(tmp.u64_value, bytes, false);
}
}
void copy_bytes(const uint8_t* source, uint8_t* destination, const size_t size) {
memcpy(destination, source, size);
}
const char* type_utils_get_fw_version(void) {
return TYPE_UTILS_FW_VERSION_STR;
}
int32_t type_utils_get_fw_version_number(void) {
return TYPE_UTILS_FW_VERSION_INT32;
}