From 9fe6ebaa0d22f34ee9e9524e1dc38c321e49ea56 Mon Sep 17 00:00:00 2001 From: tangzhaobao Date: Mon, 6 Sep 2021 19:17:28 +0800 Subject: [PATCH] modify code Signed-off-by: tangzhaobao --- .../barometer/sensor_barometer_driver.c | 225 ++++++++---------- .../barometer/sensor_barometer_driver.h | 10 +- .../chipset/barometer/barometer_bmp180.c | 105 ++++++-- .../chipset/barometer/barometer_bmp180.h | 35 +-- 4 files changed, 212 insertions(+), 163 deletions(-) diff --git a/model/sensor/driver/barometer/sensor_barometer_driver.c b/model/sensor/driver/barometer/sensor_barometer_driver.c index 77aacd490..988ea0333 100644 --- a/model/sensor/driver/barometer/sensor_barometer_driver.c +++ b/model/sensor/driver/barometer/sensor_barometer_driver.c @@ -6,13 +6,12 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include "securec.h" -#include "barometer_bmp180.h" +#include "sensor_barometer_driver.h" +#include #include "hdf_base.h" #include "hdf_device_desc.h" #include "osal_math.h" #include "osal_mem.h" -#include "sensor_barometer_driver.h" #include "sensor_config_controller.h" #include "sensor_device_manager.h" #include "sensor_platform_if.h" @@ -21,10 +20,6 @@ #define HDF_BAROMETER_WORK_QUEUE_NAME "hdf_barometer_work_queue" -static struct BarometerDetectIfList g_barometerDetectIfList[] = { - {BAROMETER_CHIP_NAME_BMP180, DetectBarometerBmp180Chip}, -}; - static struct BarometerDrvData *g_barometerDrvData = NULL; static struct BarometerDrvData *BarometerGetDrvData(void) @@ -34,14 +29,13 @@ static struct BarometerDrvData *BarometerGetDrvData(void) static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL }; -int32_t RegisterBarometerChipOps(const struct BarometerOpsCall *ops) +int32_t BarometerRegisterChipOps(const struct BarometerOpsCall *ops) { - struct BarometerDrvData *drvData = NULL; + struct BarometerDrvData *drvData = BarometerGetDrvData(); + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM); - drvData = BarometerGetDrvData(); - CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); drvData->ops.Init = ops->Init; drvData->ops.ReadData = ops->ReadData; return HDF_SUCCESS; @@ -49,16 +43,18 @@ int32_t RegisterBarometerChipOps(const struct BarometerOpsCall *ops) static void BarometerDataWorkEntry(void *arg) { - int32_t ret; - struct BarometerDrvData *drvData = (struct BarometerDrvData *)arg; + struct BarometerDrvData *drvData = NULL; + + drvData = (struct BarometerDrvData *)arg; CHECK_NULL_PTR_RETURN(drvData); - CHECK_NULL_PTR_RETURN(drvData->ops.ReadData); - ret = drvData->ops.ReadData(drvData->barometerCfg); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: barometer read data failed", __func__); + if (drvData->ops.ReadData == NULL) { + HDF_LOGI("%s: Barometer ReadData function NULl", __func__); return; } + if (drvData->ops.ReadData(drvData->barometerCfg) != HDF_SUCCESS) { + HDF_LOGE("%s: Barometer read data failed", __func__); + } } static void BarometerTimerEntry(uintptr_t arg) @@ -80,16 +76,8 @@ static void BarometerTimerEntry(uintptr_t arg) } } -static int32_t InitBarometerData(void) +static int32_t InitBarometerData(struct BarometerDrvData *drvData) { - struct BarometerDrvData *drvData = BarometerGetDrvData(); - int32_t ret; - CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); - - if (drvData->initStatus) { - return HDF_SUCCESS; - } - if (HdfWorkQueueInit(&drvData->barometerWorkQueue, HDF_BAROMETER_WORK_QUEUE_NAME) != HDF_SUCCESS) { HDF_LOGE("%s: barometer init work queue failed", __func__); return HDF_FAILURE; @@ -100,17 +88,9 @@ static int32_t InitBarometerData(void) return HDF_FAILURE; } - CHECK_NULL_PTR_RETURN_VALUE(drvData->ops.Init, HDF_ERR_INVALID_PARAM); - - ret = drvData->ops.Init(drvData->barometerCfg); - if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: barometer create thread failed", __func__); - return HDF_FAILURE; - } - drvData->interval = SENSOR_TIMER_MIN_TIME; - drvData->initStatus = true; drvData->enable = false; + drvData->detectFlag = false; return HDF_SUCCESS; } @@ -215,7 +195,7 @@ static int32_t DispatchBarometer(struct HdfDeviceIoClient *client, return HDF_SUCCESS; } -int32_t BindBarometerDriver(struct HdfDeviceObject *device) +int32_t BarometerBindDriver(struct HdfDeviceObject *device) { CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); @@ -232,11 +212,9 @@ int32_t BindBarometerDriver(struct HdfDeviceObject *device) return HDF_SUCCESS; } -static int32_t InitBarometerOps(struct SensorDeviceInfo *deviceInfo) +static int32_t InitBarometerOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo) { - struct BarometerDrvData *drvData = BarometerGetDrvData(); - - CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); + CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM); deviceInfo->ops.Enable = SetBarometerEnable; deviceInfo->ops.Disable = SetBarometerDisable; @@ -245,7 +223,7 @@ static int32_t InitBarometerOps(struct SensorDeviceInfo *deviceInfo) deviceInfo->ops.SetOption = SetBarometerOption; if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo), - &drvData->barometerCfg->sensorInfo, sizeof(drvData->barometerCfg->sensorInfo)) != EOK) { + &config->sensorInfo, sizeof(config->sensorInfo)) != EOK) { HDF_LOGE("%s: copy sensor info failed", __func__); return HDF_FAILURE; } @@ -253,141 +231,140 @@ static int32_t InitBarometerOps(struct SensorDeviceInfo *deviceInfo) return HDF_SUCCESS; } -static int32_t InitBarometerAfterConfig(void) +static int32_t InitBarometerAfterDetected(struct SensorCfgData *config) { struct SensorDeviceInfo deviceInfo; + CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM); - if (InitBarometerData() != HDF_SUCCESS) { - HDF_LOGE("%s: init barometer config failed", __func__); + if (InitBarometerOps(config, &deviceInfo) != HDF_SUCCESS) { + HDF_LOGE("%s: Init barometer ops failed", __func__); return HDF_FAILURE; } - if (InitBarometerOps(&deviceInfo) != HDF_SUCCESS) { - HDF_LOGE("%s: init barometer ops failed", __func__); + if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) { + HDF_LOGE("%s: Add barometer device failed", __func__); return HDF_FAILURE; } - if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) { - HDF_LOGE("%s: add barometer device failed", __func__); + if (ParseSensorRegConfig(config) != HDF_SUCCESS) { + HDF_LOGE("%s: Parse sensor register failed", __func__); + (void)DeleteSensorDevice(&config->sensorInfo); + ReleaseSensorAllRegConfig(config); return HDF_FAILURE; } - return HDF_SUCCESS; } -static int32_t DetectBarometerChip(void) +struct SensorCfgData *BarometerCreateCfgData(const struct DeviceResourceNode *node) { - int32_t num; - int32_t ret; - int32_t loop; struct BarometerDrvData *drvData = BarometerGetDrvData(); - CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); - CHECK_NULL_PTR_RETURN_VALUE(drvData->barometerCfg, HDF_ERR_INVALID_PARAM); + if (drvData == NULL || node == NULL) { + HDF_LOGE("%s: Barometer node pointer NULL", __func__); + return NULL; + } - num = sizeof(g_barometerDetectIfList) / sizeof(g_barometerDetectIfList[0]); - for (loop = 0; loop < num; ++loop) { - if (g_barometerDetectIfList[loop].DetectChip != NULL) { - ret = g_barometerDetectIfList[loop].DetectChip(drvData->barometerCfg); - if (ret == HDF_SUCCESS) { - drvData->detectFlag = true; - return HDF_SUCCESS; - } - } + if (drvData->detectFlag) { + HDF_LOGE("%s: Barometer sensor have detected", __func__); + return NULL; } - HDF_LOGE("%s: detect barometer device failed", __func__); - drvData->detectFlag = false; - return HDF_FAILURE; + if (drvData->barometerCfg == NULL) { + HDF_LOGE("%s: Barometer barometerCfg pointer NULL", __func__); + return NULL; + } + + if (GetSensorBaseConfigData(node, drvData->barometerCfg) != HDF_SUCCESS) { + HDF_LOGE("%s: Get sensor base config failed", __func__); + goto BASE_CONFIG_EXIT; + } + + if (DetectSensorDevice(drvData->barometerCfg) != HDF_SUCCESS) { + HDF_LOGI("%s: Barometer sensor detect device no exist", __func__); + drvData->detectFlag = false; + goto BASE_CONFIG_EXIT; + } + + drvData->detectFlag = true; + if (InitBarometerAfterDetected(drvData->barometerCfg) != HDF_SUCCESS) { + HDF_LOGE("%s: Barometer sensor detect device no exist", __func__); + goto INIT_EXIT; + } + return drvData->barometerCfg; + +INIT_EXIT: + (void)ReleaseSensorBusHandle(&drvData->barometerCfg->busCfg); +BASE_CONFIG_EXIT: + drvData->barometerCfg->root = NULL; + (void)memset_s(&drvData->barometerCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, + sizeof(struct SensorBasicInfo)); + (void)memset_s(&drvData->barometerCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg)); + (void)memset_s(&drvData->barometerCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr)); + return NULL; } -int32_t InitBarometerDriver(struct HdfDeviceObject *device) +void BarometerReleaseCfgData(struct SensorCfgData *barometerCfg) +{ + CHECK_NULL_PTR_RETURN(barometerCfg); + + (void)DeleteSensorDevice(&barometerCfg->sensorInfo); + ReleaseSensorAllRegConfig(barometerCfg); + (void)ReleaseSensorBusHandle(&barometerCfg->busCfg); + + barometerCfg->root = NULL; + (void)memset_s(&barometerCfg->sensorInfo, sizeof(struct SensorBasicInfo), 0, sizeof(struct SensorBasicInfo)); + (void)memset_s(&barometerCfg->busCfg, sizeof(struct SensorBusCfg), 0, sizeof(struct SensorBusCfg)); + (void)memset_s(&barometerCfg->sensorAttr, sizeof(struct SensorAttr), 0, sizeof(struct SensorAttr)); +} + +int32_t BarometerInitDriver(struct HdfDeviceObject *device) { CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); struct BarometerDrvData *drvData = (struct BarometerDrvData *)device->service; CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); - if (drvData->detectFlag) { - HDF_LOGE("%s: barometer sensor have detected", __func__); - return HDF_SUCCESS; + if (InitBarometerData(drvData) != HDF_SUCCESS) { + HDF_LOGE("%s: Init barometer config failed", __func__); + return HDF_FAILURE; } drvData->barometerCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->barometerCfg)); if (drvData->barometerCfg == NULL) { - HDF_LOGE("%s: malloc sensor config data failed", __func__); + HDF_LOGE("%s: Malloc barometer config data failed", __func__); return HDF_FAILURE; } drvData->barometerCfg->regCfgGroup = &g_regCfgGroup[0]; - if (GetSensorBaseConfigData(device->property, drvData->barometerCfg) != HDF_SUCCESS) { - HDF_LOGE("%s: get sensor base config failed", __func__); - goto BASE_CONFIG_EXIT; - } - - // if return failure, hdf framework go to next detect sensor - if (DetectBarometerChip() != HDF_SUCCESS) { - HDF_LOGE("%s: barometer sensor detect device no exist", __func__); - goto DETECT_CHIP_EXIT; - } - drvData->detectFlag = true; - - if (ParseSensorRegConfig(drvData->barometerCfg) != HDF_SUCCESS) { - HDF_LOGE("%s: detect sensor device failed", __func__); - goto REG_CONFIG_EXIT; - } - - if (InitBarometerAfterConfig() != HDF_SUCCESS) { - HDF_LOGE("%s: init barometer after config failed", __func__); - goto INIT_EXIT; - } - - HDF_LOGI("%s: init barometer driver success", __func__); + HDF_LOGI("%s: Init barometer driver success", __func__); return HDF_SUCCESS; - -INIT_EXIT: - (void)DeleteSensorDevice(&drvData->barometerCfg->sensorInfo); -REG_CONFIG_EXIT: - ReleaseSensorAllRegConfig(drvData->barometerCfg); - (void)ReleaseSensorBusHandle(&drvData->barometerCfg->busCfg); -DETECT_CHIP_EXIT: - drvData->detectFlag = false; -BASE_CONFIG_EXIT: - drvData->barometerCfg->root = NULL; - drvData->barometerCfg->regCfgGroup = NULL; - OsalMemFree(drvData->barometerCfg); - drvData->barometerCfg = NULL; - return HDF_FAILURE; } -void ReleaseBarometerDriver(struct HdfDeviceObject *device) +void BarometerReleaseDriver(struct HdfDeviceObject *device) { CHECK_NULL_PTR_RETURN(device); struct BarometerDrvData *drvData = (struct BarometerDrvData *)device->service; CHECK_NULL_PTR_RETURN(drvData); - (void)DeleteSensorDevice(&drvData->barometerCfg->sensorInfo); - drvData->detectFlag = false; - - if (drvData->barometerCfg != NULL) { - drvData->barometerCfg->root = NULL; - drvData->barometerCfg->regCfgGroup = NULL; - ReleaseSensorAllRegConfig(drvData->barometerCfg); - (void)ReleaseSensorBusHandle(&drvData->barometerCfg->busCfg); - OsalMemFree(drvData->barometerCfg); - drvData->barometerCfg = NULL; + if (drvData->detectFlag) { + BarometerReleaseCfgData(drvData->barometerCfg); } - drvData->initStatus = false; + OsalMemFree(drvData->barometerCfg); + drvData->barometerCfg = NULL; + + HdfWorkDestroy(&drvData->barometerWork); + HdfWorkQueueDestroy(&drvData->barometerWorkQueue); + OsalMemFree(drvData); } struct HdfDriverEntry g_sensorBarometerDevEntry = { .moduleVersion = 1, .moduleName = "HDF_SENSOR_BAROMETER", - .Bind = BindBarometerDriver, - .Init = InitBarometerDriver, - .Release = ReleaseBarometerDriver, + .Bind = BarometerBindDriver, + .Init = BarometerInitDriver, + .Release = BarometerReleaseDriver, }; HDF_INIT(g_sensorBarometerDevEntry); \ No newline at end of file diff --git a/model/sensor/driver/barometer/sensor_barometer_driver.h b/model/sensor/driver/barometer/sensor_barometer_driver.h index 8535bbc41..0888955f0 100644 --- a/model/sensor/driver/barometer/sensor_barometer_driver.h +++ b/model/sensor/driver/barometer/sensor_barometer_driver.h @@ -95,11 +95,6 @@ enum BarometerData { BAROMETER_SUM, }; -struct BarometerDetectIfList { - char *chipName; - int32_t (*DetectChip)(struct SensorCfgData *data); -}; - struct BarometerOpsCall { int32_t (*Init)(struct SensorCfgData *data); int32_t (*ReadData)(struct SensorCfgData *data); @@ -113,12 +108,13 @@ struct BarometerDrvData { OsalTimer barometerTimer; bool detectFlag; bool enable; - bool initStatus; int64_t interval; struct SensorCfgData *barometerCfg; struct BarometerOpsCall ops; }; -int32_t RegisterBarometerChipOps(const struct BarometerOpsCall *ops); +int32_t BarometerRegisterChipOps(const struct BarometerOpsCall *ops); +struct SensorCfgData *BarometerCreateCfgData(const struct DeviceResourceNode *node); +void BarometerReleaseCfgData(struct SensorCfgData *sensorCfgData); #endif /* SENSOR_BAROMETER_DRIVER_H */ \ No newline at end of file diff --git a/model/sensor/driver/chipset/barometer/barometer_bmp180.c b/model/sensor/driver/chipset/barometer/barometer_bmp180.c index 4001a49ef..298684807 100644 --- a/model/sensor/driver/chipset/barometer/barometer_bmp180.c +++ b/model/sensor/driver/chipset/barometer/barometer_bmp180.c @@ -6,16 +6,24 @@ * See the LICENSE file in the root of this repository for complete details. */ -#include "securec.h" #include "barometer_bmp180.h" +#include +#include "osal_mem.h" #include "osal_time.h" #include "sensor_barometer_driver.h" #include "sensor_config_controller.h" #include "sensor_device_manager.h" #include "sensor_platform_if.h" +static struct Bmp180DrvData *g_bmp180DrvData = NULL; + +struct Bmp180DrvData *Bmp180GetDrvData(void) +{ + return g_bmp180DrvData; +} + /* IO config for int-pin and I2C-pin */ -#define SENSOR_I2C6_DDATA_REG_ADDR 0x114f004c +#define SENSOR_I2C6_DATA_REG_ADDR 0x114f004c #define SENSOR_I2C6_CLK_REG_ADDR 0x114f0048 #define SENSOR_I2C_REG_CFG 0x403 @@ -236,7 +244,7 @@ static int32_t CalcBarometerData(struct BarometerRawData *barometerData, int32_ tnp[BAROMETER_BAROMETER] = coefficientData.p + ((coefficientData.x1 + coefficientData.x2 + BMP180_CONSTANT_11) >> BMP180_CONSTANT_3); - return 0; + return HDF_SUCCESS; } int32_t ReadBmp180Data(struct SensorCfgData *data) @@ -302,7 +310,7 @@ static int32_t InitBmp180(struct SensorCfgData *data) static int32_t InitBarometerPreConfig(void) { - if (SetSensorPinMux(SENSOR_I2C6_DDATA_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) { + if (SetSensorPinMux(SENSOR_I2C6_DATA_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) { HDF_LOGE("%s: Data write mux pin failed", __func__); return HDF_FAILURE; } @@ -310,33 +318,94 @@ static int32_t InitBarometerPreConfig(void) HDF_LOGE("%s: Clk write mux pin failed", __func__); return HDF_FAILURE; } + + return HDF_SUCCESS; +} + +static int32_t DispatchBMP180(struct HdfDeviceIoClient *client, + int cmd, struct HdfSBuf *data, struct HdfSBuf *reply) +{ + (void)client; + (void)cmd; + (void)data; + (void)reply; + + return HDF_SUCCESS; +} + +int32_t Bmp180BindDriver(struct HdfDeviceObject *device) +{ + CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); + + struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)OsalMemCalloc(sizeof(*drvData)); + if (drvData == NULL) { + HDF_LOGE("%s: Malloc Bmi160 drv data fail", __func__); + return HDF_ERR_MALLOC_FAIL; + } + + drvData->ioService.Dispatch = DispatchBMP180; + drvData->device = device; + device->service = &drvData->ioService; + g_bmp180DrvData = drvData; + return HDF_SUCCESS; } -int32_t DetectBarometerBmp180Chip(struct SensorCfgData *data) -{ +int32_t Bmp180InitDriver(struct HdfDeviceObject *device) +{ int32_t ret; struct BarometerOpsCall ops; - CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM); - if (strcmp(BAROMETER_CHIP_NAME_BMP180, data->sensorAttr.chipName) != 0) { - return HDF_SUCCESS; - } + CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM); + struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)device->service; + CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM); + ret = InitBarometerPreConfig(); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: init bmp180 bus mux config", __func__); + HDF_LOGE("%s: Init BMp180 bus mux config", __func__); return HDF_FAILURE; } - if (DetectSensorDevice(data) != HDF_SUCCESS) { - return HDF_FAILURE; + + drvData->sensorCfg = BarometerCreateCfgData(device->property); + if (drvData->sensorCfg == NULL) { + return HDF_ERR_NOT_SUPPORT; } - ops.Init = InitBmp180; + + ops.Init = NULL; ops.ReadData = ReadBmp180Data; - ret = RegisterBarometerChipOps(&ops); + ret = BarometerRegisterChipOps(&ops); + if (ret != HDF_SUCCESS) { + HDF_LOGE("%s: Register BMp180 barometer failed", __func__); + return HDF_FAILURE; + } + + ret = InitBmp180(drvData->sensorCfg); if (ret != HDF_SUCCESS) { - HDF_LOGE("%s: register bmp180 barometer failed", __func__); - (void)ReleaseSensorBusHandle(&data->busCfg); + HDF_LOGE("%s: Init BMP180 barometer failed", __func__); return HDF_FAILURE; } + return HDF_SUCCESS; -} \ No newline at end of file +} + +void Bmp180ReleaseDriver(struct HdfDeviceObject *device) +{ + CHECK_NULL_PTR_RETURN(device); + + struct Bmp180DrvData *drvData = (struct Bmp180DrvData *)device->service; + CHECK_NULL_PTR_RETURN(drvData); + + BarometerReleaseCfgData(drvData->sensorCfg); + drvData->sensorCfg = NULL; + OsalMemFree(drvData); +} + +struct HdfDriverEntry g_barometerBmp180DevEntry = { + .moduleVersion = 1, + .moduleName = "HDF_SENSOR_BAROMETER_BMP180", + .Bind = Bmp180BindDriver, + .Init = Bmp180InitDriver, + .Release = Bmp180ReleaseDriver, +}; + +HDF_INIT(g_barometerBmp180DevEntry); \ No newline at end of file diff --git a/model/sensor/driver/chipset/barometer/barometer_bmp180.h b/model/sensor/driver/chipset/barometer/barometer_bmp180.h index 958088458..a361405bf 100644 --- a/model/sensor/driver/chipset/barometer/barometer_bmp180.h +++ b/model/sensor/driver/chipset/barometer/barometer_bmp180.h @@ -9,13 +9,14 @@ #ifndef BAROMETER_BMP180_H #define BAROMETER_BMP180_H +#include "sensor_barometer_driver.h" #include "sensor_config_parser.h" -#define BMP180_REG_CHIP_ID 0xD0 +#define BMP180_REG_CHIP_ID 0xD0 // i2c slave address -#define BMP180_ADDR 0x77 +#define BMP180_ADDR 0x77 // Define calibration register address @@ -33,7 +34,7 @@ #define BMP180_AC6_LSB_ADDR 0xB5 #define BMP180_B1_MSB_ADDR 0xB6 #define BMP180_B1_LSB_ADDR 0xB7 -#define BMP180_B2_MSB_ADDR 0xB8 +#define BMP180_B2_MSB_ADDR 0xB8 #define BMP180_B2_LSB_ADDR 0xB9 #define BMP180_MB_MSB_ADDR 0xBA #define BMP180_MB_LSB_ADDR 0xBB @@ -44,26 +45,26 @@ // Control register -#define BMP180_CONTROL_REG_ADDR 0xF4 -#define BMP180_COVERT_TEMP 0x2E -#define BMP180_COVERT_PRES_0 0x34 -#define BMP180_COVERT_PRES_1 0x74 -#define BMP180_COVERT_PRES_2 0xB4 -#define BMP180_COVERT_PRES_3 0xF4 +#define BMP180_CONTROL_REG_ADDR 0xF4 +#define BMP180_COVERT_TEMP 0x2E +#define BMP180_COVERT_PRES_0 0x34 +#define BMP180_COVERT_PRES_1 0x74 +#define BMP180_COVERT_PRES_2 0xB4 +#define BMP180_COVERT_PRES_3 0xF4 -#define BMP180_OUT_MSB_ADDR 0xF6 -#define BMP180_OUT_LSB_ADDR 0xF7 -#define BMP180_OUT_XLSB_ADDR 0xF8 +#define BMP180_OUT_MSB_ADDR 0xF6 +#define BMP180_OUT_LSB_ADDR 0xF7 +#define BMP180_OUT_XLSB_ADDR 0xF8 #define BMP180_STATUS_ADDR 0X20 #define BMP180_STATUS_JUDGE 0X00 -#define SENSOR_DATA_WIDTH_16_BIT 16 +#define SENSOR_DATA_WIDTH_16_BIT 16 #define OSSETTING 1 #define DELAY_0 5 #define DELAY_1 8 -#define OSS_TIME_MS 26 +#define OSS_TIME_MS 26 #define BMP180_CONSTANT_0 (-7357) #define BMP180_CONSTANT_1 1 @@ -86,4 +87,10 @@ int32_t DetectBarometerBmp180Chip(struct SensorCfgData *data); int32_t ReadBmp180Data(struct SensorCfgData *data); +struct Bmp180DrvData { + struct IDeviceIoService ioService; + struct HdfDeviceObject *device; + struct SensorCfgData *sensorCfg; +}; + #endif /* BAROMETER_BMP180_H */ \ No newline at end of file -- Gitee