From d78a1dac71e020d771651060c76c72c35a6a7705 Mon Sep 17 00:00:00 2001 From: Hays Chan <25737801+hayschan@users.noreply.github.com> Date: Mon, 25 Dec 2023 15:39:25 +0800 Subject: [PATCH] Rename AHT20 variables and names to XGZF4000 --- include/xgzf4000.h | 39 ++++++++++++++++++------------------- priv_include/xgzf4000_reg.h | 8 -------- xgzf4000.c | 4 ++-- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/include/xgzf4000.h b/include/xgzf4000.h index 3a00be6..35e1f53 100644 --- a/include/xgzf4000.h +++ b/include/xgzf4000.h @@ -15,53 +15,53 @@ extern "C" { #include "driver/i2c.h" -/* AHT20 address: CE pin low - 0x38, CE pin high - 0x39 */ -#define AHT20_ADDRRES_0 (0x38<<1) -#define AHT20_ADDRESS_1 (0x39<<1) +/* XGZF4000 address: CE pin low - 0x38, CE pin high - 0x39 */ +#define XGZF4000_ADDRRES_0 (0x38<<1) +#define XGZF4000_ADDRESS_1 (0x39<<1) /** - * @brief Type of AHT20 device handle + * @brief Type of XGZF4000 device handle * */ -typedef void *aht20_dev_handle_t; +typedef void *xgzf4000_dev_handle_t; /** - * @brief AHT20 I2C config struct + * @brief XGZF4000 I2C config struct * */ typedef struct { - i2c_port_t i2c_port; /*!< I2C port used to connecte AHT20 device */ - uint8_t i2c_addr; /*!< I2C address of AHT20 device, can be 0x38 or 0x39 according to A0 pin */ -} aht20_i2c_config_t; + i2c_port_t i2c_port; /*!< I2C port used to connecte XGZF4000 device */ + uint8_t i2c_addr; /*!< I2C address of XGZF4000 device, can be 0x38 or 0x39 according to A0 pin */ +} xgzf4000_i2c_config_t; /** - * @brief Create new AHT20 device handle. + * @brief Create new XGZF4000 device handle. * - * @param[in] i2c_conf Config for I2C used by AHT20 - * @param[out] handle_out New AHT20 device handle + * @param[in] i2c_conf Config for I2C used by XGZF4000 + * @param[out] handle_out New XGZF4000 device handle * @return * - ESP_OK Device handle creation success. * - ESP_ERR_INVALID_ARG Invalid device handle or argument. * - ESP_ERR_NO_MEM Memory allocation failed. * */ -esp_err_t aht20_new_sensor(const aht20_i2c_config_t *i2c_conf, aht20_dev_handle_t *handle_out); +esp_err_t xgzf4000_new_sensor(const xgzf4000_i2c_config_t *i2c_conf, xgzf4000_dev_handle_t *handle_out); /** - * @brief Delete AHT20 device handle. + * @brief Delete XGZF4000 device handle. * - * @param[in] handle AHT20 device handle + * @param[in] handle XGZF4000 device handle * @return * - ESP_OK Device handle deletion success. * - ESP_ERR_INVALID_ARG Invalid device handle or argument. * */ -esp_err_t aht20_del_sensor(aht20_dev_handle_t handle); +esp_err_t xgzf4000_del_sensor(xgzf4000_dev_handle_t handle); /** * @brief read the temperature and humidity data * - * @param[in] *handle points to an aht20 handle structure + * @param[in] *handle points to an xgzf4000 handle structure * @param[out] *temperature_raw points to a raw temperature buffer * @param[out] *temperature points to a converted temperature buffer * @param[out] *humidity_raw points to a raw humidity buffer @@ -71,9 +71,8 @@ esp_err_t aht20_del_sensor(aht20_dev_handle_t handle); * - ESP_OK Success * - ESP_FAIL Fail */ -esp_err_t aht20_read_temperature_humidity(aht20_dev_handle_t handle, - uint32_t *temperature_raw, float *temperature, - uint32_t *humidity_raw, float *humidity); +static esp_err_t xgzf4000_read_flow_data(xgzf4000_dev_handle_t dev, uint8_t *data, size_t len) + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/priv_include/xgzf4000_reg.h b/priv_include/xgzf4000_reg.h index 81ebdff..fc27326 100644 --- a/priv_include/xgzf4000_reg.h +++ b/priv_include/xgzf4000_reg.h @@ -15,11 +15,3 @@ #define TEMPERATURE_MIN (0.0f) /**< chip min working temperature */ #define TEMPERATURE_MAX (50.0f) /**< chip max working temperature */ #define PRESSURE_MAX (0.2f) /**< chip max working pressure */ - -#define AHT20_START_MEASURMENT_CMD 0xAC /* start measurment command */ - -#define AT581X_STATUS_CMP_INT (2) /* 1 --Out threshold range; 0 --In threshold range */ -#define AT581X_STATUS_Calibration_Enable (3) /* 1 --Calibration enable; 0 --Calibration disable */ -#define AT581X_STATUS_CRC_FLAG (4) /* 1 --CRC ok; 0 --CRC failed */ -#define AT581X_STATUS_MODE_STATUS (5) /* 00 -NOR mode; 01 -CYC mode; 1x --CMD mode */ -#define AT581X_STATUS_BUSY_INDICATION (7) /* 1 --Equipment is busy; 0 --Equipment is idle */ diff --git a/xgzf4000.c b/xgzf4000.c index 408311e..7d3c104 100644 --- a/xgzf4000.c +++ b/xgzf4000.c @@ -76,7 +76,7 @@ esp_err_t xgzf4000_read_air_flow(xgzf4000_dev_handle_t handle, uint32_t *flow_ra esp_err_t xgzf4000_new_sensor(const xgzf4000_i2c_config_t *i2c_conf, xgzf4000_dev_handle_t *handle_out) { ESP_LOGI(TAG, "Initializing XGZF4000 Air Flow Sensor"); - ESP_LOGI(TAG, "%-15s: %d.%d.%d", CHIP_NAME, AHT20_VER_MAJOR, AHT20_VER_MINOR, AHT20_VER_PATCH); + ESP_LOGI(TAG, "%-15s: %d.%d.%d", CHIP_NAME, XGZF4000_VER_MAJOR, XGZF4000_VER_MINOR, XGZF4000_VER_PATCH); ESP_LOGI(TAG, "%-15s: %1.1f - %1.1fV", "SUPPLY_VOLTAGE", SUPPLY_VOLTAGE_MIN, SUPPLY_VOLTAGE_MAX); ESP_LOGI(TAG, "%-15s: %.2f - %.2f℃", "TEMPERATURE", TEMPERATURE_MIN, TEMPERATURE_MAX); ESP_LOGI(TAG, "%-15s: %.2fMPa", "PRESSURE", PRESSURE_MAX); @@ -96,7 +96,7 @@ esp_err_t xgzf4000_new_sensor(const xgzf4000_i2c_config_t *i2c_conf, xgzf4000_de } -esp_err_t xgzf4000_del_sensor(aht20_dev_handle_t handle) +esp_err_t xgzf4000_del_sensor(xgzf4000_dev_handle_t handle) { ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "invalid device handle pointer");