1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef MAGNETIC_LSM303_H
10 #define MAGNETIC_LSM303_H
11 
12 #include "sensor_config_parser.h"
13 #include "sensor_magnetic_driver.h"
14 
15 #define LSM303_MAGNETIC_GIN                     1000
16 
17 /* MAGNETIC SET RATE AND MODE ADDR */
18 #define LSM303_CRA_REG_ADDR                     0X00
19 #define LSM303_CRB_REG_ADDR                     0X01
20 #define LSM303_MR_REG_ADDR                      0X02
21 
22 /* MAGNETIC DATA REGISTERS ADDR */
23 #define LSM303_MAGNETIC_X_MSB_ADDR              0X03
24 #define LSM303_MAGNETIC_X_LSB_ADDR              0X04
25 #define LSM303_MAGNETIC_Y_MSB_ADDR              0X05
26 #define LSM303_MAGNETIC_Y_LSB_ADDR              0X06
27 #define LSM303_MAGNETIC_Z_MSB_ADDR              0X07
28 #define LSM303_MAGNETIC_Z_LSB_ADDR              0X08
29 #define LSM303_STATUS_ADDR                      0X09
30 
31 /* MAGNETIC DATA RATE CONFIG HZ */
32 #define LSM303_DATA_RATE_0                      0X00
33 #define LSM303_DATA_RATE_1                      0X04
34 #define LSM303_DATA_RATE_2                      0X08
35 #define LSM303_DATA_RATE_3                      0X0C
36 #define LSM303_DATA_RATE_4                      0X10
37 #define LSM303_DATA_RATE_5                      0X14
38 #define LSM303_DATA_RATE_6                      0X18
39 #define LSM303_DATA_RATE_7                      0X1C
40 
41 /* MAGNETIC GAIN CONFIG GAUSS */
42 #define LSM303_GAIN_RATE_0                      0X20
43 #define LSM303_GAIN_RATE_1                      0X40
44 #define LSM303_GAIN_RATE_2                      0X60
45 #define LSM303_GAIN_RATE_3                      0X80
46 #define LSM303_GAIN_RATE_4                      0XA0
47 #define LSM303_GAIN_RATE_5                      0XC0
48 #define LSM303_GAIN_RATE_6                      0XE0
49 
50 /* MAGNETIC GAIN SENSITIVITY RANGE */
51 #define LSM303DLHC_SENSITIVITY_XY13GA           1100
52 #define LSM303DLHC_SENSITIVITY_XY19GA           855
53 #define LSM303DLHC_SENSITIVITY_XY25GA           670
54 #define LSM303DLHC_SENSITIVITY_XY40GA           450
55 #define LSM303DLHC_SENSITIVITY_XY47GA           400
56 #define LSM303DLHC_SENSITIVITY_XY56GA           330
57 #define LSM303DLHC_SENSITIVITY_XY81GA           230
58 #define LSM303DLHC_SENSITIVITY_Z13GA            980
59 #define LSM303DLHC_SENSITIVITY_Z19GA            760
60 #define LSM303DLHC_SENSITIVITY_Z25GA            600
61 #define LSM303DLHC_SENSITIVITY_Z40GA            400
62 #define LSM303DLHC_SENSITIVITY_Z47GA            355
63 #define LSM303DLHC_SENSITIVITY_Z56GA            295
64 #define LSM303DLHC_SENSITIVITY_Z81GA            205
65 
66 /* MAGNETIC MODE CONFIG */
67 #define LSM303_OPERATING_MODE_1                 0X00
68 #define LSM303_OPERATING_MODE_2                 0X01
69 #define LSM303_OPERATING_MODE_3                 0X02
70 #define LSM303_OPERATING_MODE_4                 0X03
71 
72 /* MAGNETIC DATA READY */
73 #define LSM303_DATA_READY_MASK                  0x01
74 
75 int32_t DetectMagneticLsm303Chip(struct SensorCfgData *data);
76 
77 struct Lsm303DrvData {
78     struct IDeviceIoService ioService;
79     struct HdfDeviceObject *device;
80     struct SensorCfgData *sensorCfg;
81 };
82 
83 #endif /* MAGNETIC_LSM303_H */