From b0e565d1800b2be582d19a500cffd6125d7c7894 Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Sun, 5 Apr 2026 10:42:25 +0300 Subject: [PATCH] feat: added i2c frequency selection --- include/zh_aht.h | 2 ++ version.txt | 2 +- zh_aht.c | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/zh_aht.h b/include/zh_aht.h index 05ab5c2..3c3872b 100644 --- a/include/zh_aht.h +++ b/include/zh_aht.h @@ -14,6 +14,7 @@ */ #define ZH_AHT_INIT_CONFIG_DEFAULT() \ { \ + .i2c_frequency = 400000, \ .i2c_address = 0x38} #ifdef __cplusplus @@ -28,6 +29,7 @@ extern "C" { i2c_master_bus_handle_t i2c_handle; /*!< Unique I2C bus handle. */ uint8_t i2c_address; /*!< Sensor I2C address. */ + uint32_t i2c_frequency; /*!< Sensor I2C frequency. */ } zh_aht_init_config_t; /** diff --git a/version.txt b/version.txt index 56fea8a..a0cd9f0 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.0.0 \ No newline at end of file +3.1.0 \ No newline at end of file diff --git a/zh_aht.c b/zh_aht.c index 2525fd1..2b4fa8c 100644 --- a/zh_aht.c +++ b/zh_aht.c @@ -63,6 +63,7 @@ esp_err_t zh_aht_reset(zh_aht_handle_t *handle) static esp_err_t _zh_aht_validate_config(const zh_aht_init_config_t *config) { ZH_ERROR_CHECK(config->i2c_address == 0x38 || config->i2c_address == 0x39, ESP_ERR_INVALID_ARG, NULL, "Invalid I2C address."); + ZH_ERROR_CHECK(config->i2c_frequency <= 400000, ESP_ERR_INVALID_ARG, NULL, "Invalid I2C frequency."); ZH_ERROR_CHECK(config->i2c_handle != NULL, ESP_ERR_INVALID_ARG, NULL, "Invalid I2C handle."); return ESP_OK; } @@ -72,7 +73,7 @@ static esp_err_t _zh_aht_i2c_init(const zh_aht_init_config_t *config, zh_aht_han i2c_device_config_t aht_config = { .dev_addr_length = I2C_ADDR_BIT_LEN_7, .device_address = config->i2c_address, - .scl_speed_hz = 100000, + .scl_speed_hz = config->i2c_frequency, }; i2c_master_dev_handle_t _dev_handle = NULL; ZH_ERROR_CHECK(i2c_master_bus_add_device(config->i2c_handle, &aht_config, &_dev_handle) == ESP_OK, ESP_FAIL, NULL, "Add I2C device failed.");