Nordic Thingy:52 v2.2.0
drv_motion.h
1 /*
2  Copyright (c) 2010 - 2017, Nordic Semiconductor ASA
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification,
6  are permitted provided that the following conditions are met:
7 
8  1. Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  2. Redistributions in binary form, except as embedded into a Nordic
12  Semiconductor ASA integrated circuit in a product or a software update for
13  such product, must reproduce the above copyright notice, this list of
14  conditions and the following disclaimer in the documentation and/or other
15  materials provided with the distribution.
16 
17  3. Neither the name of Nordic Semiconductor ASA nor the names of its
18  contributors may be used to endorse or promote products derived from this
19  software without specific prior written permission.
20 
21  4. This software, with or without modification, must only be used with a
22  Nordic Semiconductor ASA integrated circuit.
23 
24  5. Any software provided in binary form under this license must not be reverse
25  engineered, decompiled, modified and/or disassembled.
26 
27  THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
28  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29  OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
30  DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
31  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
33  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */
38 
48 #ifndef __DRV_MOTION_H__
49 #define __DRV_MOTION_H__
50 
51 #include <stdint.h>
52 #include <stddef.h>
53 #include "nrf_drv_twi.h"
54 
57 typedef enum
58 {
59  DRV_MOTION_FEATURE_RAW_ACCEL,
60  DRV_MOTION_FEATURE_RAW_GYRO,
61  DRV_MOTION_FEATURE_RAW_COMPASS,
62  DRV_MOTION_FEATURE_QUAT,
63  DRV_MOTION_FEATURE_EULER,
64  DRV_MOTION_FEATURE_ROT_MAT,
65  DRV_MOTION_FEATURE_HEADING,
66  DRV_MOTION_FEATURE_GRAVITY_VECTOR,
67  DRV_MOTION_FEATURE_TAP,
68  DRV_MOTION_FEATURE_ORIENTATION,
69  DRV_MOTION_FEATURE_PEDOMETER,
70  DRV_MOTION_FEATURE_WAKE_ON_MOTION
72 
73 typedef uint32_t drv_motion_feature_mask_t;
74 
75 #define DRV_MOTION_FEATURE_MASK_RAW ((1UL << DRV_MOTION_FEATURE_RAW_ACCEL) | (1UL << DRV_MOTION_FEATURE_RAW_COMPASS) | (1UL << DRV_MOTION_FEATURE_RAW_GYRO))
76 #define DRV_MOTION_FEATURE_MASK_RAW_ACCEL (1UL << DRV_MOTION_FEATURE_RAW_ACCEL)
77 #define DRV_MOTION_FEATURE_MASK_RAW_GYRO (1UL << DRV_MOTION_FEATURE_RAW_GYRO)
78 #define DRV_MOTION_FEATURE_MASK_RAW_COMPASS (1UL << DRV_MOTION_FEATURE_RAW_COMPASS)
79 #define DRV_MOTION_FEATURE_MASK_QUAT (1UL << DRV_MOTION_FEATURE_QUAT)
80 #define DRV_MOTION_FEATURE_MASK_EULER (1UL << DRV_MOTION_FEATURE_EULER)
81 #define DRV_MOTION_FEATURE_MASK_ROT_MAT (1UL << DRV_MOTION_FEATURE_ROT_MAT)
82 #define DRV_MOTION_FEATURE_MASK_HEADING (1UL << DRV_MOTION_FEATURE_HEADING)
83 #define DRV_MOTION_FEATURE_MASK_GRAVITY_VECTOR (1UL << DRV_MOTION_FEATURE_GRAVITY_VECTOR)
84 #define DRV_MOTION_FEATURE_MASK_TAP (1UL << DRV_MOTION_FEATURE_TAP)
85 #define DRV_MOTION_FEATURE_MASK_ORIENTATION (1UL << DRV_MOTION_FEATURE_ORIENTATION)
86 #define DRV_MOTION_FEATURE_MASK_PEDOMETER (1UL << DRV_MOTION_FEATURE_PEDOMETER)
87 #define DRV_MOTION_FEATURE_MASK_WAKE_ON_MOTION (1UL << DRV_MOTION_FEATURE_WAKE_ON_MOTION)
88 
89 #define DRV_MOTION_FEATURE_MASK (DRV_MOTION_FEATURE_MASK_RAW_ACCEL | \
90  DRV_MOTION_FEATURE_MASK_RAW_GYRO | \
91  DRV_MOTION_FEATURE_MASK_RAW_COMPASS | \
92  DRV_MOTION_FEATURE_MASK_QUAT | \
93  DRV_MOTION_FEATURE_MASK_EULER | \
94  DRV_MOTION_FEATURE_MASK_ROT_MAT | \
95  DRV_MOTION_FEATURE_MASK_HEADING | \
96  DRV_MOTION_FEATURE_MASK_GRAVITY_VECTOR | \
97  DRV_MOTION_FEATURE_MASK_TAP | \
98  DRV_MOTION_FEATURE_MASK_ORIENTATION | \
99  DRV_MOTION_FEATURE_MASK_PEDOMETER | \
100  DRV_MOTION_FEATURE_MASK_WAKE_ON_MOTION)
101 
102 #define DRV_MOTION_FEATURE_DMP_MASK (DRV_MOTION_FEATURE_MASK_QUAT | \
103  DRV_MOTION_FEATURE_MASK_EULER | \
104  DRV_MOTION_FEATURE_MASK_ROT_MAT | \
105  DRV_MOTION_FEATURE_MASK_HEADING | \
106  DRV_MOTION_FEATURE_MASK_GRAVITY_VECTOR | \
107  DRV_MOTION_FEATURE_MASK_TAP | \
108  DRV_MOTION_FEATURE_MASK_ORIENTATION | \
109  DRV_MOTION_FEATURE_MASK_PEDOMETER)
110 
111 #define DRV_MOTION_FEATURE_GESTURE_MASK (DRV_MOTION_FEATURE_MASK_TAP | \
112  DRV_MOTION_FEATURE_MASK_ORIENTATION | \
113  DRV_MOTION_FEATURE_MASK_PEDOMETER)
114 
115 #define DRV_MOTION_FEATURE_CONTINUOS_MASK (DRV_MOTION_FEATURE_MASK_RAW_ACCEL | \
116  DRV_MOTION_FEATURE_MASK_RAW_GYRO | \
117  DRV_MOTION_FEATURE_MASK_RAW_COMPASS | \
118  DRV_MOTION_FEATURE_MASK_QUAT | \
119  DRV_MOTION_FEATURE_MASK_EULER | \
120  DRV_MOTION_FEATURE_MASK_ROT_MAT | \
121  DRV_MOTION_FEATURE_MASK_HEADING | \
122  DRV_MOTION_FEATURE_MASK_GRAVITY_VECTOR)
123 
126 typedef enum
127 {
128  DRV_MOTION_EVT_RAW,
129  DRV_MOTION_EVT_QUAT,
130  DRV_MOTION_EVT_EULER,
131  DRV_MOTION_EVT_ROT_MAT,
132  DRV_MOTION_EVT_HEADING,
133  DRV_MOTION_EVT_GRAVITY,
134  DRV_MOTION_EVT_TAP,
135  DRV_MOTION_EVT_ORIENTATION,
136  DRV_MOTION_EVT_PEDOMETER
138 
141 typedef void (*drv_motion_evt_handler_t)(drv_motion_evt_t const * p_evt, void * p_data, uint32_t size);
142 
145 typedef struct
146 {
147  uint16_t pedo_interval_ms;
148  uint16_t temp_interval_ms;
149  uint16_t compass_interval_ms;
150  uint16_t motion_freq_hz;
151  uint8_t wake_on_motion;
153 
156 typedef struct
157 {
158  nrf_drv_twi_t const * p_twi_instance;
159  nrf_drv_twi_config_t const * p_twi_cfg;
161 
162 
171 uint32_t drv_motion_init(drv_motion_evt_handler_t evt_handler, drv_motion_twi_init_t * p_params_mpu, drv_motion_twi_init_t * p_params_lis);
172 
179 uint32_t drv_motion_enable(drv_motion_feature_mask_t feature_mask);
180 
187 uint32_t drv_motion_disable(drv_motion_feature_mask_t feature_mask);
188 
195 uint32_t drv_motion_config(drv_motion_cfg_t * p_cfg);
196 
203 uint32_t drv_motion_sleep_prepare(bool wakeup);
204 #endif
205 
uint32_t drv_motion_enable(drv_motion_feature_mask_t feature_mask)
Function for enabling features in the motion driver.
drv_motion_feature_t
Motion features.
Definition: drv_motion.h:57
Motion configuration struct.
Definition: drv_motion.h:145
uint32_t drv_motion_disable(drv_motion_feature_mask_t feature_mask)
Function for disabling features in the motion driver.
uint32_t drv_motion_sleep_prepare(bool wakeup)
Function for preparing for sleep mode.
uint32_t drv_motion_config(drv_motion_cfg_t *p_cfg)
Function for configuring the motion driver.
drv_motion_evt_t
Motion event types.
Definition: drv_motion.h:126
void(* drv_motion_evt_handler_t)(drv_motion_evt_t const *p_evt, void *p_data, uint32_t size)
Motion driver event handler callback type.
Definition: drv_motion.h:141
Motion initialization struct.
Definition: drv_motion.h:156
uint32_t drv_motion_init(drv_motion_evt_handler_t evt_handler, drv_motion_twi_init_t *p_params_mpu, drv_motion_twi_init_t *p_params_lis)
Function for initializing the motion driver.