From f11a189e3146cef580c1dfa93ab37b7301ee626a Mon Sep 17 00:00:00 2001 From: Artur Gurgul Date: Tue, 16 Sep 2025 10:27:08 -0500 Subject: [PATCH] Make it 'flashable' --- CMakeLists.txt | 4 ++++ Makefile | 3 +++ main/CMakeLists.txt | 2 +- main/bme680_esp8266.c | 22 +++++++++++++++++----- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ad49cc..6893cb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,10 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) + +# Disable C++ thread-safe statics to avoid pthread dependency +add_compile_options($<$:-fno-threadsafe-statics>) + set(EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_LIST_DIR}/components") include($ENV{IDF_PATH}/tools/cmake/project.cmake) diff --git a/Makefile b/Makefile index 1b2ce4f..830de18 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,6 @@ build: # idf.py reconfigure # idf.py defconfig idf.py build + +flash: + idf.py -p /dev/ttyUSB0 flash monitor diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 44ffafd..7d58651 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -5,6 +5,6 @@ idf_component_register( SRCS "bme680_esp8266.c" INCLUDE_DIRS "." - REQUIRES bme68x esp8266 + REQUIRES bme68x esp8266 pthread # PRIV_REQUIRES driver ) diff --git a/main/bme680_esp8266.c b/main/bme680_esp8266.c index 12724f4..0f8a5ae 100644 --- a/main/bme680_esp8266.c +++ b/main/bme680_esp8266.c @@ -16,16 +16,28 @@ /* --------- ESP8266 I2C init (note: clk_stretch_tick field) --------- */ static void i2c_init(void) { + // i2c_config_t conf = { + // .mode = I2C_MODE_MASTER, + // .sda_io_num = I2C_SDA_PIN, + // .scl_io_num = I2C_SCL_PIN, + // .sda_pullup_en = GPIO_PULLUP_ENABLE, + // .scl_pullup_en = GPIO_PULLUP_ENABLE, + // .clk_stretch_tick = 300, // reasonable default on ESP8266 + // }; + // i2c_param_config(I2C_PORT, &conf); + // i2c_driver_install(I2C_PORT, conf.mode); // ESP8266 signature: (port, mode) + i2c_config_t conf = { .mode = I2C_MODE_MASTER, - .sda_io_num = I2C_SDA_PIN, - .scl_io_num = I2C_SCL_PIN, + .sda_io_num = GPIO_NUM_0, + .scl_io_num = GPIO_NUM_2, .sda_pullup_en = GPIO_PULLUP_ENABLE, .scl_pullup_en = GPIO_PULLUP_ENABLE, - .clk_stretch_tick = 300, // reasonable default on ESP8266 + .clk_stretch_tick = 300, // try 300..1000 }; - i2c_param_config(I2C_PORT, &conf); - i2c_driver_install(I2C_PORT, conf.mode); // ESP8266 signature: (port, mode) + + ESP_ERROR_CHECK(i2c_param_config(I2C_PORT, &conf)); + ESP_ERROR_CHECK(i2c_driver_install(I2C_PORT, conf.mode)); } /* ------------- BME68x I2C read/write helpers ------------- */