perf: added support new version of zh_vector

This commit is contained in:
aZholtikov committed 2026-07-17 09:08:06 +03:00
1 parent ad16715ab3
commit e7c19680ae
4 files changed
+32 -24

No files matched your search

+4 -4
View File
@@ -36,25 +36,25 @@ The component is designed specifically for ESP32 microcontrollers and uses ESP-I
## Installation ## Installation
1. Navigate to your project's components directory: Navigate to your project's components directory:
```bash ```bash
cd ../your_project/components cd ../your_project/components
``` ```
2. Clone the repository: Clone the repository:
```bash ```bash
git clone https://github.com/aZholtikov/zh_pcf8574.git git clone https://github.com/aZholtikov/zh_pcf8574.git
``` ```
3. In your application, include the header: In your application, include the header:
```c ```c
#include "zh_pcf8574.h" #include "zh_pcf8574.h"
``` ```
4. The component will be automatically built with your project. The component will be automatically built with your project.
### Required menuconfig Settings ### Required menuconfig Settings
+4 -4
View File
@@ -36,25 +36,25 @@
## Установка ## Установка
1. Перейдите в каталог компонентов вашего проекта: Перейдите в каталог компонентов вашего проекта:
```bash ```bash
cd ../ваш_проект/components cd ../ваш_проект/components
``` ```
2. Клонируйте репозиторий: Клонируйте репозиторий:
```bash ```bash
git clone https://github.com/aZholtikov/zh_pcf8574.git git clone https://github.com/aZholtikov/zh_pcf8574.git
``` ```
3. В вашем приложении подключите заголовочный файл: В вашем приложении подключите заголовочный файл:
```c ```c
#include "zh_pcf8574.h" #include "zh_pcf8574.h"
``` ```
4. Компонент будет автоматически собран вместе с вашим проектом. Компонент будет автоматически собран вместе с вашим проектом.
### Обязательные настройки в menuconfig ### Обязательные настройки в menuconfig
+1
View File
@@ -8,3 +8,4 @@ dependencies:
idf: ">=5.0" idf: ">=5.0"
zh_vector: zh_vector:
git: "https://github.com/aZholtikov/zh_vector.git" git: "https://github.com/aZholtikov/zh_vector.git"
version: "dev"
+23 -16
View File
@@ -21,7 +21,7 @@ volatile static uint8_t _i2c_matrix[16] = {0};
static const uint8_t _gpio_matrix[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80}; static const uint8_t _gpio_matrix[8] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
static zh_pcf8574_stats_t _stats = {0}; static zh_pcf8574_stats_t _stats = {0};
static zh_vector_t _vector = {0}; static zh_vector_t *_vector = NULL;
static esp_err_t _zh_pcf8574_validate_config(const zh_pcf8574_init_config_t *config); static esp_err_t _zh_pcf8574_validate_config(const zh_pcf8574_init_config_t *config);
static esp_err_t _zh_pcf8574_gpio_init(const zh_pcf8574_init_config_t *config, zh_pcf8574_handle_t *handle); static esp_err_t _zh_pcf8574_gpio_init(const zh_pcf8574_init_config_t *config, zh_pcf8574_handle_t *handle);
@@ -85,20 +85,19 @@ esp_err_t zh_pcf8574_deinit(zh_pcf8574_handle_t *handle) // -V2008
ZH_ERROR_CHECK(handle->is_initialized == true, ESP_ERR_INVALID_STATE, NULL, "PCF8574 deinitialization failed. PCF8574 not initialized."); ZH_ERROR_CHECK(handle->is_initialized == true, ESP_ERR_INVALID_STATE, NULL, "PCF8574 deinitialization failed. PCF8574 not initialized.");
if (_interrupt_gpio < GPIO_NUM_MAX && handle->gpio_work_mode != 0) if (_interrupt_gpio < GPIO_NUM_MAX && handle->gpio_work_mode != 0)
{ {
int16_t vector_size = (int16_t)zh_vector_get_size(&_vector); uint16_t vector_size = 0;
ZH_ERROR_CHECK(vector_size != ESP_FAIL, ESP_ERR_INVALID_STATE, NULL, "PCF8574 deinitialization failed. Vector get size fail."); ZH_ERROR_CHECK(zh_vector_get_size(&_vector, &vector_size) == ESP_OK, ESP_ERR_INVALID_STATE, NULL, "PCF8574 deinitialization failed. Vector get size fail.");
for (uint16_t i = 0; i < vector_size; ++i) for (uint16_t i = 0; i < vector_size; ++i)
{ {
zh_pcf8574_handle_t *temp_handle = zh_vector_get_item(&_vector, i); zh_pcf8574_handle_t temp_handle = {0};
ZH_ERROR_CHECK(temp_handle != NULL, ESP_ERR_INVALID_STATE, NULL, "PCF8574 deinitialization failed. Vector get item fail."); ZH_ERROR_CHECK(zh_vector_get_item(&_vector, i, &temp_handle) == ESP_OK, ESP_ERR_INVALID_STATE, NULL, "PCF8574 deinitialization failed. Vector get item fail.");
if (handle->i2c_address == temp_handle->i2c_address) if (handle->i2c_address == temp_handle.i2c_address)
{ {
ZH_ERROR_CHECK(zh_vector_delete_item(&_vector, i) == ESP_OK, ESP_FAIL, NULL, "PCF8574 deinitialization failed. Vector delete item fail."); ZH_ERROR_CHECK(zh_vector_delete_item(&_vector, i) == ESP_OK, ESP_FAIL, NULL, "PCF8574 deinitialization failed. Vector delete item fail.");
break; break;
} }
} }
vector_size = (int16_t)zh_vector_get_size(&_vector); ZH_ERROR_CHECK(zh_vector_get_size(&_vector, &vector_size) == ESP_OK, ESP_ERR_INVALID_STATE, NULL, "PCF8574 deinitialization failed. Vector get size fail.");
ZH_ERROR_CHECK(vector_size != ESP_FAIL, ESP_ERR_INVALID_STATE, NULL, "PCF8574 deinitialization failed. Vector get size fail.");
if (vector_size == 0) if (vector_size == 0)
{ {
ZH_ERROR_CHECK(gpio_isr_handler_remove(_interrupt_gpio) == ESP_OK, ESP_FAIL, NULL, "PCF8574 deinitialization failed. Remove GPIO isr handler failed."); ZH_ERROR_CHECK(gpio_isr_handler_remove(_interrupt_gpio) == ESP_OK, ESP_FAIL, NULL, "PCF8574 deinitialization failed. Remove GPIO isr handler failed.");
@@ -310,8 +309,8 @@ static void IRAM_ATTR _zh_pcf8574_isr_processing_task(void *pvParameter)
for (;;) for (;;)
{ {
xSemaphoreTake(_interrupt_semaphore, portMAX_DELAY); xSemaphoreTake(_interrupt_semaphore, portMAX_DELAY);
int16_t vector_size = (int16_t)zh_vector_get_size(&_vector); uint16_t vector_size = 0;
if (vector_size == ESP_FAIL) if (zh_vector_get_size(&_vector, &vector_size) != ESP_OK)
{ {
++_stats.vector_error; ++_stats.vector_error;
ZH_LOGE("PCF8574 isr processing failed. Failed to get vector size.", ESP_FAIL); ZH_LOGE("PCF8574 isr processing failed. Failed to get vector size.", ESP_FAIL);
@@ -320,26 +319,34 @@ static void IRAM_ATTR _zh_pcf8574_isr_processing_task(void *pvParameter)
{ {
for (uint16_t i = 0; i < vector_size; ++i) for (uint16_t i = 0; i < vector_size; ++i)
{ {
zh_pcf8574_handle_t *handle = zh_vector_get_item(&_vector, i); zh_pcf8574_handle_t handle = {0};
if (handle == NULL) esp_err_t err = zh_vector_get_item(&_vector, i, &handle);
if (err != ESP_OK)
{ {
++_stats.vector_error; ++_stats.vector_error;
ZH_LOGE("PCF8574 isr processing failed. Failed to get vector item data.", ESP_FAIL); ZH_LOGE("PCF8574 isr processing failed. Failed to get vector item data.", ESP_FAIL);
continue; continue;
} }
zh_pcf8574_event_on_isr_t event = {0}; zh_pcf8574_event_on_isr_t event = {0};
event.i2c_address = handle->i2c_address; event.i2c_address = handle.i2c_address;
uint8_t old_reg = handle->gpio_status; uint8_t old_reg = handle.gpio_status;
uint8_t new_reg = 0; uint8_t new_reg = 0;
esp_err_t err = _zh_pcf8574_read_register(handle, &new_reg); err = _zh_pcf8574_read_register(&handle, &new_reg);
if (err != ESP_OK) if (err != ESP_OK)
{ {
ZH_LOGE("PCF8574 isr processing failed. Failed to read expander register.", err); ZH_LOGE("PCF8574 isr processing failed. Failed to read expander register.", err);
continue; continue;
} }
err = zh_vector_change_item(&_vector, i, &handle);
if (err != ESP_OK)
{
++_stats.vector_error;
ZH_LOGE("PCF8574 isr processing failed. Failed to change vector item data.", ESP_FAIL);
continue;
}
for (uint8_t j = 0; j <= 7; ++j) for (uint8_t j = 0; j <= 7; ++j)
{ {
if ((handle->gpio_work_mode & _gpio_matrix[j]) != 0) if ((handle.gpio_work_mode & _gpio_matrix[j]) != 0)
{ {
if ((old_reg & _gpio_matrix[j]) != (new_reg & _gpio_matrix[j])) if ((old_reg & _gpio_matrix[j]) != (new_reg & _gpio_matrix[j]))
{ {