SensorMpu9250.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
44 #ifndef SENSOR_MPU9250_H
45 #define SENSOR_MPU9250_H
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /* -----------------------------------------------------------------------------
52  * Includes
53  * -----------------------------------------------------------------------------
54  */
55 #include "stdint.h"
56 #include "stdbool.h"
57 
58 /* -----------------------------------------------------------------------------
59  * Constants
60  * -----------------------------------------------------------------------------
61  */
62 // Accelerometer ranges
63 #define ACC_RANGE_2G 0
64 #define ACC_RANGE_4G 1
65 #define ACC_RANGE_8G 2
66 #define ACC_RANGE_16G 3
67 #define ACC_RANGE_INVALID 0xFF
69 // Axis bitmaps
70 #define MPU_AX_GYR 0x07
71 #define MPU_AX_ACC 0x38
72 #define MPU_AX_MAG 0x40
73 #define MPU_AX_ALL 0x7F
75 // Interrupt status bit
76 #define MPU_DATA_READY 0x01
77 #define MPU_MOVEMENT 0x40
79 // Magnetometer status
80 #define MAG_STATUS_OK 0x00
81 #define MAG_READ_ST_ERR 0x01
82 #define MAG_DATA_NOT_RDY 0x02
83 #define MAG_OVERFLOW 0x03
84 #define MAG_READ_DATA_ERR 0x04
85 #define MAG_BYPASS_FAIL 0x05
86 #define MAG_NO_POWER 0x06
88 /* ----------------------------------------------------------------------------
89  * Typedefs
90  * -----------------------------------------------------------------------------
91 */
92 
93 typedef void (*SensorMpu9250CallbackFn_t)(void);
94 
95 /* -----------------------------------------------------------------------------
96  * Functions
97  * -----------------------------------------------------------------------------
98  */
99 
110 bool SensorMpu9250_init(void);
111 
117 bool SensorMpu9250_reset(void);
118 
125 
131 bool SensorMpu9250_test(void);
132 
137 void SensorMpu9250_powerOn(void);
138 
143 void SensorMpu9250_powerOff(void);
144 
150 bool SensorMpu9250_powerIsOn(void);
151 
162 void SensorMpu9250_enable(uint16_t config);
163 
175 bool SensorMpu9250_womEnable(uint8_t threshold);
176 
184 uint8_t SensorMpu9250_irqStatus(void);
185 
193 bool SensorMpu9250_accSetRange(uint8_t range);
194 
200 uint8_t SensorMpu9250_accReadRange(void);
201 
211 bool SensorMpu9250_accRead(uint16_t *pData);
212 
220 float SensorMpu9250_accConvert(int16_t data);
221 
231 bool SensorMpu9250_gyroRead(uint16_t *pData);
232 
240 float SensorMpu9250_gyroConvert(int16_t data);
241 
247 bool SensorMpu9250_magTest(void);
248 
256 uint8_t SensorMpu9250_magRead(int16_t *pData);
257 
263 uint8_t SensorMpu9250_magStatus(void);
264 
268 void SensorMpu9250_magReset(void);
269 
270 /*******************************************************************************
271 */
272 
273 #ifdef __cplusplus
274 };
275 #endif
276 
277 #endif
bool SensorMpu9250_magTest(void)
Run a magnetometer self test.
void SensorMpu9250_registerCallback(SensorMpu9250CallbackFn_t pCallback)
Register an application defined call-back for interrupt processing.
bool SensorMpu9250_test(void)
Run a self-test of the gyro/accelerometer component.
void SensorMpu9250_magReset(void)
Reset the magnetometer.
void SensorMpu9250_enable(uint16_t config)
Enable data collection.
bool SensorMpu9250_gyroRead(uint16_t *pData)
Read data from the gyroscope.
uint8_t SensorMpu9250_accReadRange(void)
Read the accelerometer range.
void(* SensorMpu9250CallbackFn_t)(void)
Definition: SensorMpu9250.h:93
bool SensorMpu9250_accSetRange(uint8_t range)
Set the accelerometer range.
bool SensorMpu9250_powerIsOn(void)
get the state of the power supply to the MPU9250
bool SensorMpu9250_init(void)
This function initializes the MPU abstraction layer.
void SensorMpu9250_powerOff(void)
Remove power to the MPU9250.
void SensorMpu9250_powerOn(void)
Applies power to the MPU9250.
float SensorMpu9250_accConvert(int16_t data)
Convert raw data to G units.
uint8_t SensorMpu9250_magStatus(void)
Return the magnetometer status.
bool SensorMpu9250_reset(void)
This function resets the MPU.
uint8_t SensorMpu9250_irqStatus(void)
Read interrupt status register.
float SensorMpu9250_gyroConvert(int16_t data)
Convert raw data to deg/sec units.
bool SensorMpu9250_accRead(uint16_t *pData)
Read data from the accelerometer.
uint8_t SensorMpu9250_magRead(int16_t *pData)
Read data from the compass - X, Y, Z - 3 words.
bool SensorMpu9250_womEnable(uint8_t threshold)
Enable Wake On Motion functionality.
Copyright 2018, Texas Instruments Incorporated