8 Commits

Author SHA1 Message Date
a5c9d5a376 refactor: refactored by pvs-studio 2026-01-28 20:07:48 +03:00
c32649e826 doc: updated example 2026-01-26 18:02:09 +03:00
fd2ee05992 style: typo 2026-01-26 17:59:21 +03:00
3a87d221bb doc: updated example 2026-01-26 17:50:10 +03:00
2bc4f2f480 doc: updated readme 2026-01-26 17:45:14 +03:00
63bfc0d572 doc: updated readme 2026-01-26 16:04:32 +03:00
e172d045a6 feat: added cursor operations 2026-01-26 15:54:23 +03:00
79f5ed0ad8 doc: updated readme 2026-01-25 21:30:04 +03:00
4 changed files with 70 additions and 17 deletions

View File

@@ -2,7 +2,7 @@
## Tested on ## Tested on
1. [ESP32 ESP-IDF v5.5.1](https://docs.espressif.com/projects/esp-idf/en/v5.5.1/esp32/index.html) 1. [ESP32 ESP-IDF v5.5.2](https://docs.espressif.com/projects/esp-idf/en/v5.5.2/esp32/index.html)
## SAST Tools ## SAST Tools
@@ -12,6 +12,17 @@
1. Support of 16 LCD 160X on one bus. 1. Support of 16 LCD 160X on one bus.
## Attention
For correct operation, please enable the following settings in the menuconfig:
```text
CONFIG_FREERTOS_HZ=1000
CONFIG_GPIO_CTRL_FUNC_IN_IRAM
CONFIG_I2C_ISR_IRAM_SAFE
CONFIG_I2C_MASTER_ISR_HANDLER_IN_IRAM
```
## Connection ## Connection
| 1602(4)A | PCF8574 | | 1602(4)A | PCF8574 |
@@ -25,8 +36,8 @@
## Dependencies ## Dependencies
1. [zh_vector](http://git.zh.com.ru/alexey.zholtikov/zh_vector) 1. [zh_vector](http://git.zh.com.ru/esp_components/zh_vector)
2. [zh_pcf8574](http://git.zh.com.ru/alexey.zholtikov/zh_pcf8574) 2. [zh_pcf8574](http://git.zh.com.ru/esp_components/zh_pcf8574)
## Using ## Using
@@ -34,9 +45,9 @@ In an existing project, run the following command to install the components:
```text ```text
cd ../your_project/components cd ../your_project/components
git clone http://git.zh.com.ru/alexey.zholtikov/zh_160x_i2c git clone http://git.zh.com.ru/esp_components/zh_160x_i2c
git clone http://git.zh.com.ru/alexey.zholtikov/zh_pcf8574 git clone http://git.zh.com.ru/esp_components/zh_pcf8574
git clone http://git.zh.com.ru/alexey.zholtikov/zh_vector git clone http://git.zh.com.ru/esp_components/zh_vector
``` ```
In the application, add the component: In the application, add the component:
@@ -54,8 +65,6 @@ One LCD on bus:
#define I2C_PORT (I2C_NUM_MAX - 1) #define I2C_PORT (I2C_NUM_MAX - 1)
i2c_master_bus_handle_t i2c_bus_handle = NULL;
zh_pcf8574_handle_t lcd_160x_handle = {0}; zh_pcf8574_handle_t lcd_160x_handle = {0};
void app_main(void) void app_main(void)
@@ -71,6 +80,7 @@ void app_main(void)
.glitch_ignore_cnt = 7, .glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true, .flags.enable_internal_pullup = true,
}; };
i2c_master_bus_handle_t i2c_bus_handle = NULL;
i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle); i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle);
zh_pcf8574_init_config_t config = ZH_PCF8574_INIT_CONFIG_DEFAULT(); zh_pcf8574_init_config_t config = ZH_PCF8574_INIT_CONFIG_DEFAULT();
config.i2c_handle = i2c_bus_handle; config.i2c_handle = i2c_bus_handle;
@@ -79,11 +89,13 @@ void app_main(void)
zh_160x_init(&lcd_160x_handle, ZH_LCD_16X2); zh_160x_init(&lcd_160x_handle, ZH_LCD_16X2);
for (;;) for (;;)
{ {
zh_160x_on_cursor(&lcd_160x_handle, true);
zh_160x_set_cursor(&lcd_160x_handle, 0, 0); zh_160x_set_cursor(&lcd_160x_handle, 0, 0);
zh_160x_print_char(&lcd_160x_handle, "LCD 160X"); zh_160x_print_char(&lcd_160x_handle, "LCD 160X");
zh_160x_set_cursor(&lcd_160x_handle, 1, 0); zh_160x_set_cursor(&lcd_160x_handle, 1, 0);
zh_160x_print_char(&lcd_160x_handle, "Hello World!"); zh_160x_print_char(&lcd_160x_handle, "Hello World!");
vTaskDelay(5000 / portTICK_PERIOD_MS); vTaskDelay(5000 / portTICK_PERIOD_MS);
zh_160x_off_cursor(&lcd_160x_handle);
zh_160x_set_cursor(&lcd_160x_handle, 0, 0); zh_160x_set_cursor(&lcd_160x_handle, 0, 0);
zh_160x_print_char(&lcd_160x_handle, "Progress: "); zh_160x_print_char(&lcd_160x_handle, "Progress: ");
for (uint8_t i = 0; i <= 100; ++i) for (uint8_t i = 0; i <= 100; ++i)

View File

@@ -7,7 +7,7 @@
#include "zh_pcf8574.h" #include "zh_pcf8574.h"
#define ZH_LCD_16X2 1 /*!< LCD size 16x2. */ #define ZH_LCD_16X2 1 /*!< LCD size 16x2. */
#define ZH_LCD_16X4 0 /*!< LCD size 16x3. */ #define ZH_LCD_16X4 0 /*!< LCD size 16x4. */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@@ -96,6 +96,25 @@ extern "C"
*/ */
esp_err_t zh_160x_clear_row(zh_pcf8574_handle_t *handle, uint8_t row); esp_err_t zh_160x_clear_row(zh_pcf8574_handle_t *handle, uint8_t row);
/**
* @brief Enable the cursor.
*
* @param[in] handle Pointer to unique PCF8574 handle.
* @param[in] blink Blink mode.
*
* @return ESP_OK if success or an error code otherwise.
*/
esp_err_t zh_160x_on_cursor(zh_pcf8574_handle_t *handle, bool blink);
/**
* @brief Disable the cursor.
*
* @param[in] handle Pointer to unique PCF8574 handle.
*
* @return ESP_OK if success or an error code otherwise.
*/
esp_err_t zh_160x_off_cursor(zh_pcf8574_handle_t *handle);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -1 +1 @@
4.0.0 4.1.0

View File

@@ -18,7 +18,7 @@ static esp_err_t _zh_160x_send_command(zh_pcf8574_handle_t *handle, uint8_t comm
static esp_err_t _zh_160x_send_data(zh_pcf8574_handle_t *handle, uint8_t data); static esp_err_t _zh_160x_send_data(zh_pcf8574_handle_t *handle, uint8_t data);
static esp_err_t _zh_160x_pulse(zh_pcf8574_handle_t *handle); static esp_err_t _zh_160x_pulse(zh_pcf8574_handle_t *handle);
esp_err_t zh_160x_init(zh_pcf8574_handle_t *handle, bool size) esp_err_t zh_160x_init(zh_pcf8574_handle_t *handle, bool size) // -V2008
{ {
ZH_LOGI("160X initialization started."); ZH_LOGI("160X initialization started.");
ZH_ERROR_CHECK(handle != NULL, ESP_ERR_INVALID_ARG, NULL, "160X initialization failed. Invalid argument."); ZH_ERROR_CHECK(handle != NULL, ESP_ERR_INVALID_ARG, NULL, "160X initialization failed. Invalid argument.");
@@ -43,7 +43,7 @@ esp_err_t zh_160x_lcd_clear(zh_pcf8574_handle_t *handle)
return ESP_OK; return ESP_OK;
} }
esp_err_t zh_160x_set_cursor(zh_pcf8574_handle_t *handle, uint8_t row, uint8_t col) esp_err_t zh_160x_set_cursor(zh_pcf8574_handle_t *handle, uint8_t row, uint8_t col) // -V2008
{ {
ZH_LOGI("160X set cursor started."); ZH_LOGI("160X set cursor started.");
ZH_ERROR_CHECK(handle != NULL && row < ((*(uint8_t *)handle->system == ZH_LCD_16X2) ? 2 : 4) && col < 16, ESP_ERR_INVALID_ARG, NULL, "160X set cursor failed. Invalid argument."); ZH_ERROR_CHECK(handle != NULL && row < ((*(uint8_t *)handle->system == ZH_LCD_16X2) ? 2 : 4) && col < 16, ESP_ERR_INVALID_ARG, NULL, "160X set cursor failed. Invalid argument.");
@@ -96,7 +96,7 @@ esp_err_t zh_160x_print_float(zh_pcf8574_handle_t *handle, float num, uint8_t pr
return ESP_OK; return ESP_OK;
} }
esp_err_t zh_160x_print_progress_bar(zh_pcf8574_handle_t *handle, uint8_t row, uint8_t progress) esp_err_t zh_160x_print_progress_bar(zh_pcf8574_handle_t *handle, uint8_t row, uint8_t progress) // -V2008
{ {
ZH_LOGI("160X print progress bar started."); ZH_LOGI("160X print progress bar started.");
ZH_ERROR_CHECK(handle != NULL && row < ((*(uint8_t *)handle->system == ZH_LCD_16X2) ? 2 : 4) && progress <= 100, ESP_ERR_INVALID_ARG, NULL, "160X print progress bar failed. Invalid argument."); ZH_ERROR_CHECK(handle != NULL && row < ((*(uint8_t *)handle->system == ZH_LCD_16X2) ? 2 : 4) && progress <= 100, ESP_ERR_INVALID_ARG, NULL, "160X print progress bar failed. Invalid argument.");
@@ -121,7 +121,7 @@ esp_err_t zh_160x_print_progress_bar(zh_pcf8574_handle_t *handle, uint8_t row, u
return ESP_OK; return ESP_OK;
} }
esp_err_t zh_160x_clear_row(zh_pcf8574_handle_t *handle, uint8_t row) esp_err_t zh_160x_clear_row(zh_pcf8574_handle_t *handle, uint8_t row) // -V2008
{ {
ZH_LOGI("160X clear row started."); ZH_LOGI("160X clear row started.");
ZH_ERROR_CHECK(handle != NULL && row < ((*(uint8_t *)handle->system == ZH_LCD_16X2) ? 2 : 4), ESP_ERR_INVALID_ARG, NULL, "160X clear row failed. Invalid argument."); ZH_ERROR_CHECK(handle != NULL && row < ((*(uint8_t *)handle->system == ZH_LCD_16X2) ? 2 : 4), ESP_ERR_INVALID_ARG, NULL, "160X clear row failed. Invalid argument.");
@@ -139,7 +139,29 @@ esp_err_t zh_160x_clear_row(zh_pcf8574_handle_t *handle, uint8_t row)
return ESP_OK; return ESP_OK;
} }
static esp_err_t _zh_160x_lcd_init(zh_pcf8574_handle_t *handle) esp_err_t zh_160x_on_cursor(zh_pcf8574_handle_t *handle, bool blink)
{
ZH_LOGI("160X enable cursor started.");
ZH_ERROR_CHECK(handle != NULL, ESP_ERR_INVALID_ARG, NULL, "160X enable cursor failed. Invalid argument.");
ZH_ERROR_CHECK(handle->is_initialized == true, ESP_ERR_INVALID_STATE, NULL, "160X enable cursor failed. PCF8574 not initialized.");
esp_err_t err = _zh_160x_send_command(handle, (blink == true) ? 0x0f : 0x0e);
ZH_ERROR_CHECK(err == ESP_OK, err, NULL, "160X enable cursor failed. PCF8574 error.");
ZH_LOGI("160X enable cursor completed successfully.");
return ESP_OK;
}
esp_err_t zh_160x_off_cursor(zh_pcf8574_handle_t *handle)
{
ZH_LOGI("160X disable cursor started.");
ZH_ERROR_CHECK(handle != NULL, ESP_ERR_INVALID_ARG, NULL, "160X disable cursor failed. Invalid argument.");
ZH_ERROR_CHECK(handle->is_initialized == true, ESP_ERR_INVALID_STATE, NULL, "160X disable cursor failed. PCF8574 not initialized.");
esp_err_t err = _zh_160x_send_command(handle, 0x0c);
ZH_ERROR_CHECK(err == ESP_OK, err, NULL, "160X disable cursor failed. PCF8574 error.");
ZH_LOGI("160X disable cursor completed successfully.");
return ESP_OK;
}
static esp_err_t _zh_160x_lcd_init(zh_pcf8574_handle_t *handle) // -V2008
{ {
vTaskDelay(20 / portTICK_PERIOD_MS); vTaskDelay(20 / portTICK_PERIOD_MS);
esp_err_t err = zh_pcf8574_write(handle, 0x30); esp_err_t err = zh_pcf8574_write(handle, 0x30);
@@ -201,10 +223,10 @@ static esp_err_t _zh_160x_send_data(zh_pcf8574_handle_t *handle, uint8_t data)
static esp_err_t _zh_160x_pulse(zh_pcf8574_handle_t *handle) static esp_err_t _zh_160x_pulse(zh_pcf8574_handle_t *handle)
{ {
esp_err_t err = zh_pcf8574_write_gpio(handle, 2, true); esp_err_t err = zh_pcf8574_write_gpio(handle, ZH_PCF8574_GPIO_NUM_P2, ZH_PCF8574_GPIO_HIGH);
ZH_ERROR_CHECK(err == ESP_OK, err, NULL, "PCF8574 error."); ZH_ERROR_CHECK(err == ESP_OK, err, NULL, "PCF8574 error.");
vTaskDelay(1 / portTICK_PERIOD_MS); vTaskDelay(1 / portTICK_PERIOD_MS);
err = zh_pcf8574_write_gpio(handle, 2, false); err = zh_pcf8574_write_gpio(handle, ZH_PCF8574_GPIO_NUM_P2, ZH_PCF8574_GPIO_LOW);
ZH_ERROR_CHECK(err == ESP_OK, err, NULL, "PCF8574 error."); ZH_ERROR_CHECK(err == ESP_OK, err, NULL, "PCF8574 error.");
vTaskDelay(1 / portTICK_PERIOD_MS); vTaskDelay(1 / portTICK_PERIOD_MS);
return ESP_OK; return ESP_OK;