mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-08-28 04:59:54 -04:00
modify sensor format
Signed-off-by: kevin <liufeihu@huawei.com> Change-Id: Ib8dd76636aaf9b3477bc5aea5e7345b1197610f3
This commit is contained in:
@@ -1,370 +1,370 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "sensor_barometer_driver.h"
|
||||
#include <securec.h>
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "osal_math.h"
|
||||
#include "osal_mem.h"
|
||||
#include "sensor_config_controller.h"
|
||||
#include "sensor_device_manager.h"
|
||||
#include "sensor_platform_if.h"
|
||||
|
||||
#define HDF_LOG_TAG sensor_barometer_driver_c
|
||||
|
||||
#define HDF_BAROMETER_WORK_QUEUE_NAME "hdf_barometer_work_queue"
|
||||
|
||||
static struct BarometerDrvData *g_barometerDrvData = NULL;
|
||||
|
||||
static struct BarometerDrvData *BarometerGetDrvData(void)
|
||||
{
|
||||
return g_barometerDrvData;
|
||||
}
|
||||
|
||||
static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
|
||||
|
||||
int32_t BarometerRegisterChipOps(const struct BarometerOpsCall *ops)
|
||||
{
|
||||
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->ops.Init = ops->Init;
|
||||
drvData->ops.ReadData = ops->ReadData;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void BarometerDataWorkEntry(void *arg)
|
||||
{
|
||||
struct BarometerDrvData *drvData = NULL;
|
||||
|
||||
drvData = (struct BarometerDrvData *)arg;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
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)
|
||||
{
|
||||
int64_t interval;
|
||||
int32_t ret;
|
||||
struct BarometerDrvData *drvData = (struct BarometerDrvData *)arg;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
if (!HdfAddWork(&drvData->barometerWorkQueue, &drvData->barometerWork)) {
|
||||
HDF_LOGE("%s: barometer add work queue failed", __func__);
|
||||
}
|
||||
|
||||
interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
|
||||
interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
|
||||
ret = OsalTimerSetTimeout(&drvData->barometerTimer, interval);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer modify time failed", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t InitBarometerData(struct BarometerDrvData *drvData)
|
||||
{
|
||||
if (HdfWorkQueueInit(&drvData->barometerWorkQueue, HDF_BAROMETER_WORK_QUEUE_NAME) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer init work queue failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (HdfWorkInit(&drvData->barometerWork, BarometerDataWorkEntry, drvData) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer create thread failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
drvData->interval = SENSOR_TIMER_MIN_TIME;
|
||||
drvData->enable = false;
|
||||
drvData->detectFlag = false;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerEnable(void)
|
||||
{
|
||||
int32_t ret;
|
||||
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->enable) {
|
||||
HDF_LOGE("%s: barometer sensor is enabled", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
ret = SetSensorRegCfgArray(&drvData->barometerCfg->busCfg, drvData->barometerCfg->regCfgGroup[SENSOR_ENABLE_GROUP]);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer sensor enable config failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsalTimerCreate(&drvData->barometerTimer, SENSOR_TIMER_MIN_TIME, BarometerTimerEntry, (uintptr_t)drvData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer create timer failed[%d]", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsalTimerStartLoop(&drvData->barometerTimer);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer start timer failed[%d]", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
drvData->enable = true;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerDisable(void)
|
||||
{
|
||||
int32_t ret;
|
||||
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->enable) {
|
||||
HDF_LOGE("%s: barometer sensor had disable", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
ret = SetSensorRegCfgArray(&drvData->barometerCfg->busCfg,
|
||||
drvData->barometerCfg->regCfgGroup[SENSOR_DISABLE_GROUP]);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer sensor disable config failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsalTimerDelete(&drvData->barometerTimer);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer delete timer failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
drvData->enable = false;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerBatch(int64_t samplingInterval, int64_t interval)
|
||||
{
|
||||
(void)interval;
|
||||
|
||||
struct BarometerDrvData *drvData = NULL;
|
||||
|
||||
drvData = BarometerGetDrvData();
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
drvData->interval = samplingInterval;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerMode(int32_t mode)
|
||||
{
|
||||
return (mode == SENSOR_WORK_MODE_REALTIME) ? HDF_SUCCESS : HDF_FAILURE;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerOption(uint32_t option)
|
||||
{
|
||||
(void)option;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t DispatchBarometer(struct HdfDeviceIoClient *client,
|
||||
int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
(void)client;
|
||||
(void)cmd;
|
||||
(void)data;
|
||||
(void)reply;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t BarometerBindDriver(struct HdfDeviceObject *device)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
struct BarometerDrvData *drvData = (struct BarometerDrvData *)OsalMemCalloc(sizeof(*drvData));
|
||||
if (drvData == NULL) {
|
||||
HDF_LOGE("%s: malloc barometer drv data fail!", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
drvData->ioService.Dispatch = DispatchBarometer;
|
||||
drvData->device = device;
|
||||
device->service = &drvData->ioService;
|
||||
g_barometerDrvData = drvData;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t InitBarometerOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
deviceInfo->ops.Enable = SetBarometerEnable;
|
||||
deviceInfo->ops.Disable = SetBarometerDisable;
|
||||
deviceInfo->ops.SetBatch = SetBarometerBatch;
|
||||
deviceInfo->ops.SetMode = SetBarometerMode;
|
||||
deviceInfo->ops.SetOption = SetBarometerOption;
|
||||
|
||||
if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo),
|
||||
&config->sensorInfo, sizeof(config->sensorInfo)) != EOK) {
|
||||
HDF_LOGE("%s: copy sensor info failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t InitBarometerAfterDetected(struct SensorCfgData *config)
|
||||
{
|
||||
struct SensorDeviceInfo deviceInfo;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
if (InitBarometerOps(config, &deviceInfo) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: Init barometer ops failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: Add barometer device failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
struct SensorCfgData *BarometerCreateCfgData(const struct DeviceResourceNode *node)
|
||||
{
|
||||
struct BarometerDrvData *drvData = BarometerGetDrvData();
|
||||
|
||||
if (drvData == NULL || node == NULL) {
|
||||
HDF_LOGE("%s: Barometer node pointer NULL", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (drvData->detectFlag) {
|
||||
HDF_LOGE("%s: Barometer sensor have detected", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 (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 barometer config data failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
drvData->barometerCfg->regCfgGroup = &g_regCfgGroup[0];
|
||||
|
||||
HDF_LOGI("%s: Init barometer driver success", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void BarometerReleaseDriver(struct HdfDeviceObject *device)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN(device);
|
||||
|
||||
struct BarometerDrvData *drvData = (struct BarometerDrvData *)device->service;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
if (drvData->detectFlag) {
|
||||
BarometerReleaseCfgData(drvData->barometerCfg);
|
||||
}
|
||||
|
||||
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 = BarometerBindDriver,
|
||||
.Init = BarometerInitDriver,
|
||||
.Release = BarometerReleaseDriver,
|
||||
};
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "sensor_barometer_driver.h"
|
||||
#include <securec.h>
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "osal_math.h"
|
||||
#include "osal_mem.h"
|
||||
#include "sensor_config_controller.h"
|
||||
#include "sensor_device_manager.h"
|
||||
#include "sensor_platform_if.h"
|
||||
|
||||
#define HDF_LOG_TAG sensor_barometer_driver_c
|
||||
|
||||
#define HDF_BAROMETER_WORK_QUEUE_NAME "hdf_barometer_work_queue"
|
||||
|
||||
static struct BarometerDrvData *g_barometerDrvData = NULL;
|
||||
|
||||
static struct BarometerDrvData *BarometerGetDrvData(void)
|
||||
{
|
||||
return g_barometerDrvData;
|
||||
}
|
||||
|
||||
static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
|
||||
|
||||
int32_t BarometerRegisterChipOps(const struct BarometerOpsCall *ops)
|
||||
{
|
||||
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->ops.Init = ops->Init;
|
||||
drvData->ops.ReadData = ops->ReadData;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void BarometerDataWorkEntry(void *arg)
|
||||
{
|
||||
struct BarometerDrvData *drvData = NULL;
|
||||
|
||||
drvData = (struct BarometerDrvData *)arg;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
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)
|
||||
{
|
||||
int64_t interval;
|
||||
int32_t ret;
|
||||
struct BarometerDrvData *drvData = (struct BarometerDrvData *)arg;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
if (!HdfAddWork(&drvData->barometerWorkQueue, &drvData->barometerWork)) {
|
||||
HDF_LOGE("%s: barometer add work queue failed", __func__);
|
||||
}
|
||||
|
||||
interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
|
||||
interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
|
||||
ret = OsalTimerSetTimeout(&drvData->barometerTimer, interval);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer modify time failed", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t InitBarometerData(struct BarometerDrvData *drvData)
|
||||
{
|
||||
if (HdfWorkQueueInit(&drvData->barometerWorkQueue, HDF_BAROMETER_WORK_QUEUE_NAME) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer init work queue failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (HdfWorkInit(&drvData->barometerWork, BarometerDataWorkEntry, drvData) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer create thread failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
drvData->interval = SENSOR_TIMER_MIN_TIME;
|
||||
drvData->enable = false;
|
||||
drvData->detectFlag = false;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerEnable(void)
|
||||
{
|
||||
int32_t ret;
|
||||
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->enable) {
|
||||
HDF_LOGE("%s: barometer sensor is enabled", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
ret = SetSensorRegCfgArray(&drvData->barometerCfg->busCfg, drvData->barometerCfg->regCfgGroup[SENSOR_ENABLE_GROUP]);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer sensor enable config failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsalTimerCreate(&drvData->barometerTimer, SENSOR_TIMER_MIN_TIME, BarometerTimerEntry, (uintptr_t)drvData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer create timer failed[%d]", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsalTimerStartLoop(&drvData->barometerTimer);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer start timer failed[%d]", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
drvData->enable = true;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerDisable(void)
|
||||
{
|
||||
int32_t ret;
|
||||
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->enable) {
|
||||
HDF_LOGE("%s: barometer sensor had disable", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
ret = SetSensorRegCfgArray(&drvData->barometerCfg->busCfg,
|
||||
drvData->barometerCfg->regCfgGroup[SENSOR_DISABLE_GROUP]);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer sensor disable config failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsalTimerDelete(&drvData->barometerTimer);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: barometer delete timer failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
drvData->enable = false;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerBatch(int64_t samplingInterval, int64_t interval)
|
||||
{
|
||||
(void)interval;
|
||||
|
||||
struct BarometerDrvData *drvData = NULL;
|
||||
|
||||
drvData = BarometerGetDrvData();
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
drvData->interval = samplingInterval;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerMode(int32_t mode)
|
||||
{
|
||||
return (mode == SENSOR_WORK_MODE_REALTIME) ? HDF_SUCCESS : HDF_FAILURE;
|
||||
}
|
||||
|
||||
static int32_t SetBarometerOption(uint32_t option)
|
||||
{
|
||||
(void)option;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t DispatchBarometer(struct HdfDeviceIoClient *client,
|
||||
int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
(void)client;
|
||||
(void)cmd;
|
||||
(void)data;
|
||||
(void)reply;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t BarometerBindDriver(struct HdfDeviceObject *device)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
struct BarometerDrvData *drvData = (struct BarometerDrvData *)OsalMemCalloc(sizeof(*drvData));
|
||||
if (drvData == NULL) {
|
||||
HDF_LOGE("%s: malloc barometer drv data fail!", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
drvData->ioService.Dispatch = DispatchBarometer;
|
||||
drvData->device = device;
|
||||
device->service = &drvData->ioService;
|
||||
g_barometerDrvData = drvData;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t InitBarometerOps(struct SensorCfgData *config, struct SensorDeviceInfo *deviceInfo)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
deviceInfo->ops.Enable = SetBarometerEnable;
|
||||
deviceInfo->ops.Disable = SetBarometerDisable;
|
||||
deviceInfo->ops.SetBatch = SetBarometerBatch;
|
||||
deviceInfo->ops.SetMode = SetBarometerMode;
|
||||
deviceInfo->ops.SetOption = SetBarometerOption;
|
||||
|
||||
if (memcpy_s(&deviceInfo->sensorInfo, sizeof(deviceInfo->sensorInfo),
|
||||
&config->sensorInfo, sizeof(config->sensorInfo)) != EOK) {
|
||||
HDF_LOGE("%s: copy sensor info failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t InitBarometerAfterDetected(struct SensorCfgData *config)
|
||||
{
|
||||
struct SensorDeviceInfo deviceInfo;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(config, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
if (InitBarometerOps(config, &deviceInfo) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: Init barometer ops failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (AddSensorDevice(&deviceInfo) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: Add barometer device failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
struct SensorCfgData *BarometerCreateCfgData(const struct DeviceResourceNode *node)
|
||||
{
|
||||
struct BarometerDrvData *drvData = BarometerGetDrvData();
|
||||
|
||||
if (drvData == NULL || node == NULL) {
|
||||
HDF_LOGE("%s: Barometer node pointer NULL", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (drvData->detectFlag) {
|
||||
HDF_LOGE("%s: Barometer sensor have detected", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 (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 barometer config data failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
drvData->barometerCfg->regCfgGroup = &g_regCfgGroup[0];
|
||||
|
||||
HDF_LOGI("%s: Init barometer driver success", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void BarometerReleaseDriver(struct HdfDeviceObject *device)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN(device);
|
||||
|
||||
struct BarometerDrvData *drvData = (struct BarometerDrvData *)device->service;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
if (drvData->detectFlag) {
|
||||
BarometerReleaseCfgData(drvData->barometerCfg);
|
||||
}
|
||||
|
||||
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 = BarometerBindDriver,
|
||||
.Init = BarometerInitDriver,
|
||||
.Release = BarometerReleaseDriver,
|
||||
};
|
||||
|
||||
HDF_INIT(g_sensorBarometerDevEntry);
|
||||
@@ -1,119 +1,119 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef SENSOR_BAROMETER_DRIVER_H
|
||||
#define SENSOR_BAROMETER_DRIVER_H
|
||||
|
||||
#include "hdf_workqueue.h"
|
||||
#include "osal_timer.h"
|
||||
#include "sensor_config_parser.h"
|
||||
#include "sensor_platform_if.h"
|
||||
|
||||
#define BAR_DEFAULT_SAMPLING_200_MS 200000000
|
||||
#define BAROMETER_CHIP_NAME_BMP180 "bmp180"
|
||||
|
||||
enum BarometerEeprom {
|
||||
BAROMETER_AC1_MSB = 0,
|
||||
BAROMETER_AC1_LSB = 1,
|
||||
BAROMETER_AC2_MSB = 2,
|
||||
BAROMETER_AC2_LSB = 3,
|
||||
BAROMETER_AC3_MSB = 4,
|
||||
BAROMETER_AC3_LSB = 5,
|
||||
BAROMETER_AC4_MSB = 6,
|
||||
BAROMETER_AC4_LSB = 7,
|
||||
BAROMETER_AC5_MSB = 8,
|
||||
BAROMETER_AC5_LSB = 9,
|
||||
BAROMETER_AC6_MSB = 10,
|
||||
BAROMETER_AC6_LSB = 11,
|
||||
BAROMETER_B1_MSB = 12,
|
||||
BAROMETER_B1_LSB = 13,
|
||||
BAROMETER_B2_MSB = 14,
|
||||
BAROMETER_B2_LSB = 15,
|
||||
BAROMETER_MB_MSB = 16,
|
||||
BAROMETER_MB_LSB = 17,
|
||||
BAROMETER_MC_MSB = 18,
|
||||
BAROMETER_MC_LSB = 19,
|
||||
BAROMETER_MD_MSB = 20,
|
||||
BAROMETER_MD_LSB = 21,
|
||||
BAROMETER_EEPROM_SUM,
|
||||
};
|
||||
|
||||
struct BarometerEepromData {
|
||||
int32_t ac1;
|
||||
int32_t ac2;
|
||||
int32_t ac3;
|
||||
int32_t b1;
|
||||
int32_t b2;
|
||||
int32_t mb;
|
||||
int32_t mc;
|
||||
int32_t md;
|
||||
uint32_t ac4;
|
||||
uint32_t ac5;
|
||||
uint32_t ac6;
|
||||
};
|
||||
|
||||
struct Coefficient {
|
||||
int32_t b3;
|
||||
int32_t b5;
|
||||
int32_t b6;
|
||||
int32_t x1;
|
||||
int32_t x2;
|
||||
int32_t x3;
|
||||
int32_t p;
|
||||
uint32_t b4;
|
||||
uint32_t b7;
|
||||
};
|
||||
|
||||
enum Temperature {
|
||||
BAROMETER_TEM_MSB = 0,
|
||||
BAROMETER_TEM_LSB = 1,
|
||||
BAROMETER_TEM_SUM,
|
||||
};
|
||||
|
||||
enum Barometer {
|
||||
BAROMETER_BAR_MSB = 0,
|
||||
BAROMETER_BAR_LSB = 1,
|
||||
BAROMETER_BAR_XLSB = 2,
|
||||
BAROMETER_BAR_SUM,
|
||||
};
|
||||
|
||||
struct BarometerRawData {
|
||||
int32_t unpensatePre;
|
||||
int32_t unpensateTemp;
|
||||
};
|
||||
|
||||
enum BarometerData {
|
||||
BAROMETER_BAROMETER = 0,
|
||||
BAROMETER_TEMPERATURE = 1,
|
||||
BAROMETER_ALTITUDE = 2,
|
||||
BAROMETER_SUM,
|
||||
};
|
||||
|
||||
struct BarometerOpsCall {
|
||||
int32_t (*Init)(struct SensorCfgData *data);
|
||||
int32_t (*ReadData)(struct SensorCfgData *data);
|
||||
};
|
||||
|
||||
struct BarometerDrvData {
|
||||
struct IDeviceIoService ioService;
|
||||
struct HdfDeviceObject *device;
|
||||
HdfWorkQueue barometerWorkQueue;
|
||||
HdfWork barometerWork;
|
||||
OsalTimer barometerTimer;
|
||||
bool detectFlag;
|
||||
bool enable;
|
||||
int64_t interval;
|
||||
struct SensorCfgData *barometerCfg;
|
||||
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 */
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef SENSOR_BAROMETER_DRIVER_H
|
||||
#define SENSOR_BAROMETER_DRIVER_H
|
||||
|
||||
#include "hdf_workqueue.h"
|
||||
#include "osal_timer.h"
|
||||
#include "sensor_config_parser.h"
|
||||
#include "sensor_platform_if.h"
|
||||
|
||||
#define BAR_DEFAULT_SAMPLING_200_MS 200000000
|
||||
#define BAROMETER_CHIP_NAME_BMP180 "bmp180"
|
||||
|
||||
enum BarometerEeprom {
|
||||
BAROMETER_AC1_MSB = 0,
|
||||
BAROMETER_AC1_LSB = 1,
|
||||
BAROMETER_AC2_MSB = 2,
|
||||
BAROMETER_AC2_LSB = 3,
|
||||
BAROMETER_AC3_MSB = 4,
|
||||
BAROMETER_AC3_LSB = 5,
|
||||
BAROMETER_AC4_MSB = 6,
|
||||
BAROMETER_AC4_LSB = 7,
|
||||
BAROMETER_AC5_MSB = 8,
|
||||
BAROMETER_AC5_LSB = 9,
|
||||
BAROMETER_AC6_MSB = 10,
|
||||
BAROMETER_AC6_LSB = 11,
|
||||
BAROMETER_B1_MSB = 12,
|
||||
BAROMETER_B1_LSB = 13,
|
||||
BAROMETER_B2_MSB = 14,
|
||||
BAROMETER_B2_LSB = 15,
|
||||
BAROMETER_MB_MSB = 16,
|
||||
BAROMETER_MB_LSB = 17,
|
||||
BAROMETER_MC_MSB = 18,
|
||||
BAROMETER_MC_LSB = 19,
|
||||
BAROMETER_MD_MSB = 20,
|
||||
BAROMETER_MD_LSB = 21,
|
||||
BAROMETER_EEPROM_SUM,
|
||||
};
|
||||
|
||||
struct BarometerEepromData {
|
||||
int32_t ac1;
|
||||
int32_t ac2;
|
||||
int32_t ac3;
|
||||
int32_t b1;
|
||||
int32_t b2;
|
||||
int32_t mb;
|
||||
int32_t mc;
|
||||
int32_t md;
|
||||
uint32_t ac4;
|
||||
uint32_t ac5;
|
||||
uint32_t ac6;
|
||||
};
|
||||
|
||||
struct Coefficient {
|
||||
int32_t b3;
|
||||
int32_t b5;
|
||||
int32_t b6;
|
||||
int32_t x1;
|
||||
int32_t x2;
|
||||
int32_t x3;
|
||||
int32_t p;
|
||||
uint32_t b4;
|
||||
uint32_t b7;
|
||||
};
|
||||
|
||||
enum Temperature {
|
||||
BAROMETER_TEM_MSB = 0,
|
||||
BAROMETER_TEM_LSB = 1,
|
||||
BAROMETER_TEM_SUM,
|
||||
};
|
||||
|
||||
enum Barometer {
|
||||
BAROMETER_BAR_MSB = 0,
|
||||
BAROMETER_BAR_LSB = 1,
|
||||
BAROMETER_BAR_XLSB = 2,
|
||||
BAROMETER_BAR_SUM,
|
||||
};
|
||||
|
||||
struct BarometerRawData {
|
||||
int32_t unpensatePre;
|
||||
int32_t unpensateTemp;
|
||||
};
|
||||
|
||||
enum BarometerData {
|
||||
BAROMETER_BAROMETER = 0,
|
||||
BAROMETER_TEMPERATURE = 1,
|
||||
BAROMETER_ALTITUDE = 2,
|
||||
BAROMETER_SUM,
|
||||
};
|
||||
|
||||
struct BarometerOpsCall {
|
||||
int32_t (*Init)(struct SensorCfgData *data);
|
||||
int32_t (*ReadData)(struct SensorCfgData *data);
|
||||
};
|
||||
|
||||
struct BarometerDrvData {
|
||||
struct IDeviceIoService ioService;
|
||||
struct HdfDeviceObject *device;
|
||||
HdfWorkQueue barometerWorkQueue;
|
||||
HdfWork barometerWork;
|
||||
OsalTimer barometerTimer;
|
||||
bool detectFlag;
|
||||
bool enable;
|
||||
int64_t interval;
|
||||
struct SensorCfgData *barometerCfg;
|
||||
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 */
|
||||
|
||||
@@ -1,411 +1,411 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "barometer_bmp180.h"
|
||||
#include <securec.h>
|
||||
#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_DATA_REG_ADDR 0x114f004c
|
||||
#define SENSOR_I2C6_CLK_REG_ADDR 0x114f0048
|
||||
#define SENSOR_I2C_REG_CFG 0x403
|
||||
|
||||
static struct BarometerEepromData g_calibraData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
static int32_t ReadEepromRawData(struct SensorCfgData *data, uint8_t rfg[BAROMETER_EEPROM_SUM])
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC1_MSB_ADDR, &rfg[BAROMETER_AC1_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC1_LSB_ADDR, &rfg[BAROMETER_AC1_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC2_MSB_ADDR, &rfg[BAROMETER_AC2_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC2_LSB_ADDR, &rfg[BAROMETER_AC2_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC3_MSB_ADDR, &rfg[BAROMETER_AC3_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC3_LSB_ADDR, &rfg[BAROMETER_AC3_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC4_MSB_ADDR, &rfg[BAROMETER_AC4_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC4_LSB_ADDR, &rfg[BAROMETER_AC4_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC5_MSB_ADDR, &rfg[BAROMETER_AC5_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC5_LSB_ADDR, &rfg[BAROMETER_AC5_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC6_MSB_ADDR, &rfg[BAROMETER_AC6_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC6_LSB_ADDR, &rfg[BAROMETER_AC6_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_B1_MSB_ADDR, &rfg[BAROMETER_B1_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_B1_LSB_ADDR, &rfg[BAROMETER_B1_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_B2_MSB_ADDR, &rfg[BAROMETER_B2_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_B2_LSB_ADDR, &rfg[BAROMETER_B2_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MB_MSB_ADDR, &rfg[BAROMETER_MB_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MB_LSB_ADDR, &rfg[BAROMETER_MB_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MC_MSB_ADDR, &rfg[BAROMETER_MC_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MC_LSB_ADDR, &rfg[BAROMETER_MC_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MD_MSB_ADDR, &rfg[BAROMETER_MD_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MD_LSB_ADDR, &rfg[BAROMETER_MD_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ReadEepromData(struct SensorCfgData *data, struct BarometerEepromData *g_calibraData)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t reg[BAROMETER_EEPROM_SUM];
|
||||
|
||||
(void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
ret = ReadEepromRawData(data, reg);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
g_calibraData->ac1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC1_LSB]);
|
||||
g_calibraData->ac2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC2_LSB]);
|
||||
g_calibraData->ac3 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC3_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC3_LSB]);
|
||||
g_calibraData->ac4 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC4_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC4_LSB]);
|
||||
g_calibraData->ac5 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC5_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC5_LSB]);
|
||||
g_calibraData->ac6 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC6_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC6_LSB]);
|
||||
g_calibraData->b1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_B1_LSB]);
|
||||
g_calibraData->b2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_B2_LSB]);
|
||||
g_calibraData->mb = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MB_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_MB_LSB]);
|
||||
g_calibraData->mc = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MC_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_MC_LSB]);
|
||||
g_calibraData->md = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MD_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_MD_LSB]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ReadTempData(struct SensorCfgData *data, struct BarometerRawData *Temp)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t status = 0;
|
||||
uint8_t reg[BAROMETER_TEM_SUM];
|
||||
uint8_t value[SENSOR_VALUE_BUTT];
|
||||
value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
|
||||
value[SENSOR_VALUE_INDEX] = BMP180_COVERT_TEMP;
|
||||
|
||||
(void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
|
||||
if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
|
||||
WriteSensor(&data->busCfg, value, sizeof(value));
|
||||
OsalMDelay(DELAY_0);
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, ®[BAROMETER_TEM_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, ®[BAROMETER_TEM_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
Temp->unpensateTemp = (int32_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_TEM_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_TEM_LSB]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ReadBarometerData(struct SensorCfgData *data, struct BarometerRawData *Barom)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t status = 0;
|
||||
uint8_t reg[BAROMETER_BAR_SUM];
|
||||
uint8_t value[SENSOR_VALUE_BUTT];
|
||||
value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
|
||||
value[SENSOR_VALUE_INDEX] = BMP180_COVERT_PRES_1;
|
||||
|
||||
(void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
|
||||
if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
|
||||
WriteSensor(&data->busCfg, value, sizeof(value));
|
||||
OsalMDelay(DELAY_1);
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, ®[BAROMETER_BAR_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, ®[BAROMETER_BAR_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_XLSB_ADDR, ®[BAROMETER_BAR_XLSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
Barom->unpensatePre = (int32_t)(SENSOR_DATA_SHIFT_RIGHT(
|
||||
(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_MSB], SENSOR_DATA_WIDTH_16_BIT) |
|
||||
SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_LSB], SENSOR_DATA_WIDTH_8_BIT) | reg[BAROMETER_BAR_XLSB]),
|
||||
(BMP180_CONSTANT_4 - OSSETTING)));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t CalcBarometerData(struct BarometerRawData *barometerData, int32_t tnp[BAROMETER_SUM])
|
||||
{
|
||||
struct Coefficient coefficientData = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// Calculated temperature
|
||||
|
||||
coefficientData.x1 = ((barometerData->unpensateTemp - g_calibraData.ac6) * (g_calibraData.ac5))
|
||||
>> BMP180_CONSTANT_8;
|
||||
coefficientData.x2 = (g_calibraData.mc << BMP180_CONSTANT_5) / (coefficientData.x1 + g_calibraData.md);
|
||||
coefficientData.b5 = coefficientData.x1 + coefficientData.x2;
|
||||
tnp[BAROMETER_TEMPERATURE] = (coefficientData.b5 + BMP180_CONSTANT_4) >> BMP180_CONSTANT_3;
|
||||
|
||||
// Calculated pressure
|
||||
|
||||
coefficientData.b6 = coefficientData.b5 - BMP180_CONSTANT_12;
|
||||
coefficientData.x1 = (g_calibraData.b2 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
|
||||
>> BMP180_CONSTANT_5;
|
||||
coefficientData.x2 = (g_calibraData.ac2 * coefficientData.b6) >> BMP180_CONSTANT_5;
|
||||
coefficientData.x3 = coefficientData.x1 + coefficientData.x2;
|
||||
coefficientData.b3 = (((((int32_t)g_calibraData.ac1) * BMP180_CONSTANT_3 + coefficientData.x3) << OSSETTING)
|
||||
+ BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
|
||||
coefficientData.x1 = (g_calibraData.ac3 * coefficientData.b6) >> BMP180_CONSTANT_7;
|
||||
coefficientData.x2 = (g_calibraData.b1 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
|
||||
>> BMP180_CONSTANT_9;
|
||||
coefficientData.x3 = ((coefficientData.x1 + coefficientData.x2) + BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
|
||||
coefficientData.b4 = (g_calibraData.ac4 * (uint32_t)(coefficientData.x3 + BMP180_CONSTANT_13))
|
||||
>> BMP180_CONSTANT_8;
|
||||
coefficientData.b7 = ((uint32_t)(barometerData->unpensatePre) - (uint32_t)coefficientData.b3)
|
||||
* (BMP180_CONSTANT_14 >> OSSETTING);
|
||||
if (coefficientData.b7 < BMP180_CONSTANT_15) {
|
||||
coefficientData.p = (coefficientData.b7 << BMP180_CONSTANT_1) / coefficientData.b4;
|
||||
} else {
|
||||
coefficientData.p = (coefficientData.b7 / coefficientData.b4) << BMP180_CONSTANT_1;
|
||||
}
|
||||
coefficientData.x1 = (coefficientData.p >> BMP180_CONSTANT_4) * (coefficientData.p >> BMP180_CONSTANT_4);
|
||||
coefficientData.x1 = (coefficientData.x1 * BMP180_CONSTANT_10) >> BMP180_CONSTANT_9;
|
||||
coefficientData.x2 = (BMP180_CONSTANT_0 * coefficientData.p) >> BMP180_CONSTANT_9;
|
||||
tnp[BAROMETER_BAROMETER] = coefficientData.p + ((coefficientData.x1 + coefficientData.x2
|
||||
+ BMP180_CONSTANT_11) >> BMP180_CONSTANT_3);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ReadBmp180Data(struct SensorCfgData *data)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t tmp[BAROMETER_SUM];
|
||||
struct BarometerRawData barometerData = {0, 0};
|
||||
OsalTimespec time;
|
||||
struct SensorReportEvent event;
|
||||
|
||||
(void)memset_s(&time, sizeof(time), 0, sizeof(time));
|
||||
(void)memset_s(&event, sizeof(event), 0, sizeof(event));
|
||||
|
||||
if (OsalGetTime(&time) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: Get time failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
event.timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec * SENSOR_CONVERT_UNIT;
|
||||
|
||||
ret = ReadTempData(data, &barometerData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = ReadBarometerData(data, &barometerData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = CalcBarometerData(&barometerData, tmp);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
event.sensorId = SENSOR_TAG_BAROMETER;
|
||||
event.option = 0;
|
||||
event.mode = SENSOR_WORK_MODE_REALTIME;
|
||||
event.dataLen = sizeof(tmp);
|
||||
event.data = (uint8_t *)&tmp;
|
||||
ret = ReportSensorEvent(&event);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t InitBmp180(struct SensorCfgData *data)
|
||||
{
|
||||
int32_t ret;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
|
||||
struct SensorReportEvent event;
|
||||
|
||||
(void)memset_s(&event, sizeof(event), 0, sizeof(event));
|
||||
|
||||
ret = ReadEepromData(data, &g_calibraData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = SetSensorRegCfgArray(&data->busCfg, data->regCfgGroup[SENSOR_INIT_GROUP]);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: BMP180 sensor init config failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t InitBarometerPreConfig(void)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (SetSensorPinMux(SENSOR_I2C6_CLK_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
|
||||
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 Bmp180InitDriver(struct HdfDeviceObject *device)
|
||||
{
|
||||
int32_t ret;
|
||||
struct BarometerOpsCall ops;
|
||||
|
||||
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__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
drvData->sensorCfg = BarometerCreateCfgData(device->property);
|
||||
if (drvData->sensorCfg == NULL) {
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
ops.Init = NULL;
|
||||
ops.ReadData = ReadBmp180Data;
|
||||
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: Init BMP180 barometer failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#include "barometer_bmp180.h"
|
||||
#include <securec.h>
|
||||
#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_DATA_REG_ADDR 0x114f004c
|
||||
#define SENSOR_I2C6_CLK_REG_ADDR 0x114f0048
|
||||
#define SENSOR_I2C_REG_CFG 0x403
|
||||
|
||||
static struct BarometerEepromData g_calibraData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
static int32_t ReadEepromRawData(struct SensorCfgData *data, uint8_t rfg[BAROMETER_EEPROM_SUM])
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC1_MSB_ADDR, &rfg[BAROMETER_AC1_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC1_LSB_ADDR, &rfg[BAROMETER_AC1_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC2_MSB_ADDR, &rfg[BAROMETER_AC2_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC2_LSB_ADDR, &rfg[BAROMETER_AC2_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC3_MSB_ADDR, &rfg[BAROMETER_AC3_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC3_LSB_ADDR, &rfg[BAROMETER_AC3_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC4_MSB_ADDR, &rfg[BAROMETER_AC4_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC4_LSB_ADDR, &rfg[BAROMETER_AC4_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC5_MSB_ADDR, &rfg[BAROMETER_AC5_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC5_LSB_ADDR, &rfg[BAROMETER_AC5_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC6_MSB_ADDR, &rfg[BAROMETER_AC6_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
ret = ReadSensor(&data->busCfg, BMP180_AC6_LSB_ADDR, &rfg[BAROMETER_AC6_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_B1_MSB_ADDR, &rfg[BAROMETER_B1_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_B1_LSB_ADDR, &rfg[BAROMETER_B1_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_B2_MSB_ADDR, &rfg[BAROMETER_B2_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_B2_LSB_ADDR, &rfg[BAROMETER_B2_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MB_MSB_ADDR, &rfg[BAROMETER_MB_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MB_LSB_ADDR, &rfg[BAROMETER_MB_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MC_MSB_ADDR, &rfg[BAROMETER_MC_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MC_LSB_ADDR, &rfg[BAROMETER_MC_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MD_MSB_ADDR, &rfg[BAROMETER_MD_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_MD_LSB_ADDR, &rfg[BAROMETER_MD_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ReadEepromData(struct SensorCfgData *data, struct BarometerEepromData *g_calibraData)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t reg[BAROMETER_EEPROM_SUM];
|
||||
|
||||
(void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
ret = ReadEepromRawData(data, reg);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
g_calibraData->ac1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC1_LSB]);
|
||||
g_calibraData->ac2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC2_LSB]);
|
||||
g_calibraData->ac3 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC3_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC3_LSB]);
|
||||
g_calibraData->ac4 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC4_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC4_LSB]);
|
||||
g_calibraData->ac5 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC5_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC5_LSB]);
|
||||
g_calibraData->ac6 = (uint16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_AC6_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_AC6_LSB]);
|
||||
g_calibraData->b1 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B1_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_B1_LSB]);
|
||||
g_calibraData->b2 = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_B2_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_B2_LSB]);
|
||||
g_calibraData->mb = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MB_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_MB_LSB]);
|
||||
g_calibraData->mc = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MC_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_MC_LSB]);
|
||||
g_calibraData->md = (int16_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_MD_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_MD_LSB]);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ReadTempData(struct SensorCfgData *data, struct BarometerRawData *Temp)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t status = 0;
|
||||
uint8_t reg[BAROMETER_TEM_SUM];
|
||||
uint8_t value[SENSOR_VALUE_BUTT];
|
||||
value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
|
||||
value[SENSOR_VALUE_INDEX] = BMP180_COVERT_TEMP;
|
||||
|
||||
(void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
|
||||
if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
|
||||
WriteSensor(&data->busCfg, value, sizeof(value));
|
||||
OsalMDelay(DELAY_0);
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, ®[BAROMETER_TEM_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, ®[BAROMETER_TEM_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
Temp->unpensateTemp = (int32_t)(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_TEM_MSB], SENSOR_DATA_WIDTH_8_BIT) |
|
||||
reg[BAROMETER_TEM_LSB]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t ReadBarometerData(struct SensorCfgData *data, struct BarometerRawData *Barom)
|
||||
{
|
||||
int32_t ret;
|
||||
uint8_t status = 0;
|
||||
uint8_t reg[BAROMETER_BAR_SUM];
|
||||
uint8_t value[SENSOR_VALUE_BUTT];
|
||||
value[SENSOR_ADDR_INDEX] = BMP180_CONTROL_REG_ADDR;
|
||||
value[SENSOR_VALUE_INDEX] = BMP180_COVERT_PRES_1;
|
||||
|
||||
(void)memset_s(reg, sizeof(reg), 0, sizeof(reg));
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_COVERT_PRES_3, &status, sizeof(uint8_t));
|
||||
if ((status & BMP180_STATUS_ADDR) == BMP180_STATUS_JUDGE) {
|
||||
WriteSensor(&data->busCfg, value, sizeof(value));
|
||||
OsalMDelay(DELAY_1);
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_MSB_ADDR, ®[BAROMETER_BAR_MSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_LSB_ADDR, ®[BAROMETER_BAR_LSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
ret = ReadSensor(&data->busCfg, BMP180_OUT_XLSB_ADDR, ®[BAROMETER_BAR_XLSB], sizeof(uint8_t));
|
||||
CHECK_PARSER_RESULT_RETURN_VALUE(ret, "read data");
|
||||
|
||||
Barom->unpensatePre = (int32_t)(SENSOR_DATA_SHIFT_RIGHT(
|
||||
(SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_MSB], SENSOR_DATA_WIDTH_16_BIT) |
|
||||
SENSOR_DATA_SHIFT_LEFT(reg[BAROMETER_BAR_LSB], SENSOR_DATA_WIDTH_8_BIT) | reg[BAROMETER_BAR_XLSB]),
|
||||
(BMP180_CONSTANT_4 - OSSETTING)));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t CalcBarometerData(struct BarometerRawData *barometerData, int32_t tnp[BAROMETER_SUM])
|
||||
{
|
||||
struct Coefficient coefficientData = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
// Calculated temperature
|
||||
|
||||
coefficientData.x1 = ((barometerData->unpensateTemp - g_calibraData.ac6) * (g_calibraData.ac5))
|
||||
>> BMP180_CONSTANT_8;
|
||||
coefficientData.x2 = (g_calibraData.mc << BMP180_CONSTANT_5) / (coefficientData.x1 + g_calibraData.md);
|
||||
coefficientData.b5 = coefficientData.x1 + coefficientData.x2;
|
||||
tnp[BAROMETER_TEMPERATURE] = (coefficientData.b5 + BMP180_CONSTANT_4) >> BMP180_CONSTANT_3;
|
||||
|
||||
// Calculated pressure
|
||||
|
||||
coefficientData.b6 = coefficientData.b5 - BMP180_CONSTANT_12;
|
||||
coefficientData.x1 = (g_calibraData.b2 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
|
||||
>> BMP180_CONSTANT_5;
|
||||
coefficientData.x2 = (g_calibraData.ac2 * coefficientData.b6) >> BMP180_CONSTANT_5;
|
||||
coefficientData.x3 = coefficientData.x1 + coefficientData.x2;
|
||||
coefficientData.b3 = (((((int32_t)g_calibraData.ac1) * BMP180_CONSTANT_3 + coefficientData.x3) << OSSETTING)
|
||||
+ BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
|
||||
coefficientData.x1 = (g_calibraData.ac3 * coefficientData.b6) >> BMP180_CONSTANT_7;
|
||||
coefficientData.x2 = (g_calibraData.b1 * ((coefficientData.b6 * coefficientData.b6) >> BMP180_CONSTANT_6))
|
||||
>> BMP180_CONSTANT_9;
|
||||
coefficientData.x3 = ((coefficientData.x1 + coefficientData.x2) + BMP180_CONSTANT_2) >> BMP180_CONSTANT_2;
|
||||
coefficientData.b4 = (g_calibraData.ac4 * (uint32_t)(coefficientData.x3 + BMP180_CONSTANT_13))
|
||||
>> BMP180_CONSTANT_8;
|
||||
coefficientData.b7 = ((uint32_t)(barometerData->unpensatePre) - (uint32_t)coefficientData.b3)
|
||||
* (BMP180_CONSTANT_14 >> OSSETTING);
|
||||
if (coefficientData.b7 < BMP180_CONSTANT_15) {
|
||||
coefficientData.p = (coefficientData.b7 << BMP180_CONSTANT_1) / coefficientData.b4;
|
||||
} else {
|
||||
coefficientData.p = (coefficientData.b7 / coefficientData.b4) << BMP180_CONSTANT_1;
|
||||
}
|
||||
coefficientData.x1 = (coefficientData.p >> BMP180_CONSTANT_4) * (coefficientData.p >> BMP180_CONSTANT_4);
|
||||
coefficientData.x1 = (coefficientData.x1 * BMP180_CONSTANT_10) >> BMP180_CONSTANT_9;
|
||||
coefficientData.x2 = (BMP180_CONSTANT_0 * coefficientData.p) >> BMP180_CONSTANT_9;
|
||||
tnp[BAROMETER_BAROMETER] = coefficientData.p + ((coefficientData.x1 + coefficientData.x2
|
||||
+ BMP180_CONSTANT_11) >> BMP180_CONSTANT_3);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ReadBmp180Data(struct SensorCfgData *data)
|
||||
{
|
||||
int32_t ret;
|
||||
int32_t tmp[BAROMETER_SUM];
|
||||
struct BarometerRawData barometerData = {0, 0};
|
||||
OsalTimespec time;
|
||||
struct SensorReportEvent event;
|
||||
|
||||
(void)memset_s(&time, sizeof(time), 0, sizeof(time));
|
||||
(void)memset_s(&event, sizeof(event), 0, sizeof(event));
|
||||
|
||||
if (OsalGetTime(&time) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: Get time failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
event.timestamp = time.sec * SENSOR_SECOND_CONVERT_NANOSECOND + time.usec * SENSOR_CONVERT_UNIT;
|
||||
|
||||
ret = ReadTempData(data, &barometerData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = ReadBarometerData(data, &barometerData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = CalcBarometerData(&barometerData, tmp);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
event.sensorId = SENSOR_TAG_BAROMETER;
|
||||
event.option = 0;
|
||||
event.mode = SENSOR_WORK_MODE_REALTIME;
|
||||
event.dataLen = sizeof(tmp);
|
||||
event.data = (uint8_t *)&tmp;
|
||||
ret = ReportSensorEvent(&event);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t InitBmp180(struct SensorCfgData *data)
|
||||
{
|
||||
int32_t ret;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
|
||||
struct SensorReportEvent event;
|
||||
|
||||
(void)memset_s(&event, sizeof(event), 0, sizeof(event));
|
||||
|
||||
ret = ReadEepromData(data, &g_calibraData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
ret = SetSensorRegCfgArray(&data->busCfg, data->regCfgGroup[SENSOR_INIT_GROUP]);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: BMP180 sensor init config failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t InitBarometerPreConfig(void)
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (SetSensorPinMux(SENSOR_I2C6_CLK_REG_ADDR, SENSOR_ADDR_WIDTH_4_BYTE, SENSOR_I2C_REG_CFG) != HDF_SUCCESS) {
|
||||
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 Bmp180InitDriver(struct HdfDeviceObject *device)
|
||||
{
|
||||
int32_t ret;
|
||||
struct BarometerOpsCall ops;
|
||||
|
||||
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__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
drvData->sensorCfg = BarometerCreateCfgData(device->property);
|
||||
if (drvData->sensorCfg == NULL) {
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
ops.Init = NULL;
|
||||
ops.ReadData = ReadBmp180Data;
|
||||
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: Init BMP180 barometer failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -1,96 +1,96 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef BAROMETER_BMP180_H
|
||||
#define BAROMETER_BMP180_H
|
||||
|
||||
#include "sensor_barometer_driver.h"
|
||||
#include "sensor_config_parser.h"
|
||||
|
||||
#define BMP180_REG_CHIP_ID 0xD0
|
||||
|
||||
// i2c slave address
|
||||
|
||||
#define BMP180_ADDR 0x77
|
||||
|
||||
// Define calibration register address
|
||||
|
||||
#define BMP180_AC1_MSB_ADDR 0xAA
|
||||
#define BMP180_AC1_LSB_ADDR 0xAB
|
||||
#define BMP180_AC2_MSB_ADDR 0xAC
|
||||
#define BMP180_AC2_LSB_ADDR 0xAD
|
||||
#define BMP180_AC3_MSB_ADDR 0xAE
|
||||
#define BMP180_AC3_LSB_ADDR 0xAF
|
||||
#define BMP180_AC4_MSB_ADDR 0xB0
|
||||
#define BMP180_AC4_LSB_ADDR 0xB1
|
||||
#define BMP180_AC5_MSB_ADDR 0xB2
|
||||
#define BMP180_AC5_LSB_ADDR 0xB3
|
||||
#define BMP180_AC6_MSB_ADDR 0xB4
|
||||
#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_LSB_ADDR 0xB9
|
||||
#define BMP180_MB_MSB_ADDR 0xBA
|
||||
#define BMP180_MB_LSB_ADDR 0xBB
|
||||
#define BMP180_MC_MSB_ADDR 0xBC
|
||||
#define BMP180_MC_LSB_ADDR 0xBD
|
||||
#define BMP180_MD_MSB_ADDR 0xBE
|
||||
#define BMP180_MD_LSB_ADDR 0xBf
|
||||
|
||||
// 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_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 OSSETTING 1
|
||||
#define DELAY_0 5
|
||||
#define DELAY_1 8
|
||||
#define OSS_TIME_MS 26
|
||||
|
||||
#define BMP180_CONSTANT_0 (-7357)
|
||||
#define BMP180_CONSTANT_1 1
|
||||
#define BMP180_CONSTANT_2 2
|
||||
#define BMP180_CONSTANT_3 4
|
||||
#define BMP180_CONSTANT_4 8
|
||||
#define BMP180_CONSTANT_5 11
|
||||
#define BMP180_CONSTANT_6 12
|
||||
#define BMP180_CONSTANT_7 13
|
||||
#define BMP180_CONSTANT_8 15
|
||||
#define BMP180_CONSTANT_9 16
|
||||
#define BMP180_CONSTANT_10 3038
|
||||
#define BMP180_CONSTANT_11 3791
|
||||
#define BMP180_CONSTANT_12 4000
|
||||
#define BMP180_CONSTANT_13 32768
|
||||
#define BMP180_CONSTANT_14 50000
|
||||
#define BMP180_CONSTANT_15 0x80000000
|
||||
|
||||
|
||||
int32_t DetectBarometerBmp180Chip(struct SensorCfgData *data);
|
||||
int32_t ReadBmp180Data(struct SensorCfgData *data);
|
||||
|
||||
struct Bmp180DrvData {
|
||||
struct IDeviceIoService ioService;
|
||||
struct HdfDeviceObject *device;
|
||||
struct SensorCfgData *sensorCfg;
|
||||
};
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef BAROMETER_BMP180_H
|
||||
#define BAROMETER_BMP180_H
|
||||
|
||||
#include "sensor_barometer_driver.h"
|
||||
#include "sensor_config_parser.h"
|
||||
|
||||
#define BMP180_REG_CHIP_ID 0xD0
|
||||
|
||||
// i2c slave address
|
||||
|
||||
#define BMP180_ADDR 0x77
|
||||
|
||||
// Define calibration register address
|
||||
|
||||
#define BMP180_AC1_MSB_ADDR 0xAA
|
||||
#define BMP180_AC1_LSB_ADDR 0xAB
|
||||
#define BMP180_AC2_MSB_ADDR 0xAC
|
||||
#define BMP180_AC2_LSB_ADDR 0xAD
|
||||
#define BMP180_AC3_MSB_ADDR 0xAE
|
||||
#define BMP180_AC3_LSB_ADDR 0xAF
|
||||
#define BMP180_AC4_MSB_ADDR 0xB0
|
||||
#define BMP180_AC4_LSB_ADDR 0xB1
|
||||
#define BMP180_AC5_MSB_ADDR 0xB2
|
||||
#define BMP180_AC5_LSB_ADDR 0xB3
|
||||
#define BMP180_AC6_MSB_ADDR 0xB4
|
||||
#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_LSB_ADDR 0xB9
|
||||
#define BMP180_MB_MSB_ADDR 0xBA
|
||||
#define BMP180_MB_LSB_ADDR 0xBB
|
||||
#define BMP180_MC_MSB_ADDR 0xBC
|
||||
#define BMP180_MC_LSB_ADDR 0xBD
|
||||
#define BMP180_MD_MSB_ADDR 0xBE
|
||||
#define BMP180_MD_LSB_ADDR 0xBf
|
||||
|
||||
// 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_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 OSSETTING 1
|
||||
#define DELAY_0 5
|
||||
#define DELAY_1 8
|
||||
#define OSS_TIME_MS 26
|
||||
|
||||
#define BMP180_CONSTANT_0 (-7357)
|
||||
#define BMP180_CONSTANT_1 1
|
||||
#define BMP180_CONSTANT_2 2
|
||||
#define BMP180_CONSTANT_3 4
|
||||
#define BMP180_CONSTANT_4 8
|
||||
#define BMP180_CONSTANT_5 11
|
||||
#define BMP180_CONSTANT_6 12
|
||||
#define BMP180_CONSTANT_7 13
|
||||
#define BMP180_CONSTANT_8 15
|
||||
#define BMP180_CONSTANT_9 16
|
||||
#define BMP180_CONSTANT_10 3038
|
||||
#define BMP180_CONSTANT_11 3791
|
||||
#define BMP180_CONSTANT_12 4000
|
||||
#define BMP180_CONSTANT_13 32768
|
||||
#define BMP180_CONSTANT_14 50000
|
||||
#define BMP180_CONSTANT_15 0x80000000
|
||||
|
||||
|
||||
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 */
|
||||
@@ -34,7 +34,7 @@ int32_t HallRegisterChipOps(const struct HallOpsCall *ops)
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
|
||||
drvData->ops.Init = ops->Init;
|
||||
drvData->ops.ReadData = ops->ReadData;
|
||||
return HDF_SUCCESS;
|
||||
@@ -43,7 +43,7 @@ int32_t HallRegisterChipOps(const struct HallOpsCall *ops)
|
||||
static void HallDataWorkEntry(void *arg)
|
||||
{
|
||||
struct HallDrvData *drvData = NULL;
|
||||
|
||||
|
||||
drvData = (struct HallDrvData *)arg;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
@@ -256,7 +256,7 @@ static int32_t ParserHallPinConfigData(const struct DeviceResourceNode *node, st
|
||||
CHECK_NULL_PTR_RETURN_VALUE(parser, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(parser->GetChildNode, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
|
||||
const struct DeviceResourceNode *pinNode = parser->GetChildNode(node, "hallPinConfig");
|
||||
CHECK_NULL_PTR_RETURN_VALUE(pinNode, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef SENSOR_HALL_DRIVER_H
|
||||
#define SENSOR_HALL_DRIVER_H
|
||||
|
||||
#include "hdf_workqueue.h"
|
||||
#include "hdf_workqueue.h"
|
||||
#include "sensor_config_parser.h"
|
||||
#include "sensor_platform_if.h"
|
||||
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef SENSOR_DEVICE_IF_H
|
||||
#define SENSOR_DEVICE_IF_H
|
||||
|
||||
#include "sensor_device_type.h"
|
||||
|
||||
struct SensorOps {
|
||||
int32_t (*Enable)(void);
|
||||
int32_t (*Disable)(void);
|
||||
int32_t (*SetBatch)(int64_t samplingInterval, int64_t reportInterval);
|
||||
int32_t (*SetMode)(int32_t mode);
|
||||
int32_t (*SetOption)(uint32_t option);
|
||||
};
|
||||
|
||||
struct SensorDeviceInfo {
|
||||
struct SensorBasicInfo sensorInfo;
|
||||
struct SensorOps ops;
|
||||
};
|
||||
|
||||
int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo);
|
||||
int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo);
|
||||
int32_t ReportSensorEvent(const struct SensorReportEvent *events);
|
||||
|
||||
#endif /* SENSOR_DEVICE_IF_H */
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
|
||||
*
|
||||
* HDF is dual licensed: you can use it either under the terms of
|
||||
* the GPL, or the BSD license, at your option.
|
||||
* See the LICENSE file in the root of this repository for complete details.
|
||||
*/
|
||||
|
||||
#ifndef SENSOR_DEVICE_IF_H
|
||||
#define SENSOR_DEVICE_IF_H
|
||||
|
||||
#include "sensor_device_type.h"
|
||||
|
||||
struct SensorOps {
|
||||
int32_t (*Enable)(void);
|
||||
int32_t (*Disable)(void);
|
||||
int32_t (*SetBatch)(int64_t samplingInterval, int64_t reportInterval);
|
||||
int32_t (*SetMode)(int32_t mode);
|
||||
int32_t (*SetOption)(uint32_t option);
|
||||
};
|
||||
|
||||
struct SensorDeviceInfo {
|
||||
struct SensorBasicInfo sensorInfo;
|
||||
struct SensorOps ops;
|
||||
};
|
||||
|
||||
int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo);
|
||||
int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo);
|
||||
int32_t ReportSensorEvent(const struct SensorReportEvent *events);
|
||||
|
||||
#endif /* SENSOR_DEVICE_IF_H */
|
||||
|
||||
Reference in New Issue
Block a user