Refactor CMakeLists and add i2c_driver support for ESP-IDF v6; enhance QMI8658 task with rotation handling and stack monitoring

This commit is contained in:
2026-05-24 15:33:31 +08:00
parent 2906930d89
commit 2cb9187fcd
23 changed files with 110 additions and 3 deletions
@@ -4,4 +4,9 @@
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
project(01_AXP2101_Test)
@@ -3,6 +3,7 @@ idf_component_register(
"i2c_bsp.cpp"
PRIV_REQUIRES
driver
esp_driver_i2c
pmicpower
esp_timer
INCLUDE_DIRS
+5
View File
@@ -1,3 +1,8 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
project(02_I2C_QMI8658)
@@ -4,6 +4,7 @@ idf_component_register(
"display_bsp.cpp"
PRIV_REQUIRES
driver
esp_driver_i2c
esp_lcd
esp_lcd_sh8601
esp_lcd_touch_cst9217
+13 -1
View File
@@ -17,6 +17,8 @@ static DisplayPort *user_display = NULL;
static qmi8658_dev_t qmi8658;
static char LvglDataBuff[40] = {""};
static uint8_t current_rotation = 0;
static constexpr uint32_t QMI8658_TASK_STACK_SIZE = 6 * 1024;
static constexpr UBaseType_t QMI8658_STACK_WARN_WORDS = 256;
static bool qmi8658_detect_rotation(const qmi8658_data_t *sensor_data, uint8_t *new_rotation)
{
@@ -40,9 +42,11 @@ static bool qmi8658_detect_rotation(const qmi8658_data_t *sensor_data, uint8_t *
}
void QMI8658_Task(void *arg) {
(void)arg;
uint8_t pending_rotation = current_rotation;
int stable_samples = 0;
const int samples_required = 3;
uint32_t loop_count = 0;
while(1) {
bool ready;
@@ -80,6 +84,14 @@ void QMI8658_Task(void *arg) {
}
}
loop_count++;
if((loop_count % 100) == 0) {
UBaseType_t free_words = uxTaskGetStackHighWaterMark(NULL);
if(free_words < QMI8658_STACK_WARN_WORDS) {
ESP_LOGW("qmi8658", "Task low stack watermark: %u words", (unsigned)free_words);
}
}
vTaskDelay(pdMS_TO_TICKS(150));
}
}
@@ -114,5 +126,5 @@ extern "C" void app_main(void) {
qmi8658_set_gyro_unit_rads(&qmi8658, true);
qmi8658_set_display_precision(&qmi8658, 4);
}
xTaskCreatePinnedToCore(QMI8658_Task, "QMI8658_Task", 3 * 1024, NULL, 3, NULL,0);
xTaskCreatePinnedToCore(QMI8658_Task, "QMI8658_Task", QMI8658_TASK_STACK_SIZE, NULL, 2, NULL,0);
}
@@ -1,3 +1,8 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
project(03_I2C_PCF85063)
@@ -3,4 +3,5 @@ idf_component_register(
"i2c_bsp.cpp"
PRIV_REQUIRES
driver
esp_driver_i2c
INCLUDE_DIRS ".")
+5
View File
@@ -1,3 +1,8 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
project(04_SD_Card)
@@ -4,6 +4,7 @@ idf_component_register(
"sdcard_bsp.cpp"
PRIV_REQUIRES
driver
esp_driver_i2c
pmicpower
REQUIRES
esp_driver_sdmmc
+5
View File
@@ -1,3 +1,8 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
project(05_WIFI_STA)
@@ -3,6 +3,7 @@ idf_component_register(
"i2c_bsp.cpp"
PRIV_REQUIRES
driver
esp_driver_i2c
pmicpower
INCLUDE_DIRS
"./")
+5
View File
@@ -1,3 +1,8 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
project(06_WIFI_AP)
+5
View File
@@ -1,4 +1,9 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
set(EXTRA_COMPONENT_DIRS components/ExternLib)
project(07_Audio_Test)
@@ -5,6 +5,7 @@ idf_component_register(
"codec_bsp.cpp"
PRIV_REQUIRES
driver
esp_driver_i2c
pmicpower
espressif__esp_lcd_sh8601
waveshare__esp_lcd_touch_cst9217
@@ -1,3 +1,8 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
project(08_LVGL_V8_Test)
@@ -4,6 +4,7 @@ idf_component_register(
"display_bsp.cpp"
PRIV_REQUIRES
driver
esp_driver_i2c
pmicpower
espressif__esp_lcd_sh8601
waveshare__esp_lcd_touch_cst9217
@@ -1,6 +1,11 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
# Work around managed-component warnings that are promoted by global -Werror.
add_compile_options(-Wno-error=attributes -Wno-error=cpp -Wno-error=missing-field-initializers)
@@ -4,6 +4,7 @@ idf_component_register(
"display_bsp.cpp"
PRIV_REQUIRES
driver
esp_driver_i2c
pmicpower
espressif__esp_lcd_sh8601
waveshare__esp_lcd_touch_cst9217
+5
View File
@@ -1,6 +1,11 @@
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
# ESP-IDF v6 moved i2c_master.h to esp_driver_i2c; expose it for managed components
if(EXISTS "$ENV{IDF_PATH}/components/esp_driver_i2c/include/driver/i2c_master.h")
idf_build_set_property(INCLUDE_DIRECTORIES "$ENV{IDF_PATH}/components/esp_driver_i2c/include" APPEND)
endif()
# Work around managed-component warnings that are promoted by global -Werror.
add_compile_options(-Wno-error=attributes -Wno-error=cpp -Wno-error=missing-field-initializers)
+18
View File
@@ -125,4 +125,22 @@ esp_err_t Lvgl_PortInit(DisplayPort &display) {
void Lvgl_Refresh(void) {
esp_lv_adapter_refresh_now(disp);
}
void Lvgl_HandleRotationChange(void)
{
if(disp == NULL) {
return;
}
#if LVGL_VERSION_MAJOR >= 9
lv_obj_t *screen = lv_screen_active();
#else
lv_obj_t *screen = lv_scr_act();
#endif
if(screen != NULL) {
// Force a full redraw after MADCTL rotation since only dirty regions are usually refreshed.
lv_obj_invalidate(screen);
}
esp_lv_adapter_refresh_now(disp);
}
+1
View File
@@ -5,5 +5,6 @@
esp_err_t Lvgl_PortInit(DisplayPort &display);
void Lvgl_Refresh(void);
void Lvgl_HandleRotationChange(void);
esp_err_t Lvgl_lock(int timeout_ms);
void Lvgl_unlock(void);
+1
View File
@@ -4,6 +4,7 @@ idf_component_register(
"display_bsp.cpp"
PRIV_REQUIRES
driver
esp_driver_i2c
pmicpower
espressif__esp_lcd_sh8601
waveshare__esp_lcd_touch_cst9217
+19 -2
View File
@@ -16,6 +16,8 @@ I2cMasterBus user_i2cbus(7,8,0); //scl,sda,i2c_port
DisplayPort *user_display = NULL;
static qmi8658_dev_t qmi8658;
static uint8_t current_rotation = 0;
static constexpr uint32_t QMI8658_TASK_STACK_SIZE = 6 * 1024;
static constexpr UBaseType_t QMI8658_STACK_WARN_WORDS = 256;
static bool qmi8658_detect_rotation(const qmi8658_data_t *sensor_data, uint8_t *new_rotation)
{
@@ -45,6 +47,7 @@ static void qmi8658_orientation_task(void *arg)
uint8_t pending_rotation = current_rotation;
int stable_samples = 0;
const int samples_required = 3;
uint32_t loop_count = 0;
while(1) {
bool ready = false;
@@ -64,7 +67,13 @@ static void qmi8658_orientation_task(void *arg)
if(stable_samples >= samples_required && user_display != NULL) {
current_rotation = detected_rotation;
user_display->Set_Rotate(current_rotation);
if(Lvgl_lock(200) == ESP_OK) {
user_display->Set_Rotate(current_rotation);
Lvgl_HandleRotationChange();
Lvgl_unlock();
} else {
user_display->Set_Rotate(current_rotation);
}
ESP_LOGI(TAG, "Screen rotation changed to %s", current_rotation ? "landscape" : "portrait");
stable_samples = 0;
}
@@ -75,6 +84,14 @@ static void qmi8658_orientation_task(void *arg)
}
}
loop_count++;
if((loop_count % 100) == 0) {
UBaseType_t free_words = uxTaskGetStackHighWaterMark(NULL);
if(free_words < QMI8658_STACK_WARN_WORDS) {
ESP_LOGW(TAG, "qmi8658 task low stack watermark: %u words", (unsigned)free_words);
}
}
vTaskDelay(pdMS_TO_TICKS(150));
}
}
@@ -106,7 +123,7 @@ extern "C" void app_main(void)
qmi8658_set_accel_unit_mps2(&qmi8658, true);
qmi8658_set_gyro_unit_rads(&qmi8658, true);
qmi8658_set_display_precision(&qmi8658, 4);
xTaskCreatePinnedToCore(qmi8658_orientation_task, "qmi8658_orientation", 3 * 1024, NULL, 3, NULL, 0);
xTaskCreatePinnedToCore(qmi8658_orientation_task, "qmi8658_orientation", QMI8658_TASK_STACK_SIZE, NULL, 2, NULL, 0);
}
if(WifiProvisioning_IsProvisioning()) {