preparation for switch to C6 MCU (but also compatible with S3)
Some checks failed
ESP-IDF Build / build (esp32c6, release-v5.4) (push) Failing after 2m23s
ESP-IDF Build / build (esp32c6, release-v5.5) (push) Failing after 6m1s
ESP-IDF Build / build (esp32s3, release-v5.4) (push) Failing after 2m17s
ESP-IDF Build / build (esp32s3, release-v5.5) (push) Failing after 5m57s

Signed-off-by: Peter Siegmund <developer@mars3142.org>
This commit is contained in:
2026-02-06 22:30:48 +01:00
parent 684ce36270
commit fe4bd11a21
10 changed files with 180 additions and 166 deletions

View File

@@ -137,6 +137,7 @@ static bool is_valid(const cJSON *string)
esp_err_t api_wifi_config_handler(httpd_req_t *req) esp_err_t api_wifi_config_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/wifi/config"); ESP_LOGI(TAG, "POST /api/wifi/config");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[256]; char buf[256];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);
@@ -250,6 +251,7 @@ esp_err_t api_wifi_status_handler(httpd_req_t *req)
esp_err_t api_light_power_handler(httpd_req_t *req) esp_err_t api_light_power_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/light/power"); ESP_LOGI(TAG, "POST /api/light/power");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[64]; char buf[64];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);
@@ -303,6 +305,7 @@ esp_err_t api_light_thunder_handler(httpd_req_t *req)
esp_err_t api_light_mode_handler(httpd_req_t *req) esp_err_t api_light_mode_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/light/mode"); ESP_LOGI(TAG, "POST /api/light/mode");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[64]; char buf[64];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);
@@ -352,6 +355,7 @@ esp_err_t api_light_mode_handler(httpd_req_t *req)
esp_err_t api_light_schema_handler(httpd_req_t *req) esp_err_t api_light_schema_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/light/schema"); ESP_LOGI(TAG, "POST /api/light/schema");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[128]; char buf[128];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);
@@ -444,6 +448,7 @@ esp_err_t api_wled_config_get_handler(httpd_req_t *req)
esp_err_t api_wled_config_post_handler(httpd_req_t *req) esp_err_t api_wled_config_post_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/wled/config"); ESP_LOGI(TAG, "POST /api/wled/config");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char *buf = heap_caps_malloc(MAX_BODY_SIZE, MALLOC_CAP_DEFAULT); char *buf = heap_caps_malloc(MAX_BODY_SIZE, MALLOC_CAP_DEFAULT);
if (!buf) if (!buf)
@@ -583,6 +588,7 @@ esp_err_t api_schema_get_handler(httpd_req_t *req)
esp_err_t api_schema_post_handler(httpd_req_t *req) esp_err_t api_schema_post_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/schema/*"); ESP_LOGI(TAG, "POST /api/schema/*");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
// Extract filename from URI // Extract filename from URI
if (!req) if (!req)
@@ -676,6 +682,7 @@ esp_err_t api_devices_scan_handler(httpd_req_t *req)
esp_err_t api_devices_pair_handler(httpd_req_t *req) esp_err_t api_devices_pair_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/devices/pair"); ESP_LOGI(TAG, "POST /api/devices/pair");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[256]; char buf[256];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);
@@ -706,6 +713,7 @@ esp_err_t api_devices_paired_handler(httpd_req_t *req)
esp_err_t api_devices_update_handler(httpd_req_t *req) esp_err_t api_devices_update_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/devices/update"); ESP_LOGI(TAG, "POST /api/devices/update");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[256]; char buf[256];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);
@@ -725,6 +733,7 @@ esp_err_t api_devices_update_handler(httpd_req_t *req)
esp_err_t api_devices_unpair_handler(httpd_req_t *req) esp_err_t api_devices_unpair_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/devices/unpair"); ESP_LOGI(TAG, "POST /api/devices/unpair");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[128]; char buf[128];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);
@@ -744,6 +753,7 @@ esp_err_t api_devices_unpair_handler(httpd_req_t *req)
esp_err_t api_devices_toggle_handler(httpd_req_t *req) esp_err_t api_devices_toggle_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/devices/toggle"); ESP_LOGI(TAG, "POST /api/devices/toggle");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[128]; char buf[128];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);
@@ -796,6 +806,7 @@ esp_err_t api_scenes_get_handler(httpd_req_t *req)
esp_err_t api_scenes_post_handler(httpd_req_t *req) esp_err_t api_scenes_post_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/scenes"); ESP_LOGI(TAG, "POST /api/scenes");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[512]; char buf[512];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);
@@ -834,6 +845,7 @@ esp_err_t api_scenes_delete_handler(httpd_req_t *req)
esp_err_t api_scenes_activate_handler(httpd_req_t *req) esp_err_t api_scenes_activate_handler(httpd_req_t *req)
{ {
ESP_LOGI(TAG, "POST /api/scenes/activate"); ESP_LOGI(TAG, "POST /api/scenes/activate");
ESP_LOGI(TAG, "Request content length: %d", req->content_len);
char buf[128]; char buf[128];
int ret = httpd_req_recv(req, buf, sizeof(buf) - 1); int ret = httpd_req_recv(req, buf, sizeof(buf) - 1);

View File

@@ -97,22 +97,21 @@ esp_err_t led_status_init(int gpio_num)
.max_leds = STATUS_LED_COUNT, .max_leds = STATUS_LED_COUNT,
.led_model = LED_MODEL_WS2812, .led_model = LED_MODEL_WS2812,
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRBW, .color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRBW,
.flags = .flags = {.invert_out = 0},
{
.invert_out = false,
},
}; };
led_strip_rmt_config_t rmt_config = { led_strip_rmt_config_t rmt_config = {
.clk_src = RMT_CLK_SRC_DEFAULT, .clk_src = RMT_CLK_SRC_DEFAULT,
.resolution_hz = 10 * 1000 * 1000, // 10MHz .resolution_hz = 10 * 1000 * 1000, // 10MHz
.mem_block_symbols = 0, .mem_block_symbols = 0,
.flags = .flags = {.with_dma = 0},
{
.with_dma = false,
},
}; };
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip)); esp_err_t ret = led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip);
ESP_LOGI(TAG, "LED strip initialized."); if (ret != ESP_OK)
{
ESP_LOGE(TAG, "Failed to init status LED: %s", esp_err_to_name(ret));
return ret;
}
ESP_LOGI(TAG, "Status LED initialized.");
// Create mutex // Create mutex
mutex = xSemaphoreCreateMutex(); mutex = xSemaphoreCreateMutex();

View File

@@ -72,17 +72,21 @@ esp_err_t led_strip_init(void)
.max_leds = MAX_LEDS, .max_leds = MAX_LEDS,
.led_model = LED_MODEL_WS2812, .led_model = LED_MODEL_WS2812,
.color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB, .color_component_format = LED_STRIP_COLOR_COMPONENT_FMT_GRB,
.flags = {.invert_out = false}, .flags = {.invert_out = 0},
}; };
led_strip_rmt_config_t rmt_config = { led_strip_rmt_config_t rmt_config = {
.clk_src = RMT_CLK_SRC_DEFAULT, .clk_src = RMT_CLK_SRC_DEFAULT,
.resolution_hz = 0, .resolution_hz = 0,
.mem_block_symbols = 0, .mem_block_symbols = 0,
.flags = {.with_dma = true}, .flags = {.with_dma = 0},
}; };
esp_err_t ret = led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip);
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &led_strip)); if (ret != ESP_OK)
{
ESP_LOGE(TAG, "Failed to init main LED strip: %s", esp_err_to_name(ret));
return ret;
}
led_command_queue = xQueueCreate(5, sizeof(led_command_t)); led_command_queue = xQueueCreate(5, sizeof(led_command_t));
if (led_command_queue == NULL) if (led_command_queue == NULL)

View File

@@ -6,84 +6,6 @@ menu "System Control"
help help
Enable or disable WiFi connectivity. Enable or disable WiFi connectivity.
config WIFI_NETWORK_COUNT
depends on WIFI_ENABLED
int "Number of WiFi Networks"
default 1
range 1 5
help
Number of WiFi networks to configure (1-5).
config WIFI_SSID_1
depends on WIFI_ENABLED
string "WiFi SSID 1"
default "YourSSID1"
help
The SSID of the first WiFi network.
config WIFI_PASSWORD_1
depends on WIFI_ENABLED
string "WiFi Password 1"
default "YourPassword1"
help
The password of the first WiFi network.
config WIFI_SSID_2
depends on WIFI_ENABLED && WIFI_NETWORK_COUNT >= 2
string "WiFi SSID 2"
default ""
help
The SSID of the second WiFi network.
config WIFI_PASSWORD_2
depends on WIFI_ENABLED && WIFI_NETWORK_COUNT >= 2
string "WiFi Password 2"
default ""
help
The password of the second WiFi network.
config WIFI_SSID_3
depends on WIFI_ENABLED && WIFI_NETWORK_COUNT >= 3
string "WiFi SSID 3"
default ""
help
The SSID of the third WiFi network.
config WIFI_PASSWORD_3
depends on WIFI_ENABLED && WIFI_NETWORK_COUNT >= 3
string "WiFi Password 3"
default ""
help
The password of the third WiFi network.
config WIFI_SSID_4
depends on WIFI_ENABLED && WIFI_NETWORK_COUNT >= 4
string "WiFi SSID 4"
default ""
help
The SSID of the fourth WiFi network.
config WIFI_PASSWORD_4
depends on WIFI_ENABLED && WIFI_NETWORK_COUNT >= 4
string "WiFi Password 4"
default ""
help
The password of the fourth WiFi network.
config WIFI_SSID_5
depends on WIFI_ENABLED && WIFI_NETWORK_COUNT >= 5
string "WiFi SSID 5"
default ""
help
The SSID of the fifth WiFi network.
config WIFI_PASSWORD_5
depends on WIFI_ENABLED && WIFI_NETWORK_COUNT >= 5
string "WiFi Password 5"
default ""
help
The password of the fifth WiFi network.
config WIFI_CONNECT_RETRIES config WIFI_CONNECT_RETRIES
depends on WIFI_ENABLED depends on WIFI_ENABLED
int "WiFi Connection Retry Attempts per Network" int "WiFi Connection Retry Attempts per Network"
@@ -105,4 +27,42 @@ menu "System Control"
help help
GPIO pin number for the SCL line of the display. GPIO pin number for the SCL line of the display.
endmenu endmenu
menu "Button Configuration"
config BUTTON_UP
int "Button UP GPIO Pin"
default 1
help
GPIO pin number for the up button.
config BUTTON_DOWN
int "Button DOWN GPIO Pin"
default 6
help
GPIO pin number for the down button.
config BUTTON_LEFT
int "Button LEFT GPIO Pin"
default 3
help
GPIO pin number for the left button.
config BUTTON_RIGHT
int "Button RIGHT GPIO Pin"
default 5
help
GPIO pin number for the right button.
config BUTTON_SELECT
int "Button SELECT GPIO Pin"
default 18
help
GPIO pin number for the select button.
config BUTTON_BACK
int "Button BACK GPIO Pin"
default 16
help
GPIO pin number for the back button.
endmenu
endmenu endmenu

View File

@@ -1,8 +1,10 @@
#pragma once #pragma once
#define BUTTON_UP GPIO_NUM_1 #include "driver/gpio.h"
#define BUTTON_DOWN GPIO_NUM_6
#define BUTTON_LEFT GPIO_NUM_3 #define BUTTON_UP ((gpio_num_t)CONFIG_BUTTON_UP)
#define BUTTON_RIGHT GPIO_NUM_5 #define BUTTON_DOWN ((gpio_num_t)CONFIG_BUTTON_DOWN)
#define BUTTON_SELECT GPIO_NUM_18 #define BUTTON_LEFT ((gpio_num_t)CONFIG_BUTTON_LEFT)
#define BUTTON_BACK GPIO_NUM_16 #define BUTTON_RIGHT ((gpio_num_t)CONFIG_BUTTON_RIGHT)
#define BUTTON_SELECT ((gpio_num_t)CONFIG_BUTTON_SELECT)
#define BUTTON_BACK ((gpio_num_t)CONFIG_BUTTON_BACK)

View File

@@ -13,10 +13,11 @@
#include "u8g2.h" #include "u8g2.h"
#include "driver/gpio.h" #include "driver/gpio.h"
#include "driver/i2c.h"
#include "driver/spi_master.h" #include "driver/spi_master.h"
#include "hal/i2c_types.h" #include "hal/i2c_types.h"
#include "driver/i2c_master.h"
#define U8G2_ESP32_HAL_UNDEFINED GPIO_NUM_NC #define U8G2_ESP32_HAL_UNDEFINED GPIO_NUM_NC
#define I2C_MASTER_NUM I2C_NUM_0 // I2C port number for master dev #define I2C_MASTER_NUM I2C_NUM_0 // I2C port number for master dev

View File

@@ -13,7 +13,11 @@ static const char *TAG = "u8g2_hal";
static const unsigned int I2C_TIMEOUT_MS = 1000; static const unsigned int I2C_TIMEOUT_MS = 1000;
static spi_device_handle_t handle_spi; // SPI handle. static spi_device_handle_t handle_spi; // SPI handle.
static i2c_cmd_handle_t handle_i2c; // I2C handle. static i2c_master_bus_handle_t i2c_bus; // I2C bus handle (new driver).
static i2c_master_dev_handle_t i2c_dev; // I2C device handle (new driver).
static uint8_t i2c_tx_buf[256]; // Buffer for one I2C transaction.
static size_t i2c_tx_len; // Current length in buffer.
static uint8_t current_i2c_addr7; // Current 7-bit device address.
static u8g2_esp32_hal_t u8g2_esp32_hal; // HAL state data. static u8g2_esp32_hal_t u8g2_esp32_hal; // HAL state data.
static bool i2c_transfer_failed = false; // Flag to track I2C transfer errors static bool i2c_transfer_failed = false; // Flag to track I2C transfer errors
@@ -148,21 +152,23 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
break; break;
} }
i2c_config_t conf = {0}; // Neue I2C-Master-API: Bus einmalig anlegen
conf.mode = I2C_MODE_MASTER; if (i2c_bus == NULL)
ESP_LOGI(TAG, "sda_io_num %d", u8g2_esp32_hal.bus.i2c.sda); {
conf.sda_io_num = u8g2_esp32_hal.bus.i2c.sda; i2c_master_bus_config_t bus_cfg = {
conf.sda_pullup_en = GPIO_PULLUP_ENABLE; .i2c_port = I2C_MASTER_NUM,
ESP_LOGI(TAG, "scl_io_num %d", u8g2_esp32_hal.bus.i2c.scl); .scl_io_num = u8g2_esp32_hal.bus.i2c.scl,
conf.scl_io_num = u8g2_esp32_hal.bus.i2c.scl; .sda_io_num = u8g2_esp32_hal.bus.i2c.sda,
conf.scl_pullup_en = GPIO_PULLUP_ENABLE; .clk_source = I2C_CLK_SRC_DEFAULT,
ESP_LOGI(TAG, "clk_speed %d", I2C_MASTER_FREQ_HZ); .flags = {.enable_internal_pullup = true},
conf.master.clk_speed = I2C_MASTER_FREQ_HZ; };
ESP_LOGI(TAG, "i2c_param_config %d", conf.mode);
ESP_ERROR_CHECK(i2c_param_config(I2C_MASTER_NUM, &conf)); ESP_LOGI(TAG, "sda_io_num %d", u8g2_esp32_hal.bus.i2c.sda);
ESP_LOGI(TAG, "i2c_driver_install %d", I2C_MASTER_NUM); ESP_LOGI(TAG, "scl_io_num %d", u8g2_esp32_hal.bus.i2c.scl);
ESP_ERROR_CHECK( ESP_LOGI(TAG, "clk_speed %d", I2C_MASTER_FREQ_HZ);
i2c_driver_install(I2C_MASTER_NUM, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0)); ESP_LOGI(TAG, "i2c_new_master_bus %d", I2C_MASTER_NUM);
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_cfg, &i2c_bus));
}
break; break;
} }
@@ -174,37 +180,55 @@ uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void
uint8_t *data_ptr = (uint8_t *)arg_ptr; uint8_t *data_ptr = (uint8_t *)arg_ptr;
ESP_LOG_BUFFER_HEXDUMP(TAG, data_ptr, arg_int, ESP_LOG_VERBOSE); ESP_LOG_BUFFER_HEXDUMP(TAG, data_ptr, arg_int, ESP_LOG_VERBOSE);
while (arg_int > 0) // Bytes in lokalen Puffer sammeln, tatsächliche Übertragung bei END_TRANSFER
if (i2c_tx_len + (size_t)arg_int > sizeof(i2c_tx_buf))
{ {
I2C_ERROR_CHECK(i2c_master_write_byte(handle_i2c, *data_ptr, ACK_CHECK_EN)); ESP_LOGW(TAG, "I2C tx buffer overflow (%zu + %d)", i2c_tx_len, arg_int);
if (i2c_transfer_failed) i2c_transfer_failed = true;
{ break;
break;
}
data_ptr++;
arg_int--;
} }
memcpy(&i2c_tx_buf[i2c_tx_len], data_ptr, arg_int);
i2c_tx_len += (size_t)arg_int;
break; break;
} }
case U8X8_MSG_BYTE_START_TRANSFER: { case U8X8_MSG_BYTE_START_TRANSFER: {
uint8_t i2c_address = u8x8_GetI2CAddress(u8x8); uint8_t i2c_address = u8x8_GetI2CAddress(u8x8);
handle_i2c = i2c_cmd_link_create();
i2c_transfer_failed = false; // Reset error flag at start of transfer
ESP_LOGD(TAG, "Start I2C transfer to %02X.", i2c_address >> 1); ESP_LOGD(TAG, "Start I2C transfer to %02X.", i2c_address >> 1);
I2C_ERROR_CHECK(i2c_master_start(handle_i2c)); i2c_transfer_failed = false; // Reset error flag at start of transfer
I2C_ERROR_CHECK(i2c_master_write_byte(handle_i2c, i2c_address | I2C_MASTER_WRITE, ACK_CHECK_EN));
// Für neuen Treiber: Device-Handle für diese 7-Bit-Adresse anlegen (oder wiederverwenden)
uint8_t addr7 = i2c_address >> 1;
if (i2c_dev == NULL || addr7 != current_i2c_addr7)
{
if (i2c_dev)
{
i2c_master_bus_rm_device(i2c_dev);
i2c_dev = NULL;
}
i2c_device_config_t dev_cfg = {
.device_address = addr7,
.scl_speed_hz = I2C_MASTER_FREQ_HZ,
};
ESP_ERROR_CHECK(i2c_master_bus_add_device(i2c_bus, &dev_cfg, &i2c_dev));
current_i2c_addr7 = addr7;
}
i2c_tx_len = 0;
break; break;
} }
case U8X8_MSG_BYTE_END_TRANSFER: { case U8X8_MSG_BYTE_END_TRANSFER: {
ESP_LOGD(TAG, "End I2C transfer."); ESP_LOGD(TAG, "End I2C transfer.");
if (!i2c_transfer_failed) if (!i2c_transfer_failed && i2c_dev != NULL && i2c_tx_len > 0)
{ {
I2C_ERROR_CHECK(i2c_master_stop(handle_i2c)); esp_err_t rc = i2c_master_transmit(i2c_dev, i2c_tx_buf, i2c_tx_len, I2C_TIMEOUT_MS);
I2C_ERROR_CHECK(i2c_master_cmd_begin(I2C_MASTER_NUM, handle_i2c, pdMS_TO_TICKS(I2C_TIMEOUT_MS))); if (rc != ESP_OK)
{
ESP_LOGW(TAG, "I2C error: i2c_master_transmit = %d", rc);
i2c_transfer_failed = true;
}
} }
i2c_cmd_link_delete(handle_i2c);
break; break;
} }
} }

View File

@@ -1,56 +1,41 @@
#include "i2c_checker.h" #include "i2c_checker.h"
#include "driver/i2c.h" #include "driver/i2c_master.h"
#include "esp_insights.h" #include "esp_insights.h"
#include "esp_log.h" #include "esp_log.h"
#include "hal/u8g2_esp32_hal.h" #include "hal/u8g2_esp32_hal.h"
static const char *TAG = "i2c_checker"; static const char *TAG = "i2c_checker";
esp_err_t i2c_device_check(i2c_port_t i2c_port, uint8_t device_address) static esp_err_t i2c_device_check(i2c_master_bus_handle_t i2c_bus, uint8_t device_address)
{ {
i2c_cmd_handle_t cmd = i2c_cmd_link_create(); // Use the new I2C master driver to probe for the device.
i2c_master_start(cmd); return i2c_master_probe(i2c_bus, device_address, 100);
// Send the device address with the write bit (LSB = 0)
i2c_master_write_byte(cmd, (device_address << 1) | I2C_MASTER_WRITE, true);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(i2c_port, cmd, pdMS_TO_TICKS(100));
i2c_cmd_link_delete(cmd);
return ret;
} }
esp_err_t i2c_bus_scan_and_check(void) esp_err_t i2c_bus_scan_and_check(void)
{ {
// 1. Configure and install I2C bus // 1. Configure and create I2C master bus using the new driver API
i2c_config_t conf = { i2c_master_bus_handle_t i2c_bus = NULL;
.mode = I2C_MODE_MASTER, i2c_master_bus_config_t bus_cfg = {
.sda_io_num = I2C_MASTER_SDA_PIN, .i2c_port = I2C_MASTER_NUM,
.scl_io_num = I2C_MASTER_SCL_PIN, .scl_io_num = I2C_MASTER_SCL_PIN,
.sda_pullup_en = GPIO_PULLUP_ENABLE, .sda_io_num = I2C_MASTER_SDA_PIN,
.scl_pullup_en = GPIO_PULLUP_ENABLE, .clk_source = I2C_CLK_SRC_DEFAULT,
.master.clk_speed = I2C_MASTER_FREQ_HZ, .flags = {.enable_internal_pullup = true},
}; };
esp_err_t err = i2c_param_config(I2C_MASTER_NUM, &conf);
esp_err_t err = i2c_new_master_bus(&bus_cfg, &i2c_bus);
if (err != ESP_OK) if (err != ESP_OK)
{ {
ESP_LOGE(TAG, "I2C parameter configuration failed: %s", esp_err_to_name(err)); ESP_LOGE(TAG, "I2C bus creation failed: %s", esp_err_to_name(err));
return err; return err;
} }
err = i2c_driver_install(I2C_MASTER_NUM, conf.mode, 0, 0, 0); ESP_LOGI(TAG, "I2C master bus initialized. Searching for device...");
if (err != ESP_OK)
{
ESP_LOGE(TAG, "I2C driver installation failed: %s", esp_err_to_name(err));
return err;
}
ESP_LOGI(TAG, "I2C driver initialized. Searching for device..."); // 2. Check if the device is present using the new API
err = i2c_device_check(i2c_bus, DISPLAY_I2C_ADDRESS);
// 2. Check if the device is present
err = i2c_device_check(I2C_MASTER_NUM, DISPLAY_I2C_ADDRESS);
if (err == ESP_OK) if (err == ESP_OK)
{ {
@@ -66,9 +51,13 @@ esp_err_t i2c_bus_scan_and_check(void)
ESP_LOGE(TAG, "Error communicating with address 0x%02X: %s", DISPLAY_I2C_ADDRESS, esp_err_to_name(err)); ESP_LOGE(TAG, "Error communicating with address 0x%02X: %s", DISPLAY_I2C_ADDRESS, esp_err_to_name(err));
} }
// 3. Uninstall I2C driver if it is no longer needed // 3. Delete I2C master bus if it is no longer needed
i2c_driver_delete(I2C_MASTER_NUM); esp_err_t del_err = i2c_del_master_bus(i2c_bus);
ESP_DIAG_EVENT(TAG, "I2C driver uninstalled."); if (del_err != ESP_OK)
{
ESP_LOGW(TAG, "Failed to delete I2C master bus: %s", esp_err_to_name(del_err));
}
ESP_DIAG_EVENT(TAG, "I2C master bus deleted.");
return err; return err;
} }

View File

@@ -45,3 +45,8 @@ CONFIG_SPIRAM_USE_CAPS_ALLOC=y
# HTTP Server WebSocket Support # HTTP Server WebSocket Support
CONFIG_HTTPD_WS_SUPPORT=y CONFIG_HTTPD_WS_SUPPORT=y
# MQTT
CONFIG_MQTT_CLIENT_BROKER_URL="mqtts://mqtt.mars3142.dev:8883"
CONFIG_MQTT_CLIENT_USERNAME="mars3142"
CONFIG_MQTT_CLIENT_PASSWORD="KPkEyzs9aur3Y7LfEybnd8PsxWd94ouQZGNGJ24y"

View File

@@ -1,2 +1,20 @@
# default ESP target # default ESP target
CONFIG_IDF_TARGET="esp32c6" CONFIG_IDF_TARGET="esp32c6"
#
# Display Settings
#
CONFIG_DISPLAY_SDA_PIN=9
CONFIG_DISPLAY_SCL_PIN=8
# end of Display Settings
#
# Button Configuration
#
CONFIG_BUTTON_UP=7
CONFIG_BUTTON_DOWN=4
CONFIG_BUTTON_LEFT=6
CONFIG_BUTTON_RIGHT=5
CONFIG_BUTTON_SELECT=19
CONFIG_BUTTON_BACK=20
# end of Button Configuration