• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef SENSOR_ACCEL_DRIVER_H
10 #define SENSOR_ACCEL_DRIVER_H
11 
12 #include "hdf_workqueue.h"
13 #include "osal_mutex.h"
14 #include "osal_timer.h"
15 #include "sensor_config_parser.h"
16 #include "sensor_platform_if.h"
17 
18 enum AccelAxisNum {
19     ACCEL_X_AXIS   = 0,
20     ACCEL_Y_AXIS   = 1,
21     ACCEL_Z_AXIS   = 2,
22     ACCEL_AXIS_NUM = 3,
23 };
24 
25 enum AccelAxisPart {
26     ACCEL_X_AXIS_LSB = 0,
27     ACCEL_X_AXIS_MSB = 1,
28     ACCEL_Y_AXIS_LSB = 2,
29     ACCEL_Y_AXIS_MSB = 3,
30     ACCEL_Z_AXIS_LSB = 4,
31     ACCEL_Z_AXIS_MSB = 5,
32     ACCEL_AXIS_BUTT,
33 };
34 
35 typedef int32_t (*GravitySubscribeAccelCallback)(int32_t *rawData, int32_t size);
36 
37 struct AccelData {
38     int32_t x;
39     int32_t y;
40     int32_t z;
41 };
42 
43 struct AccelOpsCall {
44     int32_t (*Init)(struct SensorCfgData *data);
45     int32_t (*ReadData)(struct SensorCfgData *data, struct SensorReportEvent *event);
46 };
47 
48 struct AccelDrvData {
49     struct IDeviceIoService ioService;
50     struct HdfDeviceObject *device;
51     HdfWorkQueue accelWorkQueue;
52     HdfWork accelWork;
53     OsalTimer accelTimer;
54     bool detectFlag;
55     bool enable;
56     int64_t interval;
57     struct SensorCfgData *accelCfg;
58     struct AccelOpsCall ops;
59     GravitySubscribeAccelCallback cb;
60 };
61 
62 int32_t AccelRegisterChipOps(const struct AccelOpsCall *ops);
63 struct SensorCfgData *AccelCreateCfgData(const struct DeviceResourceNode *node);
64 void AccelReleaseCfgData(struct SensorCfgData *accelCfg);
65 int32_t SubscribeAccelDataCallbackFunc(GravitySubscribeAccelCallback cb);
66 #endif /* SENSOR_ACCEL_DRIVER_H */
67