doc: updated commits

This commit is contained in:
aZholtikov committed 2026-10-10 09:22:34 +03:00
1 parent 04ce9746b1
commit 9696b8a0fe
3 files changed
+70 -59

No files matched your search

+21 -17
View File
@@ -18,6 +18,9 @@ static const char *TAG = "zh_160x_i2c";
*
* Internal handle containing the PCF8574 expander pointer and
* the configured LCD size for row address calculations.
*
* @warning The expander handle is owned by the caller and must remain valid
* until the LCD handle is deinitialized.
*/
struct _zh_160x_i2c_handle_t
{
@@ -25,6 +28,8 @@ struct _zh_160x_i2c_handle_t
zh_160x_i2c_lcd_size_t zh_160x_i2c_lcd_size; /*!< Configured LCD size (16x2 or 16x4) */
};
static const uint8_t _lcd_row_addresses[] = {0x00, 0x40, 0x10, 0x50};
/**
* @brief Initialize the LCD 160x display.
*
@@ -35,49 +40,53 @@ struct _zh_160x_i2c_handle_t
* @param handle Pointer to the 160x I2C handle
*
* @return ESP_OK on success
* @return ESP_FAIL if error
* @return ESP_FAIL if any expander write or pulse operation fails
*/
static esp_err_t _zh_160x_lcd_init(zh_160x_i2c_handle_t *handle);
/**
* @brief Send a command to the LCD.
*
* Transmits a command byte to the LCD in 4-bit mode.
* RS pin is set to low (0x08) to indicate command mode.
* Transmits a command byte to the LCD in 4-bit mode. The high and low
* nibbles are sent sequentially on data lines D4-D7 (PCF8574 pins P4-P7),
* each followed by an enable pulse. Bit mask 0x08 keeps pin P3 high;
* RS (pin P0) and E (pin P2) are held low between pulses.
*
* @param handle Pointer to the 160x I2C handle
* @param command Command byte to send
*
* @return ESP_OK on success
* @return ESP_FAIL if error
* @return ESP_FAIL if any expander write or pulse operation fails
*/
static esp_err_t _zh_160x_send_command(zh_160x_i2c_handle_t *handle, uint8_t command);
/**
* @brief Send data to the LCD.
*
* Transmits a data byte to the LCD in 4-bit mode.
* RS pin is set to high (0x09) to indicate data mode.
* Transmits a data byte to the LCD in 4-bit mode. The high and low
* nibbles are sent sequentially on data lines D4-D7 (PCF8574 pins P4-P7),
* each followed by an enable pulse. Bit mask 0x09 sets RS (pin P0) high
* for data mode and keeps pin P3 high; E (pin P2) is held low between pulses.
*
* @param handle Pointer to the 160x I2C handle
* @param data Data byte to send
*
* @return ESP_OK on success
* @return ESP_FAIL if error
* @return ESP_FAIL if any expander write or pulse operation fails
*/
static esp_err_t _zh_160x_send_data(zh_160x_i2c_handle_t *handle, uint8_t data);
/**
* @brief Generate an Enable pulse for the LCD.
* @brief Generate an enable pulse for the LCD.
*
* Toggles the E pin (GPIO2 on PCF8574) to latch data into the LCD.
* Sets E high, delays 1ms, then sets E low with another 1ms delay.
* Toggles the enable line (PCF8574 pin P2) to latch data into the LCD.
* Sets the line high, delays 1ms, then sets it low with another 1ms delay.
* This pulse signals the LCD to process the data on the D4-D7 pins.
*
* @param handle Pointer to the 160x I2C handle
*
* @return ESP_OK on success
* @return ESP_FAIL if error
* @return ESP_FAIL if any GPIO write operation fails
*/
static esp_err_t _zh_160x_pulse(zh_160x_i2c_handle_t *handle);
@@ -118,10 +127,7 @@ esp_err_t zh_160x_set_cursor(zh_160x_i2c_handle_t **handle, uint8_t row, uint8_t
{
ZH_LOGI("160X set cursor started.");
ZH_ERROR_CHECK(handle != NULL && *handle != NULL && row < (((*handle)->zh_160x_i2c_lcd_size == ZH_LCD_16X2) ? 2 : 4) && col < 16, ESP_ERR_INVALID_ARG, NULL, "160X set cursor failed. Invalid argument.");
// clang-format off
ZH_ERROR_CHECK(_zh_160x_send_command(*handle, 0x80 | ((row == 0) ? col : (row == 1) ? (0x40 + col) : (row == 2) ? (0x10 + col) : (0x50 + col))) == ESP_OK,
ESP_FAIL, NULL, "160X set cursor failed. PCF8574 error.");
// clang-format on
ZH_ERROR_CHECK(_zh_160x_send_command(*handle, 0x80 | (_lcd_row_addresses[row] + col)) == ESP_OK, ESP_FAIL, NULL, "160X set cursor failed. PCF8574 error.");
ZH_LOGI("160X set cursor completed successfully.");
return ESP_OK;
}
@@ -225,8 +231,6 @@ static esp_err_t _zh_160x_lcd_init(zh_160x_i2c_handle_t *handle)
ZH_ERROR_CHECK(zh_pcf8574_write(&handle->zh_pcf8574_handle, 0x20) == ESP_OK, ESP_FAIL, NULL, "PCF8574 error.");
ZH_ERROR_CHECK(_zh_160x_pulse(handle) == ESP_OK, ESP_FAIL, NULL, "PCF8574 error.");
ZH_ERROR_CHECK(_zh_160x_send_command(handle, 0x28) == ESP_OK, ESP_FAIL, NULL, "PCF8574 error.");
ZH_ERROR_CHECK(_zh_160x_send_command(handle, 0x28) == ESP_OK, ESP_FAIL, NULL, "PCF8574 error.");
ZH_ERROR_CHECK(_zh_160x_send_command(handle, 0x28) == ESP_OK, ESP_FAIL, NULL, "PCF8574 error.");
ZH_ERROR_CHECK(_zh_160x_send_command(handle, 0x0C) == ESP_OK, ESP_FAIL, NULL, "PCF8574 error.");
ZH_ERROR_CHECK(_zh_160x_send_command(handle, 0x01) == ESP_OK, ESP_FAIL, NULL, "PCF8574 error.");
ZH_ERROR_CHECK(_zh_160x_send_command(handle, 0x06) == ESP_OK, ESP_FAIL, NULL, "PCF8574 error.");