1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef TEMPERATURE_AHT20_H
10 #define TEMPERATURE_AHT20_H
11 
12 #include "sensor_config_parser.h"
13 #include "sensor_temperature_driver.h"
14 
15 /* Temperature registers addr */
16 #define AHT20_TEMP_STATUS_ADDR               0x71 // Status
17 #define AHT20_TEMP_RESET_ADDR                0xBA
18 
19 #define AHT20_TEMP_MEASURE_ADDR              0xAC // Measure
20 #define AHT20_TEMP_MEASURE_ARG0              0x33
21 #define AHT20_TEMP_MEASURE_ARG1              0x00
22 
23 #define AHT20_TEMP_CALIBRATION_ADDR          0xBE // Calibration
24 #define AHT20_TEMP_CALIBRATION_ARG0          0x08
25 #define AHT20_TEMP_CALIBRATION_ARG1          0x00
26 
27 /* Temperature data */
28 #define AHT20_TEMP_DATA_BUF_LEN          6
29 #define AHT20_TEMP_VALUE_IDX_ZERO        0
30 #define AHT20_TEMP_VALUE_IDX_ONE         1
31 #define AHT20_TEMP_VALUE_IDX_TWO         2
32 #define AHT20_TEMP_VALUE_IDX_THREE       3
33 #define AHT20_TEMP_VALUE_IDX_FOUR        4
34 #define AHT20_TEMP_VALUE_IDX_FIVE        5
35 
36 #define AHT20_TEMP_BUSY_SHIFT            7
37 #define AHT20_TEMP_BUSY_MASK            (0x1 << AHT20_TEMP_BUSY_SHIFT)
38 #define AHT20_TEMP_IS_BUSY(status)      (((status) & AHT20_TEMP_BUSY_MASK) >> AHT20_TEMP_BUSY_SHIFT)
39 
40 #define AHT20_TEMP_CALI_SHIFT            3
41 #define AHT20_TEMP_CALI_MASK             (0x1 << AHT20_TEMP_CALI_SHIFT)
42 #define AHT20_TEMP_IS_CALI(status)       (((status) & AHT20_TEMP_CALI_MASK) >> AHT20_TEMP_CALI_SHIFT)
43 
44 #define AHT20_TEMP_DELAY_MS              80
45 #define AHT20_TEMP_STARTUP_MS            20
46 #define AHT20_TEMP_CALIBRATION_MS        40
47 
48 #define AHT20_TEMP_SHFIT_BITS            8
49 #define AHT20_TEMP_MASK                  0x0F
50 
51 #define AHT20_TEMP_CONSATNT              500  // 50 * 10
52 #define AHT20_TEMP_SLOPE                 2000 // 200 * 10
53 #define AHT20_TEMP_RESOLUTION            (0x1 << 20)
54 #define AHT20_TEMP_RETRY_TIMES           5
55 
56 struct Aht20DrvData {
57     struct IDeviceIoService ioService;
58     struct HdfDeviceObject *device;
59     struct SensorCfgData *sensorCfg;
60 };
61 
62 #endif /* TEMPERATURE_AHT20_H */
63