├── README.md
├── examples
├── DISCO_IOT_6DOrientation
│ └── DISCO_IOT_6DOrientation.ino
├── DISCO_IOT_DoubleTap
│ └── DISCO_IOT_DoubleTap.ino
├── DISCO_IOT_FreeFall
│ └── DISCO_IOT_FreeFall.ino
├── DISCO_IOT_LSM6DSL_DataLog_Terminal
│ └── DISCO_IOT_LSM6DSL_DataLog_Terminal.ino
├── DISCO_IOT_MultiEvent
│ └── DISCO_IOT_MultiEvent.ino
├── DISCO_IOT_Pedometer
│ └── DISCO_IOT_Pedometer.ino
├── DISCO_IOT_Tap
│ └── DISCO_IOT_Tap.ino
├── DISCO_IOT_Tilt
│ └── DISCO_IOT_Tilt.ino
└── DISCO_IOT_WakeUp
│ └── DISCO_IOT_WakeUp.ino
├── keywords.txt
├── library.properties
└── src
├── LSM6DSLSensor.cpp
├── LSM6DSLSensor.h
├── LSM6DSL_ACC_GYRO_Driver.c
└── LSM6DSL_ACC_GYRO_Driver.h
/README.md:
--------------------------------------------------------------------------------
1 | # LSM6DSL
2 | Arduino library to support the LSM6DSL 3D accelerometer and 3D gyroscope
3 |
4 | ## API
5 |
6 | This sensor uses I2C or SPI to communicate.
7 | For I2C it is then required to create a TwoWire interface before accessing to the sensors:
8 |
9 | TwoWire dev_i2c(I2C_SDA, I2C_SCL);
10 | dev_i2c.begin();
11 |
12 | For SPI it is then required to create a SPI interface before accessing to the sensors:
13 |
14 | SPIClass dev_spi(SPI_MOSI, SPI_MISO, SPI_SCK);
15 | dev_spi.begin();
16 |
17 | An instance can be created and enabled when the I2C bus is used following the procedure below:
18 |
19 | LSM6DSLSensor AccGyr(&dev_i2c);
20 | AccGyr.begin();
21 | AccGyr.Enable_X();
22 | AccGyr.Enable_G();
23 |
24 | An instance can be created and enabled when the SPI bus is used following the procedure below:
25 |
26 | LSM6DSLSensor AccGyr(&dev_spi, CS_PIN);
27 | AccGyr.begin();
28 | AccGyr.Enable_X();
29 | AccGyr.Enable_G();
30 |
31 | The access to the sensor values is done as explained below:
32 |
33 | Read accelerometer and gyroscope.
34 |
35 | int32_t accelerometer[3];
36 | int32_t gyroscope[3];
37 | AccGyr.Get_X_Axes(accelerometer);
38 | AccGyr.Get_G_Axes(gyroscope);
39 |
40 | ## Documentation
41 |
42 | You can find the source files at
43 | https://github.com/stm32duino/LSM6DSL
44 |
45 | The LSM6DSL datasheet is available at
46 | http://www.st.com/content/st_com/en/products/mems-and-sensors/inemo-inertial-modules/lsm6dsl.html
47 |
--------------------------------------------------------------------------------
/examples/DISCO_IOT_6DOrientation/DISCO_IOT_6DOrientation.ino:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file DISCO_IOT_6DOrientation.ino
4 | * @author WI6LABS from AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
8 | * MEMS Inertial and Environmental sensor expansion board.
9 | * This application detects 6D Orientation event through the LSM6DSL sensor.
10 | * This application makes use of C++ classes obtained from the C
11 | * components' drivers.
12 | ******************************************************************************
13 | * @attention
14 | *
15 | *
© COPYRIGHT(c) 2017 STMicroelectronics
16 | *
17 | * Redistribution and use in source and binary forms, with or without modification,
18 | * are permitted provided that the following conditions are met:
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
25 | * may be used to endorse or promote products derived from this software
26 | * without specific prior written permission.
27 | *
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | *
39 | ******************************************************************************
40 | */
41 |
42 |
43 | // Includes.
44 | #include
45 |
46 | #define SerialPort Serial
47 | #define I2C2_SCL PB10
48 | #define I2C2_SDA PB11
49 | #define INT1 PD11
50 |
51 | // Components.
52 | TwoWire dev_i2c(I2C2_SDA, I2C2_SCL);
53 | LSM6DSLSensor AccGyr(&dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
54 |
55 | //Interrupts.
56 | volatile int mems_event = 0;
57 |
58 | char report[256];
59 |
60 | void INT1Event_cb();
61 | void sendOrientation();
62 |
63 | void setup() {
64 | // Led.
65 | pinMode(LED_BUILTIN, OUTPUT);
66 |
67 | // Initialize serial for output.
68 | SerialPort.begin(9600);
69 |
70 | // Initialize I2C bus.
71 | dev_i2c.begin();
72 |
73 | //Interrupts.
74 | attachInterrupt(INT1, INT1Event_cb, RISING);
75 |
76 | // Initlialize Components.
77 | AccGyr.begin();
78 | AccGyr.Enable_X();
79 |
80 | // Enable 6D Orientation.
81 | AccGyr.Enable_6D_Orientation();
82 | }
83 |
84 | void loop() {
85 | if (mems_event)
86 | {
87 | mems_event = 0;
88 | LSM6DSL_Event_Status_t status;
89 | AccGyr.Get_Event_Status(&status);
90 | if (status.D6DOrientationStatus)
91 | {
92 | // Send 6D Orientation
93 | sendOrientation();
94 |
95 | // Led blinking.
96 | digitalWrite(LED_BUILTIN, HIGH);
97 | delay(100);
98 | digitalWrite(LED_BUILTIN, LOW);
99 | }
100 | }
101 | }
102 |
103 | void INT1Event_cb()
104 | {
105 | mems_event = 1;
106 | }
107 |
108 | void sendOrientation()
109 | {
110 | uint8_t xl = 0;
111 | uint8_t xh = 0;
112 | uint8_t yl = 0;
113 | uint8_t yh = 0;
114 | uint8_t zl = 0;
115 | uint8_t zh = 0;
116 |
117 | AccGyr.Get_6D_Orientation_XL(&xl);
118 | AccGyr.Get_6D_Orientation_XH(&xh);
119 | AccGyr.Get_6D_Orientation_YL(&yl);
120 | AccGyr.Get_6D_Orientation_YH(&yh);
121 | AccGyr.Get_6D_Orientation_ZL(&zl);
122 | AccGyr.Get_6D_Orientation_ZH(&zh);
123 |
124 | if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 1 && zh == 0 )
125 | {
126 | sprintf( report, "\r\n ________________ " \
127 | "\r\n | | " \
128 | "\r\n | * | " \
129 | "\r\n | | " \
130 | "\r\n | | " \
131 | "\r\n | | " \
132 | "\r\n | | " \
133 | "\r\n |________________| \r\n" );
134 | }
135 |
136 | else if ( xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
137 | {
138 | sprintf( report, "\r\n ________________ " \
139 | "\r\n | | " \
140 | "\r\n | * | " \
141 | "\r\n | | " \
142 | "\r\n | | " \
143 | "\r\n | | " \
144 | "\r\n | | " \
145 | "\r\n |________________| \r\n" );
146 | }
147 |
148 | else if ( xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0 )
149 | {
150 | sprintf( report, "\r\n ________________ " \
151 | "\r\n | | " \
152 | "\r\n | | " \
153 | "\r\n | | " \
154 | "\r\n | | " \
155 | "\r\n | | " \
156 | "\r\n | * | " \
157 | "\r\n |________________| \r\n" );
158 | }
159 |
160 | else if ( xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
161 | {
162 | sprintf( report, "\r\n ________________ " \
163 | "\r\n | | " \
164 | "\r\n | | " \
165 | "\r\n | | " \
166 | "\r\n | | " \
167 | "\r\n | | " \
168 | "\r\n | * | " \
169 | "\r\n |________________| \r\n" );
170 | }
171 |
172 | else if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1 )
173 | {
174 | sprintf( report, "\r\n __*_____________ " \
175 | "\r\n |________________| \r\n" );
176 | }
177 |
178 | else if ( xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0 )
179 | {
180 | sprintf( report, "\r\n ________________ " \
181 | "\r\n |________________| " \
182 | "\r\n * \r\n" );
183 | }
184 |
185 | else
186 | {
187 | sprintf( report, "None of the 6D orientation axes is set in LSM6DSL - accelerometer.\r\n" );
188 | }
189 |
190 | SerialPort.print(report);
191 | }
192 |
--------------------------------------------------------------------------------
/examples/DISCO_IOT_DoubleTap/DISCO_IOT_DoubleTap.ino:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file DISCO_IOT_DoubleTap.ino
4 | * @author WI6LABS FROM AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
8 | * MEMS Inertial and Environmental sensor expansion board.
9 | * This application detects double tap event through the LSM6DSL sensor.
10 | * This application makes use of C++ classes obtained from the C
11 | * components' drivers.
12 | ******************************************************************************
13 | * @attention
14 | *
15 | * © COPYRIGHT(c) 2017 STMicroelectronics
16 | *
17 | * Redistribution and use in source and binary forms, with or without modification,
18 | * are permitted provided that the following conditions are met:
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
25 | * may be used to endorse or promote products derived from this software
26 | * without specific prior written permission.
27 | *
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | *
39 | ******************************************************************************
40 | */
41 |
42 |
43 | // Includes.
44 | #include
45 |
46 | #define SerialPort Serial
47 | #define I2C2_SCL PB10
48 | #define I2C2_SDA PB11
49 | #define INT1 PD11
50 |
51 | // Components.
52 | TwoWire dev_i2c(I2C2_SDA, I2C2_SCL);
53 | LSM6DSLSensor AccGyr(&dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
54 |
55 | //Interrupts.
56 | volatile int mems_event = 0;
57 |
58 | void INT1Event_cb();
59 |
60 | void setup() {
61 | // Led.
62 | pinMode(LED_BUILTIN, OUTPUT);
63 |
64 | // Initialize serial for output.
65 | SerialPort.begin(9600);
66 |
67 | // Initialize I2C bus.
68 | dev_i2c.begin();
69 |
70 | //Interrupts.
71 | attachInterrupt(INT1, INT1Event_cb, RISING);
72 |
73 | // Initlialize Components.
74 | AccGyr.begin();
75 | AccGyr.Enable_X();
76 |
77 | // Enable Double Tap Detection.
78 | AccGyr.Enable_Double_Tap_Detection();
79 | }
80 |
81 | void loop() {
82 | if (mems_event) {
83 | mems_event = 0;
84 | LSM6DSL_Event_Status_t status;
85 | AccGyr.Get_Event_Status(&status);
86 | if (status.DoubleTapStatus)
87 | {
88 | // Led blinking.
89 | digitalWrite(LED_BUILTIN, HIGH);
90 | delay(100);
91 | digitalWrite(LED_BUILTIN, LOW);
92 | delay(100);
93 | digitalWrite(LED_BUILTIN, HIGH);
94 | delay(100);
95 | digitalWrite(LED_BUILTIN, LOW);
96 |
97 | // Output data.
98 | SerialPort.println("Double Tap Detected!");
99 | }
100 | }
101 | }
102 |
103 | void INT1Event_cb()
104 | {
105 | mems_event = 1;
106 | }
107 |
--------------------------------------------------------------------------------
/examples/DISCO_IOT_FreeFall/DISCO_IOT_FreeFall.ino:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file DISCO_IOT_FreeFall.ino
4 | * @author WI6LABS from AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
8 | * MEMS Inertial and Environmental sensor expansion board.
9 | * This application detects free fall through the LSM6DSL sensor.
10 | * This application makes use of C++ classes obtained from the C
11 | * components' drivers.
12 | ******************************************************************************
13 | * @attention
14 | *
15 | * © COPYRIGHT(c) 2017 STMicroelectronics
16 | *
17 | * Redistribution and use in source and binary forms, with or without modification,
18 | * are permitted provided that the following conditions are met:
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
25 | * may be used to endorse or promote products derived from this software
26 | * without specific prior written permission.
27 | *
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | *
39 | ******************************************************************************
40 | */
41 |
42 |
43 | // Includes.
44 | #include
45 |
46 | #define SerialPort Serial
47 | #define I2C2_SCL PB10
48 | #define I2C2_SDA PB11
49 | #define INT1 PD11
50 |
51 | // Components.
52 | TwoWire dev_i2c(I2C2_SDA, I2C2_SCL);
53 | LSM6DSLSensor AccGyr(&dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
54 |
55 | //Interrupts.
56 | volatile int mems_event = 0;
57 |
58 | void INT1Event_cb();
59 |
60 | void setup() {
61 | // Led.
62 | pinMode(LED_BUILTIN, OUTPUT);
63 |
64 | // Initialize serial for output.
65 | SerialPort.begin(9600);
66 |
67 | // Initialize I2C bus.
68 | dev_i2c.begin();
69 |
70 | //Interrupts.
71 | attachInterrupt(INT1, INT1Event_cb, RISING);
72 |
73 | // Initlialize Components.
74 | AccGyr.begin();
75 | AccGyr.Enable_X();
76 |
77 | // Enable Free Fall Detection.
78 | AccGyr.Enable_Free_Fall_Detection();
79 | }
80 |
81 | void loop() {
82 | if (mems_event) {
83 | mems_event = 0;
84 | LSM6DSL_Event_Status_t status;
85 | AccGyr.Get_Event_Status(&status);
86 | if (status.FreeFallStatus)
87 | {
88 | // Led blinking.
89 | digitalWrite(LED_BUILTIN, HIGH);
90 | delay(200);
91 | digitalWrite(LED_BUILTIN, LOW);
92 |
93 | // Output data.
94 | SerialPort.println("Free Fall Detected!");
95 | }
96 | }
97 | }
98 |
99 | void INT1Event_cb()
100 | {
101 | mems_event = 1;
102 | }
103 |
--------------------------------------------------------------------------------
/examples/DISCO_IOT_LSM6DSL_DataLog_Terminal/DISCO_IOT_LSM6DSL_DataLog_Terminal.ino:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file DISCO_IOT_LSM6DSL_DataLogTerminal.ino
4 | * @author WI6LABS from AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Arduino test application for the STMicrolectronics STM32 DISCO_IOT
8 | * MEMS Inertial and Environmental sensor expansion board.
9 | * This application makes use of C++ classes obtained from the C
10 | * components' drivers.
11 | ******************************************************************************
12 | * @attention
13 | *
14 | * © COPYRIGHT(c) 2017 STMicroelectronics
15 | *
16 | * Redistribution and use in source and binary forms, with or without modification,
17 | * are permitted provided that the following conditions are met:
18 | * 1. Redistributions of source code must retain the above copyright notice,
19 | * this list of conditions and the following disclaimer.
20 | * 2. Redistributions in binary form must reproduce the above copyright notice,
21 | * this list of conditions and the following disclaimer in the documentation
22 | * and/or other materials provided with the distribution.
23 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
24 | * may be used to endorse or promote products derived from this software
25 | * without specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 | *
38 | ******************************************************************************
39 | */
40 |
41 |
42 | // Includes.
43 | #include
44 |
45 | #define SerialPort Serial
46 | #define I2C2_SCL PB10
47 | #define I2C2_SDA PB11
48 |
49 | // Components.
50 | TwoWire dev_i2c(I2C2_SDA, I2C2_SCL);
51 | LSM6DSLSensor AccGyr(&dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
52 |
53 | void setup() {
54 | // Led.
55 | pinMode(LED_BUILTIN, OUTPUT);
56 | // Initialize serial for output.
57 | SerialPort.begin(9600);
58 |
59 | // Initialize I2C bus.
60 | dev_i2c.begin();
61 |
62 | // Initlialize components.
63 | AccGyr.begin();
64 | AccGyr.Enable_X();
65 | AccGyr.Enable_G();
66 | }
67 |
68 | void loop() {
69 | // Led blinking.
70 | digitalWrite(LED_BUILTIN, HIGH);
71 | delay(250);
72 | digitalWrite(LED_BUILTIN, LOW);
73 | delay(250);
74 |
75 | // Read accelerometer and gyroscope.
76 | int32_t accelerometer[3];
77 | int32_t gyroscope[3];
78 | AccGyr.Get_X_Axes(accelerometer);
79 | AccGyr.Get_G_Axes(gyroscope);
80 |
81 | // Output data.
82 | SerialPort.print("Acc[mg]: ");
83 | SerialPort.print(accelerometer[0]);
84 | SerialPort.print(" ");
85 | SerialPort.print(accelerometer[1]);
86 | SerialPort.print(" ");
87 | SerialPort.print(accelerometer[2]);
88 | SerialPort.print(" | Gyr[mdps]: ");
89 | SerialPort.print(gyroscope[0]);
90 | SerialPort.print(" ");
91 | SerialPort.print(gyroscope[1]);
92 | SerialPort.print(" ");
93 | SerialPort.println(gyroscope[2]);
94 | }
95 |
--------------------------------------------------------------------------------
/examples/DISCO_IOT_MultiEvent/DISCO_IOT_MultiEvent.ino:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file DISCO_IOT_MultiEvent.ino
4 | * @author WI6LABS from AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
8 | * MEMS Inertial and Environmental sensor expansion board.
9 | * This application detects free fall, tap, double tap, tilt, wake up,
10 | * 6D Orientation and step events through the LSM6DSL sensor.
11 | * This application makes use of C++ classes obtained from the C
12 | * components' drivers.
13 | ******************************************************************************
14 | * @attention
15 | *
16 | * © COPYRIGHT(c) 2017 STMicroelectronics
17 | *
18 | * Redistribution and use in source and binary forms, with or without modification,
19 | * are permitted provided that the following conditions are met:
20 | * 1. Redistributions of source code must retain the above copyright notice,
21 | * this list of conditions and the following disclaimer.
22 | * 2. Redistributions in binary form must reproduce the above copyright notice,
23 | * this list of conditions and the following disclaimer in the documentation
24 | * and/or other materials provided with the distribution.
25 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
26 | * may be used to endorse or promote products derived from this software
27 | * without specific prior written permission.
28 | *
29 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
33 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 | *
40 | ******************************************************************************
41 | */
42 |
43 | /** NOTE
44 | The interrupt pin INT2 of the LSM6DSL is not connected on the Discovery L475VG
45 | IoT board. So the wakeup event is not used in this sketch to not decrease
46 | performances. If wakeup event is enabled on INT1 with all other events, this
47 | could cause some troubles.
48 | */
49 |
50 | // Includes.
51 | #include
52 |
53 | #define SerialPort Serial
54 | #define I2C2_SCL PB10
55 | #define I2C2_SDA PB11
56 | #define INT1 PD11
57 |
58 | // Components.
59 | TwoWire dev_i2c(I2C2_SDA, I2C2_SCL);
60 | LSM6DSLSensor AccGyr(&dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
61 |
62 | //Interrupts.
63 | volatile int mems_event = 0;
64 |
65 | uint16_t step_count = 0;
66 | char report[256];
67 |
68 | void INT1Event_cb();
69 | void sendOrientation();
70 |
71 | void setup() {
72 | // Initialize serial for output.
73 | SerialPort.begin(9600);
74 |
75 | // Initialize I2C bus.
76 | dev_i2c.begin();
77 |
78 | //Interrupts.
79 | attachInterrupt(INT1, INT1Event_cb, RISING);
80 |
81 | // Initlialize Components.
82 | AccGyr.begin();
83 | AccGyr.Enable_X();
84 |
85 | // Enable all HW events.
86 | AccGyr.Enable_Pedometer();
87 | AccGyr.Enable_Tilt_Detection();
88 | AccGyr.Enable_Free_Fall_Detection();
89 | AccGyr.Enable_Single_Tap_Detection();
90 | AccGyr.Enable_Double_Tap_Detection();
91 | AccGyr.Enable_6D_Orientation();
92 | }
93 |
94 | void loop() {
95 | if (mems_event)
96 | {
97 | mems_event = 0;
98 | LSM6DSL_Event_Status_t status;
99 | AccGyr.Get_Event_Status(&status);
100 |
101 | if (status.StepStatus)
102 | {
103 | // New step detected, so print the step counter
104 | AccGyr.Get_Step_Counter(&step_count);
105 | snprintf(report, sizeof(report), "Step counter: %d", step_count);
106 | SerialPort.println(report);
107 | }
108 |
109 | if (status.FreeFallStatus)
110 | {
111 | // Output data.
112 | SerialPort.println("Free Fall Detected!");
113 | }
114 |
115 | if (status.TapStatus)
116 | {
117 | // Output data.
118 | SerialPort.println("Single Tap Detected!");
119 | }
120 |
121 | if (status.DoubleTapStatus)
122 | {
123 | // Output data.
124 | SerialPort.println("Double Tap Detected!");
125 | }
126 |
127 | if (status.TiltStatus)
128 | {
129 | // Output data.
130 | SerialPort.println("Tilt Detected!");
131 | }
132 |
133 | if (status.D6DOrientationStatus)
134 | {
135 | // Send 6D Orientation
136 | sendOrientation();
137 | }
138 | }
139 | }
140 |
141 | void INT1Event_cb()
142 | {
143 | mems_event = 1;
144 | }
145 |
146 | void sendOrientation()
147 | {
148 | uint8_t xl = 0;
149 | uint8_t xh = 0;
150 | uint8_t yl = 0;
151 | uint8_t yh = 0;
152 | uint8_t zl = 0;
153 | uint8_t zh = 0;
154 |
155 | AccGyr.Get_6D_Orientation_XL(&xl);
156 | AccGyr.Get_6D_Orientation_XH(&xh);
157 | AccGyr.Get_6D_Orientation_YL(&yl);
158 | AccGyr.Get_6D_Orientation_YH(&yh);
159 | AccGyr.Get_6D_Orientation_ZL(&zl);
160 | AccGyr.Get_6D_Orientation_ZH(&zh);
161 |
162 | if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 1 && zh == 0 )
163 | {
164 | sprintf( report, "\r\n ________________ " \
165 | "\r\n | | " \
166 | "\r\n | * | " \
167 | "\r\n | | " \
168 | "\r\n | | " \
169 | "\r\n | | " \
170 | "\r\n | | " \
171 | "\r\n |________________| \r\n" );
172 | }
173 |
174 | else if ( xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
175 | {
176 | sprintf( report, "\r\n ________________ " \
177 | "\r\n | | " \
178 | "\r\n | * | " \
179 | "\r\n | | " \
180 | "\r\n | | " \
181 | "\r\n | | " \
182 | "\r\n | | " \
183 | "\r\n |________________| \r\n" );
184 | }
185 |
186 | else if ( xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0 )
187 | {
188 | sprintf( report, "\r\n ________________ " \
189 | "\r\n | | " \
190 | "\r\n | | " \
191 | "\r\n | | " \
192 | "\r\n | | " \
193 | "\r\n | | " \
194 | "\r\n | * | " \
195 | "\r\n |________________| \r\n" );
196 | }
197 |
198 | else if ( xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0 )
199 | {
200 | sprintf( report, "\r\n ________________ " \
201 | "\r\n | | " \
202 | "\r\n | | " \
203 | "\r\n | | " \
204 | "\r\n | | " \
205 | "\r\n | | " \
206 | "\r\n | * | " \
207 | "\r\n |________________| \r\n" );
208 | }
209 |
210 | else if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1 )
211 | {
212 | sprintf( report, "\r\n __*_____________ " \
213 | "\r\n |________________| \r\n" );
214 | }
215 |
216 | else if ( xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0 )
217 | {
218 | sprintf( report, "\r\n ________________ " \
219 | "\r\n |________________| " \
220 | "\r\n * \r\n" );
221 | }
222 |
223 | else
224 | {
225 | sprintf( report, "None of the 6D orientation axes is set in LSM6DSL - accelerometer.\r\n" );
226 | }
227 |
228 | SerialPort.print(report);
229 | }
230 |
--------------------------------------------------------------------------------
/examples/DISCO_IOT_Pedometer/DISCO_IOT_Pedometer.ino:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file DISCO_IOT__Pedometer.ino
4 | * @author WI6LABS from AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
8 | * MEMS Inertial and Environmental sensor expansion board.
9 | * This application detects step event through the LSM6DSL sensor.
10 | * This application makes use of C++ classes obtained from the C
11 | * components' drivers.
12 | ******************************************************************************
13 | * @attention
14 | *
15 | * © COPYRIGHT(c) 2017 STMicroelectronics
16 | *
17 | * Redistribution and use in source and binary forms, with or without modification,
18 | * are permitted provided that the following conditions are met:
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
25 | * may be used to endorse or promote products derived from this software
26 | * without specific prior written permission.
27 | *
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | *
39 | ******************************************************************************
40 | */
41 |
42 |
43 | // Includes.
44 | #include
45 |
46 | #define SerialPort Serial
47 | #define I2C2_SCL PB10
48 | #define I2C2_SDA PB11
49 | #define INT1 PD11
50 |
51 | // Components.
52 | TwoWire dev_i2c(I2C2_SDA, I2C2_SCL);
53 | LSM6DSLSensor AccGyr(&dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
54 |
55 | //Interrupts.
56 | volatile int mems_event = 0;
57 |
58 | uint32_t previous_tick = 0;
59 | uint32_t current_tick = 0;
60 | uint16_t step_count = 0;
61 | char report[256];
62 |
63 | void INT1Event_cb();
64 |
65 | void setup() {
66 | // Led.
67 | pinMode(LED_BUILTIN, OUTPUT);
68 |
69 | // Initialize serial for output.
70 | SerialPort.begin(9600);
71 |
72 | // Initialize I2C bus.
73 | dev_i2c.begin();
74 |
75 | //Interrupts.
76 | attachInterrupt(INT1, INT1Event_cb, RISING);
77 |
78 | // Initlialize Components.
79 | AccGyr.begin();
80 | AccGyr.Enable_X();
81 |
82 | // Enable Pedometer.
83 | AccGyr.Enable_Pedometer();
84 |
85 | previous_tick = millis();
86 | }
87 |
88 | void loop() {
89 | if (mems_event)
90 | {
91 | mems_event = 0;
92 | LSM6DSL_Event_Status_t status;
93 | AccGyr.Get_Event_Status(&status);
94 | if (status.StepStatus)
95 | {
96 | // New step detected, so print the step counter
97 | AccGyr.Get_Step_Counter(&step_count);
98 | snprintf(report, sizeof(report), "Step counter: %d", step_count);
99 | SerialPort.println(report);
100 |
101 | // Led blinking.
102 | digitalWrite(LED_BUILTIN, HIGH);
103 | delay(100);
104 | digitalWrite(LED_BUILTIN, LOW);
105 | }
106 | }
107 |
108 | // Print the step counter in any case every 3000 ms
109 | current_tick = millis();
110 | if((current_tick - previous_tick) >= 3000)
111 | {
112 | AccGyr.Get_Step_Counter(&step_count);
113 | snprintf(report, sizeof(report), "Step counter: %d", step_count);
114 | SerialPort.println(report);
115 | previous_tick = millis();
116 | }
117 | }
118 |
119 | void INT1Event_cb()
120 | {
121 | mems_event = 1;
122 | }
123 |
--------------------------------------------------------------------------------
/examples/DISCO_IOT_Tap/DISCO_IOT_Tap.ino:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file DISCO_IOT_Tap.ino
4 | * @author WI6LABS from AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
8 | * MEMS Inertial and Environmental sensor expansion board.
9 | * This application detects tap event through the LSM6DSL sensor.
10 | * This application makes use of C++ classes obtained from the C
11 | * components' drivers.
12 | ******************************************************************************
13 | * @attention
14 | *
15 | * © COPYRIGHT(c) 2017 STMicroelectronics
16 | *
17 | * Redistribution and use in source and binary forms, with or without modification,
18 | * are permitted provided that the following conditions are met:
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
25 | * may be used to endorse or promote products derived from this software
26 | * without specific prior written permission.
27 | *
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | *
39 | ******************************************************************************
40 | */
41 |
42 |
43 | // Includes.
44 | #include
45 |
46 | #define SerialPort Serial
47 | #define I2C2_SCL PB10
48 | #define I2C2_SDA PB11
49 | #define INT1 PD11
50 |
51 | // Components.
52 | TwoWire dev_i2c(I2C2_SDA, I2C2_SCL);
53 | LSM6DSLSensor AccGyr(&dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
54 |
55 | //Interrupts.
56 | volatile int mems_event = 0;
57 |
58 | void INT1Event_cb();
59 |
60 | void setup() {
61 | // Led.
62 | pinMode(LED_BUILTIN, OUTPUT);
63 |
64 | // Initialize serial for output.
65 | SerialPort.begin(9600);
66 |
67 | // Initialize I2C bus.
68 | dev_i2c.begin();
69 |
70 | //Interrupts.
71 | attachInterrupt(INT1, INT1Event_cb, RISING);
72 |
73 | // Initlialize Components.
74 | AccGyr.begin();
75 | AccGyr.Enable_X();
76 |
77 | // Enable Single Tap Detection.
78 | AccGyr.Enable_Single_Tap_Detection();
79 | }
80 |
81 | void loop() {
82 | if (mems_event) {
83 | mems_event = 0;
84 | LSM6DSL_Event_Status_t status;
85 | AccGyr.Get_Event_Status(&status);
86 | if (status.TapStatus)
87 | {
88 | // Led blinking.
89 | digitalWrite(LED_BUILTIN, HIGH);
90 | delay(100);
91 | digitalWrite(LED_BUILTIN, LOW);
92 |
93 | // Output data.
94 | SerialPort.println("Single Tap Detected!");
95 | }
96 | }
97 | }
98 |
99 | void INT1Event_cb()
100 | {
101 | mems_event = 1;
102 | }
103 |
--------------------------------------------------------------------------------
/examples/DISCO_IOT_Tilt/DISCO_IOT_Tilt.ino:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file DISCO_IOT_Tilt.ino
4 | * @author WI6LABS from AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
8 | * MEMS Inertial and Environmental sensor expansion board.
9 | * This application detects tilt event through the LSM6DSL sensor.
10 | * This application makes use of C++ classes obtained from the C
11 | * components' drivers.
12 | ******************************************************************************
13 | * @attention
14 | *
15 | * © COPYRIGHT(c) 2017 STMicroelectronics
16 | *
17 | * Redistribution and use in source and binary forms, with or without modification,
18 | * are permitted provided that the following conditions are met:
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
25 | * may be used to endorse or promote products derived from this software
26 | * without specific prior written permission.
27 | *
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | *
39 | ******************************************************************************
40 | */
41 |
42 |
43 | // Includes.
44 | #include
45 |
46 | #define SerialPort Serial
47 | #define I2C2_SCL PB10
48 | #define I2C2_SDA PB11
49 | #define INT1 PD11
50 |
51 | // Components.
52 | TwoWire dev_i2c(I2C2_SDA, I2C2_SCL);
53 | LSM6DSLSensor AccGyr(&dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
54 |
55 | //Interrupts.
56 | volatile int mems_event = 0;
57 |
58 | void INT1Event_cb();
59 |
60 | void setup() {
61 | // Led.
62 | pinMode(LED_BUILTIN, OUTPUT);
63 |
64 | // Initialize serial for output.
65 | SerialPort.begin(9600);
66 |
67 | // Initialize I2C bus.
68 | dev_i2c.begin();
69 |
70 | //Interrupts.
71 | attachInterrupt(INT1, INT1Event_cb, RISING);
72 |
73 | // Initlialize Components.
74 | AccGyr.begin();
75 | AccGyr.Enable_X();
76 |
77 | // Enable Tilt Detection.
78 | AccGyr.Enable_Tilt_Detection();
79 | }
80 |
81 | void loop() {
82 | if (mems_event) {
83 | mems_event = 0;
84 | LSM6DSL_Event_Status_t status;
85 | AccGyr.Get_Event_Status(&status);
86 | if (status.TiltStatus)
87 | {
88 | // Led blinking.
89 | digitalWrite(LED_BUILTIN, HIGH);
90 | delay(100);
91 | digitalWrite(LED_BUILTIN, LOW);
92 |
93 | // Output data.
94 | SerialPort.println("Tilt Detected!");
95 | }
96 | }
97 | }
98 |
99 | void INT1Event_cb()
100 | {
101 | mems_event = 1;
102 | }
103 |
--------------------------------------------------------------------------------
/examples/DISCO_IOT_WakeUp/DISCO_IOT_WakeUp.ino:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file DISCO_IOT_WakeUp.ino
4 | * @author WI6LABS from AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Arduino test application for the STMicrolectronics STM32 IOT Discovery Kit.
8 | * MEMS Inertial and Environmental sensor expansion board.
9 | * This application detects wake up event through the LSM6DSL sensor.
10 | * This application makes use of C++ classes obtained from the C
11 | * components' drivers.
12 | ******************************************************************************
13 | * @attention
14 | *
15 | * © COPYRIGHT(c) 2017 STMicroelectronics
16 | *
17 | * Redistribution and use in source and binary forms, with or without modification,
18 | * are permitted provided that the following conditions are met:
19 | * 1. Redistributions of source code must retain the above copyright notice,
20 | * this list of conditions and the following disclaimer.
21 | * 2. Redistributions in binary form must reproduce the above copyright notice,
22 | * this list of conditions and the following disclaimer in the documentation
23 | * and/or other materials provided with the distribution.
24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
25 | * may be used to endorse or promote products derived from this software
26 | * without specific prior written permission.
27 | *
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | *
39 | ******************************************************************************
40 | */
41 |
42 |
43 | // Includes.
44 | #include
45 |
46 | #define SerialPort Serial
47 | #define I2C2_SCL PB10
48 | #define I2C2_SDA PB11
49 | #define INT1 PD11
50 |
51 | // Components.
52 | TwoWire dev_i2c(I2C2_SDA, I2C2_SCL);
53 | LSM6DSLSensor AccGyr(&dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW);
54 |
55 | //Interrupts.
56 | volatile int mems_event = 0;
57 |
58 | void INT1Event_cb();
59 |
60 | void setup() {
61 | // Led.
62 | pinMode(LED_BUILTIN, OUTPUT);
63 |
64 | // Initialize serial for output.
65 | SerialPort.begin(9600);
66 |
67 | // Initialize I2C bus.
68 | dev_i2c.begin();
69 |
70 | //Interrupts.
71 | attachInterrupt(INT1, INT1Event_cb, RISING);
72 |
73 | // Initlialize Components.
74 | AccGyr.begin();
75 | AccGyr.Enable_X();
76 |
77 | // Enable Wake Up Detection.
78 | AccGyr.Enable_Wake_Up_Detection(LSM6DSL_INT1_PIN);
79 | }
80 |
81 | void loop() {
82 | if (mems_event) {
83 | mems_event = 0;
84 | LSM6DSL_Event_Status_t status;
85 | AccGyr.Get_Event_Status(&status);
86 | if (status.WakeUpStatus)
87 | {
88 | // Led blinking.
89 | digitalWrite(LED_BUILTIN, HIGH);
90 | delay(100);
91 | digitalWrite(LED_BUILTIN, LOW);
92 |
93 | // Output data.
94 | SerialPort.println("Wake up Detected!");
95 | }
96 | }
97 | }
98 |
99 | void INT1Event_cb()
100 | {
101 | mems_event = 1;
102 | }
103 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | #######################################
2 | # Syntax Coloring Map For LSM6DSL
3 | #######################################
4 |
5 | #######################################
6 | # Datatypes (KEYWORD1)
7 | #######################################
8 |
9 | LSM6DSLSensor KEYWORD1
10 |
11 | #######################################
12 | # Methods and Functions (KEYWORD2)
13 | #######################################
14 |
15 | begin KEYWORD2
16 | end KEYWORD2
17 | Enable_X KEYWORD2
18 | Enable_G KEYWORD2
19 | Disable_X KEYWORD2
20 | Disable_G KEYWORD2
21 | ReadID KEYWORD2
22 | Get_X_Axes KEYWORD2
23 | Get_G_Axes KEYWORD2
24 | Get_X_Sensitivity KEYWORD2
25 | Get_G_Sensitivity KEYWORD2
26 | Get_X_AxesRaw KEYWORD2
27 | Get_G_AxesRaw KEYWORD2
28 | Get_X_ODR KEYWORD2
29 | Get_G_ODR KEYWORD2
30 | Set_X_ODR KEYWORD2
31 | Set_G_ODR KEYWORD2
32 | Get_X_FS KEYWORD2
33 | Get_G_FS KEYWORD2
34 | Set_X_FS KEYWORD2
35 | Set_G_FS KEYWORD2
36 | Enable_Free_Fall_Detection KEYWORD2
37 | Enable_Free_Fall_Detection KEYWORD2
38 | Disable_Free_Fall_Detection KEYWORD2
39 | Set_Free_Fall_Threshold KEYWORD2
40 | Enable_Pedometer KEYWORD2
41 | Disable_Pedometer KEYWORD2
42 | Get_Step_Counter KEYWORD2
43 | Reset_Step_Counter KEYWORD2
44 | Set_Pedometer_Threshold KEYWORD2
45 | Enable_Tilt_Detection KEYWORD2
46 | Enable_Tilt_Detection KEYWORD2
47 | Disable_Tilt_Detection KEYWORD2
48 | Enable_Wake_Up_Detection KEYWORD2
49 | Enable_Wake_Up_Detection KEYWORD2
50 | Disable_Wake_Up_Detection KEYWORD2
51 | Set_Wake_Up_Threshold KEYWORD2
52 | Enable_Single_Tap_Detection KEYWORD2
53 | Enable_Single_Tap_Detection KEYWORD2
54 | Disable_Single_Tap_Detection KEYWORD2
55 | Enable_Double_Tap_Detection KEYWORD2
56 | Enable_Double_Tap_Detection KEYWORD2
57 | Disable_Double_Tap_Detection KEYWORD2
58 | Set_Tap_Threshold KEYWORD2
59 | Set_Tap_Shock_Time KEYWORD2
60 | Set_Tap_Quiet_Time KEYWORD2
61 | Set_Tap_Duration_Time KEYWORD2
62 | Enable_6D_Orientation KEYWORD2
63 | Enable_6D_Orientation KEYWORD2
64 | Disable_6D_Orientation KEYWORD2
65 | Get_6D_Orientation_XL KEYWORD2
66 | Get_6D_Orientation_XH KEYWORD2
67 | Get_6D_Orientation_YL KEYWORD2
68 | Get_6D_Orientation_YH KEYWORD2
69 | Get_6D_Orientation_ZL KEYWORD2
70 | Get_6D_Orientation_ZH KEYWORD2
71 | Get_Event_Status KEYWORD2
72 | ReadReg KEYWORD2
73 | WriteReg KEYWORD2
74 |
75 | #######################################
76 | # Constants (LITERAL1)
77 | #######################################
78 |
79 | LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G LITERAL1
80 | LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G LITERAL1
81 | LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G LITERAL1
82 | LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G LITERAL1
83 | LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS LITERAL1
84 | LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS LITERAL1
85 | LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS LITERAL1
86 | LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS LITERAL1
87 | LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS LITERAL1
88 | LSM6DSL_PEDOMETER_THRESHOLD_LOW LITERAL1
89 | LSM6DSL_PEDOMETER_THRESHOLD_MID_LOW LITERAL1
90 | LSM6DSL_PEDOMETER_THRESHOLD_MID LITERAL1
91 | LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH LITERAL1
92 | LSM6DSL_PEDOMETER_THRESHOLD_HIGH LITERAL1
93 | LSM6DSL_WAKE_UP_THRESHOLD_LOW LITERAL1
94 | LSM6DSL_WAKE_UP_THRESHOLD_MID_LOW LITERAL1
95 | LSM6DSL_WAKE_UP_THRESHOLD_MID LITERAL1
96 | LSM6DSL_WAKE_UP_THRESHOLD_MID_HIGH LITERAL1
97 | LSM6DSL_WAKE_UP_THRESHOLD_HIGH LITERAL1
98 | LSM6DSL_TAP_THRESHOLD_LOW LITERAL1
99 | LSM6DSL_TAP_THRESHOLD_MID_LOW LITERAL1
100 | LSM6DSL_TAP_THRESHOLD_MID LITERAL1
101 | LSM6DSL_TAP_THRESHOLD_MID_HIGH LITERAL1
102 | LSM6DSL_TAP_THRESHOLD_HIGH LITERAL1
103 | LSM6DSL_TAP_SHOCK_TIME_LOW LITERAL1
104 | LSM6DSL_TAP_SHOCK_TIME_MID_LOW LITERAL1
105 | LSM6DSL_TAP_SHOCK_TIME_MID_HIGH LITERAL1
106 | LSM6DSL_TAP_SHOCK_TIME_HIGH LITERAL1
107 | LSM6DSL_TAP_QUIET_TIME_LOW LITERAL1
108 | LSM6DSL_TAP_QUIET_TIME_MID_LOW LITERAL1
109 | LSM6DSL_TAP_QUIET_TIME_MID_HIGH LITERAL1
110 | LSM6DSL_TAP_QUIET_TIME_HIGH LITERAL1
111 | LSM6DSL_TAP_DURATION_LOW LITERAL1
112 | LSM6DSL_TAP_DURATION_MID_LOW LITERAL1
113 | LSM6DSL_TAP_DURATION_MID LITERAL1
114 | LSM6DSL_TAP_DURATION_MID_HIGH LITERAL1
115 | LSM6DSL_TAP_DURATION_HIGH LITERAL1
116 |
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=STM32duino LSM6DSL
2 | version=2.0.0
3 | author=AST, Wi6Labs
4 | maintainer=stm32duino
5 | sentence=3D accelerometer and 3D gyroscope.
6 | paragraph=This library provides Arduino support for the 3D accelerometer and 3D gyroscope LSM6DSL for STM32 boards.
7 | category=Sensors
8 | url=https://github.com/stm32duino/LSM6DSL
9 | architectures=stm32, avr, sam
10 |
--------------------------------------------------------------------------------
/src/LSM6DSLSensor.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file LSM6DSLSensor.cpp
4 | * @author AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Implementation of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes
8 | * sensor.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * © COPYRIGHT(c) 2017 STMicroelectronics
13 | *
14 | * Redistribution and use in source and binary forms, with or without modification,
15 | * are permitted provided that the following conditions are met:
16 | * 1. Redistributions of source code must retain the above copyright notice,
17 | * this list of conditions and the following disclaimer.
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
19 | * this list of conditions and the following disclaimer in the documentation
20 | * and/or other materials provided with the distribution.
21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
22 | * may be used to endorse or promote products derived from this software
23 | * without specific prior written permission.
24 | *
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 | *
36 | ******************************************************************************
37 | */
38 |
39 |
40 | /* Includes ------------------------------------------------------------------*/
41 |
42 | #include "Arduino.h"
43 | #include "Wire.h"
44 | #include "LSM6DSLSensor.h"
45 |
46 |
47 | /* Class Implementation ------------------------------------------------------*/
48 | /** Constructor
49 | * @param i2c object of an helper class which handles the I2C peripheral
50 | * @param address the address of the component's instance
51 | */
52 | LSM6DSLSensor::LSM6DSLSensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c), address(address)
53 | {
54 | dev_spi = NULL;
55 | X_isEnabled = 0;
56 | G_isEnabled = 0;
57 | }
58 |
59 | /** Constructor
60 | * @param spi object of an helper class which handles the SPI peripheral
61 | * @param cs_pin the chip select pin
62 | * @param spi_speed the SPI speed
63 | */
64 | LSM6DSLSensor::LSM6DSLSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed) : dev_spi(spi), cs_pin(cs_pin), spi_speed(spi_speed)
65 | {
66 | dev_i2c = NULL;
67 | address = 0;
68 | X_isEnabled = 0U;
69 | G_isEnabled = 0U;
70 | }
71 |
72 | /**
73 | * @brief Configure the sensor in order to be used
74 | * @retval 0 in case of success, an error code otherwise
75 | */
76 | LSM6DSLStatusTypeDef LSM6DSLSensor::begin()
77 | {
78 | if(dev_spi)
79 | {
80 | // Configure CS pin
81 | pinMode(cs_pin, OUTPUT);
82 | digitalWrite(cs_pin, HIGH);
83 | }
84 |
85 | /* Enable register address automatically incremented during a multiple byte
86 | access with a serial interface. */
87 | if ( LSM6DSL_ACC_GYRO_W_IF_Addr_Incr( (void *)this, LSM6DSL_ACC_GYRO_IF_INC_ENABLED ) == MEMS_ERROR )
88 | {
89 | return LSM6DSL_STATUS_ERROR;
90 | }
91 |
92 | /* Enable BDU */
93 | if ( LSM6DSL_ACC_GYRO_W_BDU( (void *)this, LSM6DSL_ACC_GYRO_BDU_BLOCK_UPDATE ) == MEMS_ERROR )
94 | {
95 | return LSM6DSL_STATUS_ERROR;
96 | }
97 |
98 | /* FIFO mode selection */
99 | if ( LSM6DSL_ACC_GYRO_W_FIFO_MODE( (void *)this, LSM6DSL_ACC_GYRO_FIFO_MODE_BYPASS ) == MEMS_ERROR )
100 | {
101 | return LSM6DSL_STATUS_ERROR;
102 | }
103 |
104 | /* Output data rate selection - power down. */
105 | if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN ) == MEMS_ERROR )
106 | {
107 | return LSM6DSL_STATUS_ERROR;
108 | }
109 |
110 | /* Full scale selection. */
111 | if ( Set_X_FS( 2.0f ) == LSM6DSL_STATUS_ERROR )
112 | {
113 | return LSM6DSL_STATUS_ERROR;
114 | }
115 |
116 | /* Output data rate selection - power down */
117 | if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN ) == MEMS_ERROR )
118 | {
119 | return LSM6DSL_STATUS_ERROR;
120 | }
121 |
122 | /* Full scale selection. */
123 | if ( Set_G_FS( 2000.0f ) == LSM6DSL_STATUS_ERROR )
124 | {
125 | return LSM6DSL_STATUS_ERROR;
126 | }
127 |
128 | X_Last_ODR = 104.0f;
129 |
130 | X_isEnabled = 0;
131 |
132 | G_Last_ODR = 104.0f;
133 |
134 | G_isEnabled = 0;
135 |
136 | return LSM6DSL_STATUS_OK;
137 | }
138 |
139 | /**
140 | * @brief Disable the sensor and relative resources
141 | * @retval 0 in case of success, an error code otherwise
142 | */
143 | LSM6DSLStatusTypeDef LSM6DSLSensor::end()
144 | {
145 | /* Disable both acc and gyro */
146 | if (Disable_X() != LSM6DSL_STATUS_OK)
147 | {
148 | return LSM6DSL_STATUS_ERROR;
149 | }
150 |
151 | if (Disable_G() != LSM6DSL_STATUS_OK)
152 | {
153 | return LSM6DSL_STATUS_ERROR;
154 | }
155 |
156 | /* Reset CS configuration */
157 | if(dev_spi)
158 | {
159 | // Configure CS pin
160 | pinMode(cs_pin, INPUT);
161 | }
162 |
163 | return LSM6DSL_STATUS_OK;
164 | }
165 |
166 | /**
167 | * @brief Enable LSM6DSL Accelerator
168 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
169 | */
170 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_X(void)
171 | {
172 | /* Check if the component is already enabled */
173 | if ( X_isEnabled == 1 )
174 | {
175 | return LSM6DSL_STATUS_OK;
176 | }
177 |
178 | /* Output data rate selection. */
179 | if ( Set_X_ODR_When_Enabled( X_Last_ODR ) == LSM6DSL_STATUS_ERROR )
180 | {
181 | return LSM6DSL_STATUS_ERROR;
182 | }
183 |
184 | X_isEnabled = 1;
185 |
186 | return LSM6DSL_STATUS_OK;
187 | }
188 |
189 | /**
190 | * @brief Enable LSM6DSL Gyroscope
191 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
192 | */
193 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_G(void)
194 | {
195 | /* Check if the component is already enabled */
196 | if ( G_isEnabled == 1 )
197 | {
198 | return LSM6DSL_STATUS_OK;
199 | }
200 |
201 | /* Output data rate selection. */
202 | if ( Set_G_ODR_When_Enabled( G_Last_ODR ) == LSM6DSL_STATUS_ERROR )
203 | {
204 | return LSM6DSL_STATUS_ERROR;
205 | }
206 |
207 | G_isEnabled = 1;
208 |
209 | return LSM6DSL_STATUS_OK;
210 | }
211 |
212 | /**
213 | * @brief Disable LSM6DSL Accelerator
214 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
215 | */
216 | LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_X(void)
217 | {
218 | /* Check if the component is already disabled */
219 | if ( X_isEnabled == 0 )
220 | {
221 | return LSM6DSL_STATUS_OK;
222 | }
223 |
224 | /* Store actual output data rate. */
225 | if ( Get_X_ODR( &X_Last_ODR ) == LSM6DSL_STATUS_ERROR )
226 | {
227 | return LSM6DSL_STATUS_ERROR;
228 | }
229 |
230 | /* Output data rate selection - power down. */
231 | if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN ) == MEMS_ERROR )
232 | {
233 | return LSM6DSL_STATUS_ERROR;
234 | }
235 |
236 | X_isEnabled = 0;
237 |
238 | return LSM6DSL_STATUS_OK;
239 | }
240 |
241 | /**
242 | * @brief Disable LSM6DSL Gyroscope
243 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
244 | */
245 | LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_G(void)
246 | {
247 | /* Check if the component is already disabled */
248 | if ( G_isEnabled == 0 )
249 | {
250 | return LSM6DSL_STATUS_OK;
251 | }
252 |
253 | /* Store actual output data rate. */
254 | if ( Get_G_ODR( &G_Last_ODR ) == LSM6DSL_STATUS_ERROR )
255 | {
256 | return LSM6DSL_STATUS_ERROR;
257 | }
258 |
259 | /* Output data rate selection - power down */
260 | if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN ) == MEMS_ERROR )
261 | {
262 | return LSM6DSL_STATUS_ERROR;
263 | }
264 |
265 | G_isEnabled = 0;
266 |
267 | return LSM6DSL_STATUS_OK;
268 | }
269 |
270 | /**
271 | * @brief Read ID of LSM6DSL Accelerometer and Gyroscope
272 | * @param p_id the pointer where the ID of the device is stored
273 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
274 | */
275 | LSM6DSLStatusTypeDef LSM6DSLSensor::ReadID(uint8_t *p_id)
276 | {
277 | if(!p_id)
278 | {
279 | return LSM6DSL_STATUS_ERROR;
280 | }
281 |
282 | /* Read WHO AM I register */
283 | if ( LSM6DSL_ACC_GYRO_R_WHO_AM_I( (void *)this, p_id ) == MEMS_ERROR )
284 | {
285 | return LSM6DSL_STATUS_ERROR;
286 | }
287 |
288 | return LSM6DSL_STATUS_OK;
289 | }
290 |
291 | /**
292 | * @brief Read data from LSM6DSL Accelerometer
293 | * @param pData the pointer where the accelerometer data are stored
294 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
295 | */
296 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_Axes(int32_t *pData)
297 | {
298 | int16_t dataRaw[3];
299 | float sensitivity = 0;
300 |
301 | /* Read raw data from LSM6DSL output register. */
302 | if ( Get_X_AxesRaw( dataRaw ) == LSM6DSL_STATUS_ERROR )
303 | {
304 | return LSM6DSL_STATUS_ERROR;
305 | }
306 |
307 | /* Get LSM6DSL actual sensitivity. */
308 | if ( Get_X_Sensitivity( &sensitivity ) == LSM6DSL_STATUS_ERROR )
309 | {
310 | return LSM6DSL_STATUS_ERROR;
311 | }
312 |
313 | /* Calculate the data. */
314 | pData[0] = ( int32_t )( dataRaw[0] * sensitivity );
315 | pData[1] = ( int32_t )( dataRaw[1] * sensitivity );
316 | pData[2] = ( int32_t )( dataRaw[2] * sensitivity );
317 |
318 | return LSM6DSL_STATUS_OK;
319 | }
320 |
321 | /**
322 | * @brief Read data from LSM6DSL Gyroscope
323 | * @param pData the pointer where the gyroscope data are stored
324 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
325 | */
326 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_Axes(int32_t *pData)
327 | {
328 | int16_t dataRaw[3];
329 | float sensitivity = 0;
330 |
331 | /* Read raw data from LSM6DSL output register. */
332 | if ( Get_G_AxesRaw( dataRaw ) == LSM6DSL_STATUS_ERROR )
333 | {
334 | return LSM6DSL_STATUS_ERROR;
335 | }
336 |
337 | /* Get LSM6DSL actual sensitivity. */
338 | if ( Get_G_Sensitivity( &sensitivity ) == LSM6DSL_STATUS_ERROR )
339 | {
340 | return LSM6DSL_STATUS_ERROR;
341 | }
342 |
343 | /* Calculate the data. */
344 | pData[0] = ( int32_t )( dataRaw[0] * sensitivity );
345 | pData[1] = ( int32_t )( dataRaw[1] * sensitivity );
346 | pData[2] = ( int32_t )( dataRaw[2] * sensitivity );
347 |
348 | return LSM6DSL_STATUS_OK;
349 | }
350 |
351 | /**
352 | * @brief Read Accelerometer Sensitivity
353 | * @param pfData the pointer where the accelerometer sensitivity is stored
354 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
355 | */
356 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_Sensitivity(float *pfData)
357 | {
358 | LSM6DSL_ACC_GYRO_FS_XL_t fullScale;
359 |
360 | /* Read actual full scale selection from sensor. */
361 | if ( LSM6DSL_ACC_GYRO_R_FS_XL( (void *)this, &fullScale ) == MEMS_ERROR )
362 | {
363 | return LSM6DSL_STATUS_ERROR;
364 | }
365 |
366 | /* Store the sensitivity based on actual full scale. */
367 | switch( fullScale )
368 | {
369 | case LSM6DSL_ACC_GYRO_FS_XL_2g:
370 | *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G;
371 | break;
372 | case LSM6DSL_ACC_GYRO_FS_XL_4g:
373 | *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G;
374 | break;
375 | case LSM6DSL_ACC_GYRO_FS_XL_8g:
376 | *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G;
377 | break;
378 | case LSM6DSL_ACC_GYRO_FS_XL_16g:
379 | *pfData = ( float )LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G;
380 | break;
381 | default:
382 | *pfData = -1.0f;
383 | return LSM6DSL_STATUS_ERROR;
384 | }
385 |
386 | return LSM6DSL_STATUS_OK;
387 | }
388 |
389 | /**
390 | * @brief Read Gyroscope Sensitivity
391 | * @param pfData the pointer where the gyroscope sensitivity is stored
392 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
393 | */
394 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_Sensitivity(float *pfData)
395 | {
396 | LSM6DSL_ACC_GYRO_FS_125_t fullScale125;
397 | LSM6DSL_ACC_GYRO_FS_G_t fullScale;
398 |
399 | /* Read full scale 125 selection from sensor. */
400 | if ( LSM6DSL_ACC_GYRO_R_FS_125( (void *)this, &fullScale125 ) == MEMS_ERROR )
401 | {
402 | return LSM6DSL_STATUS_ERROR;
403 | }
404 |
405 | if ( fullScale125 == LSM6DSL_ACC_GYRO_FS_125_ENABLED )
406 | {
407 | *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS;
408 | }
409 |
410 | else
411 | {
412 |
413 | /* Read actual full scale selection from sensor. */
414 | if ( LSM6DSL_ACC_GYRO_R_FS_G( (void *)this, &fullScale ) == MEMS_ERROR )
415 | {
416 | return LSM6DSL_STATUS_ERROR;
417 | }
418 |
419 | /* Store the sensitivity based on actual full scale. */
420 | switch( fullScale )
421 | {
422 | case LSM6DSL_ACC_GYRO_FS_G_245dps:
423 | *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS;
424 | break;
425 | case LSM6DSL_ACC_GYRO_FS_G_500dps:
426 | *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS;
427 | break;
428 | case LSM6DSL_ACC_GYRO_FS_G_1000dps:
429 | *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS;
430 | break;
431 | case LSM6DSL_ACC_GYRO_FS_G_2000dps:
432 | *pfData = ( float )LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS;
433 | break;
434 | default:
435 | *pfData = -1.0f;
436 | return LSM6DSL_STATUS_ERROR;
437 | }
438 | }
439 |
440 | return LSM6DSL_STATUS_OK;
441 | }
442 |
443 | /**
444 | * @brief Read raw data from LSM6DSL Accelerometer
445 | * @param pData the pointer where the accelerometer raw data are stored
446 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
447 | */
448 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_AxesRaw(int16_t *pData)
449 | {
450 | uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
451 |
452 | /* Read output registers from LSM6DSL_ACC_GYRO_OUTX_L_XL to LSM6DSL_ACC_GYRO_OUTZ_H_XL. */
453 | if ( LSM6DSL_ACC_GYRO_GetRawAccData( (void *)this, regValue ) == MEMS_ERROR )
454 | {
455 | return LSM6DSL_STATUS_ERROR;
456 | }
457 |
458 | /* Format the data. */
459 | pData[0] = ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] );
460 | pData[1] = ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] );
461 | pData[2] = ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] );
462 |
463 | return LSM6DSL_STATUS_OK;
464 | }
465 |
466 | /**
467 | * @brief Read raw data from LSM6DSL Gyroscope
468 | * @param pData the pointer where the gyroscope raw data are stored
469 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
470 | */
471 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_AxesRaw(int16_t *pData)
472 | {
473 | uint8_t regValue[6] = {0, 0, 0, 0, 0, 0};
474 |
475 | /* Read output registers from LSM6DSL_ACC_GYRO_OUTX_L_G to LSM6DSL_ACC_GYRO_OUTZ_H_G. */
476 | if ( LSM6DSL_ACC_GYRO_GetRawGyroData( (void *)this, regValue ) == MEMS_ERROR )
477 | {
478 | return LSM6DSL_STATUS_ERROR;
479 | }
480 |
481 | /* Format the data. */
482 | pData[0] = ( ( ( ( int16_t )regValue[1] ) << 8 ) + ( int16_t )regValue[0] );
483 | pData[1] = ( ( ( ( int16_t )regValue[3] ) << 8 ) + ( int16_t )regValue[2] );
484 | pData[2] = ( ( ( ( int16_t )regValue[5] ) << 8 ) + ( int16_t )regValue[4] );
485 |
486 | return LSM6DSL_STATUS_OK;
487 | }
488 |
489 | /**
490 | * @brief Read LSM6DSL Accelerometer output data rate
491 | * @param odr the pointer to the output data rate
492 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
493 | */
494 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_ODR(float* odr)
495 | {
496 | LSM6DSL_ACC_GYRO_ODR_XL_t odr_low_level;
497 |
498 | if ( LSM6DSL_ACC_GYRO_R_ODR_XL( (void *)this, &odr_low_level ) == MEMS_ERROR )
499 | {
500 | return LSM6DSL_STATUS_ERROR;
501 | }
502 |
503 | switch( odr_low_level )
504 | {
505 | case LSM6DSL_ACC_GYRO_ODR_XL_POWER_DOWN:
506 | *odr = 0.0f;
507 | break;
508 | case LSM6DSL_ACC_GYRO_ODR_XL_13Hz:
509 | *odr = 13.0f;
510 | break;
511 | case LSM6DSL_ACC_GYRO_ODR_XL_26Hz:
512 | *odr = 26.0f;
513 | break;
514 | case LSM6DSL_ACC_GYRO_ODR_XL_52Hz:
515 | *odr = 52.0f;
516 | break;
517 | case LSM6DSL_ACC_GYRO_ODR_XL_104Hz:
518 | *odr = 104.0f;
519 | break;
520 | case LSM6DSL_ACC_GYRO_ODR_XL_208Hz:
521 | *odr = 208.0f;
522 | break;
523 | case LSM6DSL_ACC_GYRO_ODR_XL_416Hz:
524 | *odr = 416.0f;
525 | break;
526 | case LSM6DSL_ACC_GYRO_ODR_XL_833Hz:
527 | *odr = 833.0f;
528 | break;
529 | case LSM6DSL_ACC_GYRO_ODR_XL_1660Hz:
530 | *odr = 1660.0f;
531 | break;
532 | case LSM6DSL_ACC_GYRO_ODR_XL_3330Hz:
533 | *odr = 3330.0f;
534 | break;
535 | case LSM6DSL_ACC_GYRO_ODR_XL_6660Hz:
536 | *odr = 6660.0f;
537 | break;
538 | default:
539 | *odr = -1.0f;
540 | return LSM6DSL_STATUS_ERROR;
541 | }
542 |
543 | return LSM6DSL_STATUS_OK;
544 | }
545 |
546 | /**
547 | * @brief Read LSM6DSL Gyroscope output data rate
548 | * @param odr the pointer to the output data rate
549 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
550 | */
551 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_ODR(float* odr)
552 | {
553 | LSM6DSL_ACC_GYRO_ODR_G_t odr_low_level;
554 |
555 | if ( LSM6DSL_ACC_GYRO_R_ODR_G( (void *)this, &odr_low_level ) == MEMS_ERROR )
556 | {
557 | return LSM6DSL_STATUS_ERROR;
558 | }
559 |
560 | switch( odr_low_level )
561 | {
562 | case LSM6DSL_ACC_GYRO_ODR_G_POWER_DOWN:
563 | *odr = 0.0f;
564 | break;
565 | case LSM6DSL_ACC_GYRO_ODR_G_13Hz:
566 | *odr = 13.0f;
567 | break;
568 | case LSM6DSL_ACC_GYRO_ODR_G_26Hz:
569 | *odr = 26.0f;
570 | break;
571 | case LSM6DSL_ACC_GYRO_ODR_G_52Hz:
572 | *odr = 52.0f;
573 | break;
574 | case LSM6DSL_ACC_GYRO_ODR_G_104Hz:
575 | *odr = 104.0f;
576 | break;
577 | case LSM6DSL_ACC_GYRO_ODR_G_208Hz:
578 | *odr = 208.0f;
579 | break;
580 | case LSM6DSL_ACC_GYRO_ODR_G_416Hz:
581 | *odr = 416.0f;
582 | break;
583 | case LSM6DSL_ACC_GYRO_ODR_G_833Hz:
584 | *odr = 833.0f;
585 | break;
586 | case LSM6DSL_ACC_GYRO_ODR_G_1660Hz:
587 | *odr = 1660.0f;
588 | break;
589 | case LSM6DSL_ACC_GYRO_ODR_G_3330Hz:
590 | *odr = 3330.0f;
591 | break;
592 | case LSM6DSL_ACC_GYRO_ODR_G_6660Hz:
593 | *odr = 6660.0f;
594 | break;
595 | default:
596 | *odr = -1.0f;
597 | return LSM6DSL_STATUS_ERROR;
598 | }
599 |
600 | return LSM6DSL_STATUS_OK;
601 | }
602 |
603 | /**
604 | * @brief Set LSM6DSL Accelerometer output data rate
605 | * @param odr the output data rate to be set
606 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
607 | */
608 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_X_ODR(float odr)
609 | {
610 | if(X_isEnabled == 1)
611 | {
612 | if(Set_X_ODR_When_Enabled(odr) == LSM6DSL_STATUS_ERROR)
613 | {
614 | return LSM6DSL_STATUS_ERROR;
615 | }
616 | }
617 | else
618 | {
619 | if(Set_X_ODR_When_Disabled(odr) == LSM6DSL_STATUS_ERROR)
620 | {
621 | return LSM6DSL_STATUS_ERROR;
622 | }
623 | }
624 |
625 | return LSM6DSL_STATUS_OK;
626 | }
627 |
628 | /**
629 | * @brief Set LSM6DSL Accelerometer output data rate when enabled
630 | * @param odr the output data rate to be set
631 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
632 | */
633 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_X_ODR_When_Enabled(float odr)
634 | {
635 | LSM6DSL_ACC_GYRO_ODR_XL_t new_odr;
636 |
637 | new_odr = ( odr <= 13.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_13Hz
638 | : ( odr <= 26.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_26Hz
639 | : ( odr <= 52.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_52Hz
640 | : ( odr <= 104.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_104Hz
641 | : ( odr <= 208.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_208Hz
642 | : ( odr <= 416.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_416Hz
643 | : ( odr <= 833.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_833Hz
644 | : ( odr <= 1660.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_1660Hz
645 | : ( odr <= 3330.0f ) ? LSM6DSL_ACC_GYRO_ODR_XL_3330Hz
646 | : LSM6DSL_ACC_GYRO_ODR_XL_6660Hz;
647 |
648 | if ( LSM6DSL_ACC_GYRO_W_ODR_XL( (void *)this, new_odr ) == MEMS_ERROR )
649 | {
650 | return LSM6DSL_STATUS_ERROR;
651 | }
652 |
653 | return LSM6DSL_STATUS_OK;
654 | }
655 |
656 | /**
657 | * @brief Set LSM6DSL Accelerometer output data rate when disabled
658 | * @param odr the output data rate to be set
659 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
660 | */
661 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_X_ODR_When_Disabled(float odr)
662 | {
663 | X_Last_ODR = ( odr <= 13.0f ) ? 13.0f
664 | : ( odr <= 26.0f ) ? 26.0f
665 | : ( odr <= 52.0f ) ? 52.0f
666 | : ( odr <= 104.0f ) ? 104.0f
667 | : ( odr <= 208.0f ) ? 208.0f
668 | : ( odr <= 416.0f ) ? 416.0f
669 | : ( odr <= 833.0f ) ? 833.0f
670 | : ( odr <= 1660.0f ) ? 1660.0f
671 | : ( odr <= 3330.0f ) ? 3330.0f
672 | : 6660.0f;
673 |
674 | return LSM6DSL_STATUS_OK;
675 | }
676 |
677 | /**
678 | * @brief Set LSM6DSL Gyroscope output data rate
679 | * @param odr the output data rate to be set
680 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
681 | */
682 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_G_ODR(float odr)
683 | {
684 | if(G_isEnabled == 1)
685 | {
686 | if(Set_G_ODR_When_Enabled(odr) == LSM6DSL_STATUS_ERROR)
687 | {
688 | return LSM6DSL_STATUS_ERROR;
689 | }
690 | }
691 | else
692 | {
693 | if(Set_G_ODR_When_Disabled(odr) == LSM6DSL_STATUS_ERROR)
694 | {
695 | return LSM6DSL_STATUS_ERROR;
696 | }
697 | }
698 |
699 | return LSM6DSL_STATUS_OK;
700 | }
701 |
702 | /**
703 | * @brief Set LSM6DSL Gyroscope output data rate when enabled
704 | * @param odr the output data rate to be set
705 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
706 | */
707 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_G_ODR_When_Enabled(float odr)
708 | {
709 | LSM6DSL_ACC_GYRO_ODR_G_t new_odr;
710 |
711 | new_odr = ( odr <= 13.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_13Hz
712 | : ( odr <= 26.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_26Hz
713 | : ( odr <= 52.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_52Hz
714 | : ( odr <= 104.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_104Hz
715 | : ( odr <= 208.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_208Hz
716 | : ( odr <= 416.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_416Hz
717 | : ( odr <= 833.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_833Hz
718 | : ( odr <= 1660.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_1660Hz
719 | : ( odr <= 3330.0f ) ? LSM6DSL_ACC_GYRO_ODR_G_3330Hz
720 | : LSM6DSL_ACC_GYRO_ODR_G_6660Hz;
721 |
722 | if ( LSM6DSL_ACC_GYRO_W_ODR_G( (void *)this, new_odr ) == MEMS_ERROR )
723 | {
724 | return LSM6DSL_STATUS_ERROR;
725 | }
726 |
727 | return LSM6DSL_STATUS_OK;
728 | }
729 |
730 | /**
731 | * @brief Set LSM6DSL Gyroscope output data rate when disabled
732 | * @param odr the output data rate to be set
733 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
734 | */
735 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_G_ODR_When_Disabled(float odr)
736 | {
737 | G_Last_ODR = ( odr <= 13.0f ) ? 13.0f
738 | : ( odr <= 26.0f ) ? 26.0f
739 | : ( odr <= 52.0f ) ? 52.0f
740 | : ( odr <= 104.0f ) ? 104.0f
741 | : ( odr <= 208.0f ) ? 208.0f
742 | : ( odr <= 416.0f ) ? 416.0f
743 | : ( odr <= 833.0f ) ? 833.0f
744 | : ( odr <= 1660.0f ) ? 1660.0f
745 | : ( odr <= 3330.0f ) ? 3330.0f
746 | : 6660.0f;
747 |
748 | return LSM6DSL_STATUS_OK;
749 | }
750 |
751 | /**
752 | * @brief Read LSM6DSL Accelerometer full scale
753 | * @param fullScale the pointer to the full scale
754 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
755 | */
756 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_X_FS(float* fullScale)
757 | {
758 | LSM6DSL_ACC_GYRO_FS_XL_t fs_low_level;
759 |
760 | if ( LSM6DSL_ACC_GYRO_R_FS_XL( (void *)this, &fs_low_level ) == MEMS_ERROR )
761 | {
762 | return LSM6DSL_STATUS_ERROR;
763 | }
764 |
765 | switch( fs_low_level )
766 | {
767 | case LSM6DSL_ACC_GYRO_FS_XL_2g:
768 | *fullScale = 2.0f;
769 | break;
770 | case LSM6DSL_ACC_GYRO_FS_XL_4g:
771 | *fullScale = 4.0f;
772 | break;
773 | case LSM6DSL_ACC_GYRO_FS_XL_8g:
774 | *fullScale = 8.0f;
775 | break;
776 | case LSM6DSL_ACC_GYRO_FS_XL_16g:
777 | *fullScale = 16.0f;
778 | break;
779 | default:
780 | *fullScale = -1.0f;
781 | return LSM6DSL_STATUS_ERROR;
782 | }
783 |
784 | return LSM6DSL_STATUS_OK;
785 | }
786 |
787 | /**
788 | * @brief Read LSM6DSL Gyroscope full scale
789 | * @param fullScale the pointer to the full scale
790 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
791 | */
792 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_G_FS(float* fullScale)
793 | {
794 | LSM6DSL_ACC_GYRO_FS_G_t fs_low_level;
795 | LSM6DSL_ACC_GYRO_FS_125_t fs_125;
796 |
797 | if ( LSM6DSL_ACC_GYRO_R_FS_125( (void *)this, &fs_125 ) == MEMS_ERROR )
798 | {
799 | return LSM6DSL_STATUS_ERROR;
800 | }
801 | if ( LSM6DSL_ACC_GYRO_R_FS_G( (void *)this, &fs_low_level ) == MEMS_ERROR )
802 | {
803 | return LSM6DSL_STATUS_ERROR;
804 | }
805 |
806 | if ( fs_125 == LSM6DSL_ACC_GYRO_FS_125_ENABLED )
807 | {
808 | *fullScale = 125.0f;
809 | }
810 |
811 | else
812 | {
813 | switch( fs_low_level )
814 | {
815 | case LSM6DSL_ACC_GYRO_FS_G_245dps:
816 | *fullScale = 245.0f;
817 | break;
818 | case LSM6DSL_ACC_GYRO_FS_G_500dps:
819 | *fullScale = 500.0f;
820 | break;
821 | case LSM6DSL_ACC_GYRO_FS_G_1000dps:
822 | *fullScale = 1000.0f;
823 | break;
824 | case LSM6DSL_ACC_GYRO_FS_G_2000dps:
825 | *fullScale = 2000.0f;
826 | break;
827 | default:
828 | *fullScale = -1.0f;
829 | return LSM6DSL_STATUS_ERROR;
830 | }
831 | }
832 |
833 | return LSM6DSL_STATUS_OK;
834 | }
835 |
836 | /**
837 | * @brief Set LSM6DSL Accelerometer full scale
838 | * @param fullScale the full scale to be set
839 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
840 | */
841 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_X_FS(float fullScale)
842 | {
843 | LSM6DSL_ACC_GYRO_FS_XL_t new_fs;
844 |
845 | new_fs = ( fullScale <= 2.0f ) ? LSM6DSL_ACC_GYRO_FS_XL_2g
846 | : ( fullScale <= 4.0f ) ? LSM6DSL_ACC_GYRO_FS_XL_4g
847 | : ( fullScale <= 8.0f ) ? LSM6DSL_ACC_GYRO_FS_XL_8g
848 | : LSM6DSL_ACC_GYRO_FS_XL_16g;
849 |
850 | if ( LSM6DSL_ACC_GYRO_W_FS_XL( (void *)this, new_fs ) == MEMS_ERROR )
851 | {
852 | return LSM6DSL_STATUS_ERROR;
853 | }
854 |
855 | return LSM6DSL_STATUS_OK;
856 | }
857 |
858 | /**
859 | * @brief Set LSM6DSL Gyroscope full scale
860 | * @param fullScale the full scale to be set
861 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
862 | */
863 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_G_FS(float fullScale)
864 | {
865 | LSM6DSL_ACC_GYRO_FS_G_t new_fs;
866 |
867 | if ( fullScale <= 125.0f )
868 | {
869 | if ( LSM6DSL_ACC_GYRO_W_FS_125( (void *)this, LSM6DSL_ACC_GYRO_FS_125_ENABLED ) == MEMS_ERROR )
870 | {
871 | return LSM6DSL_STATUS_ERROR;
872 | }
873 | }
874 | else
875 | {
876 | new_fs = ( fullScale <= 245.0f ) ? LSM6DSL_ACC_GYRO_FS_G_245dps
877 | : ( fullScale <= 500.0f ) ? LSM6DSL_ACC_GYRO_FS_G_500dps
878 | : ( fullScale <= 1000.0f ) ? LSM6DSL_ACC_GYRO_FS_G_1000dps
879 | : LSM6DSL_ACC_GYRO_FS_G_2000dps;
880 |
881 | if ( LSM6DSL_ACC_GYRO_W_FS_125( (void *)this, LSM6DSL_ACC_GYRO_FS_125_DISABLED ) == MEMS_ERROR )
882 | {
883 | return LSM6DSL_STATUS_ERROR;
884 | }
885 | if ( LSM6DSL_ACC_GYRO_W_FS_G( (void *)this, new_fs ) == MEMS_ERROR )
886 | {
887 | return LSM6DSL_STATUS_ERROR;
888 | }
889 | }
890 |
891 | return LSM6DSL_STATUS_OK;
892 | }
893 |
894 | /**
895 | * @brief Enable free fall detection
896 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
897 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
898 | */
899 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Free_Fall_Detection(void)
900 | {
901 | return Enable_Free_Fall_Detection(LSM6DSL_INT1_PIN);
902 | }
903 |
904 | /**
905 | * @brief Enable free fall detection
906 | * @param int_pin the interrupt pin to be used
907 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
908 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
909 | */
910 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Free_Fall_Detection(LSM6DSL_Interrupt_Pin_t int_pin)
911 | {
912 | /* Output Data Rate selection */
913 | if(Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR)
914 | {
915 | return LSM6DSL_STATUS_ERROR;
916 | }
917 |
918 | /* Full scale selection */
919 | if ( LSM6DSL_ACC_GYRO_W_FS_XL( (void *)this, LSM6DSL_ACC_GYRO_FS_XL_2g ) == MEMS_ERROR )
920 | {
921 | return LSM6DSL_STATUS_ERROR;
922 | }
923 |
924 | /* FF_DUR setting */
925 | if ( LSM6DSL_ACC_GYRO_W_FF_Duration( (void *)this, 0x06 ) == MEMS_ERROR )
926 | {
927 | return LSM6DSL_STATUS_ERROR;
928 | }
929 |
930 | /* WAKE_DUR setting */
931 | if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
932 | {
933 | return LSM6DSL_STATUS_ERROR;
934 | }
935 |
936 | /* TIMER_HR setting */
937 | if ( LSM6DSL_ACC_GYRO_W_TIMER_HR( (void *)this, LSM6DSL_ACC_GYRO_TIMER_HR_6_4ms ) == MEMS_ERROR )
938 | {
939 | return LSM6DSL_STATUS_ERROR;
940 | }
941 |
942 | /* SLEEP_DUR setting */
943 | if ( LSM6DSL_ACC_GYRO_W_SLEEP_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
944 | {
945 | return LSM6DSL_STATUS_ERROR;
946 | }
947 |
948 | /* FF_THS setting */
949 | if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, LSM6DSL_ACC_GYRO_FF_THS_312mg ) == MEMS_ERROR )
950 | {
951 | return LSM6DSL_STATUS_ERROR;
952 | }
953 |
954 | /* Enable basic Interrupts */
955 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
956 | {
957 | return LSM6DSL_STATUS_ERROR;
958 | }
959 |
960 | /* Enable free fall event on either INT1 or INT2 pin */
961 | switch (int_pin)
962 | {
963 | case LSM6DSL_INT1_PIN:
964 | if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_FF_ENABLED ) == MEMS_ERROR )
965 | {
966 | return LSM6DSL_STATUS_ERROR;
967 | }
968 | break;
969 |
970 | case LSM6DSL_INT2_PIN:
971 | if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_FF_ENABLED ) == MEMS_ERROR )
972 | {
973 | return LSM6DSL_STATUS_ERROR;
974 | }
975 | break;
976 |
977 | default:
978 | return LSM6DSL_STATUS_ERROR;
979 | }
980 |
981 | return LSM6DSL_STATUS_OK;
982 | }
983 |
984 | /**
985 | * @brief Disable free fall detection
986 | * @param None
987 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
988 | */
989 | LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Free_Fall_Detection(void)
990 | {
991 | /* Disable free fall event on INT1 pin */
992 | if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_FF_DISABLED ) == MEMS_ERROR )
993 | {
994 | return LSM6DSL_STATUS_ERROR;
995 | }
996 |
997 | /* Disable free fall event on INT2 pin */
998 | if ( LSM6DSL_ACC_GYRO_W_FFEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_FF_DISABLED ) == MEMS_ERROR )
999 | {
1000 | return LSM6DSL_STATUS_ERROR;
1001 | }
1002 |
1003 | /* Disable basic Interrupts */
1004 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
1005 | {
1006 | return LSM6DSL_STATUS_ERROR;
1007 | }
1008 |
1009 | /* FF_DUR setting */
1010 | if ( LSM6DSL_ACC_GYRO_W_FF_Duration( (void *)this, 0x00 ) == MEMS_ERROR )
1011 | {
1012 | return LSM6DSL_STATUS_ERROR;
1013 | }
1014 |
1015 | /* FF_THS setting */
1016 | if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, LSM6DSL_ACC_GYRO_FF_THS_156mg ) == MEMS_ERROR )
1017 | {
1018 | return LSM6DSL_STATUS_ERROR;
1019 | }
1020 |
1021 | return LSM6DSL_STATUS_OK;
1022 | }
1023 |
1024 | /**
1025 | * @brief Set the free fall detection threshold for LSM6DSL accelerometer sensor
1026 | * @param thr the threshold to be set
1027 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1028 | */
1029 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Free_Fall_Threshold(uint8_t thr)
1030 | {
1031 |
1032 | if ( LSM6DSL_ACC_GYRO_W_FF_THS( (void *)this, (LSM6DSL_ACC_GYRO_FF_THS_t)thr ) == MEMS_ERROR )
1033 | {
1034 | return LSM6DSL_STATUS_ERROR;
1035 | }
1036 |
1037 | return LSM6DSL_STATUS_OK;
1038 | }
1039 |
1040 | /**
1041 | * @brief Enable the pedometer feature for LSM6DSL accelerometer sensor
1042 | * @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g
1043 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1044 | */
1045 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Pedometer(void)
1046 | {
1047 | /* Output Data Rate selection */
1048 | if( Set_X_ODR(26.0f) == LSM6DSL_STATUS_ERROR )
1049 | {
1050 | return LSM6DSL_STATUS_ERROR;
1051 | }
1052 |
1053 | /* Full scale selection. */
1054 | if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
1055 | {
1056 | return LSM6DSL_STATUS_ERROR;
1057 | }
1058 |
1059 | /* Set pedometer threshold. */
1060 | if ( Set_Pedometer_Threshold(LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH) == LSM6DSL_STATUS_ERROR )
1061 | {
1062 | return LSM6DSL_STATUS_ERROR;
1063 | }
1064 |
1065 | /* Enable embedded functionalities. */
1066 | if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED ) == MEMS_ERROR )
1067 | {
1068 | return LSM6DSL_STATUS_ERROR;
1069 | }
1070 |
1071 | /* Enable pedometer algorithm. */
1072 | if ( LSM6DSL_ACC_GYRO_W_PEDO( (void *)this, LSM6DSL_ACC_GYRO_PEDO_ENABLED ) == MEMS_ERROR )
1073 | {
1074 | return LSM6DSL_STATUS_ERROR;
1075 | }
1076 |
1077 | /* Enable pedometer on INT1. */
1078 | if ( LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1( (void *)this, LSM6DSL_ACC_GYRO_INT1_PEDO_ENABLED ) == MEMS_ERROR )
1079 | {
1080 | return LSM6DSL_STATUS_ERROR;
1081 | }
1082 |
1083 | return LSM6DSL_STATUS_OK;
1084 | }
1085 |
1086 | /**
1087 | * @brief Disable the pedometer feature for LSM6DSL accelerometer sensor
1088 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1089 | */
1090 | LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Pedometer(void)
1091 | {
1092 | /* Disable pedometer on INT1. */
1093 | if ( LSM6DSL_ACC_GYRO_W_STEP_DET_on_INT1( (void *)this, LSM6DSL_ACC_GYRO_INT1_PEDO_DISABLED ) == MEMS_ERROR )
1094 | {
1095 | return LSM6DSL_STATUS_ERROR;
1096 | }
1097 |
1098 | /* Disable pedometer algorithm. */
1099 | if ( LSM6DSL_ACC_GYRO_W_PEDO( (void *)this, LSM6DSL_ACC_GYRO_PEDO_DISABLED ) == MEMS_ERROR )
1100 | {
1101 | return LSM6DSL_STATUS_ERROR;
1102 | }
1103 |
1104 | /* Disable embedded functionalities. */
1105 | if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED ) == MEMS_ERROR )
1106 | {
1107 | return LSM6DSL_STATUS_ERROR;
1108 | }
1109 |
1110 | /* Reset pedometer threshold. */
1111 | if ( Set_Pedometer_Threshold(0x0) == LSM6DSL_STATUS_ERROR )
1112 | {
1113 | return LSM6DSL_STATUS_ERROR;
1114 | }
1115 |
1116 | return LSM6DSL_STATUS_OK;
1117 | }
1118 |
1119 | /**
1120 | * @brief Get the step counter for LSM6DSL accelerometer sensor
1121 | * @param step_count the pointer to the step counter
1122 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1123 | */
1124 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Step_Counter(uint16_t *step_count)
1125 | {
1126 | if ( LSM6DSL_ACC_GYRO_Get_GetStepCounter( (void *)this, ( uint8_t* )step_count ) == MEMS_ERROR )
1127 | {
1128 | return LSM6DSL_STATUS_ERROR;
1129 | }
1130 |
1131 | return LSM6DSL_STATUS_OK;
1132 | }
1133 |
1134 | /**
1135 | * @brief Reset of the step counter for LSM6DSL accelerometer sensor
1136 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1137 | */
1138 | LSM6DSLStatusTypeDef LSM6DSLSensor::Reset_Step_Counter(void)
1139 | {
1140 | if ( LSM6DSL_ACC_GYRO_W_PedoStepReset( (void *)this, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_ENABLED ) == MEMS_ERROR )
1141 | {
1142 | return LSM6DSL_STATUS_ERROR;
1143 | }
1144 |
1145 | delay(10);
1146 |
1147 | if ( LSM6DSL_ACC_GYRO_W_PedoStepReset( (void *)this, LSM6DSL_ACC_GYRO_PEDO_RST_STEP_DISABLED ) == MEMS_ERROR )
1148 | {
1149 | return LSM6DSL_STATUS_ERROR;
1150 | }
1151 |
1152 | return LSM6DSL_STATUS_OK;
1153 | }
1154 |
1155 | /**
1156 | * @brief Set the pedometer threshold for LSM6DSL accelerometer sensor
1157 | * @param thr the threshold to be set
1158 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1159 | */
1160 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Pedometer_Threshold(uint8_t thr)
1161 | {
1162 | if ( LSM6DSL_ACC_GYRO_W_PedoThreshold( (void *)this, thr ) == MEMS_ERROR )
1163 | {
1164 | return LSM6DSL_STATUS_ERROR;
1165 | }
1166 |
1167 | return LSM6DSL_STATUS_OK;
1168 | }
1169 |
1170 | /**
1171 | * @brief Enable the tilt detection for LSM6DSL accelerometer sensor
1172 | * @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g
1173 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1174 | */
1175 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Tilt_Detection(void)
1176 | {
1177 | return Enable_Tilt_Detection(LSM6DSL_INT1_PIN);
1178 | }
1179 |
1180 | /**
1181 | * @brief Enable the tilt detection for LSM6DSL accelerometer sensor
1182 | * @param int_pin the interrupt pin to be used
1183 | * @note This function sets the LSM6DSL accelerometer ODR to 26Hz and the LSM6DSL accelerometer full scale to 2g
1184 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1185 | */
1186 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Tilt_Detection(LSM6DSL_Interrupt_Pin_t int_pin)
1187 | {
1188 | /* Output Data Rate selection */
1189 | if( Set_X_ODR(26.0f) == LSM6DSL_STATUS_ERROR )
1190 | {
1191 | return LSM6DSL_STATUS_ERROR;
1192 | }
1193 |
1194 | /* Full scale selection. */
1195 | if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
1196 | {
1197 | return LSM6DSL_STATUS_ERROR;
1198 | }
1199 |
1200 | /* Enable embedded functionalities */
1201 | if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_ENABLED ) == MEMS_ERROR )
1202 | {
1203 | return LSM6DSL_STATUS_ERROR;
1204 | }
1205 |
1206 | /* Enable tilt calculation. */
1207 | if ( LSM6DSL_ACC_GYRO_W_TILT( (void *)this, LSM6DSL_ACC_GYRO_TILT_ENABLED ) == MEMS_ERROR )
1208 | {
1209 | return LSM6DSL_STATUS_ERROR;
1210 | }
1211 |
1212 | /* Enable tilt detection on either INT1 or INT2 pin */
1213 | switch (int_pin)
1214 | {
1215 | case LSM6DSL_INT1_PIN:
1216 | if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TILT_ENABLED ) == MEMS_ERROR )
1217 | {
1218 | return LSM6DSL_STATUS_ERROR;
1219 | }
1220 | break;
1221 |
1222 | case LSM6DSL_INT2_PIN:
1223 | if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TILT_ENABLED ) == MEMS_ERROR )
1224 | {
1225 | return LSM6DSL_STATUS_ERROR;
1226 | }
1227 | break;
1228 |
1229 | default:
1230 | return LSM6DSL_STATUS_ERROR;
1231 | }
1232 |
1233 | return LSM6DSL_STATUS_OK;
1234 | }
1235 |
1236 | /**
1237 | * @brief Disable the tilt detection for LSM6DSL accelerometer sensor
1238 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1239 | */
1240 | LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Tilt_Detection(void)
1241 | {
1242 | /* Disable tilt event on INT1. */
1243 | if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TILT_DISABLED ) == MEMS_ERROR )
1244 | {
1245 | return LSM6DSL_STATUS_ERROR;
1246 | }
1247 |
1248 | /* Disable tilt event on INT2. */
1249 | if ( LSM6DSL_ACC_GYRO_W_TiltEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TILT_DISABLED ) == MEMS_ERROR )
1250 | {
1251 | return LSM6DSL_STATUS_ERROR;
1252 | }
1253 |
1254 | /* Disable tilt calculation. */
1255 | if ( LSM6DSL_ACC_GYRO_W_TILT( (void *)this, LSM6DSL_ACC_GYRO_TILT_DISABLED ) == MEMS_ERROR )
1256 | {
1257 | return LSM6DSL_STATUS_ERROR;
1258 | }
1259 |
1260 | /* Disable embedded functionalities */
1261 | if ( LSM6DSL_ACC_GYRO_W_FUNC_EN( (void *)this, LSM6DSL_ACC_GYRO_FUNC_EN_DISABLED ) == MEMS_ERROR )
1262 | {
1263 | return LSM6DSL_STATUS_ERROR;
1264 | }
1265 |
1266 | return LSM6DSL_STATUS_OK;
1267 | }
1268 |
1269 | /**
1270 | * @brief Enable the wake up detection for LSM6DSL accelerometer sensor
1271 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
1272 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1273 | */
1274 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Wake_Up_Detection(void)
1275 | {
1276 | return Enable_Wake_Up_Detection(LSM6DSL_INT2_PIN);
1277 | }
1278 |
1279 | /**
1280 | * @brief Enable the wake up detection for LSM6DSL accelerometer sensor
1281 | * @param int_pin the interrupt pin to be used
1282 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
1283 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1284 | */
1285 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Wake_Up_Detection(LSM6DSL_Interrupt_Pin_t int_pin)
1286 | {
1287 | /* Output Data Rate selection */
1288 | if( Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR )
1289 | {
1290 | return LSM6DSL_STATUS_ERROR;
1291 | }
1292 |
1293 | /* Full scale selection. */
1294 | if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
1295 | {
1296 | return LSM6DSL_STATUS_ERROR;
1297 | }
1298 |
1299 | /* WAKE_DUR setting */
1300 | if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
1301 | {
1302 | return LSM6DSL_STATUS_ERROR;
1303 | }
1304 |
1305 | /* Set wake up threshold. */
1306 | if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, 0x02 ) == MEMS_ERROR )
1307 | {
1308 | return LSM6DSL_STATUS_ERROR;
1309 | }
1310 |
1311 | /* Enable basic Interrupts */
1312 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
1313 | {
1314 | return LSM6DSL_STATUS_ERROR;
1315 | }
1316 |
1317 | /* Enable wake up detection on either INT1 or INT2 pin */
1318 | switch (int_pin)
1319 | {
1320 | case LSM6DSL_INT1_PIN:
1321 | if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_WU_ENABLED ) == MEMS_ERROR )
1322 | {
1323 | return LSM6DSL_STATUS_ERROR;
1324 | }
1325 | break;
1326 |
1327 | case LSM6DSL_INT2_PIN:
1328 | if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_WU_ENABLED ) == MEMS_ERROR )
1329 | {
1330 | return LSM6DSL_STATUS_ERROR;
1331 | }
1332 | break;
1333 |
1334 | default:
1335 | return LSM6DSL_STATUS_ERROR;
1336 | }
1337 |
1338 | return LSM6DSL_STATUS_OK;
1339 | }
1340 |
1341 | /**
1342 | * @brief Disable the wake up detection for LSM6DSL accelerometer sensor
1343 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1344 | */
1345 | LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Wake_Up_Detection(void)
1346 | {
1347 | /* Disable wake up event on INT1 */
1348 | if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_WU_DISABLED ) == MEMS_ERROR )
1349 | {
1350 | return LSM6DSL_STATUS_ERROR;
1351 | }
1352 |
1353 | /* Disable wake up event on INT2 */
1354 | if ( LSM6DSL_ACC_GYRO_W_WUEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_WU_DISABLED ) == MEMS_ERROR )
1355 | {
1356 | return LSM6DSL_STATUS_ERROR;
1357 | }
1358 |
1359 | /* Disable basic Interrupts */
1360 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
1361 | {
1362 | return LSM6DSL_STATUS_ERROR;
1363 | }
1364 |
1365 | /* WU_DUR setting */
1366 | if ( LSM6DSL_ACC_GYRO_W_WAKE_DUR( (void *)this, 0x00 ) == MEMS_ERROR )
1367 | {
1368 | return LSM6DSL_STATUS_ERROR;
1369 | }
1370 |
1371 | /* WU_THS setting */
1372 | if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, 0x00 ) == MEMS_ERROR )
1373 | {
1374 | return LSM6DSL_STATUS_ERROR;
1375 | }
1376 |
1377 | return LSM6DSL_STATUS_OK;
1378 | }
1379 |
1380 | /**
1381 | * @brief Set the wake up threshold for LSM6DSL accelerometer sensor
1382 | * @param thr the threshold to be set
1383 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1384 | */
1385 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Wake_Up_Threshold(uint8_t thr)
1386 | {
1387 | if ( LSM6DSL_ACC_GYRO_W_WK_THS( (void *)this, thr ) == MEMS_ERROR )
1388 | {
1389 | return LSM6DSL_STATUS_ERROR;
1390 | }
1391 |
1392 | return LSM6DSL_STATUS_OK;
1393 | }
1394 |
1395 | /**
1396 | * @brief Enable the single tap detection for LSM6DSL accelerometer sensor
1397 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
1398 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1399 | */
1400 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Single_Tap_Detection(void)
1401 | {
1402 | return Enable_Single_Tap_Detection(LSM6DSL_INT1_PIN);
1403 | }
1404 |
1405 | /**
1406 | * @brief Enable the single tap detection for LSM6DSL accelerometer sensor
1407 | * @param int_pin the interrupt pin to be used
1408 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
1409 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1410 | */
1411 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Single_Tap_Detection(LSM6DSL_Interrupt_Pin_t int_pin)
1412 | {
1413 | /* Output Data Rate selection */
1414 | if( Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR )
1415 | {
1416 | return LSM6DSL_STATUS_ERROR;
1417 | }
1418 |
1419 | /* Full scale selection. */
1420 | if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
1421 | {
1422 | return LSM6DSL_STATUS_ERROR;
1423 | }
1424 |
1425 | /* Enable X direction in tap recognition. */
1426 | if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_ENABLED ) == MEMS_ERROR )
1427 | {
1428 | return LSM6DSL_STATUS_ERROR;
1429 | }
1430 |
1431 | /* Enable Y direction in tap recognition. */
1432 | if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_ENABLED ) == MEMS_ERROR )
1433 | {
1434 | return LSM6DSL_STATUS_ERROR;
1435 | }
1436 |
1437 | /* Enable Z direction in tap recognition. */
1438 | if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_ENABLED ) == MEMS_ERROR )
1439 | {
1440 | return LSM6DSL_STATUS_ERROR;
1441 | }
1442 |
1443 | /* Set tap threshold. */
1444 | if ( Set_Tap_Threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == LSM6DSL_STATUS_ERROR )
1445 | {
1446 | return LSM6DSL_STATUS_ERROR;
1447 | }
1448 |
1449 | /* Set tap shock time window. */
1450 | if ( Set_Tap_Shock_Time( LSM6DSL_TAP_SHOCK_TIME_MID_HIGH ) == LSM6DSL_STATUS_ERROR )
1451 | {
1452 | return LSM6DSL_STATUS_ERROR;
1453 | }
1454 |
1455 | /* Set tap quiet time window. */
1456 | if ( Set_Tap_Quiet_Time( LSM6DSL_TAP_QUIET_TIME_MID_LOW ) == LSM6DSL_STATUS_ERROR )
1457 | {
1458 | return LSM6DSL_STATUS_ERROR;
1459 | }
1460 |
1461 | /* _NOTE_: Tap duration time window - don't care for single tap. */
1462 |
1463 | /* _NOTE_: Single/Double Tap event - don't care of this flag for single tap. */
1464 |
1465 | /* Enable basic Interrupts */
1466 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
1467 | {
1468 | return LSM6DSL_STATUS_ERROR;
1469 | }
1470 |
1471 | /* Enable single tap on either INT1 or INT2 pin */
1472 | switch (int_pin)
1473 | {
1474 | case LSM6DSL_INT1_PIN:
1475 | if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_ENABLED ) == MEMS_ERROR )
1476 | {
1477 | return LSM6DSL_STATUS_ERROR;
1478 | }
1479 | break;
1480 |
1481 | case LSM6DSL_INT2_PIN:
1482 | if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_ENABLED ) == MEMS_ERROR )
1483 | {
1484 | return LSM6DSL_STATUS_ERROR;
1485 | }
1486 | break;
1487 |
1488 | default:
1489 | return LSM6DSL_STATUS_ERROR;
1490 | }
1491 |
1492 | return LSM6DSL_STATUS_OK;
1493 | }
1494 |
1495 | /**
1496 | * @brief Disable the single tap detection for LSM6DSL accelerometer sensor
1497 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1498 | */
1499 | LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Single_Tap_Detection(void)
1500 | {
1501 | /* Disable single tap interrupt on INT1 pin. */
1502 | if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_DISABLED ) == MEMS_ERROR )
1503 | {
1504 | return LSM6DSL_STATUS_ERROR;
1505 | }
1506 |
1507 | /* Disable single tap interrupt on INT2 pin. */
1508 | if ( LSM6DSL_ACC_GYRO_W_SingleTapOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_DISABLED ) == MEMS_ERROR )
1509 | {
1510 | return LSM6DSL_STATUS_ERROR;
1511 | }
1512 |
1513 | /* Disable basic Interrupts */
1514 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
1515 | {
1516 | return LSM6DSL_STATUS_ERROR;
1517 | }
1518 |
1519 | /* Reset tap threshold. */
1520 | if ( Set_Tap_Threshold( 0x0 ) == LSM6DSL_STATUS_ERROR )
1521 | {
1522 | return LSM6DSL_STATUS_ERROR;
1523 | }
1524 |
1525 | /* Reset tap shock time window. */
1526 | if ( Set_Tap_Shock_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
1527 | {
1528 | return LSM6DSL_STATUS_ERROR;
1529 | }
1530 |
1531 | /* Reset tap quiet time window. */
1532 | if ( Set_Tap_Quiet_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
1533 | {
1534 | return LSM6DSL_STATUS_ERROR;
1535 | }
1536 |
1537 | /* _NOTE_: Tap duration time window - don't care for single tap. */
1538 |
1539 | /* _NOTE_: Single/Double Tap event - don't care of this flag for single tap. */
1540 |
1541 | /* Disable Z direction in tap recognition. */
1542 | if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_DISABLED ) == MEMS_ERROR )
1543 | {
1544 | return LSM6DSL_STATUS_ERROR;
1545 | }
1546 |
1547 | /* Disable Y direction in tap recognition. */
1548 | if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_DISABLED ) == MEMS_ERROR )
1549 | {
1550 | return LSM6DSL_STATUS_ERROR;
1551 | }
1552 |
1553 | /* Disable X direction in tap recognition. */
1554 | if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_DISABLED ) == MEMS_ERROR )
1555 | {
1556 | return LSM6DSL_STATUS_ERROR;
1557 | }
1558 |
1559 | return LSM6DSL_STATUS_OK;
1560 | }
1561 |
1562 | /**
1563 | * @brief Enable the double tap detection for LSM6DSL accelerometer sensor
1564 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
1565 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1566 | */
1567 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Double_Tap_Detection(void)
1568 | {
1569 | return Enable_Double_Tap_Detection(LSM6DSL_INT1_PIN);
1570 | }
1571 |
1572 | /**
1573 | * @brief Enable the double tap detection for LSM6DSL accelerometer sensor
1574 | * @param int_pin the interrupt pin to be used
1575 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
1576 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1577 | */
1578 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_Double_Tap_Detection(LSM6DSL_Interrupt_Pin_t int_pin)
1579 | {
1580 | /* Output Data Rate selection */
1581 | if( Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR )
1582 | {
1583 | return LSM6DSL_STATUS_ERROR;
1584 | }
1585 |
1586 | /* Full scale selection. */
1587 | if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
1588 | {
1589 | return LSM6DSL_STATUS_ERROR;
1590 | }
1591 |
1592 | /* Enable X direction in tap recognition. */
1593 | if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_ENABLED ) == MEMS_ERROR )
1594 | {
1595 | return LSM6DSL_STATUS_ERROR;
1596 | }
1597 |
1598 | /* Enable Y direction in tap recognition. */
1599 | if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_ENABLED ) == MEMS_ERROR )
1600 | {
1601 | return LSM6DSL_STATUS_ERROR;
1602 | }
1603 |
1604 | /* Enable Z direction in tap recognition. */
1605 | if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_ENABLED ) == MEMS_ERROR )
1606 | {
1607 | return LSM6DSL_STATUS_ERROR;
1608 | }
1609 |
1610 | /* Set tap threshold. */
1611 | if ( Set_Tap_Threshold( LSM6DSL_TAP_THRESHOLD_MID_LOW ) == LSM6DSL_STATUS_ERROR )
1612 | {
1613 | return LSM6DSL_STATUS_ERROR;
1614 | }
1615 |
1616 | /* Set tap shock time window. */
1617 | if ( Set_Tap_Shock_Time( LSM6DSL_TAP_SHOCK_TIME_HIGH ) == LSM6DSL_STATUS_ERROR )
1618 | {
1619 | return LSM6DSL_STATUS_ERROR;
1620 | }
1621 |
1622 | /* Set tap quiet time window. */
1623 | if ( Set_Tap_Quiet_Time( LSM6DSL_TAP_QUIET_TIME_HIGH ) == LSM6DSL_STATUS_ERROR )
1624 | {
1625 | return LSM6DSL_STATUS_ERROR;
1626 | }
1627 |
1628 | /* Set tap duration time window. */
1629 | if ( Set_Tap_Duration_Time( LSM6DSL_TAP_DURATION_TIME_MID ) == LSM6DSL_STATUS_ERROR )
1630 | {
1631 | return LSM6DSL_STATUS_ERROR;
1632 | }
1633 |
1634 | /* Single and double tap enabled. */
1635 | if ( LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV( (void *)this, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_DOUBLE_TAP ) == MEMS_ERROR )
1636 | {
1637 | return LSM6DSL_STATUS_ERROR;
1638 | }
1639 |
1640 | /* Enable basic Interrupts */
1641 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
1642 | {
1643 | return LSM6DSL_STATUS_ERROR;
1644 | }
1645 |
1646 | /* Enable double tap on either INT1 or INT2 pin */
1647 | switch (int_pin)
1648 | {
1649 | case LSM6DSL_INT1_PIN:
1650 | if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TAP_ENABLED ) == MEMS_ERROR )
1651 | {
1652 | return LSM6DSL_STATUS_ERROR;
1653 | }
1654 | break;
1655 |
1656 | case LSM6DSL_INT2_PIN:
1657 | if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TAP_ENABLED ) == MEMS_ERROR )
1658 | {
1659 | return LSM6DSL_STATUS_ERROR;
1660 | }
1661 | break;
1662 |
1663 | default:
1664 | return LSM6DSL_STATUS_ERROR;
1665 | }
1666 |
1667 | return LSM6DSL_STATUS_OK;
1668 | }
1669 |
1670 | /**
1671 | * @brief Disable the double tap detection for LSM6DSL accelerometer sensor
1672 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1673 | */
1674 | LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_Double_Tap_Detection(void)
1675 | {
1676 | /* Disable double tap interrupt on INT1 pin. */
1677 | if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_TAP_DISABLED ) == MEMS_ERROR )
1678 | {
1679 | return LSM6DSL_STATUS_ERROR;
1680 | }
1681 |
1682 | /* Disable double tap interrupt on INT2 pin. */
1683 | if ( LSM6DSL_ACC_GYRO_W_TapEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_TAP_DISABLED ) == MEMS_ERROR )
1684 | {
1685 | return LSM6DSL_STATUS_ERROR;
1686 | }
1687 |
1688 | /* Disable basic Interrupts */
1689 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
1690 | {
1691 | return LSM6DSL_STATUS_ERROR;
1692 | }
1693 |
1694 | /* Reset tap threshold. */
1695 | if ( Set_Tap_Threshold( 0x0 ) == LSM6DSL_STATUS_ERROR )
1696 | {
1697 | return LSM6DSL_STATUS_ERROR;
1698 | }
1699 |
1700 | /* Reset tap shock time window. */
1701 | if ( Set_Tap_Shock_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
1702 | {
1703 | return LSM6DSL_STATUS_ERROR;
1704 | }
1705 |
1706 | /* Reset tap quiet time window. */
1707 | if ( Set_Tap_Quiet_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
1708 | {
1709 | return LSM6DSL_STATUS_ERROR;
1710 | }
1711 |
1712 | /* Reset tap duration time window. */
1713 | if ( Set_Tap_Duration_Time( 0x0 ) == LSM6DSL_STATUS_ERROR )
1714 | {
1715 | return LSM6DSL_STATUS_ERROR;
1716 | }
1717 |
1718 | /* Only single tap enabled. */
1719 | if ( LSM6DSL_ACC_GYRO_W_SINGLE_DOUBLE_TAP_EV( (void *)this, LSM6DSL_ACC_GYRO_SINGLE_DOUBLE_TAP_SINGLE_TAP ) == MEMS_ERROR )
1720 | {
1721 | return LSM6DSL_STATUS_ERROR;
1722 | }
1723 |
1724 | /* Disable Z direction in tap recognition. */
1725 | if ( LSM6DSL_ACC_GYRO_W_TAP_Z_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Z_EN_DISABLED ) == MEMS_ERROR )
1726 | {
1727 | return LSM6DSL_STATUS_ERROR;
1728 | }
1729 |
1730 | /* Disable Y direction in tap recognition. */
1731 | if ( LSM6DSL_ACC_GYRO_W_TAP_Y_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_Y_EN_DISABLED ) == MEMS_ERROR )
1732 | {
1733 | return LSM6DSL_STATUS_ERROR;
1734 | }
1735 |
1736 | /* Disable X direction in tap recognition. */
1737 | if ( LSM6DSL_ACC_GYRO_W_TAP_X_EN( (void *)this, LSM6DSL_ACC_GYRO_TAP_X_EN_DISABLED ) == MEMS_ERROR )
1738 | {
1739 | return LSM6DSL_STATUS_ERROR;
1740 | }
1741 |
1742 | return LSM6DSL_STATUS_OK;
1743 | }
1744 |
1745 | /**
1746 | * @brief Set the tap threshold for LSM6DSL accelerometer sensor
1747 | * @param thr the threshold to be set
1748 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1749 | */
1750 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Tap_Threshold(uint8_t thr)
1751 | {
1752 | if ( LSM6DSL_ACC_GYRO_W_TAP_THS( (void *)this, thr ) == MEMS_ERROR )
1753 | {
1754 | return LSM6DSL_STATUS_ERROR;
1755 | }
1756 |
1757 | return LSM6DSL_STATUS_OK;
1758 | }
1759 |
1760 | /**
1761 | * @brief Set the tap shock time window for LSM6DSL accelerometer sensor
1762 | * @param time the shock time window to be set
1763 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1764 | */
1765 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Tap_Shock_Time(uint8_t time)
1766 | {
1767 | if ( LSM6DSL_ACC_GYRO_W_SHOCK_Duration( (void *)this, time ) == MEMS_ERROR )
1768 | {
1769 | return LSM6DSL_STATUS_ERROR;
1770 | }
1771 |
1772 | return LSM6DSL_STATUS_OK;
1773 | }
1774 |
1775 | /**
1776 | * @brief Set the tap quiet time window for LSM6DSL accelerometer sensor
1777 | * @param time the quiet time window to be set
1778 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1779 | */
1780 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Tap_Quiet_Time(uint8_t time)
1781 | {
1782 | if ( LSM6DSL_ACC_GYRO_W_QUIET_Duration( (void *)this, time ) == MEMS_ERROR )
1783 | {
1784 | return LSM6DSL_STATUS_ERROR;
1785 | }
1786 |
1787 | return LSM6DSL_STATUS_OK;
1788 | }
1789 |
1790 | /**
1791 | * @brief Set the tap duration of the time window for LSM6DSL accelerometer sensor
1792 | * @param time the duration of the time window to be set
1793 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1794 | */
1795 | LSM6DSLStatusTypeDef LSM6DSLSensor::Set_Tap_Duration_Time(uint8_t time)
1796 | {
1797 | if ( LSM6DSL_ACC_GYRO_W_DUR( (void *)this, time ) == MEMS_ERROR )
1798 | {
1799 | return LSM6DSL_STATUS_ERROR;
1800 | }
1801 |
1802 | return LSM6DSL_STATUS_OK;
1803 | }
1804 |
1805 | /**
1806 | * @brief Enable the 6D orientation detection for LSM6DSL accelerometer sensor
1807 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
1808 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1809 | */
1810 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_6D_Orientation(void)
1811 | {
1812 | return Enable_6D_Orientation(LSM6DSL_INT1_PIN);
1813 | }
1814 |
1815 | /**
1816 | * @brief Enable the 6D orientation detection for LSM6DSL accelerometer sensor
1817 | * @param int_pin the interrupt pin to be used
1818 | * @note This function sets the LSM6DSL accelerometer ODR to 416Hz and the LSM6DSL accelerometer full scale to 2g
1819 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1820 | */
1821 | LSM6DSLStatusTypeDef LSM6DSLSensor::Enable_6D_Orientation(LSM6DSL_Interrupt_Pin_t int_pin)
1822 | {
1823 | /* Output Data Rate selection */
1824 | if( Set_X_ODR(416.0f) == LSM6DSL_STATUS_ERROR )
1825 | {
1826 | return LSM6DSL_STATUS_ERROR;
1827 | }
1828 |
1829 | /* Full scale selection. */
1830 | if( Set_X_FS(2.0f) == LSM6DSL_STATUS_ERROR )
1831 | {
1832 | return LSM6DSL_STATUS_ERROR;
1833 | }
1834 |
1835 | /* Set 6D threshold. */
1836 | if ( LSM6DSL_ACC_GYRO_W_SIXD_THS( (void *)this, LSM6DSL_ACC_GYRO_SIXD_THS_60_degree ) == MEMS_ERROR )
1837 | {
1838 | return LSM6DSL_STATUS_ERROR;
1839 | }
1840 |
1841 | /* Enable basic Interrupts */
1842 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_ENABLED ) == MEMS_ERROR )
1843 | {
1844 | return LSM6DSL_STATUS_ERROR;
1845 | }
1846 |
1847 | /* Enable 6D orientation on either INT1 or INT2 pin */
1848 | switch (int_pin)
1849 | {
1850 | case LSM6DSL_INT1_PIN:
1851 | if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_6D_ENABLED ) == MEMS_ERROR )
1852 | {
1853 | return LSM6DSL_STATUS_ERROR;
1854 | }
1855 | break;
1856 |
1857 | case LSM6DSL_INT2_PIN:
1858 | if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_6D_ENABLED ) == MEMS_ERROR )
1859 | {
1860 | return LSM6DSL_STATUS_ERROR;
1861 | }
1862 | break;
1863 |
1864 | default:
1865 | return LSM6DSL_STATUS_ERROR;
1866 | }
1867 |
1868 | return LSM6DSL_STATUS_OK;
1869 | }
1870 |
1871 | /**
1872 | * @brief Disable the 6D orientation detection for LSM6DSL accelerometer sensor
1873 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1874 | */
1875 | LSM6DSLStatusTypeDef LSM6DSLSensor::Disable_6D_Orientation(void)
1876 | {
1877 | /* Disable 6D orientation interrupt on INT1 pin. */
1878 | if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt1( (void *)this, LSM6DSL_ACC_GYRO_INT1_6D_DISABLED ) == MEMS_ERROR )
1879 | {
1880 | return LSM6DSL_STATUS_ERROR;
1881 | }
1882 |
1883 | /* Disable 6D orientation interrupt on INT2 pin. */
1884 | if ( LSM6DSL_ACC_GYRO_W_6DEvOnInt2( (void *)this, LSM6DSL_ACC_GYRO_INT2_6D_DISABLED ) == MEMS_ERROR )
1885 | {
1886 | return LSM6DSL_STATUS_ERROR;
1887 | }
1888 |
1889 | /* Disable basic Interrupts */
1890 | if ( LSM6DSL_ACC_GYRO_W_BASIC_INT( (void *)this, LSM6DSL_ACC_GYRO_BASIC_INT_DISABLED ) == MEMS_ERROR )
1891 | {
1892 | return LSM6DSL_STATUS_ERROR;
1893 | }
1894 |
1895 | /* Reset 6D threshold. */
1896 | if ( LSM6DSL_ACC_GYRO_W_SIXD_THS( (void *)this, LSM6DSL_ACC_GYRO_SIXD_THS_80_degree ) == MEMS_ERROR )
1897 | {
1898 | return LSM6DSL_STATUS_ERROR;
1899 | }
1900 |
1901 | return LSM6DSL_STATUS_OK;
1902 | }
1903 |
1904 | /**
1905 | * @brief Get the 6D orientation XL axis for LSM6DSL accelerometer sensor
1906 | * @param xl the pointer to the 6D orientation XL axis
1907 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1908 | */
1909 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_XL(uint8_t *xl)
1910 | {
1911 | LSM6DSL_ACC_GYRO_DSD_XL_t xl_raw;
1912 |
1913 | if ( LSM6DSL_ACC_GYRO_R_DSD_XL( (void *)this, &xl_raw ) == MEMS_ERROR )
1914 | {
1915 | return LSM6DSL_STATUS_ERROR;
1916 | }
1917 |
1918 | switch( xl_raw )
1919 | {
1920 | case LSM6DSL_ACC_GYRO_DSD_XL_DETECTED:
1921 | *xl = 1;
1922 | break;
1923 | case LSM6DSL_ACC_GYRO_DSD_XL_NOT_DETECTED:
1924 | *xl = 0;
1925 | break;
1926 | default:
1927 | return LSM6DSL_STATUS_ERROR;
1928 | }
1929 |
1930 | return LSM6DSL_STATUS_OK;
1931 | }
1932 |
1933 | /**
1934 | * @brief Get the 6D orientation XH axis for LSM6DSL accelerometer sensor
1935 | * @param xh the pointer to the 6D orientation XH axis
1936 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1937 | */
1938 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_XH(uint8_t *xh)
1939 | {
1940 | LSM6DSL_ACC_GYRO_DSD_XH_t xh_raw;
1941 |
1942 | if ( LSM6DSL_ACC_GYRO_R_DSD_XH( (void *)this, &xh_raw ) == MEMS_ERROR )
1943 | {
1944 | return LSM6DSL_STATUS_ERROR;
1945 | }
1946 |
1947 | switch( xh_raw )
1948 | {
1949 | case LSM6DSL_ACC_GYRO_DSD_XH_DETECTED:
1950 | *xh = 1;
1951 | break;
1952 | case LSM6DSL_ACC_GYRO_DSD_XH_NOT_DETECTED:
1953 | *xh = 0;
1954 | break;
1955 | default:
1956 | return LSM6DSL_STATUS_ERROR;
1957 | }
1958 |
1959 | return LSM6DSL_STATUS_OK;
1960 | }
1961 |
1962 | /**
1963 | * @brief Get the 6D orientation YL axis for LSM6DSL accelerometer sensor
1964 | * @param yl the pointer to the 6D orientation YL axis
1965 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1966 | */
1967 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_YL(uint8_t *yl)
1968 | {
1969 | LSM6DSL_ACC_GYRO_DSD_YL_t yl_raw;
1970 |
1971 | if ( LSM6DSL_ACC_GYRO_R_DSD_YL( (void *)this, &yl_raw ) == MEMS_ERROR )
1972 | {
1973 | return LSM6DSL_STATUS_ERROR;
1974 | }
1975 |
1976 | switch( yl_raw )
1977 | {
1978 | case LSM6DSL_ACC_GYRO_DSD_YL_DETECTED:
1979 | *yl = 1;
1980 | break;
1981 | case LSM6DSL_ACC_GYRO_DSD_YL_NOT_DETECTED:
1982 | *yl = 0;
1983 | break;
1984 | default:
1985 | return LSM6DSL_STATUS_ERROR;
1986 | }
1987 |
1988 | return LSM6DSL_STATUS_OK;
1989 | }
1990 |
1991 | /**
1992 | * @brief Get the 6D orientation YH axis for LSM6DSL accelerometer sensor
1993 | * @param yh the pointer to the 6D orientation YH axis
1994 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
1995 | */
1996 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_YH(uint8_t *yh)
1997 | {
1998 | LSM6DSL_ACC_GYRO_DSD_YH_t yh_raw;
1999 |
2000 | if ( LSM6DSL_ACC_GYRO_R_DSD_YH( (void *)this, &yh_raw ) == MEMS_ERROR )
2001 | {
2002 | return LSM6DSL_STATUS_ERROR;
2003 | }
2004 |
2005 | switch( yh_raw )
2006 | {
2007 | case LSM6DSL_ACC_GYRO_DSD_YH_DETECTED:
2008 | *yh = 1;
2009 | break;
2010 | case LSM6DSL_ACC_GYRO_DSD_YH_NOT_DETECTED:
2011 | *yh = 0;
2012 | break;
2013 | default:
2014 | return LSM6DSL_STATUS_ERROR;
2015 | }
2016 |
2017 | return LSM6DSL_STATUS_OK;
2018 | }
2019 |
2020 | /**
2021 | * @brief Get the 6D orientation ZL axis for LSM6DSL accelerometer sensor
2022 | * @param zl the pointer to the 6D orientation ZL axis
2023 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
2024 | */
2025 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_ZL(uint8_t *zl)
2026 | {
2027 | LSM6DSL_ACC_GYRO_DSD_ZL_t zl_raw;
2028 |
2029 | if ( LSM6DSL_ACC_GYRO_R_DSD_ZL( (void *)this, &zl_raw ) == MEMS_ERROR )
2030 | {
2031 | return LSM6DSL_STATUS_ERROR;
2032 | }
2033 |
2034 | switch( zl_raw )
2035 | {
2036 | case LSM6DSL_ACC_GYRO_DSD_ZL_DETECTED:
2037 | *zl = 1;
2038 | break;
2039 | case LSM6DSL_ACC_GYRO_DSD_ZL_NOT_DETECTED:
2040 | *zl = 0;
2041 | break;
2042 | default:
2043 | return LSM6DSL_STATUS_ERROR;
2044 | }
2045 |
2046 | return LSM6DSL_STATUS_OK;
2047 | }
2048 |
2049 | /**
2050 | * @brief Get the 6D orientation ZH axis for LSM6DSL accelerometer sensor
2051 | * @param zh the pointer to the 6D orientation ZH axis
2052 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
2053 | */
2054 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_6D_Orientation_ZH(uint8_t *zh)
2055 | {
2056 | LSM6DSL_ACC_GYRO_DSD_ZH_t zh_raw;
2057 |
2058 | if ( LSM6DSL_ACC_GYRO_R_DSD_ZH( (void *)this, &zh_raw ) == MEMS_ERROR )
2059 | {
2060 | return LSM6DSL_STATUS_ERROR;
2061 | }
2062 |
2063 | switch( zh_raw )
2064 | {
2065 | case LSM6DSL_ACC_GYRO_DSD_ZH_DETECTED:
2066 | *zh = 1;
2067 | break;
2068 | case LSM6DSL_ACC_GYRO_DSD_ZH_NOT_DETECTED:
2069 | *zh = 0;
2070 | break;
2071 | default:
2072 | return LSM6DSL_STATUS_ERROR;
2073 | }
2074 |
2075 | return LSM6DSL_STATUS_OK;
2076 | }
2077 |
2078 | /**
2079 | * @brief Get the status of all hardware events for LSM6DSL accelerometer sensor
2080 | * @param status the pointer to the status of all hardware events
2081 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
2082 | */
2083 | LSM6DSLStatusTypeDef LSM6DSLSensor::Get_Event_Status( LSM6DSL_Event_Status_t *status )
2084 | {
2085 | uint8_t Wake_Up_Src = 0, Tap_Src = 0, D6D_Src = 0, Func_Src = 0, Md1_Cfg = 0, Md2_Cfg = 0, Int1_Ctrl = 0;
2086 |
2087 | memset((void *)status, 0x0, sizeof(LSM6DSL_Event_Status_t));
2088 |
2089 | if(ReadReg(LSM6DSL_ACC_GYRO_WAKE_UP_SRC, &Wake_Up_Src ) == LSM6DSL_STATUS_ERROR )
2090 | {
2091 | return LSM6DSL_STATUS_ERROR;
2092 | }
2093 |
2094 | if(ReadReg(LSM6DSL_ACC_GYRO_TAP_SRC, &Tap_Src ) == LSM6DSL_STATUS_ERROR )
2095 | {
2096 | return LSM6DSL_STATUS_ERROR;
2097 | }
2098 |
2099 | if(ReadReg(LSM6DSL_ACC_GYRO_D6D_SRC, &D6D_Src ) == LSM6DSL_STATUS_ERROR )
2100 | {
2101 | return LSM6DSL_STATUS_ERROR;
2102 | }
2103 |
2104 | if(ReadReg(LSM6DSL_ACC_GYRO_FUNC_SRC, &Func_Src ) == LSM6DSL_STATUS_ERROR )
2105 | {
2106 | return LSM6DSL_STATUS_ERROR;
2107 | }
2108 |
2109 | if(ReadReg(LSM6DSL_ACC_GYRO_MD1_CFG, &Md1_Cfg ) == LSM6DSL_STATUS_ERROR )
2110 | {
2111 | return LSM6DSL_STATUS_ERROR;
2112 | }
2113 |
2114 | if(ReadReg(LSM6DSL_ACC_GYRO_MD2_CFG, &Md2_Cfg ) == LSM6DSL_STATUS_ERROR )
2115 | {
2116 | return LSM6DSL_STATUS_ERROR;
2117 | }
2118 |
2119 | if(ReadReg(LSM6DSL_ACC_GYRO_INT1_CTRL, &Int1_Ctrl ) == LSM6DSL_STATUS_ERROR )
2120 | {
2121 | return LSM6DSL_STATUS_ERROR;
2122 | }
2123 |
2124 | if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_FF_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_FF_MASK))
2125 | {
2126 | if((Wake_Up_Src & LSM6DSL_ACC_GYRO_FF_EV_STATUS_MASK))
2127 | {
2128 | status->FreeFallStatus = 1;
2129 | }
2130 | }
2131 |
2132 | if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_WU_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_WU_MASK))
2133 | {
2134 | if((Wake_Up_Src & LSM6DSL_ACC_GYRO_WU_EV_STATUS_MASK))
2135 | {
2136 | status->WakeUpStatus = 1;
2137 | }
2138 | }
2139 |
2140 | if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_SINGLE_TAP_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_SINGLE_TAP_MASK))
2141 | {
2142 | if((Tap_Src & LSM6DSL_ACC_GYRO_SINGLE_TAP_EV_STATUS_MASK))
2143 | {
2144 | status->TapStatus = 1;
2145 | }
2146 | }
2147 |
2148 | if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_TAP_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_TAP_MASK))
2149 | {
2150 | if((Tap_Src & LSM6DSL_ACC_GYRO_DOUBLE_TAP_EV_STATUS_MASK))
2151 | {
2152 | status->DoubleTapStatus = 1;
2153 | }
2154 | }
2155 |
2156 | if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_6D_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_6D_MASK))
2157 | {
2158 | if((D6D_Src & LSM6DSL_ACC_GYRO_D6D_EV_STATUS_MASK))
2159 | {
2160 | status->D6DOrientationStatus = 1;
2161 | }
2162 | }
2163 |
2164 | if((Int1_Ctrl & LSM6DSL_ACC_GYRO_INT1_PEDO_MASK))
2165 | {
2166 | if((Func_Src & LSM6DSL_ACC_GYRO_PEDO_EV_STATUS_MASK))
2167 | {
2168 | status->StepStatus = 1;
2169 | }
2170 | }
2171 |
2172 | if((Md1_Cfg & LSM6DSL_ACC_GYRO_INT1_TILT_MASK) || (Md2_Cfg & LSM6DSL_ACC_GYRO_INT2_TILT_MASK))
2173 | {
2174 | if((Func_Src & LSM6DSL_ACC_GYRO_TILT_EV_STATUS_MASK))
2175 | {
2176 | status->TiltStatus = 1;
2177 | }
2178 | }
2179 |
2180 | return LSM6DSL_STATUS_OK;
2181 | }
2182 |
2183 | /**
2184 | * @brief Read the data from register
2185 | * @param reg register address
2186 | * @param data register data
2187 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
2188 | */
2189 | LSM6DSLStatusTypeDef LSM6DSLSensor::ReadReg( uint8_t reg, uint8_t *data )
2190 | {
2191 |
2192 | if ( LSM6DSL_ACC_GYRO_ReadReg( (void *)this, reg, data, 1 ) == MEMS_ERROR )
2193 | {
2194 | return LSM6DSL_STATUS_ERROR;
2195 | }
2196 |
2197 | return LSM6DSL_STATUS_OK;
2198 | }
2199 |
2200 | /**
2201 | * @brief Write the data to register
2202 | * @param reg register address
2203 | * @param data register data
2204 | * @retval LSM6DSL_STATUS_OK in case of success, an error code otherwise
2205 | */
2206 | LSM6DSLStatusTypeDef LSM6DSLSensor::WriteReg( uint8_t reg, uint8_t data )
2207 | {
2208 |
2209 | if ( LSM6DSL_ACC_GYRO_WriteReg( (void *)this, reg, &data, 1 ) == MEMS_ERROR )
2210 | {
2211 | return LSM6DSL_STATUS_ERROR;
2212 | }
2213 |
2214 | return LSM6DSL_STATUS_OK;
2215 | }
2216 |
2217 |
2218 | uint8_t LSM6DSL_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite )
2219 | {
2220 | return ((LSM6DSLSensor *)handle)->IO_Write(pBuffer, WriteAddr, nBytesToWrite);
2221 | }
2222 |
2223 | uint8_t LSM6DSL_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead )
2224 | {
2225 | return ((LSM6DSLSensor *)handle)->IO_Read(pBuffer, ReadAddr, nBytesToRead);
2226 | }
2227 |
--------------------------------------------------------------------------------
/src/LSM6DSLSensor.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file LSM6DSLSensor.h
4 | * @author AST
5 | * @version V1.0.0
6 | * @date 7 September 2017
7 | * @brief Abstract Class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes
8 | * sensor.
9 | ******************************************************************************
10 | * @attention
11 | *
12 | * © COPYRIGHT(c) 2017 STMicroelectronics
13 | *
14 | * Redistribution and use in source and binary forms, with or without modification,
15 | * are permitted provided that the following conditions are met:
16 | * 1. Redistributions of source code must retain the above copyright notice,
17 | * this list of conditions and the following disclaimer.
18 | * 2. Redistributions in binary form must reproduce the above copyright notice,
19 | * this list of conditions and the following disclaimer in the documentation
20 | * and/or other materials provided with the distribution.
21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors
22 | * may be used to endorse or promote products derived from this software
23 | * without specific prior written permission.
24 | *
25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 | *
36 | ******************************************************************************
37 | */
38 |
39 |
40 | /* Prevent recursive inclusion -----------------------------------------------*/
41 |
42 | #ifndef __LSM6DSLSensor_H__
43 | #define __LSM6DSLSensor_H__
44 |
45 |
46 | /* Includes ------------------------------------------------------------------*/
47 |
48 | #include "Wire.h"
49 | #include "SPI.h"
50 | #include "LSM6DSL_ACC_GYRO_Driver.h"
51 |
52 | /* Defines -------------------------------------------------------------------*/
53 |
54 | #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_2G 0.061 /**< Sensitivity value for 2 g full scale [mg/LSB] */
55 | #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_4G 0.122 /**< Sensitivity value for 4 g full scale [mg/LSB] */
56 | #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_8G 0.244 /**< Sensitivity value for 8 g full scale [mg/LSB] */
57 | #define LSM6DSL_ACC_SENSITIVITY_FOR_FS_16G 0.488 /**< Sensitivity value for 16 g full scale [mg/LSB] */
58 |
59 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_125DPS 04.375 /**< Sensitivity value for 125 dps full scale [mdps/LSB] */
60 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_245DPS 08.750 /**< Sensitivity value for 245 dps full scale [mdps/LSB] */
61 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_500DPS 17.500 /**< Sensitivity value for 500 dps full scale [mdps/LSB] */
62 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_1000DPS 35.000 /**< Sensitivity value for 1000 dps full scale [mdps/LSB] */
63 | #define LSM6DSL_GYRO_SENSITIVITY_FOR_FS_2000DPS 70.000 /**< Sensitivity value for 2000 dps full scale [mdps/LSB] */
64 |
65 | #define LSM6DSL_PEDOMETER_THRESHOLD_LOW 0x00 /**< Lowest value of pedometer threshold */
66 | #define LSM6DSL_PEDOMETER_THRESHOLD_MID_LOW 0x07
67 | #define LSM6DSL_PEDOMETER_THRESHOLD_MID 0x0F
68 | #define LSM6DSL_PEDOMETER_THRESHOLD_MID_HIGH 0x17
69 | #define LSM6DSL_PEDOMETER_THRESHOLD_HIGH 0x1F /**< Highest value of pedometer threshold */
70 |
71 | #define LSM6DSL_WAKE_UP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */
72 | #define LSM6DSL_WAKE_UP_THRESHOLD_MID_LOW 0x0F
73 | #define LSM6DSL_WAKE_UP_THRESHOLD_MID 0x1F
74 | #define LSM6DSL_WAKE_UP_THRESHOLD_MID_HIGH 0x2F
75 | #define LSM6DSL_WAKE_UP_THRESHOLD_HIGH 0x3F /**< Highest value of wake up threshold */
76 |
77 | #define LSM6DSL_TAP_THRESHOLD_LOW 0x01 /**< Lowest value of wake up threshold */
78 | #define LSM6DSL_TAP_THRESHOLD_MID_LOW 0x08
79 | #define LSM6DSL_TAP_THRESHOLD_MID 0x10
80 | #define LSM6DSL_TAP_THRESHOLD_MID_HIGH 0x18
81 | #define LSM6DSL_TAP_THRESHOLD_HIGH 0x1F /**< Highest value of wake up threshold */
82 |
83 | #define LSM6DSL_TAP_SHOCK_TIME_LOW 0x00 /**< Lowest value of wake up threshold */
84 | #define LSM6DSL_TAP_SHOCK_TIME_MID_LOW 0x01
85 | #define LSM6DSL_TAP_SHOCK_TIME_MID_HIGH 0x02
86 | #define LSM6DSL_TAP_SHOCK_TIME_HIGH 0x03 /**< Highest value of wake up threshold */
87 |
88 | #define LSM6DSL_TAP_QUIET_TIME_LOW 0x00 /**< Lowest value of wake up threshold */
89 | #define LSM6DSL_TAP_QUIET_TIME_MID_LOW 0x01
90 | #define LSM6DSL_TAP_QUIET_TIME_MID_HIGH 0x02
91 | #define LSM6DSL_TAP_QUIET_TIME_HIGH 0x03 /**< Highest value of wake up threshold */
92 |
93 | #define LSM6DSL_TAP_DURATION_TIME_LOW 0x00 /**< Lowest value of wake up threshold */
94 | #define LSM6DSL_TAP_DURATION_TIME_MID_LOW 0x04
95 | #define LSM6DSL_TAP_DURATION_TIME_MID 0x08
96 | #define LSM6DSL_TAP_DURATION_TIME_MID_HIGH 0x0C
97 | #define LSM6DSL_TAP_DURATION_TIME_HIGH 0x0F /**< Highest value of wake up threshold */
98 |
99 | /* Typedefs ------------------------------------------------------------------*/
100 | typedef enum
101 | {
102 | LSM6DSL_STATUS_OK = 0,
103 | LSM6DSL_STATUS_ERROR,
104 | LSM6DSL_STATUS_TIMEOUT,
105 | LSM6DSL_STATUS_NOT_IMPLEMENTED
106 | } LSM6DSLStatusTypeDef;
107 |
108 | typedef enum
109 | {
110 | LSM6DSL_INT1_PIN,
111 | LSM6DSL_INT2_PIN
112 | } LSM6DSL_Interrupt_Pin_t;
113 |
114 | typedef struct
115 | {
116 | unsigned int FreeFallStatus : 1;
117 | unsigned int TapStatus : 1;
118 | unsigned int DoubleTapStatus : 1;
119 | unsigned int WakeUpStatus : 1;
120 | unsigned int StepStatus : 1;
121 | unsigned int TiltStatus : 1;
122 | unsigned int D6DOrientationStatus : 1;
123 | } LSM6DSL_Event_Status_t;
124 |
125 | /* Class Declaration ---------------------------------------------------------*/
126 |
127 | /**
128 | * Abstract class of an LSM6DSL Inertial Measurement Unit (IMU) 6 axes
129 | * sensor.
130 | */
131 | class LSM6DSLSensor
132 | {
133 | public:
134 | LSM6DSLSensor (TwoWire *i2c, uint8_t address=LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH);
135 | LSM6DSLSensor (SPIClass *spi, int cs_pin, uint32_t spi_speed=2000000);
136 | LSM6DSLStatusTypeDef begin (void);
137 | LSM6DSLStatusTypeDef end (void);
138 | LSM6DSLStatusTypeDef Enable_X (void);
139 | LSM6DSLStatusTypeDef Enable_G (void);
140 | LSM6DSLStatusTypeDef Disable_X (void);
141 | LSM6DSLStatusTypeDef Disable_G (void);
142 | LSM6DSLStatusTypeDef ReadID (uint8_t *p_id);
143 | LSM6DSLStatusTypeDef Get_X_Axes (int32_t *pData);
144 | LSM6DSLStatusTypeDef Get_G_Axes (int32_t *pData);
145 | LSM6DSLStatusTypeDef Get_X_Sensitivity (float *pfData);
146 | LSM6DSLStatusTypeDef Get_G_Sensitivity (float *pfData);
147 | LSM6DSLStatusTypeDef Get_X_AxesRaw (int16_t *pData);
148 | LSM6DSLStatusTypeDef Get_G_AxesRaw (int16_t *pData);
149 | LSM6DSLStatusTypeDef Get_X_ODR (float *odr);
150 | LSM6DSLStatusTypeDef Get_G_ODR (float *odr);
151 | LSM6DSLStatusTypeDef Set_X_ODR (float odr);
152 | LSM6DSLStatusTypeDef Set_G_ODR (float odr);
153 | LSM6DSLStatusTypeDef Get_X_FS (float *fullScale);
154 | LSM6DSLStatusTypeDef Get_G_FS (float *fullScale);
155 | LSM6DSLStatusTypeDef Set_X_FS (float fullScale);
156 | LSM6DSLStatusTypeDef Set_G_FS (float fullScale);
157 | LSM6DSLStatusTypeDef Enable_Free_Fall_Detection (void);
158 | LSM6DSLStatusTypeDef Enable_Free_Fall_Detection (LSM6DSL_Interrupt_Pin_t int_pin);
159 | LSM6DSLStatusTypeDef Disable_Free_Fall_Detection (void);
160 | LSM6DSLStatusTypeDef Set_Free_Fall_Threshold (uint8_t thr);
161 | LSM6DSLStatusTypeDef Enable_Pedometer (void);
162 | LSM6DSLStatusTypeDef Disable_Pedometer (void);
163 | LSM6DSLStatusTypeDef Get_Step_Counter (uint16_t *step_count);
164 | LSM6DSLStatusTypeDef Reset_Step_Counter (void);
165 | LSM6DSLStatusTypeDef Set_Pedometer_Threshold (uint8_t thr);
166 | LSM6DSLStatusTypeDef Enable_Tilt_Detection (void);
167 | LSM6DSLStatusTypeDef Enable_Tilt_Detection (LSM6DSL_Interrupt_Pin_t int_pin);
168 | LSM6DSLStatusTypeDef Disable_Tilt_Detection (void);
169 | LSM6DSLStatusTypeDef Enable_Wake_Up_Detection (void);
170 | LSM6DSLStatusTypeDef Enable_Wake_Up_Detection (LSM6DSL_Interrupt_Pin_t int_pin);
171 | LSM6DSLStatusTypeDef Disable_Wake_Up_Detection (void);
172 | LSM6DSLStatusTypeDef Set_Wake_Up_Threshold (uint8_t thr);
173 | LSM6DSLStatusTypeDef Enable_Single_Tap_Detection (void);
174 | LSM6DSLStatusTypeDef Enable_Single_Tap_Detection (LSM6DSL_Interrupt_Pin_t int_pin);
175 | LSM6DSLStatusTypeDef Disable_Single_Tap_Detection (void);
176 | LSM6DSLStatusTypeDef Enable_Double_Tap_Detection (void);
177 | LSM6DSLStatusTypeDef Enable_Double_Tap_Detection (LSM6DSL_Interrupt_Pin_t int_pin);
178 | LSM6DSLStatusTypeDef Disable_Double_Tap_Detection (void);
179 | LSM6DSLStatusTypeDef Set_Tap_Threshold (uint8_t thr);
180 | LSM6DSLStatusTypeDef Set_Tap_Shock_Time (uint8_t time);
181 | LSM6DSLStatusTypeDef Set_Tap_Quiet_Time (uint8_t time);
182 | LSM6DSLStatusTypeDef Set_Tap_Duration_Time (uint8_t time);
183 | LSM6DSLStatusTypeDef Enable_6D_Orientation (void);
184 | LSM6DSLStatusTypeDef Enable_6D_Orientation (LSM6DSL_Interrupt_Pin_t int_pin);
185 | LSM6DSLStatusTypeDef Disable_6D_Orientation (void);
186 | LSM6DSLStatusTypeDef Get_6D_Orientation_XL (uint8_t *xl);
187 | LSM6DSLStatusTypeDef Get_6D_Orientation_XH (uint8_t *xh);
188 | LSM6DSLStatusTypeDef Get_6D_Orientation_YL (uint8_t *yl);
189 | LSM6DSLStatusTypeDef Get_6D_Orientation_YH (uint8_t *yh);
190 | LSM6DSLStatusTypeDef Get_6D_Orientation_ZL (uint8_t *zl);
191 | LSM6DSLStatusTypeDef Get_6D_Orientation_ZH (uint8_t *zh);
192 | LSM6DSLStatusTypeDef Get_Event_Status (LSM6DSL_Event_Status_t *status);
193 | LSM6DSLStatusTypeDef ReadReg (uint8_t reg, uint8_t *data);
194 | LSM6DSLStatusTypeDef WriteReg (uint8_t reg, uint8_t data);
195 |
196 | /**
197 | * @brief Utility function to read data.
198 | * @param pBuffer: pointer to data to be read.
199 | * @param RegisterAddr: specifies internal address register to be read.
200 | * @param NumByteToRead: number of bytes to be read.
201 | * @retval 0 if ok, an error code otherwise.
202 | */
203 | uint8_t IO_Read(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToRead)
204 | {
205 | if (dev_spi) {
206 | dev_spi->beginTransaction(SPISettings(spi_speed, MSBFIRST, SPI_MODE3));
207 |
208 | digitalWrite(cs_pin, LOW);
209 |
210 | /* Write Reg Address */
211 | dev_spi->transfer(RegisterAddr | 0x80);
212 | /* Read the data */
213 | for (uint16_t i=0; itransfer(0x00);
215 | }
216 |
217 | digitalWrite(cs_pin, HIGH);
218 |
219 | dev_spi->endTransaction();
220 |
221 | return 0;
222 | }
223 |
224 | if (dev_i2c) {
225 | dev_i2c->beginTransmission(((uint8_t)(((address) >> 1) & 0x7F)));
226 | dev_i2c->write(RegisterAddr);
227 | dev_i2c->endTransmission(false);
228 |
229 | dev_i2c->requestFrom(((uint8_t)(((address) >> 1) & 0x7F)), (byte) NumByteToRead);
230 |
231 | int i=0;
232 | while (dev_i2c->available())
233 | {
234 | pBuffer[i] = dev_i2c->read();
235 | i++;
236 | }
237 |
238 | return 0;
239 | }
240 |
241 | return 1;
242 | }
243 |
244 | /**
245 | * @brief Utility function to write data.
246 | * @param pBuffer: pointer to data to be written.
247 | * @param RegisterAddr: specifies internal address register to be written.
248 | * @param NumByteToWrite: number of bytes to write.
249 | * @retval 0 if ok, an error code otherwise.
250 | */
251 | uint8_t IO_Write(uint8_t* pBuffer, uint8_t RegisterAddr, uint16_t NumByteToWrite)
252 | {
253 | if (dev_spi) {
254 | dev_spi->beginTransaction(SPISettings(spi_speed, MSBFIRST, SPI_MODE3));
255 |
256 | digitalWrite(cs_pin, LOW);
257 |
258 | /* Write Reg Address */
259 | dev_spi->transfer(RegisterAddr);
260 | /* Write the data */
261 | for (uint16_t i=0; itransfer(pBuffer[i]);
263 | }
264 |
265 | digitalWrite(cs_pin, HIGH);
266 |
267 | dev_spi->endTransaction();
268 |
269 | return 0;
270 | }
271 |
272 | if (dev_i2c) {
273 | dev_i2c->beginTransmission(((uint8_t)(((address) >> 1) & 0x7F)));
274 |
275 | dev_i2c->write(RegisterAddr);
276 | for (int i = 0 ; i < NumByteToWrite ; i++)
277 | dev_i2c->write(pBuffer[i]);
278 |
279 | dev_i2c->endTransmission(true);
280 |
281 | return 0;
282 | }
283 |
284 | return 1;
285 | }
286 |
287 | private:
288 | LSM6DSLStatusTypeDef Set_X_ODR_When_Enabled(float odr);
289 | LSM6DSLStatusTypeDef Set_G_ODR_When_Enabled(float odr);
290 | LSM6DSLStatusTypeDef Set_X_ODR_When_Disabled(float odr);
291 | LSM6DSLStatusTypeDef Set_G_ODR_When_Disabled(float odr);
292 |
293 | /* Helper classes. */
294 | TwoWire *dev_i2c;
295 | SPIClass *dev_spi;
296 |
297 | /* Configuration */
298 | uint8_t address;
299 | int cs_pin;
300 | uint32_t spi_speed;
301 |
302 | uint8_t X_isEnabled;
303 | float X_Last_ODR;
304 | uint8_t G_isEnabled;
305 | float G_Last_ODR;
306 | };
307 |
308 | #ifdef __cplusplus
309 | extern "C" {
310 | #endif
311 | uint8_t LSM6DSL_IO_Write( void *handle, uint8_t WriteAddr, uint8_t *pBuffer, uint16_t nBytesToWrite );
312 | uint8_t LSM6DSL_IO_Read( void *handle, uint8_t ReadAddr, uint8_t *pBuffer, uint16_t nBytesToRead );
313 | #ifdef __cplusplus
314 | }
315 | #endif
316 |
317 | #endif
--------------------------------------------------------------------------------