feat: added i2c frequency selection

This commit is contained in:
aZholtikov committed 2026-03-21 11:51:55 +03:00
1 parent c47407fc83
commit 6c77273187
3 files changed
+5 -2

No files matched your search

+2
View File
@@ -26,6 +26,7 @@
.task_priority = 1, \ .task_priority = 1, \
.stack_size = configMINIMAL_STACK_SIZE, \ .stack_size = configMINIMAL_STACK_SIZE, \
.i2c_address = 0xFF, \ .i2c_address = 0xFF, \
.i2c_frequency = 100000, \
.p0_gpio_work_mode = ZH_PCF8574_GPIO_OUTPUT, \ .p0_gpio_work_mode = ZH_PCF8574_GPIO_OUTPUT, \
.p1_gpio_work_mode = ZH_PCF8574_GPIO_OUTPUT, \ .p1_gpio_work_mode = ZH_PCF8574_GPIO_OUTPUT, \
.p2_gpio_work_mode = ZH_PCF8574_GPIO_OUTPUT, \ .p2_gpio_work_mode = ZH_PCF8574_GPIO_OUTPUT, \
@@ -65,6 +66,7 @@ extern "C"
typedef struct typedef struct
{ {
i2c_master_bus_handle_t i2c_handle; /*!< Unique I2C bus handle. @attention Must be same for all PCF8574 expanders. */ i2c_master_bus_handle_t i2c_handle; /*!< Unique I2C bus handle. @attention Must be same for all PCF8574 expanders. */
uint32_t i2c_frequency; /*!< Expander I2C frequency. */
uint16_t stack_size; /*!< Stack size for task for the PCF8574 expander isr processing processing. @note The minimum size is configMINIMAL_STACK_SIZE. */ uint16_t stack_size; /*!< Stack size for task for the PCF8574 expander isr processing processing. @note The minimum size is configMINIMAL_STACK_SIZE. */
uint8_t task_priority; /*!< Task priority for the PCF8574 expander isr processing. @note Minimum value is 1. */ uint8_t task_priority; /*!< Task priority for the PCF8574 expander isr processing. @note Minimum value is 1. */
uint8_t i2c_address; /*!< Expander I2C address. */ uint8_t i2c_address; /*!< Expander I2C address. */
+1 -1
View File
@@ -1 +1 @@
2.6.0 2.7.0
+2 -1
View File
@@ -224,6 +224,7 @@ void zh_pcf8574_reset_stats(void)
static esp_err_t _zh_pcf8574_validate_config(const zh_pcf8574_init_config_t *config) // -V2008 static esp_err_t _zh_pcf8574_validate_config(const zh_pcf8574_init_config_t *config) // -V2008
{ {
ZH_ERROR_CHECK((config->i2c_address >= 0x20 && config->i2c_address <= 0x27) || (config->i2c_address >= 0x38 && config->i2c_address <= 0x3F), ESP_ERR_INVALID_ARG, NULL, "Invalid I2C address."); ZH_ERROR_CHECK((config->i2c_address >= 0x20 && config->i2c_address <= 0x27) || (config->i2c_address >= 0x38 && config->i2c_address <= 0x3F), ESP_ERR_INVALID_ARG, NULL, "Invalid I2C address.");
ZH_ERROR_CHECK(config->i2c_frequency <= 100000, ESP_ERR_INVALID_ARG, NULL, "Invalid I2C frequency.");
ZH_ERROR_CHECK(config->task_priority >= 1 && config->stack_size >= configMINIMAL_STACK_SIZE, ESP_ERR_INVALID_ARG, NULL, "Invalid task settings."); ZH_ERROR_CHECK(config->task_priority >= 1 && config->stack_size >= configMINIMAL_STACK_SIZE, ESP_ERR_INVALID_ARG, NULL, "Invalid task settings.");
ZH_ERROR_CHECK(config->interrupt_gpio <= GPIO_NUM_MAX, ESP_ERR_INVALID_ARG, NULL, "Invalid GPIO number."); ZH_ERROR_CHECK(config->interrupt_gpio <= GPIO_NUM_MAX, ESP_ERR_INVALID_ARG, NULL, "Invalid GPIO number.");
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.");
@@ -279,7 +280,7 @@ static esp_err_t _zh_pcf8574_i2c_init(const zh_pcf8574_init_config_t *config, zh
i2c_device_config_t pcf8574_config = { i2c_device_config_t pcf8574_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;
esp_err_t err = i2c_master_bus_add_device(config->i2c_handle, &pcf8574_config, &_dev_handle); esp_err_t err = i2c_master_bus_add_device(config->i2c_handle, &pcf8574_config, &_dev_handle);