feat: added i2c frequency selection

This commit is contained in:
aZholtikov committed 2026-04-05 10:42:25 +03:00
1 parent 5269a4bade
commit b0e565d180
3 files changed
+5 -2

No files matched your search

+2
View File
@@ -14,6 +14,7 @@
*/ */
#define ZH_AHT_INIT_CONFIG_DEFAULT() \ #define ZH_AHT_INIT_CONFIG_DEFAULT() \
{ \ { \
.i2c_frequency = 400000, \
.i2c_address = 0x38} .i2c_address = 0x38}
#ifdef __cplusplus #ifdef __cplusplus
@@ -28,6 +29,7 @@ extern "C"
{ {
i2c_master_bus_handle_t i2c_handle; /*!< Unique I2C bus handle. */ i2c_master_bus_handle_t i2c_handle; /*!< Unique I2C bus handle. */
uint8_t i2c_address; /*!< Sensor I2C address. */ uint8_t i2c_address; /*!< Sensor I2C address. */
uint32_t i2c_frequency; /*!< Sensor I2C frequency. */
} zh_aht_init_config_t; } zh_aht_init_config_t;
/** /**
+1 -1
View File
@@ -1 +1 @@
3.0.0 3.1.0
+2 -1
View File
@@ -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) 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_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."); ZH_ERROR_CHECK(config->i2c_handle != NULL, ESP_ERR_INVALID_ARG, NULL, "Invalid I2C handle.");
return ESP_OK; 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 = { i2c_device_config_t aht_config = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7, .dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = config->i2c_address, .device_address = config->i2c_address,
.scl_speed_hz = 100000, .scl_speed_hz = config->i2c_frequency,
}; };
i2c_master_dev_handle_t _dev_handle = NULL; 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."); ZH_ERROR_CHECK(i2c_master_bus_add_device(config->i2c_handle, &aht_config, &_dev_handle) == ESP_OK, ESP_FAIL, NULL, "Add I2C device failed.");