This commit is contained in:
2025-05-08 18:44:00 +03:00
parent c6b2449e51
commit 047a20470e
2 changed files with 8 additions and 9 deletions

View File

@ -26,8 +26,7 @@
.p6_gpio_work_mode = 0, \
.p7_gpio_work_mode = 0, \
.interrupt_gpio = GPIO_NUM_MAX, \
.i2c_port = 0, \
.i2c_handle = NULL}
.i2c_port = 0}
#ifdef __cplusplus
extern "C"

View File

@ -22,7 +22,7 @@ static zh_vector_t _vector = {0};
static esp_err_t _zh_pcf8574_validate_config(const zh_pcf8574_init_config_t *config);
static esp_err_t _zh_pcf8574_configure_i2c_device(const zh_pcf8574_init_config_t *config, zh_pcf8574_handle_t *handle);
static esp_err_t _zh_pcf8574_configure_interrupts(const zh_pcf8574_init_config_t *config, const zh_pcf8574_handle_t handle);
static esp_err_t _zh_pcf8574_configure_interrupts(const zh_pcf8574_init_config_t *config, zh_pcf8574_handle_t handle);
static void _zh_pcf8574_isr_handler(void *arg);
static void _zh_pcf8574_isr_processing_task(void *pvParameter);
static esp_err_t _zh_pcf8574_read_register(zh_pcf8574_handle_t *handle, uint8_t *reg);
@ -38,11 +38,9 @@ esp_err_t zh_pcf8574_init(const zh_pcf8574_init_config_t *config, zh_pcf8574_han
esp_err_t err = _zh_pcf8574_validate_config(config);
ZH_PCF8574_CHECK(err == ESP_OK, err, "PCF8574 initialization failed. Initial configuration check failed.");
ZH_PCF8574_LOGI("PCF8574 initial configuration check completed successfully.");
#ifndef CONFIG_IDF_TARGET_ESP8266
err = _zh_pcf8574_configure_i2c_device(config, handle);
ZH_PCF8574_CHECK(err == ESP_OK, err, "PCF8574 initialization failed. Failed to add I2C device.");
ZH_PCF8574_LOGI("PCF8574 add I2C device completed successfully.");
#endif
err = _zh_pcf8574_write_register(handle, handle->gpio_work_mode);
if (err != ESP_OK)
{
@ -51,7 +49,7 @@ esp_err_t zh_pcf8574_init(const zh_pcf8574_init_config_t *config, zh_pcf8574_han
return err;
}
ZH_PCF8574_LOGI("GPIO setup completed successfully.");
if (config->interrupt_gpio < GPIO_NUM_MAX && config->interrupt_gpio > GPIO_NUM_NC && handle->gpio_work_mode != 0)
if (config->interrupt_gpio < GPIO_NUM_MAX && config->interrupt_gpio >= GPIO_NUM_0 && handle->gpio_work_mode != 0)
{
err = _zh_pcf8574_configure_interrupts(config, *handle);
if (err != ESP_OK)
@ -117,6 +115,7 @@ static esp_err_t _zh_pcf8574_validate_config(const zh_pcf8574_init_config_t *con
static esp_err_t _zh_pcf8574_configure_i2c_device(const zh_pcf8574_init_config_t *config, zh_pcf8574_handle_t *handle)
{
#ifndef CONFIG_IDF_TARGET_ESP8266
i2c_device_config_t pcf8574_config = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = config->i2c_address,
@ -139,19 +138,20 @@ static esp_err_t _zh_pcf8574_configure_i2c_device(const zh_pcf8574_init_config_t
handle->dev_handle = NULL;
return err;
}
handle->i2c_handle = config->i2c_handle;
handle->dev_handle = _dev_handle;
#endif
handle->gpio_work_mode = (config->p7_gpio_work_mode << 7) | (config->p6_gpio_work_mode << 6) | (config->p5_gpio_work_mode << 5) |
(config->p4_gpio_work_mode << 4) | (config->p3_gpio_work_mode << 3) | (config->p2_gpio_work_mode << 2) |
(config->p1_gpio_work_mode << 1) | (config->p0_gpio_work_mode << 0);
handle->gpio_status = handle->gpio_work_mode;
handle->i2c_address = config->i2c_address;
handle->i2c_port = config->i2c_port;
handle->i2c_handle = config->i2c_handle;
handle->dev_handle = _dev_handle;
handle->is_initialized = true;
return ESP_OK;
}
static esp_err_t _zh_pcf8574_configure_interrupts(const zh_pcf8574_init_config_t *config, const zh_pcf8574_handle_t handle)
static esp_err_t _zh_pcf8574_configure_interrupts(const zh_pcf8574_init_config_t *config, zh_pcf8574_handle_t handle)
{
if (_interrupt_gpio != GPIO_NUM_MAX)
{