• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #include "barometer_bmp180.h"
10 #include <securec.h>
11 #include "osal_mem.h"
12 #include "osal_time.h"
13 #include "sensor_barometer_driver.h"
14 #include "sensor_config_controller.h"
15 #include "sensor_device_manager.h"
16 #include "sensor_platform_if.h"
17 
18 #define HDF_LOG_TAG    khdf_sensor_barometer_driver
19 
20 static struct Bmp180DrvData *g_bmp180DrvData = NULL;
21 
22 /* IO config for int-pin and I2C-pin */
23 #define SENSOR_I2C6_DATA_REG_ADDR 0x114f004c
24 #define SENSOR_I2C6_CLK_REG_ADDR  0x114f0048
25 #define SENSOR_I2C_REG_CFG        0x403
26 
27 static struct BarometerEepromData g_calibraData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
28 
ReadEepromRawData(struct SensorCfgData * data,uint8_t rfg[BAROMETER_EEPROM_SUM])29 static int32_t ReadEepromRawData(struct SensorCfgData *data, uint8_t rfg[BAROMETER_EEPROM_SUM])
30 {
31     int32_t ret;
32 
33     ret = ReadSensor(&data->busCfg, BMP180_AC1_MSB_ADDR, &rfg[BAROMETER_AC1_MSB], sizeof(uint8_t));
34     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
35 
36     ret = ReadSensor(&data->busCfg, BMP180_AC1_LSB_ADDR, &rfg[BAROMETER_AC1_LSB], sizeof(uint8_t));
37     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
38 
39     ret = ReadSensor(&data->busCfg, BMP180_AC2_MSB_ADDR, &rfg[BAROMETER_AC2_MSB], sizeof(uint8_t));
40     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
41 
42     ret = ReadSensor(&data->busCfg, BMP180_AC2_LSB_ADDR, &rfg[BAROMETER_AC2_LSB], sizeof(uint8_t));
43     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
44 
45     ret = ReadSensor(&data->busCfg, BMP180_AC3_MSB_ADDR, &rfg[BAROMETER_AC3_MSB], sizeof(uint8_t));
46     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
47 
48     ret = ReadSensor(&data->busCfg, BMP180_AC3_LSB_ADDR, &rfg[BAROMETER_AC3_LSB], sizeof(uint8_t));
49     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
50 
51     ret = ReadSensor(&data->busCfg, BMP180_AC4_MSB_ADDR, &rfg[BAROMETER_AC4_MSB], sizeof(uint8_t));
52     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
53 
54     ret = ReadSensor(&data->busCfg, BMP180_AC4_LSB_ADDR, &rfg[BAROMETER_AC4_LSB], sizeof(uint8_t));
55     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
56 
57     ret = ReadSensor(&data->busCfg, BMP180_AC5_MSB_ADDR, &rfg[BAROMETER_AC5_MSB], sizeof(uint8_t));
58     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
59 
60     ret = ReadSensor(&data->busCfg, BMP180_AC5_LSB_ADDR, &rfg[BAROMETER_AC5_LSB], sizeof(uint8_t));
61     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
62 
63     ret = ReadSensor(&data->busCfg, BMP180_AC6_MSB_ADDR, &rfg[BAROMETER_AC6_MSB], sizeof(uint8_t));
64     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
65     ret = ReadSensor(&data->busCfg, BMP180_AC6_LSB_ADDR, &rfg[BAROMETER_AC6_LSB], sizeof(uint8_t));
66     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
67 
68     ret = ReadSensor(&data->busCfg, BMP180_B1_MSB_ADDR, &rfg[BAROMETER_B1_MSB], sizeof(uint8_t));
69     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
70 
71     ret = ReadSensor(&data->busCfg, BMP180_B1_LSB_ADDR, &rfg[BAROMETER_B1_LSB], sizeof(uint8_t));
72     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
73 
74     ret = ReadSensor(&data->busCfg, BMP180_B2_MSB_ADDR, &rfg[BAROMETER_B2_MSB], sizeof(uint8_t));
75     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
76 
77     ret = ReadSensor(&data->busCfg, BMP180_B2_LSB_ADDR, &rfg[BAROMETER_B2_LSB], sizeof(uint8_t));
78     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
79 
80     ret = ReadSensor(&data->busCfg, BMP180_MB_MSB_ADDR, &rfg[BAROMETER_MB_MSB], sizeof(uint8_t));
81     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
82 
83     ret = ReadSensor(&data->busCfg, BMP180_MB_LSB_ADDR, &rfg[BAROMETER_MB_LSB], sizeof(uint8_t));
84     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
85 
86     ret = ReadSensor(&data->busCfg, BMP180_MC_MSB_ADDR, &rfg[BAROMETER_MC_MSB], sizeof(uint8_t));
87     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
88 
89     ret = ReadSensor(&data->busCfg, BMP180_MC_LSB_ADDR, &rfg[BAROMETER_MC_LSB], sizeof(uint8_t));
90     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
91 
92     ret = ReadSensor(&data->busCfg, BMP180_MD_MSB_ADDR, &rfg[BAROMETER_MD_MSB], sizeof(uint8_t));
93     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
94 
95     ret = ReadSensor(&data->busCfg, BMP180_MD_LSB_ADDR, &rfg[BAROMETER_MD_LSB], sizeof(uint8_t));
96     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
97 
98     return ret;
99 }
100 
ReadEepromData(struct SensorCfgData * data,struct BarometerEepromData * g_calibraData)101 static int32_t ReadEepromData(struct SensorCfgData *data, struct BarometerEepromData *g_calibraData)
102 {
103     int32_t ret;
104     uint8_t reg[BAROMETER_EEPROM_SUM];
105 
106     (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
107 
108     CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
109 
110     ret = ReadEepromRawData(data, reg);
111     if (ret != HDF_SUCCESS) {
112     return HDF_FAILURE;
113     }
114 
115     g_calibraData->ac1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
116     reg[BAROMETER_AC1_LSB]);
117     g_calibraData->ac2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
118     reg[BAROMETER_AC2_LSB]);
119     g_calibraData->ac3 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC3_MSB], SENSOR_DATA_WIDTH_8_BIT) |
120     reg[BAROMETER_AC3_LSB]);
121     g_calibraData->ac4 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC4_MSB], SENSOR_DATA_WIDTH_8_BIT) |
122     reg[BAROMETER_AC4_LSB]);
123     g_calibraData->ac5 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC5_MSB], SENSOR_DATA_WIDTH_8_BIT) |
124     reg[BAROMETER_AC5_LSB]);
125     g_calibraData->ac6 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC6_MSB], SENSOR_DATA_WIDTH_8_BIT) |
126     reg[BAROMETER_AC6_LSB]);
127     g_calibraData->b1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
128     reg[BAROMETER_B1_LSB]);
129     g_calibraData->b2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
130     reg[BAROMETER_B2_LSB]);
131     g_calibraData->mb = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MB_MSB], SENSOR_DATA_WIDTH_8_BIT) |
132     reg[BAROMETER_MB_LSB]);
133     g_calibraData->mc = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MC_MSB], SENSOR_DATA_WIDTH_8_BIT) |
134     reg[BAROMETER_MC_LSB]);
135     g_calibraData->md = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MD_MSB], SENSOR_DATA_WIDTH_8_BIT) |
136     reg[BAROMETER_MD_LSB]);
137 
138     return ret;
139 }
140 
ReadTempData(struct SensorCfgData * data,struct BarometerData * Temp)141 static int32_t ReadTempData(struct SensorCfgData *data,  struct BarometerData *Temp)
142 {
143     int32_t ret;
144     uint8_t status = 0;
145     uint8_t reg[BAROMETER_TEM_SUM];
146     uint8_t value[SENSOR_VALUE_BUTT];
147     value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
148     value[SENSOR_VALUE_INDEX] = BMP180_COVERT_TEMP;
149 
150     (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
151 
152     CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
153 
154     ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
155     if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
156         WriteSensor(&data->busCfg, value, sizeof(value));
157         OsalMDelay(DELAY_0);
158         ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, &reg[BAROMETER_TEM_MSB], sizeof(uint8_t));
159         CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
160 
161         ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, &reg[BAROMETER_TEM_LSB], sizeof(uint8_t));
162         CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
163 
164         Temp->unpensateTemp = (int32_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_TEM_MSB], SENSOR_DATA_WIDTH_8_BIT) |
165             reg[BAROMETER_TEM_LSB]);
166     }
167     return ret;
168 }
169 
ReadBarometerData(struct SensorCfgData * data,struct BarometerData * Barom)170 static int32_t ReadBarometerData(struct SensorCfgData *data, struct BarometerData *Barom)
171 {
172     int32_t ret;
173     uint8_t status = 0;
174     uint8_t reg[BAROMETER_BAR_SUM];
175     uint8_t value[SENSOR_VALUE_BUTT];
176     value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
177     value[SENSOR_VALUE_INDEX] = BMP180_COVERT_PRES_1;
178 
179     (void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
180 
181     CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
182 
183     ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
184     if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
185     WriteSensor(&data->busCfg, value, sizeof(value));
186     OsalMDelay(DELAY_1);
187     ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, &reg[BAROMETER_BAR_MSB], sizeof(uint8_t));
188     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
189 
190     ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, &reg[BAROMETER_BAR_LSB], sizeof(uint8_t));
191     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
192 
193     ret = ReadSensor(&data->busCfg, BMP180_OUT_XLSB_ADDR, &reg[BAROMETER_BAR_XLSB], sizeof(uint8_t));
194     CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
195 
196     Barom->unpensatePre = (int32_t)(SENSOR_DATA_SHIFT_RIGHT(
197         (SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_MSB], SENSOR_DATA_WIDTH_16_BIT) |
198             SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_LSB], SENSOR_DATA_WIDTH_8_BIT) | reg[BAROMETER_BAR_XLSB]),
199         (BMP180_CONSTANT_4 - OSSETTING)));
200     }
201     return ret;
202 }
203 
CalcBarometerData(struct BarometerData * barometerData,int32_t tnp[BAROMETER_SUM])204 static int32_t CalcBarometerData(struct  BarometerData *barometerData, int32_t tnp[BAROMETER_SUM])
205 {
206     struct Coefficient coefficientData = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
207 
208     // Calculated temperature
209 
210     coefficientData.x1 = ((barometerData->unpensateTemp - g_calibraData.ac6) * (g_calibraData.ac5))
211         >> BMP180_CONSTANT_8;
212     coefficientData.x2 = (g_calibraData.mc << BMP180_CONSTANT_5) / (coefficientData.x1 + g_calibraData.md);
213     coefficientData.b5 = coefficientData.x1 + coefficientData.x2;
214     tnp[BAROMETER_TEMPERATURE] = (coefficientData.b5 + BMP180_CONSTANT_4) >> BMP180_CONSTANT_3;
215 
216     // Calculated pressure
217 
218     coefficientData.b6 = coefficientData.b5 - BMP180_CONSTANT_12;
219     coefficientData.x1 = (g_calibraData.b2 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
220         >> BMP180_CONSTANT_5;
221     coefficientData.x2 = (g_calibraData.ac2 * coefficientData.b6) >> BMP180_CONSTANT_5;
222     coefficientData.x3 = coefficientData.x1 + coefficientData.x2;
223     coefficientData.b3 = (((((int32_t)g_calibraData.ac1) * BMP180_CONSTANT_3 + coefficientData.x3) << OSSETTING)
224         + BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
225     coefficientData.x1 = (g_calibraData.ac3 * coefficientData.b6) >> BMP180_CONSTANT_7;
226     coefficientData.x2 = (g_calibraData.b1 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
227         >> BMP180_CONSTANT_9;
228     coefficientData.x3 = ((coefficientData.x1 + coefficientData.x2) + BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
229     coefficientData.b4 = (g_calibraData.ac4 * (uint32_t)(coefficientData.x3 + BMP180_CONSTANT_13))
230         >> BMP180_CONSTANT_8;
231     coefficientData.b7 = ((uint32_t)(barometerData->unpensatePre) - (uint32_t)coefficientData.b3)
232         * (BMP180_CONSTANT_14 >> OSSETTING);
233     if (coefficientData.b7 < BMP180_CONSTANT_15) {
234         coefficientData.p = (coefficientData.b7 << BMP180_CONSTANT_1) / coefficientData.b4;
235     } else {
236         coefficientData.p = (coefficientData.b7 / coefficientData.b4) << BMP180_CONSTANT_1;
237     }
238     coefficientData.x1 = (coefficientData.p >> BMP180_CONSTANT_4) * (coefficientData.p >> BMP180_CONSTANT_4);
239     coefficientData.x1 = (coefficientData.x1 * BMP180_CONSTANT_10) >> BMP180_CONSTANT_9;
240     coefficientData.x2 = (BMP180_CONSTANT_0 * coefficientData.p) >> BMP180_CONSTANT_9;
241     tnp[BAROMETER_BAROMETER] = coefficientData.p + ((coefficientData.x1 + coefficientData.x2
242         + BMP180_CONSTANT_11) >> BMP180_CONSTANT_3);
243 
244     return HDF_SUCCESS;
245 }
246 
ReadBmp180Data(struct SensorCfgData * data)247 int32_t ReadBmp180Data(struct SensorCfgData *data)
248 {
249     int32_t ret;
250     int32_t tmp[BAROMETER_SUM];
251     struct  BarometerData barometerData = {0, 0};
252     OsalTimespec time;
253     struct SensorReportEvent event;
254 
255     (void)memset_s(&time, sizeof(time), 0, sizeof(time));
256     (void)memset_s(&event, sizeof(event), 0, sizeof(event));
257 
258     if (OsalGetTime(&time) != HDF_SUCCESS) {
259         HDF_LOGE("%s: Get time failed", __func__);
260         return HDF_FAILURE;
261     }
262     event.timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec * SENSOR_CONVERT_UNIT;
263 
264     ret = ReadTempData(data, &barometerData);
265     if (ret != HDF_SUCCESS) {
266     return HDF_FAILURE;
267     }
268 
269     ret = ReadBarometerData(data, &barometerData);
270     if (ret != HDF_SUCCESS) {
271     return HDF_FAILURE;
272     }
273 
274     ret = CalcBarometerData(&barometerData, tmp);
275     if (ret != HDF_SUCCESS) {
276     return HDF_FAILURE;
277     }
278 
279     event.sensorId = SENSOR_TAG_BAROMETER;
280     event.option = 0;
281     event.mode = SENSOR_WORK_MODE_REALTIME;
282     event.dataLen = sizeof(tmp);
283     event.data = (uint8_t *)&tmp;
284     ret = ReportSensorEvent(&event);
285     return ret;
286 }
287 
InitBmp180(struct SensorCfgData * data)288 static int32_t InitBmp180(struct SensorCfgData *data)
289 {
290     int32_t ret;
291     CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
292     struct SensorReportEvent event;
293 
294     (void)memset_s(&event, sizeof(event), 0, sizeof(event));
295 
296     ret = ReadEepromData(data, &g_calibraData);
297     if (ret != HDF_SUCCESS) {
298         return HDF_FAILURE;
299     }
300     ret = SetSensorRegCfgArray(&data->busCfg, data->regCfgGroup[SENSOR_INIT_GROUP]);
301     if (ret != HDF_SUCCESS) {
302         HDF_LOGE("%s: BMP180 sensor init config failed", __func__);
303         return HDF_FAILURE;
304     }
305     return HDF_SUCCESS;
306 }
307 
InitBarometerPreConfig(void)308 static int32_t InitBarometerPreConfig(void)
309 {
310     if (SetSensorPinMux(SENSOR_I2C6_DATA_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
311         HDF_LOGE("%s: Data write mux pin failed", __func__);
312         return HDF_FAILURE;
313     }
314     if (SetSensorPinMux(SENSOR_I2C6_CLK_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
315         HDF_LOGE("%s: Clk write mux pin failed", __func__);
316         return HDF_FAILURE;
317     }
318 
319     return HDF_SUCCESS;
320 }
321 
DispatchBMP180(struct HdfDeviceIoClient * client,int cmd,struct HdfSBuf * data,struct HdfSBuf * reply)322 static int32_t DispatchBMP180(struct HdfDeviceIoClient *client,
323     int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
324 {
325     (void)client;
326     (void)cmd;
327     (void)data;
328     (void)reply;
329 
330     return HDF_SUCCESS;
331 }
332 
Bmp180BindDriver(struct HdfDeviceObject * device)333 int32_t Bmp180BindDriver(struct HdfDeviceObject *device)
334 {
335     CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
336 
337     struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)OsalMemCalloc(sizeof(*drvData));
338     if (drvData == NULL) {
339         HDF_LOGE("%s: Malloc Bmi160 drv data fail", __func__);
340         return HDF_ERR_MALLOC_FAIL;
341     }
342 
343     drvData->ioService.Dispatch = DispatchBMP180;
344     drvData->device = device;
345     device->service = &drvData->ioService;
346     g_bmp180DrvData = drvData;
347 
348     return HDF_SUCCESS;
349 }
350 
Bmp180InitDriver(struct HdfDeviceObject * device)351 int32_t Bmp180InitDriver(struct HdfDeviceObject *device)
352 {
353     int32_t ret;
354     struct BarometerOpsCall ops;
355 
356     CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
357     struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)device->service;
358     CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
359 
360     ret = InitBarometerPreConfig();
361     if (ret != HDF_SUCCESS) {
362         HDF_LOGE("%s: Init  BMp180 bus mux config", __func__);
363         return HDF_FAILURE;
364     }
365 
366     drvData->sensorCfg = BarometerCreateCfgData(device->property);
367     if (drvData->sensorCfg == NULL || drvData->sensorCfg->root == NULL) {
368         HDF_LOGD("%s: Creating barometercfg failed because detection failed", __func__);
369         return HDF_ERR_NOT_SUPPORT;
370     }
371 
372     ops.Init = NULL;
373     ops.ReadData = ReadBmp180Data;
374     ret = BarometerRegisterChipOps(&ops);
375     if (ret != HDF_SUCCESS) {
376         HDF_LOGE("%s: Register BMp180 barometer failed", __func__);
377         return HDF_FAILURE;
378     }
379 
380     ret = InitBmp180(drvData->sensorCfg);
381     if (ret != HDF_SUCCESS) {
382         HDF_LOGE("%s: Init BMP180 barometer failed", __func__);
383         return HDF_FAILURE;
384     }
385 
386     return HDF_SUCCESS;
387 }
388 
Bmp180ReleaseDriver(struct HdfDeviceObject * device)389 void Bmp180ReleaseDriver(struct HdfDeviceObject *device)
390 {
391     CHECK_NULL_PTR_RETURN(device);
392 
393     struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)device->service;
394     CHECK_NULL_PTR_RETURN(drvData);
395 
396     if (drvData->sensorCfg != NULL) {
397         BarometerReleaseCfgData(drvData->sensorCfg);
398         drvData->sensorCfg = NULL;
399     }
400     OsalMemFree(drvData);
401 }
402 
403 struct HdfDriverEntry g_barometerBmp180DevEntry = {
404     .moduleVersion = 1,
405     .moduleName = "HDF_SENSOR_BAROMETER_BMP180",
406     .Bind = Bmp180BindDriver,
407     .Init = Bmp180InitDriver,
408     .Release = Bmp180ReleaseDriver,
409 };
410 
411 HDF_INIT(g_barometerBmp180DevEntry);