1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * 4094332d3Sopenharmony_ci * HDF is dual licensed: you can use it either under the terms of 5094332d3Sopenharmony_ci * the GPL, or the BSD license, at your option. 6094332d3Sopenharmony_ci * See the LICENSE file in the root of this repository for complete details. 7094332d3Sopenharmony_ci */ 8094332d3Sopenharmony_ci 9094332d3Sopenharmony_ci#ifndef TEMPERATURE_AHT20_H 10094332d3Sopenharmony_ci#define TEMPERATURE_AHT20_H 11094332d3Sopenharmony_ci 12094332d3Sopenharmony_ci#include "sensor_config_parser.h" 13094332d3Sopenharmony_ci#include "sensor_temperature_driver.h" 14094332d3Sopenharmony_ci 15094332d3Sopenharmony_ci/* Temperature registers addr */ 16094332d3Sopenharmony_ci#define AHT20_TEMP_STATUS_ADDR 0x71 // Status 17094332d3Sopenharmony_ci#define AHT20_TEMP_RESET_ADDR 0xBA 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#define AHT20_TEMP_MEASURE_ADDR 0xAC // Measure 20094332d3Sopenharmony_ci#define AHT20_TEMP_MEASURE_ARG0 0x33 21094332d3Sopenharmony_ci#define AHT20_TEMP_MEASURE_ARG1 0x00 22094332d3Sopenharmony_ci 23094332d3Sopenharmony_ci#define AHT20_TEMP_CALIBRATION_ADDR 0xBE // Calibration 24094332d3Sopenharmony_ci#define AHT20_TEMP_CALIBRATION_ARG0 0x08 25094332d3Sopenharmony_ci#define AHT20_TEMP_CALIBRATION_ARG1 0x00 26094332d3Sopenharmony_ci 27094332d3Sopenharmony_ci/* Temperature data */ 28094332d3Sopenharmony_ci#define AHT20_TEMP_DATA_BUF_LEN 6 29094332d3Sopenharmony_ci#define AHT20_TEMP_VALUE_IDX_ZERO 0 30094332d3Sopenharmony_ci#define AHT20_TEMP_VALUE_IDX_ONE 1 31094332d3Sopenharmony_ci#define AHT20_TEMP_VALUE_IDX_TWO 2 32094332d3Sopenharmony_ci#define AHT20_TEMP_VALUE_IDX_THREE 3 33094332d3Sopenharmony_ci#define AHT20_TEMP_VALUE_IDX_FOUR 4 34094332d3Sopenharmony_ci#define AHT20_TEMP_VALUE_IDX_FIVE 5 35094332d3Sopenharmony_ci 36094332d3Sopenharmony_ci#define AHT20_TEMP_BUSY_SHIFT 7 37094332d3Sopenharmony_ci#define AHT20_TEMP_BUSY_MASK (0x1 << AHT20_TEMP_BUSY_SHIFT) 38094332d3Sopenharmony_ci#define AHT20_TEMP_IS_BUSY(status) (((status) & AHT20_TEMP_BUSY_MASK) >> AHT20_TEMP_BUSY_SHIFT) 39094332d3Sopenharmony_ci 40094332d3Sopenharmony_ci#define AHT20_TEMP_CALI_SHIFT 3 41094332d3Sopenharmony_ci#define AHT20_TEMP_CALI_MASK (0x1 << AHT20_TEMP_CALI_SHIFT) 42094332d3Sopenharmony_ci#define AHT20_TEMP_IS_CALI(status) (((status) & AHT20_TEMP_CALI_MASK) >> AHT20_TEMP_CALI_SHIFT) 43094332d3Sopenharmony_ci 44094332d3Sopenharmony_ci#define AHT20_TEMP_DELAY_MS 80 45094332d3Sopenharmony_ci#define AHT20_TEMP_STARTUP_MS 20 46094332d3Sopenharmony_ci#define AHT20_TEMP_CALIBRATION_MS 40 47094332d3Sopenharmony_ci 48094332d3Sopenharmony_ci#define AHT20_TEMP_SHFIT_BITS 8 49094332d3Sopenharmony_ci#define AHT20_TEMP_MASK 0x0F 50094332d3Sopenharmony_ci 51094332d3Sopenharmony_ci#define AHT20_TEMP_CONSATNT 500 // 50 * 10 52094332d3Sopenharmony_ci#define AHT20_TEMP_SLOPE 2000 // 200 * 10 53094332d3Sopenharmony_ci#define AHT20_TEMP_RESOLUTION (0x1 << 20) 54094332d3Sopenharmony_ci#define AHT20_TEMP_RETRY_TIMES 5 55094332d3Sopenharmony_ci 56094332d3Sopenharmony_cistruct Aht20DrvData { 57094332d3Sopenharmony_ci struct IDeviceIoService ioService; 58094332d3Sopenharmony_ci struct HdfDeviceObject *device; 59094332d3Sopenharmony_ci struct SensorCfgData *sensorCfg; 60094332d3Sopenharmony_ci}; 61094332d3Sopenharmony_ci 62094332d3Sopenharmony_ci#endif /* TEMPERATURE_AHT20_H */ 63