1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef SENSOR_MAGNETIC_DRIVER_H
10 #define SENSOR_MAGNETIC_DRIVER_H
11 
12 #include "hdf_workqueue.h"
13 #include "osal_timer.h"
14 #include "sensor_config_parser.h"
15 #include "sensor_platform_if.h"
16 
17 #define MAGNETIC_DEFAULT_SAMPLING_200_MS    200000000
18 #define MAGNETIC_CHIP_NAME_LSM303    "lsm303"
19 
20 enum MagneticAxisNum {
21     MAGNETIC_X_AXIS   = 0,
22     MAGNETIC_Y_AXIS   = 1,
23     MAGNETIC_Z_AXIS   = 2,
24     MAGNETIC_AXIS_NUM = 3,
25 };
26 
27 enum MagneticAxisPart {
28     MAGNETIC_X_AXIS_MSB = 0,
29     MAGNETIC_X_AXIS_LSB = 1,
30     MAGNETIC_Y_AXIS_MSB = 2,
31     MAGNETIC_Y_AXIS_LSB = 3,
32     MAGNETIC_Z_AXIS_MSB = 4,
33     MAGNETIC_Z_AXIS_LSB = 5,
34     MAGNETIC_AXIS_BUTT,
35 };
36 
37 struct MagneticData {
38     int32_t x;
39     int32_t y;
40     int32_t z;
41 };
42 
43 struct MagneticOpsCall {
44     int32_t (*Init)(struct SensorCfgData *data);
45     int32_t (*ReadData)(struct SensorCfgData *data);
46 };
47 
48 struct MagneticDrvData {
49     struct IDeviceIoService ioService;
50     struct HdfDeviceObject *device;
51     HdfWorkQueue magneticWorkQueue;
52     HdfWork magneticWork;
53     OsalTimer magneticTimer;
54     bool detectFlag;
55     bool enable;
56     int64_t interval;
57     struct SensorCfgData *magneticCfg;
58     struct MagneticOpsCall ops;
59 };
60 
61 int32_t MagneticRegisterChipOps(const struct MagneticOpsCall *ops);
62 struct SensorCfgData *MagneticCreateCfgData(const struct DeviceResourceNode *node);
63 void MagneticReleaseCfgData(struct SensorCfgData *magneticCfg);
64 
65 #endif /* SENSOR_MAGNETIC_DRIVER_H */
66