├── .gitignore
├── .travis.yml
├── CMakeLists.txt
├── Kconfig
├── Kconfig.projbuild
├── LICENSE
├── Makefile.projbuild
├── README.md
├── component.mk
├── docs
├── Makefile
├── doxygen
│ ├── Doxyfile
│ ├── DoxygenLayout.xml
│ ├── customdoxygen.css
│ ├── doxy-boot.js
│ ├── footer.html
│ ├── header.html
│ └── mainpage.dox
├── make.bat
└── source
│ ├── _static
│ ├── MPUdriver.jpg
│ └── menuconfig_mpu-driver.png
│ ├── conf.py
│ ├── index.rst
│ └── requirements.txt
├── examples
├── README.md
├── mpu_i2c
│ ├── Makefile
│ └── main
│ │ ├── component.mk
│ │ └── mpu_i2c.cpp
├── mpu_real
│ ├── Makefile
│ └── main
│ │ ├── component.mk
│ │ └── mpu_real.cpp
└── mpu_spi
│ ├── Makefile
│ └── main
│ ├── component.mk
│ └── mpu_spi.cpp
├── include
├── MPU.hpp
├── MPUdmp.hpp
└── mpu
│ ├── log.hpp
│ ├── math.hpp
│ ├── registers.hpp
│ ├── types.hpp
│ └── utils.hpp
├── src
├── MPU.cpp
└── MPUdmp.cpp
├── test
├── README.md
├── mpu-tests
│ ├── Kconfig
│ ├── component.mk
│ └── test_mpu.cpp
└── unit-test-app
│ ├── Makefile
│ └── main
│ ├── app_main.cpp
│ └── component.mk
└── tools
└── ci
├── build.sh
├── gen_doxygen_docs.sh
├── setup_esp_idf.sh
└── setup_ext_libs.sh
/.gitignore:
--------------------------------------------------------------------------------
1 | ### ESP-IDF
2 | **/build/
3 | **/sdkconfig
4 | **/sdkconfig.old
5 |
6 | ## This partition table is generated
7 | test/unit-test-app/partition_table_unit_test_app.csv
8 |
9 | ### Documentation build artifacts
10 | docs/build/
11 | docs/doxygen/xml/
12 | docs/doxygen/man/
13 | docs/doxygen/html/
14 | docs/doxygen/doxygen-warning-log.txt
15 |
16 | ### Miscellaneous
17 | NOTES.md
18 | tools.mk
19 | .clang-format
20 |
21 | ### Visual Studio Code
22 | .vscode/
23 |
24 | ### CLion
25 | .idea/
26 | cmake-build-*/
27 |
28 |
29 | ### temporarily
30 | include/mpu/fusion.hpp
31 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: cpp
3 |
4 | # Environment variables
5 | env:
6 | global:
7 | - PATH: $PATH:$TRAVIS_BUILD_DIR/esp/xtensa-esp32-elf/bin
8 | - IDF_PATH: $TRAVIS_BUILD_DIR/esp/esp-idf
9 | - GH_REPO_NAME: esp32-MPU-driver
10 | - GH_REPO_REF: github.com/natanaeljr/esp32-MPU-driver.git
11 | - DOXYFILE_PATH: docs/doxygen
12 | - DOXYFILE: Doxyfile
13 | - MAKEFLAGS: "-j2"
14 |
15 | stages:
16 | - test
17 | - name: docs deploy
18 | if: branch = dev
19 |
20 | # Install dependencies
21 | addons:
22 | apt:
23 | packages:
24 | - bash
25 | - libncurses-dev
26 | - flex
27 | - bison
28 | - gperf
29 | - python
30 | - python-serial
31 |
32 | # setup to run script
33 | before_script:
34 | - $TRAVIS_BUILD_DIR/tools/ci/setup_esp_idf.sh
35 | - $TRAVIS_BUILD_DIR/tools/ci/setup_ext_libs.sh
36 |
37 | jobs:
38 | include:
39 | - script: ./tools/ci/build.sh test/unit-test-app --protocols=I2C --chips=all
40 | env:
41 | - UNIT_TEST_I2C: 1
42 | - script: ./tools/ci/build.sh test/unit-test-app --protocols=SPI --chips=all
43 | env:
44 | - UNIT_TEST_SPI: 1
45 | - script: ./tools/ci/build.sh examples/mpu_real --protocols=all --chips=all
46 | env:
47 | - EXAMPLE_MPU_REAL: 1
48 | - script: ./tools/ci/build.sh examples/mpu_i2c --protocols=I2C --chips=all
49 | env:
50 | - EXAMPLE_MPU_I2C: 1
51 | - script: ./tools/ci/build.sh examples/mpu_spi --protocols=SPI --chips=all
52 | env:
53 | - EXAMPLE_MPU_SPI: 1
54 | - stage: docs deploy
55 | addons:
56 | apt:
57 | packages:
58 | - bash
59 | - doxygen
60 | - doxygen-doc
61 | - doxygen-latex
62 | - doxygen-gui
63 | - graphviz
64 | before_script: skip
65 | script: ./tools/ci/gen_doxygen_docs.sh
66 | deploy:
67 | provider: pages
68 | skip-cleanup: true
69 | github-token: $GITHUB_TOKEN
70 | keep-history: true
71 | target-branch: gh-pages
72 | local-dir: gh-pages
73 | on:
74 | branch: dev
75 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | set(COMPONENT_SRCS
2 | "src/MPU.cpp")
3 | set(COMPONENT_ADD_INCLUDEDIRS "include")
4 | set(COMPONENT_REQUIRES "I2Cbus")
5 |
6 | register_component()
7 |
8 | component_compile_options(PUBLIC -DMPU_COMPONENT_TRUE=1)
9 |
10 | ## Defines needed for library code implementation
11 | # MPU9250 is the same as MPU6500 + AK8963
12 | # MPU9150 is the same as MPU6050 + AK8975
13 | # MPU6000 code is the same as MPU6050 code
14 | # MPU6555 equals MPU6500, MPU9255 equals MPU9250
15 | if(${CONFIG_MPU_CHIP_MODEL} STREQUAL "MPU9250")
16 | component_compile_options(PUBLIC -DCONFIG_MPU6500)
17 | elseif (${CONFIG_MPU_CHIP_MODEL} STREQUAL "MPU9150")
18 | component_compile_options(PUBLIC -DCONFIG_MPU6050)
19 | elseif (${CONFIG_MPU_CHIP_MODEL} STREQUAL "MPU6000")
20 | component_compile_options(PUBLIC -DCONFIG_MPU6050)
21 | elseif (${CONFIG_MPU_CHIP_MODEL} STREQUAL "MPU6555")
22 | component_compile_options(PUBLIC -DCONFIG_MPU6500)
23 | elseif (${CONFIG_MPU_CHIP_MODEL} STREQUAL "MPU9255")
24 | component_compile_options(PUBLIC -DCONFIG_MPU9250 -DCONFIG_MPU6500)
25 | endif()
26 |
--------------------------------------------------------------------------------
/Kconfig:
--------------------------------------------------------------------------------
1 | menu "MPU driver"
2 |
3 | #
4 | # Options defined in this menu
5 | #
6 | # CONFIG_MPU_CHIP_MODEL
7 | # CONFIG_MPU6000
8 | # CONFIG_MPU6050
9 | # CONFIG_MPU6500
10 | # CONFIG_MPU6555
11 | # CONFIG_MPU9150
12 | # CONFIG_MPU9250
13 | # CONFIG_MPU9255
14 | # CONFIG_MPU_AK8963
15 | # CONFIG_MPU_AK8975
16 | # CONFIG_MPU_AK89xx
17 | # CONFIG_MPU_COMM_PROTOCOL
18 | # CONFIG MPU_I2C
19 | # CONFIG MPU_SPI
20 | # CONFIG_MPU_ENABLE_DMP
21 | # CONFIG_MPU_FIFO_CORRUPTION_CHECK
22 | # CONFIG_MPU_LOG_LEVEL
23 | # CONFIG_MPU_LOG_LEVEL_DEFAULT
24 | # CONFIG_MPU_LOG_LEVEL_NONE
25 | # CONFIG_MPU_LOG_LEVEL_ERROR
26 | # CONFIG_MPU_LOG_LEVEL_WARN
27 | # CONFIG_MPU_LOG_LEVEL_INFO
28 | # CONFIG_MPU_LOG_LEVEL_DEBUG
29 | # CONFIG_MPU_LOG_LEVEL_VERBOSE
30 | #
31 |
32 |
33 | choice MPU_CHIP_MODEL
34 | prompt "MPU chip model"
35 | default MPU6050
36 | help
37 | Select MPU chip model which will be used with MPU library.
38 |
39 | config MPU6000
40 | bool "MPU6000"
41 | config MPU6050
42 | bool "MPU6050"
43 | config MPU6500
44 | bool "MPU6500"
45 | config MPU6555
46 | bool "MPU6555"
47 | config MPU9150
48 | bool "MPU9150"
49 | config MPU9250
50 | bool "MPU9250"
51 | config MPU9255
52 | bool "MPU9255"
53 |
54 | endchoice
55 |
56 |
57 | config MPU_CHIP_MODEL
58 | string
59 | default "MPU6000" if MPU6000
60 | default "MPU6050" if MPU6050
61 | default "MPU6500" if MPU6500
62 | default "MPU6555" if MPU6555
63 | default "MPU9150" if MPU9150
64 | default "MPU9250" if MPU9250
65 | default "MPU9255" if MPU9255
66 |
67 |
68 | config MPU_AK8963
69 | bool
70 | default "y"
71 | depends on MPU9250 || MPU9255
72 |
73 | config MPU_AK8975
74 | bool
75 | default "y"
76 | depends on MPU9150
77 |
78 | config MPU_AK89xx
79 | bool
80 | default "y"
81 | depends on MPU_AK8963 || MPU_AK8975
82 |
83 |
84 | choice MPU_COMM_PROTOCOL
85 | prompt "Communication Protocol"
86 | default MPU_I2C
87 | help
88 | Select MPU communication protocol. Available options are I2C and SPI, according to the MPU model.
89 |
90 | config MPU_I2C
91 | bool "I2C"
92 | help
93 | Inter-Integrated Circuit (I2C)
94 |
95 | config MPU_SPI
96 | bool "SPI"
97 | depends on MPU6000 || MPU6500 || MPU6555 || MPU9250 || MPU9255
98 | help
99 | Serial Peripheral Interface bus (SPI)
100 |
101 | endchoice
102 |
103 |
104 | config MPU_COMM_PROTOCOL
105 | string
106 | default "I2C" if MPU_I2C
107 | default "SPI" if MPU_SPI
108 |
109 |
110 | choice MPU_LOG_LEVEL
111 | prompt "Log verbosity"
112 | default MPU_LOG_LEVEL_DEFAULT
113 | help
114 | Specify how much output to see in logs from MPU library.
115 | Options depend on default log level, change on Log output.
116 |
117 | config MPU_LOG_LEVEL_DEFAULT
118 | bool "Default"
119 | help
120 | Log level Default is whatever is set in default esp32 log output verbosity.
121 |
122 | config MPU_LOG_LEVEL_NONE
123 | bool "No output"
124 | config MPU_LOG_LEVEL_ERROR
125 | bool "Error"
126 | depends on LOG_DEFAULT_LEVEL_ERROR || LOG_DEFAULT_LEVEL_WARN || LOG_DEFAULT_LEVEL_INFO || LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE
127 | config MPU_LOG_LEVEL_WARN
128 | bool "Warning"
129 | depends on LOG_DEFAULT_LEVEL_WARN || LOG_DEFAULT_LEVEL_INFO || LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE
130 | config MPU_LOG_LEVEL_INFO
131 | bool "Info"
132 | depends on LOG_DEFAULT_LEVEL_INFO || LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE
133 | config MPU_LOG_LEVEL_DEBUG
134 | bool "Debug"
135 | depends on LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE
136 | config MPU_LOG_LEVEL_VERBOSE
137 | bool "Verbose"
138 | depends on LOG_DEFAULT_LEVEL_VERBOSE
139 |
140 | endchoice
141 |
142 | config MPU_LOG_LEVEL
143 | int
144 | default 0 if MPU_LOG_LEVEL_NONE || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_NONE)
145 | default 1 if MPU_LOG_LEVEL_ERROR || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_ERROR)
146 | default 2 if MPU_LOG_LEVEL_WARN || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_WARN)
147 | default 3 if MPU_LOG_LEVEL_INFO || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_INFO)
148 | default 4 if MPU_LOG_LEVEL_DEBUG || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_DEBUG)
149 | default 5 if MPU_LOG_LEVEL_VERBOSE || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_VERBOSE)
150 |
151 |
152 | config MPU_ENABLE_DMP
153 | bool "Digital Motion Processor (DMP)"
154 | default "n"
155 | help
156 | Enable DMP (Digital Motion Processor) code to be compiled.
157 |
158 | # config MPU_FIFO_CORRUPTION_CHECK
159 | # bool "Enable FIFO packet corruption check (DMP only)"
160 | # depends on MPU_ENABLE_DMP
161 | # default "y"
162 | # help
163 | # Check for corrupted FIFO packet by monitoring the quaternion data and
164 | # ensuring that the magnitude is always normalized to one. This
165 | # shouldn't happen in normal operation, but if an I2C error occurs,
166 | # the FIFO reads might become misaligned.
167 |
168 |
169 | config MPU_LOG_ERROR_TRACES
170 | bool "Log communication error traces"
171 | depends on MPU_LOG_LEVEL > 0
172 | default "y"
173 | help
174 | Display on console communication error traces that occur within MPU driver code.
175 | Mostly for debugging.
176 |
177 |
178 | endmenu
179 |
--------------------------------------------------------------------------------
/Kconfig.projbuild:
--------------------------------------------------------------------------------
1 | menu "MPU driver"
2 |
3 | #
4 | # Options defined in this menu
5 | #
6 | # CONFIG_MPU_CHIP_MODEL
7 | # CONFIG_MPU6000
8 | # CONFIG_MPU6050
9 | # CONFIG_MPU6500
10 | # CONFIG_MPU6555
11 | # CONFIG_MPU9150
12 | # CONFIG_MPU9250
13 | # CONFIG_MPU9255
14 | # CONFIG_MPU_AK8963
15 | # CONFIG_MPU_AK8975
16 | # CONFIG_MPU_AK89xx
17 | # CONFIG_MPU_COMM_PROTOCOL
18 | # CONFIG MPU_I2C
19 | # CONFIG MPU_SPI
20 | # CONFIG_MPU_ENABLE_DMP
21 | # CONFIG_MPU_FIFO_CORRUPTION_CHECK
22 | # CONFIG_MPU_LOG_LEVEL
23 | # CONFIG_MPU_LOG_LEVEL_DEFAULT
24 | # CONFIG_MPU_LOG_LEVEL_NONE
25 | # CONFIG_MPU_LOG_LEVEL_ERROR
26 | # CONFIG_MPU_LOG_LEVEL_WARN
27 | # CONFIG_MPU_LOG_LEVEL_INFO
28 | # CONFIG_MPU_LOG_LEVEL_DEBUG
29 | # CONFIG_MPU_LOG_LEVEL_VERBOSE
30 | #
31 |
32 |
33 | choice MPU_CHIP_MODEL
34 | prompt "MPU chip model"
35 | default MPU6050
36 | help
37 | Select MPU chip model which will be used with MPU library.
38 |
39 | config MPU6000
40 | bool "MPU6000"
41 | config MPU6050
42 | bool "MPU6050"
43 | config MPU6500
44 | bool "MPU6500"
45 | config MPU6555
46 | bool "MPU6555"
47 | config MPU9150
48 | bool "MPU9150"
49 | config MPU9250
50 | bool "MPU9250"
51 | config MPU9255
52 | bool "MPU9255"
53 |
54 | endchoice
55 |
56 |
57 | config MPU_CHIP_MODEL
58 | string
59 | default "MPU6000" if MPU6000
60 | default "MPU6050" if MPU6050
61 | default "MPU6500" if MPU6500
62 | default "MPU6555" if MPU6555
63 | default "MPU9150" if MPU9150
64 | default "MPU9250" if MPU9250
65 | default "MPU9255" if MPU9255
66 |
67 |
68 | config MPU_AK8963
69 | bool
70 | default "y"
71 | depends on MPU9250 || MPU9255
72 |
73 | config MPU_AK8975
74 | bool
75 | default "y"
76 | depends on MPU9150
77 |
78 | config MPU_AK89xx
79 | bool
80 | default "y"
81 | depends on MPU_AK8963 || MPU_AK8975
82 |
83 |
84 | choice MPU_COMM_PROTOCOL
85 | prompt "Communication Protocol"
86 | default MPU_I2C
87 | help
88 | Select MPU communication protocol. Available options are I2C and SPI, according to the MPU model.
89 |
90 | config MPU_I2C
91 | bool "I2C"
92 | help
93 | Inter-Integrated Circuit (I2C)
94 |
95 | config MPU_SPI
96 | bool "SPI"
97 | depends on MPU6000 || MPU6500 || MPU6555 || MPU9250 || MPU9255
98 | help
99 | Serial Peripheral Interface bus (SPI)
100 |
101 | endchoice
102 |
103 |
104 | config MPU_COMM_PROTOCOL
105 | string
106 | default "I2C" if MPU_I2C
107 | default "SPI" if MPU_SPI
108 |
109 |
110 | choice MPU_LOG_LEVEL
111 | prompt "Log verbosity"
112 | default MPU_LOG_LEVEL_DEFAULT
113 | help
114 | Specify how much output to see in logs from MPU library.
115 | Options depend on default log level, change on Log output.
116 |
117 | config MPU_LOG_LEVEL_DEFAULT
118 | bool "Default"
119 | help
120 | Log level Default is whatever is set in default esp32 log output verbosity.
121 |
122 | config MPU_LOG_LEVEL_NONE
123 | bool "No output"
124 | config MPU_LOG_LEVEL_ERROR
125 | bool "Error"
126 | depends on LOG_DEFAULT_LEVEL_ERROR || LOG_DEFAULT_LEVEL_WARN || LOG_DEFAULT_LEVEL_INFO || LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE
127 | config MPU_LOG_LEVEL_WARN
128 | bool "Warning"
129 | depends on LOG_DEFAULT_LEVEL_WARN || LOG_DEFAULT_LEVEL_INFO || LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE
130 | config MPU_LOG_LEVEL_INFO
131 | bool "Info"
132 | depends on LOG_DEFAULT_LEVEL_INFO || LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE
133 | config MPU_LOG_LEVEL_DEBUG
134 | bool "Debug"
135 | depends on LOG_DEFAULT_LEVEL_DEBUG || LOG_DEFAULT_LEVEL_VERBOSE
136 | config MPU_LOG_LEVEL_VERBOSE
137 | bool "Verbose"
138 | depends on LOG_DEFAULT_LEVEL_VERBOSE
139 |
140 | endchoice
141 |
142 | config MPU_LOG_LEVEL
143 | int
144 | default 0 if MPU_LOG_LEVEL_NONE || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_NONE)
145 | default 1 if MPU_LOG_LEVEL_ERROR || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_ERROR)
146 | default 2 if MPU_LOG_LEVEL_WARN || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_WARN)
147 | default 3 if MPU_LOG_LEVEL_INFO || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_INFO)
148 | default 4 if MPU_LOG_LEVEL_DEBUG || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_DEBUG)
149 | default 5 if MPU_LOG_LEVEL_VERBOSE || (MPU_LOG_LEVEL_DEFAULT && LOG_DEFAULT_LEVEL_VERBOSE)
150 |
151 |
152 | config MPU_ENABLE_DMP
153 | bool "Digital Motion Processor (DMP)"
154 | default "n"
155 | help
156 | Enable DMP (Digital Motion Processor) code to be compiled.
157 |
158 | # config MPU_FIFO_CORRUPTION_CHECK
159 | # bool "Enable FIFO packet corruption check (DMP only)"
160 | # depends on MPU_ENABLE_DMP
161 | # default "y"
162 | # help
163 | # Check for corrupted FIFO packet by monitoring the quaternion data and
164 | # ensuring that the magnitude is always normalized to one. This
165 | # shouldn't happen in normal operation, but if an I2C error occurs,
166 | # the FIFO reads might become misaligned.
167 |
168 |
169 | config MPU_LOG_ERROR_TRACES
170 | bool "Log communication error traces"
171 | depends on MPU_LOG_LEVEL > 0
172 | default "y"
173 | help
174 | Display on console communication error traces that occur within MPU driver code.
175 | Mostly for debugging.
176 |
177 |
178 | endmenu
179 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright 2017-2018 Natanael Josue Rabello. All rights reserved.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to
7 | deal in the Software without restriction, including without limitation the
8 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 | sell copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 | IN THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Makefile.projbuild:
--------------------------------------------------------------------------------
1 | #
2 | # Top-level component makefile
3 | #
4 |
5 | CPPFLAGS += -DMPU_COMPONENT_TRUE=1
6 |
7 |
8 | ## Defines needed for library code implementation
9 | # MPU9250 is the same as MPU6500 + AK8963
10 | # MPU9150 is the same as MPU6050 + AK8975
11 | # MPU6000 code is the same as MPU6050 code
12 | # MPU6555 equals MPU6500, MPU9255 equals MPU9250
13 | ifeq ($(CONFIG_MPU_CHIP_MODEL),"MPU9250")
14 | CPPFLAGS += -DCONFIG_MPU6500
15 | else
16 | ifeq ($(CONFIG_MPU_CHIP_MODEL),"MPU9150")
17 | CPPFLAGS += -DCONFIG_MPU6050
18 | else
19 | ifeq ($(CONFIG_MPU_CHIP_MODEL),"MPU6000")
20 | CPPFLAGS += -DCONFIG_MPU6050
21 | else
22 | ifeq ($(CONFIG_MPU_CHIP_MODEL),"MPU6555")
23 | CPPFLAGS += -DCONFIG_MPU6500
24 | else
25 | ifeq ($(CONFIG_MPU_CHIP_MODEL),"MPU9255")
26 | CPPFLAGS += -DCONFIG_MPU9250 -DCONFIG_MPU6500
27 | endif
28 | endif
29 | endif
30 | endif
31 | endif
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://esp32-mpu-driver.readthedocs.io/en/latest)
2 | [](https://travis-ci.org/natanaeljr/esp32-MPU-driver)
3 | [](LICENSE)
4 |
5 | ![MPU Driver][Banner]
6 |
7 | [Banner]: docs/source/_static/MPUdriver.jpg
8 |
9 | A library for _Invensense_ MPU chips.
10 | It is written in C++ and designed for working with **[ESP32]** microcontroller _[esp-idf]_ framework.
11 | Supports both SPI and I2C protocols interchangeably, selectable bus port, and even multiple connected MPUs.
12 |
13 | [ESP32]: https://www.espressif.com/en/products/hardware/esp32/overview
14 | [esp-idf]: https://github.com/espressif/esp-idf/
15 |
16 | ## Models
17 |
18 | | part | sensors | protocol |
19 | | ------------: | :----------------: | :----------- |
20 | | **[MPU6000]** | Gyro/Accel | _I2C_, _SPI_ |
21 | | **[MPU6050]** | Gyro/Accel | _I2C_ |
22 | | **[MPU6500]** | Gyro/Accel | _I2C_, _SPI_ |
23 | | **MPU6555** | Gyro/Accel | _I2C_, _SPI_ |
24 | | **[MPU9150]** | Gyro/Accel/Compass | _I2C_ |
25 | | **[MPU9250]** | Gyro/Accel/Compass | _I2C_, _SPI_ |
26 | | **MPU9255** | Gyro/Accel/Compass | _I2C_, _SPI_ |
27 |
28 | [MPU6000]: https://www.invensense.com/products/motion-tracking/6-axis/mpu-6050/
29 | [MPU6050]: https://www.invensense.com/products/motion-tracking/6-axis/mpu-6050/
30 | [MPU6500]: https://www.invensense.com/products/motion-tracking/6-axis/mpu-6500/
31 | [MPU9150]: https://www.invensense.com/products/motion-tracking/9-axis/mpu-9150/
32 | [MPU9250]: https://www.invensense.com/products/motion-tracking/9-axis/mpu-9250/
33 |
34 | ## Features
35 |
36 | - [x] Support to SPI and I2C protocol (with selectable port)
37 | - [x] Basic configurations (sample rate _(4Hz~32KHz)_, clock source, full-scale, standby mode, offsets, interrupts, DLPF, etc..)
38 | - [x] Burst reading for all sensors
39 | - [x] Low Power Accelerometer mode _(various rates, e.g. 8.4μA at 0.98Hz)_
40 | - [x] Low Power Wake-on-motion mode _(with motion detection interrupt)_
41 | - [x] FIFO buffer access for all internal and external sensors
42 | - [x] Complete Auxiliary I2C support for external sensors _(up to 4)_
43 | - [x] External Frame Synchronization _(FSYNC)_ pass-through interrupt
44 | - [x] Motion, Zero-motion and Free-Fall detection _(as motion detection interrupt)_
45 | - [x] Total access to the Magnetometer _(even when MPU connected by SPI protocol)_
46 | - [x] Calibration for Gyro and Accel
47 | - [x] Self-Test _(true implementation from MotionApps)_
48 |
49 | #### DMP
50 |
51 | - [ ] Quaternion (3-axis Gyroscope)
52 | - [ ] Quaternion (6-axis Gyroscope and Accelerometer)
53 | - [ ] Screen Orientation (Android's screen rotation algorithm)
54 | - [ ] Tap Detection
55 | - [ ] Pedometer
56 | - [ ] Gyroscope calibrated data
57 |
58 | # Getting Started
59 |
60 | ## Prerequisites
61 |
62 | MPU driver depends on the following protocol libraries to communicate with the chip with ease: [ [I2Cbus] | [SPIbus] ].
63 | You must download the one according to the protocol you'll use and place within your components directory as well.
64 |
65 | ```
66 | I2Cbus: git clone https://github.com/natanaeljr/esp32-I2Cbus.git I2Cbus
67 | SPIbus: git clone https://github.com/natanaeljr/esp32-SPIbus.git SPIbus
68 | ```
69 |
70 | **_Note:_** At least one of these libraries must be installed as components for the MPU library to work. It won't work otherwise.
71 |
72 | [I2Cbus]: https://github.com/natanaeljr/esp32-I2Cbus
73 | [SPIbus]: https://github.com/natanaeljr/esp32-SPIbus
74 |
75 | ## Installation
76 |
77 | Download the repository [here](https://github.com/natanaeljr/esp32-MPU-driver/archive/master.zip),
78 | or clone it right into your project components directory with the following command.
79 |
80 | ```
81 | git clone https://github.com/natanaeljr/esp32-MPU-driver.git MPUdriver
82 | ```
83 |
84 | This way you can easily update the library with `git pull` whenever a update is available.
85 |
86 | ## Usage
87 |
88 | First of all, make sure MPU Driver is a component in you project, then run `make menuconfig`, select your chip model and communication protocol you'll use browsing through to `Component config` -> `MPU Driver`.
89 |
90 | 
91 |
92 | Now, in your source code, include the mpu main header `MPU.hpp`, the communication library `I2Cbus.hpp` or `SPIbus.hpp` and any other mpu headers that you'll use. Then get the bus ready as shown below.
93 |
94 | ```C++
95 | #include "MPU.hpp" // main file, provides the class itself
96 | #include "mpu/math.hpp" // math helper for dealing with MPU data
97 | #include "mpu/types.hpp" // MPU data types and definitions
98 | #include "I2Cbus.hpp"
99 | // ...
100 | i2c0.begin(SDA, SCL, CLOCK); // initialize the I2C bus
101 | ```
102 |
103 | And for SPI:
104 |
105 | ```C++
106 | #include "MPU.hpp" // main file, provides the class itself
107 | #include "mpu/math.hpp" // math helper for dealing with MPU data
108 | #include "mpu/types.hpp" // MPU data types and definitions
109 | #include "SPIbus.hpp"
110 | // ...
111 | hspi.begin(MOSI, MISO, SCLK); // initialize the SPI bus
112 | spi_device_handle_t mpu_spi_handle;
113 | hspi.addDevice(SPIMODE, CLOCK, CS_PIN, &mpu_spi_handle);
114 | ```
115 |
116 | **Note**: You can initialize/configure the bus through the _esp-idf_ API normally, it should work just fine too.
117 |
118 | Create a MPU object, setup and initialize it.
119 |
120 | ```C++
121 | MPU_t MPU; // create an object
122 | MPU.setBus(i2c0); // set communication bus, for SPI -> pass 'hspi'
123 | MPU.setAddr(mpud::MPU_I2CADDRESS_AD0_LOW); // set address or handle, for SPI -> pass 'mpu_spi_handle'
124 | MPU.testConnection() // test connection with the chip, return is a error code
125 | MPU.initialize(); // this will initialize the chip and set default configurations
126 | ```
127 |
128 | Call `set` functions to configure the chip as needed.
129 |
130 | ```C++
131 | MPU.setSampleRate(250); // in (Hz)
132 | MPU.setAccelFullScale(mpud::ACCEL_FS_4G);
133 | MPU.setGyroFullScale(mpud::GYRO_FS_500DPS);
134 | MPU.setDigitalLowPassFilter(mpud::DLPF_42HZ); // smoother data
135 | MPU.setInterruptEnabled(mpud::INT_EN_RAWDATA_READY); // enable INT pin
136 | ```
137 |
138 | Read sensor data:
139 |
140 | ```C++
141 | mpud::raw_axes_t accelRaw; // holds x, y, z axes as int16
142 | mpud::raw_axes_t gyroRaw; // holds x, y, z axes as int16
143 | MPU.acceleration(&accelRaw); // fetch raw data from the registers
144 | MPU.rotation(&gyroRaw); // fetch raw data from the registers
145 | printf("accel: %+d %+d %+d\n", accelRaw.x, accelRaw.y, accelRaw.z);
146 | printf("gyro: %+d %+d %+d\n", gyroRaw[0], gyroRaw[1], gyroRaw[2]);
147 | ```
148 |
149 | Convert to more readable formats.
150 |
151 | ```C++
152 | mpud::float_axes_t accelG = mpud::accelGravity(accelRaw, mpud::ACCEL_FS_4G); // raw data to gravity
153 | mpud::float_axes_t gyroDPS = mpud::gyroDecPerSec(gyroRaw, mpud::GYRO_FS_500DPS); // raw data to º/s
154 | printf("accel: %+.2f %+.2f %+.2f\n", accelG[0], accelG[1], accelG[2]);
155 | printf("gyro: %+.2f %+.2f %+.2f\n", gyroDPS.x, gyroDPS.y, gyroDPS.z);
156 | ```
157 |
158 | The API provides many other functions to manage and operate the sensor in its full potencial. See
159 |
160 | API Reference
161 | .
162 |
163 | ## Tests
164 |
165 | See [MPU Unit Test] for more information.
166 |
167 | [MPU Unit Test]: test/README.md
168 |
169 | ## License
170 |
171 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
172 |
173 | Copyright © 2017-2018, Natanael Josue Rabello [_natanael.rabello@outlook.com_]
174 |
175 | ---
176 |
--------------------------------------------------------------------------------
/component.mk:
--------------------------------------------------------------------------------
1 | #
2 | # Main component makefile.
3 | #
4 |
5 | COMPONENT_SRCDIRS := src .
6 |
7 |
8 | ## Compile DMP code only if enabled in menuconfig
9 | $(call compile_only_if,$(CONFIG_MPU_ENABLE_DMP),src/MPUdmp.o)
10 |
--------------------------------------------------------------------------------
/docs/Makefile:
--------------------------------------------------------------------------------
1 | # Minimal makefile for Sphinx documentation
2 | #
3 |
4 | # You can set these variables from the command line.
5 | SPHINXOPTS =
6 | SPHINXBUILD = sphinx-build
7 | SPHINXPROJ = MPUDriver
8 | SOURCEDIR = source
9 | BUILDDIR = build
10 |
11 | # Put it first so that "make" without argument is like "make help".
12 | help:
13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14 |
15 | .PHONY: help Makefile
16 |
17 | # Catch-all target: route all unknown targets to Sphinx using the new
18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19 | %: Makefile
20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
--------------------------------------------------------------------------------
/docs/doxygen/DoxygenLayout.xml:
--------------------------------------------------------------------------------
1 |