mpu9150
Fork of MPU9150 by
MPU9150_9Axis_MotionApps41.h@0:78ba160ba5f3, 2016-02-01 (annotated)
- Committer:
- syundo0730
- Date:
- Mon Feb 01 15:54:51 2016 +0000
- Revision:
- 0:78ba160ba5f3
- Child:
- 2:da1e88bafc3f
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
syundo0730 | 0:78ba160ba5f3 | 1 | #ifndef _MPU9150_9AXIS_MOTIONAPPS41_H_ |
syundo0730 | 0:78ba160ba5f3 | 2 | #define _MPU9150_9AXIS_MOTIONAPPS41_H_ |
syundo0730 | 0:78ba160ba5f3 | 3 | |
syundo0730 | 0:78ba160ba5f3 | 4 | #include "I2Cdev.h" |
syundo0730 | 0:78ba160ba5f3 | 5 | #include "helper_3dmath.h" |
syundo0730 | 0:78ba160ba5f3 | 6 | |
syundo0730 | 0:78ba160ba5f3 | 7 | // MotionApps 4.1 DMP implementation, built using the MPU-9150 "MotionFit" board |
syundo0730 | 0:78ba160ba5f3 | 8 | #define MPU9150_INCLUDE_DMP_MOTIONAPPS41 |
syundo0730 | 0:78ba160ba5f3 | 9 | |
syundo0730 | 0:78ba160ba5f3 | 10 | #include "MPU9150.h" |
syundo0730 | 0:78ba160ba5f3 | 11 | |
syundo0730 | 0:78ba160ba5f3 | 12 | // Tom Carpenter's conditional PROGMEM code |
syundo0730 | 0:78ba160ba5f3 | 13 | // http://forum.arduino.cc/index.php?topic=129407.0 |
syundo0730 | 0:78ba160ba5f3 | 14 | #ifdef __AVR__ |
syundo0730 | 0:78ba160ba5f3 | 15 | #include <avr/pgmspace.h> |
syundo0730 | 0:78ba160ba5f3 | 16 | #else |
syundo0730 | 0:78ba160ba5f3 | 17 | // Teensy 3.0 library conditional PROGMEM code from Paul Stoffregen |
syundo0730 | 0:78ba160ba5f3 | 18 | #ifndef __PGMSPACE_H_ |
syundo0730 | 0:78ba160ba5f3 | 19 | #define __PGMSPACE_H_ 1 |
syundo0730 | 0:78ba160ba5f3 | 20 | #include <inttypes.h> |
syundo0730 | 0:78ba160ba5f3 | 21 | |
syundo0730 | 0:78ba160ba5f3 | 22 | #define PROGMEM |
syundo0730 | 0:78ba160ba5f3 | 23 | #define PGM_P const char * |
syundo0730 | 0:78ba160ba5f3 | 24 | #define PSTR(str) (str) |
syundo0730 | 0:78ba160ba5f3 | 25 | #define F(x) x |
syundo0730 | 0:78ba160ba5f3 | 26 | |
syundo0730 | 0:78ba160ba5f3 | 27 | typedef void prog_void; |
syundo0730 | 0:78ba160ba5f3 | 28 | typedef char prog_char; |
syundo0730 | 0:78ba160ba5f3 | 29 | typedef unsigned char prog_uchar; |
syundo0730 | 0:78ba160ba5f3 | 30 | typedef int8_t prog_int8_t; |
syundo0730 | 0:78ba160ba5f3 | 31 | typedef uint8_t prog_uint8_t; |
syundo0730 | 0:78ba160ba5f3 | 32 | typedef int16_t prog_int16_t; |
syundo0730 | 0:78ba160ba5f3 | 33 | typedef uint16_t prog_uint16_t; |
syundo0730 | 0:78ba160ba5f3 | 34 | typedef int32_t prog_int32_t; |
syundo0730 | 0:78ba160ba5f3 | 35 | typedef uint32_t prog_uint32_t; |
syundo0730 | 0:78ba160ba5f3 | 36 | |
syundo0730 | 0:78ba160ba5f3 | 37 | #define strcpy_P(dest, src) strcpy((dest), (src)) |
syundo0730 | 0:78ba160ba5f3 | 38 | #define strcat_P(dest, src) strcat((dest), (src)) |
syundo0730 | 0:78ba160ba5f3 | 39 | #define strcmp_P(a, b) strcmp((a), (b)) |
syundo0730 | 0:78ba160ba5f3 | 40 | |
syundo0730 | 0:78ba160ba5f3 | 41 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) |
syundo0730 | 0:78ba160ba5f3 | 42 | #define pgm_read_word(addr) (*(const unsigned short *)(addr)) |
syundo0730 | 0:78ba160ba5f3 | 43 | #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) |
syundo0730 | 0:78ba160ba5f3 | 44 | #define pgm_read_float(addr) (*(const float *)(addr)) |
syundo0730 | 0:78ba160ba5f3 | 45 | |
syundo0730 | 0:78ba160ba5f3 | 46 | #define pgm_read_byte_near(addr) pgm_read_byte(addr) |
syundo0730 | 0:78ba160ba5f3 | 47 | #define pgm_read_word_near(addr) pgm_read_word(addr) |
syundo0730 | 0:78ba160ba5f3 | 48 | #define pgm_read_dword_near(addr) pgm_read_dword(addr) |
syundo0730 | 0:78ba160ba5f3 | 49 | #define pgm_read_float_near(addr) pgm_read_float(addr) |
syundo0730 | 0:78ba160ba5f3 | 50 | #define pgm_read_byte_far(addr) pgm_read_byte(addr) |
syundo0730 | 0:78ba160ba5f3 | 51 | #define pgm_read_word_far(addr) pgm_read_word(addr) |
syundo0730 | 0:78ba160ba5f3 | 52 | #define pgm_read_dword_far(addr) pgm_read_dword(addr) |
syundo0730 | 0:78ba160ba5f3 | 53 | #define pgm_read_float_far(addr) pgm_read_float(addr) |
syundo0730 | 0:78ba160ba5f3 | 54 | #endif |
syundo0730 | 0:78ba160ba5f3 | 55 | #endif |
syundo0730 | 0:78ba160ba5f3 | 56 | |
syundo0730 | 0:78ba160ba5f3 | 57 | // NOTE! Enabling DEBUG adds about 3.3kB to the flash program size. |
syundo0730 | 0:78ba160ba5f3 | 58 | // Debug output is now working even on ATMega328P MCUs (e.g. Arduino Uno) |
syundo0730 | 0:78ba160ba5f3 | 59 | // after moving string constants to flash memory storage using the F() |
syundo0730 | 0:78ba160ba5f3 | 60 | // compiler macro (Arduino IDE 1.0+ required). |
syundo0730 | 0:78ba160ba5f3 | 61 | |
syundo0730 | 0:78ba160ba5f3 | 62 | //#define DEBUG |
syundo0730 | 0:78ba160ba5f3 | 63 | #ifdef DEBUG |
syundo0730 | 0:78ba160ba5f3 | 64 | #include "ArduinoSerial.h" |
syundo0730 | 0:78ba160ba5f3 | 65 | ArduinoSerial arduinoSerial; |
syundo0730 | 0:78ba160ba5f3 | 66 | #define DEBUG_PRINT(x) arduinoSerial.print(x) |
syundo0730 | 0:78ba160ba5f3 | 67 | #define DEBUG_PRINTF(x, y) arduinoSerial.print(x, y) |
syundo0730 | 0:78ba160ba5f3 | 68 | #define DEBUG_PRINTLN(x) arduinoSerial.println(x) |
syundo0730 | 0:78ba160ba5f3 | 69 | #define DEBUG_PRINTLNF(x, y) arduinoSerial.println(x, y) |
syundo0730 | 0:78ba160ba5f3 | 70 | #else |
syundo0730 | 0:78ba160ba5f3 | 71 | #define DEBUG_PRINT(x) |
syundo0730 | 0:78ba160ba5f3 | 72 | #define DEBUG_PRINTF(x, y) |
syundo0730 | 0:78ba160ba5f3 | 73 | #define DEBUG_PRINTLN(x) |
syundo0730 | 0:78ba160ba5f3 | 74 | #define DEBUG_PRINTLNF(x, y) |
syundo0730 | 0:78ba160ba5f3 | 75 | #endif |
syundo0730 | 0:78ba160ba5f3 | 76 | |
syundo0730 | 0:78ba160ba5f3 | 77 | #define MPU9150_DMP_CODE_SIZE 1962 // dmpMemory[] |
syundo0730 | 0:78ba160ba5f3 | 78 | #define MPU9150_DMP_CONFIG_SIZE 232 // dmpConfig[] |
syundo0730 | 0:78ba160ba5f3 | 79 | #define MPU9150_DMP_UPDATES_SIZE 140 // dmpUpdates[] |
syundo0730 | 0:78ba160ba5f3 | 80 | |
syundo0730 | 0:78ba160ba5f3 | 81 | /* ================================================================================================ * |
syundo0730 | 0:78ba160ba5f3 | 82 | | Default MotionApps v4.1 48-byte FIFO packet structure: | |
syundo0730 | 0:78ba160ba5f3 | 83 | | | |
syundo0730 | 0:78ba160ba5f3 | 84 | | [QUAT W][ ][QUAT X][ ][QUAT Y][ ][QUAT Z][ ][GYRO X][ ][GYRO Y][ ] | |
syundo0730 | 0:78ba160ba5f3 | 85 | | 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
syundo0730 | 0:78ba160ba5f3 | 86 | | | |
syundo0730 | 0:78ba160ba5f3 | 87 | | [GYRO Z][ ][MAG X ][MAG Y ][MAG Z ][ACC X ][ ][ACC Y ][ ][ACC Z ][ ][ ] | |
syundo0730 | 0:78ba160ba5f3 | 88 | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
syundo0730 | 0:78ba160ba5f3 | 89 | * ================================================================================================ */ |
syundo0730 | 0:78ba160ba5f3 | 90 | |
syundo0730 | 0:78ba160ba5f3 | 91 | // this block of memory gets written to the MPU on start-up, and it seems |
syundo0730 | 0:78ba160ba5f3 | 92 | // to be volatile memory, so it has to be done each time (it only takes ~1 |
syundo0730 | 0:78ba160ba5f3 | 93 | // second though) |
syundo0730 | 0:78ba160ba5f3 | 94 | const prog_uchar dmpMemory[MPU9150_DMP_CODE_SIZE] PROGMEM = { |
syundo0730 | 0:78ba160ba5f3 | 95 | // bank 0, 256 bytes |
syundo0730 | 0:78ba160ba5f3 | 96 | 0xFB, 0x00, 0x00, 0x3E, 0x00, 0x0B, 0x00, 0x36, 0x00, 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 97 | 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0xFA, 0x80, 0x00, 0x0B, 0x12, 0x82, 0x00, 0x01, |
syundo0730 | 0:78ba160ba5f3 | 98 | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 99 | 0x00, 0x28, 0x00, 0x00, 0xFF, 0xFF, 0x45, 0x81, 0xFF, 0xFF, 0xFA, 0x72, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 100 | 0x00, 0x00, 0x03, 0xE8, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x7F, 0xFF, 0xFF, 0xFE, 0x80, 0x01, |
syundo0730 | 0:78ba160ba5f3 | 101 | 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 102 | 0x00, 0x3E, 0x03, 0x30, 0x40, 0x00, 0x00, 0x00, 0x02, 0xCA, 0xE3, 0x09, 0x3E, 0x80, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 103 | 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 104 | 0x41, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x0B, 0x2A, 0x00, 0x00, 0x16, 0x55, 0x00, 0x00, 0x21, 0x82, |
syundo0730 | 0:78ba160ba5f3 | 105 | 0xFD, 0x87, 0x26, 0x50, 0xFD, 0x80, 0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x05, 0x80, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 106 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 107 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x6F, 0x00, 0x02, 0x65, 0x32, 0x00, 0x00, 0x5E, 0xC0, |
syundo0730 | 0:78ba160ba5f3 | 108 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 109 | 0xFB, 0x8C, 0x6F, 0x5D, 0xFD, 0x5D, 0x08, 0xD9, 0x00, 0x7C, 0x73, 0x3B, 0x00, 0x6C, 0x12, 0xCC, |
syundo0730 | 0:78ba160ba5f3 | 110 | 0x32, 0x00, 0x13, 0x9D, 0x32, 0x00, 0xD0, 0xD6, 0x32, 0x00, 0x08, 0x00, 0x40, 0x00, 0x01, 0xF4, |
syundo0730 | 0:78ba160ba5f3 | 111 | 0xFF, 0xE6, 0x80, 0x79, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0, 0xD6, 0x00, 0x00, 0x27, 0x10, |
syundo0730 | 0:78ba160ba5f3 | 112 | |
syundo0730 | 0:78ba160ba5f3 | 113 | // bank 1, 256 bytes |
syundo0730 | 0:78ba160ba5f3 | 114 | 0xFB, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 115 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 116 | 0x00, 0x00, 0xFA, 0x36, 0xFF, 0xBC, 0x30, 0x8E, 0x00, 0x05, 0xFB, 0xF0, 0xFF, 0xD9, 0x5B, 0xC8, |
syundo0730 | 0:78ba160ba5f3 | 117 | 0xFF, 0xD0, 0x9A, 0xBE, 0x00, 0x00, 0x10, 0xA9, 0xFF, 0xF4, 0x1E, 0xB2, 0x00, 0xCE, 0xBB, 0xF7, |
syundo0730 | 0:78ba160ba5f3 | 118 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0x02, 0x02, 0x00, 0x00, 0x0C, |
syundo0730 | 0:78ba160ba5f3 | 119 | 0xFF, 0xC2, 0x80, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0xCF, 0x80, 0x00, 0x40, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 120 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x14, |
syundo0730 | 0:78ba160ba5f3 | 121 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 122 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 123 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 124 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x3F, 0x68, 0xB6, 0x79, 0x35, 0x28, 0xBC, 0xC6, 0x7E, 0xD1, 0x6C, |
syundo0730 | 0:78ba160ba5f3 | 125 | 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2, 0x6A, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 126 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x30, |
syundo0730 | 0:78ba160ba5f3 | 127 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 128 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 129 | 0x00, 0x00, 0x25, 0x4D, 0x00, 0x2F, 0x70, 0x6D, 0x00, 0x00, 0x05, 0xAE, 0x00, 0x0C, 0x02, 0xD0, |
syundo0730 | 0:78ba160ba5f3 | 130 | |
syundo0730 | 0:78ba160ba5f3 | 131 | // bank 2, 256 bytes |
syundo0730 | 0:78ba160ba5f3 | 132 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x54, 0xFF, 0xEF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 133 | 0x00, 0x00, 0x01, 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x01, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 134 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0xFF, 0xEF, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 135 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 136 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 137 | 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 138 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 139 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 141 | 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 142 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 143 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 144 | 0x00, 0x1B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 145 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 146 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x78, 0xA2, |
syundo0730 | 0:78ba160ba5f3 | 147 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 148 | |
syundo0730 | 0:78ba160ba5f3 | 149 | // bank 3, 256 bytes |
syundo0730 | 0:78ba160ba5f3 | 150 | 0xD8, 0xDC, 0xF4, 0xD8, 0xB9, 0xAB, 0xF3, 0xF8, 0xFA, 0xF1, 0xBA, 0xA2, 0xDE, 0xB2, 0xB8, 0xB4, |
syundo0730 | 0:78ba160ba5f3 | 151 | 0xA8, 0x81, 0x98, 0xF7, 0x4A, 0x90, 0x7F, 0x91, 0x6A, 0xF3, 0xF9, 0xDB, 0xA8, 0xF9, 0xB0, 0xBA, |
syundo0730 | 0:78ba160ba5f3 | 152 | 0xA0, 0x80, 0xF2, 0xCE, 0x81, 0xF3, 0xC2, 0xF1, 0xC1, 0xF2, 0xC3, 0xF3, 0xCC, 0xA2, 0xB2, 0x80, |
syundo0730 | 0:78ba160ba5f3 | 153 | 0xF1, 0xC6, 0xD8, 0x80, 0xBA, 0xA7, 0xDF, 0xDF, 0xDF, 0xF2, 0xA7, 0xC3, 0xCB, 0xC5, 0xB6, 0xF0, |
syundo0730 | 0:78ba160ba5f3 | 154 | 0x87, 0xA2, 0x94, 0x24, 0x48, 0x70, 0x3C, 0x95, 0x40, 0x68, 0x34, 0x58, 0x9B, 0x78, 0xA2, 0xF1, |
syundo0730 | 0:78ba160ba5f3 | 155 | 0x83, 0x92, 0x2D, 0x55, 0x7D, 0xD8, 0xB1, 0xB4, 0xB8, 0xA1, 0xD0, 0x91, 0x80, 0xF2, 0x70, 0xF3, |
syundo0730 | 0:78ba160ba5f3 | 156 | 0x70, 0xF2, 0x7C, 0x80, 0xA8, 0xF1, 0x01, 0xB0, 0x98, 0x87, 0xD9, 0x43, 0xD8, 0x86, 0xC9, 0x88, |
syundo0730 | 0:78ba160ba5f3 | 157 | 0xBA, 0xA1, 0xF2, 0x0E, 0xB8, 0x97, 0x80, 0xF1, 0xA9, 0xDF, 0xDF, 0xDF, 0xAA, 0xDF, 0xDF, 0xDF, |
syundo0730 | 0:78ba160ba5f3 | 158 | 0xF2, 0xAA, 0xC5, 0xCD, 0xC7, 0xA9, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, 0x97, 0xF1, 0xA9, 0x89, |
syundo0730 | 0:78ba160ba5f3 | 159 | 0x26, 0x46, 0x66, 0xB0, 0xB4, 0xBA, 0x80, 0xAC, 0xDE, 0xF2, 0xCA, 0xF1, 0xB2, 0x8C, 0x02, 0xA9, |
syundo0730 | 0:78ba160ba5f3 | 160 | 0xB6, 0x98, 0x00, 0x89, 0x0E, 0x16, 0x1E, 0xB8, 0xA9, 0xB4, 0x99, 0x2C, 0x54, 0x7C, 0xB0, 0x8A, |
syundo0730 | 0:78ba160ba5f3 | 161 | 0xA8, 0x96, 0x36, 0x56, 0x76, 0xF1, 0xB9, 0xAF, 0xB4, 0xB0, 0x83, 0xC0, 0xB8, 0xA8, 0x97, 0x11, |
syundo0730 | 0:78ba160ba5f3 | 162 | 0xB1, 0x8F, 0x98, 0xB9, 0xAF, 0xF0, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0xF1, 0xA3, 0x29, 0x55, |
syundo0730 | 0:78ba160ba5f3 | 163 | 0x7D, 0xAF, 0x83, 0xB5, 0x93, 0xF0, 0x00, 0x28, 0x50, 0xF5, 0xBA, 0xAD, 0x8F, 0x9F, 0x28, 0x54, |
syundo0730 | 0:78ba160ba5f3 | 164 | 0x7C, 0xB9, 0xF1, 0xA3, 0x86, 0x9F, 0x61, 0xA6, 0xDA, 0xDE, 0xDF, 0xDB, 0xB2, 0xB6, 0x8E, 0x9D, |
syundo0730 | 0:78ba160ba5f3 | 165 | 0xAE, 0xF5, 0x60, 0x68, 0x70, 0xB1, 0xB5, 0xF1, 0xDA, 0xA6, 0xDF, 0xD9, 0xA6, 0xFA, 0xA3, 0x86, |
syundo0730 | 0:78ba160ba5f3 | 166 | |
syundo0730 | 0:78ba160ba5f3 | 167 | // bank 4, 256 bytes |
syundo0730 | 0:78ba160ba5f3 | 168 | 0x96, 0xDB, 0x31, 0xA6, 0xD9, 0xF8, 0xDF, 0xBA, 0xA6, 0x8F, 0xC2, 0xC5, 0xC7, 0xB2, 0x8C, 0xC1, |
syundo0730 | 0:78ba160ba5f3 | 169 | 0xB8, 0xA2, 0xDF, 0xDF, 0xDF, 0xA3, 0xDF, 0xDF, 0xDF, 0xD8, 0xD8, 0xF1, 0xB8, 0xA8, 0xB2, 0x86, |
syundo0730 | 0:78ba160ba5f3 | 170 | 0xB4, 0x98, 0x0D, 0x35, 0x5D, 0xB8, 0xAA, 0x98, 0xB0, 0x87, 0x2D, 0x35, 0x3D, 0xB2, 0xB6, 0xBA, |
syundo0730 | 0:78ba160ba5f3 | 171 | 0xAF, 0x8C, 0x96, 0x19, 0x8F, 0x9F, 0xA7, 0x0E, 0x16, 0x1E, 0xB4, 0x9A, 0xB8, 0xAA, 0x87, 0x2C, |
syundo0730 | 0:78ba160ba5f3 | 172 | 0x54, 0x7C, 0xB9, 0xA3, 0xDE, 0xDF, 0xDF, 0xA3, 0xB1, 0x80, 0xF2, 0xC4, 0xCD, 0xC9, 0xF1, 0xB8, |
syundo0730 | 0:78ba160ba5f3 | 173 | 0xA9, 0xB4, 0x99, 0x83, 0x0D, 0x35, 0x5D, 0x89, 0xB9, 0xA3, 0x2D, 0x55, 0x7D, 0xB5, 0x93, 0xA3, |
syundo0730 | 0:78ba160ba5f3 | 174 | 0x0E, 0x16, 0x1E, 0xA9, 0x2C, 0x54, 0x7C, 0xB8, 0xB4, 0xB0, 0xF1, 0x97, 0x83, 0xA8, 0x11, 0x84, |
syundo0730 | 0:78ba160ba5f3 | 175 | 0xA5, 0x09, 0x98, 0xA3, 0x83, 0xF0, 0xDA, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0xD8, 0xF1, 0xA5, |
syundo0730 | 0:78ba160ba5f3 | 176 | 0x29, 0x55, 0x7D, 0xA5, 0x85, 0x95, 0x02, 0x1A, 0x2E, 0x3A, 0x56, 0x5A, 0x40, 0x48, 0xF9, 0xF3, |
syundo0730 | 0:78ba160ba5f3 | 177 | 0xA3, 0xD9, 0xF8, 0xF0, 0x98, 0x83, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0x97, 0x82, 0xA8, 0xF1, |
syundo0730 | 0:78ba160ba5f3 | 178 | 0x11, 0xF0, 0x98, 0xA2, 0x24, 0x08, 0x44, 0x10, 0x64, 0x18, 0xDA, 0xF3, 0xDE, 0xD8, 0x83, 0xA5, |
syundo0730 | 0:78ba160ba5f3 | 179 | 0x94, 0x01, 0xD9, 0xA3, 0x02, 0xF1, 0xA2, 0xC3, 0xC5, 0xC7, 0xD8, 0xF1, 0x84, 0x92, 0xA2, 0x4D, |
syundo0730 | 0:78ba160ba5f3 | 180 | 0xDA, 0x2A, 0xD8, 0x48, 0x69, 0xD9, 0x2A, 0xD8, 0x68, 0x55, 0xDA, 0x32, 0xD8, 0x50, 0x71, 0xD9, |
syundo0730 | 0:78ba160ba5f3 | 181 | 0x32, 0xD8, 0x70, 0x5D, 0xDA, 0x3A, 0xD8, 0x58, 0x79, 0xD9, 0x3A, 0xD8, 0x78, 0x93, 0xA3, 0x4D, |
syundo0730 | 0:78ba160ba5f3 | 182 | 0xDA, 0x2A, 0xD8, 0x48, 0x69, 0xD9, 0x2A, 0xD8, 0x68, 0x55, 0xDA, 0x32, 0xD8, 0x50, 0x71, 0xD9, |
syundo0730 | 0:78ba160ba5f3 | 183 | 0x32, 0xD8, 0x70, 0x5D, 0xDA, 0x3A, 0xD8, 0x58, 0x79, 0xD9, 0x3A, 0xD8, 0x78, 0xA8, 0x8A, 0x9A, |
syundo0730 | 0:78ba160ba5f3 | 184 | |
syundo0730 | 0:78ba160ba5f3 | 185 | // bank 5, 256 bytes |
syundo0730 | 0:78ba160ba5f3 | 186 | 0xF0, 0x28, 0x50, 0x78, 0x9E, 0xF3, 0x88, 0x18, 0xF1, 0x9F, 0x1D, 0x98, 0xA8, 0xD9, 0x08, 0xD8, |
syundo0730 | 0:78ba160ba5f3 | 187 | 0xC8, 0x9F, 0x12, 0x9E, 0xF3, 0x15, 0xA8, 0xDA, 0x12, 0x10, 0xD8, 0xF1, 0xAF, 0xC8, 0x97, 0x87, |
syundo0730 | 0:78ba160ba5f3 | 188 | 0x34, 0xB5, 0xB9, 0x94, 0xA4, 0x21, 0xF3, 0xD9, 0x22, 0xD8, 0xF2, 0x2D, 0xF3, 0xD9, 0x2A, 0xD8, |
syundo0730 | 0:78ba160ba5f3 | 189 | 0xF2, 0x35, 0xF3, 0xD9, 0x32, 0xD8, 0x81, 0xA4, 0x60, 0x60, 0x61, 0xD9, 0x61, 0xD8, 0x6C, 0x68, |
syundo0730 | 0:78ba160ba5f3 | 190 | 0x69, 0xD9, 0x69, 0xD8, 0x74, 0x70, 0x71, 0xD9, 0x71, 0xD8, 0xB1, 0xA3, 0x84, 0x19, 0x3D, 0x5D, |
syundo0730 | 0:78ba160ba5f3 | 191 | 0xA3, 0x83, 0x1A, 0x3E, 0x5E, 0x93, 0x10, 0x30, 0x81, 0x10, 0x11, 0xB8, 0xB0, 0xAF, 0x8F, 0x94, |
syundo0730 | 0:78ba160ba5f3 | 192 | 0xF2, 0xDA, 0x3E, 0xD8, 0xB4, 0x9A, 0xA8, 0x87, 0x29, 0xDA, 0xF8, 0xD8, 0x87, 0x9A, 0x35, 0xDA, |
syundo0730 | 0:78ba160ba5f3 | 193 | 0xF8, 0xD8, 0x87, 0x9A, 0x3D, 0xDA, 0xF8, 0xD8, 0xB1, 0xB9, 0xA4, 0x98, 0x85, 0x02, 0x2E, 0x56, |
syundo0730 | 0:78ba160ba5f3 | 194 | 0xA5, 0x81, 0x00, 0x0C, 0x14, 0xA3, 0x97, 0xB0, 0x8A, 0xF1, 0x2D, 0xD9, 0x28, 0xD8, 0x4D, 0xD9, |
syundo0730 | 0:78ba160ba5f3 | 195 | 0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0xB1, 0x84, 0x0D, 0xDA, 0x0E, 0xD8, 0xA3, 0x29, 0x83, 0xDA, |
syundo0730 | 0:78ba160ba5f3 | 196 | 0x2C, 0x0E, 0xD8, 0xA3, 0x84, 0x49, 0x83, 0xDA, 0x2C, 0x4C, 0x0E, 0xD8, 0xB8, 0xB0, 0x97, 0x86, |
syundo0730 | 0:78ba160ba5f3 | 197 | 0xA8, 0x31, 0x9B, 0x06, 0x99, 0x07, 0xAB, 0x97, 0x28, 0x88, 0x9B, 0xF0, 0x0C, 0x20, 0x14, 0x40, |
syundo0730 | 0:78ba160ba5f3 | 198 | 0xB9, 0xA3, 0x8A, 0xC3, 0xC5, 0xC7, 0x9A, 0xA3, 0x28, 0x50, 0x78, 0xF1, 0xB5, 0x93, 0x01, 0xD9, |
syundo0730 | 0:78ba160ba5f3 | 199 | 0xDF, 0xDF, 0xDF, 0xD8, 0xB8, 0xB4, 0xA8, 0x8C, 0x9C, 0xF0, 0x04, 0x28, 0x51, 0x79, 0x1D, 0x30, |
syundo0730 | 0:78ba160ba5f3 | 200 | 0x14, 0x38, 0xB2, 0x82, 0xAB, 0xD0, 0x98, 0x2C, 0x50, 0x50, 0x78, 0x78, 0x9B, 0xF1, 0x1A, 0xB0, |
syundo0730 | 0:78ba160ba5f3 | 201 | 0xF0, 0xB1, 0x83, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0xB0, 0x8B, 0x29, 0x51, 0x79, 0xB1, 0x83, 0x24, |
syundo0730 | 0:78ba160ba5f3 | 202 | |
syundo0730 | 0:78ba160ba5f3 | 203 | // bank 6, 256 bytes |
syundo0730 | 0:78ba160ba5f3 | 204 | 0x70, 0x59, 0xB0, 0x8B, 0x20, 0x58, 0x71, 0xB1, 0x83, 0x44, 0x69, 0x38, 0xB0, 0x8B, 0x39, 0x40, |
syundo0730 | 0:78ba160ba5f3 | 205 | 0x68, 0xB1, 0x83, 0x64, 0x48, 0x31, 0xB0, 0x8B, 0x30, 0x49, 0x60, 0xA5, 0x88, 0x20, 0x09, 0x71, |
syundo0730 | 0:78ba160ba5f3 | 206 | 0x58, 0x44, 0x68, 0x11, 0x39, 0x64, 0x49, 0x30, 0x19, 0xF1, 0xAC, 0x00, 0x2C, 0x54, 0x7C, 0xF0, |
syundo0730 | 0:78ba160ba5f3 | 207 | 0x8C, 0xA8, 0x04, 0x28, 0x50, 0x78, 0xF1, 0x88, 0x97, 0x26, 0xA8, 0x59, 0x98, 0xAC, 0x8C, 0x02, |
syundo0730 | 0:78ba160ba5f3 | 208 | 0x26, 0x46, 0x66, 0xF0, 0x89, 0x9C, 0xA8, 0x29, 0x51, 0x79, 0x24, 0x70, 0x59, 0x44, 0x69, 0x38, |
syundo0730 | 0:78ba160ba5f3 | 209 | 0x64, 0x48, 0x31, 0xA9, 0x88, 0x09, 0x20, 0x59, 0x70, 0xAB, 0x11, 0x38, 0x40, 0x69, 0xA8, 0x19, |
syundo0730 | 0:78ba160ba5f3 | 210 | 0x31, 0x48, 0x60, 0x8C, 0xA8, 0x3C, 0x41, 0x5C, 0x20, 0x7C, 0x00, 0xF1, 0x87, 0x98, 0x19, 0x86, |
syundo0730 | 0:78ba160ba5f3 | 211 | 0xA8, 0x6E, 0x76, 0x7E, 0xA9, 0x99, 0x88, 0x2D, 0x55, 0x7D, 0x9E, 0xB9, 0xA3, 0x8A, 0x22, 0x8A, |
syundo0730 | 0:78ba160ba5f3 | 212 | 0x6E, 0x8A, 0x56, 0x8A, 0x5E, 0x9F, 0xB1, 0x83, 0x06, 0x26, 0x46, 0x66, 0x0E, 0x2E, 0x4E, 0x6E, |
syundo0730 | 0:78ba160ba5f3 | 213 | 0x9D, 0xB8, 0xAD, 0x00, 0x2C, 0x54, 0x7C, 0xF2, 0xB1, 0x8C, 0xB4, 0x99, 0xB9, 0xA3, 0x2D, 0x55, |
syundo0730 | 0:78ba160ba5f3 | 214 | 0x7D, 0x81, 0x91, 0xAC, 0x38, 0xAD, 0x3A, 0xB5, 0x83, 0x91, 0xAC, 0x2D, 0xD9, 0x28, 0xD8, 0x4D, |
syundo0730 | 0:78ba160ba5f3 | 215 | 0xD9, 0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0x8C, 0x9D, 0xAE, 0x29, 0xD9, 0x04, 0xAE, 0xD8, 0x51, |
syundo0730 | 0:78ba160ba5f3 | 216 | 0xD9, 0x04, 0xAE, 0xD8, 0x79, 0xD9, 0x04, 0xD8, 0x81, 0xF3, 0x9D, 0xAD, 0x00, 0x8D, 0xAE, 0x19, |
syundo0730 | 0:78ba160ba5f3 | 217 | 0x81, 0xAD, 0xD9, 0x01, 0xD8, 0xF2, 0xAE, 0xDA, 0x26, 0xD8, 0x8E, 0x91, 0x29, 0x83, 0xA7, 0xD9, |
syundo0730 | 0:78ba160ba5f3 | 218 | 0xAD, 0xAD, 0xAD, 0xAD, 0xF3, 0x2A, 0xD8, 0xD8, 0xF1, 0xB0, 0xAC, 0x89, 0x91, 0x3E, 0x5E, 0x76, |
syundo0730 | 0:78ba160ba5f3 | 219 | 0xF3, 0xAC, 0x2E, 0x2E, 0xF1, 0xB1, 0x8C, 0x5A, 0x9C, 0xAC, 0x2C, 0x28, 0x28, 0x28, 0x9C, 0xAC, |
syundo0730 | 0:78ba160ba5f3 | 220 | |
syundo0730 | 0:78ba160ba5f3 | 221 | // bank 7, 170 bytes (remainder) |
syundo0730 | 0:78ba160ba5f3 | 222 | 0x30, 0x18, 0xA8, 0x98, 0x81, 0x28, 0x34, 0x3C, 0x97, 0x24, 0xA7, 0x28, 0x34, 0x3C, 0x9C, 0x24, |
syundo0730 | 0:78ba160ba5f3 | 223 | 0xF2, 0xB0, 0x89, 0xAC, 0x91, 0x2C, 0x4C, 0x6C, 0x8A, 0x9B, 0x2D, 0xD9, 0xD8, 0xD8, 0x51, 0xD9, |
syundo0730 | 0:78ba160ba5f3 | 224 | 0xD8, 0xD8, 0x79, 0xD9, 0xD8, 0xD8, 0xF1, 0x9E, 0x88, 0xA3, 0x31, 0xDA, 0xD8, 0xD8, 0x91, 0x2D, |
syundo0730 | 0:78ba160ba5f3 | 225 | 0xD9, 0x28, 0xD8, 0x4D, 0xD9, 0x48, 0xD8, 0x6D, 0xD9, 0x68, 0xD8, 0xB1, 0x83, 0x93, 0x35, 0x3D, |
syundo0730 | 0:78ba160ba5f3 | 226 | 0x80, 0x25, 0xDA, 0xD8, 0xD8, 0x85, 0x69, 0xDA, 0xD8, 0xD8, 0xB4, 0x93, 0x81, 0xA3, 0x28, 0x34, |
syundo0730 | 0:78ba160ba5f3 | 227 | 0x3C, 0xF3, 0xAB, 0x8B, 0xA3, 0x91, 0xB6, 0x09, 0xB4, 0xD9, 0xAB, 0xDE, 0xB0, 0x87, 0x9C, 0xB9, |
syundo0730 | 0:78ba160ba5f3 | 228 | 0xA3, 0xDD, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x95, 0xF1, 0xA3, 0xA3, 0xA3, 0x9D, 0xF1, 0xA3, 0xA3, |
syundo0730 | 0:78ba160ba5f3 | 229 | 0xA3, 0xA3, 0xF2, 0xA3, 0xB4, 0x90, 0x80, 0xF2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, |
syundo0730 | 0:78ba160ba5f3 | 230 | 0xA3, 0xA3, 0xB2, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xA3, 0xB0, 0x87, 0xB5, 0x99, 0xF1, 0xA3, 0xA3, |
syundo0730 | 0:78ba160ba5f3 | 231 | 0xA3, 0x98, 0xF1, 0xA3, 0xA3, 0xA3, 0xA3, 0x97, 0xA3, 0xA3, 0xA3, 0xA3, 0xF3, 0x9B, 0xA3, 0xA3, |
syundo0730 | 0:78ba160ba5f3 | 232 | 0xDC, 0xB9, 0xA7, 0xF1, 0x26, 0x26, 0x26, 0xD8, 0xD8, 0xFF |
syundo0730 | 0:78ba160ba5f3 | 233 | }; |
syundo0730 | 0:78ba160ba5f3 | 234 | |
syundo0730 | 0:78ba160ba5f3 | 235 | const prog_uchar dmpConfig[MPU9150_DMP_CONFIG_SIZE] PROGMEM = { |
syundo0730 | 0:78ba160ba5f3 | 236 | // BANK OFFSET LENGTH [DATA] |
syundo0730 | 0:78ba160ba5f3 | 237 | 0x02, 0xEC, 0x04, 0x00, 0x47, 0x7D, 0x1A, // ? |
syundo0730 | 0:78ba160ba5f3 | 238 | 0x03, 0x82, 0x03, 0x4C, 0xCD, 0x6C, // FCFG_1 inv_set_gyro_calibration |
syundo0730 | 0:78ba160ba5f3 | 239 | 0x03, 0xB2, 0x03, 0x36, 0x56, 0x76, // FCFG_3 inv_set_gyro_calibration |
syundo0730 | 0:78ba160ba5f3 | 240 | 0x00, 0x68, 0x04, 0x02, 0xCA, 0xE3, 0x09, // D_0_104 inv_set_gyro_calibration |
syundo0730 | 0:78ba160ba5f3 | 241 | 0x01, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // D_1_152 inv_set_accel_calibration |
syundo0730 | 0:78ba160ba5f3 | 242 | 0x03, 0x86, 0x03, 0x0C, 0xC9, 0x2C, // FCFG_2 inv_set_accel_calibration |
syundo0730 | 0:78ba160ba5f3 | 243 | 0x03, 0x90, 0x03, 0x26, 0x46, 0x66, // (continued)...FCFG_2 inv_set_accel_calibration |
syundo0730 | 0:78ba160ba5f3 | 244 | 0x00, 0x6C, 0x02, 0x40, 0x00, // D_0_108 inv_set_accel_calibration |
syundo0730 | 0:78ba160ba5f3 | 245 | |
syundo0730 | 0:78ba160ba5f3 | 246 | 0x02, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_00 inv_set_compass_calibration |
syundo0730 | 0:78ba160ba5f3 | 247 | 0x02, 0x44, 0x04, 0x40, 0x00, 0x00, 0x00, // CPASS_MTX_01 |
syundo0730 | 0:78ba160ba5f3 | 248 | 0x02, 0x48, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_02 |
syundo0730 | 0:78ba160ba5f3 | 249 | 0x02, 0x4C, 0x04, 0x40, 0x00, 0x00, 0x00, // CPASS_MTX_10 |
syundo0730 | 0:78ba160ba5f3 | 250 | 0x02, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_11 |
syundo0730 | 0:78ba160ba5f3 | 251 | 0x02, 0x54, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_12 |
syundo0730 | 0:78ba160ba5f3 | 252 | 0x02, 0x58, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_20 |
syundo0730 | 0:78ba160ba5f3 | 253 | 0x02, 0x5C, 0x04, 0x00, 0x00, 0x00, 0x00, // CPASS_MTX_21 |
syundo0730 | 0:78ba160ba5f3 | 254 | 0x02, 0xBC, 0x04, 0xC0, 0x00, 0x00, 0x00, // CPASS_MTX_22 |
syundo0730 | 0:78ba160ba5f3 | 255 | |
syundo0730 | 0:78ba160ba5f3 | 256 | 0x01, 0xEC, 0x04, 0x00, 0x00, 0x40, 0x00, // D_1_236 inv_apply_endian_accel |
syundo0730 | 0:78ba160ba5f3 | 257 | 0x03, 0x86, 0x06, 0x0C, 0xC9, 0x2C, 0x97, 0x97, 0x97, // FCFG_2 inv_set_mpu_sensors |
syundo0730 | 0:78ba160ba5f3 | 258 | 0x04, 0x22, 0x03, 0x0D, 0x35, 0x5D, // CFG_MOTION_BIAS inv_turn_on_bias_from_no_motion |
syundo0730 | 0:78ba160ba5f3 | 259 | 0x00, 0xA3, 0x01, 0x00, // ? |
syundo0730 | 0:78ba160ba5f3 | 260 | 0x04, 0x29, 0x04, 0x87, 0x2D, 0x35, 0x3D, // FCFG_5 inv_set_bias_update |
syundo0730 | 0:78ba160ba5f3 | 261 | 0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // CFG_8 inv_send_quaternion |
syundo0730 | 0:78ba160ba5f3 | 262 | 0x07, 0x9F, 0x01, 0x30, // CFG_16 inv_set_footer |
syundo0730 | 0:78ba160ba5f3 | 263 | 0x07, 0x67, 0x01, 0x9A, // CFG_GYRO_SOURCE inv_send_gyro |
syundo0730 | 0:78ba160ba5f3 | 264 | 0x07, 0x68, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_9 inv_send_gyro -> inv_construct3_fifo |
syundo0730 | 0:78ba160ba5f3 | 265 | 0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // ? |
syundo0730 | 0:78ba160ba5f3 | 266 | 0x02, 0x0C, 0x04, 0x00, 0x00, 0x00, 0x00, // ? |
syundo0730 | 0:78ba160ba5f3 | 267 | 0x07, 0x83, 0x06, 0xC2, 0xCA, 0xC4, 0xA3, 0xA3, 0xA3, // ? |
syundo0730 | 0:78ba160ba5f3 | 268 | // SPECIAL 0x01 = enable interrupts |
syundo0730 | 0:78ba160ba5f3 | 269 | 0x00, 0x00, 0x00, 0x01, // SET INT_ENABLE, SPECIAL INSTRUCTION |
syundo0730 | 0:78ba160ba5f3 | 270 | 0x07, 0xA7, 0x01, 0xFE, // ? |
syundo0730 | 0:78ba160ba5f3 | 271 | 0x07, 0x62, 0x05, 0xF1, 0x20, 0x28, 0x30, 0x38, // ? |
syundo0730 | 0:78ba160ba5f3 | 272 | 0x07, 0x67, 0x01, 0x9A, // ? |
syundo0730 | 0:78ba160ba5f3 | 273 | 0x07, 0x68, 0x04, 0xF1, 0x28, 0x30, 0x38, // CFG_12 inv_send_accel -> inv_construct3_fifo |
syundo0730 | 0:78ba160ba5f3 | 274 | 0x07, 0x8D, 0x04, 0xF1, 0x28, 0x30, 0x38, // ??? CFG_12 inv_send_mag -> inv_construct3_fifo |
syundo0730 | 0:78ba160ba5f3 | 275 | 0x02, 0x16, 0x02, 0x00, 0x03 // D_0_22 inv_set_fifo_rate |
syundo0730 | 0:78ba160ba5f3 | 276 | |
syundo0730 | 0:78ba160ba5f3 | 277 | // This very last 0x01 WAS a 0x09, which drops the FIFO rate down to 20 Hz. 0x07 is 25 Hz, |
syundo0730 | 0:78ba160ba5f3 | 278 | // 0x01 is 100Hz. Going faster than 100Hz (0x00=200Hz) tends to result in very noisy data. |
syundo0730 | 0:78ba160ba5f3 | 279 | // DMP output frequency is calculated easily using this equation: (200Hz / (1 + value)) |
syundo0730 | 0:78ba160ba5f3 | 280 | |
syundo0730 | 0:78ba160ba5f3 | 281 | // It is important to make sure the host processor can keep up with reading and processing |
syundo0730 | 0:78ba160ba5f3 | 282 | // the FIFO output at the desired rate. Handling FIFO overflow cleanly is also a good idea. |
syundo0730 | 0:78ba160ba5f3 | 283 | }; |
syundo0730 | 0:78ba160ba5f3 | 284 | |
syundo0730 | 0:78ba160ba5f3 | 285 | const prog_uchar dmpUpdates[MPU9150_DMP_UPDATES_SIZE] PROGMEM = { |
syundo0730 | 0:78ba160ba5f3 | 286 | 0x01, 0xB2, 0x02, 0xFF, 0xF5, |
syundo0730 | 0:78ba160ba5f3 | 287 | 0x01, 0x90, 0x04, 0x0A, 0x0D, 0x97, 0xC0, |
syundo0730 | 0:78ba160ba5f3 | 288 | 0x00, 0xA3, 0x01, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 289 | 0x04, 0x29, 0x04, 0x87, 0x2D, 0x35, 0x3D, |
syundo0730 | 0:78ba160ba5f3 | 290 | 0x01, 0x6A, 0x02, 0x06, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 291 | 0x01, 0x60, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 292 | 0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 293 | 0x02, 0x60, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 294 | 0x01, 0x08, 0x02, 0x01, 0x20, |
syundo0730 | 0:78ba160ba5f3 | 295 | 0x01, 0x0A, 0x02, 0x00, 0x4E, |
syundo0730 | 0:78ba160ba5f3 | 296 | 0x01, 0x02, 0x02, 0xFE, 0xB3, |
syundo0730 | 0:78ba160ba5f3 | 297 | 0x02, 0x6C, 0x04, 0x00, 0x00, 0x00, 0x00, // READ |
syundo0730 | 0:78ba160ba5f3 | 298 | 0x02, 0x6C, 0x04, 0xFA, 0xFE, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 299 | 0x02, 0x60, 0x0C, 0xFF, 0xFF, 0xCB, 0x4D, 0x00, 0x01, 0x08, 0xC1, 0xFF, 0xFF, 0xBC, 0x2C, |
syundo0730 | 0:78ba160ba5f3 | 300 | 0x02, 0xF4, 0x04, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 301 | 0x02, 0xF8, 0x04, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 302 | 0x02, 0xFC, 0x04, 0x00, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 303 | 0x00, 0x60, 0x04, 0x40, 0x00, 0x00, 0x00, |
syundo0730 | 0:78ba160ba5f3 | 304 | 0x00, 0x60, 0x04, 0x00, 0x40, 0x00, 0x00 |
syundo0730 | 0:78ba160ba5f3 | 305 | }; |
syundo0730 | 0:78ba160ba5f3 | 306 | |
syundo0730 | 0:78ba160ba5f3 | 307 | uint8_t MPU9150::dmpInitialize() { |
syundo0730 | 0:78ba160ba5f3 | 308 | // reset device |
syundo0730 | 0:78ba160ba5f3 | 309 | DEBUG_PRINTLN(F("\n\nResetting MPU9150...")); |
syundo0730 | 0:78ba160ba5f3 | 310 | reset(); |
syundo0730 | 0:78ba160ba5f3 | 311 | wait_ms(30); // wait after reset |
syundo0730 | 0:78ba160ba5f3 | 312 | |
syundo0730 | 0:78ba160ba5f3 | 313 | // disable sleep mode |
syundo0730 | 0:78ba160ba5f3 | 314 | DEBUG_PRINTLN(F("Disabling sleep mode...")); |
syundo0730 | 0:78ba160ba5f3 | 315 | setSleepEnabled(false); |
syundo0730 | 0:78ba160ba5f3 | 316 | |
syundo0730 | 0:78ba160ba5f3 | 317 | // get MPU product ID |
syundo0730 | 0:78ba160ba5f3 | 318 | DEBUG_PRINTLN(F("Getting product ID...")); |
syundo0730 | 0:78ba160ba5f3 | 319 | //uint8_t productID = 0; //getProductID(); |
syundo0730 | 0:78ba160ba5f3 | 320 | DEBUG_PRINT(F("Product ID = ")); |
syundo0730 | 0:78ba160ba5f3 | 321 | DEBUG_PRINT(productID); |
syundo0730 | 0:78ba160ba5f3 | 322 | |
syundo0730 | 0:78ba160ba5f3 | 323 | // get MPU hardware revision |
syundo0730 | 0:78ba160ba5f3 | 324 | DEBUG_PRINTLN(F("Selecting user bank 16...")); |
syundo0730 | 0:78ba160ba5f3 | 325 | setMemoryBank(0x10, true, true); |
syundo0730 | 0:78ba160ba5f3 | 326 | DEBUG_PRINTLN(F("Selecting memory byte 6...")); |
syundo0730 | 0:78ba160ba5f3 | 327 | setMemoryStartAddress(0x06); |
syundo0730 | 0:78ba160ba5f3 | 328 | DEBUG_PRINTLN(F("Checking hardware revision...")); |
syundo0730 | 0:78ba160ba5f3 | 329 | uint8_t hwRevision = readMemoryByte(); |
syundo0730 | 0:78ba160ba5f3 | 330 | DEBUG_PRINT(F("Revision @ user[16][6] = ")); |
syundo0730 | 0:78ba160ba5f3 | 331 | DEBUG_PRINTLNF(hwRevision, HEX); |
syundo0730 | 0:78ba160ba5f3 | 332 | DEBUG_PRINTLN(F("Resetting memory bank selection to 0...")); |
syundo0730 | 0:78ba160ba5f3 | 333 | setMemoryBank(0, false, false); |
syundo0730 | 0:78ba160ba5f3 | 334 | |
syundo0730 | 0:78ba160ba5f3 | 335 | // check OTP bank valid |
syundo0730 | 0:78ba160ba5f3 | 336 | DEBUG_PRINTLN(F("Reading OTP bank valid flag...")); |
syundo0730 | 0:78ba160ba5f3 | 337 | uint8_t otpValid = getOTPBankValid(); |
syundo0730 | 0:78ba160ba5f3 | 338 | DEBUG_PRINT(F("OTP bank is ")); |
syundo0730 | 0:78ba160ba5f3 | 339 | DEBUG_PRINTLN(otpValid ? F("valid!") : F("invalid!")); |
syundo0730 | 0:78ba160ba5f3 | 340 | |
syundo0730 | 0:78ba160ba5f3 | 341 | // get X/Y/Z gyro offsets |
syundo0730 | 0:78ba160ba5f3 | 342 | DEBUG_PRINTLN(F("Reading gyro offset values...")); |
syundo0730 | 0:78ba160ba5f3 | 343 | int8_t xgOffset = getXGyroOffset(); |
syundo0730 | 0:78ba160ba5f3 | 344 | int8_t ygOffset = getYGyroOffset(); |
syundo0730 | 0:78ba160ba5f3 | 345 | int8_t zgOffset = getZGyroOffset(); |
syundo0730 | 0:78ba160ba5f3 | 346 | DEBUG_PRINT(F("X gyro offset = ")); |
syundo0730 | 0:78ba160ba5f3 | 347 | DEBUG_PRINTLN(xgOffset); |
syundo0730 | 0:78ba160ba5f3 | 348 | DEBUG_PRINT(F("Y gyro offset = ")); |
syundo0730 | 0:78ba160ba5f3 | 349 | DEBUG_PRINTLN(ygOffset); |
syundo0730 | 0:78ba160ba5f3 | 350 | DEBUG_PRINT(F("Z gyro offset = ")); |
syundo0730 | 0:78ba160ba5f3 | 351 | DEBUG_PRINTLN(zgOffset); |
syundo0730 | 0:78ba160ba5f3 | 352 | |
syundo0730 | 0:78ba160ba5f3 | 353 | I2Cdev::readByte(devAddr, MPU9150_RA_USER_CTRL, buffer); // ? |
syundo0730 | 0:78ba160ba5f3 | 354 | |
syundo0730 | 0:78ba160ba5f3 | 355 | DEBUG_PRINTLN(F("Enabling interrupt latch, clear on any read, AUX bypass enabled")); |
syundo0730 | 0:78ba160ba5f3 | 356 | I2Cdev::writeByte(devAddr, MPU9150_RA_INT_PIN_CFG, 0x32); |
syundo0730 | 0:78ba160ba5f3 | 357 | |
syundo0730 | 0:78ba160ba5f3 | 358 | // enable MPU AUX I2C bypass mode |
syundo0730 | 0:78ba160ba5f3 | 359 | //DEBUG_PRINTLN(F("Enabling AUX I2C bypass mode...")); |
syundo0730 | 0:78ba160ba5f3 | 360 | //setI2CBypassEnabled(true); |
syundo0730 | 0:78ba160ba5f3 | 361 | |
syundo0730 | 0:78ba160ba5f3 | 362 | DEBUG_PRINTLN(F("Setting magnetometer mode to power-down...")); |
syundo0730 | 0:78ba160ba5f3 | 363 | //mag -> setMode(0); |
syundo0730 | 0:78ba160ba5f3 | 364 | I2Cdev::writeByte(0x0E, 0x0A, 0x00); |
syundo0730 | 0:78ba160ba5f3 | 365 | |
syundo0730 | 0:78ba160ba5f3 | 366 | DEBUG_PRINTLN(F("Setting magnetometer mode to fuse access...")); |
syundo0730 | 0:78ba160ba5f3 | 367 | //mag -> setMode(0x0F); |
syundo0730 | 0:78ba160ba5f3 | 368 | I2Cdev::writeByte(0x0E, 0x0A, 0x0F); |
syundo0730 | 0:78ba160ba5f3 | 369 | |
syundo0730 | 0:78ba160ba5f3 | 370 | DEBUG_PRINTLN(F("Reading mag magnetometer factory calibration...")); |
syundo0730 | 0:78ba160ba5f3 | 371 | int8_t asax, asay, asaz; |
syundo0730 | 0:78ba160ba5f3 | 372 | //mag -> getAdjustment(&asax, &asay, &asaz); |
syundo0730 | 0:78ba160ba5f3 | 373 | I2Cdev::readBytes(0x0E, 0x10, 3, buffer); |
syundo0730 | 0:78ba160ba5f3 | 374 | asax = (int8_t)buffer[0]; |
syundo0730 | 0:78ba160ba5f3 | 375 | asay = (int8_t)buffer[1]; |
syundo0730 | 0:78ba160ba5f3 | 376 | asaz = (int8_t)buffer[2]; |
syundo0730 | 0:78ba160ba5f3 | 377 | DEBUG_PRINT(F("Adjustment X/Y/Z = ")); |
syundo0730 | 0:78ba160ba5f3 | 378 | DEBUG_PRINT(asax); |
syundo0730 | 0:78ba160ba5f3 | 379 | DEBUG_PRINT(F(" / ")); |
syundo0730 | 0:78ba160ba5f3 | 380 | DEBUG_PRINT(asay); |
syundo0730 | 0:78ba160ba5f3 | 381 | DEBUG_PRINT(F(" / ")); |
syundo0730 | 0:78ba160ba5f3 | 382 | DEBUG_PRINTLN(asaz); |
syundo0730 | 0:78ba160ba5f3 | 383 | |
syundo0730 | 0:78ba160ba5f3 | 384 | DEBUG_PRINTLN(F("Setting magnetometer mode to power-down...")); |
syundo0730 | 0:78ba160ba5f3 | 385 | //mag -> setMode(0); |
syundo0730 | 0:78ba160ba5f3 | 386 | I2Cdev::writeByte(0x0E, 0x0A, 0x00); |
syundo0730 | 0:78ba160ba5f3 | 387 | |
syundo0730 | 0:78ba160ba5f3 | 388 | // load DMP code into memory banks |
syundo0730 | 0:78ba160ba5f3 | 389 | DEBUG_PRINT(F("Writing DMP code to MPU memory banks (")); |
syundo0730 | 0:78ba160ba5f3 | 390 | DEBUG_PRINT(MPU9150_DMP_CODE_SIZE); |
syundo0730 | 0:78ba160ba5f3 | 391 | DEBUG_PRINTLN(F(" bytes)")); |
syundo0730 | 0:78ba160ba5f3 | 392 | if (writeProgMemoryBlock(dmpMemory, MPU9150_DMP_CODE_SIZE)) { |
syundo0730 | 0:78ba160ba5f3 | 393 | DEBUG_PRINTLN(F("Success! DMP code written and verified.")); |
syundo0730 | 0:78ba160ba5f3 | 394 | |
syundo0730 | 0:78ba160ba5f3 | 395 | DEBUG_PRINTLN(F("Configuring DMP and related settings...")); |
syundo0730 | 0:78ba160ba5f3 | 396 | |
syundo0730 | 0:78ba160ba5f3 | 397 | // write DMP configuration |
syundo0730 | 0:78ba160ba5f3 | 398 | DEBUG_PRINT(F("Writing DMP configuration to MPU memory banks (")); |
syundo0730 | 0:78ba160ba5f3 | 399 | DEBUG_PRINT(MPU9150_DMP_CONFIG_SIZE); |
syundo0730 | 0:78ba160ba5f3 | 400 | DEBUG_PRINTLN(F(" bytes in config def)")); |
syundo0730 | 0:78ba160ba5f3 | 401 | if (writeProgDMPConfigurationSet(dmpConfig, MPU9150_DMP_CONFIG_SIZE)) { |
syundo0730 | 0:78ba160ba5f3 | 402 | DEBUG_PRINTLN(F("Success! DMP configuration written and verified.")); |
syundo0730 | 0:78ba160ba5f3 | 403 | |
syundo0730 | 0:78ba160ba5f3 | 404 | DEBUG_PRINTLN(F("Setting DMP and FIFO_OFLOW interrupts enabled...")); |
syundo0730 | 0:78ba160ba5f3 | 405 | setIntEnabled(0x12); |
syundo0730 | 0:78ba160ba5f3 | 406 | |
syundo0730 | 0:78ba160ba5f3 | 407 | DEBUG_PRINTLN(F("Setting sample rate to 200Hz...")); |
syundo0730 | 0:78ba160ba5f3 | 408 | setRate(4); // 1khz / (1 + 4) = 200 Hz |
syundo0730 | 0:78ba160ba5f3 | 409 | |
syundo0730 | 0:78ba160ba5f3 | 410 | DEBUG_PRINTLN(F("Setting clock source to Z Gyro...")); |
syundo0730 | 0:78ba160ba5f3 | 411 | setClockSource(MPU9150_CLOCK_PLL_ZGYRO); |
syundo0730 | 0:78ba160ba5f3 | 412 | |
syundo0730 | 0:78ba160ba5f3 | 413 | DEBUG_PRINTLN(F("Setting DLPF bandwidth to 42Hz...")); |
syundo0730 | 0:78ba160ba5f3 | 414 | setDLPFMode(MPU9150_DLPF_BW_42); |
syundo0730 | 0:78ba160ba5f3 | 415 | |
syundo0730 | 0:78ba160ba5f3 | 416 | DEBUG_PRINTLN(F("Setting external frame sync to TEMP_OUT_L[0]...")); |
syundo0730 | 0:78ba160ba5f3 | 417 | setExternalFrameSync(MPU9150_EXT_SYNC_TEMP_OUT_L); |
syundo0730 | 0:78ba160ba5f3 | 418 | |
syundo0730 | 0:78ba160ba5f3 | 419 | DEBUG_PRINTLN(F("Setting gyro sensitivity to +/- 2000 deg/sec...")); |
syundo0730 | 0:78ba160ba5f3 | 420 | setFullScaleGyroRange(MPU9150_GYRO_FS_2000); |
syundo0730 | 0:78ba160ba5f3 | 421 | |
syundo0730 | 0:78ba160ba5f3 | 422 | DEBUG_PRINTLN(F("Setting DMP configuration bytes (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 423 | setDMPConfig1(0x03); |
syundo0730 | 0:78ba160ba5f3 | 424 | setDMPConfig2(0x00); |
syundo0730 | 0:78ba160ba5f3 | 425 | |
syundo0730 | 0:78ba160ba5f3 | 426 | DEBUG_PRINTLN(F("Clearing OTP Bank flag...")); |
syundo0730 | 0:78ba160ba5f3 | 427 | setOTPBankValid(false); |
syundo0730 | 0:78ba160ba5f3 | 428 | |
syundo0730 | 0:78ba160ba5f3 | 429 | DEBUG_PRINTLN(F("Setting X/Y/Z gyro offsets to previous values...")); |
syundo0730 | 0:78ba160ba5f3 | 430 | setXGyroOffsetTC(xgOffset); |
syundo0730 | 0:78ba160ba5f3 | 431 | setYGyroOffsetTC(ygOffset); |
syundo0730 | 0:78ba160ba5f3 | 432 | setZGyroOffsetTC(zgOffset); |
syundo0730 | 0:78ba160ba5f3 | 433 | |
syundo0730 | 0:78ba160ba5f3 | 434 | DEBUG_PRINTLN(F("Setting X/Y/Z gyro user offsets to zero...")); |
syundo0730 | 0:78ba160ba5f3 | 435 | setXGyroOffset(0); |
syundo0730 | 0:78ba160ba5f3 | 436 | setYGyroOffset(0); |
syundo0730 | 0:78ba160ba5f3 | 437 | setZGyroOffset(0); |
syundo0730 | 0:78ba160ba5f3 | 438 | |
syundo0730 | 0:78ba160ba5f3 | 439 | DEBUG_PRINTLN(F("Writing final memory update 1/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 440 | uint8_t dmpUpdate[16], j; |
syundo0730 | 0:78ba160ba5f3 | 441 | uint16_t pos = 0; |
syundo0730 | 0:78ba160ba5f3 | 442 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 443 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 444 | |
syundo0730 | 0:78ba160ba5f3 | 445 | DEBUG_PRINTLN(F("Writing final memory update 2/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 446 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 447 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 448 | |
syundo0730 | 0:78ba160ba5f3 | 449 | DEBUG_PRINTLN(F("Resetting FIFO...")); |
syundo0730 | 0:78ba160ba5f3 | 450 | resetFIFO(); |
syundo0730 | 0:78ba160ba5f3 | 451 | |
syundo0730 | 0:78ba160ba5f3 | 452 | DEBUG_PRINTLN(F("Reading FIFO count...")); |
syundo0730 | 0:78ba160ba5f3 | 453 | uint8_t fifoCount = getFIFOCount(); |
syundo0730 | 0:78ba160ba5f3 | 454 | |
syundo0730 | 0:78ba160ba5f3 | 455 | DEBUG_PRINT(F("Current FIFO count=")); |
syundo0730 | 0:78ba160ba5f3 | 456 | DEBUG_PRINTLN(fifoCount); |
syundo0730 | 0:78ba160ba5f3 | 457 | uint8_t fifoBuffer[128]; |
syundo0730 | 0:78ba160ba5f3 | 458 | //getFIFOBytes(fifoBuffer, fifoCount); |
syundo0730 | 0:78ba160ba5f3 | 459 | |
syundo0730 | 0:78ba160ba5f3 | 460 | DEBUG_PRINTLN(F("Writing final memory update 3/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 461 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 462 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 463 | |
syundo0730 | 0:78ba160ba5f3 | 464 | DEBUG_PRINTLN(F("Writing final memory update 4/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 465 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 466 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 467 | |
syundo0730 | 0:78ba160ba5f3 | 468 | DEBUG_PRINTLN(F("Disabling all standby flags...")); |
syundo0730 | 0:78ba160ba5f3 | 469 | I2Cdev::writeByte(0x68, MPU9150_RA_PWR_MGMT_2, 0x00); |
syundo0730 | 0:78ba160ba5f3 | 470 | |
syundo0730 | 0:78ba160ba5f3 | 471 | DEBUG_PRINTLN(F("Setting accelerometer sensitivity to +/- 2g...")); |
syundo0730 | 0:78ba160ba5f3 | 472 | I2Cdev::writeByte(0x68, MPU9150_RA_ACCEL_CONFIG, 0x00); |
syundo0730 | 0:78ba160ba5f3 | 473 | |
syundo0730 | 0:78ba160ba5f3 | 474 | DEBUG_PRINTLN(F("Setting motion detection threshold to 2...")); |
syundo0730 | 0:78ba160ba5f3 | 475 | setMotionDetectionThreshold(2); |
syundo0730 | 0:78ba160ba5f3 | 476 | |
syundo0730 | 0:78ba160ba5f3 | 477 | DEBUG_PRINTLN(F("Setting zero-motion detection threshold to 156...")); |
syundo0730 | 0:78ba160ba5f3 | 478 | setZeroMotionDetectionThreshold(156); |
syundo0730 | 0:78ba160ba5f3 | 479 | |
syundo0730 | 0:78ba160ba5f3 | 480 | DEBUG_PRINTLN(F("Setting motion detection duration to 80...")); |
syundo0730 | 0:78ba160ba5f3 | 481 | setMotionDetectionDuration(80); |
syundo0730 | 0:78ba160ba5f3 | 482 | |
syundo0730 | 0:78ba160ba5f3 | 483 | DEBUG_PRINTLN(F("Setting zero-motion detection duration to 0...")); |
syundo0730 | 0:78ba160ba5f3 | 484 | setZeroMotionDetectionDuration(0); |
syundo0730 | 0:78ba160ba5f3 | 485 | |
syundo0730 | 0:78ba160ba5f3 | 486 | DEBUG_PRINTLN(F("Setting AK8975 to single measurement mode...")); |
syundo0730 | 0:78ba160ba5f3 | 487 | //mag -> setMode(1); |
syundo0730 | 0:78ba160ba5f3 | 488 | I2Cdev::writeByte(0x0E, 0x0A, 0x01); |
syundo0730 | 0:78ba160ba5f3 | 489 | |
syundo0730 | 0:78ba160ba5f3 | 490 | // setup AK8975 (0x0E) as Slave 0 in read mode |
syundo0730 | 0:78ba160ba5f3 | 491 | DEBUG_PRINTLN(F("Setting up AK8975 read slave 0...")); |
syundo0730 | 0:78ba160ba5f3 | 492 | I2Cdev::writeByte(0x68, MPU9150_RA_I2C_SLV0_ADDR, 0x8E); |
syundo0730 | 0:78ba160ba5f3 | 493 | I2Cdev::writeByte(0x68, MPU9150_RA_I2C_SLV0_REG, 0x01); |
syundo0730 | 0:78ba160ba5f3 | 494 | I2Cdev::writeByte(0x68, MPU9150_RA_I2C_SLV0_CTRL, 0xDA); |
syundo0730 | 0:78ba160ba5f3 | 495 | |
syundo0730 | 0:78ba160ba5f3 | 496 | // setup AK8975 (0x0E) as Slave 2 in write mode |
syundo0730 | 0:78ba160ba5f3 | 497 | DEBUG_PRINTLN(F("Setting up AK8975 write slave 2...")); |
syundo0730 | 0:78ba160ba5f3 | 498 | I2Cdev::writeByte(0x68, MPU9150_RA_I2C_SLV2_ADDR, 0x0E); |
syundo0730 | 0:78ba160ba5f3 | 499 | I2Cdev::writeByte(0x68, MPU9150_RA_I2C_SLV2_REG, 0x0A); |
syundo0730 | 0:78ba160ba5f3 | 500 | I2Cdev::writeByte(0x68, MPU9150_RA_I2C_SLV2_CTRL, 0x81); |
syundo0730 | 0:78ba160ba5f3 | 501 | I2Cdev::writeByte(0x68, MPU9150_RA_I2C_SLV2_DO, 0x01); |
syundo0730 | 0:78ba160ba5f3 | 502 | |
syundo0730 | 0:78ba160ba5f3 | 503 | // setup I2C timing/delay control |
syundo0730 | 0:78ba160ba5f3 | 504 | DEBUG_PRINTLN(F("Setting up slave access delay...")); |
syundo0730 | 0:78ba160ba5f3 | 505 | I2Cdev::writeByte(0x68, MPU9150_RA_I2C_SLV4_CTRL, 0x18); |
syundo0730 | 0:78ba160ba5f3 | 506 | I2Cdev::writeByte(0x68, MPU9150_RA_I2C_MST_DELAY_CTRL, 0x05); |
syundo0730 | 0:78ba160ba5f3 | 507 | |
syundo0730 | 0:78ba160ba5f3 | 508 | // enable interrupts |
syundo0730 | 0:78ba160ba5f3 | 509 | DEBUG_PRINTLN(F("Enabling default interrupt behavior/no bypass...")); |
syundo0730 | 0:78ba160ba5f3 | 510 | I2Cdev::writeByte(0x68, MPU9150_RA_INT_PIN_CFG, 0x00); |
syundo0730 | 0:78ba160ba5f3 | 511 | |
syundo0730 | 0:78ba160ba5f3 | 512 | // enable I2C master mode and reset DMP/FIFO |
syundo0730 | 0:78ba160ba5f3 | 513 | DEBUG_PRINTLN(F("Enabling I2C master mode...")); |
syundo0730 | 0:78ba160ba5f3 | 514 | I2Cdev::writeByte(0x68, MPU9150_RA_USER_CTRL, 0x20); |
syundo0730 | 0:78ba160ba5f3 | 515 | DEBUG_PRINTLN(F("Resetting FIFO...")); |
syundo0730 | 0:78ba160ba5f3 | 516 | I2Cdev::writeByte(0x68, MPU9150_RA_USER_CTRL, 0x24); |
syundo0730 | 0:78ba160ba5f3 | 517 | DEBUG_PRINTLN(F("Rewriting I2C master mode enabled because...I don't know")); |
syundo0730 | 0:78ba160ba5f3 | 518 | I2Cdev::writeByte(0x68, MPU9150_RA_USER_CTRL, 0x20); |
syundo0730 | 0:78ba160ba5f3 | 519 | DEBUG_PRINTLN(F("Enabling and resetting DMP/FIFO...")); |
syundo0730 | 0:78ba160ba5f3 | 520 | I2Cdev::writeByte(0x68, MPU9150_RA_USER_CTRL, 0xE8); |
syundo0730 | 0:78ba160ba5f3 | 521 | |
syundo0730 | 0:78ba160ba5f3 | 522 | DEBUG_PRINTLN(F("Writing final memory update 5/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 523 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 524 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 525 | DEBUG_PRINTLN(F("Writing final memory update 6/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 526 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 527 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 528 | DEBUG_PRINTLN(F("Writing final memory update 7/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 529 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 530 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 531 | DEBUG_PRINTLN(F("Writing final memory update 8/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 532 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 533 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 534 | DEBUG_PRINTLN(F("Writing final memory update 9/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 535 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 536 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 537 | DEBUG_PRINTLN(F("Writing final memory update 10/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 538 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 539 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 540 | DEBUG_PRINTLN(F("Writing final memory update 11/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 541 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 542 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 543 | |
syundo0730 | 0:78ba160ba5f3 | 544 | DEBUG_PRINTLN(F("Reading final memory update 12/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 545 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 546 | readMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 547 | #ifdef DEBUG |
syundo0730 | 0:78ba160ba5f3 | 548 | DEBUG_PRINT(F("Read bytes: ")); |
syundo0730 | 0:78ba160ba5f3 | 549 | for (j = 0; j < 4; j++) { |
syundo0730 | 0:78ba160ba5f3 | 550 | DEBUG_PRINTF(dmpUpdate[3 + j], HEX); |
syundo0730 | 0:78ba160ba5f3 | 551 | DEBUG_PRINT(" "); |
syundo0730 | 0:78ba160ba5f3 | 552 | } |
syundo0730 | 0:78ba160ba5f3 | 553 | DEBUG_PRINTLN(""); |
syundo0730 | 0:78ba160ba5f3 | 554 | #endif |
syundo0730 | 0:78ba160ba5f3 | 555 | |
syundo0730 | 0:78ba160ba5f3 | 556 | DEBUG_PRINTLN(F("Writing final memory update 13/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 557 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 558 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 559 | DEBUG_PRINTLN(F("Writing final memory update 14/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 560 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 561 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 562 | DEBUG_PRINTLN(F("Writing final memory update 15/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 563 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 564 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 565 | DEBUG_PRINTLN(F("Writing final memory update 16/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 566 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 567 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 568 | DEBUG_PRINTLN(F("Writing final memory update 17/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 569 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 570 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 571 | |
syundo0730 | 0:78ba160ba5f3 | 572 | DEBUG_PRINTLN(F("Waiting for FIRO count >= 46...")); |
syundo0730 | 0:78ba160ba5f3 | 573 | while ((fifoCount = getFIFOCount()) < 46); |
syundo0730 | 0:78ba160ba5f3 | 574 | DEBUG_PRINTLN(F("Reading FIFO...")); |
syundo0730 | 0:78ba160ba5f3 | 575 | getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes |
syundo0730 | 0:78ba160ba5f3 | 576 | DEBUG_PRINTLN(F("Reading interrupt status...")); |
syundo0730 | 0:78ba160ba5f3 | 577 | getIntStatus(); |
syundo0730 | 0:78ba160ba5f3 | 578 | |
syundo0730 | 0:78ba160ba5f3 | 579 | DEBUG_PRINTLN(F("Writing final memory update 18/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 580 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 581 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 582 | |
syundo0730 | 0:78ba160ba5f3 | 583 | DEBUG_PRINTLN(F("Waiting for FIRO count >= 48...")); |
syundo0730 | 0:78ba160ba5f3 | 584 | while ((fifoCount = getFIFOCount()) < 48); |
syundo0730 | 0:78ba160ba5f3 | 585 | DEBUG_PRINTLN(F("Reading FIFO...")); |
syundo0730 | 0:78ba160ba5f3 | 586 | getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes |
syundo0730 | 0:78ba160ba5f3 | 587 | DEBUG_PRINTLN(F("Reading interrupt status...")); |
syundo0730 | 0:78ba160ba5f3 | 588 | getIntStatus(); |
syundo0730 | 0:78ba160ba5f3 | 589 | DEBUG_PRINTLN(F("Waiting for FIRO count >= 48...")); |
syundo0730 | 0:78ba160ba5f3 | 590 | while ((fifoCount = getFIFOCount()) < 48); |
syundo0730 | 0:78ba160ba5f3 | 591 | DEBUG_PRINTLN(F("Reading FIFO...")); |
syundo0730 | 0:78ba160ba5f3 | 592 | getFIFOBytes(fifoBuffer, min(fifoCount, 128)); // safeguard only 128 bytes |
syundo0730 | 0:78ba160ba5f3 | 593 | DEBUG_PRINTLN(F("Reading interrupt status...")); |
syundo0730 | 0:78ba160ba5f3 | 594 | getIntStatus(); |
syundo0730 | 0:78ba160ba5f3 | 595 | |
syundo0730 | 0:78ba160ba5f3 | 596 | DEBUG_PRINTLN(F("Writing final memory update 19/19 (function unknown)...")); |
syundo0730 | 0:78ba160ba5f3 | 597 | for (j = 0; j < 4 || j < dmpUpdate[2] + 3; j++, pos++) dmpUpdate[j] = pgm_read_byte(&dmpUpdates[pos]); |
syundo0730 | 0:78ba160ba5f3 | 598 | writeMemoryBlock(dmpUpdate + 3, dmpUpdate[2], dmpUpdate[0], dmpUpdate[1]); |
syundo0730 | 0:78ba160ba5f3 | 599 | |
syundo0730 | 0:78ba160ba5f3 | 600 | DEBUG_PRINTLN(F("Disabling DMP (you turn it on later)...")); |
syundo0730 | 0:78ba160ba5f3 | 601 | setDMPEnabled(false); |
syundo0730 | 0:78ba160ba5f3 | 602 | |
syundo0730 | 0:78ba160ba5f3 | 603 | DEBUG_PRINTLN(F("Setting up internal 48-byte (default) DMP packet buffer...")); |
syundo0730 | 0:78ba160ba5f3 | 604 | dmpPacketSize = 48; |
syundo0730 | 0:78ba160ba5f3 | 605 | /*if ((dmpPacketBuffer = (uint8_t *)malloc(42)) == 0) { |
syundo0730 | 0:78ba160ba5f3 | 606 | return 3; // TODO: proper error code for no memory |
syundo0730 | 0:78ba160ba5f3 | 607 | }*/ |
syundo0730 | 0:78ba160ba5f3 | 608 | |
syundo0730 | 0:78ba160ba5f3 | 609 | DEBUG_PRINTLN(F("Resetting FIFO and clearing INT status one last time...")); |
syundo0730 | 0:78ba160ba5f3 | 610 | resetFIFO(); |
syundo0730 | 0:78ba160ba5f3 | 611 | getIntStatus(); |
syundo0730 | 0:78ba160ba5f3 | 612 | } else { |
syundo0730 | 0:78ba160ba5f3 | 613 | DEBUG_PRINTLN(F("ERROR! DMP configuration verification failed.")); |
syundo0730 | 0:78ba160ba5f3 | 614 | return 2; // configuration block loading failed |
syundo0730 | 0:78ba160ba5f3 | 615 | } |
syundo0730 | 0:78ba160ba5f3 | 616 | } else { |
syundo0730 | 0:78ba160ba5f3 | 617 | DEBUG_PRINTLN(F("ERROR! DMP code verification failed.")); |
syundo0730 | 0:78ba160ba5f3 | 618 | return 1; // main binary block loading failed |
syundo0730 | 0:78ba160ba5f3 | 619 | } |
syundo0730 | 0:78ba160ba5f3 | 620 | return 0; // success |
syundo0730 | 0:78ba160ba5f3 | 621 | } |
syundo0730 | 0:78ba160ba5f3 | 622 | |
syundo0730 | 0:78ba160ba5f3 | 623 | bool MPU9150::dmpPacketAvailable() { |
syundo0730 | 0:78ba160ba5f3 | 624 | return getFIFOCount() >= dmpGetFIFOPacketSize(); |
syundo0730 | 0:78ba160ba5f3 | 625 | } |
syundo0730 | 0:78ba160ba5f3 | 626 | |
syundo0730 | 0:78ba160ba5f3 | 627 | // uint8_t MPU9150::dmpSetFIFORate(uint8_t fifoRate); |
syundo0730 | 0:78ba160ba5f3 | 628 | // uint8_t MPU9150::dmpGetFIFORate(); |
syundo0730 | 0:78ba160ba5f3 | 629 | // uint8_t MPU9150::dmpGetSampleStepSizeMS(); |
syundo0730 | 0:78ba160ba5f3 | 630 | // uint8_t MPU9150::dmpGetSampleFrequency(); |
syundo0730 | 0:78ba160ba5f3 | 631 | // int32_t MPU9150::dmpDecodeTemperature(int8_t tempReg); |
syundo0730 | 0:78ba160ba5f3 | 632 | |
syundo0730 | 0:78ba160ba5f3 | 633 | //uint8_t MPU9150::dmpRegisterFIFORateProcess(inv_obj_func func, int16_t priority); |
syundo0730 | 0:78ba160ba5f3 | 634 | //uint8_t MPU9150::dmpUnregisterFIFORateProcess(inv_obj_func func); |
syundo0730 | 0:78ba160ba5f3 | 635 | //uint8_t MPU9150::dmpRunFIFORateProcesses(); |
syundo0730 | 0:78ba160ba5f3 | 636 | |
syundo0730 | 0:78ba160ba5f3 | 637 | // uint8_t MPU9150::dmpSendQuaternion(uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 638 | // uint8_t MPU9150::dmpSendGyro(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 639 | // uint8_t MPU9150::dmpSendAccel(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 640 | // uint8_t MPU9150::dmpSendLinearAccel(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 641 | // uint8_t MPU9150::dmpSendLinearAccelInWorld(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 642 | // uint8_t MPU9150::dmpSendControlData(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 643 | // uint8_t MPU9150::dmpSendSensorData(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 644 | // uint8_t MPU9150::dmpSendExternalSensorData(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 645 | // uint8_t MPU9150::dmpSendGravity(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 646 | // uint8_t MPU9150::dmpSendPacketNumber(uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 647 | // uint8_t MPU9150::dmpSendQuantizedAccel(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 648 | // uint8_t MPU9150::dmpSendEIS(uint_fast16_t elements, uint_fast16_t accuracy); |
syundo0730 | 0:78ba160ba5f3 | 649 | |
syundo0730 | 0:78ba160ba5f3 | 650 | uint8_t MPU9150::dmpGetAccel(int32_t *data, const uint8_t* packet) { |
syundo0730 | 0:78ba160ba5f3 | 651 | // TODO: accommodate different arrangements of sent data (ONLY default supported now) |
syundo0730 | 0:78ba160ba5f3 | 652 | if (packet == 0) packet = dmpPacketBuffer; |
syundo0730 | 0:78ba160ba5f3 | 653 | data[0] = ((packet[34] << 24) + (packet[35] << 16) + (packet[36] << 8) + packet[37]); |
syundo0730 | 0:78ba160ba5f3 | 654 | data[1] = ((packet[38] << 24) + (packet[39] << 16) + (packet[40] << 8) + packet[41]); |
syundo0730 | 0:78ba160ba5f3 | 655 | data[2] = ((packet[42] << 24) + (packet[43] << 16) + (packet[44] << 8) + packet[45]); |
syundo0730 | 0:78ba160ba5f3 | 656 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 657 | } |
syundo0730 | 0:78ba160ba5f3 | 658 | uint8_t MPU9150::dmpGetAccel(int16_t *data, const uint8_t* packet) { |
syundo0730 | 0:78ba160ba5f3 | 659 | // TODO: accommodate different arrangements of sent data (ONLY default supported now) |
syundo0730 | 0:78ba160ba5f3 | 660 | if (packet == 0) packet = dmpPacketBuffer; |
syundo0730 | 0:78ba160ba5f3 | 661 | data[0] = (packet[34] << 8) + packet[35]; |
syundo0730 | 0:78ba160ba5f3 | 662 | data[1] = (packet[38] << 8) + packet[39]; |
syundo0730 | 0:78ba160ba5f3 | 663 | data[2] = (packet[42] << 8) + packet[43]; |
syundo0730 | 0:78ba160ba5f3 | 664 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 665 | } |
syundo0730 | 0:78ba160ba5f3 | 666 | uint8_t MPU9150::dmpGetAccel(VectorInt16 *v, const uint8_t* packet) { |
syundo0730 | 0:78ba160ba5f3 | 667 | // TODO: accommodate different arrangements of sent data (ONLY default supported now) |
syundo0730 | 0:78ba160ba5f3 | 668 | if (packet == 0) packet = dmpPacketBuffer; |
syundo0730 | 0:78ba160ba5f3 | 669 | v -> x = (packet[34] << 8) + packet[35]; |
syundo0730 | 0:78ba160ba5f3 | 670 | v -> y = (packet[38] << 8) + packet[39]; |
syundo0730 | 0:78ba160ba5f3 | 671 | v -> z = (packet[42] << 8) + packet[43]; |
syundo0730 | 0:78ba160ba5f3 | 672 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 673 | } |
syundo0730 | 0:78ba160ba5f3 | 674 | uint8_t MPU9150::dmpGetQuaternion(int32_t *data, const uint8_t* packet) { |
syundo0730 | 0:78ba160ba5f3 | 675 | // TODO: accommodate different arrangements of sent data (ONLY default supported now) |
syundo0730 | 0:78ba160ba5f3 | 676 | if (packet == 0) packet = dmpPacketBuffer; |
syundo0730 | 0:78ba160ba5f3 | 677 | data[0] = ((packet[0] << 24) + (packet[1] << 16) + (packet[2] << 8) + packet[3]); |
syundo0730 | 0:78ba160ba5f3 | 678 | data[1] = ((packet[4] << 24) + (packet[5] << 16) + (packet[6] << 8) + packet[7]); |
syundo0730 | 0:78ba160ba5f3 | 679 | data[2] = ((packet[8] << 24) + (packet[9] << 16) + (packet[10] << 8) + packet[11]); |
syundo0730 | 0:78ba160ba5f3 | 680 | data[3] = ((packet[12] << 24) + (packet[13] << 16) + (packet[14] << 8) + packet[15]); |
syundo0730 | 0:78ba160ba5f3 | 681 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 682 | } |
syundo0730 | 0:78ba160ba5f3 | 683 | uint8_t MPU9150::dmpGetQuaternion(int16_t *data, const uint8_t* packet) { |
syundo0730 | 0:78ba160ba5f3 | 684 | // TODO: accommodate different arrangements of sent data (ONLY default supported now) |
syundo0730 | 0:78ba160ba5f3 | 685 | if (packet == 0) packet = dmpPacketBuffer; |
syundo0730 | 0:78ba160ba5f3 | 686 | data[0] = ((packet[0] << 8) + packet[1]); |
syundo0730 | 0:78ba160ba5f3 | 687 | data[1] = ((packet[4] << 8) + packet[5]); |
syundo0730 | 0:78ba160ba5f3 | 688 | data[2] = ((packet[8] << 8) + packet[9]); |
syundo0730 | 0:78ba160ba5f3 | 689 | data[3] = ((packet[12] << 8) + packet[13]); |
syundo0730 | 0:78ba160ba5f3 | 690 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 691 | } |
syundo0730 | 0:78ba160ba5f3 | 692 | uint8_t MPU9150::dmpGetQuaternion(Quaternion *q, const uint8_t* packet) { |
syundo0730 | 0:78ba160ba5f3 | 693 | // TODO: accommodate different arrangements of sent data (ONLY default supported now) |
syundo0730 | 0:78ba160ba5f3 | 694 | int16_t qI[4]; |
syundo0730 | 0:78ba160ba5f3 | 695 | uint8_t status = dmpGetQuaternion(qI, packet); |
syundo0730 | 0:78ba160ba5f3 | 696 | if (status == 0) { |
syundo0730 | 0:78ba160ba5f3 | 697 | q -> w = (float)qI[0] / 16384.0f; |
syundo0730 | 0:78ba160ba5f3 | 698 | q -> x = (float)qI[1] / 16384.0f; |
syundo0730 | 0:78ba160ba5f3 | 699 | q -> y = (float)qI[2] / 16384.0f; |
syundo0730 | 0:78ba160ba5f3 | 700 | q -> z = (float)qI[3] / 16384.0f; |
syundo0730 | 0:78ba160ba5f3 | 701 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 702 | } |
syundo0730 | 0:78ba160ba5f3 | 703 | return status; // int16 return value, indicates error if this line is reached |
syundo0730 | 0:78ba160ba5f3 | 704 | } |
syundo0730 | 0:78ba160ba5f3 | 705 | // uint8_t MPU9150::dmpGet6AxisQuaternion(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 706 | // uint8_t MPU9150::dmpGetRelativeQuaternion(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 707 | uint8_t MPU9150::dmpGetGyro(int32_t *data, const uint8_t* packet) { |
syundo0730 | 0:78ba160ba5f3 | 708 | // TODO: accommodate different arrangements of sent data (ONLY default supported now) |
syundo0730 | 0:78ba160ba5f3 | 709 | if (packet == 0) packet = dmpPacketBuffer; |
syundo0730 | 0:78ba160ba5f3 | 710 | data[0] = ((packet[16] << 24) + (packet[17] << 16) + (packet[18] << 8) + packet[19]); |
syundo0730 | 0:78ba160ba5f3 | 711 | data[1] = ((packet[20] << 24) + (packet[21] << 16) + (packet[22] << 8) + packet[23]); |
syundo0730 | 0:78ba160ba5f3 | 712 | data[2] = ((packet[24] << 24) + (packet[25] << 16) + (packet[26] << 8) + packet[27]); |
syundo0730 | 0:78ba160ba5f3 | 713 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 714 | } |
syundo0730 | 0:78ba160ba5f3 | 715 | uint8_t MPU9150::dmpGetGyro(int16_t *data, const uint8_t* packet) { |
syundo0730 | 0:78ba160ba5f3 | 716 | // TODO: accommodate different arrangements of sent data (ONLY default supported now) |
syundo0730 | 0:78ba160ba5f3 | 717 | if (packet == 0) packet = dmpPacketBuffer; |
syundo0730 | 0:78ba160ba5f3 | 718 | data[0] = (packet[16] << 8) + packet[17]; |
syundo0730 | 0:78ba160ba5f3 | 719 | data[1] = (packet[20] << 8) + packet[21]; |
syundo0730 | 0:78ba160ba5f3 | 720 | data[2] = (packet[24] << 8) + packet[25]; |
syundo0730 | 0:78ba160ba5f3 | 721 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 722 | } |
syundo0730 | 0:78ba160ba5f3 | 723 | uint8_t MPU9150::dmpGetMag(int16_t *data, const uint8_t* packet) { |
syundo0730 | 0:78ba160ba5f3 | 724 | // TODO: accommodate different arrangements of sent data (ONLY default supported now) |
syundo0730 | 0:78ba160ba5f3 | 725 | if (packet == 0) packet = dmpPacketBuffer; |
syundo0730 | 0:78ba160ba5f3 | 726 | data[0] = (packet[28] << 8) + packet[29]; |
syundo0730 | 0:78ba160ba5f3 | 727 | data[1] = (packet[30] << 8) + packet[31]; |
syundo0730 | 0:78ba160ba5f3 | 728 | data[2] = (packet[32] << 8) + packet[33]; |
syundo0730 | 0:78ba160ba5f3 | 729 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 730 | } |
syundo0730 | 0:78ba160ba5f3 | 731 | // uint8_t MPU9150::dmpSetLinearAccelFilterCoefficient(float coef); |
syundo0730 | 0:78ba160ba5f3 | 732 | // uint8_t MPU9150::dmpGetLinearAccel(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 733 | uint8_t MPU9150::dmpGetLinearAccel(VectorInt16 *v, VectorInt16 *vRaw, VectorFloat *gravity) { |
syundo0730 | 0:78ba160ba5f3 | 734 | // get rid of the gravity component (+1g = +4096 in standard DMP FIFO packet) |
syundo0730 | 0:78ba160ba5f3 | 735 | v -> x = vRaw -> x - gravity -> x*4096; |
syundo0730 | 0:78ba160ba5f3 | 736 | v -> y = vRaw -> y - gravity -> y*4096; |
syundo0730 | 0:78ba160ba5f3 | 737 | v -> z = vRaw -> z - gravity -> z*4096; |
syundo0730 | 0:78ba160ba5f3 | 738 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 739 | } |
syundo0730 | 0:78ba160ba5f3 | 740 | // uint8_t MPU9150::dmpGetLinearAccelInWorld(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 741 | uint8_t MPU9150::dmpGetLinearAccelInWorld(VectorInt16 *v, VectorInt16 *vReal, Quaternion *q) { |
syundo0730 | 0:78ba160ba5f3 | 742 | // rotate measured 3D acceleration vector into original state |
syundo0730 | 0:78ba160ba5f3 | 743 | // frame of reference based on orientation quaternion |
syundo0730 | 0:78ba160ba5f3 | 744 | memcpy(v, vReal, sizeof(VectorInt16)); |
syundo0730 | 0:78ba160ba5f3 | 745 | v -> rotate(q); |
syundo0730 | 0:78ba160ba5f3 | 746 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 747 | } |
syundo0730 | 0:78ba160ba5f3 | 748 | // uint8_t MPU9150::dmpGetGyroAndAccelSensor(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 749 | // uint8_t MPU9150::dmpGetGyroSensor(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 750 | // uint8_t MPU9150::dmpGetControlData(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 751 | // uint8_t MPU9150::dmpGetTemperature(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 752 | // uint8_t MPU9150::dmpGetGravity(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 753 | uint8_t MPU9150::dmpGetGravity(VectorFloat *v, Quaternion *q) { |
syundo0730 | 0:78ba160ba5f3 | 754 | v -> x = 2 * (q -> x*q -> z - q -> w*q -> y); |
syundo0730 | 0:78ba160ba5f3 | 755 | v -> y = 2 * (q -> w*q -> x + q -> y*q -> z); |
syundo0730 | 0:78ba160ba5f3 | 756 | v -> z = q -> w*q -> w - q -> x*q -> x - q -> y*q -> y + q -> z*q -> z; |
syundo0730 | 0:78ba160ba5f3 | 757 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 758 | } |
syundo0730 | 0:78ba160ba5f3 | 759 | // uint8_t MPU9150::dmpGetUnquantizedAccel(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 760 | // uint8_t MPU9150::dmpGetQuantizedAccel(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 761 | // uint8_t MPU9150::dmpGetExternalSensorData(long *data, int size, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 762 | // uint8_t MPU9150::dmpGetEIS(long *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 763 | |
syundo0730 | 0:78ba160ba5f3 | 764 | uint8_t MPU9150::dmpGetEuler(float *data, Quaternion *q) { |
syundo0730 | 0:78ba160ba5f3 | 765 | data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); // psi |
syundo0730 | 0:78ba160ba5f3 | 766 | data[1] = -asin(2*q -> x*q -> z + 2*q -> w*q -> y); // theta |
syundo0730 | 0:78ba160ba5f3 | 767 | data[2] = atan2(2*q -> y*q -> z - 2*q -> w*q -> x, 2*q -> w*q -> w + 2*q -> z*q -> z - 1); // phi |
syundo0730 | 0:78ba160ba5f3 | 768 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 769 | } |
syundo0730 | 0:78ba160ba5f3 | 770 | uint8_t MPU9150::dmpGetYawPitchRoll(float *data, Quaternion *q, VectorFloat *gravity) { |
syundo0730 | 0:78ba160ba5f3 | 771 | // yaw: (about Z axis) |
syundo0730 | 0:78ba160ba5f3 | 772 | data[0] = atan2(2*q -> x*q -> y - 2*q -> w*q -> z, 2*q -> w*q -> w + 2*q -> x*q -> x - 1); |
syundo0730 | 0:78ba160ba5f3 | 773 | // pitch: (nose up/down, about Y axis) |
syundo0730 | 0:78ba160ba5f3 | 774 | data[1] = atan(gravity -> x / sqrt(gravity -> y*gravity -> y + gravity -> z*gravity -> z)); |
syundo0730 | 0:78ba160ba5f3 | 775 | // roll: (tilt left/right, about X axis) |
syundo0730 | 0:78ba160ba5f3 | 776 | data[2] = atan(gravity -> y / sqrt(gravity -> x*gravity -> x + gravity -> z*gravity -> z)); |
syundo0730 | 0:78ba160ba5f3 | 777 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 778 | } |
syundo0730 | 0:78ba160ba5f3 | 779 | |
syundo0730 | 0:78ba160ba5f3 | 780 | // uint8_t MPU9150::dmpGetAccelFloat(float *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 781 | // uint8_t MPU9150::dmpGetQuaternionFloat(float *data, const uint8_t* packet); |
syundo0730 | 0:78ba160ba5f3 | 782 | |
syundo0730 | 0:78ba160ba5f3 | 783 | uint8_t MPU9150::dmpProcessFIFOPacket(const unsigned char *dmpData) { |
syundo0730 | 0:78ba160ba5f3 | 784 | /*for (uint8_t k = 0; k < dmpPacketSize; k++) { |
syundo0730 | 0:78ba160ba5f3 | 785 | if (dmpData[k] < 0x10) Serial.print("0"); |
syundo0730 | 0:78ba160ba5f3 | 786 | Serial.print(dmpData[k], HEX); |
syundo0730 | 0:78ba160ba5f3 | 787 | Serial.print(" "); |
syundo0730 | 0:78ba160ba5f3 | 788 | } |
syundo0730 | 0:78ba160ba5f3 | 789 | Serial.print("\n");*/ |
syundo0730 | 0:78ba160ba5f3 | 790 | //Serial.println((uint16_t)dmpPacketBuffer); |
syundo0730 | 0:78ba160ba5f3 | 791 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 792 | } |
syundo0730 | 0:78ba160ba5f3 | 793 | uint8_t MPU9150::dmpReadAndProcessFIFOPacket(uint8_t numPackets, uint8_t *processed) { |
syundo0730 | 0:78ba160ba5f3 | 794 | uint8_t status; |
syundo0730 | 0:78ba160ba5f3 | 795 | uint8_t buf[dmpPacketSize]; |
syundo0730 | 0:78ba160ba5f3 | 796 | for (uint8_t i = 0; i < numPackets; i++) { |
syundo0730 | 0:78ba160ba5f3 | 797 | // read packet from FIFO |
syundo0730 | 0:78ba160ba5f3 | 798 | getFIFOBytes(buf, dmpPacketSize); |
syundo0730 | 0:78ba160ba5f3 | 799 | |
syundo0730 | 0:78ba160ba5f3 | 800 | // process packet |
syundo0730 | 0:78ba160ba5f3 | 801 | if ((status = dmpProcessFIFOPacket(buf)) > 0) return status; |
syundo0730 | 0:78ba160ba5f3 | 802 | |
syundo0730 | 0:78ba160ba5f3 | 803 | // increment external process count variable, if supplied |
syundo0730 | 0:78ba160ba5f3 | 804 | if (processed != 0) *processed++; |
syundo0730 | 0:78ba160ba5f3 | 805 | } |
syundo0730 | 0:78ba160ba5f3 | 806 | return 0; |
syundo0730 | 0:78ba160ba5f3 | 807 | } |
syundo0730 | 0:78ba160ba5f3 | 808 | |
syundo0730 | 0:78ba160ba5f3 | 809 | // uint8_t MPU9150::dmpSetFIFOProcessedCallback(void (*func) (void)); |
syundo0730 | 0:78ba160ba5f3 | 810 | |
syundo0730 | 0:78ba160ba5f3 | 811 | // uint8_t MPU9150::dmpInitFIFOParam(); |
syundo0730 | 0:78ba160ba5f3 | 812 | // uint8_t MPU9150::dmpCloseFIFO(); |
syundo0730 | 0:78ba160ba5f3 | 813 | // uint8_t MPU9150::dmpSetGyroDataSource(uint_fast8_t source); |
syundo0730 | 0:78ba160ba5f3 | 814 | // uint8_t MPU9150::dmpDecodeQuantizedAccel(); |
syundo0730 | 0:78ba160ba5f3 | 815 | // uint32_t MPU9150::dmpGetGyroSumOfSquare(); |
syundo0730 | 0:78ba160ba5f3 | 816 | // uint32_t MPU9150::dmpGetAccelSumOfSquare(); |
syundo0730 | 0:78ba160ba5f3 | 817 | // void MPU9150::dmpOverrideQuaternion(long *q); |
syundo0730 | 0:78ba160ba5f3 | 818 | uint16_t MPU9150::dmpGetFIFOPacketSize() { |
syundo0730 | 0:78ba160ba5f3 | 819 | return dmpPacketSize; |
syundo0730 | 0:78ba160ba5f3 | 820 | } |
syundo0730 | 0:78ba160ba5f3 | 821 | |
syundo0730 | 0:78ba160ba5f3 | 822 | #endif /* _MPU9150_9AXIS_MOTIONAPPS41_H_ */ |