Files
espidf_i2c/aht20/include/aht20.h
Julien Lazarewicz e940c767a6 Add bh1750, aht20, sgp40 drivers unified on native i2c_master API
Forked from managed_components (espressif/bh1750, espressif/aht20,
esp-idf-lib/sgp40) and rewrote aht20/sgp40 internals to use
driver/i2c_master.h directly instead of the i2c_bus and i2cdev
wrapper components, so all three sensors share one create/delete
handle pattern over a single i2c_master_bus_handle_t.
2026-07-05 23:27:50 +02:00

71 lines
1.9 KiB
C

/*
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_types.h"
#include "esp_err.h"
#include "driver/i2c_master.h"
/* AHT20 address: CE pin low - 0x38, CE pin high - 0x39 */
#define AHT20_ADDRRES_0 (0x38)
#define AHT20_ADDRESS_1 (0x39)
/**
* @brief Type of AHT20 device handle
*/
typedef void *aht20_handle_t;
/**
* @brief Create and init sensor object and return a sensor handle
*
* @param[in] bus_handle I2C bus handle. Obtained from i2c_new_master_bus().
* @param[in] dev_addr I2C address of sensor. Use AHT20_ADDRRES_0 for default address.
* @param[out] handle_ret Handle to created AHT20 driver object.
*
* @return
* - ESP_OK Success
* - ESP_ERR_NO_MEM Not enough memory for the driver
* - Others Error from underlying I2C driver
*/
esp_err_t aht20_create(i2c_master_bus_handle_t bus_handle, const uint8_t dev_addr, aht20_handle_t *handle_ret);
/**
* @brief Delete and release a sensor object
*
* @param sensor object handle of aht20
*
* @return
* - ESP_OK Success
* - ESP_FAIL Fail
*/
esp_err_t aht20_delete(aht20_handle_t sensor);
/**
* @brief read the temperature and humidity data
*
* @param[in] sensor object handle of aht20
* @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
* @param[out] humidity points to a converted humidity buffer
*
* @return
* - ESP_OK Success
* - ESP_ERR_NOT_FINISHED Measurement not ready yet
* - ESP_FAIL Fail
*/
esp_err_t aht20_read_temperature_humidity(aht20_handle_t sensor,
uint32_t *temperature_raw, float *temperature,
uint32_t *humidity_raw, float *humidity);
#ifdef __cplusplus
}
#endif