1 /*
2  * Copyright (C) 2016 STMicroelectronics
3  *
4  * Author: Denis Ciocca <denis.ciocca@st.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *    http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef __LSM6DSM_I2C_MASTER_AK09916__
20 #define __LSM6DSM_I2C_MASTER_AK09916__
21 
22 #ifdef LSM6DSM_I2C_MASTER_AK09916
23 #ifndef LSM6DSM_I2C_MASTER_MAGNETOMETER_ENABLED
24 #define LSM6DSM_I2C_MASTER_MAGNETOMETER_ENABLED       1
25 #else /* LSM6DSM_I2C_MASTER_MAGNETOMETER_ENABLED */
26 #error "Another magnetometer is already selected! One magn per time can be used."
27 #endif /* LSM6DSM_I2C_MASTER_MAGNETOMETER_ENABLED */
28 #endif /* LSM6DSM_I2C_MASTER_AK09916 */
29 
30 #define AK09916_KSCALE                                0.15          /* MAGN scale in uT/LSB */
31 #define AK09916_I2C_ADDRESS                           (0x0c)
32 
33 /* AK09916 registers */
34 #define AK09916_WAI_ADDR                              (0x00)
35 #define AK09916_CNTL2_ADDR                            (0x31)
36 #define AK09916_CNTL3_ADDR                            (0x32)
37 #define AK09916_OUTDATA_ADDR                          (0x11)
38 #define AK09916_STATUS_DATA_ADDR                      (0x18)
39 
40 #define AK09916_SW_RESET                              (0x01)
41 #define AK09916_POWER_ON_VALUE                        (0x02)
42 #define AK09916_POWER_OFF_VALUE                       (0x00)
43 #define AK09916_OUTDATA_LEN                           (0x06)
44 
45 
46 /* AK09916 default base registers status */
47 /* AK09916_CNTL2_BASE: control register 2 default settings */
48 #define AK09916_CNTL2_BASE                           ((0 << 7) |    /* (0) */ \
49                                                       (0 << 6) |    /* (0) */ \
50                                                       (0 << 5) |    /* (0) */ \
51                                                       (0 << 4) |    /* MODE4 */ \
52                                                       (0 << 3) |    /* MODE3 */ \
53                                                       (0 << 2) |    /* MODE2 */ \
54                                                       (0 << 1) |    /* MODE1 */ \
55                                                       (0 << 0))     /* MODE0 */
56 
57 #ifdef LSM6DSM_I2C_MASTER_AK09916
58 /* MUST BE SAME LENGTH OF LSM6DSMMagnRates */
59 static uint8_t AK09916MagnRatesRegValue[] = {
60     0x02, /* Expected 3.25Hz, ODR = 10Hz */
61     0x02, /* Expected 6.5Hz, ODR = 10Hz */
62     0x04, /* Expected 12.5Hz, ODR = 20Hz */
63     0x06, /* Expected 26Hz, ODR = 50Hz */
64     0x08, /* Expected 52Hz, ODR = 100Hz */
65     0x08, /* Expected 104Hz, ODR = 100Hz */
66 };
67 #endif /* LSM6DSM_I2C_MASTER_AK09916 */
68 
69 #endif /* __LSM6DSM_I2C_MASTER_AK09916__ */
70