Init
This commit is contained in:
13
.devcontainer/Dockerfile
Normal file
13
.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
ARG DOCKER_TAG=latest
|
||||||
|
FROM espressif/idf:${DOCKER_TAG}
|
||||||
|
|
||||||
|
ENV LC_ALL=C.UTF-8
|
||||||
|
ENV LANG=C.UTF-8
|
||||||
|
|
||||||
|
RUN apt-get update -y && apt-get install udev -y
|
||||||
|
|
||||||
|
RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc
|
||||||
|
|
||||||
|
ENTRYPOINT [ "/opt/esp/entrypoint.sh" ]
|
||||||
|
|
||||||
|
CMD ["/bin/bash", "-c"]
|
21
.devcontainer/devcontainer.json
Normal file
21
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "ESP-IDF QEMU",
|
||||||
|
"build": {
|
||||||
|
"dockerfile": "Dockerfile"
|
||||||
|
},
|
||||||
|
"customizations": {
|
||||||
|
"vscode": {
|
||||||
|
"settings": {
|
||||||
|
"terminal.integrated.defaultProfile.linux": "bash",
|
||||||
|
"idf.espIdfPath": "/opt/esp/idf",
|
||||||
|
"idf.toolsPath": "/opt/esp",
|
||||||
|
"idf.gitPath": "/usr/bin/git"
|
||||||
|
},
|
||||||
|
"extensions": [
|
||||||
|
"espressif.esp-idf-extension",
|
||||||
|
"espressif.esp-idf-web"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"runArgs": ["--privileged"]
|
||||||
|
}
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
build/
|
||||||
|
sdkconfig
|
||||||
|
sdkconfig.old
|
23
.vscode/c_cpp_properties.json
vendored
Normal file
23
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "ESP-IDF",
|
||||||
|
"compilerPath": "${config:idf.toolsPath}/tools/xtensa-esp-elf/esp-14.2.0_20241119/xtensa-esp-elf/bin/xtensa-esp32s3-elf-gcc",
|
||||||
|
"compileCommands": "${config:idf.buildPath}/compile_commands.json",
|
||||||
|
"includePath": [
|
||||||
|
"${config:idf.espIdfPath}/components/**",
|
||||||
|
"${config:idf.espIdfPathWin}/components/**",
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"browse": {
|
||||||
|
"path": [
|
||||||
|
"${config:idf.espIdfPath}/components",
|
||||||
|
"${config:idf.espIdfPathWin}/components",
|
||||||
|
"${workspaceFolder}"
|
||||||
|
],
|
||||||
|
"limitSymbolsToIncludedHeaders": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "gdbtarget",
|
||||||
|
"request": "attach",
|
||||||
|
"name": "Eclipse CDT GDB Adapter"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "espidf",
|
||||||
|
"name": "Launch",
|
||||||
|
"request": "launch"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
33
.vscode/settings.json
vendored
Normal file
33
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"C_Cpp.intelliSenseEngine": "default",
|
||||||
|
"idf.espIdfPath": "/home/bruno/esp/master/esp-idf",
|
||||||
|
"idf.pythonInstallPath": "/usr/bin/python",
|
||||||
|
"idf.openOcdConfigs": [
|
||||||
|
"board/esp32s3-builtin.cfg"
|
||||||
|
],
|
||||||
|
"idf.port": "/dev/ttyACM0",
|
||||||
|
"idf.toolsPath": "/home/bruno/.espressif",
|
||||||
|
"idf.flashType": "JTAG",
|
||||||
|
"idf.customExtraVars": {
|
||||||
|
"OPENOCD_SCRIPTS": "/home/bruno/.espressif/tools/openocd-esp32/v0.12.0-esp32-20240821/openocd-esp32/share/openocd/scripts",
|
||||||
|
"ESP_ROM_ELF_DIR": "/home/bruno/.espressif/tools/esp-rom-elfs/20240305/",
|
||||||
|
"IDF_TARGET": "esp32s3"
|
||||||
|
},
|
||||||
|
"files.associations": {
|
||||||
|
"**/debian/*.install": "plain",
|
||||||
|
"stdio.h": "c",
|
||||||
|
"sensors.h": "c",
|
||||||
|
"freertos.h": "c",
|
||||||
|
"util.h": "c",
|
||||||
|
"i2cbrn.h": "c",
|
||||||
|
"sdkconfig.h": "c",
|
||||||
|
"esp_log.h": "c",
|
||||||
|
"bme680b.h": "c",
|
||||||
|
"mcp23018.h": "c",
|
||||||
|
"string.h": "c",
|
||||||
|
"ccs811.h": "c",
|
||||||
|
"esp_mac.h": "c",
|
||||||
|
"gpio.h": "c",
|
||||||
|
"chrono": "c"
|
||||||
|
}
|
||||||
|
}
|
9
CMakeLists.txt
Normal file
9
CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# For more information about build system see
|
||||||
|
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
|
||||||
|
# The following five lines of boilerplate have to be in your project's
|
||||||
|
# CMakeLists in this exact order for cmake to work correctly
|
||||||
|
cmake_minimum_required(VERSION 3.5)
|
||||||
|
|
||||||
|
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||||
|
|
||||||
|
project(espmain)
|
32
README.md
Normal file
32
README.md
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# _Sample project_
|
||||||
|
|
||||||
|
(See the README.md file in the upper level 'examples' directory for more information about examples.)
|
||||||
|
|
||||||
|
This is the simplest buildable example. The example is used by command `idf.py create-project`
|
||||||
|
that copies the project to user specified path and set it's name. For more information follow the [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## How to use example
|
||||||
|
We encourage the users to use the example as a template for the new projects.
|
||||||
|
A recommended way is to follow the instructions on a [docs page](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html#start-a-new-project).
|
||||||
|
|
||||||
|
## Example folder contents
|
||||||
|
|
||||||
|
The project **sample_project** contains one source file in C language [main.c](main/main.c). The file is located in folder [main](main).
|
||||||
|
|
||||||
|
ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt`
|
||||||
|
files that provide set of directives and instructions describing the project's source files and targets
|
||||||
|
(executable, library, or both).
|
||||||
|
|
||||||
|
Below is short explanation of remaining files in the project folder.
|
||||||
|
|
||||||
|
```
|
||||||
|
├── CMakeLists.txt
|
||||||
|
├── main
|
||||||
|
│ ├── CMakeLists.txt
|
||||||
|
│ └── main.c
|
||||||
|
└── README.md This is the file you are currently reading
|
||||||
|
```
|
||||||
|
Additionally, the sample project contains Makefile and component.mk files, used for the legacy Make based build system.
|
||||||
|
They are not used or needed when building with CMake and idf.py.
|
5
components/ra01s/CMakeLists.txt
Normal file
5
components/ra01s/CMakeLists.txt
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
set(component_srcs "ra01s.c")
|
||||||
|
|
||||||
|
idf_component_register(SRCS "${component_srcs}"
|
||||||
|
PRIV_REQUIRES driver
|
||||||
|
INCLUDE_DIRS ".")
|
163
components/ra01s/Kconfig.projbuild
Normal file
163
components/ra01s/Kconfig.projbuild
Normal file
@@ -0,0 +1,163 @@
|
|||||||
|
menu "SX126X Configuration"
|
||||||
|
|
||||||
|
config GPIO_RANGE_MAX
|
||||||
|
int
|
||||||
|
default 33 if IDF_TARGET_ESP32
|
||||||
|
default 46 if IDF_TARGET_ESP32S2
|
||||||
|
default 48 if IDF_TARGET_ESP32S3
|
||||||
|
default 18 if IDF_TARGET_ESP32C2
|
||||||
|
default 19 if IDF_TARGET_ESP32C3
|
||||||
|
default 30 if IDF_TARGET_ESP32C6
|
||||||
|
|
||||||
|
choice FREQUENCY
|
||||||
|
prompt "Frequency to use"
|
||||||
|
default 433MHZ
|
||||||
|
help
|
||||||
|
Select Frequency to use.
|
||||||
|
config 433MHZ
|
||||||
|
bool "433MHz"
|
||||||
|
help
|
||||||
|
Frequency is 433MHz.
|
||||||
|
config 866MHZ
|
||||||
|
bool "866MHz"
|
||||||
|
help
|
||||||
|
Frequency is 866MHz.
|
||||||
|
config 915MHZ
|
||||||
|
bool "915MHz"
|
||||||
|
help
|
||||||
|
Frequency is 915MHz.
|
||||||
|
config OTHER
|
||||||
|
bool "Other"
|
||||||
|
help
|
||||||
|
Other Frequency.
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
config OTHER_FREQUENCY
|
||||||
|
depends on OTHER
|
||||||
|
int "Frequency to use[MHz]"
|
||||||
|
range 1 999
|
||||||
|
default 433
|
||||||
|
help
|
||||||
|
Frequency to use[MHz].
|
||||||
|
|
||||||
|
config ADVANCED
|
||||||
|
bool "Enable Advanced settings"
|
||||||
|
default false
|
||||||
|
help
|
||||||
|
Enable Advanced settings.
|
||||||
|
|
||||||
|
config CODING_RATE
|
||||||
|
depends on ADVANCED
|
||||||
|
int "Error coding rate"
|
||||||
|
range 1 4
|
||||||
|
default 1
|
||||||
|
help
|
||||||
|
Error coding rate.
|
||||||
|
|
||||||
|
config BANDWIDTH
|
||||||
|
depends on ADVANCED
|
||||||
|
int "Signal Bandwidth"
|
||||||
|
range 0 6
|
||||||
|
default 4
|
||||||
|
help
|
||||||
|
Signal Bandwidth.
|
||||||
|
|
||||||
|
config SF_RATE
|
||||||
|
depends on ADVANCED
|
||||||
|
int "Spreading Factor"
|
||||||
|
range 5 12
|
||||||
|
default 7
|
||||||
|
help
|
||||||
|
Spreading Factor.
|
||||||
|
|
||||||
|
config USE_TCXO
|
||||||
|
bool "Enable TCXO"
|
||||||
|
default false
|
||||||
|
help
|
||||||
|
Enable Temperature-Compensated Crystal Oscillator.
|
||||||
|
|
||||||
|
config MISO_GPIO
|
||||||
|
int "SX126X MISO GPIO"
|
||||||
|
range 0 GPIO_RANGE_MAX
|
||||||
|
default 19 if IDF_TARGET_ESP32
|
||||||
|
default 37 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||||
|
default 4 # C3 and others
|
||||||
|
help
|
||||||
|
Pin Number to be used as the MISO SPI signal.
|
||||||
|
|
||||||
|
config SCLK_GPIO
|
||||||
|
int "SX126X SCLK GPIO"
|
||||||
|
range 0 GPIO_RANGE_MAX
|
||||||
|
default 18 if IDF_TARGET_ESP32
|
||||||
|
default 36 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||||
|
default 5 # C3 and others
|
||||||
|
help
|
||||||
|
Pin Number to be used as the SCLK SPI signal.
|
||||||
|
|
||||||
|
config MOSI_GPIO
|
||||||
|
int "SX126X MOSI GPIO"
|
||||||
|
range 0 GPIO_RANGE_MAX
|
||||||
|
default 23 if IDF_TARGET_ESP32
|
||||||
|
default 35 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||||
|
default 6 # C3 and others
|
||||||
|
help
|
||||||
|
Pin Number to be used as the MOSI SPI signal.
|
||||||
|
|
||||||
|
config NSS_GPIO
|
||||||
|
int "SX126X NSS GPIO"
|
||||||
|
range 0 GPIO_RANGE_MAX
|
||||||
|
default 15 if IDF_TARGET_ESP32
|
||||||
|
default 34 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||||
|
default 7 # C3 and others
|
||||||
|
help
|
||||||
|
Pin Number to be used as the NSS SPI signal.
|
||||||
|
|
||||||
|
config RST_GPIO
|
||||||
|
int "SX126X RST GPIO"
|
||||||
|
range 0 GPIO_RANGE_MAX
|
||||||
|
default 16 if IDF_TARGET_ESP32
|
||||||
|
default 38 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||||
|
default 2 # C3 and others
|
||||||
|
help
|
||||||
|
Pin Number to be used as the RST signal.
|
||||||
|
|
||||||
|
config BUSY_GPIO
|
||||||
|
int "SX126X BUSY GPIO"
|
||||||
|
range 0 GPIO_RANGE_MAX
|
||||||
|
default 17 if IDF_TARGET_ESP32
|
||||||
|
default 39 if IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||||
|
default 3 # C3 and others
|
||||||
|
help
|
||||||
|
Pin Number to be used as the BUSY signal.
|
||||||
|
|
||||||
|
config TXEN_GPIO
|
||||||
|
int "SX126X TXEN GPIO"
|
||||||
|
range -1 GPIO_RANGE_MAX
|
||||||
|
default -1
|
||||||
|
help
|
||||||
|
Pin Number to be used as the TXEN signal.
|
||||||
|
|
||||||
|
config RXEN_GPIO
|
||||||
|
int "SX126X RXEN GPIO"
|
||||||
|
range -1 GPIO_RANGE_MAX
|
||||||
|
default -1
|
||||||
|
help
|
||||||
|
Pin Number to be used as the RXEN signal.
|
||||||
|
|
||||||
|
choice SPI_HOST
|
||||||
|
prompt "SPI peripheral that controls this bus"
|
||||||
|
default SPI2_HOST
|
||||||
|
help
|
||||||
|
Select SPI peripheral that controls this bus.
|
||||||
|
config SPI2_HOST
|
||||||
|
bool "SPI2_HOST"
|
||||||
|
help
|
||||||
|
Use SPI2_HOST. This is also called HSPI_HOST.
|
||||||
|
config SPI3_HOST
|
||||||
|
depends on IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||||
|
bool "SPI3_HOST"
|
||||||
|
help
|
||||||
|
USE SPI3_HOST. This is also called VSPI_HOST
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
endmenu
|
1021
components/ra01s/ra01s.c
Executable file
1021
components/ra01s/ra01s.c
Executable file
File diff suppressed because it is too large
Load Diff
436
components/ra01s/ra01s.h
Executable file
436
components/ra01s/ra01s.h
Executable file
@@ -0,0 +1,436 @@
|
|||||||
|
#ifndef _RA01S_H
|
||||||
|
#define _RA01S_H
|
||||||
|
|
||||||
|
#include "driver/spi_master.h"
|
||||||
|
|
||||||
|
//return values
|
||||||
|
#define ERR_NONE 0
|
||||||
|
#define ERR_PACKET_TOO_LONG 1
|
||||||
|
#define ERR_UNKNOWN 2
|
||||||
|
#define ERR_TX_TIMEOUT 3
|
||||||
|
#define ERR_RX_TIMEOUT 4
|
||||||
|
#define ERR_CRC_MISMATCH 5
|
||||||
|
#define ERR_WRONG_MODEM 6
|
||||||
|
#define ERR_INVALID_BANDWIDTH 7
|
||||||
|
#define ERR_INVALID_SPREADING_FACTOR 8
|
||||||
|
#define ERR_INVALID_CODING_RATE 9
|
||||||
|
#define ERR_INVALID_FREQUENCY_DEVIATION 10
|
||||||
|
#define ERR_INVALID_BIT_RATE 11
|
||||||
|
#define ERR_INVALID_RX_BANDWIDTH 12
|
||||||
|
#define ERR_INVALID_DATA_SHAPING 13
|
||||||
|
#define ERR_INVALID_SYNC_WORD 14
|
||||||
|
#define ERR_INVALID_OUTPUT_POWER 15
|
||||||
|
#define ERR_INVALID_MODE 16
|
||||||
|
#define ERR_INVALID_TRANCEIVER 17
|
||||||
|
#define ERR_INVALID_SETRX_STATE 18
|
||||||
|
#define ERR_INVALID_SETTX_STATE 19
|
||||||
|
#define ERR_IDLE_TIMEOUT 20
|
||||||
|
#define ERR_SPI_TRANSACTION 21
|
||||||
|
|
||||||
|
// SX126X physical layer properties
|
||||||
|
#define XTAL_FREQ ( double )32000000
|
||||||
|
#define FREQ_DIV ( double )pow( 2.0, 25.0 )
|
||||||
|
#define FREQ_STEP ( double )( XTAL_FREQ / FREQ_DIV )
|
||||||
|
|
||||||
|
#define LOW 0
|
||||||
|
#define HIGH 1
|
||||||
|
#define BUSY_WAIT 5000
|
||||||
|
|
||||||
|
// SX126X Model
|
||||||
|
#define SX1261_TRANCEIVER 0x01
|
||||||
|
#define SX1262_TRANCEIVER 0x02
|
||||||
|
#define SX1268_TRANCEIVER 0x08
|
||||||
|
|
||||||
|
// SX126X SPI commands
|
||||||
|
// operational modes commands
|
||||||
|
#define SX126X_CMD_NOP 0x00
|
||||||
|
#define SX126X_CMD_SET_SLEEP 0x84
|
||||||
|
#define SX126X_CMD_SET_STANDBY 0x80
|
||||||
|
#define SX126X_CMD_SET_FS 0xC1
|
||||||
|
#define SX126X_CMD_SET_TX 0x83
|
||||||
|
#define SX126X_CMD_SET_RX 0x82
|
||||||
|
#define SX126X_CMD_STOP_TIMER_ON_PREAMBLE 0x9F
|
||||||
|
#define SX126X_CMD_SET_RX_DUTY_CYCLE 0x94
|
||||||
|
#define SX126X_CMD_SET_CAD 0xC5
|
||||||
|
#define SX126X_CMD_SET_TX_CONTINUOUS_WAVE 0xD1
|
||||||
|
#define SX126X_CMD_SET_TX_INFINITE_PREAMBLE 0xD2
|
||||||
|
#define SX126X_CMD_SET_REGULATOR_MODE 0x96
|
||||||
|
#define SX126X_CMD_CALIBRATE 0x89
|
||||||
|
#define SX126X_CMD_CALIBRATE_IMAGE 0x98
|
||||||
|
#define SX126X_CMD_SET_PA_CONFIG 0x95
|
||||||
|
#define SX126X_CMD_SET_RX_TX_FALLBACK_MODE 0x93
|
||||||
|
|
||||||
|
// register and buffer access commands
|
||||||
|
#define SX126X_CMD_WRITE_REGISTER 0x0D
|
||||||
|
#define SX126X_CMD_READ_REGISTER 0x1D
|
||||||
|
#define SX126X_CMD_WRITE_BUFFER 0x0E
|
||||||
|
#define SX126X_CMD_READ_BUFFER 0x1E
|
||||||
|
|
||||||
|
// DIO and IRQ control
|
||||||
|
#define SX126X_CMD_SET_DIO_IRQ_PARAMS 0x08
|
||||||
|
#define SX126X_CMD_GET_IRQ_STATUS 0x12
|
||||||
|
#define SX126X_CMD_CLEAR_IRQ_STATUS 0x02
|
||||||
|
#define SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL 0x9D
|
||||||
|
#define SX126X_CMD_SET_DIO3_AS_TCXO_CTRL 0x97
|
||||||
|
|
||||||
|
// RF, modulation and packet commands
|
||||||
|
#define SX126X_CMD_SET_RF_FREQUENCY 0x86
|
||||||
|
#define SX126X_CMD_SET_PACKET_TYPE 0x8A
|
||||||
|
#define SX126X_CMD_GET_PACKET_TYPE 0x11
|
||||||
|
#define SX126X_CMD_SET_TX_PARAMS 0x8E
|
||||||
|
#define SX126X_CMD_SET_MODULATION_PARAMS 0x8B
|
||||||
|
#define SX126X_CMD_SET_PACKET_PARAMS 0x8C
|
||||||
|
#define SX126X_CMD_SET_CAD_PARAMS 0x88
|
||||||
|
#define SX126X_CMD_SET_BUFFER_BASE_ADDRESS 0x8F
|
||||||
|
#define SX126X_CMD_SET_LORA_SYMB_NUM_TIMEOUT 0xA0
|
||||||
|
|
||||||
|
#define SX126X_PA_CONFIG_SX1261 0x01
|
||||||
|
#define SX126X_PA_CONFIG_SX1262 0x00
|
||||||
|
|
||||||
|
// status commands
|
||||||
|
#define SX126X_CMD_GET_STATUS 0xC0
|
||||||
|
#define SX126X_CMD_GET_RSSI_INST 0x15
|
||||||
|
#define SX126X_CMD_GET_RX_BUFFER_STATUS 0x13
|
||||||
|
#define SX126X_CMD_GET_PACKET_STATUS 0x14
|
||||||
|
#define SX126X_CMD_GET_DEVICE_ERRORS 0x17
|
||||||
|
#define SX126X_CMD_CLEAR_DEVICE_ERRORS 0x07
|
||||||
|
#define SX126X_CMD_GET_STATS 0x10
|
||||||
|
#define SX126X_CMD_RESET_STATS 0x00
|
||||||
|
|
||||||
|
|
||||||
|
// SX126X register map
|
||||||
|
#define SX126X_REG_HOPPING_ENABLE 0x0385
|
||||||
|
#define SX126X_REG_PACKECT_LENGTH 0x0386
|
||||||
|
#define SX126X_REG_NB_HOPPING_BLOCKS 0x0387
|
||||||
|
#define SX126X_REG_NB_SYMBOLS0 0x0388
|
||||||
|
#define SX126X_REG_FREQ0 0x038A
|
||||||
|
#define SX126X_REG_NB_SYMBOLS15 0x03E2
|
||||||
|
#define SX126X_REG_FREQ15 0x03E4
|
||||||
|
#define SX126X_REG_DIOX_OUTPUT_ENABLE 0x0580
|
||||||
|
#define SX126X_REG_DIOX_INPUT_ENABLE 0x0583
|
||||||
|
#define SX126X_REG_DIOX_PILL_UP_CONTROL 0x0584
|
||||||
|
#define SX126X_REG_DIOX_PULL_DOWN_CONTROL 0x0585
|
||||||
|
#define SX126X_REG_WHITENING_INITIAL_MSB 0x06B8
|
||||||
|
#define SX126X_REG_WHITENING_INITIAL_LSB 0x06B9
|
||||||
|
#define SX126X_REG_CRC_INITIAL_MSB 0x06BC
|
||||||
|
#define SX126X_REG_CRC_INITIAL_LSB 0x06BD
|
||||||
|
#define SX126X_REG_CRC_POLYNOMIAL_MSB 0x06BE
|
||||||
|
#define SX126X_REG_CRC_POLYNOMIAL_LSB 0x06BF
|
||||||
|
#define SX126X_REG_SYNC_WORD_0 0x06C0
|
||||||
|
#define SX126X_REG_SYNC_WORD_1 0x06C1
|
||||||
|
#define SX126X_REG_SYNC_WORD_2 0x06C2
|
||||||
|
#define SX126X_REG_SYNC_WORD_3 0x06C3
|
||||||
|
#define SX126X_REG_SYNC_WORD_4 0x06C4
|
||||||
|
#define SX126X_REG_SYNC_WORD_5 0x06C5
|
||||||
|
#define SX126X_REG_SYNC_WORD_6 0x06C6
|
||||||
|
#define SX126X_REG_SYNC_WORD_7 0x06C7
|
||||||
|
#define SX126X_REG_NODE_ADDRESS 0x06CD
|
||||||
|
#define SX126X_REG_BROADCAST_ADDRESS 0x06CE
|
||||||
|
#define SX126X_REG_IQ_POLARITY_SETUP 0x0736
|
||||||
|
#define SX126X_REG_LORA_SYNC_WORD_MSB 0x0740
|
||||||
|
#define SX126X_REG_LORA_SYNC_WORD_LSB 0x0741
|
||||||
|
#define SX126X_REG_RANDOM_NUMBER_0 0x0819
|
||||||
|
#define SX126X_REG_RANDOM_NUMBER_1 0x081A
|
||||||
|
#define SX126X_REG_RANDOM_NUMBER_2 0x081B
|
||||||
|
#define SX126X_REG_RANDOM_NUMBER_3 0x081C
|
||||||
|
#define SX126X_REG_TX_MODULETION 0x0889
|
||||||
|
#define SX126X_REG_RX_GAIN 0x08AC
|
||||||
|
#define SX126X_REG_TX_CLAMP_CONFIG 0x08D8
|
||||||
|
#define SX126X_REG_OCP_CONFIGURATION 0x08E7
|
||||||
|
#define SX126X_REG_RTC_CONTROL 0x0902
|
||||||
|
#define SX126X_REG_XTA_TRIM 0x0911
|
||||||
|
#define SX126X_REG_XTB_TRIM 0x0912
|
||||||
|
#define SX126X_REG_DIO3_OUTPUT_VOLTAGE_CONTROL 0x0920
|
||||||
|
#define SX126X_REG_EVENT_MASK 0x0944
|
||||||
|
|
||||||
|
|
||||||
|
// SX126X SPI command variables
|
||||||
|
//SX126X_CMD_SET_SLEEP
|
||||||
|
#define SX126X_SLEEP_START_COLD 0b00000000 // 2 2 sleep mode: cold start, configuration is lost (default)
|
||||||
|
#define SX126X_SLEEP_START_WARM 0b00000100 // 2 2 warm start, configuration is retained
|
||||||
|
#define SX126X_SLEEP_RTC_OFF 0b00000000 // 0 0 wake on RTC timeout: disabled
|
||||||
|
#define SX126X_SLEEP_RTC_ON 0b00000001 // 0 0 enabled
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_STANDBY
|
||||||
|
#define SX126X_STANDBY_RC 0x00 // 7 0 standby mode: 13 MHz RC oscillator
|
||||||
|
#define SX126X_STANDBY_XOSC 0x01 // 7 0 32 MHz crystal oscillator
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_RX
|
||||||
|
#define SX126X_RX_TIMEOUT_NONE 0x000000 // 23 0 Rx timeout duration: no timeout (Rx single mode)
|
||||||
|
#define SX126X_RX_TIMEOUT_INF 0xFFFFFF // 23 0 infinite (Rx continuous mode)
|
||||||
|
|
||||||
|
//SX126X_CMD_STOP_TIMER_ON_PREAMBLE
|
||||||
|
#define SX126X_STOP_ON_PREAMBLE_OFF 0x00 // 7 0 stop timer on: sync word or header (default)
|
||||||
|
#define SX126X_STOP_ON_PREAMBLE_ON 0x01 // 7 0 preamble detection
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_REGULATOR_MODE
|
||||||
|
#define SX126X_REGULATOR_LDO 0x00 // 7 0 set regulator mode: LDO (default)
|
||||||
|
#define SX126X_REGULATOR_DC_DC 0x01 // 7 0 DC-DC
|
||||||
|
|
||||||
|
//SX126X_CMD_CALIBRATE
|
||||||
|
#define SX126X_CALIBRATE_IMAGE_OFF 0b00000000 // 6 6 image calibration: disabled
|
||||||
|
#define SX126X_CALIBRATE_IMAGE_ON 0b01000000 // 6 6 enabled
|
||||||
|
#define SX126X_CALIBRATE_ADC_BULK_P_OFF 0b00000000 // 5 5 ADC bulk P calibration: disabled
|
||||||
|
#define SX126X_CALIBRATE_ADC_BULK_P_ON 0b00100000 // 5 5 enabled
|
||||||
|
#define SX126X_CALIBRATE_ADC_BULK_N_OFF 0b00000000 // 4 4 ADC bulk N calibration: disabled
|
||||||
|
#define SX126X_CALIBRATE_ADC_BULK_N_ON 0b00010000 // 4 4 enabled
|
||||||
|
#define SX126X_CALIBRATE_ADC_PULSE_OFF 0b00000000 // 3 3 ADC pulse calibration: disabled
|
||||||
|
#define SX126X_CALIBRATE_ADC_PULSE_ON 0b00001000 // 3 3 enabled
|
||||||
|
#define SX126X_CALIBRATE_PLL_OFF 0b00000000 // 2 2 PLL calibration: disabled
|
||||||
|
#define SX126X_CALIBRATE_PLL_ON 0b00000100 // 2 2 enabled
|
||||||
|
#define SX126X_CALIBRATE_RC13M_OFF 0b00000000 // 1 1 13 MHz RC osc. calibration: disabled
|
||||||
|
#define SX126X_CALIBRATE_RC13M_ON 0b00000010 // 1 1 enabled
|
||||||
|
#define SX126X_CALIBRATE_RC64K_OFF 0b00000000 // 0 0 64 kHz RC osc. calibration: disabled
|
||||||
|
#define SX126X_CALIBRATE_RC64K_ON 0b00000001 // 0 0 enabled
|
||||||
|
|
||||||
|
//SX126X_CMD_CALIBRATE_IMAGE
|
||||||
|
#define SX126X_CAL_IMG_430_MHZ_1 0x6B
|
||||||
|
#define SX126X_CAL_IMG_430_MHZ_2 0x6F
|
||||||
|
#define SX126X_CAL_IMG_470_MHZ_1 0x75
|
||||||
|
#define SX126X_CAL_IMG_470_MHZ_2 0x81
|
||||||
|
#define SX126X_CAL_IMG_779_MHZ_1 0xC1
|
||||||
|
#define SX126X_CAL_IMG_779_MHZ_2 0xC5
|
||||||
|
#define SX126X_CAL_IMG_863_MHZ_1 0xD7
|
||||||
|
#define SX126X_CAL_IMG_863_MHZ_2 0xDB
|
||||||
|
#define SX126X_CAL_IMG_902_MHZ_1 0xE1
|
||||||
|
#define SX126X_CAL_IMG_902_MHZ_2 0xE9
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_PA_CONFIG
|
||||||
|
#define SX126X_PA_CONFIG_HP_MAX 0x07
|
||||||
|
#define SX126X_PA_CONFIG_SX1268 0x01
|
||||||
|
#define SX126X_PA_CONFIG_PA_LUT 0x01
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_RX_TX_FALLBACK_MODE
|
||||||
|
#define SX126X_RX_TX_FALLBACK_MODE_FS 0x40 // 7 0 after Rx/Tx go to: FS mode
|
||||||
|
#define SX126X_RX_TX_FALLBACK_MODE_STDBY_XOSC 0x30 // 7 0 standby with crystal oscillator
|
||||||
|
#define SX126X_RX_TX_FALLBACK_MODE_STDBY_RC 0x20 // 7 0 standby with RC oscillator (default)
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_DIO_IRQ_PARAMS
|
||||||
|
#define SX126X_IRQ_TIMEOUT 0b1000000000 // 9 9 Rx or Tx timeout
|
||||||
|
#define SX126X_IRQ_CAD_DETECTED 0b0100000000 // 8 8 channel activity detected
|
||||||
|
#define SX126X_IRQ_CAD_DONE 0b0010000000 // 7 7 channel activity detection finished
|
||||||
|
#define SX126X_IRQ_CRC_ERR 0b0001000000 // 6 6 wrong CRC received
|
||||||
|
#define SX126X_IRQ_HEADER_ERR 0b0000100000 // 5 5 LoRa header CRC error
|
||||||
|
#define SX126X_IRQ_HEADER_VALID 0b0000010000 // 4 4 valid LoRa header received
|
||||||
|
#define SX126X_IRQ_SYNC_WORD_VALID 0b0000001000 // 3 3 valid sync word detected
|
||||||
|
#define SX126X_IRQ_PREAMBLE_DETECTED 0b0000000100 // 2 2 preamble detected
|
||||||
|
#define SX126X_IRQ_RX_DONE 0b0000000010 // 1 1 packet received
|
||||||
|
#define SX126X_IRQ_TX_DONE 0b0000000001 // 0 0 packet transmission completed
|
||||||
|
#define SX126X_IRQ_ALL 0b1111111111 // 9 0 all interrupts
|
||||||
|
#define SX126X_IRQ_NONE 0b0000000000 // 9 0 no interrupts
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_DIO2_AS_RF_SWITCH_CTRL
|
||||||
|
#define SX126X_DIO2_AS_IRQ 0x00 // 7 0 DIO2 configuration: IRQ
|
||||||
|
#define SX126X_DIO2_AS_RF_SWITCH 0x01 // 7 0 RF switch control
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_DIO3_AS_TCXO_CTRL
|
||||||
|
#define SX126X_DIO3_OUTPUT_1_6 0x00 // 7 0 DIO3 voltage output for TCXO: 1.6 V
|
||||||
|
#define SX126X_DIO3_OUTPUT_1_7 0x01 // 7 0 1.7 V
|
||||||
|
#define SX126X_DIO3_OUTPUT_1_8 0x02 // 7 0 1.8 V
|
||||||
|
#define SX126X_DIO3_OUTPUT_2_2 0x03 // 7 0 2.2 V
|
||||||
|
#define SX126X_DIO3_OUTPUT_2_4 0x04 // 7 0 2.4 V
|
||||||
|
#define SX126X_DIO3_OUTPUT_2_7 0x05 // 7 0 2.7 V
|
||||||
|
#define SX126X_DIO3_OUTPUT_3_0 0x06 // 7 0 3.0 V
|
||||||
|
#define SX126X_DIO3_OUTPUT_3_3 0x07 // 7 0 3.3 V
|
||||||
|
|
||||||
|
//Radio complete Wake-up Time with TCXO stabilisation time
|
||||||
|
#define RADIO_TCXO_SETUP_TIME 5000 // [us]
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_PACKET_TYPE
|
||||||
|
#define SX126X_PACKET_TYPE_GFSK 0x00 // 7 0 packet type: GFSK
|
||||||
|
#define SX126X_PACKET_TYPE_LORA 0x01 // 7 0 LoRa
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_TX_PARAMS
|
||||||
|
#define SX126X_PA_RAMP_10U 0x00 // 7 0 ramp time: 10 us
|
||||||
|
#define SX126X_PA_RAMP_20U 0x01 // 7 0 20 us
|
||||||
|
#define SX126X_PA_RAMP_40U 0x02 // 7 0 40 us
|
||||||
|
#define SX126X_PA_RAMP_80U 0x03 // 7 0 80 us
|
||||||
|
#define SX126X_PA_RAMP_200U 0x04 // 7 0 200 us
|
||||||
|
#define SX126X_PA_RAMP_800U 0x05 // 7 0 800 us
|
||||||
|
#define SX126X_PA_RAMP_1700U 0x06 // 7 0 1700 us
|
||||||
|
#define SX126X_PA_RAMP_3400U 0x07 // 7 0 3400 us
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_MODULATION_PARAMS
|
||||||
|
#define SX126X_GFSK_FILTER_NONE 0x00 // 7 0 GFSK filter: none
|
||||||
|
#define SX126X_GFSK_FILTER_GAUSS_0_3 0x08 // 7 0 Gaussian, BT = 0.3
|
||||||
|
#define SX126X_GFSK_FILTER_GAUSS_0_5 0x09 // 7 0 Gaussian, BT = 0.5
|
||||||
|
#define SX126X_GFSK_FILTER_GAUSS_0_7 0x0A // 7 0 Gaussian, BT = 0.7
|
||||||
|
#define SX126X_GFSK_FILTER_GAUSS_1 0x0B // 7 0 Gaussian, BT = 1
|
||||||
|
#define SX126X_GFSK_RX_BW_4_8 0x1F // 7 0 GFSK Rx bandwidth: 4.8 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_5_8 0x17 // 7 0 5.8 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_7_3 0x0F // 7 0 7.3 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_9_7 0x1E // 7 0 9.7 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_11_7 0x16 // 7 0 11.7 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_14_6 0x0E // 7 0 14.6 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_19_5 0x1D // 7 0 19.5 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_23_4 0x15 // 7 0 23.4 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_29_3 0x0D // 7 0 29.3 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_39_0 0x1C // 7 0 39.0 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_46_9 0x14 // 7 0 46.9 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_58_6 0x0C // 7 0 58.6 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_78_2 0x1B // 7 0 78.2 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_93_8 0x13 // 7 0 93.8 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_117_3 0x0B // 7 0 117.3 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_156_2 0x1A // 7 0 156.2 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_187_2 0x12 // 7 0 187.2 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_234_3 0x0A // 7 0 234.3 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_312_0 0x19 // 7 0 312.0 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_373_6 0x11 // 7 0 373.6 kHz
|
||||||
|
#define SX126X_GFSK_RX_BW_467_0 0x09 // 7 0 467.0 kHz
|
||||||
|
#define SX126X_LORA_BW_7_8 0x00 // 7 0 LoRa bandwidth: 7.8 kHz
|
||||||
|
#define SX126X_LORA_BW_10_4 0x08 // 7 0 10.4 kHz
|
||||||
|
#define SX126X_LORA_BW_15_6 0x01 // 7 0 15.6 kHz
|
||||||
|
#define SX126X_LORA_BW_20_8 0x09 // 7 0 20.8 kHz
|
||||||
|
#define SX126X_LORA_BW_31_25 0x02 // 7 0 31.25 kHz
|
||||||
|
#define SX126X_LORA_BW_41_7 0x0A // 7 0 41.7 kHz
|
||||||
|
#define SX126X_LORA_BW_62_5 0x03 // 7 0 62.5 kHz
|
||||||
|
#define SX126X_LORA_BW_125_0 0x04 // 7 0 125.0 kHz
|
||||||
|
#define SX126X_LORA_BW_250_0 0x05 // 7 0 250.0 kHz
|
||||||
|
#define SX126X_LORA_BW_500_0 0x06 // 7 0 500.0 kHz
|
||||||
|
#define SX126X_LORA_CR_4_5 0x01 // 7 0 LoRa coding rate: 4/5
|
||||||
|
#define SX126X_LORA_CR_4_6 0x02 // 7 0 4/6
|
||||||
|
#define SX126X_LORA_CR_4_7 0x03 // 7 0 4/7
|
||||||
|
#define SX126X_LORA_CR_4_8 0x04 // 7 0 4/8
|
||||||
|
#define SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_OFF 0x00 // 7 0 LoRa low data rate optimization: disabled
|
||||||
|
#define SX126X_LORA_LOW_DATA_RATE_OPTIMIZE_ON 0x01 // 7 0 enabled
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_PACKET_PARAMS
|
||||||
|
#define SX126X_GFSK_PREAMBLE_DETECT_OFF 0x00 // 7 0 GFSK minimum preamble length before reception starts: detector disabled
|
||||||
|
#define SX126X_GFSK_PREAMBLE_DETECT_8 0x04 // 7 0 8 bits
|
||||||
|
#define SX126X_GFSK_PREAMBLE_DETECT_16 0x05 // 7 0 16 bits
|
||||||
|
#define SX126X_GFSK_PREAMBLE_DETECT_24 0x06 // 7 0 24 bits
|
||||||
|
#define SX126X_GFSK_PREAMBLE_DETECT_32 0x07 // 7 0 32 bits
|
||||||
|
#define SX126X_GFSK_ADDRESS_FILT_OFF 0x00 // 7 0 GFSK address filtering: disabled
|
||||||
|
#define SX126X_GFSK_ADDRESS_FILT_NODE 0x01 // 7 0 node only
|
||||||
|
#define SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST 0x02 // 7 0 node and broadcast
|
||||||
|
#define SX126X_GFSK_PACKET_FIXED 0x00 // 7 0 GFSK packet type: fixed (payload length known in advance to both sides)
|
||||||
|
#define SX126X_GFSK_PACKET_VARIABLE 0x01 // 7 0 variable (payload length added to packet)
|
||||||
|
#define SX126X_GFSK_CRC_OFF 0x01 // 7 0 GFSK packet CRC: disabled
|
||||||
|
#define SX126X_GFSK_CRC_1_BYTE 0x00 // 7 0 1 byte
|
||||||
|
#define SX126X_GFSK_CRC_2_BYTE 0x02 // 7 0 2 byte
|
||||||
|
#define SX126X_GFSK_CRC_1_BYTE_INV 0x04 // 7 0 1 byte, inverted
|
||||||
|
#define SX126X_GFSK_CRC_2_BYTE_INV 0x06 // 7 0 2 byte, inverted
|
||||||
|
#define SX126X_GFSK_WHITENING_OFF 0x00 // 7 0 GFSK data whitening: disabled
|
||||||
|
#define SX126X_GFSK_WHITENING_ON 0x01 // 7 0 enabled
|
||||||
|
#define SX126X_LORA_HEADER_EXPLICIT 0x00 // 7 0 LoRa header mode: explicit
|
||||||
|
#define SX126X_LORA_HEADER_IMPLICIT 0x01 // 7 0 implicit
|
||||||
|
#define SX126X_LORA_CRC_OFF 0x00 // 7 0 LoRa CRC mode: disabled
|
||||||
|
#define SX126X_LORA_CRC_ON 0x01 // 7 0 enabled
|
||||||
|
#define SX126X_LORA_IQ_STANDARD 0x00 // 7 0 LoRa IQ setup: standard
|
||||||
|
#define SX126X_LORA_IQ_INVERTED 0x01 // 7 0 inverted
|
||||||
|
|
||||||
|
//SX126X_CMD_SET_CAD_PARAMS
|
||||||
|
#define SX126X_CAD_ON_1_SYMB 0x00 // 7 0 number of symbols used for CAD: 1
|
||||||
|
#define SX126X_CAD_ON_2_SYMB 0x01 // 7 0 2
|
||||||
|
#define SX126X_CAD_ON_4_SYMB 0x02 // 7 0 4
|
||||||
|
#define SX126X_CAD_ON_8_SYMB 0x03 // 7 0 8
|
||||||
|
#define SX126X_CAD_ON_16_SYMB 0x04 // 7 0 16
|
||||||
|
#define SX126X_CAD_GOTO_STDBY 0x00 // 7 0 after CAD is done, always go to STDBY_RC mode
|
||||||
|
#define SX126X_CAD_GOTO_RX 0x01 // 7 0 after CAD is done, go to Rx mode if activity is detected
|
||||||
|
|
||||||
|
//SX126X_CMD_GET_STATUS
|
||||||
|
#define SX126X_STATUS_MODE_STDBY_RC 0b00100000 // 6 4 current chip mode: STDBY_RC
|
||||||
|
#define SX126X_STATUS_MODE_STDBY_XOSC 0b00110000 // 6 4 STDBY_XOSC
|
||||||
|
#define SX126X_STATUS_MODE_FS 0b01000000 // 6 4 FS
|
||||||
|
#define SX126X_STATUS_MODE_RX 0b01010000 // 6 4 RX
|
||||||
|
#define SX126X_STATUS_MODE_TX 0b01100000 // 6 4 TX
|
||||||
|
#define SX126X_STATUS_DATA_AVAILABLE 0b00000100 // 3 1 command status: packet received and data can be retrieved
|
||||||
|
#define SX126X_STATUS_CMD_TIMEOUT 0b00000110 // 3 1 SPI command timed out
|
||||||
|
#define SX126X_STATUS_CMD_INVALID 0b00001000 // 3 1 invalid SPI command
|
||||||
|
#define SX126X_STATUS_CMD_FAILED 0b00001010 // 3 1 SPI command failed to execute
|
||||||
|
#define SX126X_STATUS_TX_DONE 0b00001100 // 3 1 packet transmission done
|
||||||
|
#define SX126X_STATUS_SPI_FAILED 0b11111111 // 7 0 SPI transaction failed
|
||||||
|
|
||||||
|
//SX126X_CMD_GET_PACKET_STATUS
|
||||||
|
#define SX126X_GFSK_RX_STATUS_PREAMBLE_ERR 0b10000000 // 7 7 GFSK Rx status: preamble error
|
||||||
|
#define SX126X_GFSK_RX_STATUS_SYNC_ERR 0b01000000 // 6 6 sync word error
|
||||||
|
#define SX126X_GFSK_RX_STATUS_ADRS_ERR 0b00100000 // 5 5 address error
|
||||||
|
#define SX126X_GFSK_RX_STATUS_CRC_ERR 0b00010000 // 4 4 CRC error
|
||||||
|
#define SX126X_GFSK_RX_STATUS_LENGTH_ERR 0b00001000 // 3 3 length error
|
||||||
|
#define SX126X_GFSK_RX_STATUS_ABORT_ERR 0b00000100 // 2 2 abort error
|
||||||
|
#define SX126X_GFSK_RX_STATUS_PACKET_RECEIVED 0b00000010 // 2 2 packet received
|
||||||
|
#define SX126X_GFSK_RX_STATUS_PACKET_SENT 0b00000001 // 2 2 packet sent
|
||||||
|
|
||||||
|
//SX126X_CMD_GET_DEVICE_ERRORS
|
||||||
|
#define SX126X_PA_RAMP_ERR 0b100000000 // 8 8 device errors: PA ramping failed
|
||||||
|
#define SX126X_PLL_LOCK_ERR 0b001000000 // 6 6 PLL failed to lock
|
||||||
|
#define SX126X_XOSC_START_ERR 0b000100000 // 5 5 crystal oscillator failed to start
|
||||||
|
#define SX126X_IMG_CALIB_ERR 0b000010000 // 4 4 image calibration failed
|
||||||
|
#define SX126X_ADC_CALIB_ERR 0b000001000 // 3 3 ADC calibration failed
|
||||||
|
#define SX126X_PLL_CALIB_ERR 0b000000100 // 2 2 PLL calibration failed
|
||||||
|
#define SX126X_RC13M_CALIB_ERR 0b000000010 // 1 1 RC13M calibration failed
|
||||||
|
#define SX126X_RC64K_CALIB_ERR 0b000000001 // 0 0 RC64K calibration failed
|
||||||
|
|
||||||
|
|
||||||
|
// SX126X SPI register variables
|
||||||
|
//SX126X_REG_LORA_SYNC_WORD_MSB + LSB
|
||||||
|
#define SX126X_SYNC_WORD_PUBLIC 0x3444
|
||||||
|
#define SX126X_SYNC_WORD_PRIVATE 0x1424
|
||||||
|
|
||||||
|
#define SX126x_TXMODE_ASYNC 0x01
|
||||||
|
#define SX126x_TXMODE_SYNC 0x02
|
||||||
|
#define SX126x_TXMODE_BACK2RX 0x04
|
||||||
|
|
||||||
|
// Public function
|
||||||
|
void LoRaInit(void);
|
||||||
|
int16_t LoRaBegin(uint32_t frequencyInHz, int8_t txPowerInDbm, float tcxoVoltage, bool useRegulatorLDO);
|
||||||
|
void LoRaConfig(uint8_t spreadingFactor, uint8_t bandwidth, uint8_t codingRate, uint16_t preambleLength, uint8_t payloadLen, bool crcOn, bool invertIrq);
|
||||||
|
uint8_t LoRaReceive(uint8_t *pData, int16_t len);
|
||||||
|
bool LoRaSend(uint8_t *pData, int16_t len, uint8_t mode);
|
||||||
|
void LoRaDebugPrint(bool enable);
|
||||||
|
|
||||||
|
// Private function
|
||||||
|
void spi_write_byte(uint8_t* Dataout, size_t DataLength );
|
||||||
|
void spi_read_byte(uint8_t* Datain, uint8_t* Dataout, size_t DataLength );
|
||||||
|
uint8_t spi_transfer(uint8_t address);
|
||||||
|
|
||||||
|
bool ReceiveMode(void);
|
||||||
|
void GetPacketStatus(int8_t *rssiPacket, int8_t *snrPacket);
|
||||||
|
void SetTxPower(int8_t txPowerInDbm);
|
||||||
|
|
||||||
|
void FixInvertedIQ(uint8_t iqConfig);
|
||||||
|
void SetDio3AsTcxoCtrl(float voltage, uint32_t delay);
|
||||||
|
void SetDio2AsRfSwitchCtrl(uint8_t enable);
|
||||||
|
void Reset(void);
|
||||||
|
void SetStandby(uint8_t mode);
|
||||||
|
void SetRfFrequency(uint32_t frequency);
|
||||||
|
void Calibrate(uint8_t calibParam);
|
||||||
|
void CalibrateImage(uint32_t frequency);
|
||||||
|
void SetRegulatorMode(uint8_t mode);
|
||||||
|
void SetBufferBaseAddress(uint8_t txBaseAddress, uint8_t rxBaseAddress);
|
||||||
|
void SetPowerConfig(int8_t power, uint8_t rampTime);
|
||||||
|
void SetOvercurrentProtection(float currentLimit);
|
||||||
|
void SetSyncWord(int16_t sync);
|
||||||
|
void SetPaConfig(uint8_t paDutyCycle, uint8_t hpMax, uint8_t deviceSel, uint8_t paLut);
|
||||||
|
void SetDioIrqParams(uint16_t irqMask, uint16_t dio1Mask, uint16_t dio2Mask, uint16_t dio3Mask);
|
||||||
|
void SetStopRxTimerOnPreambleDetect(bool enable);
|
||||||
|
void SetLoRaSymbNumTimeout(uint8_t SymbNum);
|
||||||
|
void SetPacketType(uint8_t packetType);
|
||||||
|
void SetModulationParams(uint8_t spreadingFactor, uint8_t bandwidth, uint8_t codingRate, uint8_t lowDataRateOptimize);
|
||||||
|
void SetCadParams(uint8_t cadSymbolNum, uint8_t cadDetPeak, uint8_t cadDetMin, uint8_t cadExitMode, uint32_t cadTimeout);
|
||||||
|
void SetCad();
|
||||||
|
uint8_t GetStatus(void);
|
||||||
|
uint16_t GetIrqStatus(void);
|
||||||
|
void ClearIrqStatus(uint16_t irq);
|
||||||
|
void SetTxEnable(void);
|
||||||
|
void SetRxEnable(void);
|
||||||
|
void SetRx(uint32_t timeout);
|
||||||
|
void SetTx(uint32_t timeoutInMs);
|
||||||
|
int GetPacketLost();
|
||||||
|
uint8_t GetRssiInst();
|
||||||
|
void GetRxBufferStatus(uint8_t *payloadLength, uint8_t *rxStartBufferPointer);
|
||||||
|
void Wakeup(void);
|
||||||
|
void WaitForIdleBegin(unsigned long timeout, char *text);
|
||||||
|
bool WaitForIdle(unsigned long timeout, char *text, bool stop);
|
||||||
|
uint8_t ReadBuffer(uint8_t *rxData, int16_t rxDataLen);
|
||||||
|
void WriteBuffer(uint8_t *txData, int16_t txDataLen);
|
||||||
|
void WriteRegister(uint16_t reg, uint8_t* data, uint8_t numBytes);
|
||||||
|
void ReadRegister(uint16_t reg, uint8_t* data, uint8_t numBytes);
|
||||||
|
void WriteCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes);
|
||||||
|
uint8_t WriteCommand2(uint8_t cmd, uint8_t* data, uint8_t numBytes);
|
||||||
|
void ReadCommand(uint8_t cmd, uint8_t* data, uint8_t numBytes);
|
||||||
|
void SPItransfer(uint8_t cmd, bool write, uint8_t* dataOut, uint8_t* dataIn, uint8_t numBytes, bool waitForBusy);
|
||||||
|
void LoRaError(int error);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
38
dependencies.lock
Normal file
38
dependencies.lock
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
dependencies:
|
||||||
|
idf:
|
||||||
|
source:
|
||||||
|
type: idf
|
||||||
|
version: 5.5.0
|
||||||
|
k0i05/esp_bme680:
|
||||||
|
component_hash: 2df0cb14d4425565a8745d4a96bfaa8ff7e90bbec3e208a073821406dded23c8
|
||||||
|
dependencies:
|
||||||
|
- name: idf
|
||||||
|
require: private
|
||||||
|
version: '>5.3.0'
|
||||||
|
- name: k0i05/esp_type_utils
|
||||||
|
registry_url: https://components.espressif.com
|
||||||
|
require: private
|
||||||
|
version: '>=0.0.1'
|
||||||
|
source:
|
||||||
|
registry_url: https://components.espressif.com/
|
||||||
|
type: service
|
||||||
|
version: 1.2.5
|
||||||
|
k0i05/esp_type_utils:
|
||||||
|
component_hash: dfe2feb2117ee060c085ec166b56cfd9d66cef4019216bf8722e45e43a3b562f
|
||||||
|
dependencies:
|
||||||
|
- name: idf
|
||||||
|
require: private
|
||||||
|
version: '>5.3.0'
|
||||||
|
source:
|
||||||
|
registry_url: https://components.espressif.com
|
||||||
|
type: service
|
||||||
|
targets:
|
||||||
|
- esp32
|
||||||
|
- esp32s3
|
||||||
|
version: 1.2.5
|
||||||
|
direct_dependencies:
|
||||||
|
- idf
|
||||||
|
- k0i05/esp_bme680
|
||||||
|
manifest_hash: d1239cf31dae728c3bdf1f5256203c673d51f614a8d7b2baac1052e75c913edf
|
||||||
|
target: esp32s3
|
||||||
|
version: 2.0.0
|
20
main/CMakeLists.txt
Normal file
20
main/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
idf_component_register(SRCS
|
||||||
|
"hw/i2cbrn.c"
|
||||||
|
"hw/i2cbrn.h"
|
||||||
|
"components/util.c"
|
||||||
|
"components/util.h"
|
||||||
|
"hw/bme680b.c"
|
||||||
|
"hw/bme680b.h"
|
||||||
|
"hw/ccs811.c"
|
||||||
|
"hw/ccs811.h"
|
||||||
|
"hw/ina260.c"
|
||||||
|
"hw/ina260.h"
|
||||||
|
"hw/mcp23018.c"
|
||||||
|
"hw/mcp23018.h"
|
||||||
|
"hw/mpu9250.c"
|
||||||
|
"hw/mpu9250.h"
|
||||||
|
"components/sensors.c"
|
||||||
|
"components/sensors.h"
|
||||||
|
"main.c"
|
||||||
|
|
||||||
|
INCLUDE_DIRS ".")
|
88
main/components/sensors.c
Normal file
88
main/components/sensors.c
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include "sensors.h"
|
||||||
|
|
||||||
|
#define BLINK_GPIO 2
|
||||||
|
|
||||||
|
static uint8_t s_led_state = 0;
|
||||||
|
|
||||||
|
static void configure_led(void)
|
||||||
|
{
|
||||||
|
gpio_reset_pin(BLINK_GPIO);
|
||||||
|
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_sensors_task(void *pvParameters)
|
||||||
|
{
|
||||||
|
// initialize the xLastWakeTime variable with the current time.
|
||||||
|
TickType_t last_wake_time = xTaskGetTickCount();
|
||||||
|
const TickType_t I2C0_TASK_SAMPLING_RATE = 5;
|
||||||
|
//
|
||||||
|
// initialize i2c device configuration
|
||||||
|
|
||||||
|
bme680b_init();
|
||||||
|
mpu9250_init();
|
||||||
|
mcp23018_init();
|
||||||
|
ina260_init();
|
||||||
|
ccs811_init();
|
||||||
|
|
||||||
|
configure_led();
|
||||||
|
|
||||||
|
int16_t accel[3], gyro[3], temp;
|
||||||
|
float accel_f[3], gyro_f[3], temp_f;
|
||||||
|
uint16_t eCO2;
|
||||||
|
uint16_t tvoc;
|
||||||
|
uint32_t volts;
|
||||||
|
uint32_t current;
|
||||||
|
uint32_t power;
|
||||||
|
|
||||||
|
// task loop entry point
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// handle sensor
|
||||||
|
|
||||||
|
bme680_data_t data;
|
||||||
|
esp_err_t result = bme680_get_data(BME680_DEV_HANDLE, &data);
|
||||||
|
if (result != ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG_BME, "bme680 device read failed (%s)", esp_err_to_name(result));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
data.barometric_pressure = data.barometric_pressure / 100;
|
||||||
|
// ESP_LOGI(TAG, "dewpoint temperature:%.2f °C", data.dewpoint_temperature);
|
||||||
|
ESP_LOGI(TAG_BME, "air temperature: %.2f °C", data.air_temperature);
|
||||||
|
ESP_LOGI(TAG_BME, "relative humidity: %.2f %%", data.relative_humidity);
|
||||||
|
ESP_LOGI(TAG_BME, "barometric pressure: %.2f hPa", data.barometric_pressure);
|
||||||
|
// ESP_LOGI(TAG, "gas resistance: %.2f kOhms", data.gas_resistance / 1000);
|
||||||
|
// ESP_LOGI(TAG, "iaq score: %u (%s)", data.iaq_score, bme680_air_quality_to_string(data.iaq_score));
|
||||||
|
}
|
||||||
|
|
||||||
|
ccs811_get_data(&eCO2, &tvoc);
|
||||||
|
ESP_LOGI(TAG_CCS, "eCO₂: %d ppm, TVOC: %d ppb", eCO2, tvoc);
|
||||||
|
|
||||||
|
if (mpu9250_read_sensor_data(MPU9250_DEV_HANDLE, accel, gyro, &temp) == ESP_OK)
|
||||||
|
{
|
||||||
|
mpu9250_convert_data(accel, gyro, temp, accel_f, gyro_f, &temp_f);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG_MPU, "Accel: X=%.2f g, Y=%.2f g, Z=%.2f g", accel_f[0], accel_f[1], accel_f[2]);
|
||||||
|
ESP_LOGI(TAG_MPU, "Gyro: X=%.2f°/s, Y=%.2f°/s, Z=%.2f°/s", gyro_f[0], gyro_f[1], gyro_f[2]);
|
||||||
|
ESP_LOGI(TAG_MPU, "Temperature: %.2f °C", temp_f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG_MPU, "Failed to read sensor data");
|
||||||
|
}
|
||||||
|
|
||||||
|
ina260_readParams(&volts, ¤t, &power);
|
||||||
|
ina260_printParams(volts, current, power);
|
||||||
|
|
||||||
|
gpio_set_level(BLINK_GPIO, s_led_state);
|
||||||
|
/* Toggle the LED state */
|
||||||
|
s_led_state = !s_led_state;
|
||||||
|
vTaskDelaySecUntil(&last_wake_time, I2C0_TASK_SAMPLING_RATE);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// free resources
|
||||||
|
bme680_delete(BME680_DEV_HANDLE);
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
}
|
23
main/components/sensors.h
Normal file
23
main/components/sensors.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef SENSORS_COMPONENT
|
||||||
|
#define SENSORS_COMPONENT
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include <bme680.h>
|
||||||
|
#include "esp_mac.h"
|
||||||
|
|
||||||
|
#include "../hw/bme680b.h"
|
||||||
|
#include "../hw/ccs811.h"
|
||||||
|
#include "../hw/i2cbrn.h"
|
||||||
|
|
||||||
|
#include "../hw/mcp23018.h"
|
||||||
|
#include "../hw/ina260.h"
|
||||||
|
#include "../hw/mpu9250.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void i2c_sensors_task(void *pvParameters);
|
||||||
|
|
||||||
|
#endif
|
7
main/components/util.c
Normal file
7
main/components/util.c
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
void vTaskDelaySecUntil(TickType_t *previousWakeTime, const unsigned int sec)
|
||||||
|
{
|
||||||
|
const TickType_t xFrequency = ((sec * 100) / portTICK_PERIOD_MS);
|
||||||
|
vTaskDelayUntil(previousWakeTime, xFrequency);
|
||||||
|
}
|
9
main/components/util.h
Normal file
9
main/components/util.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef UTIL_COMPONENT
|
||||||
|
#define UTIL_COMPONENT
|
||||||
|
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
|
||||||
|
void vTaskDelaySecUntil(TickType_t *previousWakeTime, const unsigned int sec);
|
||||||
|
|
||||||
|
#endif
|
51
main/hw/bme680b.c
Normal file
51
main/hw/bme680b.c
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include "bme680.h"
|
||||||
|
#include "bme680b.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "i2cbrn.h"
|
||||||
|
|
||||||
|
bme680_config_t BME680_DEV_CFG = I2C_BME680_CONFIG_DEFAULT;
|
||||||
|
bme680_handle_t BME680_DEV_HANDLE;
|
||||||
|
|
||||||
|
void bme680_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(TAG_BME, "Variant Id (0x%02x): %s", handle->variant_id, uint8_to_binary(handle->variant_id));
|
||||||
|
ESP_LOGI(TAG_BME, "Configuration (0x%02x): %s", config_reg.reg, uint8_to_binary(config_reg.reg));
|
||||||
|
ESP_LOGI(TAG_BME, "Control Measurement (0x%02x): %s", ctrl_meas_reg.reg, uint8_to_binary(ctrl_meas_reg.reg));
|
||||||
|
ESP_LOGI(TAG_BME, "Control Humidity (0x%02x): %s", ctrl_humi_reg.reg, uint8_to_binary(ctrl_humi_reg.reg));
|
||||||
|
ESP_LOGI(TAG_BME, "Control Gas 0 (0x%02x): %s", ctrl_gas0_reg.reg, uint8_to_binary(ctrl_gas0_reg.reg));
|
||||||
|
ESP_LOGI(TAG_BME, "Control Gas 1 (0x%02x): %s", ctrl_gas1_reg.reg, uint8_to_binary(ctrl_gas1_reg.reg));
|
||||||
|
}
|
||||||
|
|
||||||
|
void bme680b_init() {
|
||||||
|
// init device
|
||||||
|
bme680_init(i2c0_bus_hdl, &BME680_DEV_CFG, &BME680_DEV_HANDLE);
|
||||||
|
if (BME680_DEV_HANDLE == NULL)
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG_BME, "bme680 handle init failed");
|
||||||
|
assert(BME680_DEV_HANDLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
bme680_print_registers(BME680_DEV_HANDLE);
|
||||||
|
}
|
13
main/hw/bme680b.h
Normal file
13
main/hw/bme680b.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef BME680_COMPONENT
|
||||||
|
#define BME680_COMPONENT
|
||||||
|
|
||||||
|
#include <bme680.h>
|
||||||
|
#include "i2cbrn.h"
|
||||||
|
#define TAG_BME "BME680"
|
||||||
|
extern bme680_config_t BME680_DEV_CFG;
|
||||||
|
extern bme680_handle_t BME680_DEV_HANDLE;
|
||||||
|
|
||||||
|
void bme680_print_registers(bme680_handle_t handle);
|
||||||
|
void bme680b_init();
|
||||||
|
|
||||||
|
#endif
|
46
main/hw/ccs811.c
Normal file
46
main/hw/ccs811.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include "ccs811.h"
|
||||||
|
|
||||||
|
#define CONFIG_FREERTOS_HZ 100
|
||||||
|
|
||||||
|
i2c_device_config_t CCS811_DEV_CFG = {
|
||||||
|
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||||
|
.device_address = 0x5A,
|
||||||
|
.scl_speed_hz = 100000,
|
||||||
|
};
|
||||||
|
|
||||||
|
i2c_master_dev_handle_t CCS811_DEV_HANDLE;
|
||||||
|
|
||||||
|
void ccs811_init()
|
||||||
|
{
|
||||||
|
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c0_bus_hdl, &CCS811_DEV_CFG, &CCS811_DEV_HANDLE));
|
||||||
|
mcp23018_set_pin(MCP23018_DEV_HANDLE, MCP_CCS811_WAKE, 0);
|
||||||
|
mcp23018_set_pin(MCP23018_DEV_HANDLE, MCP_CCS811_POWER, 1);
|
||||||
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||||
|
uint8_t reset_seq[4] = {0x11, 0xE5, 0x72, 0x8A};
|
||||||
|
i2c_write_register(CCS811_DEV_HANDLE, 0xFF, reset_seq, sizeof(reset_seq)); //Reset
|
||||||
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||||
|
uint8_t status;
|
||||||
|
uint16_t version;
|
||||||
|
i2c_read_register_8(CCS811_DEV_HANDLE, 0x00, &status);
|
||||||
|
i2c_read_register_16(CCS811_DEV_HANDLE, 0x24, &version);
|
||||||
|
ESP_LOGW(TAG_CCS, "CCS811 status: %d, version: %d", status, version);
|
||||||
|
i2c_write_register(CCS811_DEV_HANDLE, 0xF4, NULL, 0); //start
|
||||||
|
vTaskDelay(10 / portTICK_PERIOD_MS);
|
||||||
|
i2c_write_register_8(CCS811_DEV_HANDLE, 0x10, 0x0001); // MODE 1 interrupts vypnuté
|
||||||
|
i2c_read_register_8(CCS811_DEV_HANDLE, 0x00, &status);
|
||||||
|
i2c_read_register_16(CCS811_DEV_HANDLE, 0x24, &version);
|
||||||
|
ESP_LOGW(TAG_CCS, "CCS811 status: %d, version: %d", status, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_err_t ccs811_get_data(uint16_t * eCO2, uint16_t * tvoc)
|
||||||
|
{
|
||||||
|
uint8_t ccsResult[8];
|
||||||
|
esp_err_t ret = i2c_read_register(CCS811_DEV_HANDLE, 0x05, ccsResult, 8);
|
||||||
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
|
*eCO2 = (ccsResult[0] << 8) | ccsResult[1];
|
||||||
|
*tvoc = (ccsResult[2] << 8) | ccsResult[3];
|
||||||
|
ESP_LOGI(TAG_CCS, "CCS Status: %d, Error %d", ccsResult[4], ccsResult[5]);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
15
main/hw/ccs811.h
Normal file
15
main/hw/ccs811.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef CCS811_COMPONENT
|
||||||
|
#define CCS811_COMPONENT
|
||||||
|
#include "i2cbrn.h"
|
||||||
|
#include "mcp23018.h"
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#define TAG_CCS "CCS811"
|
||||||
|
extern i2c_device_config_t CCS811_DEV_CFG;
|
||||||
|
|
||||||
|
extern i2c_master_dev_handle_t CCS811_DEV_HANDLE;
|
||||||
|
|
||||||
|
void ccs811_init();
|
||||||
|
esp_err_t ccs811_get_data(uint16_t * eCO2, uint16_t * tvoc);
|
||||||
|
|
||||||
|
#endif
|
204
main/hw/i2cbrn.c
Normal file
204
main/hw/i2cbrn.c
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
#include "i2cbrn.h"
|
||||||
|
|
||||||
|
i2c_master_bus_config_t i2c0_bus_cfg = {
|
||||||
|
.clk_source = I2C_CLK_SRC_DEFAULT,
|
||||||
|
.i2c_port = I2C_NUM_0,
|
||||||
|
.scl_io_num = GPIO_NUM_9,
|
||||||
|
.sda_io_num = GPIO_NUM_8,
|
||||||
|
.glitch_ignore_cnt = 7,
|
||||||
|
.flags.enable_internal_pullup = true,
|
||||||
|
};
|
||||||
|
i2c_master_bus_handle_t i2c0_bus_hdl;
|
||||||
|
|
||||||
|
esp_err_t i2c_master_bus_detect_devices(i2c_master_bus_handle_t handle)
|
||||||
|
{
|
||||||
|
const uint16_t probe_timeout_ms = 50; // timeout in milliseconds
|
||||||
|
uint8_t address;
|
||||||
|
|
||||||
|
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\r\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < 128; i += 16)
|
||||||
|
{
|
||||||
|
printf("%02x: ", i);
|
||||||
|
|
||||||
|
for (int j = 0; j < 16; j++)
|
||||||
|
{
|
||||||
|
fflush(stdout);
|
||||||
|
|
||||||
|
address = i + j;
|
||||||
|
|
||||||
|
esp_err_t ret = i2c_master_probe(handle, address, probe_timeout_ms);
|
||||||
|
|
||||||
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
|
printf("%02x ", address);
|
||||||
|
}
|
||||||
|
else if (ret == ESP_ERR_TIMEOUT)
|
||||||
|
{
|
||||||
|
printf("UU ");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("-- ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes data to a specific register of an I2C device.
|
||||||
|
*
|
||||||
|
* @param dev_handle I2C device handle
|
||||||
|
* @param reg_addr Register address to write to
|
||||||
|
* @param data Pointer to the data buffer to write
|
||||||
|
* @param len Number of bytes to write
|
||||||
|
* @return esp_err_t ESP_OK on success, or an error code
|
||||||
|
*/
|
||||||
|
esp_err_t i2c_write_register(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t *data, size_t len)
|
||||||
|
{
|
||||||
|
if (len == 0) {
|
||||||
|
// If no data, send just the register address
|
||||||
|
return i2c_master_transmit(dev_handle, ®_addr, 1, I2C_TIMEOUT_MS_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t buffer[len + 1];
|
||||||
|
buffer[0] = reg_addr;
|
||||||
|
memcpy(&buffer[1], data, len);
|
||||||
|
|
||||||
|
esp_err_t ret = i2c_master_transmit(dev_handle, buffer, sizeof(buffer), I2C_TIMEOUT_MS_VALUE);
|
||||||
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGV(TAG_I2C, "Write to register 0x%02X successful", reg_addr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG_I2C, "Write to register 0x%02X failed: %s", reg_addr, esp_err_to_name(ret));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads data from a specific register of an I2C device.
|
||||||
|
*
|
||||||
|
* @param dev_handle I2C device handle
|
||||||
|
* @param reg_addr Register address to read from
|
||||||
|
* @param data Pointer to a buffer to store read data
|
||||||
|
* @param len Number of bytes to read
|
||||||
|
* @return esp_err_t ESP_OK on success, or an error code
|
||||||
|
*/
|
||||||
|
esp_err_t i2c_read_register(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t *data, size_t len)
|
||||||
|
{
|
||||||
|
esp_err_t ret = i2c_master_transmit_receive(dev_handle, ®_addr, 1, data, len, I2C_TIMEOUT_MS_VALUE);
|
||||||
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGV(TAG_I2C, "Read from register 0x%02X successful", reg_addr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG_I2C, "Read from register 0x%02X failed: %s", reg_addr, esp_err_to_name(ret));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes a 16-bit value to a specific register of an I2C device.
|
||||||
|
*
|
||||||
|
* @param dev_handle I2C device handle
|
||||||
|
* @param reg_addr Register address to write to
|
||||||
|
* @param value 16-bit value to write
|
||||||
|
* @return esp_err_t ESP_OK on success, or an error code
|
||||||
|
*/
|
||||||
|
esp_err_t i2c_write_register_16(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint16_t value)
|
||||||
|
{
|
||||||
|
uint8_t buffer[3];
|
||||||
|
buffer[0] = reg_addr; // Register address
|
||||||
|
buffer[1] = (value >> 8); // High byte
|
||||||
|
buffer[2] = (value & 0xFF); // Low byte
|
||||||
|
|
||||||
|
esp_err_t ret = i2c_master_transmit(dev_handle, buffer, sizeof(buffer), I2C_TIMEOUT_MS_VALUE);
|
||||||
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGV(TAG_I2C, "Write to register 0x%02X successful (Value: 0x%04X)", reg_addr, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG_I2C, "Write to register 0x%02X failed: %s", reg_addr, esp_err_to_name(ret));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads a 16-bit value from a specific register of an I2C device.
|
||||||
|
*
|
||||||
|
* @param dev_handle I2C device handle
|
||||||
|
* @param reg_addr Register address to read from
|
||||||
|
* @param value Pointer to store the read 16-bit value
|
||||||
|
* @return esp_err_t ESP_OK on success, or an error code
|
||||||
|
*/
|
||||||
|
esp_err_t i2c_read_register_16(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint16_t *value)
|
||||||
|
{
|
||||||
|
uint8_t buffer[2];
|
||||||
|
|
||||||
|
esp_err_t ret = i2c_master_transmit_receive(dev_handle, ®_addr, 1, buffer, sizeof(buffer), I2C_TIMEOUT_MS_VALUE);
|
||||||
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
|
*value = (buffer[0] << 8) | buffer[1]; // Combine MSB and LSB
|
||||||
|
ESP_LOGV(TAG_I2C, "Read from register 0x%02X successful (Value: 0x%04X)", reg_addr, *value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG_I2C, "Read from register 0x%02X failed: %s", reg_addr, esp_err_to_name(ret));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Writes an 8-bit value to a specific register of an I2C device.
|
||||||
|
*
|
||||||
|
* @param dev_handle I2C device handle
|
||||||
|
* @param reg_addr Register address to write to
|
||||||
|
* @param value 8-bit value to write
|
||||||
|
* @return esp_err_t ESP_OK on success, or an error code
|
||||||
|
*/
|
||||||
|
esp_err_t i2c_write_register_8(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t value)
|
||||||
|
{
|
||||||
|
uint8_t buffer[2];
|
||||||
|
buffer[0] = reg_addr; // Register address
|
||||||
|
buffer[1] = value; // 8-bit value
|
||||||
|
|
||||||
|
esp_err_t ret = i2c_master_transmit(dev_handle, buffer, sizeof(buffer), I2C_TIMEOUT_MS_VALUE);
|
||||||
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGV(TAG_I2C, "Write to register 0x%02X successful (Value: 0x%02X)", reg_addr, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG_I2C, "Write to register 0x%02X failed: %s", reg_addr, esp_err_to_name(ret));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Reads an 8-bit value from a specific register of an I2C device.
|
||||||
|
*
|
||||||
|
* @param dev_handle I2C device handle
|
||||||
|
* @param reg_addr Register address to read from
|
||||||
|
* @param value Pointer to store the read 8-bit value
|
||||||
|
* @return esp_err_t ESP_OK on success, or an error code
|
||||||
|
*/
|
||||||
|
esp_err_t i2c_read_register_8(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t *value)
|
||||||
|
{
|
||||||
|
esp_err_t ret = i2c_master_transmit_receive(dev_handle, ®_addr, 1, value, 1, I2C_TIMEOUT_MS_VALUE);
|
||||||
|
if (ret == ESP_OK)
|
||||||
|
{
|
||||||
|
ESP_LOGV(TAG_I2C, "Read from register 0x%02X successful (Value: 0x%02X)", reg_addr, *value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ESP_LOGE(TAG_I2C, "Read from register 0x%02X failed: %s", reg_addr, esp_err_to_name(ret));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
20
main/hw/i2cbrn.h
Normal file
20
main/hw/i2cbrn.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef I2CBRN_COMPONENT
|
||||||
|
#define I2CBRN_COMPONENT
|
||||||
|
#define I2C_TIMEOUT_MS_VALUE 20
|
||||||
|
#include <string.h>
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
#define TAG_I2C "cani2c"
|
||||||
|
|
||||||
|
#include "driver/i2c_master.h"
|
||||||
|
extern i2c_master_bus_config_t i2c0_bus_cfg;
|
||||||
|
extern i2c_master_bus_handle_t i2c0_bus_hdl;
|
||||||
|
|
||||||
|
esp_err_t i2c_master_bus_detect_devices(i2c_master_bus_handle_t handle);
|
||||||
|
esp_err_t i2c_write_register(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t *data, size_t len);
|
||||||
|
esp_err_t i2c_read_register(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t *data, size_t len);
|
||||||
|
esp_err_t i2c_write_register_16(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint16_t value);
|
||||||
|
esp_err_t i2c_read_register_16(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint16_t *value);
|
||||||
|
esp_err_t i2c_write_register_8(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t value);
|
||||||
|
esp_err_t i2c_read_register_8(i2c_master_dev_handle_t dev_handle, uint8_t reg_addr, uint8_t *value);
|
||||||
|
#endif
|
53
main/hw/ina260.c
Normal file
53
main/hw/ina260.c
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#include "ina260.h"
|
||||||
|
|
||||||
|
i2c_device_config_t INA260_DEV_CFG = {
|
||||||
|
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||||
|
.device_address = 0x40,
|
||||||
|
.scl_speed_hz = 100000,
|
||||||
|
};
|
||||||
|
|
||||||
|
i2c_master_dev_handle_t INA260_DEV_HANDLE;
|
||||||
|
|
||||||
|
void ina260_init()
|
||||||
|
{
|
||||||
|
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c0_bus_hdl, &INA260_DEV_CFG, &INA260_DEV_HANDLE));
|
||||||
|
i2c_write_register_16(INA260_DEV_HANDLE, 0x00, 0x0FFF); // set ina max averaging and max time
|
||||||
|
}
|
||||||
|
|
||||||
|
void ina260_readParams(uint32_t *volt, uint32_t *cur, uint32_t *pow)
|
||||||
|
{
|
||||||
|
for (uint8_t reg_addr = 1; reg_addr <= 3; reg_addr++)
|
||||||
|
{
|
||||||
|
uint8_t reg_value[2] = {0}; // Buffer for storing register data
|
||||||
|
|
||||||
|
// Perform the register read
|
||||||
|
ESP_ERROR_CHECK(i2c_master_transmit_receive(INA260_DEV_HANDLE, ®_addr, 1, reg_value, sizeof(reg_value), I2C_TIMEOUT_MS_VALUE));
|
||||||
|
switch (reg_addr)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
*cur = *((uint16_t *)reg_value);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
*volt = *((uint16_t *)reg_value);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
*pow = *((uint16_t *)reg_value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ina260_printParams(uint32_t volt, uint32_t cur, uint32_t pow)
|
||||||
|
{
|
||||||
|
cur *= 125;
|
||||||
|
ESP_LOGI(TAG_INA, "Current: %ld.%ld mA", cur / 10000, cur % 10000);
|
||||||
|
cur *= 125;
|
||||||
|
ESP_LOGI(TAG_INA, "Voltage: %ld.%ld V", volt / 10000, volt % 10000);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG_INA, "Power: %ld.%ld W", pow / 10000, pow % 10000);
|
||||||
|
}
|
15
main/hw/ina260.h
Normal file
15
main/hw/ina260.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef INA260_COMPONENT
|
||||||
|
#define INA260_COMPONENT
|
||||||
|
#include "i2cbrn.h"
|
||||||
|
#define TAG_INA "INA260"
|
||||||
|
extern i2c_device_config_t INA260_DEV_CFG;
|
||||||
|
|
||||||
|
extern i2c_master_dev_handle_t INA260_DEV_HANDLE;
|
||||||
|
|
||||||
|
|
||||||
|
void ina260_init();
|
||||||
|
void ina260_readParams(uint32_t *volt, uint32_t *cur, uint32_t *pow);
|
||||||
|
void ina260_printParams(uint32_t volt, uint32_t cur, uint32_t pow);
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
51
main/hw/mcp23018.c
Normal file
51
main/hw/mcp23018.c
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include "mcp23018.h"
|
||||||
|
// Local buffer for tracking GPIO state
|
||||||
|
|
||||||
|
i2c_device_config_t MCP23018_DEV_CFG = {
|
||||||
|
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||||
|
.device_address = 0x20,
|
||||||
|
.scl_speed_hz = 100000,
|
||||||
|
};
|
||||||
|
|
||||||
|
i2c_master_dev_handle_t MCP23018_DEV_HANDLE;
|
||||||
|
uint8_t gpioa_state = 0x00; // All LOW initially
|
||||||
|
uint8_t gpiob_state = 0x00; // All LOW initially
|
||||||
|
|
||||||
|
void mcp23018_set_pin(i2c_master_dev_handle_t dev_handle, uint8_t pin, uint8_t value)
|
||||||
|
{
|
||||||
|
if (pin < 8)
|
||||||
|
{
|
||||||
|
// GPIOA (Pins 0-7)
|
||||||
|
if (value)
|
||||||
|
gpioa_state |= (1 << pin); // Set bit
|
||||||
|
else
|
||||||
|
gpioa_state &= ~(1 << pin); // Clear bit
|
||||||
|
|
||||||
|
// Write updated buffer to MCP23018
|
||||||
|
i2c_write_register_8(dev_handle, MCP23018_GPIOA, gpioa_state);
|
||||||
|
}
|
||||||
|
else if (pin < 16)
|
||||||
|
{
|
||||||
|
// GPIOB (Pins 8-15)
|
||||||
|
uint8_t pinB = pin - 8;
|
||||||
|
if (value)
|
||||||
|
gpiob_state |= (1 << pinB); // Set bit
|
||||||
|
else
|
||||||
|
gpiob_state &= ~(1 << pinB); // Clear bit
|
||||||
|
|
||||||
|
// Write updated buffer to MCP23018
|
||||||
|
i2c_write_register_8(dev_handle, MCP23018_GPIOB, gpiob_state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcp23018_init()
|
||||||
|
{
|
||||||
|
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c0_bus_hdl, &MCP23018_DEV_CFG, &MCP23018_DEV_HANDLE));
|
||||||
|
i2c_write_register_8(MCP23018_DEV_HANDLE, MCP23018_IODIRA, gpioa_state);
|
||||||
|
i2c_write_register_8(MCP23018_DEV_HANDLE, MCP23018_IODIRB, gpiob_state);
|
||||||
|
mcp23018_set_pin(MCP23018_DEV_HANDLE, MCP_CS_ADC_CO, 1);
|
||||||
|
mcp23018_set_pin(MCP23018_DEV_HANDLE, MCP_CS_ADC_NH3, 1);
|
||||||
|
mcp23018_set_pin(MCP23018_DEV_HANDLE, MCP_CS_ADC_NO2, 1);
|
||||||
|
mcp23018_set_pin(MCP23018_DEV_HANDLE, MCP_CS_ADC_UVC, 1);
|
||||||
|
mcp23018_set_pin(MCP23018_DEV_HANDLE, MCP_LORA_RST, 1);
|
||||||
|
}
|
31
main/hw/mcp23018.h
Normal file
31
main/hw/mcp23018.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef MCP23018_COMPONENT
|
||||||
|
#define MCP23018_COMPONENT
|
||||||
|
#include "i2cbrn.h"
|
||||||
|
#define TAG_MCP "MCP23018"
|
||||||
|
#define MCP23018_IODIRA 0x00 // I/O Direction A
|
||||||
|
#define MCP23018_IODIRB 0x01 // I/O Direction B
|
||||||
|
#define MCP23018_GPIOA 0x12 // GPIO Output A
|
||||||
|
#define MCP23018_GPIOB 0x13 // GPIO Output B
|
||||||
|
|
||||||
|
#define MCP_LORA_RST 4
|
||||||
|
#define MCP_MICS_POWER 5
|
||||||
|
#define MCP_CCS811_WAKE 6
|
||||||
|
#define MCP_CCS811_POWER 7
|
||||||
|
|
||||||
|
#define MCP_CS_ADC_NH3 8
|
||||||
|
#define MCP_CS_ADC_CO 9
|
||||||
|
#define MCP_CS_ADC_NO2 10
|
||||||
|
#define MCP_CS_ADC_UVC 11
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern i2c_device_config_t MCP23018_DEV_CFG;
|
||||||
|
|
||||||
|
extern i2c_master_dev_handle_t MCP23018_DEV_HANDLE;
|
||||||
|
extern uint8_t gpioa_state;
|
||||||
|
extern uint8_t gpiob_state;
|
||||||
|
|
||||||
|
void mcp23018_set_pin(i2c_master_dev_handle_t dev_handle, uint8_t pin, uint8_t value);
|
||||||
|
void mcp23018_init();
|
||||||
|
|
||||||
|
#endif
|
46
main/hw/mpu9250.c
Normal file
46
main/hw/mpu9250.c
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#include "mpu9250.h"
|
||||||
|
|
||||||
|
i2c_device_config_t MPU9250_DEV_CFG = {
|
||||||
|
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
|
||||||
|
.device_address = 0x68,
|
||||||
|
.scl_speed_hz = 100000,
|
||||||
|
};
|
||||||
|
|
||||||
|
i2c_master_dev_handle_t MPU9250_DEV_HANDLE;
|
||||||
|
|
||||||
|
esp_err_t mpu9250_read_sensor_data(i2c_master_dev_handle_t dev_handle, int16_t *accel, int16_t *gyro, int16_t *temp)
|
||||||
|
{
|
||||||
|
uint8_t buffer[14]; // 6 (Accel) + 2 (Temp) + 6 (Gyro)
|
||||||
|
esp_err_t ret = i2c_read_register(dev_handle, 0x3B, buffer, 14);
|
||||||
|
if (ret != ESP_OK)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
// Convert raw data (Big-Endian)
|
||||||
|
accel[0] = (buffer[0] << 8) | buffer[1]; // Accel X
|
||||||
|
accel[1] = (buffer[2] << 8) | buffer[3]; // Accel Y
|
||||||
|
accel[2] = (buffer[4] << 8) | buffer[5]; // Accel Z
|
||||||
|
*temp = (buffer[6] << 8) | buffer[7]; // Temperature
|
||||||
|
gyro[0] = (buffer[8] << 8) | buffer[9]; // Gyro X
|
||||||
|
gyro[1] = (buffer[10] << 8) | buffer[11]; // Gyro Y
|
||||||
|
gyro[2] = (buffer[12] << 8) | buffer[13]; // Gyro Z
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mpu9250_convert_data(int16_t *accel, int16_t *gyro, int16_t temp, float *accel_out, float *gyro_out, float *temp_out)
|
||||||
|
{
|
||||||
|
accel_out[0] = accel[0] / 16384.0; // Accel X in g
|
||||||
|
accel_out[1] = accel[1] / 16384.0; // Accel Y in g
|
||||||
|
accel_out[2] = accel[2] / 16384.0; // Accel Z in g
|
||||||
|
|
||||||
|
gyro_out[0] = gyro[0] / 131.0; // Gyro X in deg/s
|
||||||
|
gyro_out[1] = gyro[1] / 131.0; // Gyro Y in deg/s
|
||||||
|
gyro_out[2] = gyro[2] / 131.0; // Gyro Z in deg/s
|
||||||
|
|
||||||
|
*temp_out = (temp / 333.87) + 21.0; // Temperature in °C
|
||||||
|
}
|
||||||
|
|
||||||
|
void mpu9250_init() {
|
||||||
|
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c0_bus_hdl, &MPU9250_DEV_CFG, &MPU9250_DEV_HANDLE));
|
||||||
|
i2c_write_register_16(MPU9250_DEV_HANDLE, 0x6B, 0x0001); // zapni uz tu hovadinu
|
||||||
|
}
|
15
main/hw/mpu9250.h
Normal file
15
main/hw/mpu9250.h
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef MPU9250_COMPONENT
|
||||||
|
#define MPU9250_COMPONENT
|
||||||
|
#include "i2cbrn.h"
|
||||||
|
#define TAG_MPU "MPU9250"
|
||||||
|
|
||||||
|
extern i2c_device_config_t MPU9250_DEV_CFG;
|
||||||
|
|
||||||
|
extern i2c_master_dev_handle_t MPU9250_DEV_HANDLE;
|
||||||
|
|
||||||
|
|
||||||
|
esp_err_t mpu9250_read_sensor_data(i2c_master_dev_handle_t dev_handle, int16_t *accel, int16_t *gyro, int16_t *temp);
|
||||||
|
void mpu9250_convert_data(int16_t *accel, int16_t *gyro, int16_t temp, float *accel_out, float *gyro_out, float *temp_out);
|
||||||
|
void mpu9250_init();
|
||||||
|
|
||||||
|
#endif
|
17
main/idf_component.yml
Normal file
17
main/idf_component.yml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
## IDF Component Manager Manifest File
|
||||||
|
dependencies:
|
||||||
|
## Required IDF version
|
||||||
|
idf:
|
||||||
|
version: '>=4.1.0'
|
||||||
|
# # Put list of dependencies here
|
||||||
|
# # For components maintained by Espressif:
|
||||||
|
# component: "~1.0.0"
|
||||||
|
# # For 3rd party components:
|
||||||
|
# username/component: ">=1.0.0,<2.0.0"
|
||||||
|
# username2/component2:
|
||||||
|
# version: "~1.0.0"
|
||||||
|
# # For transient dependencies `public` flag can be set.
|
||||||
|
# # `public` flag doesn't have an effect dependencies of the `main` component.
|
||||||
|
# # All dependencies of `main` are public by default.
|
||||||
|
# public: true
|
||||||
|
k0i05/esp_bme680: ^1.2.5
|
57
main/main.c
Normal file
57
main/main.c
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/* Blink Example
|
||||||
|
|
||||||
|
This example code is in the Public Domain (or CC0 licensed, at your option.)
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, this
|
||||||
|
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
*/
|
||||||
|
#include <stdio.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/task.h"
|
||||||
|
#include "driver/gpio.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
#include "sdkconfig.h"
|
||||||
|
#include "esp_mac.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "components/sensors.h"
|
||||||
|
#include "components/util.h"
|
||||||
|
#include "hw/bme680b.h"
|
||||||
|
#include "hw/ccs811.h"
|
||||||
|
#include "hw/i2cbrn.h"
|
||||||
|
#include "hw/ina260.h"
|
||||||
|
#include "hw/mcp23018.h"
|
||||||
|
#include "hw/mpu9250.h"
|
||||||
|
|
||||||
|
#define TAG "cantest"
|
||||||
|
|
||||||
|
|
||||||
|
#define CONFIG_FREERTOS_HZ 100
|
||||||
|
|
||||||
|
|
||||||
|
void app_main(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* instantiate i2c master bus 0 */
|
||||||
|
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c0_bus_cfg, &i2c0_bus_hdl));
|
||||||
|
|
||||||
|
/* scan i2c devices on i2c master bus 0 and print results */
|
||||||
|
ESP_ERROR_CHECK(i2c_master_bus_detect_devices(i2c0_bus_hdl));
|
||||||
|
|
||||||
|
/* create task pinned to the app core */
|
||||||
|
xTaskCreatePinnedToCore(
|
||||||
|
i2c_sensors_task,
|
||||||
|
"I2CTaskBME",
|
||||||
|
8192,
|
||||||
|
NULL,
|
||||||
|
(tskIDLE_PRIORITY + 2),
|
||||||
|
NULL,
|
||||||
|
APP_CPU_NUM);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
|
||||||
|
vTaskDelay(100 / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
}
|
1
managed_components/k0i05__esp_bme680/.component_hash
Normal file
1
managed_components/k0i05__esp_bme680/.component_hash
Normal file
@@ -0,0 +1 @@
|
|||||||
|
2df0cb14d4425565a8745d4a96bfaa8ff7e90bbec3e208a073821406dded23c8
|
98
managed_components/k0i05__esp_bme680/CMakeLists.txt
Normal file
98
managed_components/k0i05__esp_bme680/CMakeLists.txt
Normal 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
|
||||||
|
)
|
||||||
|
|
21
managed_components/k0i05__esp_bme680/LICENSE
Normal file
21
managed_components/k0i05__esp_bme680/LICENSE
Normal 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.
|
124
managed_components/k0i05__esp_bme680/README.md
Normal file
124
managed_components/k0i05__esp_bme680/README.md
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
# Bosch BME680 Sensor
|
||||||
|
|
||||||
|
[](/LICENSE)
|
||||||
|
[](https://visualstudio.microsoft.com)
|
||||||
|
[](https://platformio.org/)
|
||||||
|
[](https://registry.platformio.org/libraries/k0i05/esp_bme680)
|
||||||
|
[](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>)
|
1347
managed_components/k0i05__esp_bme680/bme680.c
Normal file
1347
managed_components/k0i05__esp_bme680/bme680.c
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
26
managed_components/k0i05__esp_bme680/idf_component.yml
Normal file
26
managed_components/k0i05__esp_bme680/idf_component.yml
Normal 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
|
713
managed_components/k0i05__esp_bme680/include/bme680.h
Normal file
713
managed_components/k0i05__esp_bme680/include/bme680.h
Normal 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__
|
108
managed_components/k0i05__esp_bme680/include/bme680_version.h
Normal file
108
managed_components/k0i05__esp_bme680/include/bme680_version.h
Normal 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__
|
25
managed_components/k0i05__esp_bme680/library.json
Normal file
25
managed_components/k0i05__esp_bme680/library.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
1
managed_components/k0i05__esp_type_utils/.component_hash
Normal file
1
managed_components/k0i05__esp_type_utils/.component_hash
Normal file
@@ -0,0 +1 @@
|
|||||||
|
dfe2feb2117ee060c085ec166b56cfd9d66cef4019216bf8722e45e43a3b562f
|
97
managed_components/k0i05__esp_type_utils/CMakeLists.txt
Normal file
97
managed_components/k0i05__esp_type_utils/CMakeLists.txt
Normal 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
|
||||||
|
)
|
63
managed_components/k0i05__esp_type_utils/README.md
Normal file
63
managed_components/k0i05__esp_type_utils/README.md
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
# ESP-IDF Type Utilities
|
||||||
|
|
||||||
|
[](/LICENSE)
|
||||||
|
[](https://visualstudio.microsoft.com)
|
||||||
|
[](https://platformio.org/)
|
||||||
|
[](https://registry.platformio.org/libraries/k0i05/esp_type_utils)
|
||||||
|
[](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>)
|
16
managed_components/k0i05__esp_type_utils/idf_component.yml
Normal file
16
managed_components/k0i05__esp_type_utils/idf_component.yml
Normal 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
|
396
managed_components/k0i05__esp_type_utils/include/type_utils.h
Normal file
396
managed_components/k0i05__esp_type_utils/include/type_utils.h
Normal 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__
|
@@ -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__
|
22
managed_components/k0i05__esp_type_utils/library.json
Normal file
22
managed_components/k0i05__esp_type_utils/library.json
Normal 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"
|
||||||
|
}
|
399
managed_components/k0i05__esp_type_utils/type_utils.c
Normal file
399
managed_components/k0i05__esp_type_utils/type_utils.c
Normal 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;
|
||||||
|
}
|
Reference in New Issue
Block a user