• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 HUMIDITY_AHT20_H
10 #define HUMIDITY_AHT20_H
11 
12 #include "sensor_config_parser.h"
13 #include "sensor_humidity_driver.h"
14 
15 /* Humidity registers addr */
16 #define AHT20_HUM_STATUS_ADDR              0x71 // Status
17 #define AHT20_HUM_RESET_ADDR               0xBA
18 
19 #define AHT20_HUM_MEASURE_ADDR             0xAC // Measure
20 #define AHT20_HUM_MEASURE_ARG0             0x33
21 #define AHT20_HUM_MEASURE_ARG1             0x00
22 
23 #define AHT20_HUM_CALIBRATION_ADDR         0xBE // Calibration
24 #define AHT20_HUM_CALIBRATION_ARG0         0x08
25 #define AHT20_HUM_CALIBRATION_ARG1         0x00
26 
27 /* Humidity data */
28 #define AHT20_HUM_DATA_BUF_LEN          6
29 #define AHT20_HUM_VALUE_IDX_ZERO        0
30 #define AHT20_HUM_VALUE_IDX_ONE         1
31 #define AHT20_HUM_VALUE_IDX_TWO         2
32 #define AHT20_HUM_VALUE_IDX_THREE       3
33 #define AHT20_HUM_VALUE_IDX_FOUR        4
34 #define AHT20_HUM_VALUE_IDX_FIVE        5
35 
36 #define AHT20_HUM_BUSY_SHIFT            7
37 #define AHT20_HUM_BUSY_MASK             (0x1 << AHT20_HUM_BUSY_SHIFT)
38 #define AHT20_HUM_IS_BUSY(status)       (((status) & AHT20_HUM_BUSY_MASK) >> AHT20_HUM_BUSY_SHIFT)
39 
40 #define AHT20_HUM_CALI_SHIFT            3
41 #define AHT20_HUM_CALI_MASK             (0x1 << AHT20_HUM_CALI_SHIFT)
42 #define AHT20_HUM_IS_CALI(status)       (((status) & AHT20_HUM_CALI_MASK) >> AHT20_HUM_CALI_SHIFT)
43 
44 #define AHT20_HUM_DELAY_MS              80
45 #define AHT20_HUM_STARTUP_MS            20
46 #define AHT20_HUM_CALIBRATION_MS        40
47 
48 #define AHT20_HUM_SHFIT_FOUR_BITS       4
49 #define AHT20_HUM_SHFIT_EIGHT_BITS      8
50 #define AHT20_HUM_MASK                  0xF0
51 
52 #define AHT20_HUM_SLOPE                 10000 // 100 * 100.0
53 #define AHT20_HUM_RESOLUTION            (0x1 << 20)
54 #define AHT20_HUM_RETRY_TIMES           5
55 
56 struct Aht20DrvData {
57     struct IDeviceIoService ioService;
58     struct HdfDeviceObject *device;
59     struct SensorCfgData *sensorCfg;
60 };
61 
62 #endif /* HUMIDITY_AHT20_H */
63