• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 SENSOR_BAROMETER_DRIVER_H
10 #define SENSOR_BAROMETER_DRIVER_H
11 
12 #include "hdf_workqueue.h"
13 #include "osal_timer.h"
14 #include "sensor_config_parser.h"
15 #include "sensor_platform_if.h"
16 
17 #define BAR_DEFAULT_SAMPLING_200_MS    200000000
18 #define BAROMETER_CHIP_NAME_BMP180    "bmp180"
19 
20 enum BarometerEeprom {
21     BAROMETER_AC1_MSB = 0,
22     BAROMETER_AC1_LSB = 1,
23     BAROMETER_AC2_MSB = 2,
24     BAROMETER_AC2_LSB = 3,
25     BAROMETER_AC3_MSB = 4,
26     BAROMETER_AC3_LSB = 5,
27     BAROMETER_AC4_MSB = 6,
28     BAROMETER_AC4_LSB = 7,
29     BAROMETER_AC5_MSB = 8,
30     BAROMETER_AC5_LSB = 9,
31     BAROMETER_AC6_MSB = 10,
32     BAROMETER_AC6_LSB = 11,
33     BAROMETER_B1_MSB  = 12,
34     BAROMETER_B1_LSB  = 13,
35     BAROMETER_B2_MSB  = 14,
36     BAROMETER_B2_LSB  = 15,
37     BAROMETER_MB_MSB  = 16,
38     BAROMETER_MB_LSB  = 17,
39     BAROMETER_MC_MSB  = 18,
40     BAROMETER_MC_LSB  = 19,
41     BAROMETER_MD_MSB  = 20,
42     BAROMETER_MD_LSB  = 21,
43     BAROMETER_EEPROM_SUM,
44 };
45 
46 struct BarometerEepromData {
47     int32_t ac1;
48     int32_t ac2;
49     int32_t ac3;
50     int32_t b1;
51     int32_t b2;
52     int32_t mb;
53     int32_t mc;
54     int32_t md;
55     uint32_t ac4;
56     uint32_t ac5;
57     uint32_t ac6;
58 };
59 
60 struct Coefficient {
61     int32_t b3;
62     int32_t b5;
63     int32_t b6;
64     int32_t x1;
65     int32_t x2;
66     int32_t x3;
67     int32_t p;
68     uint32_t b4;
69     uint32_t b7;
70 };
71 
72 enum Temperature {
73     BAROMETER_TEM_MSB = 0,
74     BAROMETER_TEM_LSB = 1,
75     BAROMETER_TEM_SUM,
76 };
77 
78 enum Barometer {
79     BAROMETER_BAR_MSB  = 0,
80     BAROMETER_BAR_LSB  = 1,
81     BAROMETER_BAR_XLSB = 2,
82     BAROMETER_BAR_SUM,
83 };
84 
85 struct  BarometerData {
86     int32_t unpensatePre;
87     int32_t unpensateTemp;
88 };
89 
90 enum BarometerRawData {
91     BAROMETER_BAROMETER   = 0,
92     BAROMETER_TEMPERATURE = 1,
93     BAROMETER_ALTITUDE    = 2,
94     BAROMETER_SUM,
95 };
96 
97 struct BarometerOpsCall {
98     int32_t (*Init)(struct SensorCfgData *data);
99     int32_t (*ReadData)(struct SensorCfgData *data);
100 };
101 
102 struct BarometerDrvData {
103     struct IDeviceIoService ioService;
104     struct HdfDeviceObject *device;
105     HdfWorkQueue barometerWorkQueue;
106     HdfWork barometerWork;
107     OsalTimer barometerTimer;
108     bool detectFlag;
109     bool enable;
110     int64_t interval;
111     struct SensorCfgData *barometerCfg;
112     struct BarometerOpsCall ops;
113 };
114 
115 int32_t BarometerRegisterChipOps(const struct BarometerOpsCall *ops);
116 struct SensorCfgData *BarometerCreateCfgData(const struct DeviceResourceNode *node);
117 void BarometerReleaseCfgData(struct SensorCfgData *barometerCfg);
118 
119 #endif /* SENSOR_BAROMETER_DRIVER_H */
120