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