diff --git a/include/zh_ttp229.h b/include/zh_ttp229.h index 13fc248..5392efc 100644 --- a/include/zh_ttp229.h +++ b/include/zh_ttp229.h @@ -128,6 +128,7 @@ extern "C" * @return ESP_OK on success * @return ESP_ERR_INVALID_ARG if config or handle is NULL, or if any configuration value is out of range * @return ESP_ERR_INVALID_STATE if the device is already initialized + * @return ESP_ERR_NO_MEM if memory allocation fails * @return ESP_FAIL on resource allocation or peripheral failure */ esp_err_t zh_ttp229_init(const zh_ttp229_init_config_t *config, zh_ttp229_handle_t **handle); diff --git a/zh_ttp229.c b/zh_ttp229.c index 6b65b86..571bbd6 100644 --- a/zh_ttp229.c +++ b/zh_ttp229.c @@ -160,6 +160,7 @@ esp_err_t zh_ttp229_init(const zh_ttp229_init_config_t *config, zh_ttp229_handle ZH_ERROR_CHECK(config != NULL && handle != NULL, ESP_ERR_INVALID_ARG, NULL, "Touch pad initialization failed. Invalid argument."); ZH_ERROR_CHECK(*handle == NULL, ESP_ERR_INVALID_STATE, NULL, "Touch pad initialization failed. Touch pad is already initialized."); *handle = heap_caps_calloc(1, sizeof(zh_ttp229_handle_t), MALLOC_CAP_8BIT); + ZH_ERROR_CHECK(*handle != NULL, ESP_ERR_NO_MEM, NULL, "Touch pad initialization failed. Failed to allocate touch pad handle."); ZH_ERROR_CHECK(_zh_ttp229_validate_config(config, *handle) == ESP_OK, ESP_FAIL, heap_caps_free(*handle); *handle = NULL, "Touch pad initialization failed. Initial configuration check failed."); if (_vector == NULL) {