From 467030c97f5f77b9df45a42da16b0bc4de4b6dca Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Sat, 7 Jun 2025 09:22:10 +0300 Subject: [PATCH] feat!: support new version of zh_pcf8574 --- version.txt | 2 +- zh_160x_i2c.c | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/version.txt b/version.txt index 359a5b9..56fea8a 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2.0.0 \ No newline at end of file +3.0.0 \ No newline at end of file diff --git a/zh_160x_i2c.c b/zh_160x_i2c.c index 192d5a4..4d36ba6 100644 --- a/zh_160x_i2c.c +++ b/zh_160x_i2c.c @@ -35,7 +35,9 @@ esp_err_t zh_160x_init(zh_pcf8574_handle_t *handle, bool size) ZH_160X_I2C_LOGI("160X initialization started."); ZH_160X_I2C_CHECK(handle != NULL, ESP_ERR_INVALID_ARG, "160X initialization failed. Invalid argument."); ZH_160X_I2C_CHECK(handle->is_initialized == true, ESP_ERR_INVALID_STATE, "160X initialization failed. PCF8574 not initialized."); - handle->system = size; + handle->system = heap_caps_calloc(1, sizeof(uint8_t), MALLOC_CAP_8BIT); + ZH_160X_I2C_CHECK(handle->system != NULL, ESP_ERR_INVALID_ARG, "160X initialization failed. Memory allocation fail."); + *(uint8_t *)handle->system = size; _zh_160x_lcd_init(handle); ZH_160X_I2C_LOGI("160X initialization completed successfully."); return ESP_OK; @@ -54,7 +56,7 @@ esp_err_t zh_160x_lcd_clear(zh_pcf8574_handle_t *handle) esp_err_t zh_160x_set_cursor(zh_pcf8574_handle_t *handle, uint8_t row, uint8_t col) { ZH_160X_I2C_LOGI("160X set cursor started."); - ZH_160X_I2C_CHECK(row < ((handle->system == ZH_LCD_16X2) ? 2 : 4) && col < 16 && handle != NULL, ESP_ERR_INVALID_ARG, "160X set cursor failed. Invalid argument."); + ZH_160X_I2C_CHECK(row < ((*(uint8_t *)handle->system == ZH_LCD_16X2) ? 2 : 4) && col < 16 && handle != NULL, ESP_ERR_INVALID_ARG, "160X set cursor failed. Invalid argument."); ZH_160X_I2C_CHECK(handle->is_initialized == true, ESP_ERR_INVALID_STATE, "160X set cursor failed. PCF8574 not initialized."); _zh_160x_send_command(handle, 0x80 | ((row == 0) ? col : (row == 1) ? (0x40 + col) : (row == 2) ? (0x10 + col) @@ -103,7 +105,7 @@ esp_err_t zh_160x_print_float(zh_pcf8574_handle_t *handle, float num, uint8_t pr esp_err_t zh_160x_print_progress_bar(zh_pcf8574_handle_t *handle, uint8_t row, uint8_t progress) { ZH_160X_I2C_LOGI("160X print progress bar started."); - ZH_160X_I2C_CHECK(row < ((handle->system == ZH_LCD_16X2) ? 2 : 4) && progress <= 100 && handle != NULL, ESP_ERR_INVALID_ARG, "160X print progress bar failed. Invalid argument."); + ZH_160X_I2C_CHECK(row < ((*(uint8_t *)handle->system == ZH_LCD_16X2) ? 2 : 4) && progress <= 100 && handle != NULL, ESP_ERR_INVALID_ARG, "160X print progress bar failed. Invalid argument."); ZH_160X_I2C_CHECK(handle->is_initialized == true, ESP_ERR_INVALID_STATE, "160X print progress bar failed. PCF8574 not initialized."); uint8_t blocks = (progress * 16) / 100; zh_160x_set_cursor(handle, row, 0); @@ -125,7 +127,7 @@ esp_err_t zh_160x_print_progress_bar(zh_pcf8574_handle_t *handle, uint8_t row, u esp_err_t zh_160x_clear_row(zh_pcf8574_handle_t *handle, uint8_t row) { ZH_160X_I2C_LOGI("160X clear row started."); - ZH_160X_I2C_CHECK(row < ((handle->system == ZH_LCD_16X2) ? 2 : 4) && handle != NULL, ESP_ERR_INVALID_ARG, "160X clear row failed. Invalid argument."); + ZH_160X_I2C_CHECK(row < ((*(uint8_t *)handle->system == ZH_LCD_16X2) ? 2 : 4) && handle != NULL, ESP_ERR_INVALID_ARG, "160X clear row failed. Invalid argument."); ZH_160X_I2C_CHECK(handle->is_initialized == true, ESP_ERR_INVALID_STATE, "160X clear row failed. PCF8574 not initialized."); zh_160x_set_cursor(handle, row, 0); for (uint8_t i = 0; i < 16; ++i)