From ddb70139f1f1d05dc188868bcab619110c0b87c2 Mon Sep 17 00:00:00 2001 From: Jacek Wieczorek Date: Sat, 7 Aug 2021 14:28:10 +0200 Subject: [PATCH] Add ESP-IDF component files --- .gitignore | 1 + CMakeLists.txt | 27 +++++++++++++ src/esp.config.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ src/impl.c | 2 + 4 files changed, 128 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 src/esp.config.h create mode 100644 src/impl.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..94a629f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +liblightmodbus diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2cb0baf --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,27 @@ +# This CMakeLists.txt is only a ESP-IDF component declaration +include(FetchContent) +set(LIBLIGHTMODBUS_REPO_DIR "${CMAKE_CURRENT_LIST_DIR}/liblightmodbus") + +# Fetch liblightmodbus source code from GitHub +FetchContent_Populate(liblightmodbus-src + GIT_REPOSITORY "https://github.com/jacajack/liblightmodbus.git" + GIT_TAG "dev-v3.0" + SOURCE_DIR "${LIBLIGHTMODBUS_REPO_DIR}" +) + +# Copy config file to liblightmodbus include directory +configure_file( + "${CMAKE_CURRENT_LIST_DIR}/src/esp.config.h" + "${LIBLIGHTMODBUS_REPO_DIR}/include/lightmodbus/esp.config.h" + COPYONLY +) + +# Register component +idf_component_register( + SRCS "src/impl.c" + INCLUDE_DIRS "${LIBLIGHTMODBUS_REPO_DIR}/include" +) + +# Inform liblightmodbus to use ESP config header +idf_build_set_property(COMPILE_DEFINITIONS "-DLIGHTMODBUS_USE_CONFIG_FILE" APPEND) +idf_build_set_property(COMPILE_DEFINITIONS "-DLIGHTMODBUS_CONFIG_FILE=\"esp.config.h\"" APPEND) diff --git a/src/esp.config.h b/src/esp.config.h new file mode 100644 index 0000000..6698b4b --- /dev/null +++ b/src/esp.config.h @@ -0,0 +1,98 @@ +#ifndef LIGHTMODBUS_ESP_CONFIG_H +#define LIGHTMODBUS_ESP_CONFIG_H + +#include "sdkconfig.h" + +#ifdef CONFIG_LIGHTMODBUS_DEBUG +#define LIGHTMODBUS_DEBUG +#endif + +#ifdef CONFIG_LIGHTMODBUS_FULL +#define LIGHTMODBUS_FULL +#endif + +#ifdef CONFIG_LIGHTMODBUS_SLAVE +#define LIGHTMODBUS_SLAVE +#endif + +#ifdef CONFIG_LIGHTMODBUS_F01S +#define LIGHTMODBUS_F01S +#endif + +#ifdef CONFIG_LIGHTMODBUS_F02S +#define LIGHTMODBUS_F02S +#endif + +#ifdef CONFIG_LIGHTMODBUS_F03S +#define LIGHTMODBUS_F03S +#endif + +#ifdef CONFIG_LIGHTMODBUS_F04S +#define LIGHTMODBUS_F04S +#endif + +#ifdef CONFIG_LIGHTMODBUS_F05S +#define LIGHTMODBUS_F05S +#endif + +#ifdef CONFIG_LIGHTMODBUS_F06S +#define LIGHTMODBUS_F06S +#endif + +#ifdef CONFIG_LIGHTMODBUS_F15S +#define LIGHTMODBUS_F15S +#endif + +#ifdef CONFIG_LIGHTMODBUS_F16S +#define LIGHTMODBUS_F16S +#endif + +#ifdef CONFIG_LIGHTMODBUS_F22S +#define LIGHTMODBUS_F22S +#endif + +#ifdef CONFIG_LIGHTMODBUS_MASTER +#define LIGHTMODBUS_MASTER +#endif + +#ifdef CONFIG_LIGHTMODBUS_MASTER_OMIT_REQUEST_CRC +#define LIGHTMODBUS_MASTER_OMIT_REQUEST_CRC +#endif + +#ifdef CONFIG_LIGHTMODBUS_F01M +#define LIGHTMODBUS_F01M +#endif + +#ifdef CONFIG_LIGHTMODBUS_F02M +#define LIGHTMODBUS_F02M +#endif + +#ifdef CONFIG_LIGHTMODBUS_F03M +#define LIGHTMODBUS_F03M +#endif + +#ifdef CONFIG_LIGHTMODBUS_F04M +#define LIGHTMODBUS_F04M +#endif + +#ifdef CONFIG_LIGHTMODBUS_F05M +#define LIGHTMODBUS_F05M +#endif + +#ifdef CONFIG_LIGHTMODBUS_F06M +#define LIGHTMODBUS_F06M +#endif + +#ifdef CONFIG_LIGHTMODBUS_F15M +#define LIGHTMODBUS_F15M +#endif + +#ifdef CONFIG_LIGHTMODBUS_F16M +#define LIGHTMODBUS_F16M +#endif + +#ifdef CONFIG_LIGHTMODBUS_F22M +#define LIGHTMODBUS_F22M +#endif + +#endif diff --git a/src/impl.c b/src/impl.c new file mode 100644 index 0000000..e437c75 --- /dev/null +++ b/src/impl.c @@ -0,0 +1,2 @@ +#define LIGHTMODBUS_IMPL +#include